mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-22 09:57:41 +00:00
[#226] Finished v6 code
This commit is contained in:
parent
45799e22bf
commit
3776e08a16
@ -27,8 +27,8 @@ std::string FLQ_CONFIG =
|
|||||||
"\"preferred-lifetime\": 200,"
|
"\"preferred-lifetime\": 200,"
|
||||||
"\"max-preferred-lifetime\": 300,"
|
"\"max-preferred-lifetime\": 300,"
|
||||||
"\"min-valid-lifetime\": 400,"
|
"\"min-valid-lifetime\": 400,"
|
||||||
"\"valid-lifetime\": 500,"
|
"\"valid-lifetime\": 600,"
|
||||||
"\"max-valid-lifetime\": 600,"
|
"\"max-valid-lifetime\": 700,"
|
||||||
"\"rebind-timer\": 250,"
|
"\"rebind-timer\": 250,"
|
||||||
"\"renew-timer\": 250,"
|
"\"renew-timer\": 250,"
|
||||||
"\"adaptive-lease-time-threshold\": .5,"
|
"\"adaptive-lease-time-threshold\": .5,"
|
||||||
@ -99,8 +99,8 @@ TEST_F(FLQTest, empty) {
|
|||||||
// Preferred lifetime should be the config preferred-lifetime (200).
|
// Preferred lifetime should be the config preferred-lifetime (200).
|
||||||
EXPECT_EQ(200, lease->preferred_lft_);
|
EXPECT_EQ(200, lease->preferred_lft_);
|
||||||
|
|
||||||
// Valid lifetime should be the config valid-lifetime (500).
|
// Valid lifetime should be the config valid-lifetime (600).
|
||||||
EXPECT_EQ(500, lease->valid_lft_);
|
EXPECT_EQ(600, lease->valid_lft_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test allocation with almost full pool.
|
// Test allocation with almost full pool.
|
||||||
@ -247,190 +247,273 @@ TEST_F(FLQTest, reclaimed) {
|
|||||||
// Valid lifetime should be the config min-valid-lifetime (400).
|
// Valid lifetime should be the config min-valid-lifetime (400).
|
||||||
EXPECT_EQ(400, lease->valid_lft_);
|
EXPECT_EQ(400, lease->valid_lft_);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
// Test renewal with almost empty pool.
|
// Test renewal with almost empty pool.
|
||||||
TEST_F(FLQTest, renew) {
|
TEST_F(FLQTest, renew) {
|
||||||
Dhcp6Client client(srv_, Dhcp6Client::SELECTING);
|
Dhcp6Client client(srv_);
|
||||||
|
|
||||||
// Configure DHCP server.
|
// Configure DHCP server.
|
||||||
configure(FLQ_CONFIG, *client.getServer());
|
configure(FLQ_CONFIG, *client.getServer());
|
||||||
|
|
||||||
// Obtain a lease from the server using the 4-way exchange.
|
// Perform 4-way exchange with the server requesting the last prefix.
|
||||||
boost::shared_ptr<IOAddress> hint(new IOAddress("10.0.0.14"));
|
client.requestPrefix(1, 51, IOAddress("2001:db8:1:e000::"));
|
||||||
ASSERT_NO_THROW(client.doDORA(hint));
|
ASSERT_NO_THROW(client.doSARR());
|
||||||
|
|
||||||
// Make sure that the server responded.
|
// Server should have assigned a prefix.
|
||||||
Pkt6Ptr resp = client.getContext().response_;
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
ASSERT_TRUE(resp);
|
Lease6Ptr lease = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(lease);
|
||||||
|
|
||||||
// Make sure that the server has responded with DHCPACK.
|
// Make sure that the client has got the requested prefix.
|
||||||
ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
|
EXPECT_EQ("2001:db8:1:e000::", lease->addr_.toText());
|
||||||
|
EXPECT_EQ(51, lease->prefixlen_);
|
||||||
|
|
||||||
// Make sure that the client has got the requested address.
|
// Preferred lifetime should be the config preferred-lifetime (200).
|
||||||
EXPECT_EQ(*hint, resp->getYiaddr());
|
EXPECT_EQ(200, lease->preferred_lft_);
|
||||||
|
|
||||||
// Valid lifetime should be the valid-lifetime parameter value (200).
|
// Valid lifetime should be the config valid-lifetime (600).
|
||||||
OptionUint32Ptr opt = boost::dynamic_pointer_cast<
|
EXPECT_EQ(600, lease->valid_lft_);
|
||||||
OptionUint32>(resp->getOption(DHO_DHCP_LEASE_TIME));
|
|
||||||
ASSERT_TRUE(opt);
|
|
||||||
EXPECT_EQ(200, opt->getValue());
|
|
||||||
|
|
||||||
// Age the lease.
|
// Age the lease.
|
||||||
|
lease->cltt_ -= 1000;
|
||||||
|
lease->current_cltt_ -= 1000;
|
||||||
auto& lease_mgr = LeaseMgrFactory::instance();
|
auto& lease_mgr = LeaseMgrFactory::instance();
|
||||||
Lease6Ptr lease = lease_mgr.getLease6(*hint);
|
|
||||||
ASSERT_TRUE(lease);
|
|
||||||
lease->cltt_ -= 150;
|
|
||||||
lease->current_cltt_ -= 150;
|
|
||||||
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
||||||
|
|
||||||
// Let's transition the client to Renewing state.
|
// Send the renew message to the server.
|
||||||
client.setState(Dhcp6Client::RENEWING);
|
ASSERT_NO_THROW(client.doRenew());
|
||||||
|
|
||||||
// Set the unicast destination address to indicate that it is a renewal.
|
// Server should have renewed the prefix.
|
||||||
client.setDestAddress(IOAddress("10.0.0.1"));
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
ASSERT_NO_THROW(client.doRequest());
|
Lease6Ptr renewed = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(renewed);
|
||||||
|
|
||||||
// Make sure that renewal was ACKed.
|
// Make sure that the client has got the same prefix.
|
||||||
resp = client.getContext().response_;
|
EXPECT_EQ(lease->addr_, renewed->addr_);
|
||||||
ASSERT_TRUE(resp);
|
EXPECT_EQ(lease->prefixlen_, renewed->prefixlen_);
|
||||||
ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
|
|
||||||
|
|
||||||
// Make sure that the client renewed the requested address.
|
// Check the lease was updated.
|
||||||
EXPECT_EQ(*hint, resp->getYiaddr());
|
EXPECT_NEAR(lease->cltt_ + 1000, renewed->cltt_, 2);
|
||||||
|
|
||||||
// Valid lifetime should be the valid-lifetime parameter value (200).
|
// Preferred lifetime should be the config preferred-lifetime (200).
|
||||||
opt = boost::dynamic_pointer_cast<OptionUint32>(resp->getOption(DHO_DHCP_LEASE_TIME));
|
EXPECT_EQ(200, renewed->preferred_lft_);
|
||||||
ASSERT_TRUE(opt);
|
|
||||||
EXPECT_EQ(200, opt->getValue());
|
// Valid lifetime should be the config valid-lifetime (600).
|
||||||
|
EXPECT_EQ(600, renewed->valid_lft_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test renewal with full pool.
|
// Test renewal with full pool.
|
||||||
TEST_F(FLQTest, renewFull) {
|
TEST_F(FLQTest, renewFull) {
|
||||||
Dhcp6Client client(srv_, Dhcp6Client::SELECTING);
|
Dhcp6Client client(srv_);
|
||||||
|
|
||||||
// Configure DHCP server.
|
// Configure DHCP server.
|
||||||
configure(FLQ_CONFIG, *client.getServer());
|
configure(FLQ_CONFIG, *client.getServer());
|
||||||
|
|
||||||
// Obtain a lease from the server using the 4-way exchange.
|
// Perform 4-way exchange with the server requesting the last prefix.
|
||||||
boost::shared_ptr<IOAddress> hint(new IOAddress("10.0.0.14"));
|
client.requestPrefix(1, 51, IOAddress("2001:db8:1:e000::"));
|
||||||
ASSERT_NO_THROW(client.doDORA(hint));
|
ASSERT_NO_THROW(client.doSARR());
|
||||||
|
|
||||||
// Make sure that the server responded.
|
// Server should have assigned a prefix.
|
||||||
Pkt6Ptr resp = client.getContext().response_;
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
ASSERT_TRUE(resp);
|
Lease6Ptr lease = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(lease);
|
||||||
|
|
||||||
// Make sure that the server has responded with DHCPACK.
|
// Make sure that the client has got the requested prefix.
|
||||||
ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
|
EXPECT_EQ("2001:db8:1:e000::", lease->addr_.toText());
|
||||||
|
EXPECT_EQ(51, lease->prefixlen_);
|
||||||
|
|
||||||
// Make sure that the client has got the requested address.
|
// Preferred lifetime should be the config preferred-lifetime (200).
|
||||||
EXPECT_EQ(*hint, resp->getYiaddr());
|
EXPECT_EQ(200, lease->preferred_lft_);
|
||||||
|
|
||||||
// Valid lifetime should be the valid-lifetime parameter value (200).
|
// Valid lifetime should be the config valid-lifetime (600).
|
||||||
OptionUint32Ptr opt = boost::dynamic_pointer_cast<
|
EXPECT_EQ(600, lease->valid_lft_);
|
||||||
OptionUint32>(resp->getOption(DHO_DHCP_LEASE_TIME));
|
|
||||||
ASSERT_TRUE(opt);
|
// Create leases for the first prefixes.
|
||||||
EXPECT_EQ(200, opt->getValue());
|
auto& lease_mgr = LeaseMgrFactory::instance();
|
||||||
|
auto lease0 = createLease6(IOAddress("2001:db8:1::"), 1);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease0));
|
||||||
|
auto lease1 = createLease6(IOAddress("2001:db8:1:2000::"), 2);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease1));
|
||||||
|
auto lease2 = createLease6(IOAddress("2001:db8:1:4000::"), 3);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease2));
|
||||||
|
auto lease3 = createLease6(IOAddress("2001:db8:1:6000::"), 4);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease3));
|
||||||
|
auto lease4 = createLease6(IOAddress("2001:db8:1:8000::"), 5);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease4));
|
||||||
|
auto lease5 = createLease6(IOAddress("2001:db8:1:a000::"), 6);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease5));
|
||||||
|
auto lease6 = createLease6(IOAddress("2001:db8:1:c000::"), 7);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease6));
|
||||||
|
auto lease7 = createLease6(IOAddress("2001:db8:1:e000::"), 8);
|
||||||
|
|
||||||
// Age the lease.
|
// Age the lease.
|
||||||
auto& lease_mgr = LeaseMgrFactory::instance();
|
lease->cltt_ -= 1000;
|
||||||
Lease6Ptr lease = lease_mgr.getLease6(*hint);
|
lease->current_cltt_ -= 1000;
|
||||||
ASSERT_TRUE(lease);
|
|
||||||
lease->cltt_ -= 150;
|
|
||||||
lease->current_cltt_ -= 150;
|
|
||||||
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
||||||
|
|
||||||
// Create leases for the first addresses.
|
// Send the renew message to the server.
|
||||||
auto lease1 = createLease6(IOAddress("10.0.0.11"), 1);
|
ASSERT_NO_THROW(client.doRenew());
|
||||||
EXPECT_TRUE(lease_mgr.addLease(lease1));
|
|
||||||
auto lease2 = createLease6(IOAddress("10.0.0.12"), 2);
|
|
||||||
EXPECT_TRUE(lease_mgr.addLease(lease2));
|
|
||||||
auto lease3 = createLease6(IOAddress("10.0.0.13"), 3);
|
|
||||||
EXPECT_TRUE(lease_mgr.addLease(lease3));
|
|
||||||
|
|
||||||
// Let's transition the client to Renewing state.
|
// Server should have renewed the prefix.
|
||||||
client.setState(Dhcp6Client::RENEWING);
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
|
Lease6Ptr renewed = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(renewed);
|
||||||
|
|
||||||
// Set the unicast destination address to indicate that it is a renewal.
|
// Make sure that the client has got the same prefix.
|
||||||
client.setDestAddress(IOAddress("10.0.0.1"));
|
EXPECT_EQ(lease->addr_, renewed->addr_);
|
||||||
ASSERT_NO_THROW(client.doRequest());
|
EXPECT_EQ(lease->prefixlen_, renewed->prefixlen_);
|
||||||
|
|
||||||
// Make sure that renewal was ACKed.
|
// Check the lease was updated.
|
||||||
resp = client.getContext().response_;
|
EXPECT_NEAR(lease->cltt_ + 1000, renewed->cltt_, 2);
|
||||||
ASSERT_TRUE(resp);
|
|
||||||
ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
|
|
||||||
|
|
||||||
// Make sure that the client renewed the requested address.
|
// Preferred lifetime should be the config min-preferred-lifetime (100).
|
||||||
EXPECT_EQ(*hint, resp->getYiaddr());
|
EXPECT_EQ(100, renewed->preferred_lft_);
|
||||||
|
|
||||||
// Valid lifetime should be the min-valid-lifetime parameter value (100).
|
// Valid lifetime should be the config min-valid-lifetime (400).
|
||||||
opt = boost::dynamic_pointer_cast<OptionUint32>(resp->getOption(DHO_DHCP_LEASE_TIME));
|
EXPECT_EQ(400, renewed->valid_lft_);
|
||||||
ASSERT_TRUE(opt);
|
|
||||||
EXPECT_EQ(100, opt->getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test renewal with full pool but remaining lifetime greater than minimal.
|
// Test renewal with full pool but remaining lifetimes greater than minimal.
|
||||||
TEST_F(FLQTest, renewRemaining) {
|
TEST_F(FLQTest, renewRemaining) {
|
||||||
Dhcp6Client client(srv_, Dhcp6Client::SELECTING);
|
Dhcp6Client client(srv_);
|
||||||
|
|
||||||
// Configure DHCP server.
|
// Configure DHCP server.
|
||||||
configure(FLQ_CONFIG, *client.getServer());
|
configure(FLQ_CONFIG, *client.getServer());
|
||||||
|
|
||||||
// Obtain a lease from the server using the 4-way exchange.
|
// Perform 4-way exchange with the server requesting the last prefix.
|
||||||
boost::shared_ptr<IOAddress> hint(new IOAddress("10.0.0.14"));
|
client.requestPrefix(1, 51, IOAddress("2001:db8:1:e000::"));
|
||||||
ASSERT_NO_THROW(client.doDORA(hint));
|
ASSERT_NO_THROW(client.doSARR());
|
||||||
|
|
||||||
// Make sure that the server responded.
|
// Server should have assigned a prefix.
|
||||||
Pkt6Ptr resp = client.getContext().response_;
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
ASSERT_TRUE(resp);
|
Lease6Ptr lease = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(lease);
|
||||||
|
|
||||||
// Make sure that the server has responded with DHCPACK.
|
// Make sure that the client has got the requested prefix.
|
||||||
ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
|
EXPECT_EQ("2001:db8:1:e000::", lease->addr_.toText());
|
||||||
|
EXPECT_EQ(51, lease->prefixlen_);
|
||||||
|
|
||||||
// Make sure that the client has got the requested address.
|
// Preferred lifetime should be the config preferred-lifetime (200).
|
||||||
EXPECT_EQ(*hint, resp->getYiaddr());
|
EXPECT_EQ(200, lease->preferred_lft_);
|
||||||
|
|
||||||
// Valid lifetime should be the valid-lifetime parameter value (200).
|
// Valid lifetime should be the config valid-lifetime (600).
|
||||||
OptionUint32Ptr opt = boost::dynamic_pointer_cast<
|
EXPECT_EQ(600, lease->valid_lft_);
|
||||||
OptionUint32>(resp->getOption(DHO_DHCP_LEASE_TIME));
|
|
||||||
ASSERT_TRUE(opt);
|
// Create leases for the first prefixes.
|
||||||
EXPECT_EQ(200, opt->getValue());
|
auto& lease_mgr = LeaseMgrFactory::instance();
|
||||||
|
auto lease0 = createLease6(IOAddress("2001:db8:1::"), 1);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease0));
|
||||||
|
auto lease1 = createLease6(IOAddress("2001:db8:1:2000::"), 2);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease1));
|
||||||
|
auto lease2 = createLease6(IOAddress("2001:db8:1:4000::"), 3);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease2));
|
||||||
|
auto lease3 = createLease6(IOAddress("2001:db8:1:6000::"), 4);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease3));
|
||||||
|
auto lease4 = createLease6(IOAddress("2001:db8:1:8000::"), 5);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease4));
|
||||||
|
auto lease5 = createLease6(IOAddress("2001:db8:1:a000::"), 6);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease5));
|
||||||
|
auto lease6 = createLease6(IOAddress("2001:db8:1:c000::"), 7);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease6));
|
||||||
|
auto lease7 = createLease6(IOAddress("2001:db8:1:e000::"), 8);
|
||||||
|
|
||||||
// Age the lease but only by 50 seconds.
|
// Age the lease but only by 50 seconds.
|
||||||
auto& lease_mgr = LeaseMgrFactory::instance();
|
|
||||||
Lease6Ptr lease = lease_mgr.getLease6(*hint);
|
|
||||||
ASSERT_TRUE(lease);
|
|
||||||
lease->cltt_ -= 50;
|
lease->cltt_ -= 50;
|
||||||
lease->current_cltt_ -= 50;
|
lease->current_cltt_ -= 50;
|
||||||
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
||||||
|
|
||||||
// Create leases for the first addresses.
|
// Send the renew message to the server.
|
||||||
auto lease1 = createLease6(IOAddress("10.0.0.11"), 1);
|
ASSERT_NO_THROW(client.doRenew());
|
||||||
|
|
||||||
|
// Server should have renewed the prefix.
|
||||||
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
|
Lease6Ptr renewed = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(renewed);
|
||||||
|
|
||||||
|
// Make sure that the client has got the same prefix.
|
||||||
|
EXPECT_EQ(lease->addr_, renewed->addr_);
|
||||||
|
EXPECT_EQ(lease->prefixlen_, renewed->prefixlen_);
|
||||||
|
|
||||||
|
// Check the lease was updated.
|
||||||
|
EXPECT_NEAR(lease->cltt_ + 50, renewed->cltt_, 2);
|
||||||
|
|
||||||
|
// Preferred lifetime should be the remaining lifetime so ~150.
|
||||||
|
EXPECT_NEAR(150, renewed->preferred_lft_, 2);
|
||||||
|
|
||||||
|
// Valid lifetime should be the remaining lifetime so ~550
|
||||||
|
EXPECT_NEAR(550, renewed->valid_lft_, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test renewal with full pool but remaining valid lifetime only greater
|
||||||
|
// than minimal.
|
||||||
|
TEST_F(FLQTest, renewRemainingValid) {
|
||||||
|
Dhcp6Client client(srv_);
|
||||||
|
|
||||||
|
// Configure DHCP server.
|
||||||
|
configure(FLQ_CONFIG, *client.getServer());
|
||||||
|
|
||||||
|
// Perform 4-way exchange with the server requesting the last prefix.
|
||||||
|
client.requestPrefix(1, 51, IOAddress("2001:db8:1:e000::"));
|
||||||
|
ASSERT_NO_THROW(client.doSARR());
|
||||||
|
|
||||||
|
// Server should have assigned a prefix.
|
||||||
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
|
Lease6Ptr lease = checkLease(client.getLease(0));
|
||||||
|
ASSERT_TRUE(lease);
|
||||||
|
|
||||||
|
// Make sure that the client has got the requested prefix.
|
||||||
|
EXPECT_EQ("2001:db8:1:e000::", lease->addr_.toText());
|
||||||
|
EXPECT_EQ(51, lease->prefixlen_);
|
||||||
|
|
||||||
|
// Preferred lifetime should be the config preferred-lifetime (200).
|
||||||
|
EXPECT_EQ(200, lease->preferred_lft_);
|
||||||
|
|
||||||
|
// Valid lifetime should be the config valid-lifetime (600).
|
||||||
|
EXPECT_EQ(600, lease->valid_lft_);
|
||||||
|
|
||||||
|
// Create leases for the first prefixes.
|
||||||
|
auto& lease_mgr = LeaseMgrFactory::instance();
|
||||||
|
auto lease0 = createLease6(IOAddress("2001:db8:1::"), 1);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease0));
|
||||||
|
auto lease1 = createLease6(IOAddress("2001:db8:1:2000::"), 2);
|
||||||
EXPECT_TRUE(lease_mgr.addLease(lease1));
|
EXPECT_TRUE(lease_mgr.addLease(lease1));
|
||||||
auto lease2 = createLease6(IOAddress("10.0.0.12"), 2);
|
auto lease2 = createLease6(IOAddress("2001:db8:1:4000::"), 3);
|
||||||
EXPECT_TRUE(lease_mgr.addLease(lease2));
|
EXPECT_TRUE(lease_mgr.addLease(lease2));
|
||||||
auto lease3 = createLease6(IOAddress("10.0.0.13"), 3);
|
auto lease3 = createLease6(IOAddress("2001:db8:1:6000::"), 4);
|
||||||
EXPECT_TRUE(lease_mgr.addLease(lease3));
|
EXPECT_TRUE(lease_mgr.addLease(lease3));
|
||||||
|
auto lease4 = createLease6(IOAddress("2001:db8:1:8000::"), 5);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease4));
|
||||||
|
auto lease5 = createLease6(IOAddress("2001:db8:1:a000::"), 6);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease5));
|
||||||
|
auto lease6 = createLease6(IOAddress("2001:db8:1:c000::"), 7);
|
||||||
|
EXPECT_TRUE(lease_mgr.addLease(lease6));
|
||||||
|
auto lease7 = createLease6(IOAddress("2001:db8:1:e000::"), 8);
|
||||||
|
|
||||||
// Let's transition the client to Renewing state.
|
// Age the lease but only by 150 seconds.
|
||||||
client.setState(Dhcp6Client::RENEWING);
|
lease->cltt_ -= 150;
|
||||||
|
lease->current_cltt_ -= 150;
|
||||||
|
EXPECT_NO_THROW(lease_mgr.updateLease6(lease));
|
||||||
|
|
||||||
// Set the unicast destination address to indicate that it is a renewal.
|
// Send the renew message to the server.
|
||||||
client.setDestAddress(IOAddress("10.0.0.1"));
|
ASSERT_NO_THROW(client.doRenew());
|
||||||
ASSERT_NO_THROW(client.doRequest());
|
|
||||||
|
|
||||||
// Make sure that renewal was ACKed.
|
// Server should have renewed the prefix.
|
||||||
resp = client.getContext().response_;
|
ASSERT_EQ(1, client.getLeaseNum());
|
||||||
ASSERT_TRUE(resp);
|
Lease6Ptr renewed = checkLease(client.getLease(0));
|
||||||
ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
|
ASSERT_TRUE(renewed);
|
||||||
|
|
||||||
// Make sure that the client renewed the requested address.
|
// Make sure that the client has got the same prefix.
|
||||||
EXPECT_EQ(*hint, resp->getYiaddr());
|
EXPECT_EQ(lease->addr_, renewed->addr_);
|
||||||
|
EXPECT_EQ(lease->prefixlen_, renewed->prefixlen_);
|
||||||
|
|
||||||
// Valid lifetime should be the remaining lifetime so ~150 seconds.
|
// Check the lease was updated.
|
||||||
opt = boost::dynamic_pointer_cast<OptionUint32>(resp->getOption(DHO_DHCP_LEASE_TIME));
|
EXPECT_NEAR(lease->cltt_ + 150, renewed->cltt_, 2);
|
||||||
ASSERT_TRUE(opt);
|
|
||||||
EXPECT_NEAR(150, opt->getValue(), 2);
|
// Preferred lifetime should be the config min-preferred-lifetime (100).
|
||||||
|
EXPECT_EQ(100, renewed->preferred_lft_);
|
||||||
|
|
||||||
|
// Valid lifetime should be the remaining lifetime so ~450
|
||||||
|
EXPECT_NEAR(450, renewed->valid_lft_, 2);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1737,6 +1737,22 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx,
|
|||||||
existing_leases.end(), Lease6Ptr()), existing_leases.end());
|
existing_leases.end(), Lease6Ptr()), existing_leases.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool
|
||||||
|
useMinLifetimes6(AllocEngine::ClientContext6& ctx, const IOAddress& addr,
|
||||||
|
uint8_t prefix_len) {
|
||||||
|
auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold();
|
||||||
|
if (!threshold.unspecified() && (threshold < 1.0)) {
|
||||||
|
auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_PD)->
|
||||||
|
getOccupancyRate(addr, prefix_len, ctx.query_->getClasses());
|
||||||
|
if (occupancy >= threshold) {
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
} // end of anonymous namespace.
|
||||||
|
|
||||||
Lease6Ptr
|
Lease6Ptr
|
||||||
AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
|
AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
|
||||||
uint8_t prefix_len,
|
uint8_t prefix_len,
|
||||||
@ -1750,19 +1766,8 @@ AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
|
|||||||
isc_throw(BadValue, "Attempt to recycle registered address");
|
isc_throw(BadValue, "Attempt to recycle registered address");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_min = false;
|
|
||||||
if (expired->type_ != Lease::TYPE_PD) {
|
if (expired->type_ != Lease::TYPE_PD) {
|
||||||
prefix_len = 128; // non-PD lease types must be always /128
|
prefix_len = 128; // non-PD lease types must be always /128
|
||||||
} else {
|
|
||||||
auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold();
|
|
||||||
if (!threshold.unspecified() && (threshold < 1.0)) {
|
|
||||||
auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_PD)->
|
|
||||||
getOccupancyRate(expired->addr_, prefix_len,
|
|
||||||
ctx.query_->getClasses());
|
|
||||||
if (occupancy >= threshold) {
|
|
||||||
use_min = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.fake_allocation_) {
|
if (!ctx.fake_allocation_) {
|
||||||
@ -1780,7 +1785,8 @@ AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
|
|||||||
// Calculate life times.
|
// Calculate life times.
|
||||||
expired->preferred_lft_ = 0;
|
expired->preferred_lft_ = 0;
|
||||||
expired->valid_lft_ = 0;
|
expired->valid_lft_ = 0;
|
||||||
if (use_min) {
|
if ((expired->type_ == Lease::TYPE_PD) &&
|
||||||
|
useMinLifetimes6(ctx, expired->addr_, prefix_len)) {
|
||||||
getMinLifetimes6(ctx, expired->preferred_lft_, expired->valid_lft_);
|
getMinLifetimes6(ctx, expired->preferred_lft_, expired->valid_lft_);
|
||||||
} else {
|
} else {
|
||||||
getLifetimes6(ctx, expired->preferred_lft_, expired->valid_lft_);
|
getLifetimes6(ctx, expired->preferred_lft_, expired->valid_lft_);
|
||||||
@ -2053,23 +2059,14 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx,
|
|||||||
uint8_t prefix_len,
|
uint8_t prefix_len,
|
||||||
CalloutHandle::CalloutNextStep& callout_status) {
|
CalloutHandle::CalloutNextStep& callout_status) {
|
||||||
|
|
||||||
uint32_t preferred = 0;
|
|
||||||
uint32_t valid = 0;
|
|
||||||
bool use_min = false;
|
|
||||||
if (ctx.currentIA().type_ != Lease::TYPE_PD) {
|
if (ctx.currentIA().type_ != Lease::TYPE_PD) {
|
||||||
prefix_len = 128; // non-PD lease types must be always /128
|
prefix_len = 128; // non-PD lease types must be always /128
|
||||||
} else {
|
|
||||||
auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold();
|
|
||||||
if (!threshold.unspecified() && (threshold < 1.0)) {
|
|
||||||
auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_PD)->
|
|
||||||
getOccupancyRate(addr, prefix_len,
|
|
||||||
ctx.query_->getClasses());
|
|
||||||
if (occupancy >= threshold) {
|
|
||||||
use_min = true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
uint32_t preferred = 0;
|
||||||
if (use_min) {
|
uint32_t valid = 0;
|
||||||
|
if ((ctx.currentIA().type_ == Lease::TYPE_PD) &&
|
||||||
|
useMinLifetimes6(ctx, addr, prefix_len)) {
|
||||||
getMinLifetimes6(ctx, preferred, valid);
|
getMinLifetimes6(ctx, preferred, valid);
|
||||||
} else {
|
} else {
|
||||||
getLifetimes6(ctx, preferred, valid);
|
getLifetimes6(ctx, preferred, valid);
|
||||||
@ -2201,8 +2198,8 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AllocEngine::getRemaining(const Lease6Ptr& lease, uint32_t& valid,
|
AllocEngine::getRemaining(const Lease6Ptr& lease, uint32_t& preferred,
|
||||||
uint32_t& preferred) {
|
uint32_t& valid) {
|
||||||
valid = 0;
|
valid = 0;
|
||||||
preferred = 0;
|
preferred = 0;
|
||||||
if (!lease || (lease->state_ != Lease::STATE_DEFAULT)) {
|
if (!lease || (lease->state_ != Lease::STATE_DEFAULT)) {
|
||||||
@ -2409,7 +2406,17 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
|
|||||||
|
|
||||||
// Calculate life times.
|
// Calculate life times.
|
||||||
uint32_t current_preferred_lft = lease->preferred_lft_;
|
uint32_t current_preferred_lft = lease->preferred_lft_;
|
||||||
|
if ((lease->type_ == Lease::TYPE_PD) &&
|
||||||
|
useMinLifetimes6(ctx, lease->addr_, lease->prefixlen_)) {
|
||||||
|
uint32_t remain_preferred_lft(0);
|
||||||
|
uint32_t remain_valid_lft(0);
|
||||||
|
getRemaining(lease, remain_preferred_lft, remain_valid_lft);
|
||||||
|
lease->preferred_lft_ = remain_preferred_lft;
|
||||||
|
lease->valid_lft_ = remain_valid_lft;
|
||||||
|
getMinLifetimes6(ctx, lease->preferred_lft_, lease->valid_lft_);
|
||||||
|
} else {
|
||||||
getLifetimes6(ctx, lease->preferred_lft_, lease->valid_lft_);
|
getLifetimes6(ctx, lease->preferred_lft_, lease->valid_lft_);
|
||||||
|
}
|
||||||
|
|
||||||
// If either has changed set the changed flag.
|
// If either has changed set the changed flag.
|
||||||
if ((lease->preferred_lft_ != current_preferred_lft) ||
|
if ((lease->preferred_lft_ != current_preferred_lft) ||
|
||||||
@ -2595,8 +2602,14 @@ AllocEngine::updateLeaseData(ClientContext6& ctx, const Lease6Collection& leases
|
|||||||
uint32_t current_preferred_lft = lease->preferred_lft_;
|
uint32_t current_preferred_lft = lease->preferred_lft_;
|
||||||
if (lease->valid_lft_ == 0) {
|
if (lease->valid_lft_ == 0) {
|
||||||
// The lease was expired by a release: reset zero lifetimes.
|
// The lease was expired by a release: reset zero lifetimes.
|
||||||
|
lease->preferred_lft_ = 0;
|
||||||
|
if ((lease->type_ == Lease::TYPE_PD) &&
|
||||||
|
useMinLifetimes6(ctx, lease->addr_, lease->prefixlen_)) {
|
||||||
|
getMinLifetimes6(ctx, lease->preferred_lft_, lease->valid_lft_);
|
||||||
|
} else {
|
||||||
getLifetimes6(ctx, lease->preferred_lft_, lease->valid_lft_);
|
getLifetimes6(ctx, lease->preferred_lft_, lease->valid_lft_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!ctx.fake_allocation_) {
|
if (!ctx.fake_allocation_) {
|
||||||
bool update_stats = false;
|
bool update_stats = false;
|
||||||
|
|
||||||
@ -4484,6 +4497,21 @@ AllocEngine::getMinValidLft(const ClientContext4& ctx, uint32_t& valid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool
|
||||||
|
useMinValidLft(const AllocEngine::ClientContext4& ctx, const IOAddress&addr) {
|
||||||
|
auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold();
|
||||||
|
if (!threshold.unspecified() && (threshold < 1.0)) {
|
||||||
|
auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_V4)->
|
||||||
|
getOccupancyRate(addr, ctx.query_->getClasses());
|
||||||
|
if (occupancy >= threshold) {
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
} // end of anonymous namespace.
|
||||||
|
|
||||||
Lease4Ptr
|
Lease4Ptr
|
||||||
AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr,
|
AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr,
|
||||||
CalloutHandle::CalloutNextStep& callout_status) {
|
CalloutHandle::CalloutNextStep& callout_status) {
|
||||||
@ -4497,16 +4525,7 @@ AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr,
|
|||||||
// Get the context appropriate lifetime.
|
// Get the context appropriate lifetime.
|
||||||
uint32_t valid_lft = ctx.offer_lft_;
|
uint32_t valid_lft = ctx.offer_lft_;
|
||||||
if (!valid_lft) {
|
if (!valid_lft) {
|
||||||
bool use_min(false);
|
if (useMinValidLft(ctx, addr)) {
|
||||||
auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold();
|
|
||||||
if (!threshold.unspecified() && (threshold < 1.0)) {
|
|
||||||
auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_V4)->
|
|
||||||
getOccupancyRate(addr, ctx.query_->getClasses());
|
|
||||||
if (occupancy >= threshold) {
|
|
||||||
use_min = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (use_min) {
|
|
||||||
getMinValidLft(ctx, valid_lft);
|
getMinValidLft(ctx, valid_lft);
|
||||||
} else {
|
} else {
|
||||||
valid_lft = getValidLft(ctx);
|
valid_lft = getValidLft(ctx);
|
||||||
@ -5216,16 +5235,7 @@ AllocEngine::updateLease4Information(const Lease4Ptr& lease,
|
|||||||
// Get the context appropriate valid lifetime.
|
// Get the context appropriate valid lifetime.
|
||||||
lease->valid_lft_ = ctx.offer_lft_;
|
lease->valid_lft_ = ctx.offer_lft_;
|
||||||
if (!lease->valid_lft_) {
|
if (!lease->valid_lft_) {
|
||||||
bool use_min(false);
|
if (useMinValidLft(ctx, lease->addr_)) {
|
||||||
auto const& threshold = ctx.subnet_->getAdaptiveLeaseTimeThreshold();
|
|
||||||
if (!threshold.unspecified() && (threshold < 1.0)) {
|
|
||||||
auto const& occupancy = ctx.subnet_->getAllocator(Lease::TYPE_V4)->
|
|
||||||
getOccupancyRate(lease->addr_, ctx.query_->getClasses());
|
|
||||||
if (occupancy >= threshold) {
|
|
||||||
use_min = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (use_min) {
|
|
||||||
lease->valid_lft_ = remain_lft;
|
lease->valid_lft_ = remain_lft;
|
||||||
getMinValidLft(ctx, lease->valid_lft_);
|
getMinValidLft(ctx, lease->valid_lft_);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1596,10 +1596,10 @@ public:
|
|||||||
/// @brief Set remaining valid and preferred life times.
|
/// @brief Set remaining valid and preferred life times.
|
||||||
///
|
///
|
||||||
/// @param lease A pointer to the lease.
|
/// @param lease A pointer to the lease.
|
||||||
/// @param [out] valid The remaining valid life time or 0.
|
|
||||||
/// @param [out] preferred The remaining preferred life time or 0.
|
/// @param [out] preferred The remaining preferred life time or 0.
|
||||||
static void getRemaining(const Lease6Ptr& lease, uint32_t& valid,
|
/// @param [out] valid The remaining valid life time or 0.
|
||||||
uint32_t& preferred);
|
static void getRemaining(const Lease6Ptr& lease, uint32_t& preferred,
|
||||||
|
uint32_t& valid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user