curr_transid_(0),
dest_addr_("255.255.255.255"),
hwaddr_(generateHWAddr()),
+ clientid_(),
iface_name_("eth0"),
relay_addr_("192.0.2.2"),
requested_options_(),
dest_addr_("255.255.255.255"),
fqdn_(),
hwaddr_(generateHWAddr()),
+ clientid_(),
iface_name_("eth0"),
relay_addr_("192.0.2.2"),
requested_options_(),
includePRL();
// Include FQDN or Hostname.
includeName();
+ // Include Client Identifier
+ includeClientId();
if (requested_addr) {
addRequestedAddress(*requested_addr);
}
includePRL();
// Include FQDN or Hostname.
includeName();
+ // Include Client Identifier
+ includeClientId();
// Send the message to the server.
sendMsg(context_.query_);
// Expect response.
}
}
+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) {
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.
///
/// @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
/// @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_;
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<int>(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<int>(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