namespace flex_option {
const SimpleKeywords FlexOptionImpl::OPTION_PARAMETERS = {
- { "code", Element::integer },
- { "name", Element::string },
- { "space", Element::string },
- { "csv-format", Element::boolean },
- { "add", Element::string },
- { "supersede", Element::string },
- { "remove", Element::string },
- { "client-class", Element::string },
- { "comment", Element::string }
+ { "code", Element::integer },
+ { "name", Element::string },
+ { "space", Element::string },
+ { "csv-format", Element::boolean },
+ { "add", Element::string },
+ { "supersede", Element::string },
+ { "remove", Element::string },
+ { "sub-options", Element::list },
+ { "client-class", Element::string },
+ { "comment", Element::string }
+};
+
+const SimpleKeywords FlexOptionImpl::SUB_OPTION_PARAMETERS = {
+ { "code", Element::integer },
+ { "name", Element::string },
+ { "space", Element::string },
+ { "csv-format", Element::boolean },
+ { "add", Element::string },
+ { "supersede", Element::string },
+ { "remove", Element::string },
+ { "container-add", Element::boolean },
+ { "container-remove", Element::boolean },
+ { "client-class", Element::string },
+ { "comment", Element::string }
};
FlexOptionImpl::OptionConfig::OptionConfig(uint16_t code,
FlexOptionImpl::OptionConfig::~OptionConfig() {
}
+FlexOptionImpl::SubOptionConfig::SubOptionConfig(uint16_t code,
+ OptionDefinitionPtr def,
+ OptionConfigPtr container)
+ : OptionConfig(code, def), container_(container), vendor_id_(0),
+ container_action_(NONE) {
+ if (!container) {
+ isc_throw(Unexpected, "null container?");
+ }
+}
+
+FlexOptionImpl::SubOptionConfig::~SubOptionConfig() {
+ container_.reset();
+}
+
FlexOptionImpl::FlexOptionImpl() {
}
FlexOptionImpl::~FlexOptionImpl() {
+ sub_option_config_map_.clear();
option_config_map_.clear();
}
void
FlexOptionImpl::logAction(Action action, uint16_t code,
const string& value) const {
- if (action == NONE) {
+ if ((action == NONE) || (action == SUB_OPTIONS)) {
return;
}
if (action == REMOVE) {
/// - add (if not already existing)
/// - supersede (as add but also when already existing)
/// - remove
+ /// - sub-options
enum Action {
NONE,
ADD,
SUPERSEDE,
- REMOVE
+ REMOVE,
+ SUB_OPTIONS
};
- /// @brief Option configuration.
+ /// @brief Base option configuration.
///
/// Per option configuration.
class OptionConfig {
/// @brief The type of the option config map.
typedef std::map<uint16_t, OptionConfigList> OptionConfigMap;
+ /// @brief Sub-option configuration.
+ ///
+ /// Per sub-option configuration.
+ class SubOptionConfig : public OptionConfig {
+ public:
+ /// @brief Constructor.
+ ///
+ /// @param code the sub-option code.
+ /// @param def the sub-option definition.
+ /// @param container pointer to the container option.
+ SubOptionConfig(uint16_t code, isc::dhcp::OptionDefinitionPtr def,
+ OptionConfigPtr container);
+
+ /// @brief Destructor.
+ virtual ~SubOptionConfig();
+
+ /// @brief Set vendor id.
+ ///
+ /// @param vendor_id the vendor id.
+ void setVendorId(uint32_t vendor_id) {
+ vendor_id_ = vendor_id;
+ }
+
+ /// @brief Return vendor id.
+ ///
+ /// @return vendor id.
+ uint32_t getVendorId() const {
+ return (vendor_id_);
+ }
+
+ /// @brief Return container code.
+ ///
+ /// @return container code.
+ uint16_t getContainerCode() const {
+ return (container_->getCode());
+ }
+
+ /// @brief Return container definition.
+ ///
+ /// @return container definition.
+ isc::dhcp::OptionDefinitionPtr getContainerDef() const {
+ return (container_->getOptionDef());
+ }
+
+ /// @brief Set action on the container.
+ ///
+ /// @param action the action.
+ void setContainerAction(Action action) {
+ container_action_ = action;
+ }
+
+ /// @brief Return action on the container.
+ ///
+ /// @return action on the container.
+ Action getContainerAction() const {
+ return (container_action_);
+ }
+
+ private:
+ /// @brief Pointer to the container option configuration.
+ OptionConfigPtr container_;
+
+ /// @brief Vendor id (0 when the container is not a vendor one).
+ uint32_t vendor_id_;
+
+ /// @brief The action on the container.
+ Action container_action_;
+ };
+
+ /// @brief The type of shared pointers to sub-option config.
+ typedef boost::shared_ptr<SubOptionConfig> SubOptionConfigPtr;
+
+ /// @brief The type of the sub-option config map.
+ /// @note the index is the sub-option code.
+ typedef std::map<uint16_t, SubOptionConfigPtr> SubOptionConfigMap;
+
+ /// @brief The type of the map of sub-option config maps.
+ /// @note the index is the container option code.
+ typedef std::map<uint16_t, SubOptionConfigMap> SubOptionConfigMapMap;
+
/// @brief Constructor.
FlexOptionImpl();
}
logAction(REMOVE, opt_cfg->getCode(), "");
break;
+ case SUB_OPTIONS:
+ /////// todo!
+ logAction(SUB_OPTIONS, opt_cfg->getCode(), "");
+ break;
}
}
}
/// @brief Option parameters.
static const data::SimpleKeywords OPTION_PARAMETERS;
+ /// @brief Sub-option parameters.
+ static const data::SimpleKeywords SUB_OPTION_PARAMETERS;
+
/// @brief The option config map (code and pointer to option config).
OptionConfigMap option_config_map_;
+ /// @brief The sub-option config map of map.
+ SubOptionConfigMapMap sub_option_config_map_;
+
/// @brief Parse an option config.
///
/// @param option The element with option config.