Browse Source

[3173] Refactor: rename ADDRESS_ONLY and PREFIX_ONLY in LeaseType.

Marcin Siodelski 11 years ago
parent
commit
33b1dda333

+ 8 - 8
tests/tools/perfdhcp/command_options.cc

@@ -33,7 +33,7 @@ namespace isc {
 namespace perfdhcp {
 
 CommandOptions::LeaseType::LeaseType()
-    : type_(ADDRESS_ONLY) {
+    : type_(ADDRESS) {
 }
 
 CommandOptions::LeaseType::LeaseType(const Type lease_type)
@@ -58,10 +58,10 @@ CommandOptions::LeaseType::set(const Type lease_type) {
 void
 CommandOptions::LeaseType::fromCommandLine(const std::string& cmd_line_arg) {
     if (cmd_line_arg == "address-only") {
-        type_ = ADDRESS_ONLY;
+        type_ = ADDRESS;
 
     } else if (cmd_line_arg == "prefix-only") {
-        type_ = PREFIX_ONLY;
+        type_ = PREFIX;
 
     } else if (cmd_line_arg == "address-and-prefix") {
         type_ = ADDRESS_AND_PREFIX;
@@ -76,9 +76,9 @@ CommandOptions::LeaseType::fromCommandLine(const std::string& cmd_line_arg) {
 std::string
 CommandOptions::LeaseType::toText() const {
     switch (type_) {
-    case ADDRESS_ONLY:
+    case ADDRESS:
         return ("address-only (IA_NA option added to the client's request)");
-    case PREFIX_ONLY:
+    case PREFIX:
         return ("prefix-only (IA_PD option added to the client's request)");
     case ADDRESS_AND_PREFIX:
         return ("address-and-prefix (Both IA_NA and IA_PD options added to the"
@@ -109,7 +109,7 @@ CommandOptions::reset() {
     // will need to reset all members many times to perform unit tests
     ipversion_ = 0;
     exchange_mode_ = DORA_SARR;
-    lease_type_.set(LeaseType::ADDRESS_ONLY);
+    lease_type_.set(LeaseType::ADDRESS);
     rate_ = 0;
     report_delay_ = 0;
     clients_num_ = 0;
@@ -682,11 +682,11 @@ CommandOptions::validate() const {
           "-6 (IPv6) must be set to use -c");
     check((getExchangeMode() == DO_SA) && (getNumRequests().size() > 1),
           "second -n<num-request> is not compatible with -i");
-    check((getIpVersion() == 4) && !getLeaseType().is(LeaseType::ADDRESS_ONLY),
+    check((getIpVersion() == 4) && !getLeaseType().is(LeaseType::ADDRESS),
           "-6 option must be used if lease type other than '-e address-only'"
           " is specified");
     check(!getTemplateFiles().empty() &&
-          !getLeaseType().is(LeaseType::ADDRESS_ONLY),
+          !getLeaseType().is(LeaseType::ADDRESS),
           "template files may be only used with '-e address-only'");
     check((getExchangeMode() == DO_SA) && (getDropTime()[1] != 1.),
           "second -d<drop-time> is not compatible with -i");

+ 4 - 4
tests/tools/perfdhcp/command_options.h

@@ -42,8 +42,8 @@ public:
 
         /// The lease type code.
         enum Type {
-            ADDRESS_ONLY,
-            PREFIX_ONLY,
+            ADDRESS,
+            PREFIX,
             ADDRESS_AND_PREFIX
         };
 
@@ -68,8 +68,8 @@ public:
         /// specified from the command line, the address or prefix
         /// (IA_NA or IA_PD) option should be sent to the server.
         /// For example, if user specified '-e address-and-prefix' in the
-        /// command line this function will return true for both ADDRESS_ONLY
-        /// and PREFIX_ONLY, because both address and prefix is requested from
+        /// command line this function will return true for both ADDRESS
+        /// and PREFIX, because both address and prefix is requested from
         /// the server.
         ///
         /// \param lease_type A lease type.

+ 4 - 4
tests/tools/perfdhcp/test_control.cc

@@ -105,7 +105,7 @@ TestControl::copyIaOptions(const Pkt6Ptr& pkt_from, Pkt6Ptr& pkt_to) {
     }
     // IA_NA
     if (CommandOptions::instance().getLeaseType()
-        .includes(CommandOptions::LeaseType::ADDRESS_ONLY)) {
+        .includes(CommandOptions::LeaseType::ADDRESS)) {
         OptionPtr option = pkt_from->getOption(D6O_IA_NA);
         if (!option) {
             isc_throw(OptionNotFound, "IA_NA option not found in the"
@@ -115,7 +115,7 @@ TestControl::copyIaOptions(const Pkt6Ptr& pkt_from, Pkt6Ptr& pkt_to) {
     }
     // IA_PD
     if (CommandOptions::instance().getLeaseType()
-        .includes(CommandOptions::LeaseType::PREFIX_ONLY)) {
+        .includes(CommandOptions::LeaseType::PREFIX)) {
         OptionPtr option = pkt_from->getOption(D6O_IA_PD);
         if (!option) {
             isc_throw(OptionNotFound, "IA_PD option not found in the"
@@ -1789,12 +1789,12 @@ TestControl::sendSolicit6(const TestControlSocket& socket,
 
     // IA_NA
     if (CommandOptions::instance().getLeaseType()
-        .includes(CommandOptions::LeaseType::ADDRESS_ONLY)) {
+        .includes(CommandOptions::LeaseType::ADDRESS)) {
         pkt6->addOption(Option::factory(Option::V6, D6O_IA_NA));
     }
     // IA_PD
     if (CommandOptions::instance().getLeaseType()
-        .includes(CommandOptions::LeaseType::PREFIX_ONLY)) {
+        .includes(CommandOptions::LeaseType::PREFIX)) {
         pkt6->addOption(Option::factory(Option::V6, D6O_IA_PD));
     }
 

+ 28 - 29
tests/tools/perfdhcp/tests/command_options_unittest.cc

@@ -30,48 +30,48 @@ using namespace boost::posix_time;
 
 TEST(LeaseTypeTest, defaultConstructor) {
     CommandOptions::LeaseType lease_type;
-    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS_ONLY));
+    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS));
 }
 
 TEST(LeaseTypeTest, constructor) {
     CommandOptions::LeaseType
-        lease_type1(CommandOptions::LeaseType::ADDRESS_ONLY);
-    EXPECT_TRUE(lease_type1.is(CommandOptions::LeaseType::ADDRESS_ONLY));
+        lease_type1(CommandOptions::LeaseType::ADDRESS);
+    EXPECT_TRUE(lease_type1.is(CommandOptions::LeaseType::ADDRESS));
 
     CommandOptions::LeaseType
-        lease_type2(CommandOptions::LeaseType::PREFIX_ONLY);
-    EXPECT_TRUE(lease_type2.is(CommandOptions::LeaseType::PREFIX_ONLY));
+        lease_type2(CommandOptions::LeaseType::PREFIX);
+    EXPECT_TRUE(lease_type2.is(CommandOptions::LeaseType::PREFIX));
 }
 
 TEST(LeaseTypeTest, set) {
     CommandOptions::LeaseType
-        lease_type(CommandOptions::LeaseType::ADDRESS_ONLY);
-    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS_ONLY));
+        lease_type(CommandOptions::LeaseType::ADDRESS);
+    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS));
 
-    lease_type.set(CommandOptions::LeaseType::PREFIX_ONLY);
-    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::PREFIX_ONLY));
+    lease_type.set(CommandOptions::LeaseType::PREFIX);
+    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::PREFIX));
 }
 
 TEST(LeaseTypeTest, includes) {
     CommandOptions::LeaseType
-        lease_type(CommandOptions::LeaseType::ADDRESS_ONLY);
-    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS_ONLY));
-    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::ADDRESS_ONLY));
-    EXPECT_FALSE(lease_type.includes(CommandOptions::LeaseType::PREFIX_ONLY));
+        lease_type(CommandOptions::LeaseType::ADDRESS);
+    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS));
+    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::ADDRESS));
+    EXPECT_FALSE(lease_type.includes(CommandOptions::LeaseType::PREFIX));
     EXPECT_FALSE(
         lease_type.includes(CommandOptions::LeaseType::ADDRESS_AND_PREFIX)
     );
 
