Changes according to the review.
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,
}
// Check which bit is set and append state name.
switch (single_state) {
- case STATE_DEFAULT:
- s << "default";
- break;
-
case STATE_DECLINED:
s << "declined";
break;
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
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 {
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_) {
/// @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;
//@}
///
/// @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.
///
///
/// @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.
///
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.
// 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());
}
"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());
}
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.
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));
}
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
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