]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5-netconf-config] Updated syntax
authorFrancis Dupont <fdupont@isc.org>
Fri, 28 Sep 2018 11:08:22 +0000 (13:08 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 28 Sep 2018 13:20:46 +0000 (09:20 -0400)
src/bin/netconf/netconf_lexer.ll
src/bin/netconf/netconf_parser.yy
src/bin/netconf/parser_context.cc
src/bin/netconf/parser_context.h
src/bin/netconf/tests/parser_unittests.cc

index d5bb76d1455a72388bb3c978e0af21950e0401b0..fef6c5499dc14e8a934540b8b0b232df21164daa 100644 (file)
@@ -296,40 +296,30 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
     }
 }
 
-\"name\" {
+\"socket-type\" {
     switch(driver.ctx_) {
     case ParserContext::CONTROL_SOCKET:
-    case ParserContext::LOGGERS:
-        return NetconfParser::make_NAME(driver.loc_);
+        return NetconfParser::make_SOCKET_TYPE(driver.loc_);
     default:
-        return NetconfParser::make_STRING("name", driver.loc_);
+        return NetconfParser::make_STRING("socket-type", driver.loc_);
     }
 }
 
-\"type\" {
+\"socket-name\" {
     switch(driver.ctx_) {
     case ParserContext::CONTROL_SOCKET:
-        return NetconfParser::make_TYPE(driver.loc_);
+        return NetconfParser::make_SOCKET_NAME(driver.loc_);
     default:
-        return NetconfParser::make_STRING("type", driver.loc_);
+        return NetconfParser::make_STRING("socket-name", driver.loc_);
     }
 }
 
-\"host\" {
+\"socket-url\" {
     switch(driver.ctx_) {
     case ParserContext::CONTROL_SOCKET:
-        return NetconfParser::make_HOST(driver.loc_);
+        return NetconfParser::make_SOCKET_URL(driver.loc_);
     default:
-        return NetconfParser::make_STRING("host", driver.loc_);
-    }
-}
-
-\"port\" {
-    switch(driver.ctx_) {
-    case ParserContext::CONTROL_SOCKET:
-        return NetconfParser::make_PORT(driver.loc_);
-    default:
-        return NetconfParser::make_STRING("port", driver.loc_);
+        return NetconfParser::make_STRING("socket-url", driver.loc_);
     }
 }
 
@@ -378,6 +368,15 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
     }
 }
 
+\"name\" {
+    switch(driver.ctx_) {
+    case ParserContext::LOGGERS:
+        return NetconfParser::make_NAME(driver.loc_);
+    default:
+        return NetconfParser::make_STRING("name", driver.loc_);
+    }
+}
+
 \"output_options\" {
     switch(driver.ctx_) {
     case ParserContext::LOGGERS:
@@ -441,42 +440,6 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
     }
 }
 
