|
@@ -14,8 +14,11 @@
|
|
|
|
|
|
#include <config.h>
|
|
#include <config.h>
|
|
#include <dhcp/tests/iface_mgr_test_config.h>
|
|
#include <dhcp/tests/iface_mgr_test_config.h>
|
|
|
|
+#include <dhcp/option6_client_fqdn.h>
|
|
#include <dhcp6/tests/dhcp6_test_utils.h>
|
|
#include <dhcp6/tests/dhcp6_test_utils.h>
|
|
#include <dhcp6/tests/dhcp6_client.h>
|
|
#include <dhcp6/tests/dhcp6_client.h>
|
|
|
|
+#include <dhcpsrv/cfgmgr.h>
|
|
|
|
+#include <dhcpsrv/d2_client_mgr.h>
|
|
|
|
|
|
using namespace isc;
|
|
using namespace isc;
|
|
using namespace isc::dhcp;
|
|
using namespace isc::dhcp;
|
|
@@ -32,6 +35,16 @@ namespace {
|
|
/// - the delegated prefix was intentionally selected to not match the
|
|
/// - the delegated prefix was intentionally selected to not match the
|
|
/// subnet prefix, to test that the delegated prefix doesn't need to
|
|
/// subnet prefix, to test that the delegated prefix doesn't need to
|
|
/// match the subnet prefix
|
|
/// match the subnet prefix
|
|
|
|
+///
|
|
|
|
+/// - Configuration 1:
|
|
|
|
+/// - two subnets 2001:db8:1::/48 and 2001:db8:2::/48
|
|
|
|
+/// - first subnet assigned to interface eth0, another one assigned to eth1
|
|
|
|
+/// - one pool for subnet in a range of 2001:db8:X::1 - 2001:db8:X::10,
|
|
|
|
+/// where X is 1 or 2
|
|
|
|
+/// - enables Rapid Commit for the first subnet and disables for the second
|
|
|
|
+/// one
|
|
|
|
+/// - DNS updates enabled
|
|
|
|
+///
|
|
const char* CONFIGS[] = {
|
|
const char* CONFIGS[] = {
|
|
// Configuration 0
|
|
// Configuration 0
|
|
"{ \"interfaces-config\": {"
|
|
"{ \"interfaces-config\": {"
|
|
@@ -50,11 +63,36 @@ const char* CONFIGS[] = {
|
|
" \"interface-id\": \"\","
|
|
" \"interface-id\": \"\","
|
|
" \"interface\": \"eth0\""
|
|
" \"interface\": \"eth0\""
|
|
" } ],"
|
|
" } ],"
|
|
- "\"valid-lifetime\": 4000 }"
|
|
|
|
|
|
+ "\"valid-lifetime\": 4000 }",
|
|
|
|
+
|
|
|
|
+// Configuration 1
|
|
|
|
+ "{ \"interfaces-config\": {"
|
|
|
|
+ " \"interfaces\": [ \"*\" ]"
|
|
|
|
+ "},"
|
|
|
|
+ "\"preferred-lifetime\": 3000,"
|
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
|
+ "\"subnet6\": [ { "
|
|
|
|
+ " \"pools\": [ { \"pool\": \"2001:db8:1::1 - 2001:db8:1::10\" } ],"
|
|
|
|
+ " \"subnet\": \"2001:db8:1::/48\", "
|
|
|
|
+ " \"interface\": \"eth0\","
|
|
|
|
+ " \"rapid-commit\": True"
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"pools\": [ { \"pool\": \"2001:db8:2::1 - 2001:db8:2::10\" } ],"
|
|
|
|
+ " \"subnet\": \"2001:db8:2::/48\", "
|
|
|
|
+ " \"interface\": \"eth1\","
|
|
|
|
+ " \"rapid-commit\": False"
|
|
|
|
+ " } ],"
|
|
|
|
+ "\"valid-lifetime\": 4000,"
|
|
|
|
+ " \"dhcp-ddns\" : {"
|
|
|
|
+ " \"enable-updates\" : True, "
|
|
|
|
+ " \"qualifying-suffix\" : \"example.com\" }"
|
|
|
|
+ "}"
|
|
};
|
|
};
|
|
|
|
|
|
/// @brief Test fixture class for testing 4-way exchange: Solicit-Advertise,
|
|
/// @brief Test fixture class for testing 4-way exchange: Solicit-Advertise,
|
|
-/// Request-Reply.
|
|
|
|
|
|
+/// Request-Reply and 2-way exchange: Solicit-Reply.
|
|
class SARRTest : public Dhcpv6SrvTest {
|
|
class SARRTest : public Dhcpv6SrvTest {
|
|
public:
|
|
public:
|
|
/// @brief Constructor.
|
|
/// @brief Constructor.
|
|
@@ -65,6 +103,14 @@ public:
|
|
iface_mgr_test_config_(true) {
|
|
iface_mgr_test_config_(true) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// @brief Destructor.
|
|
|
|
+ ///
|
|
|
|
+ /// Clear the DHCP-DDNS configuration.
|
|
|
|
+ virtual ~SARRTest() {
|
|
|
|
+ D2ClientConfigPtr cfg(new D2ClientConfig());
|
|
|
|
+ CfgMgr::instance().setD2ClientConfig(cfg);
|
|
|
|
+ }
|
|
|
|
+
|
|
/// @brief Interface Manager's fake configuration control.
|
|
/// @brief Interface Manager's fake configuration control.
|
|
IfaceMgrTestConfig iface_mgr_test_config_;
|
|
IfaceMgrTestConfig iface_mgr_test_config_;
|
|
};
|
|
};
|
|
@@ -127,4 +173,108 @@ TEST_F(SARRTest, directClientPrefixHint) {
|
|
ASSERT_TRUE(lease_server);
|
|
ASSERT_TRUE(lease_server);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Check that when the client includes the Rapid Commit option in its
|
|
|
|
+// Solicit, the server responds with Reply and commits the lease.
|
|
|
|
+TEST_F(SARRTest, rapidCommitEnable) {
|
|
|
|
+ Dhcp6Client client;
|
|
|
|
+ // Configure client to request IA_NA
|
|
|
|
+ client.useNA();
|
|
|
|
+ configure(CONFIGS[1], *client.getServer());
|
|
|
|
+ ASSERT_NO_THROW(client.getServer()->startD2());
|
|
|
|
+ // Make sure we ended-up having expected number of subnets configured.
|
|
|
|
+ const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
|
|
|
|
+ getCfgSubnets6()->getAll();
|
|
|
|
+ ASSERT_EQ(2, subnets->size());
|
|
|
|
+ // Perform 2-way exchange.
|
|
|
|
+ client.useRapidCommit(true);
|
|
|
|
+ // Include FQDN to trigger generation of name change requests.
|
|
|
|
+ ASSERT_NO_THROW(client.useFQDN(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "client-name.example.org",
|
|
|
|
+ Option6ClientFqdn::FULL));
|
|
|
|
+
|
|
|
|
+ ASSERT_NO_THROW(client.doSolicit());
|
|
|
|
+ // Server should have committed a lease.
|
|
|
|
+ ASSERT_EQ(1, client.getLeaseNum());
|
|
|
|
+ Lease6 lease_client = client.getLease(0);
|
|
|
|
+ // Make sure that the address belongs to the subnet configured.
|
|
|
|
+ ASSERT_TRUE(CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->
|
|
|
|
+ selectSubnet(lease_client.addr_, ClientClasses()));
|
|
|
|
+ // Make sure that the server responded with Reply.
|
|
|
|
+ ASSERT_TRUE(client.getContext().response_);
|
|
|
|
+ EXPECT_EQ(DHCPV6_REPLY, client.getContext().response_->getType());
|
|
|
|
+ // Rapid Commit option should be included.
|
|
|
|
+ EXPECT_TRUE(client.getContext().response_->getOption(D6O_RAPID_COMMIT));
|
|
|
|
+ // Check that the lease has been committed.
|
|
|
|
+ Lease6Ptr lease_server = checkLease(lease_client);
|
|
|
|
+ EXPECT_TRUE(lease_server);
|
|
|
|
+ // There should be one name change request generated.
|
|
|
|
+ EXPECT_EQ(1, CfgMgr::instance().getD2ClientMgr().getQueueSize());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Check that the server responds with Advertise if the client hasn't
|
|
|
|
+// included the Rapid Commit option in the Solicit.
|
|
|
|
+TEST_F(SARRTest, rapidCommitNoOption) {
|
|
|
|
+ Dhcp6Client client;
|
|
|
|
+ // Configure client to request IA_NA
|
|
|
|
+ client.useNA();
|
|
|
|
+ configure(CONFIGS[1], *client.getServer());
|
|
|
|
+ ASSERT_NO_THROW(client.getServer()->startD2());
|
|
|
|
+ // Make sure we ended-up having expected number of subnets configured.
|
|
|
|
+ const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
|
|
|
|
+ getCfgSubnets6()->getAll();
|
|
|
|
+ ASSERT_EQ(2, subnets->size());
|
|
|
|
+ // Include FQDN to test that the server will not create name change
|
|
|
|
+ // requests when it sends Advertise (Rapid Commit disabled).
|
|
|
|
+ ASSERT_NO_THROW(client.useFQDN(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "client-name.example.org",
|
|
|
|
+ Option6ClientFqdn::FULL));
|
|
|
|
+ ASSERT_NO_THROW(client.doSolicit());
|
|
|
|
+ // There should be no lease because the server should have responded
|
|
|
|
+ // with Advertise.
|
|
|
|
+ ASSERT_EQ(0, client.getLeaseNum());
|
|
|
|
+ // Make sure that the server responded.
|
|
|
|
+ ASSERT_TRUE(client.getContext().response_);
|
|
|
|
+ EXPECT_EQ(DHCPV6_ADVERTISE, client.getContext().response_->getType());
|
|
|
|
+ // Make sure that the Rapid Commit option is not included.
|
|
|
|
+ EXPECT_FALSE(client.getContext().response_->getOption(D6O_RAPID_COMMIT));
|
|
|
|
+ // There should be no name change request generated.
|
|
|
|
+ EXPECT_EQ(0, CfgMgr::instance().getD2ClientMgr().getQueueSize());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Check that when the Rapid Commit support is disabled for the subnet
|
|
|
|
+// the server replies with an Advertise and ignores the Rapid Commit
|
|
|
|
+// option sent by the client.
|
|
|
|
+TEST_F(SARRTest, rapidCommitDisable) {
|
|
|
|
+ Dhcp6Client client;
|
|
|
|
+ // The subnet assigned to eth1 has Rapid Commit disabled.
|
|
|
|
+ client.setInterface("eth1");
|
|
|
|
+ // Configure client to request IA_NA
|
|
|
|
+ client.useNA();
|
|
|
|
+ configure(CONFIGS[1], *client.getServer());
|
|
|
|
+ ASSERT_NO_THROW(client.getServer()->startD2());
|
|
|
|
+ // Make sure we ended-up having expected number of subnets configured.
|
|
|
|
+ const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
|
|
|
|
+ getCfgSubnets6()->getAll();
|
|
|
|
+ ASSERT_EQ(2, subnets->size());
|
|
|
|
+ // Send Rapid Commit option to the server.
|
|
|
|
+ client.useRapidCommit(true);
|
|
|
|
+ // Include FQDN to test that the server will not create name change
|
|
|
|
+ // requests when it sends Advertise (Rapid Commit disabled).
|
|
|
|
+ ASSERT_NO_THROW(client.useFQDN(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "client-name.example.org",
|
|
|
|
+ Option6ClientFqdn::FULL));
|
|
|
|
+ ASSERT_NO_THROW(client.doSolicit());
|
|
|
|
+ // There should be no lease because the server should have responded
|
|
|
|
+ // with Advertise.
|
|
|
|
+ ASSERT_EQ(0, client.getLeaseNum());
|
|
|
|
+ // Make sure that the server responded.
|
|
|
|
+ ASSERT_TRUE(client.getContext().response_);
|
|
|
|
+ EXPECT_EQ(DHCPV6_ADVERTISE, client.getContext().response_->getType());
|
|
|
|
+ // Make sure that the Rapid Commit option is not included.
|
|
|
|
+ EXPECT_FALSE(client.getContext().response_->getOption(D6O_RAPID_COMMIT));
|
|
|
|
+ // There should be no name change request generated.
|
|
|
|
+ EXPECT_EQ(0, CfgMgr::instance().getD2ClientMgr().getQueueSize());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
} // end of anonymous namespace
|
|
} // end of anonymous namespace
|