address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id
-::10,32:30:33,30,1642000000,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16,0
-::11,32:31:33,30,1643210000,40,50,1,60,70,1,1,,38:30,1,{ },90,1,0
-::12,32:32:33,30,1643212345,40,50,1,60,70,1,1,threeˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },90,4,0
+::10,32:30:33,30,1642000000,40,50,1,60,128,1,1,one.example.com,38:30,0,,90,16,0
+::11,32:31:33,30,1643210000,40,50,1,60,128,1,1,,38:30,1,{ },90,1,0
+::12,32:32:33,30,1643212345,40,50,1,60,128,1,1,threeˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },90,4,0
# Insert the reference record
insert_sql="\
-insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,0);\
-insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }',0);\
-insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',0)"
+insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,128,1,1,'one.example.com',80,90,16,0,NULL,0);\
+insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,128,1,1,'',80,90,1,1,'{ }',0);\
+insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,128,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',0)"
run_command \
mysql_execute "$insert_sql"
# Because shell evaluates the double quoted string one more time, they need to be doubled.
# Otherwise, the value is interpreted as ASCII instead of raw bytes.
insert_sql="\
-insert into lease6 values(cast('::10' as inet),E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,1,60,70,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,'',0); \
-insert into lease6 values(cast('::11' as inet),E'\\\\x323133',30,TO_TIMESTAMP(1643210000),40,50,1,60,70,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }',0); \
-insert into lease6 values(cast('::12' as inet),E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,1,60,70,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }',0)"
+insert into lease6 values(cast('::10' as inet),E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,1,60,128,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,'',0); \
+insert into lease6 values(cast('::11' as inet),E'\\\\x323133',30,TO_TIMESTAMP(1643210000),40,50,1,60,128,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }',0); \
+insert into lease6 values(cast('::12' as inet),E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,1,60,128,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }',0)"
run_command \
pgsql_execute "$insert_sql"
// leased by client B. The server should detect that the lease belong to
// someone else and assign a different lease. This is the third out of three
// scenarios tests by old RenewReject test.
-TEST_F(Dhcpv6SrvTest, RenewSomeoneElesesLease) {
+TEST_F(Dhcpv6SrvTest, RenewSomeoneElsesLease) {
testRenewSomeoneElsesLease(Lease::TYPE_NA, IOAddress("2001:db8::1"));
}
const uint32_t valid_iaid = 234;
const uint32_t bogus_iaid = 456;
- uint8_t prefix_len = (type == Lease::TYPE_PD) ? 128 : pd_pool_->getLength();
+ uint8_t prefix_len = (type != Lease::TYPE_PD) ? 128 : pd_pool_->getLength();
// Quick sanity check that the address we're about to use is ok
ASSERT_TRUE(subnet_->inPool(type, addr));
const uint32_t valid_iaid = 234;
const uint32_t transid = 1234;
- uint8_t prefix_len = (type == Lease::TYPE_PD) ? 128 : pd_pool_->getLength();
+ uint8_t prefix_len = (type != Lease::TYPE_PD) ? 128 : pd_pool_->getLength();
// GenerateClientId() also sets duid_
OptionPtr clientid = generateClientId();
// generateClientId assigns DUID to duid_.
generateClientId();
lease_.reset(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
- duid_, 1234, 501, 502,
- 1, HWAddrPtr(), 0));
+ duid_, 1234, 501, 502, 1, HWAddrPtr()));
// Config DDNS to be enabled, all controls off
enableD2();
}
// Make sure the lease hostname and fqdn flags are correct.
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- IOAddress("2001:db8:1::1"));
+ IOAddress("2001:db8:1::1"));
ASSERT_TRUE(lease);
EXPECT_EQ("client1.one.example.com.", lease->hostname_);
EXPECT_TRUE(lease->fqdn_fwd_);
// Make sure the lease hostname and fdqn flags are correct.
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- IOAddress("2001:db8:1::1"));
+ IOAddress("2001:db8:1::1"));
ASSERT_TRUE(lease);
EXPECT_EQ("client1.one.example.com.", lease->hostname_);
EXPECT_TRUE(lease->fqdn_fwd_);
SCOPED_TRACE(scenario.description_); {
// Make sure the lease does not exist.
ASSERT_FALSE(LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- IOAddress("2001:db8:1:1::dead:beef")));
+ IOAddress("2001:db8:1:1::dead:beef")));
// Set and verify DDNS params flags
subnet_->setDdnsSendUpdates(scenario.send_updates_);
subnet_->setDdnsUpdateOnRenew(scenario.update_on_renew_);
// The lease should have been recorded in the database.
Lease6Ptr old_lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- IOAddress("2001:db8:1:1::dead:beef"));
+ IOAddress("2001:db8:1:1::dead:beef"));
ASSERT_TRUE(old_lease);
if (!scenario.send_updates_ || scenario.old_fqdn_.empty()) {
// The lease should have been recorded in the database.
Lease6Ptr new_lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- IOAddress("2001:db8:1:1::dead:beef"));
+ IOAddress("2001:db8:1:1::dead:beef"));
ASSERT_TRUE(new_lease);
// Verify queue count is correct.
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Check that preferred, valid and cltt really set and not using
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Check that preferred, valid and cltt really set and not using
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Check that preferred, valid and cltt are really set and not using
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during REBIND.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Check that preferred, valid and cltt really set and not using
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during REBIND.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Check that T1, T2, preferred, valid and cltt really set and not using
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during REBIND.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Check that preferred, valid and cltt really set and not using
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
lease->valid_lft_ = Lease::INFINITY_LFT;
lease->current_valid_lft_ = Lease::INFINITY_LFT;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_PD, prefix, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 80));
+ 501, 502, subnet_->getID(), HWAddrPtr(), 80));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
- prefix);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_PD, prefix, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 80));
+ 501, 502, subnet_->getID(), HWAddrPtr(), 80));
lease->cltt_ = 1234;
lease->valid_lft_ = Lease::INFINITY_LFT;
lease->current_valid_lft_ = Lease::INFINITY_LFT;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
- prefix);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_PD, prefix, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 80));
+ 501, 502, subnet_->getID(), HWAddrPtr(), 80));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
- prefix);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Check that the lease is still there
// get lease by address
- l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Get lease by subnetid/duid/iaid combination
// Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid
// value on purpose. They should be updated during RENEW.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = 1234;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Check that the lease is really in the database
- Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Let's create a RELEASE
// Check that the lease is still there
// get lease by address
- l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
- addr);
+ l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr);
ASSERT_TRUE(l);
// Get lease by subnetid/duid/iaid combination
EXPECT_TRUE(noExistIOF());
removeTestFile();
-
// Test 3: Create a file for previous and finish but not copy.
writeFile(xstr_, "4");
writeFile(fstr_, "6");
EXPECT_TRUE(noExistIOF());
removeTestFile();
-
// Test 4: Create a file for copy and finish but not previous.
writeFile(istr_, "8");
writeFile(fstr_, "9");
EXPECT_TRUE(noExistIOF());
removeTestFile();
-
// Test 5: rerun test 2 but using launch instead of cleanup
// as we already have a finish file we shouldn't do any extra
// processing
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 2: only previous available
// Create the test previous file
test_str = v4_hdr_ + a_1 + b_1 + c_1 + b_2 + a_2 + d_1;
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 3: only copy available
// No previous file
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 4: neither available
// No previous file
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 5: a file with a lot of errors
// A previous file with a lot of errors
astr = "1,\n2,\n3,\n4,\n5,\n6,\n7,\n7,\n8,\n9,\n10,\n";
string d_1 = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,600,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n";
- // Subtest 1: bot previous and copy available
+ // new files have 128 prefixlen for non PD type
+ string a_3_n = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
+ "200,400,8,100,0,7,128,1,1,host.example.com,,1,,,,0\n";
+
+ string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
+ "300,800,6,150,0,8,128,0,0,,,1,,,,0\n";
+
+ string b_3_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
+ "300,1000,6,150,0,8,128,0,0,,,1,,,,0\n";
+
+ string d_1_n = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
+ "200,600,8,100,0,7,128,1,1,host.example.com,,1,,,,0\n";
+
+ // Subtest 1: both previous and copy available
// Create the test previous file
test_str = v6_hdr_ + a_1 + b_1 + a_2 + c_1 + a_3 + b_2;
writeFile(xstr_, test_str);
// Compare the results, we expect the last lease for each ip
// except for A which has expired.
// We also verify none of the temp or pid files remain.
- test_str = v6_hdr_ + d_1 + b_3 + c_2;
+ test_str = v6_hdr_ + d_1_n + b_3_n + c_2;
EXPECT_EQ(readFile(xstr_), test_str);
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 2: only previous available
// Create the test previous file
test_str = v6_hdr_ + a_1 + b_1 + a_2 + c_1 + a_3 + b_2;
// Compare the results, we expect the last lease for each ip.
// We also verify none of the temp or pid files remain.
- test_str = v6_hdr_ + a_3 + b_2 + c_1;
+ test_str = v6_hdr_ + a_3_n + b_2_n + c_1;
EXPECT_EQ(readFile(xstr_), test_str);
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 3: only copy available
// No previous file
// Compare the results, we expect the last lease for each ip.
// We also verify none of the temp or pid files remain.
- test_str = v6_hdr_ + d_1 + b_3 + c_2;
+ test_str = v6_hdr_ + d_1_n + b_3_n + c_2;
EXPECT_EQ(readFile(xstr_), test_str);
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 4: neither available
// No previous file
EXPECT_TRUE(noExistIOFP());
removeTestFile();
-
// Subtest 5: a file with a lot of errors
// A previous file with a lot of errors.
astr = "1,\n2,\n3,\n4,\n5,\n6,\n7,\n7,\n8,\n9,\n10,\n";
return (true);
}
- lease.reset(new Lease6(readType(row), readAddress(row), readDUID(row),
+ Lease::Type type = readType(row);
+ uint8_t prefixlen = 128;
+ if (type == Lease::TYPE_PD) {
+ prefixlen = readPrefixLen(row);
+ }
+
+ lease.reset(new Lease6(type, readAddress(row), readDUID(row),
readIAID(row), readPreferred(row),
readValid(row),
readSubnetID(row),
readHWAddr(row),
- readPrefixLen(row)));
+ prefixlen));
lease->cltt_ = readCltt(row);
lease->fqdn_fwd_ = readFqdnFwd(row);
#include <config.h>
+#include <asiolink/io_address.h>
+#include <asiolink/addr_utilities.h>
#include <dhcpsrv/lease.h>
#include <util/pointer_util.h>
#include <util/strutil.h>
#include <sstream>
#include <iostream>
+using namespace isc::asiolink;
using namespace isc::util;
using namespace isc::data;
using namespace std;
preferred_lft_(preferred), reuseable_preferred_lft_(0),
extended_info_action_(ExtendedInfoAction::ACTION_IGNORE) {
if (!duid) {
- isc_throw(InvalidOperation, "DUID is mandatory for an IPv6 lease");
+ isc_throw(BadValue, "DUID is mandatory for an IPv6 lease");
+ }
+
+ if (type != Lease::TYPE_PD && prefixlen != 128) {
+ isc_throw(BadValue, "prefixlen must be 128 for non prefix type");
+ }
+
+ IOAddress first_address = firstAddrInPrefix(addr, prefixlen);
+ if (first_address != addr) {
+ isc_throw(BadValue, "Invalid Lease address boundaries: " << addr
+ << " is not the first address in prefix: " << first_address
+ << "/" << static_cast<uint32_t>(prefixlen));
}
cltt_ = time(NULL);
extended_info_action_(ExtendedInfoAction::ACTION_IGNORE) {
if (!duid) {
- isc_throw(InvalidOperation, "DUID is mandatory for an IPv6 lease");
+ isc_throw(BadValue, "DUID is mandatory for an IPv6 lease");
+ }
+
+ if (type != Lease::TYPE_PD && prefixlen != 128) {
+ isc_throw(BadValue, "prefixlen must be 128 for non prefix type");
+ }
+
+ IOAddress first_address = firstAddrInPrefix(addr, prefixlen);
+ if (first_address != addr) {
+ isc_throw(BadValue, "Invalid Lease address boundaries: " << addr
+ << " is not the first address in prefix: " << first_address
+ << "/" << static_cast<uint32_t>(prefixlen));
}
cltt_ = time(NULL);
<< "allowed.");
}
+ if (type != Lease::TYPE_PD) {
+ prefix_len_ = 128;
+ }
+
// Set up DUID,
DuidPtr duid_ptr(new DUID(duid_buffer_, duid_length_));
getColumnValue(r, row, POOL_ID_COL, pool_id_);
+ if (lease_type_ != Lease::TYPE_PD) {
+ prefix_len_ = 128;
+ }
+
Lease6Ptr result(boost::make_shared<Lease6>(lease_type_, addr,
duid_ptr,
iaid_u_.uval_,
public:
/// @brief Initializes configuration (2 subnets, 1 shared network)
- SharedNetworkAlloc4Test()
- :engine_(0) {
+ SharedNetworkAlloc4Test() : engine_(0) {
// Create two subnets, each with a single address pool. The first subnet
// has only one address in its address pool to make it easier to simulate
// address exhaustion.
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
DuidPtr other_duid = DuidPtr(new DUID(vector<uint8_t>(12, 0xff)));
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
const SubnetID other_subnetid = 999;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid,
- 501, 502, other_subnetid, HWAddrPtr(),
- 0));
+ 501, 502, other_subnetid, HWAddrPtr()));
int64_t other_cumulative =
getStatistics("cumulative-assigned-nas", other_subnetid);
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1c"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
lease->cltt_ = lease_cltt;
// Create a lease for the client.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"),
duid_, iaid_, 300, 400,
- subnet_->getID(), HWAddrPtr(), 128));
+ subnet_->getID(), HWAddrPtr()));
// Allocated 200 seconds ago - half of the lifetime.
time_t lease_cltt = time(NULL) - 200;
// Allocate the lease.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress(address.str()),
- duid, iaid, 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ duid, iaid, 501, 502, subnet_->getID(), HWAddrPtr()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
}
// Let's create an expired lease
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid_,
- 501, 502, subnet_->getID(), HWAddrPtr(),
- 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
lease->fqdn_fwd_ = true;
/// - 2001:db8:1::/56 subnet with pool with 64K addresses.
class SharedNetworkAlloc6Test : public AllocEngine6Test {
public:
- SharedNetworkAlloc6Test()
- :engine_(0) {
-
+ SharedNetworkAlloc6Test() : engine_(0) {
subnet1_ = Subnet6::create(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4, SubnetID(10));
subnet2_ = Subnet6::create(IOAddress("2001:db8:2::"), 56, 1, 2, 3, 4, SubnetID(20));
pool1_.reset(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
Lease6Ptr
insertLease(std::string addr, SubnetID subnet_id) {
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress(addr), duid_, iaid_,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago
if (!LeaseMgrFactory::instance().addLease(lease)) {
ADD_FAILURE() << "Failed to add a lease for address " << addr
const uint32_t other_iaid = 3568;
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
other_duid, other_iaid, 501, 502,
- subnet1_->getID(),
- HWAddrPtr(), 0));
+ subnet1_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// gets renewed.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:2::1"),
duid_, iaid_, 501, 502,
- subnet2_->getID(), HWAddrPtr(), 128));
+ subnet2_->getID(), HWAddrPtr()));
lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
// Create an expired lease for duid1_.
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid1_, 1234,
- 501, 502, subnet_->getID(),
- HWAddrPtr(), 0));
+ 501, 502, subnet_->getID(), HWAddrPtr()));
lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago
lease->valid_lft_ = 495; // Lease was valid for 495 seconds
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("host.example.com", lease->hostname_);
EXPECT_EQ(150, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(8, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_FALSE(lease->fqdn_fwd_);
EXPECT_FALSE(lease->fqdn_rev_);
EXPECT_TRUE(lease->hostname_.empty());
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("one.example.com", lease->hostname_);
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("two.example.com", lease->hostname_);
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("three.example.com", lease->hostname_);
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("three.example.com", lease->hostname_);
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
- EXPECT_EQ(0, lease->prefixlen_);
+ EXPECT_EQ(128, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("three.example.com", lease->hostname_);
NULL
};
const char* ADDRESS6[] = {
- "2001:db8::0", "2001:db8::1", "2001:db8::2", "2001:db8::3",
- "2001:db8::4", "2001:db8::5", "2001:db8::6", "2001:db8::7",
+ "2001:db8::", "2001:db8:1::", "2001:db8:2::", "2001:db8:3::",
+ "2001:db8:4::", "2001:db8:5::", "2001:db8:6::", "2001:db8:7::",
NULL
};
// Set other parameters. For historical reasons, address 0 is not used.
if (address == straddress6_[0]) {
lease->type_ = leasetype6_[0];
- lease->prefixlen_ = 4;
+ lease->prefixlen_ = 128;
lease->iaid_ = 142;
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0x77)));
lease->preferred_lft_ = 900;
} else if (address == straddress6_[1]) {
lease->type_ = leasetype6_[1];
- lease->prefixlen_ = 0;
+ lease->prefixlen_ = 128;
lease->iaid_ = 42;
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0x42)));
lease->preferred_lft_ = 3600;
} else if (address == straddress6_[2]) {
lease->type_ = leasetype6_[2];
- lease->prefixlen_ = 7;
+ lease->prefixlen_ = 48;
lease->iaid_ = 89;
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0x3a)));
lease->preferred_lft_ = 1800;
} else if (address == straddress6_[3]) {
lease->type_ = leasetype6_[3];
- lease->prefixlen_ = 28;
+ lease->prefixlen_ = 128;
lease->iaid_ = 0xfffffffe;
vector<uint8_t> duid;
for (uint8_t i = 31; i < 126; ++i) {
} else if (address == straddress6_[4]) {
// Same DUID and IAID as straddress6_1
lease->type_ = leasetype6_[4];
- lease->prefixlen_ = 15;
+ lease->prefixlen_ = 128;
lease->iaid_ = 42;
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0x42)));
lease->preferred_lft_ = 4800;
} else if (address == straddress6_[5]) {
// Same DUID and IAID as straddress6_1
lease->type_ = leasetype6_[5];
- lease->prefixlen_ = 24;
+ lease->prefixlen_ = 56;
lease->iaid_ = 42; // Same as lease 4
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0x42)));
// Same as lease 4
} else if (address == straddress6_[6]) {
// Same DUID as straddress6_1
lease->type_ = leasetype6_[6];
- lease->prefixlen_ = 24;
+ lease->prefixlen_ = 128;
lease->iaid_ = 93;
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0x42)));
// Same as lease 4
} else if (address == straddress6_[7]) {
// Same IAID as straddress6_1
lease->type_ = leasetype6_[7];
- lease->prefixlen_ = 24;
+ lease->prefixlen_ = 128;
lease->iaid_ = 42;
lease->duid_ = DuidPtr(new DUID(vector<uint8_t>(8, 0xe5)));
lease->preferred_lft_ = 5600;
empty_lease->fqdn_fwd_ = true;
empty_lease->fqdn_rev_ = true;
empty_lease->hostname_ = "myhost.example.com.";
- empty_lease->prefixlen_ = 4;
+ empty_lease->prefixlen_ = 128;
- // Make Two leases per lease type, all with the same DUID, IAID but
+ // Make Two leases per lease type, all with the same DUID, IAID but
// alternate the subnet_ids.
vector<Lease6Ptr> leases;
for (int i = 0; i < 6; ++i) {
- Lease6Ptr lease(new Lease6(*empty_lease));
- lease->type_ = leasetype6_[i / 2];
- lease->addr_ = IOAddress(straddress6_[i]);
- lease->subnet_id_ += (i % 2);
- leases.push_back(lease);
- EXPECT_TRUE(lmptr_->addLease(lease));
- }
+ if (i > 3) {
+ empty_lease->prefixlen_ = 48;
+ } else {
+ empty_lease->prefixlen_ = 128;
+ }
+ Lease6Ptr lease(new Lease6(*empty_lease));
+ lease->type_ = leasetype6_[i / 2];
+ lease->addr_ = IOAddress(straddress6_[(i / 2) + (i % 2) * 3]);
+ lease->subnet_id_ += (i % 2);
+ leases.push_back(lease);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+ }
// Verify getting a single lease by type and address.
for (int i = 0; i < 6; ++i) {
// Iterate over the lease types, asking for leases based on
// lease type, DUID, and IAID.
for (int i = 0; i < 3; ++i) {
- Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i],
- *duid, 142);
+ Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i], *duid, 142);
+
+ auto compare = [](Lease6Ptr& left, Lease6Ptr& right) {
+ return (left->addr_ < right->addr_);
+ };
+ std::sort(returned.begin(), returned.end(), compare);
+
// We should match two per lease type.
ASSERT_EQ(2, returned.size());
it != returned.end(); ++it) {
addresses.push_back((*it)->addr_.toText());
}
- sort(addresses.begin(), addresses.end());
+
+ auto compare_addr = [](const string& left, const string& right) {
+ return (IOAddress(left) < IOAddress(right));
+ };
+ sort(addresses.begin(), addresses.end(), compare_addr);
// Now verify that the lease addresses match.
EXPECT_EQ(addresses[0], leases[(i * 2)]->addr_.toText());
// Iterate over the lease types, asking for leases based on
// lease type, DUID, IAID, and subnet_id.
for (int i = 0; i < 3; ++i) {
- Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i],
- *duid, 142, 23);
+ Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i], *duid, 142, 23);
// We should match one per lease type.
ASSERT_EQ(1, returned.size());
EXPECT_TRUE(*(returned[0]) == *leases[i * 2]);
// Verify getting a single lease by type, duid, iad, and subnet id.
for (int i = 0; i < 6; ++i) {
- Lease6Ptr returned = lmptr_->getLease6(leasetype6_[i / 2],
- *duid, 142, (23 + (i % 2)));
+ Lease6Ptr returned = lmptr_->getLease6(leasetype6_[i / 2], *duid, 142, (23 + (i % 2)));
// We should match one per lease type.
ASSERT_TRUE(returned);
EXPECT_TRUE(*returned == *leases[i]);
void
GenericLeaseMgrTest::testGetLeases6Duid() {
//add leases
- IOAddress addr1(std::string("2001:db8:1::111"));
- IOAddress addr2(std::string("2001:db8:1::222"));
- IOAddress addr3(std::string("2001:db8:1::333"));
+ IOAddress addr1(std::string("2001:db8:1::"));
+ IOAddress addr2(std::string("2001:db8:2::"));
+ IOAddress addr3(std::string("2001:db8:3::"));
DuidPtr duid1(new DUID({0, 1, 1, 1, 1, 1, 1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}));
DuidPtr duid2(new DUID({0, 2, 2, 2, 2, 2, 2, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}));
// Modify some fields in lease 1 (not the address) and update it.
++leases[1]->iaid_;
leases[1]->type_ = Lease::TYPE_PD;
+ leases[1]->prefixlen_ = 93;
leases[1]->valid_lft_ *= 2;
leases[1]->hostname_ = "modified.hostname.v6.";
leases[1]->fqdn_fwd_ = !leases[1]->fqdn_fwd_;
++leases[1]->iaid_;
leases[1]->type_ = Lease::TYPE_TA;
leases[1]->cltt_ += 6;
- leases[1]->prefixlen_ = 93;
+ leases[1]->prefixlen_ = 128;
leases[1]->setContext(Element::fromJSON("{ \"foo\": \"bar\" }"));
lmptr_->updateLease6(leases[1]);
subnet_id = 1;
// Insert three assigned NAs.
- makeLease6(Lease::TYPE_NA, "3001:1::1", 0, subnet_id);
- Lease6Ptr lease2 = makeLease6(Lease::TYPE_NA, "3001:1::2", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "3001:1::3", 0, subnet_id);
+ makeLease6(Lease::TYPE_NA, "3001:1::1", 128, subnet_id);
+ Lease6Ptr lease2 = makeLease6(Lease::TYPE_NA, "3001:1::2", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "3001:1::3", 128, subnet_id);
expectedStats[subnet_id - 1]["assigned-nas"] = 5; // 3 + 2 declined
// Insert two declined NAs.
- makeLease6(Lease::TYPE_NA, "3001:1::4", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "3001:1::4", 128, subnet_id,
Lease::STATE_DECLINED);
- makeLease6(Lease::TYPE_NA, "3001:1::5", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "3001:1::5", 128, subnet_id,
Lease::STATE_DECLINED);
expectedStats[subnet_id - 1]["declined-addresses"] = 2;
// Insert one expired NA.
- makeLease6(Lease::TYPE_NA, "3001:1::6", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "3001:1::6", 128, subnet_id,
Lease::STATE_EXPIRED_RECLAIMED);
// Insert two assigned PDs.
subnet_id = 2;
// Insert two assigned NAs.
- makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2001:db81::1", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2001:db81::2", 128, subnet_id);
expectedStats[subnet_id - 1]["assigned-nas"] = 3; // 2 + 1 declined
// Insert one declined NA.
- Lease6Ptr lease3 = makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id,
+ Lease6Ptr lease3 = makeLease6(Lease::TYPE_NA, "2001:db81::3", 128, subnet_id,
Lease::STATE_DECLINED);
expectedStats[subnet_id - 1]["declined-addresses"] = 1;
// Two assigned PDs.
// Two expired PDs.
subnet_id = 1;
- makeLease6(Lease::TYPE_NA, "3001:1::1", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "3001:1::2", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "3001:1::3", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "3001:1::4", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "3001:1::1", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "3001:1::2", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "3001:1::3", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "3001:1::4", 128, subnet_id,
Lease::STATE_DECLINED);
- makeLease6(Lease::TYPE_NA, "3001:1::5", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "3001:1::5", 128, subnet_id,
Lease::STATE_DECLINED);
- makeLease6(Lease::TYPE_NA, "3001:1::6", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "3001:1::6", 128, subnet_id,
Lease::STATE_EXPIRED_RECLAIMED);
makeLease6(Lease::TYPE_PD, "3001:1:2:0100::", 112, subnet_id);
makeLease6(Lease::TYPE_PD, "3001:1:2:0200::", 112, subnet_id);
// Two assigned NAs
// One declined NAs
subnet_id = 2;
- makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "2001:db81::1", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2001:db81::2", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2001:db81::3", 128, subnet_id,
Lease::STATE_DECLINED);
// Now let's add leases to subnet 3.
// Two assigned NAs
// One declined NAs
subnet_id = 3;
- makeLease6(Lease::TYPE_NA, "2002:db81::1", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "2002:db81::2", 0, subnet_id);
- makeLease6(Lease::TYPE_NA, "2002:db81::3", 0, subnet_id,
+ makeLease6(Lease::TYPE_NA, "2002:db81::1", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2002:db81::2", 128, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2002:db81::3", 128, subnet_id,
Lease::STATE_DECLINED);
// Test single subnet for non-matching subnet
// Now let's insert two leases into subnet 1.
subnet_id = 1;
- makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id);
- Lease6Ptr lease = makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2001:db81::1", 128, subnet_id);
+ Lease6Ptr lease = makeLease6(Lease::TYPE_NA, "2001:db81::2", 128, subnet_id);
// And one lease into subnet 2.
subnet_id = 2;
- makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id);
+ makeLease6(Lease::TYPE_NA, "2001:db81::3", 128, subnet_id);
// Move a lease to the second subnet.
lease->subnet_id_ = subnet_id;
EXPECT_EQ(text, "");
// -- A limit of 1 with 1 current lease should deny further leases. --
- makeLease6(Lease::TYPE_NA, "2001:db8::", 0, 1, Lease::STATE_DEFAULT, Element::fromJSON(
+ makeLease6(Lease::TYPE_NA, "2001:db8::", 128, 1, Lease::STATE_DEFAULT, Element::fromJSON(
R"({ "ISC": { "client-classes": [ "foo" ] } })"));
makeLease6(Lease::TYPE_PD, "2001:db8:1::", 64, 1, Lease::STATE_DEFAULT, Element::fromJSON(
std::string b_2 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
"100,135,7,0,0,,1,,0\n";
-
// Create lease file in which one of the entries for 192.0.2.1
// has a valid_lifetime of 0 and results in the deletion of the
// lease.
std::string a_3 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,400,8,100,0,7,0,1,1,host.example.com,,1,"
"{ \"foobar\": true },,,0\n";
+
std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
"300,300,6,150,0,8,0,0,0,,,1,,,,0\n";
std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
std::string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"100,200,8,0,2,16,64,0,0,,,1,,,,0\n";
+ // new files have 128 prefixlen for non PD type
+ std::string a_3_n = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
+ "200,400,8,100,0,7,128,1,1,host.example.com,,1,"
+ "{ \"foobar\": true },,,0\n";
+
+ std::string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
+ "300,800,6,150,0,8,128,0,0,,,1,,,,0\n";
// Create a lease file with three valid leases: 2001:db8:1::1,
// 3000:1:: and 2001:db8:2::10.
EXPECT_EQ(500, lease->cltt_);
EXPECT_FALSE(lease->getContext());
- test_str = v6_hdr_ + a_3 + b_2 + c_1;
+ test_str = v6_hdr_ + a_3_n + b_2_n + c_1;
writeLeases<Lease6, CSVLeaseFile6, Lease6Storage>(*lf, storage, test_str);
// We should have made 3 attempts to write, with 3 leases written and 0 errors
std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
"300,300,6,150,0,8,0,0,0,,,1,,,,0\n";
+
std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
"300,800,6,150,0,8,0,0,0,,,1,,,,0\n";
+ // new files have 128 prefixlen for non PD type
+ std::string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
+ "300,800,6,150,0,8,128,0,0,,,1,,,,0\n";
+
// Create lease file in which one of the entries for the 2001:db8:1::1
// has valid lifetime set to 0, in which case the lease should be
// deleted.
ASSERT_TRUE(lease);
EXPECT_EQ(500, lease->cltt_);
- test_str = v6_hdr_ + b_2;
+ test_str = v6_hdr_ + b_2_n;
writeLeases<Lease6, CSVLeaseFile6, Lease6Storage>(*lf, storage, test_str);
// We should have made 1 attempts to write, with 1 leases written and 0 errors
EXPECT_FALSE(lease.belongsToClient(null_hw, diff_client_id));
EXPECT_FALSE(lease.belongsToClient(null_hw, null_client_id));
-
// Verify cases for lease that has only HW address.
lease.client_id_ = null_client_id;
EXPECT_TRUE(lease.belongsToClient(matching_hw, matching_client_id));
Lease6Ptr lease2;
EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
DuidPtr(), iaid, 100, 200,
- subnet_id)), InvalidOperation);
+ subnet_id)), BadValue);
+
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
+ DuidPtr(), iaid, 100, 200,
+ subnet_id, true, true, "", HWAddrPtr())), BadValue);
+
+ // Lease6 must have a valid prefix and prefix length.
+ addr = IOAddress(ADDRESS[5]);
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_PD, addr,
+ duid, iaid, 100, 200,
+ subnet_id, HWAddrPtr(), 16)), BadValue);
+
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_PD, addr,
+ duid, iaid, 100, 200,
+ subnet_id, true, true, "", HWAddrPtr(), 16)), BadValue);
+
+ // Lease6 must have a prefixlen set to 128 for non prefix type.
+ addr = IOAddress(ADDRESS[4]);
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
+ duid, iaid, 100, 200,
+ subnet_id, HWAddrPtr(), 96)), BadValue);
+
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
+ duid, iaid, 100, 200,
+ subnet_id, true, true, "", HWAddrPtr(), 96)), BadValue);
}
// This test verifies that the Lease6 constructor which accepts FQDN data,
Lease6Ptr lease2;
EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
DuidPtr(), iaid, 100, 200,
- subnet_id)), InvalidOperation);
+ subnet_id)), BadValue);
+
+ EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr,
+ DuidPtr(), iaid, 100, 200,
+ subnet_id, true, true, "", HWAddrPtr())), BadValue);
}
/// @brief Lease6 Equality Test
// entry each.
std::string result_file_contents = new_file_contents +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n"
+ "8,100,0,7,128,1,1,,,1,{ \"foo\": true },,,0\n"
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,,1,,,,0\n";
+ "8,100,0,7,128,1,1,,,1,,,,0\n";
// The LFC should have created a file with the two leases and moved it
// to leasefile6_0.csv.2
// the same.
std::string input_file_contents = new_file_contents +
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n";
+ "8,100,0,7,128,1,1,,,1,{ \"foo\": true },,,0\n";
LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.1"));
input_file.writeFile(input_file_contents);
// Verify cleaned, converted contents
std::string result_file_contents = header_5_0 +
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800,"
- "8,100,0,7,0,1,1,,,0,,,,0\n"
+ "8,100,0,7,128,1,1,,,0,,,,0\n"
"2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800,"
- "8,100,0,7,0,1,1,,11:22:33:44:55,0,,1,0,0\n";
+ "8,100,0,7,128,1,1,,11:22:33:44:55,0,,1,0,0\n";
EXPECT_EQ(result_file_contents, input_file.readFile());
}
lease->toText(),
"Type: IA_NA(0)\n"
"Address: 2001:db8:1::1\n"
- "Prefix length: 0\n"
+ "Prefix length: 128\n"
"IAID: 7\n"
"Pref life: 100\n"
"Valid life: 400\n"
lease->toText(),
"Type: IA_NA(0)\n"
"Address: 2001:db8:1::2\n"
- "Prefix length: 0\n"
+ "Prefix length: 128\n"
"IAID: 7\n"
"Pref life: 100\n"
"Valid life: 200\n"
lease->toText(),
"Type: IA_NA(0)\n"
"Address: 2001:db8:1::4\n"
- "Prefix length: 0\n"
+ "Prefix length: 128\n"
"IAID: 7\n"
"Pref life: 100\n"
"Valid life: 200\n"
lease->toText(),
"Type: IA_NA(0)\n"
"Address: 2001:db8:1::8\n"
- "Prefix length: 0\n"
+ "Prefix length: 128\n"
"IAID: 7\n"
"Pref life: 100\n"
"Valid life: 200\n"
// List of lease recipes.
std::list<Recipe> recipes{
- { Lease::TYPE_NA, "3001::1", 0, Lease::STATE_DEFAULT, {"water", "slice"} },
- { Lease::TYPE_NA, "3001::2", 0, Lease::STATE_DEFAULT, {"melon"} },
- { Lease::TYPE_NA, "3001::3", 0, Lease::STATE_DEFAULT, {"melon", "slice"} },
+ { Lease::TYPE_NA, "3001::1", 128, Lease::STATE_DEFAULT, {"water", "slice"} },
+ { Lease::TYPE_NA, "3001::2", 128, Lease::STATE_DEFAULT, {"melon"} },
+ { Lease::TYPE_NA, "3001::3", 128, Lease::STATE_DEFAULT, {"melon", "slice"} },
{ Lease::TYPE_PD, "3001:1:2:0100::", 112, Lease::STATE_DEFAULT, {"grapes", "slice"} },
{ Lease::TYPE_PD, "3001:1:2:0200::", 112, Lease::STATE_DEFAULT, {"wrath"} },
// Check the lease file was updated.
string new_content =
"2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01,"
- "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n"
+ "400,1000,8,100,0,7,128,1,1,,,1,,,,0\n"
"2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02,"
- "200,200,8,100,0,7,0,1,1,,,1,"
+ "200,200,8,100,0,7,128,1,1,,,1,"
"{ \"ISC\": { \"relay-info\": [ { \"hop\": 44,"
" \"link\": \"2001:db8::4\","
" \"options\": \"0x00250006010203040506003500086464646464646464\""