Browse Source

[3965] Lease state 0 is a default state.

Changes according to the review.
Marcin Siodelski 9 years ago
parent
commit
5ac55adce6

+ 15 - 11
src/lib/dhcpsrv/lease.cc

@@ -23,11 +23,11 @@ using namespace std;
 namespace isc {
 namespace dhcp {
 
-const uint32_t Lease::STATE_DEFAULT = 0x1;
-const uint32_t Lease::STATE_DECLINED = 0x2;
-const uint32_t Lease::STATE_EXPIRED_RECLAIMED = 0x4;
+const uint32_t Lease::STATE_DEFAULT = 0x0;
+const uint32_t Lease::STATE_DECLINED = 0x1;
+const uint32_t Lease::STATE_EXPIRED_RECLAIMED = 0x2;
 
-const unsigned int Lease::BASIC_STATES_NUM = 3;
+const unsigned int Lease::BASIC_STATES_NUM = 2;
 
 
 Lease::Lease(const isc::asiolink::IOAddress& addr, uint32_t t1, uint32_t t2,
@@ -77,10 +77,6 @@ Lease::basicStatesToText(const uint32_t state) {
             }
             // Check which bit is set and append state name.
             switch (single_state) {
-            case STATE_DEFAULT:
-                s << "default";
-                break;
-
             case STATE_DECLINED:
                 s << "declined";
                 break;
@@ -91,12 +87,12 @@ Lease::basicStatesToText(const uint32_t state) {
 
             default:
                 // This shouldn't really happen.
-                s << "unknown";
+                s << "unknown (" << i << ")";
             }
         }
     }
 
-    return (s.tellp() > 0 ? s.str() : "(not set)");
+    return (s.tellp() > 0 ? s.str() : "default");
 }
 
 bool
@@ -165,7 +161,10 @@ Lease4::Lease4(const isc::asiolink::IOAddress& address,
       ext_(0), client_id_(client_id) {
 }
 
-
+std::string
+Lease4::statesToText(const uint32_t state) {
+    return (Lease::basicStatesToText(state));
+}
 
 const std::vector<uint8_t>&
 Lease4::getClientIdVector() const {
@@ -273,6 +272,11 @@ Lease6::Lease6()
             duid_(DuidPtr()), preferred_lft_(0) {
 }
 
+std::string
+Lease6::statesToText(const uint32_t state) {
+    return (Lease::basicStatesToText(state));
+}
+
 const std::vector<uint8_t>&
 Lease6::getDuidVector() const {
     if (!duid_) {

+ 4 - 9
src/lib/dhcpsrv/lease.h

@@ -63,8 +63,8 @@ struct Lease {
     /// @brief Number of common states for DHCPv4 and DHCPv6.
     ///
     /// This constants holds the number of states used for both DHCPv4 and
-    /// DHCPv6 leases. If new states are defined, this value must be adjusted
-    /// accordingly.
+    /// DHCPv6 leases excluding the default state. If new states are defined,
+    /// this value must be adjusted accordingly.
     static const unsigned int BASIC_STATES_NUM;
     //@}
 
@@ -311,10 +311,7 @@ struct Lease4 : public Lease {
     ///
     /// @param state Numeric value holding lease states.
     /// @return Comma separated list of lease state names.
-    static std::string statesToText(const uint32_t state) {
-        return (Lease::basicStatesToText(state));
-    }
-
+    static std::string statesToText(const uint32_t state);
 
     /// @brief Returns a client identifier.
     ///
@@ -509,9 +506,7 @@ struct Lease6 : public Lease {
     ///
     /// @param state Numeric value holding lease states.
     /// @return Comma separated list of lease state names.
-    static std::string statesToText(const uint32_t state) {
-        return (Lease::basicStatesToText(state));
-    }
+    static std::string statesToText(const uint32_t state);
 
     /// @brief Returns a reference to a vector representing a DUID.
     ///

+ 4 - 4
src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc

@@ -113,10 +113,10 @@ CSVLeaseFile4Test::writeSampleFile() const {
     io_.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
                   "fqdn_fwd,fqdn_rev,hostname,state\n"
                   "192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,"
-                  "host.example.com,1\n"
+                  "host.example.com,0\n"
                   "192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com,1\n"
                   "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,100,100,7,"
-                  "0,0,,2\n");
+                  "0,0,,1\n");
 }
 
 // This test checks the capability to read and parse leases from the file.
@@ -242,9 +242,9 @@ TEST_F(CSVLeaseFile4Test, recreate) {
     // Check that the contents of the csv file are correct.
     EXPECT_EQ("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
               "fqdn_fwd,fqdn_rev,hostname,state\n"
-              "192.0.3.2,00:01:02:03:04:05,,200,200,8,1,1,host.example.com,4\n"
+              "192.0.3.2,00:01:02:03:04:05,,200,200,8,1,1,host.example.com,2\n"
               "192.0.3.10,0d:0e:0a:0d:0b:0e:0e:0f,01:02:03:04,100,100,7,0,"
-              "0,,1\n",
+              "0,,0\n",
               io_.readFile());
 }
 

+ 3 - 3
src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc

@@ -280,11 +280,11 @@ TEST_F(CSVLeaseFile6Test, recreate) {
               "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
               "state\n"
               "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
-              "200,200,8,100,0,7,0,1,1,host.example.com,,1\n"
+              "200,200,8,100,0,7,0,1,1,host.example.com,,0\n"
               "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05"
-              ",300,300,6,150,0,8,128,0,0,,,1\n"
+              ",300,300,6,150,0,8,128,0,0,,,0\n"
               "3000:1:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
-              "300,300,10,150,2,7,64,0,0,,,1\n",
+              "300,300,10,150,2,7,64,0,0,,,0\n",
               io_.readFile());
 }
 

+ 4 - 11
src/lib/dhcpsrv/tests/lease_unittest.cc

@@ -476,12 +476,9 @@ TEST_F(Lease4Test, stateToText) {
     EXPECT_EQ("expired-reclaimed", Lease4::statesToText(Lease::STATE_EXPIRED_RECLAIMED));
 
     // Try multiple states.
-    EXPECT_EQ("default,declined,expired-reclaimed",
-              Lease4::statesToText(Lease::STATE_DEFAULT | Lease::STATE_DECLINED |
-                                   Lease::STATE_EXPIRED_RECLAIMED));
+    EXPECT_EQ("declined,expired-reclaimed",
+              Lease4::statesToText(Lease::STATE_DECLINED | Lease::STATE_EXPIRED_RECLAIMED));
 
-    // Try undefined state.
-    EXPECT_EQ("(not set)", Lease4::statesToText(0));
 }
 
 /// @brief Creates an instance of the lease with certain FQDN data.
@@ -854,12 +851,8 @@ TEST(Lease6Test, stateToText) {
     EXPECT_EQ("expired-reclaimed", Lease6::statesToText(Lease::STATE_EXPIRED_RECLAIMED));
 
     // Try multiple states.
-    EXPECT_EQ("default,declined,expired-reclaimed",
-              Lease6::statesToText(Lease::STATE_DEFAULT | Lease::STATE_DECLINED |
-                                   Lease::STATE_EXPIRED_RECLAIMED));
-
-    // Try undefined state.
-    EXPECT_EQ("(not set)", Lease6::statesToText(0));
+    EXPECT_EQ("declined,expired-reclaimed",
+              Lease6::statesToText(Lease::STATE_DECLINED | Lease::STATE_EXPIRED_RECLAIMED));
 }
 
 

+ 2 - 2
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc

@@ -453,7 +453,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup4) {
     ASSERT_NO_THROW(lease_mgr->addLease(new_lease));
 
     std::string updated_file_contents = new_file_contents +
-        "192.0.2.45,00:00:00:00:00:00,,100,100,1,0,0,,1\n";
+        "192.0.2.45,00:00:00:00:00:00,,100,100,1,0,0,,0\n";
     EXPECT_EQ(updated_file_contents, current_file.readFile());
 
     // This string contains the contents of the lease file we
@@ -536,7 +536,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) {
 
     std::string update_file_contents = new_file_contents +
         "3000::1,00:00:00:00:00:00:00:00:00:00:00:00:00,400,"
-        "400,2,300,0,123,128,0,0,,,1\n";
+        "400,2,300,0,123,128,0,0,,,0\n";
     EXPECT_EQ(update_file_contents, current_file.readFile());
 
     // This string contains the contents of the lease file we