} else if (identifier_name == "circuit-id") {
return (IDENT_CIRCUIT_ID);
+ } else if (identifier_name == "client-id") {
+ return (IDENT_CLIENT_ID);
+
} else {
isc_throw(isc::BadValue, "invalid client identifier type '"
<< identifier_name << "'");
case IDENT_CIRCUIT_ID:
s << "circuit-id";
break;
+ case IDENT_CLIENT_ID:
+ s << "client-id";
+ break;
default:
// This should never happen actually, unless we add new identifier
// and forget to add a case for it above.
case Host::IDENT_CIRCUIT_ID:
return ("circuit-id");
+ case Host::IDENT_CLIENT_ID:
+ return ("client-id");
+
default:
;
}
/// @brief Type of the host identifier.
///
- /// Currently hardware address assigned to an interface and the
- /// DHCPv6 client's DUID are supported.
+ /// Currently supported identifiers are:
+ /// - hardware address (DHCPv4 and DHCPv6),
+ /// - DUID (DHCPv4 and DHCPv6),
+ /// - circuit identifier (DHCPv4),
+ /// - client identifier (DHCPv4).
enum IdentifierType {
IDENT_HWADDR,
IDENT_DUID,
- IDENT_CIRCUIT_ID
+ IDENT_CIRCUIT_ID,
+ IDENT_CLIENT_ID
};
/// @brief Constant pointing to the last identifier of the
/// @ref IdentifierType enumeration.
- static const IdentifierType LAST_IDENTIFIER_TYPE = IDENT_CIRCUIT_ID;
+ static const IdentifierType LAST_IDENTIFIER_TYPE = IDENT_CLIENT_ID;
/// @brief Constructor.
///
///
/// @param identifier Identifier in the textual format. The expected formats
/// for the hardware address and other identifiers are provided above.
- /// @param identifier_name One of "hw-address", "duid", "circuit-id".
+ /// @param identifier_name One of "hw-address", "duid", "circuit-id", "client-id".
/// @param ipv4_subnet_id Identifier of the IPv4 subnet to which the host
/// is connected.
/// @param ipv6_subnet_id Identifier of the IPv6 subnet to which the host
/// This method is called by the @c Host constructor.
///
/// @param identifier Reference to a new identifier in the textual format.
- /// @param name One of "hw-address", "duid", "circuit-id".
+ /// @param name One of "hw-address", "duid", "circuit-id", "client-id".
///
/// @throw BadValue if the identifier is invalid.
void setIdentifier(const std::string& identifier, const std::string& name);
identifiers_set.insert("hw-address");
identifiers_set.insert("duid");
identifiers_set.insert("circuit-id");
+ identifiers_set.insert("client-id");
}
// Copy identifiers and add all other parameters.
if (params_set.empty()) {
/// @brief Vector holding circuit id used by tests.
std::vector<uint8_t> circuit_id_;
+
+ /// @brief Vector holding client id used by tests.
+ std::vector<uint8_t> client_id_;
};
void
const std::string circuit_id_str = "howdy";
circuit_id_.assign(circuit_id_str.begin(), circuit_id_str.end());
+
+ client_id_.push_back(0x01); // Client identifier type.
+ // Often client id comprises HW address.
+ client_id_.insert(client_id_.end(), hwaddr_->hwaddr_.begin(),
+ hwaddr_->hwaddr_.end());
}
void
circuit_id_);
}
+// This test verifies that the parser can parse a reservation entry for
+// which client-id is an identifier. The client-id is specified in
+// hexadecimal format.
+TEST_F(HostReservationParserTest, dhcp4ClientIdHex) {
+ testIdentifier4("client-id", "01010203040506", Host::IDENT_CLIENT_ID,
+ client_id_);
+}
+
+// This test verifies that the parser can parse a reservation entry for
+// which client-id is an identifier. The client-id is specified in
+// hexadecimal format with a '0x' prefix.
+TEST_F(HostReservationParserTest, dhcp4ClientIdHexWithPrefix) {
+ testIdentifier4("client-id", "0x01010203040506", Host::IDENT_CLIENT_ID,
+ client_id_);
+}
+
// This test verifies that the parser can parse the reservation entry
// when IPv4 address is specified, but hostname is not.
TEST_F(HostReservationParserTest, dhcp4NoHostname) {
testInvalidConfig<HostReservationParser6>(config);
}
+// This test verifies that host reservation parser for DHCPv6 rejects
+// "client-id" as a host identifier.
+TEST_F(HostReservationParserTest, dhcp6ClientId) {
+ // Use DHCPv4 specific identifier 'circuit-id' with DHCPv6 parser.
+ std::string config = "{ \"client-id\": \"01010203040506\","
+ "\"ip-addresses\": [ \"2001:db8:1::100\", \"2001:db8:1::200\" ],"
+ "\"prefixes\": [ ],"
+ "\"hostname\": \"foo.example.com\" }";
+ testInvalidConfig<HostReservationParser6>(config);
+}
+
// This test verfies that the parser can parse the IPv6 reservation entry
// which lacks hostname parameter.
TEST_F(HostReservationParserTest, dhcp6NoHostname) {
/// @brief Holds a type of the last identifier in @c IdentifierType enum.
///
/// This value must be updated when new identifiers are added to the enum.
-const Host::IdentifierType LAST_IDENTIFIER_TYPE = Host::IDENT_CIRCUIT_ID;
+const Host::IdentifierType LAST_IDENTIFIER_TYPE = Host::IDENT_CLIENT_ID;
// This test verifies that it is possible to create IPv6 address
// reservation.
EXPECT_EQ(Host::IDENT_HWADDR, Host::getIdentifierType("hw-address"));
EXPECT_EQ(Host::IDENT_DUID, Host::getIdentifierType("duid"));
EXPECT_EQ(Host::IDENT_CIRCUIT_ID, Host::getIdentifierType("circuit-id"));
+ EXPECT_EQ(Host::IDENT_CLIENT_ID, Host::getIdentifierType("client-id"));
EXPECT_THROW(Host::getIdentifierType("unuspported"), isc::BadValue);
}