]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5097] Added an unit test and 2 examples
authorFrancis Dupont <fdupont@isc.org>
Wed, 18 Jan 2017 00:08:28 +0000 (01:08 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 18 Jan 2017 00:08:28 +0000 (01:08 +0100)
doc/examples/kea6/hooks.json
doc/examples/kea6/multiple-options.json
src/lib/cc/simple_parser.h
src/lib/cc/tests/simple_parser_unittest.cc

index c4039b845d2badf2f19010bce292459e74dc212d..23a403514f530dd48f516e74cec4bbadf690e372 100644 (file)
 # Define a single subnet.
   "subnet6": [
     {
-      "pools": [ { "pool": "2001:db8:1::/80" } ],
+      "pools": [
+        {
+          "pool": "2001:db8:1::/80",
+          "user-context": { "charging": true }
+        } ],
       "subnet": "2001:db8:1::/64",
       "interface": "ethX"
     }
index b0d2cf1be3e1c701335594b6a761f481b03904ae..45b249dd7e715f444680597bf46aa4fea9ebd60c 100644 (file)
@@ -39,6 +39,8 @@
 # addresses from the other pool, or the clients obtaining
 # stateless configuration will be assigned subnet specific value
 # of option 12, i.e. 2001:db8:1:0:ff00::1.
+# For DHCPv6 subnets can have prefix delegation pools too so
+# a pd-pools with an option-data is defined too.
   "subnet6": [
     {
       "option-data": [
             "pool": "2001:db8:1::500 - 2001:db8:2::1000"
         }
       ],
+      "pd-pools": [
+        {
+             "prefix": "2001:2b8:2::",
+             "prefix-len": 56,
+             "delegated-len": 64,
+             "option-data": [
+               {
+                   "code": 12,
+                   "data": "3001:cafe::12:"
+               }
+             ]
+         }
+      ],
       "subnet": "2001:db8:1::/64",
       "interface": "ethX"
     }
index cfcf82bc6481934cbf1735b8ea694dd510a296cd..1a3a500f8d62888726187c0970e425ce1b5625a4 100644 (file)
@@ -11,7 +11,7 @@
 #include <vector>
 #include <string>
 #include <stdint.h>
-#include <vector>
+#include <limits>
 
 namespace isc {
 namespace data {
index d61f557d07c830e09eacb87d34105fba43c50fd7..aa0ccdf81b287c7c40d2b853754ff225f03dca32 100644 (file)
@@ -1,9 +1,10 @@
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+#include <stdint.h>
 #include <cc/simple_parser.h>
 #include <gtest/gtest.h>
 
@@ -54,6 +55,18 @@ public:
     }
 };
 
+class SimpleParserClassTest : public SimpleParser {
+public:
+    /// @brief Instantiation of extractInt for uint8_t
+    ///
+    /// @param name name of the parameter for error report
+    /// @param value value of the parameter
+    uint8_t extractUint8(const std::string& name, ConstElementPtr value) const {
+        return (extractInt<uint8_t, isc::OutOfRange>(name, value));
+    }
+
+};
+
 // This test checks if the parameters can be inherited from the global
 // scope to the subnet scope.
 TEST_F(SimpleParserTest, deriveParams) {
@@ -130,3 +143,25 @@ TEST_F(SimpleParserTest, setListDefaults) {
     checkIntegerValue(third, "rebind-timer", 1800);
     checkIntegerValue(third, "renew-timer", 900);
 }
+
+// This test exercises the extractInt template
+TEST_F(SimpleParserTest, extractInt) {
+
+    SimpleParserClassTest parser;
+
+    // extractInt checks if it is an integer
+    ConstElementPtr not_int(new StringElement("xyz"));
+    EXPECT_THROW(parser.extractUint8("foo", not_int), TypeError);
+
+    // extractInt checks bounds
+    ConstElementPtr negative(new IntElement(-1));
+    EXPECT_THROW(parser.extractUint8("foo", negative), isc::OutOfRange);
+    ConstElementPtr too_large(new IntElement(1024));
+    EXPECT_THROW(parser.extractUint8("foo", too_large),isc::OutOfRange);
+
+    // checks if extractInt can return the expected value
+    ConstElementPtr hundred(new IntElement(100));
+    uint8_t val = 0;
+    EXPECT_NO_THROW(val = parser.extractUint8("foo", hundred));
+    EXPECT_EQ(100, val);
+}