// Static container with DHCPv6 option definitions.
OptionDefContainerPtr LibDHCP::v6option_defs_(new OptionDefContainer());
+// Static container with option definitions grouped by option space.
+OptionDefContainers LibDHCP::option_defs_;
+
+// Static container with vendor option definitions for DHCPv4.
VendorOptionDefContainers LibDHCP::vendor4_defs_;
+// Static container with vendor option definitions for DHCPv6.
VendorOptionDefContainers LibDHCP::vendor6_defs_;
// Static container with option definitions created in runtime.
}
}
+const OptionDefContainerPtr&
+LibDHCP::getOptionDefs(const std::string& space) {
+ if (space == DHCP4_OPTION_SPACE) {
+ return (getOptionDefs(Option::V4));
+
+ } else if (space == DHCP6_OPTION_SPACE) {
+ return (getOptionDefs(Option::V6));
+ }
+
+ OptionDefContainers::const_iterator container = option_defs_.find(space);
+ if (container != option_defs_.end()) {
+ return (container->second);
+ }
+ return (null_option_def_container_);
+}
+
const OptionDefContainerPtr&
LibDHCP::getVendorOption4Defs(const uint32_t vendor_id) {
void
LibDHCP::initStdOptionDefs4() {
- initOptionSpace(v4option_defs_, OPTION_DEF_PARAMS4, OPTION_DEF_PARAMS_SIZE4);
+ initOptionSpace(v4option_defs_, STANDARD_V4_OPTION_DEFINITIONS,
+ STANDARD_V4_OPTION_DEFINITIONS_SIZE);
}
void
LibDHCP::initStdOptionDefs6() {
- initOptionSpace(v6option_defs_, OPTION_DEF_PARAMS6, OPTION_DEF_PARAMS_SIZE6);
+ initOptionSpace(v6option_defs_, STANDARD_V6_OPTION_DEFINITIONS,
+ STANDARD_V6_OPTION_DEFINITIONS_SIZE);
+ initOptionSpace(option_defs_[MAPE_V6_OPTION_SPACE], MAPE_V6_OPTION_DEFINITIONS,
+ MAPE_V6_OPTION_DEFINITIONS_SIZE);
+ initOptionSpace(option_defs_[MAPT_V6_OPTION_SPACE], MAPT_V6_OPTION_DEFINITIONS,
+ MAPT_V6_OPTION_DEFINITIONS_SIZE);
+ initOptionSpace(option_defs_[LW_V6_OPTION_SPACE], LW_V6_OPTION_DEFINITIONS,
+ LW_V6_OPTION_DEFINITIONS_SIZE);
+ initOptionSpace(option_defs_[V4V6_RULE_OPTION_SPACE], V4V6_RULE_OPTION_DEFINITIONS,
+ V4V6_RULE_OPTION_DEFINITIONS_SIZE);
+ initOptionSpace(option_defs_[V4V6_BIND_OPTION_SPACE], V4V6_BIND_OPTION_DEFINITIONS,
+ V4V6_BIND_OPTION_DEFINITIONS_SIZE);
}
void
LibDHCP::initVendorOptsDocsis4() {
- initOptionSpace(vendor4_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V4_DEFS, DOCSIS3_V4_DEFS_SIZE);
+ initOptionSpace(vendor4_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V4_DEFS,
+ DOCSIS3_V4_DEFS_SIZE);
}
void
LibDHCP::initVendorOptsDocsis6() {
- initOptionSpace(vendor6_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V6_DEFS, DOCSIS3_V6_DEFS_SIZE);
+ initOptionSpace(vendor6_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V6_DEFS,
+ DOCSIS3_V6_DEFS_SIZE);
}
void
LibDHCP::initVendorOptsIsc6() {
- initOptionSpace(vendor6_defs_[ENTERPRISE_ID_ISC], ISC_V6_DEFS, ISC_V6_DEFS_SIZE);
+ initOptionSpace(vendor6_defs_[ENTERPRISE_ID_ISC], ISC_V6_OPTION_DEFINITIONS,
+ ISC_V6_OPTION_DEFINITIONS_SIZE);
}
uint32_t
/// @return Pointer to a collection of option definitions.
static const OptionDefContainerPtr& getOptionDefs(const Option::Universe u);
+ /// @brief Returns collection of option definitions.
+ ///
+ /// This method returns a collection of option definitions for a specified
+ /// option space.
+ ///
+ /// @param space Option space.
+ ///
+ /// @return Pointer to a collection of option definitions.
+ static const OptionDefContainerPtr& getOptionDefs(const std::string& space);
+
/// @brief Return the first option definition matching a
/// particular option code.
///
/// Container with DHCPv6 option definitions.
static OptionDefContainerPtr v6option_defs_;
+ /// Container that holds option definitions for various option spaces.
+ static OptionDefContainers option_defs_;
+
/// Container for v4 vendor option definitions
static VendorOptionDefContainers vendor4_defs_;
#include <boost/multi_index_container.hpp>
#include <boost/shared_ptr.hpp>
#include <map>
+#include <string>
namespace isc {
namespace dhcp {
/// Pointer to an option definition container.
typedef boost::shared_ptr<OptionDefContainer> OptionDefContainerPtr;
+/// Container that holds option definitions for various option spaces.
+typedef std::map<std::string, OptionDefContainerPtr> OptionDefContainers;
+
/// Container that holds various vendor option containers
typedef std::map<uint32_t, OptionDefContainerPtr> VendorOptionDefContainers;
-// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2016 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
#define DOCSIS3_V4_OPTION_SPACE "docsis3_v4"
#define DOCSIS3_V6_OPTION_SPACE "docsis3_v6"
#define ISC_V6_OPTION_SPACE "4o6"
-#define MAPE_V6_OPTION_SPACE "4over6-mape"
-#define MAPT_V6_OPTION_SPACE "4over6-mapt"
-#define LW_V6_OPTION_SPACE "4over6-lw"
-#define V4V6_RULE_OPTION_SPACE "v4v6rule"
-#define V4V6_BIND_OPTION_SPACE "v4v6bind"
+#define MAPE_V6_OPTION_SPACE "s46-cont-mape-options"
+#define MAPT_V6_OPTION_SPACE "s46-cont-mapt-options"
+#define LW_V6_OPTION_SPACE "s46-cont-lw-options"
+#define V4V6_RULE_OPTION_SPACE "s46-rule-options"
+#define V4V6_BIND_OPTION_SPACE "s46-v4v6bind-options"
namespace isc {
namespace dhcp {
RECORD_DECL(REMOTE_ID_RECORDS, OPT_UINT32_TYPE, OPT_BINARY_TYPE);
// s46-rule
RECORD_DECL(S46_RULE, OPT_UINT8_TYPE, OPT_UINT8_TYPE, OPT_UINT8_TYPE,
- OPT_IPV4_ADDRESS_TYPE, OPT_IPV6_PREFIX_TYPE);
+ OPT_IPV4_ADDRESS_TYPE, OPT_IPV6_PREFIX_TYPE);
// s46-v4v6bind
RECORD_DECL(S46_V4V6BIND, OPT_IPV4_ADDRESS_TYPE, OPT_IPV6_PREFIX_TYPE);
// s46-portparams
sizeof(ISC_V6_OPTION_DEFINITIONS[0]);
/// @brief MAPE option definitions
-/// @todo: Maybe move this to a separate file, e.g. mape_option_defs.h
const OptionDefParams MAPE_V6_OPTION_DEFINITIONS[] = {
OPTION_DEF_PARAMS_S46_BR,
OPTION_DEF_PARAMS_S46_RULE
sizeof(MAPE_V6_OPTION_DEFINITIONS[0]);
/// @brief MAPT option definitions
-/// @todo: Maybe move this to a separate file, e.g. mapt_option_defs.h
const OptionDefParams MAPT_V6_OPTION_DEFINITIONS[] = {
OPTION_DEF_PARAMS_S46_RULE,
{ "s46-dmr", D6O_S46_DMR, OPT_IPV6_PREFIX_TYPE, false, NO_RECORD_DEF, "" }
sizeof(MAPT_V6_OPTION_DEFINITIONS[0]);
/// @brief LW option definitions
-/// @todo: Maybe move this to a separate file, e.g. lw_option_defs.h
const OptionDefParams LW_V6_OPTION_DEFINITIONS[] = {
OPTION_DEF_PARAMS_S46_BR,
{ "s46-v4v6bind", D6O_S46_V4V6BIND, OPT_RECORD_TYPE, false,
sizeof(LW_V6_OPTION_DEFINITIONS[0]);
/// @brief Rule option definitions
-/// @todo: Maybe move this to a separate file, e.g. rule_option_defs.h
const OptionDefParams V4V6_RULE_OPTION_DEFINITIONS[] = {
OPTION_DEF_PARAMS_S46_PORTPARAMS
};
sizeof(V4V6_RULE_OPTION_DEFINITIONS[0]);
/// @brief Bind option definitions
-/// @todo: Maybe move this to a separate file, e.g. bind_option_defs.h
const OptionDefParams V4V6_BIND_OPTION_DEFINITIONS[] = {
OPTION_DEF_PARAMS_S46_PORTPARAMS
};
const std::type_info& expected_type,
const std::string& encapsulates = "") {
// Use V4 universe.
- testStdOptionDefs(Option::V4, code, begin, end, expected_type,
- encapsulates);
+ testStdOptionDefs(Option::V4, DHCP4_OPTION_SPACE, code, begin, end,
+ expected_type, encapsulates);
}
/// @brief Test DHCPv6 option definition.
const std::type_info& expected_type,
const std::string& encapsulates = "") {
// Use V6 universe.
- testStdOptionDefs(Option::V6, code, begin, end, expected_type,
- encapsulates);
+ testStdOptionDefs(Option::V6, DHCP6_OPTION_SPACE, code, begin,
+ end, expected_type, encapsulates);
+ }
+
+ /// @brief Test DHCPv6 option definition in a given option space.
+ ///
+ /// This function tests if option definition for an option from a
+ /// given option space has been initialized correctly.
+ ///
+ /// @param option_space option space.
+ /// @param code option code.
+ /// @param begin iterator pointing at beginning of a buffer to
+ /// be used to create option instance.
+ /// @param end iterator pointing at end of a buffer to be
+ /// used to create option instance.
+ /// @param expected_type type of the option created by the
+ /// factory function returned by the option definition.
+ /// @param encapsulates name of the option space being encapsulated
+ /// by the option.
+ static void testOptionDefs6(const std::string& option_space,
+ const uint16_t code,
+ const OptionBufferConstIter begin,
+ const OptionBufferConstIter end,
+ const std::type_info& expected_type,
+ const std::string& encapsulates = "") {
+ testStdOptionDefs(Option::V6, option_space, code, begin,
+ end, expected_type, encapsulates);
}
/// @brief Create a sample DHCPv4 option 43 with suboptions.
/// This function tests if option definition for standard
/// option has been initialized correctly.
///
+ /// @param option_space option space.
/// @param code option code.
/// @param begin iterator pointing at beginning of a buffer to
/// be used to create option instance.
/// factory function returned by the option definition.
/// @param encapsulates name of the option space being encapsulated
/// by the option.
- static void testStdOptionDefs(const Option::Universe u,
+ static void testStdOptionDefs(const Option::Universe& u,
+ const std::string& option_space,
const uint16_t code,
const OptionBufferConstIter begin,
const OptionBufferConstIter end,
// the definition for a particular option code.
// We don't have to initialize option definitions here because they
// are initialized in the class's constructor.
- OptionDefContainerPtr options = LibDHCP::getOptionDefs(u);
+ OptionDefContainerPtr options = LibDHCP::getOptionDefs(option_space);
// Get the container index #1. This one allows for searching
// option definitions using option code.
const OptionDefContainerTypeIndex& idx = options->get<1>();
LibDhcpTest::testStdOptionDefs6(D6O_TIMESTAMP, begin, begin + 8,
typeid(Option));
+
+ // RFC7598 options
+ LibDhcpTest::testOptionDefs6(MAPE_V6_OPTION_SPACE, D6O_S46_RULE, begin, end,
+ typeid(OptionCustom), "s46-rule-options");
+ LibDhcpTest::testOptionDefs6(MAPT_V6_OPTION_SPACE, D6O_S46_RULE, begin, end,
+ typeid(OptionCustom), "s46-rule-options");
+ LibDhcpTest::testOptionDefs6(MAPE_V6_OPTION_SPACE, D6O_S46_BR, begin, end,
+ typeid(OptionCustom));
+ LibDhcpTest::testOptionDefs6(LW_V6_OPTION_SPACE, D6O_S46_BR, begin, end,
+ typeid(OptionCustom));
+ LibDhcpTest::testOptionDefs6(MAPT_V6_OPTION_SPACE, D6O_S46_DMR, begin, end,
+ typeid(OptionCustom));
+ LibDhcpTest::testOptionDefs6(LW_V6_OPTION_SPACE, D6O_S46_V4V6BIND, begin,
+ end, typeid(OptionCustom),
+ "s46-v4v6bind-options");
+ LibDhcpTest::testOptionDefs6(V4V6_RULE_OPTION_SPACE, D6O_S46_PORTPARAMS,
+ begin, end, typeid(OptionCustom), "");
+ LibDhcpTest::testStdOptionDefs6(D6O_S46_CONT_MAPE, begin, end,
+ typeid(OptionCustom),
+ "s46-cont-mape-options");
+ LibDhcpTest::testStdOptionDefs6(D6O_S46_CONT_MAPT, begin, end,
+ typeid(OptionCustom),
+ "s46-cont-mapt-options");
+ LibDhcpTest::testStdOptionDefs6(D6O_S46_CONT_LW, begin, end,
+ typeid(OptionCustom),
+ "s46-cont-lw-options");
+
}
// This test checks if the DHCPv6 option definition can be searched by