-    lease_type.set(CommandOptions::LeaseType::PREFIX_ONLY);
-    EXPECT_FALSE(lease_type.includes(CommandOptions::LeaseType::ADDRESS_ONLY));
-    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::PREFIX_ONLY));
+    lease_type.set(CommandOptions::LeaseType::PREFIX);
+    EXPECT_FALSE(lease_type.includes(CommandOptions::LeaseType::ADDRESS));
+    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::PREFIX));
     EXPECT_FALSE(
         lease_type.includes(CommandOptions::LeaseType::ADDRESS_AND_PREFIX)
     );
 
     lease_type.set(CommandOptions::LeaseType::ADDRESS_AND_PREFIX);
-    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::ADDRESS_ONLY));
-    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::PREFIX_ONLY));
+    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::ADDRESS));
+    EXPECT_TRUE(lease_type.includes(CommandOptions::LeaseType::PREFIX));
     EXPECT_TRUE(
         lease_type.includes(CommandOptions::LeaseType::ADDRESS_AND_PREFIX)
     );
@@ -81,14 +81,14 @@ TEST(LeaseTypeTest, includes) {
 
 TEST(LeaseTypeTest, fromCommandLine) {
     CommandOptions::LeaseType
-        lease_type(CommandOptions::LeaseType::ADDRESS_ONLY);
-    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS_ONLY));
+        lease_type(CommandOptions::LeaseType::ADDRESS);
+    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS));
 
     lease_type.fromCommandLine("prefix-only");
