testMultiStageBoot(0);
}
+ // This test verifies that custom server identifier can be specified for
+ // a subnet.
+ TEST_F(DORATest, customServerIdentifier) {
+ Dhcp4Client client1(Dhcp4Client::SELECTING);
+ // Configure DHCP server.
+ ASSERT_NO_THROW(configure(DORA_CONFIGS[7], *client1.getServer()));
+
+ ASSERT_NO_THROW(client1.doDORA());
+ // Make sure that the server responded.
+ ASSERT_TRUE(client1.getContext().response_);
+ Pkt4Ptr resp = client1.getContext().response_;
+ // Make sure that the server has responded with DHCPACK.
+ ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+ // The explicitly configured server identifier should take precedence
+ // over generated server identifier.
+ EXPECT_EQ("1.2.3.4", client1.config_.serverid_.toText());
+
+ // Repeat the test for different subnet.
+ Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING);
+ client2.setIfaceName("eth1");
+
+ ASSERT_NO_THROW(client2.doDORA());
+ ASSERT_TRUE(client2.getContext().response_);
+ resp = client2.getContext().response_;
+ ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+ EXPECT_EQ("2.3.4.5", client2.config_.serverid_.toText());
+
+ // Create relayed client which will be assigned a lease from the third
+ // subnet. This subnet inherits server identifier value from the global
+ // scope.
+ Dhcp4Client client3(client1.getServer(), Dhcp4Client::SELECTING);
+ client3.useRelay(true, IOAddress("10.2.3.4"));
+
+ ASSERT_NO_THROW(client3.doDORA());
+ ASSERT_TRUE(client3.getContext().response_);
+ resp = client3.getContext().response_;
+ ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+ EXPECT_EQ("3.4.5.6", client3.config_.serverid_.toText());
+ }
+
+ // This test verifies that reserved lease is not assigned to a client which
+ // identifier doesn't match the identifier in the reservation.
+ TEST_F(DORATest, changingCircuitId) {
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ client.setHWAddress("aa:bb:cc:dd:ee:ff");
+ // Use relay agent so as the circuit-id can be inserted.
+ client.useRelay(true, IOAddress("10.0.0.1"), IOAddress("10.0.0.2"));
+
+ // Configure DHCP server.
+ configure(DORA_CONFIGS[11], *client.getServer());
+
+ // Send DHCPDISCOVER.
+ boost::shared_ptr<IOAddress> requested_address(new IOAddress("10.0.0.9"));
+ ASSERT_NO_THROW(client.doDiscover(requested_address));
+ // Make sure that the server responded.
+ ASSERT_TRUE(client.getContext().response_);
+ Pkt4Ptr resp = client.getContext().response_;
+ // Make sure that the server has responded with DHCPOFFER
+ ASSERT_EQ(DHCPOFFER, static_cast<int>(resp->getType()));
+ // Make sure that the client has been offerred a different address
+ // given that circuit-id is not used.
+ EXPECT_NE("10.0.0.9", resp->getYiaddr().toText());
+
+ // Specify circuit-id matching the one in the configuration.
+ client.setCircuitId("charter950");
+
+ // Send DHCPDISCOVER.
+ ASSERT_NO_THROW(client.doDiscover());
+ // Make sure that the server responded.
+ ASSERT_TRUE(client.getContext().response_);
+ resp = client.getContext().response_;
+ // Make sure that the server has responded with DHCPOFFER
+ ASSERT_EQ(DHCPOFFER, static_cast<int>(resp->getType()));
+ // Make sure that the client has been offerred reserved address given that
+ // matching circuit-id has been specified.
+ EXPECT_EQ("10.0.0.9", resp->getYiaddr().toText());
+
+ // Let's now change the circuit-id.
+ client.setCircuitId("gdansk");
+
+ // The client requests offerred address but should be refused this address
+ // given that the circuit-id is not matching.
+ ASSERT_NO_THROW(client.doRequest());
+ // Make sure that the server responded.
+ ASSERT_TRUE(client.getContext().response_);
+ resp = client.getContext().response_;
+ // The client should be refused this address.
+ EXPECT_EQ(DHCPNAK, static_cast<int>(resp->getType()));
+
+ // In this case, the client falls back to the 4-way exchange and should be
+ // allocated an address from the dynamic pool.
+ ASSERT_NO_THROW(client.doDORA());
+ // Make sure that the server responded.
+ ASSERT_TRUE(client.getContext().response_);
+ resp = client.getContext().response_;
+ // The client should be allocated some address.
+ ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+ EXPECT_NE("10.0.0.9", client.config_.lease_.addr_.toText());
+ }
+
// Starting tests which require MySQL backend availability. Those tests
// will not be executed if Kea has been compiled without the
-// --with-dhcp-mysql.
+// --with-mysql.
#ifdef HAVE_MYSQL
/// @brief Test fixture class for the test utilizing MySQL database backend.