Commit 317b6b6c authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[5132] Unit-test written, code fixed for host6_identifier

parent 98831558
...@@ -1002,6 +1002,16 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} ...@@ -1002,6 +1002,16 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
} }
} }
\"flex-id\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::HOST_RESERVATION_IDENTIFIERS:
case isc::dhcp::Parser6Context::RESERVATIONS:
return isc::dhcp::Dhcp6Parser::make_FLEX_ID(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("flex-id", driver.loc_);
}
}
\"space\" { \"space\" {
switch(driver.ctx_) { switch(driver.ctx_) {
case isc::dhcp::Parser6Context::OPTION_DEF: case isc::dhcp::Parser6Context::OPTION_DEF:
......
...@@ -119,6 +119,7 @@ using namespace std; ...@@ -119,6 +119,7 @@ using namespace std;
DUID "duid" DUID "duid"
HW_ADDRESS "hw-address" HW_ADDRESS "hw-address"
HOSTNAME "hostname" HOSTNAME "hostname"
FLEX_ID "flex-id"
RELAY "relay" RELAY "relay"
IP_ADDRESS "ip-address" IP_ADDRESS "ip-address"
...@@ -642,6 +643,7 @@ host_reservation_identifiers_list: host_reservation_identifier ...@@ -642,6 +643,7 @@ host_reservation_identifiers_list: host_reservation_identifier
host_reservation_identifier: duid_id host_reservation_identifier: duid_id
| hw_address_id | hw_address_id
| flex_id
; ;
hw_address_id : HW_ADDRESS { hw_address_id : HW_ADDRESS {
...@@ -649,6 +651,11 @@ hw_address_id : HW_ADDRESS { ...@@ -649,6 +651,11 @@ hw_address_id : HW_ADDRESS {
ctx.stack_.back()->add(hwaddr); ctx.stack_.back()->add(hwaddr);
}; };
flex_id : FLEX_ID {
ElementPtr flex_id(new StringElement("flex-id", ctx.loc2pos(@1)));
ctx.stack_.back()->add(flex_id);
};
// list_content below accepts any value when options are by name (string) // list_content below accepts any value when options are by name (string)
// or by code (number) // or by code (number)
relay_supplied_options: RELAY_SUPPLIED_OPTIONS { relay_supplied_options: RELAY_SUPPLIED_OPTIONS {
...@@ -1308,6 +1315,7 @@ reservation_param: duid ...@@ -1308,6 +1315,7 @@ reservation_param: duid
| prefixes | prefixes
| hw_address | hw_address
| hostname | hostname
| flex_id_value
| option_data_list | option_data_list
| unknown_map_entry | unknown_map_entry
; ;
...@@ -1356,6 +1364,14 @@ hostname: HOSTNAME { ...@@ -1356,6 +1364,14 @@ hostname: HOSTNAME {
ctx.leave(); ctx.leave();
}; };
flex_id_value: FLEX_ID {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr hw(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("flex-id", hw);
ctx.leave();
};
reservation_client_classes: CLIENT_CLASSES { reservation_client_classes: CLIENT_CLASSES {
ElementPtr c(new ListElement(ctx.loc2pos(@1))); ElementPtr c(new ListElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("client-classes", c); ctx.stack_.back()->set("client-classes", c);
......
...@@ -656,9 +656,20 @@ public: ...@@ -656,9 +656,20 @@ public:
/// @return always 0 /// @return always 0
static int static int
host6_identifier_foo_callout(CalloutHandle& handle) { host6_identifier_foo_callout(CalloutHandle& handle) {
callback_name_ = string("host4_identifier"); callback_name_ = string("host6_identifier");
std::vector<uint8_t> id(3); // Make sure the query6 parameter is passed.
handle.getArgument("query6", callback_qry_pkt6_);
// Make sure id_type parameter is passed.
Host::IdentifierType type = Host::IDENT_FLEX;
handle.getArgument("id_type", type);
// Make sure id_value parameter is passed.
std::vector<uint8_t> id;
handle.getArgument("id_value", id);
id.resize(3);
id[0] = 0x66; // f id[0] = 0x66; // f
id[1] = 0x6f; // o id[1] = 0x6f; // o
id[2] = 0x6f; // o id[2] = 0x6f; // o
...@@ -2260,23 +2271,24 @@ TEST_F(HooksDhcpv6SrvTest, host6Identifier) { ...@@ -2260,23 +2271,24 @@ TEST_F(HooksDhcpv6SrvTest, host6Identifier) {
// Configure 2 subnets, both directly reachable over local interface // Configure 2 subnets, both directly reachable over local interface
// (let's not complicate the matter with relays) // (let's not complicate the matter with relays)
string config = "{ \"interfaces-config\": {" string config = "{ \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]" " \"interfaces\": [ \"*\" ]\n"
"}," "},\n"
"\"preferred-lifetime\": 3000," "\"preferred-lifetime\": 3000,\n"
"\"rebind-timer\": 2000, " "\"rebind-timer\": 2000,\n"
"\"renew-timer\": 1000, " "\"renew-timer\": 1000,\n"
"\"subnet6\": [ { " "\"host-reservation-identifiers\": [ \"flex-id\" ],\n"
" \"pools\": [ { \"pool\": \"2001:db8::/64\" } ]," "\"subnet6\": [ {\n"
" \"subnet\": \"2001:db8::/48\", " " \"pools\": [ { \"pool\": \"2001:db8::/64\" } ],\n"
" \"interface\": \"" + valid_iface_ + "\", " " \"subnet\": \"2001:db8::/48\", \n"
" \"reservations\": [" " \"interface\": \"" + valid_iface_ + "\",\n"
" {" " \"reservations\": [\n"
" \"flex-id\": \"'foo'\"," " {\n"
" \"ip-addresses\": \"2001:db8::f00\"" " \"flex-id\": \"'foo'\",\n"
" }" " \"ip-addresses\": [ \"2001:db8::f00\" ]\n"
" ]" " }\n"
" } ]," " ]\n"
" } ]\n,"
"\"valid-lifetime\": 4000 }"; "\"valid-lifetime\": 4000 }";
ConstElementPtr json; ConstElementPtr json;
......
...@@ -77,6 +77,7 @@ getSupportedParams6(const bool identifiers_only = false) { ...@@ -77,6 +77,7 @@ getSupportedParams6(const bool identifiers_only = false) {
if (identifiers_set.empty()) { if (identifiers_set.empty()) {
identifiers_set.insert("hw-address"); identifiers_set.insert("hw-address");
identifiers_set.insert("duid"); identifiers_set.insert("duid");
identifiers_set.insert("flex-id");
} }
// Copy identifiers and add all other parameters. // Copy identifiers and add all other parameters.
if (params_set.empty()) { if (params_set.empty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment