Parcourir la source

[3151] Addressed review comments.

Added additional unit tests, a starter section to
the user's guide for b10-dhcp6 prefix delegation
configuration and various cleanup.
Thomas Markwalder il y a 11 ans
Parent
commit
b5f8586097

+ 21 - 0
doc/guide/bind10-guide.xml

@@ -4725,6 +4725,27 @@ Dhcp6/subnet6/	list
       </para>
     </section>
 
+    <section>
+<!-- @todo: add real meat to the prefix delegation config this is just place holder stuff -->
+      <title>Subnet and Prefix Delegation Pools</title>
+      <para>
+        Subnets may also be configured to delegate address prefixes....
+        A subnet may have one or more prefix delegation pools.  Each pool has
+        a prefixed address, which is specified as a prefix and a prefix length,
+        as well as a delegated prefix length.  A sample configuration is shown
+        below:
+      <screen>
+&gt; <userinput>config add Dhcp6/subnet6</userinput>
+&gt; <userinput>config set Dhcp6/subnet6[0]/subnet "2001:db8:1::/64"</userinput>
+&gt; <userinput>config show Dhcp6/subnet6[0]</userinput>
+&gt; <userinput>config add Dhcp6/subnet6[0]/pd-pools</userinput>
+&gt; <userinput>config set Dhcp6/subnet6[0]/pd-pools[0]/prefix "2001:db8:1::"</userinput>
+&gt; <userinput>config set Dhcp6/subnet6[0]/pd-pools[0]/prefix-len 64</userinput>
+&gt; <userinput>config set Dhcp6/subnet6[0]/pd-pools[0]/delegated-len 96</userinput>
+&gt; <userinput>config commit</userinput></screen>
+      </para>
+    </section>
+
     <section id="dhcp6-std-options">
       <title>Standard DHCPv6 options</title>
       <para>

+ 15 - 0
src/bin/dhcp6/config_parser.cc

@@ -166,6 +166,21 @@ protected:
     }
 };
 
