options_,
AF_INET6));
parser = option_parser;
-
+ } else if (entry == "user-context") {
+ user_context_ = param.second;
} else {
isc_throw(DhcpConfigError, "unsupported parameter: " << entry
<< " (" << param.second->getPosition() << ")");
isc_throw(isc::dhcp::DhcpConfigError, ex.what()
<< " (" << pd_pool_->getPosition() << ")");
}
+
+ if (user_context_) {
+ pool_->setUserContext(user_context_);
+ }
}
// @brief Commits the constructed local pool to the pool storage.
/// A storage for pool specific option values.
CfgOptionPtr options_;
+
+ isc::data::ConstElementPtr user_context_;
};
/// @brief Parser for a list of prefix delegation pools.
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) {
return (std::string(DHCP6_SRC_DIR) + "/" + name);
}
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());
+
+
+}
+
};
<< " (" << 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
/// A storage for pool specific option values.
CfgOptionPtr options_;
+ /// A storage for user context.
+ isc::data::ConstElementPtr user_context_;
+
/// @brief Address family: AF_INET (for DHCPv4) or AF_INET6 for DHCPv6.
uint16_t address_family_;
};
#include <asiolink/io_address.h>
#include <boost/shared_ptr.hpp>
+#include <cc/data.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/lease.h>
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:
/// @brief protected constructor
/// @brief Pointer to the option data configuration for this pool.
CfgOptionPtr cfg_option_;
+
+ /// @brief Pointer to the user context (may be NULL)
+ data::ConstElementPtr user_context_;
};
/// @brief Pool information for IPv4 addresses