-\"Dhcp4\" {
-    switch(driver.ctx_) {
-    case ParserContext::CONFIG:
-        return NetconfParser::make_DHCP4(driver.loc_);
-    default:
-        return NetconfParser::make_STRING("Dhcp4", driver.loc_);
-    }
-}
-
-\"Dhcp6\" {
-    switch(driver.ctx_) {
-    case ParserContext::CONFIG:
-        return NetconfParser::make_DHCP6(driver.loc_);
-    default:
-        return NetconfParser::make_STRING("Dhcp6", driver.loc_);
-    }
-}
-
-\"DhcpDdns\" {
-    switch(driver.ctx_) {
-    case ParserContext::CONFIG:
-        return NetconfParser::make_DHCPDDNS(driver.loc_);
-    default:
-        return NetconfParser::make_STRING("DhcpDdns", driver.loc_);
-    }
-}
-
-\"Control-agent\" {
-    switch(driver.ctx_) {
-    case ParserContext::CONFIG:
-        return NetconfParser::make_CONTROL_AGENT(driver.loc_);
-    default:
-        return NetconfParser::make_STRING("Control-agent", driver.loc_);
-    }
-}
-
 {JSONString} {
     /* A string has been matched. It contains the actual string and single quotes.
        We need to get those quotes out of the way and just use its content, e.g.
index 2d2710375b316ce74a07ecff9e72fc48dfd7f25f..c6ace3e2bd0d094c9d1d2d94e80529a5c97073c2 100644 (file)
@@ -60,13 +60,12 @@ using namespace std;
   CA_SERVER "ca"
   MODEL "model"
   CONTROL_SOCKET "control-socket"
-  TYPE "type"
+  SOCKET_TYPE "socket-type"
   UNIX "unix"
   HTTP "http"
   STDOUT "stdout"
-  NAME "name"
-  HOST "host"
-  PORT "port"
+  SOCKET_NAME "socket-name"
+  SOCKET_URL "socket-url"
 
   HOOKS_LIBRARIES "hooks-libraries"
   LIBRARY "library"
@@ -74,6 +73,7 @@ using namespace std;
 
   LOGGING "Logging"
   LOGGERS "loggers"
+  NAME "name"
   OUTPUT_OPTIONS "output_options"
   OUTPUT "output"
   DEBUGLEVEL "debuglevel"
@@ -82,11 +82,6 @@ using namespace std;
   MAXSIZE "maxsize"
   MAXVER "maxver"
 
-  DHCP4 "Dhcp4"
-  DHCP6 "Dhcp6"
-  DHCPDDNS "DhcpDdns"
-  CONTROL_AGENT "Control-agent"
-
   // Not real tokens, just a way to signal what the parser is expected to
   // parse. This define the starting point. It either can be full grammar
   // (START_NETCONF), part of the grammar related to control-netconf (START_SUB_NETCONF)
@@ -223,8 +218,7 @@ unknown_map_entry: STRING COLON {
           "got unexpected keyword \"" + keyword + "\" in " + where + " map.");
 };
 
-// This defines the top-level { } that holds Netconf, Dhcp6, Dhcp4,
-// DhcpDdns, Control-agent or Logging objects.
+// This defines the top-level { } that holds Netconf or Logging objects.
 netconf_syntax_map: LCURLY_BRACKET {
     // This code is executed when we're about to start parsing
     // the content of the map
@@ -244,10 +238,6 @@ global_objects: global_object
 // This represents a single top level entry, e.g. Control-netconf, Dhcp6 or DhcpDdns.
 global_object: netconf_object
              | logging_object
-             | dhcp4_json_object
-             | dhcp6_json_object
-             | dhcpddns_json_object
-             | control_agent_object
              | unknown_map_entry
              ;
 
@@ -269,10 +259,14 @@ netconf_object: NETCONF {
     ctx.leave();
 };
 
-global_params: global_param
-             | global_params COMMA global_param
+global_params: %empty
+             | not_empty_global_params
              ;
 
+not_empty_global_params: global_param
+                       | not_empty_global_params COMMA global_param
+                       ;
+
 // These are the parameters that are allowed in the top-level for
 // Netconf.
 global_param: managed_servers
@@ -499,18 +493,17 @@ control_socket_params: control_socket_param
                      ;
 
 control_socket_param: socket_type
-                    | name
-                    | host
-                    | port
+                    | socket_name
+                    | socket_url
                     | user_context
                     | comment
                     | unknown_map_entry
                     ;
 
-socket_type: TYPE {
+socket_type: SOCKET_TYPE {
     ctx.enter(ctx.SOCKET_TYPE);
 } COLON socket_type_value {
-    ctx.stack_.back()->set("type", $4);
+    ctx.stack_.back()->set("socket-type", $4);
     ctx.leave();
 };
 
@@ -520,61 +513,25 @@ socket_type_value : UNIX { $$ = ElementPtr(new StringElement("unix", ctx.loc2pos
                   | STDOUT { $$ = ElementPtr(new StringElement("stdout", ctx.loc2pos(@1))); }
                   ;
 // Unix name.
-name: NAME {
+socket_name: SOCKET_NAME {
     ctx.enter(ctx.NO_KEYWORDS);
 } COLON STRING {
     ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
-    ctx.stack_.back()->set("name", name);
+    ctx.stack_.back()->set("socket-name", name);
     ctx.leave();
 };
 
-// HTTP host.
-host: HOST {
+// HTTP url.
+socket_url: SOCKET_URL {
     ctx.enter(ctx.NO_KEYWORDS);
 } COLON STRING {
-    ElementPtr host(new StringElement($4, ctx.loc2pos(@4)));
-    ctx.stack_.back()->set("host", host);
+    ElementPtr url(new StringElement($4, ctx.loc2pos(@4)));
+    ctx.stack_.back()->set("socket-url", url);
     ctx.leave();
 };
 
-// HTTP PORT
-port: PORT COLON INTEGER {
-    ElementPtr port(new IntElement($3, ctx.loc2pos(@3)));
-    ctx.stack_.back()->set("port", port);
-};
-
 // --- managed-servers end here ------------------------------------------------
 
-// JSON entries for other global objects (Dhcp4,Dhcp6 and DhcpDdns)
-dhcp4_json_object: DHCP4 {
-    ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
-    ctx.stack_.back()->set("Dhcp4", $4);
-    ctx.leave();
-};
-
-dhcp6_json_object: DHCP6 {
-    ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
-    ctx.stack_.back()->set("Dhcp6", $4);
-    ctx.leave();
-};
-
-dhcpddns_json_object: DHCPDDNS {
-    ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
-    ctx.stack_.back()->set("DhcpDdns", $4);
-    ctx.leave();
-};
-
-control_agent_object: CONTROL_AGENT {
-    ctx.enter(ctx.NO_KEYWORDS);
-} COLON value {
-    ctx.stack_.back()->set("Control-agent", $4);
-    ctx.leave();
-};
-
-
 // --- Logging starts here -----------------------------------------------------
 
 // This defines the top level "Logging" object. It parses
@@ -640,6 +597,14 @@ logger_param: name
             | unknown_map_entry
             ;
 
+name: NAME {
+    ctx.enter(ctx.NO_KEYWORDS);
+} COLON STRING {
+    ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
+    ctx.stack_.back()->set("name", name);
+    ctx.leave();
+};
+
 debuglevel: DEBUGLEVEL COLON INTEGER {
     ElementPtr dl(new IntElement($3, ctx.loc2pos(@3)));
     ctx.stack_.back()->set("debuglevel", dl);
index 2b52c0abd0e88bcda485730c87dcb3ca9ee782dc..7f69b714f058b5b73325a72caf04ee18d001789e 100644 (file)
@@ -144,11 +144,11 @@ ParserContext::contextName()
     case MANAGED_SERVERS:
         return ("managed-servers");
     case SERVER:
-        return ("[managed-]server");
+        return ("managed-servers/*");
     case CONTROL_SOCKET:
         return ("control-socket");
     case SOCKET_TYPE:
-        return ("[socket-]type");
+        return ("socket-type");
     case HOOKS_LIBRARIES:
         return ("hooks-libraries");
     case LOGGERS:
index c4985ef84a16ce8df385bad896af65faaea3d98e..9725b589c8534e478f30ca94a96c9356b0295c5f 100644 (file)
@@ -184,7 +184,7 @@ public:
         ///< Used while parsing Netconf/manages-servers/*/control-socket
         CONTROL_SOCKET,
 
-        ///< Used while parsing Netconf/managed-servers/*/control-socket/type.
+        ///< Used while parsing Netconf/managed-servers/*/control-socket/socket-type.
         SOCKET_TYPE,
 
         ///< Used while parsing Netconf/hooks-libraries.
index d4fb8b6d40c016bb8cb4931355b8c741a650f12f..c2ad8221f1b7a172155c6a6f25c94b2a0bff2d22 100644 (file)
@@ -120,78 +120,6 @@ TEST(ParserTest, keywordJSON) {
     testParser(txt, ParserContext::PARSER_JSON);
 }
 
-// This test checks that the DhcpDdns configuration is accepted
-// by the parser.
-TEST(ParserTest, keywordDhcpDdns) {
-    string txt =
-        "{ \"DhcpDdns\" : \n"
-           "{ \n"
-            " \"ip-address\": \"192.168.77.1\", \n"
-            " \"port\": 777 , \n "
-            " \"ncr-protocol\": \"UDP\", \n"
-            "\"tsig-keys\": [], \n"
-            "\"forward-ddns\" : {}, \n"
-            "\"reverse-ddns\" : {} \n"
-            "} \n"
-         "} \n";
-     testParser(txt, ParserContext::PARSER_NETCONF);
-}
-
-// This test checks that the Dhcp6 configuration is accepted
-// by the parser.
-TEST(ParserTest, keywordDhcp6) {
-     string txt = "{ \"Dhcp6\": { \"interfaces-config\": {"
-                  " \"interfaces\": [ \"type\", \"htype\" ] },\n"
-                  "\"preferred-lifetime\": 3000,\n"
-                  "\"rebind-timer\": 2000, \n"
-                  "\"renew-timer\": 1000, \n"
-                  "\"subnet6\": [ { "
-                  "    \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
-                  "    \"subnet\": \"2001:db8:1::/48\", "
-                  "    \"interface\": \"test\" } ],\n"
-                   "\"valid-lifetime\": 4000 } }";
-     testParser(txt, ParserContext::PARSER_NETCONF);
-}
-
-// This test checks that the Dhcp4 configuration is accepted
-// by the parser.
-TEST(ParserTest, keywordDhcp4) {
-    string txt = "{ \"Dhcp4\": { \"interfaces-config\": {"
-                  " \"interfaces\": [ \"type\", \"htype\" ] },\n"
-                  "\"rebind-timer\": 2000, \n"
-                  "\"renew-timer\": 1000, \n"
-                  "\"subnet4\": [ { "
-                  "  \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
-                  "  \"subnet\": \"192.0.2.0/24\", "
-                  "  \"interface\": \"test\" } ],\n"
-                   "\"valid-lifetime\": 4000 } }";
-     testParser(txt, ParserContext::PARSER_NETCONF);
-}
-
-// This test checks that the Control-agent configuration is accepted
-// by the parser.
-TEST(ParserTest, keywordControlAgent) {
-    string txt = "{ \"Control-agent\": {\n"
-        "    \"http-host\": \"localhost\",\n"
-        "    \"http-port\": 8000,\n"
-        "    \"control-sockets\": {"
-        "        \"dhcp4\": {"
-        "            \"socket-type\": \"unix\","
-        "            \"socket-name\": \"/path/to/the/unix/socket-v4\""
-        "        },"
-        "        \"dhcp6\": {"
-        "            \"socket-type\": \"unix\","
-        "            \"socket-name\": \"/path/to/the/unix/socket-v6\""
-        "        },"
-        "        \"d2\": {"
-        "            \"socket-type\": \"unix\","
-        "            \"socket-name\": \"/path/to/the/unix/socket-d2\""
-        "        }"
-        "    }"
-        "} }";
-    testParser(txt, ParserContext::PARSER_NETCONF);
-}
-
 // This test checks if full config (with top level and Netconf objects) can
 // be parsed with syntactic checking (and as pure JSON).
 TEST(ParserTest, keywordNetconf) {
@@ -200,28 +128,27 @@ TEST(ParserTest, keywordNetconf) {
         "        \"dhcp4\": {"
         "            \"model\": \"kea-dhcp4-server\","
         "            \"control-socket\": {"
-        "                \"type\": \"unix\","
-        "                \"name\": \"/path/to/the/unix/socket-v4\""
+        "                \"socket-type\": \"unix\","
+        "                \"socket-name\": \"/path/to/the/unix/socket-v4\""
         "            }"
         "        },"
         "        \"dhcp6\": {"
         "            \"model\": \"kea-dhcp6-server\","
         "            \"control-socket\": {"
-        "                \"type\": \"http\","
-        "                \"host\": \"127.0.0.1\","
-        "                \"port\": 12345"
+        "                \"socket-type\": \"http\","
+        "                \"socket-url\": \"http://127.0.0.1:12345/\""
         "            }"
         "        },"
         "        \"d2\": {"
         "            \"model\": \"kea-dhcp-ddns\","
         "            \"control-socket\": {"
-        "                \"type\": \"stdout\""
+        "                \"socket-type\": \"stdout\""
         "            }"
         "        },"
         "        \"ca\": {"
         "            \"model\": \"kea-ctrl-agent\","
         "            \"control-socket\": {"
-        "                \"type\": \"http\","
+        "                \"socket-type\": \"http\","
         "                \"user-context\": { \"use default\": true }"
         "            }"
         "        }"
@@ -251,29 +178,28 @@ TEST(ParserTest, keywordSubNetconf) {
         "        \"dhcp4\": {"
         "            \"model\": \"kea-dhcp4-server\","
         "            \"control-socket\": {"
-        "                \"type\": \"unix\","
-        "                \"name\": \"/path/to/the/unix/socket-v4\""
+        "                \"socket-type\": \"unix\","
+        "                \"socket-name\": \"/path/to/the/unix/socket-v4\""
         "            }"
         "        },"
         "        \"dhcp6\": {"
         "            \"model\": \"kea-dhcp6-server\","
         "            \"control-socket\": {"
-        "                \"type\": \"http\","
-        "                \"host\": \"127.0.0.1\","
-        "                \"port\": 12345"
+        "                \"socket-type\": \"http\","
+        "                \"socket-url\": \"http://127.0.0.1:12345/\""
         "            }"
         "        },"
         "        \"d2\": {"
         "            \"model\": \"kea-dhcp-ddns\","
         "            \"control-socket\": {"
-        "                \"type\": \"stdout\""
+        "                \"socket-type\": \"stdout\""
         "            }"
         "        },"
         "        \"ca\": {"
         "            \"model\": \"kea-ctrl-agent\","
         "            \"model\": \"kea-dhcp6-server\","
         "            \"control-socket\": {"
-        "                \"type\": \"http\","
+        "                \"socket-type\": \"http\","
         "                \"user-context\": { \"use default\": true }"
         "            }"
         "        }"
@@ -302,10 +228,10 @@ TEST(ParserTest, bashComments) {
                 "      \"model\": \"foo\",\n"
                 "      \"control-socket\": {\n"
                 "# this is a comment\n"
-                "\"type\": \"unix\", \n"
+                "\"socket-type\": \"unix\", \n"
                 "# This socket is mine. I can name it whatever\n"
                 "# I like, ok?\n"
-                "\"name\": \"Hector\" \n"
+                "\"socket-name\": \"Hector\" \n"
                 "} } } } }";
     testParser(txt, ParserContext::PARSER_NETCONF);
 }
@@ -319,8 +245,8 @@ TEST(ParserTest, cppComments) {
                 "    \"d2\": {\n"
                 "      \"model\": \"foo\",\n"
                 "      \"control-socket\": {\n"
-                "\"type\": \"unix\", \n"
-                "\"name\": \"Hector\" \n"
+                "\"socket-type\": \"unix\", \n"
+                "\"socket-name\": \"Hector\" \n"
                 "} } } } }";
 
     testParser(txt, ParserContext::PARSER_NETCONF, false);
@@ -333,8 +259,8 @@ TEST(ParserTest, bashCommentsInline) {
                 "    \"d2\": {\n"
                 "      \"model\": \"foo\",\n"
                 "      \"control-socket\": {\n"
-                "\"type\": \"unix\", # Maybe Hector is not really a \n"
-                "\"name\": \"Hector\" # Unix process?\n"
+                "\"socket-type\": \"unix\", # Maybe Hector is not really a \n"
+                "\"socket-name\": \"Hector\" # Unix process?\n"
                 "# Oh no! He's a windows one and just pretending!\n"
                 "} } } } }";
     testParser(txt, ParserContext::PARSER_NETCONF, false);
@@ -347,7 +273,7 @@ TEST(ParserTest, multilineComments) {
                 "    \"dhcp4\": {\n"
                 "        \"model\": \"foo\",\n"
                 "        \"control-socket\": {\n"
-                "            \"type\": \"stdout\"\n"
+                "            \"socket-type\": \"stdout\"\n"
                 "        }\n"
                 "    }\n"
                 "  /* Ok, forget about it. If Hector doesn't want to talk,\n"
@@ -355,8 +281,8 @@ TEST(ParserTest, multilineComments) {
                 "  /* \"d2\": {"
                 "  \"model\": \"bar\",\n"
                 "  \"control-socket\": {\n"
-                "  \"type\": \"unix\",\n"
-                "\"name\": \"Hector\"\n"
+                "  \"socket-type\": \"unix\",\n"
+                "\"socket-name\": \"Hector\"\n"
                 "} }*/ } } }";
     testParser(txt, ParserContext::PARSER_NETCONF, false);
 }
@@ -369,7 +295,7 @@ TEST(ParserTest, embbededComments) {
                 "    \"dhcp4\": {\n"
                 "      \"control-socket\": {\n"
                 "        \"user-context\": { \"comment\": \"indirect\" },\n"
-                "        \"type\": \"stdout\"\n"
+                "        \"socket-type\": \"stdout\"\n"
                 "    } } },\n"
                 "  \"user-context\": { \"compatible\": true }\n"
                 "} }";