+/// @brief Parser for IPv6 prefix delegation definitions.
+///
+/// This class handles prefix delegation pool definitions for IPv6 subnets
+/// Pool6 objects are created and stored in the given PoolStorage container.
+///
+/// PdPool defintions currently support three elements: prefix, prefix-len,
+/// and delegated-len, as shown in the example JSON text below:
+///
+/// {{{
+///
+/// {
+///     "prefix": "2001:db8:1::",
+///     "prefix-len": 64,
+///     "delegated-len": 128
+/// }
 class PdPoolParser : public DhcpConfigParser {
 public:
 

+ 79 - 1
src/bin/dhcp6/tests/config_parser_unittest.cc

@@ -22,6 +22,7 @@
 #include <dhcp/option_int.h>
 #include <dhcp6/config_parser.h>
 #include <dhcp6/dhcp6_srv.h>
+#include <dhcpsrv/addr_utilities.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/subnet.h>
 #include <hooks/hooks_manager.h>
@@ -694,6 +695,8 @@ TEST_F(Dhcp6ParserTest, poolOutOfSubnet) {
 // Goal of this test is to verify if pools can be defined
 // using prefix/length notation. There is no separate test for min-max
 // notation as it was tested in several previous tests.
+// Note this test also verifies that subnets can be configured without
+// prefix delegation pools.
 TEST_F(Dhcp6ParserTest, poolPrefixLen) {
 
     ConstElementPtr x;
@@ -775,9 +778,18 @@ TEST_F(Dhcp6ParserTest, pdPoolBasics) {
     ASSERT_TRUE(p6);
     EXPECT_EQ("2001:db8:1::", p6->getFirstAddress().toText());
     EXPECT_EQ(128, p6->getLength());
+
+    // prefix-len is not directly accessible after pool construction, so
+    // verify that it was interpreted correctly by checking the last address
+    // value.
+    isc::asiolink::IOAddress prefixAddress("2001:db8:1::");
+    EXPECT_EQ(lastAddrInPrefix(prefixAddress, 64).toText(),
+              p6->getLastAddress().toText());
 }
 
 // Goal of this test is verify that a list of PD pools can be configured.
+// It also verifies that a subnet may be configured with both regular pools
+// and pd pools.
 TEST_F(Dhcp6ParserTest, pdPoolList) {
 
     ConstElementPtr x;
@@ -794,6 +806,7 @@ TEST_F(Dhcp6ParserTest, pdPoolList) {
         "\"rebind-timer\": 2000, "
         "\"renew-timer\": 1000, "
         "\"subnet6\": [ { "
+        "    \"pool\": [ \"2001:db8:1:04::/80\" ],"
         "    \"subnet\": \"2001:db8:1::/40\","
         "    \"pd-pools\": ["
         "        { \"prefix\": \"2001:db8:1:01::\", "
@@ -829,8 +842,12 @@ TEST_F(Dhcp6ParserTest, pdPoolList) {
                         instance().getSubnet6(IOAddress("2001:db8:1::5"));
     ASSERT_TRUE(subnet);
 
-    // Fetch the collection of PD pools.  It should have 3 entries.
+    // Fetch the collection of NA pools.  It should have 1 entry.
     PoolCollection pc;
+    ASSERT_NO_THROW(pc = subnet->getPools(Lease::TYPE_NA));
+    EXPECT_EQ(1, pc.size());
+
+    // Fetch the collection of PD pools.  It should have 3 entries.
     ASSERT_NO_THROW(pc = subnet->getPools(Lease::TYPE_PD));
     EXPECT_EQ(3, pc.size());
 
@@ -844,6 +861,67 @@ TEST_F(Dhcp6ParserTest, pdPoolList) {
     }
 }
 
+// Goal of this test is to verify the a whole prefix can be delegated and that
+// a whole subnet can be delegated.
+TEST_F(Dhcp6ParserTest, subnetAndPrefixDelegated) {
+
+    ConstElementPtr x;
+
+    // Define a single valid pd pool.
+    string config =
+        "{ \"interfaces\": [ \"*\" ],"
+        "\"preferred-lifetime\": 3000,"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, "
+        "\"subnet6\": [ { "
+        "    \"subnet\": \"2001:db8:1::/64\","
+        "    \"pd-pools\": ["
+        "        { \"prefix\": \"2001:db8:1::\", "
+        "          \"prefix-len\": 64, "
+        "          \"delegated-len\": 64"
+        "        } ],"
+        "\"valid-lifetime\": 4000 }"
+        "] }";
+
+    // Convert the JSON string into Elements.
+    ElementPtr json;
+    ASSERT_NO_THROW(json = Element::fromJSON(config));
+
+    // Verify that DHCP6 configuration processing succeeds.
+    // Returned value must be non-empty ConstElementPtr to config result.
+    // rcode should be 0 which indicates successful configuration processing.
+    EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
+    ASSERT_TRUE(x);
+    comment_ = parseAnswer(rcode_, x);
+    EXPECT_EQ(0, rcode_);
+
+    // Test that we can retrieve the subnet.
+    Subnet6Ptr subnet = CfgMgr::
+                        instance().getSubnet6(IOAddress("2001:db8:1::5"));
+
+    ASSERT_TRUE(subnet);
+
+    // Fetch the collection of PD pools.  It should have 1 entry.
+    PoolCollection pc;
+    ASSERT_NO_THROW(pc = subnet->getPools(Lease::TYPE_PD));
+    EXPECT_EQ(1, pc.size());
+
+    // Get a pointer to the pd pool instance, and verify its contents.
+    Pool6Ptr p6;
+    ASSERT_NO_THROW(p6 = boost::dynamic_pointer_cast<Pool6>(pc[0]));
+    ASSERT_TRUE(p6);
+    EXPECT_EQ("2001:db8:1::", p6->getFirstAddress().toText());
+    EXPECT_EQ(64, p6->getLength());
+
+    // prefix-len is not directly accessible after pool construction, so
+    // verify that it was interpreted correctly by checking the last address
+    // value.
+    isc::asiolink::IOAddress prefixAddress("2001:db8:1::");
+    EXPECT_EQ(lastAddrInPrefix(prefixAddress, 64).toText(),
+              p6->getLastAddress().toText());
+}
+
+
 // Goal of this test is check for proper handling of invalid prefix delegation
 // pool configuration.  It uses an array of invalid configurations to check
 // a variety of configuration errors.

+ 7 - 1
src/bin/dhcp6/tests/test_data_files_config.h.in

@@ -1,4 +1,4 @@
-// Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")   
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -14,4 +14,10 @@
 
 /// @brief Path to DHCP6 source dir so tests against the dhcp6.spec file
 /// can find it reliably.
+
+#ifndef TEST_DATA_FILES_CONFIG_H
+#define TEST_DATA_FILES_CONFIG_H
+
 #define DHCP6_SRC_DIR "@abs_top_srcdir@/src/bin/dhcp6"
+
+#endif