-    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::PREFIX_ONLY));
+    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::PREFIX));
 
     lease_type.fromCommandLine("address-only");
-    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS_ONLY));
+    EXPECT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS));
 
     EXPECT_THROW(lease_type.fromCommandLine("bogus-parameter"),
                  isc::InvalidParameter);
@@ -97,11 +97,11 @@ TEST(LeaseTypeTest, fromCommandLine) {
 
 TEST(LeaseTypeTest, toText) {
     CommandOptions::LeaseType lease_type;
-    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS_ONLY));
+    ASSERT_TRUE(lease_type.is(CommandOptions::LeaseType::ADDRESS));
     EXPECT_EQ("address-only (IA_NA option added to the client's request)",
               lease_type.toText());
 
-    lease_type.set(CommandOptions::LeaseType::PREFIX_ONLY);
+    lease_type.set(CommandOptions::LeaseType::PREFIX);
     EXPECT_EQ("prefix-only (IA_PD option added to the client's request)",
               lease_type.toText());
 }
@@ -138,8 +138,7 @@ protected:
         EXPECT_NO_THROW(process("perfdhcp 192.168.0.1"));
         EXPECT_EQ(4, opt.getIpVersion());
         EXPECT_EQ(CommandOptions::DORA_SARR, opt.getExchangeMode());
-        EXPECT_TRUE(opt.getLeaseType()
-                    .is(CommandOptions::LeaseType::ADDRESS_ONLY));
+        EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::ADDRESS));
         EXPECT_EQ(0, opt.getRate());
         EXPECT_EQ(0, opt.getReportDelay());
         EXPECT_EQ(0, opt.getClientsNum());
@@ -267,17 +266,17 @@ TEST_F(CommandOptionsTest, LeaseType) {
     ASSERT_NO_THROW(process("perfdhcp -6 -l etx -e address-only all"));
     EXPECT_EQ(6, opt.getIpVersion());
     EXPECT_EQ("etx", opt.getLocalName());
-    EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::ADDRESS_ONLY));
+    EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::ADDRESS));
     // Check that the -e address-only works for IPv4.
     ASSERT_NO_THROW(process("perfdhcp -4 -l etx -e address-only all"));
     EXPECT_EQ(4, opt.getIpVersion());
     EXPECT_EQ("etx", opt.getLocalName());
-    EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::ADDRESS_ONLY));
+    EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::ADDRESS));
     // Check that the -e prefix-only works.
     ASSERT_NO_THROW(process("perfdhcp -6 -l etx -e prefix-only all"));
     EXPECT_EQ(6, opt.getIpVersion());
     EXPECT_EQ("etx", opt.getLocalName());
-    EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::PREFIX_ONLY));
+    EXPECT_TRUE(opt.getLeaseType().is(CommandOptions::LeaseType::PREFIX));
     // Check that -e prefix-only must not coexist with -4 option.
     EXPECT_THROW(process("perfdhcp -4 -l ethx -e prefix-only all"),
                  InvalidParameter);

+ 2 - 2
tests/tools/perfdhcp/tests/test_control_unittest.cc

@@ -656,13 +656,13 @@ private:
         boost::shared_ptr<Pkt6> advertise(new Pkt6(DHCPV6_ADVERTISE, transid));
         // Add IA_NA if requested by the client.
         if (CommandOptions::instance().getLeaseType()
-            .includes(CommandOptions::LeaseType::ADDRESS_ONLY)) {
+            .includes(CommandOptions::LeaseType::ADDRESS)) {
             OptionPtr opt_ia_na = Option::factory(Option::V6, D6O_IA_NA);
             advertise->addOption(opt_ia_na);
         }
         // Add IA_PD if requested by the client.
         if (CommandOptions::instance().getLeaseType()
-            .includes(CommandOptions::LeaseType::PREFIX_ONLY)) {
+            .includes(CommandOptions::LeaseType::PREFIX)) {
             OptionPtr opt_ia_pd = Option::factory(Option::V6, D6O_IA_PD);
             advertise->addOption(opt_ia_pd);
         }