From: Francis Dupont Date: Wed, 18 Jan 2017 00:08:28 +0000 (+0100) Subject: [5097] Added an unit test and 2 examples X-Git-Tag: trac5119_base~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdac736eb48c02fede0138631d937299a80079db;p=thirdparty%2Fkea.git [5097] Added an unit test and 2 examples --- diff --git a/doc/examples/kea6/hooks.json b/doc/examples/kea6/hooks.json index c4039b845d..23a403514f 100644 --- a/doc/examples/kea6/hooks.json +++ b/doc/examples/kea6/hooks.json @@ -24,7 +24,11 @@ # 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" } diff --git a/doc/examples/kea6/multiple-options.json b/doc/examples/kea6/multiple-options.json index b0d2cf1be3..45b249dd7e 100644 --- a/doc/examples/kea6/multiple-options.json +++ b/doc/examples/kea6/multiple-options.json @@ -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": [ @@ -65,6 +67,19 @@ "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" } diff --git a/src/lib/cc/simple_parser.h b/src/lib/cc/simple_parser.h index cfcf82bc64..1a3a500f8d 100644 --- a/src/lib/cc/simple_parser.h +++ b/src/lib/cc/simple_parser.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace isc { namespace data { diff --git a/src/lib/cc/tests/simple_parser_unittest.cc b/src/lib/cc/tests/simple_parser_unittest.cc index d61f557d07..aa0ccdf81b 100644 --- a/src/lib/cc/tests/simple_parser_unittest.cc +++ b/src/lib/cc/tests/simple_parser_unittest.cc @@ -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 #include #include @@ -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(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); +}