Browse Source

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

Tomek Mrugalski 8 years ago
parent
commit
317b6b6c9e

+ 10 - 0
src/bin/dhcp6/dhcp6_lexer.ll

@@ -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\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser6Context::OPTION_DEF:

+ 16 - 0
src/bin/dhcp6/dhcp6_parser.yy

@@ -119,6 +119,7 @@ using namespace std;
   DUID "duid"
   HW_ADDRESS "hw-address"
   HOSTNAME "hostname"
+  FLEX_ID "flex-id"
 
   RELAY "relay"
   IP_ADDRESS "ip-address"
@@ -642,6 +643,7 @@ host_reservation_identifiers_list: host_reservation_identifier
 
 host_reservation_identifier: duid_id
                            | hw_address_id
+                           | flex_id
                            ;
 
 hw_address_id : HW_ADDRESS {
@@ -649,6 +651,11 @@ hw_address_id : HW_ADDRESS {
     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)
 // or by code (number)
 relay_supplied_options: RELAY_SUPPLIED_OPTIONS {
@@ -1308,6 +1315,7 @@ reservation_param: duid
                  | prefixes
                  | hw_address
                  | hostname
+                 | flex_id_value
                  | option_data_list
                  | unknown_map_entry
                  ;
@@ -1356,6 +1364,14 @@ hostname: HOSTNAME {
     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 {
     ElementPtr c(new ListElement(ctx.loc2pos(@1)));
     ctx.stack_.back()->set("client-classes", c);

+ 31 - 19
src/bin/dhcp6/tests/hooks_unittest.cc

@@ -656,9 +656,20 @@ public:
     /// @return always 0
     static int
     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[1] = 0x6f; // o
         id[2] = 0x6f; // o
@@ -2260,23 +2271,24 @@ TEST_F(HooksDhcpv6SrvTest, host6Identifier) {
 
     // Configure 2 subnets, both directly reachable over local interface
     // (let's not complicate the matter with relays)
-    string config = "{ \"interfaces-config\": {"
-        "  \"interfaces\": [ \"*\" ]"
-        "},"
-        "\"preferred-lifetime\": 3000,"
-        "\"rebind-timer\": 2000, "
-        "\"renew-timer\": 1000, "
-        "\"subnet6\": [ { "
-        "    \"pools\": [ { \"pool\": \"2001:db8::/64\" } ],"
-        "    \"subnet\": \"2001:db8::/48\", "
-        "    \"interface\": \"" + valid_iface_ + "\", "
-        "    \"reservations\": ["
-        "        {"
-        "            \"flex-id\": \"'foo'\","
-        "            \"ip-addresses\": \"2001:db8::f00\""
-        "        }"
-        "    ]"
-        " } ],"
+    string config = "{ \"interfaces-config\": {\n"
+        "  \"interfaces\": [ \"*\" ]\n"
+        "},\n"
+        "\"preferred-lifetime\": 3000,\n"
+        "\"rebind-timer\": 2000,\n"
+        "\"renew-timer\": 1000,\n"
+        "\"host-reservation-identifiers\": [ \"flex-id\" ],\n"
+        "\"subnet6\": [ {\n"
+        "    \"pools\": [ { \"pool\": \"2001:db8::/64\" } ],\n"
+        "    \"subnet\": \"2001:db8::/48\", \n"
+        "    \"interface\": \"" + valid_iface_ + "\",\n"
+        "    \"reservations\": [\n"
+        "        {\n"
+        "            \"flex-id\": \"'foo'\",\n"
+        "            \"ip-addresses\": [ \"2001:db8::f00\" ]\n"
+        "        }\n"
+        "    ]\n"
+        " } ]\n,"
         "\"valid-lifetime\": 4000 }";
 
     ConstElementPtr json;

+ 1 - 0
src/lib/dhcpsrv/parsers/host_reservation_parser.cc

@@ -77,6 +77,7 @@ getSupportedParams6(const bool identifiers_only = false) {
     if (identifiers_set.empty()) {
         identifiers_set.insert("hw-address");
         identifiers_set.insert("duid");
+        identifiers_set.insert("flex-id");
     }
     // Copy identifiers and add all other parameters.
     if (params_set.empty()) {