Browse Source

[5023] Implementation in progress

Tomek Mrugalski 8 years ago
parent
commit
690527d3e8

+ 8 - 1
src/bin/dhcp6/json_config_parser.cc

@@ -187,7 +187,8 @@ public:
                                                                                options_,
                                                                                options_,
                                                                                AF_INET6));
                                                                                AF_INET6));
                 parser = option_parser;
                 parser = option_parser;
-
+            } else if (entry == "user-context") {
+                user_context_ = param.second;
             } else {
             } else {
                 isc_throw(DhcpConfigError, "unsupported parameter: " << entry
                 isc_throw(DhcpConfigError, "unsupported parameter: " << entry
                           << " (" << param.second->getPosition() << ")");
                           << " (" << param.second->getPosition() << ")");
@@ -216,6 +217,10 @@ public:
             isc_throw(isc::dhcp::DhcpConfigError, ex.what()
             isc_throw(isc::dhcp::DhcpConfigError, ex.what()
                       << " (" << pd_pool_->getPosition() << ")");
                       << " (" << pd_pool_->getPosition() << ")");
         }
         }
+
+        if (user_context_) {
+            pool_->setUserContext(user_context_);
+        }
     }
     }
 
 
     // @brief Commits the constructed local pool to the pool storage.
     // @brief Commits the constructed local pool to the pool storage.
@@ -242,6 +247,8 @@ protected:
 
 
     /// A storage for pool specific option values.
     /// A storage for pool specific option values.
     CfgOptionPtr options_;
     CfgOptionPtr options_;
+
+    isc::data::ConstElementPtr user_context_;
 };
 };
 
 
 /// @brief Parser for a list of prefix delegation pools.
 /// @brief Parser for a list of prefix delegation pools.

+ 59 - 0
src/bin/dhcp6/tests/config_parser_unittest.cc

@@ -55,6 +55,42 @@ using namespace std;
 
 
 namespace {
 namespace {
 
 
+const char* PARSER_CONFIGS[] = {
+    // CONFIGURATION 0:
+    // - basic timers, one subnet
+    "{"
+    "    \"inerfaces-config\": {"
+    "        \"interfaces\": [\"*\" ]"
+    "    },"
+    "    \"valid-lifetime\": 4000,"
+    "    \"rebind-timer\": 2000,"
+    "    \"renew-timer\": 1000,"
+    "    \"subnet6\": [ {"
+    "        \"pools\": [ "
+    "            { \"pool\":  \"2001:db8::/64\" }"
+    "        ],"
+    "        \"subnet\": \"2001:db8::/32\""
+    "     } ]"
+    "}",
+    "{"
+    "    \"inerfaces-config\": {"
+    "        \"interfaces\": [\"*\" ]"
+    "    },"
+    "    \"valid-lifetime\": 4000,"
+    "    \"rebind-timer\": 2000,"
+    "    \"renew-timer\": 1000,"
+    "    \"subnet6\": [ {"
+    "        \"pools\": [ "
+    "            { \"pool\":  \"2001:db8::/64\","
+    "                \"user-context\": {"
+    "                }"
+    "            }"
+    "        ],"
+    "        \"subnet\": \"2001:db8::/32\""
+    "     } ]"
+    "}"
+};
+
 std::string specfile(const std::string& name) {
 std::string specfile(const std::string& name) {
     return (std::string(DHCP6_SRC_DIR) + "/" + name);
     return (std::string(DHCP6_SRC_DIR) + "/" + name);
 }
 }
@@ -4518,4 +4554,27 @@ TEST_F(Dhcp6ParserTest, invalidClientClassDictionary) {
     checkResult(status, 1);
     checkResult(status, 1);
 }
 }
 
 
+TEST_F(Dhcp6ParserTest, PdPoolUserContextEmpty) {
+
+    ConstElementPtr status;
+    ElementPtr json = Element::fromJSON(string(PARSER_CONFIGS[0]));
+
+    EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
+    ASSERT_TRUE(status);
+    checkResult(status, 1);
+
+    ConstCfgSubnets6Ptr subnets6 = CfgMgr::instance().getStagingCfg()->getCfgSubnets6();
+    ASSERT_TRUE(subnets6);
+
+    const Subnet6Collection* subnets = subnets6->getAll();
+    ASSERT_TRUE(subnets);
+
+    ASSERT_EQ(1, subnets->size());
+
+    const PoolCollection pools = subnets->at(0)->getPools(Lease::TYPE_NA);
+    ASSERT_EQ(1, pools.size());
+    
+        
+}
+
 };
 };

+ 6 - 0
src/lib/dhcpsrv/parsers/dhcp_parsers.cc

@@ -1144,6 +1144,12 @@ PoolParser::build(ConstElementPtr pool_structure) {
                       << " (" << option_data->getPosition() << ")");
                       << " (" << option_data->getPosition() << ")");
         }
         }
     }
     }
+
+    user_context_ = pool_structure->get("user-context");
+    if (user_context_ && user_context_->getType() != Element::map) {
+        isc_throw(isc::dhcp::DhcpConfigError, "User context has to be a map ("
+                  << user_context_->getPosition() << ")");
+    }
 }
 }
 
 
 void
 void

+ 3 - 0
src/lib/dhcpsrv/parsers/dhcp_parsers.h

@@ -885,6 +885,9 @@ protected:
     /// A storage for pool specific option values.
     /// A storage for pool specific option values.
     CfgOptionPtr options_;
     CfgOptionPtr options_;
 
 
+    /// A storage for user context.
+    isc::data::ConstElementPtr user_context_;
+
     /// @brief Address family: AF_INET (for DHCPv4) or AF_INET6 for DHCPv6.
     /// @brief Address family: AF_INET (for DHCPv4) or AF_INET6 for DHCPv6.
     uint16_t address_family_;
     uint16_t address_family_;
 };
 };

+ 15 - 0
src/lib/dhcpsrv/pool.h

@@ -9,6 +9,7 @@
 
 
 #include <asiolink/io_address.h>
 #include <asiolink/io_address.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/shared_ptr.hpp>
+#include <cc/data.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease.h>
 
 
@@ -92,6 +93,17 @@ public:
         return (cfg_option_);
         return (cfg_option_);
     }
     }
 
 
+    /// @brief Returns const pointer to the user context.
+    data::ConstElementPtr getContext() const {
+        return (user_context_);
+    }
+
+    /// @brief Sets user context.
+    /// @param ctx user context to be stored.
+    void setUserContext(const data::ConstElementPtr& ctx) {
+        user_context_ = ctx;
+    }
+
 protected:
 protected:
 
 
     /// @brief protected constructor
     /// @brief protected constructor
@@ -144,6 +156,9 @@ protected:
 
 
     /// @brief Pointer to the option data configuration for this pool.
     /// @brief Pointer to the option data configuration for this pool.
     CfgOptionPtr cfg_option_;
     CfgOptionPtr cfg_option_;
+
+    /// @brief Pointer to the user context (may be NULL)
+    data::ConstElementPtr user_context_;
 };
 };
 
 
 /// @brief Pool information for IPv4 addresses
 /// @brief Pool information for IPv4 addresses