From: Marcin Siodelski Date: Wed, 18 Mar 2015 21:04:32 +0000 (+0100) Subject: [3768] Implemented the test which checks overlapping client ids. X-Git-Tag: kea-0.9.1~10^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba89c257a32c944924362349cb70b72a73a2cf7e;p=thirdparty%2Fkea.git [3768] Implemented the test which checks overlapping client ids. --- diff --git a/src/bin/dhcp4/tests/dhcp4_client.cc b/src/bin/dhcp4/tests/dhcp4_client.cc index 18f59ac27c..98d1ce20a3 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.cc +++ b/src/bin/dhcp4/tests/dhcp4_client.cc @@ -49,6 +49,7 @@ Dhcp4Client::Dhcp4Client(const Dhcp4Client::State& state) : curr_transid_(0), dest_addr_("255.255.255.255"), hwaddr_(generateHWAddr()), + clientid_(), iface_name_("eth0"), relay_addr_("192.0.2.2"), requested_options_(), @@ -66,6 +67,7 @@ Dhcp4Client::Dhcp4Client(boost::shared_ptr srv, dest_addr_("255.255.255.255"), fqdn_(), hwaddr_(generateHWAddr()), + clientid_(), iface_name_("eth0"), relay_addr_("192.0.2.2"), requested_options_(), @@ -153,6 +155,8 @@ Dhcp4Client::doDiscover(const boost::shared_ptr& requested_addr) { includePRL(); // Include FQDN or Hostname. includeName(); + // Include Client Identifier + includeClientId(); if (requested_addr) { addRequestedAddress(*requested_addr); } @@ -244,6 +248,8 @@ Dhcp4Client::doRequest() { includePRL(); // Include FQDN or Hostname. includeName(); + // Include Client Identifier + includeClientId(); // Send the message to the server. sendMsg(context_.query_); // Expect response. @@ -254,6 +260,25 @@ Dhcp4Client::doRequest() { } } +void +Dhcp4Client::includeClientId(const std::string& clientid) { + clientid_ = ClientId::fromText(clientid); +} + +void +Dhcp4Client::includeClientId() { + if (!context_.query_) { + isc_throw(Dhcp4ClientError, "pointer to the query must not be NULL" + " when adding Client Identifier option"); + } + + if (clientid_) { + OptionPtr opt(new Option(Option::V4, DHO_DHCP_CLIENT_IDENTIFIER, + clientid_->getClientId())); + context_.query_->addOption(opt); + } +} + void Dhcp4Client::includeFQDN(const uint8_t flags, const std::string& fqdn_name, Option4ClientFqdn::DomainNameType fqdn_type) { diff --git a/src/bin/dhcp4/tests/dhcp4_client.h b/src/bin/dhcp4/tests/dhcp4_client.h index b2b324cbfb..174d1553a7 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.h +++ b/src/bin/dhcp4/tests/dhcp4_client.h @@ -217,6 +217,14 @@ public: return (srv_); } + /// @brief Creates the client id from the client id in the textual format. + /// + /// The generated client id will be added to the client's messages to the + /// server. + /// + /// @param clientid Client id in the textual format. + void includeClientId(const std::string& clientid); + /// @brief Creates an instance of the Client FQDN option to be included /// in the client's message. /// @@ -360,6 +368,13 @@ private: /// @return An instance of the message created. Pkt4Ptr createMsg(const uint8_t msg_type); + /// @brief Includes the Client Identifier option in the client's message. + /// + /// This function creates an instance of the Client Identifier option + /// if the client identifier has been specified and includes this + /// option in the client's message to the server. + void includeClientId(); + /// @brief Includes FQDN or Hostname option in the client's message. /// /// This method checks if @c fqdn_ or @c hostname_ is specified and @@ -407,6 +422,9 @@ private: /// @brief Current hardware address of the client. HWAddrPtr hwaddr_; + /// @brief Current client identifier. + ClientIdPtr clientid_; + /// @brief Interface to be used to send the messages. std::string iface_name_; diff --git a/src/bin/dhcp4/tests/dora_unittest.cc b/src/bin/dhcp4/tests/dora_unittest.cc index 2e98c2d672..e7548a02e2 100644 --- a/src/bin/dhcp4/tests/dora_unittest.cc +++ b/src/bin/dhcp4/tests/dora_unittest.cc @@ -441,6 +441,28 @@ TEST_F(DORATest, ciaddr) { EXPECT_EQ("0.0.0.0", resp->getCiaddr().toText()); } +TEST_F(DORATest, overlappingClientId) { + Dhcp4Client clientA(Dhcp4Client::SELECTING); + clientA.includeClientId("12:34"); + configure(DORA_CONFIGS[0], *clientA.getServer()); + ASSERT_NO_THROW(clientA.doDORA()); + // Make sure that the server responded. + ASSERT_TRUE(clientA.getContext().response_); + Pkt4Ptr respA = clientA.getContext().response_; + // Make sure that the server has responded with DHCPACK. + ASSERT_EQ(DHCPACK, static_cast(respA->getType())); + + Dhcp4Client clientB(clientA.getServer(), Dhcp4Client::SELECTING); + clientB.includeClientId("12:34"); + ASSERT_NO_THROW(clientB.doDiscover()); + + Pkt4Ptr respB = clientB.getContext().response_; + // Make sure that the server has responded with DHCPOFFER. + ASSERT_EQ(DHCPOFFER, static_cast(respB->getType())); + + EXPECT_NE(clientA.config_.lease_.addr_, respB->getYiaddr()); +} + // This is a simple test for the host reservation. It creates a reservation // for an address for a single client, identified by the HW address. The // test verifies that the client using this HW address will obtain a