14#include <boost/algorithm/string/split.hpp> 
   15#include <boost/algorithm/string/classification.hpp> 
   16#include <boost/make_shared.hpp> 
   28                         const std::string& formatted_value,
 
   30    return (boost::make_shared<OptionDescriptor>(opt, persist, cancel,
 
 
   37    return (boost::make_shared<OptionDescriptor>(persist, cancel));
 
 
   42    return (boost::make_shared<OptionDescriptor>(desc));
 
 
   59    if (!trimmed.empty()) {
 
 
   79    : encapsulated_(false) {
 
 
   84    return (options_.empty() && vendor_options_.empty());
 
 
   89    return (options_.equals(other.options_) &&
 
   90            vendor_options_.equals(other.vendor_options_));
 
 
   95               const bool persistent,
 
   97               const std::string& option_space,
 
  103    add(desc, option_space);
 
 
  113                  << option_space << 
"'");
 
  118        vendor_options_.addItem(desc, vendor_id);
 
  120        options_.addItem(desc, option_space);
 
 
  134                  << 
" does not exist");
 
  138    auto& idx6 = options->get<6>();
 
  140    if (od_itr == idx6.end()) {
 
  142                  << option_space << 
":" << desc.
option_->getType()
 
  144                  << 
", it does not exist");
 
  147    idx6.replace(od_itr, desc);
 
 
  150std::list<std::string>
 
  153    std::list<std::string> names;
 
  154    for (
auto const& 
id : ids) {
 
  155        std::ostringstream s;
 
  158        s << 
"vendor-" << id;
 
  159        names.push_back(s.str());
 
 
  191        for (
auto opt_desc : *(
getAll(space))) {
 
 
  205                  "validateCreateOption: descriptor has no option instance");
 
  209    uint16_t code = opt_desc.
option_->getType();
 
  227        def = cfg_def->get(space, code);
 
  237        if (!formatted_value.empty()) {
 
  239                      << 
" has a formatted value: '" << formatted_value
 
  240                      << 
"' but no option definition");
 
  252        if (formatted_value.empty()) {
 
  254            opt_desc.
option_ = def->optionFactory(universe, code, opt_desc.
option_->getData());
 
  257            std::vector<std::string> split_vec;
 
  258            boost::split(split_vec, formatted_value, boost::is_any_of(
","));
 
  259            opt_desc.
option_ = def->optionFactory(universe, code, split_vec);
 
  261    } 
catch (
const std::exception& ex) {
 
  263                      << 
" from data specified, reason: " << ex.what());
 
 
  273    mergeInternal(options_, other.options_);
 
  275    mergeInternal(vendor_options_, other.vendor_options_);
 
 
  293    encapsulated_ = 
true;
 
 
  297CfgOption::encapsulateInternal(
const std::string& option_space) {
 
  302    for (
auto const& opt : *options) {
 
  303        encapsulateInternal(opt.option_);
 
  308CfgOption::encapsulateInternal(
const OptionPtr& option) {
 
  310    const std::string& encap_space = option->getEncapsulatedSpace();
 
  312    if (!encap_space.empty()) {
 
  318        for (
auto const& encap_opt : *encap_options) {
 
  319            if (option.get() == encap_opt.option_.get()) {
 
  325            if (!option->getOption(encap_opt.option_->getType())) {
 
  326                option->addOption(encap_opt.option_);
 
  328            encapsulateInternal(encap_opt.option_);
 
  333template <
typename Selector>
 
  340    std::list<Selector> selectors = src_container.getOptionSpaceNames();
 
  345    for (
auto const& it : selectors) {
 
  353        for (
auto const& src_opt : *src_all) {
 
  356                idx.equal_range(src_opt.option_->getType());
 
  359            if (std::distance(range.first, range.second) == 0) {
 
  360                dest_container.addItem(OptionDescriptor(src_opt), it);
 
  368    return (options_.getItems(option_space));
 
 
  373    return (vendor_options_.getItems(vendor_id));
 
 
  380        return (
getAll(vendor_id));
 
  382    return (
getAll(option_space));
 
 
  389    if (!options || options->empty()) {
 
  401        for (
auto const& option_space_from_list : option_space_names) {
 
  403            auto const& options_in_space = 
getAll(option_space_from_list);
 
  404            for (
auto const& option_it : *options_in_space) {
 
  408                if (option_it.option_ &&
 
  409                    (option_it.option_->getEncapsulatedSpace() == option_space)) {
 
  410                    option_it.option_->delOption(option_code);
 
  416    auto& idx = options->get<1>();
 
  417    return (idx.erase(option_code));
 
 
  425    if (!options || options->empty()) {
 
  437        for (
auto const& option_space_from_list : option_space_names) {
 
  439            auto const& options_in_space = 
getAll(option_space_from_list);
 
  440            for (
auto const& option_it : *options_in_space) {
 
  444                if (option_it.option_ &&
 
  445                    (option_it.option_->getEncapsulatedSpace() == option_space)) {
 
  446                    option_it.option_->delOption(option_code);
 
  452    auto& idx6 = options->get<6>();
 
  453    auto range = idx6.equal_range(boost::make_tuple(option_code, client_classes));
 
  454    auto count = std::distance(range.first, range.second);
 
  456        idx6.erase(range.first, range.second);
 
 
  466    if (!vendor_options || vendor_options->empty()) {
 
  471    auto& idx = vendor_options->get<1>();
 
  472    return (idx.erase(option_code));
 
 
  482        auto const& options = 
getAll(space_name);
 
  483        for (
auto const& option_it : *options) {
 
  484            if (!option_it.option_) {
 
  490            auto sub_options = option_it.option_->getOptions();
 
  491            for (
auto const& sub : sub_options) {
 
  493                option_it.option_->delOption(sub.second->getType());
 
  500    size_t num_deleted = options_.deleteItems(
id) + vendor_options_.deleteItems(
id);
 
  506    return (num_deleted);
 
 
  525    const std::list<std::string>& names = options_.getOptionSpaceNames();
 
  526    for (
auto const& name : names) {
 
  528        for (
auto const& opt : *opts) {
 
  532            opt.contextToElement(map);
 
  536            uint16_t code = opt.option_->getType();
 
  540            if (cfg_option_def) {
 
  541                def = cfg_option_def->get(name, code);
 
  556            if (!opt.formatted_value_.empty()) {
 
  564                std::vector<uint8_t> bin = opt.option_->toBinary();
 
  565                if (!opt.cancelled_ || !bin.empty()) {
 
  580            if (include_metadata) {
 
  581                map->set(
"metadata", opt.getMetadata());
 
  585            if (!opt.client_classes_.empty()) {
 
  586                map->set(
"client-classes", opt.client_classes_.toElement());
 
  594    const std::list<uint32_t>& ids = vendor_options_.getOptionSpaceNames();
 
  595    for (
auto const& 
id : ids) {
 
  597        for (
auto const& opt : *opts) {
 
  601            opt.contextToElement(map);
 
  603            std::ostringstream oss;
 
  604            oss << 
"vendor-" << id;
 
  607            uint16_t code = opt.option_->getType();
 
  621            if (!opt.formatted_value_.empty()) {
 
  629                std::vector<uint8_t> bin = opt.option_->toBinary();
 
  630                if (!opt.cancelled_ || !bin.empty()) {
 
  646            if (!opt.client_classes_.empty()) {
 
  647                map->set(
"client-classes", opt.client_classes_.toElement());
 
 
boost::shared_ptr< Option > OptionPtr
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
void setId(const uint64_t id)
Sets element's database identifier.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
bool isEncapsulated() const
Checks if options have been encapsulated.
OptionContainerPtr getAllCombined(const std::string &option_space) const
Returns all non-vendor or vendor options for the specified option space.
void encapsulate()
Appends encapsulated options to top-level options.
void replace(const OptionDescriptor &desc, const std::string &option_space)
Replaces the instance of an option within this collection.
static bool createDescriptorOption(CfgOptionDefPtr cfg_def, const std::string &space, OptionDescriptor &opt_desc)
Creates an option descriptor's option based on a set of option defs.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void createOptions(CfgOptionDefPtr cfg_def)
Re-create the option in each descriptor based on given definitions.
isc::data::ElementPtr toElementWithMetadata(const bool include_metadata, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr()) const
Unparse a configuration object with optionally including the metadata.
size_t del(const std::string &option_space, const uint16_t option_code)
Deletes option for the specified option space and option code.
std::list< std::string > getOptionSpaceNames() const
Returns a list of configured option space names.
bool empty() const
Indicates the object is empty.
void mergeTo(CfgOption &other) const
Merges this configuration to another configuration.
void copyTo(CfgOption &other) const
Copies this configuration to another configuration.
CfgOption()
default constructor
std::list< std::string > getVendorIdsSpaceNames() const
Returns a list of option space names for configured vendor ids.
OptionContainerPtr getAll(const std::string &option_space) const
Returns all options for the specified option space.
void merge(CfgOptionDefPtr cfg_def, CfgOption &other)
Merges another option configuration into this one.
bool equals(const CfgOption &other) const
Check if configuration is equal to other configuration.
void add(const OptionPtr &option, const bool persistent, const bool cancelled, const std::string &option_space, const uint64_t id=0)
Adds instance of the option to the configuration.
std::list< uint32_t > getVendorIds() const
Returns a list of all configured vendor identifiers.
Container for storing client class names.
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id, const uint16_t code)
Returns vendor option definition for a given vendor-id and code.
static uint32_t optionSpaceToVendorId(const std::string &option_space)
Converts option space name to vendor id.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
OptionPtr option_
Option instance.
void addClientClass(const std::string &class_name)
Adds new client class for which the option is allowed.
std::string space_name_
Option space name.
OptionDescriptor(const OptionPtr &opt, bool persist, bool cancel, const std::string &formatted_value="", data::ConstElementPtr user_context=data::ConstElementPtr())
Constructor.
bool equals(const OptionDescriptor &other) const
Checks if the one descriptor is equal to another.
bool allowedForClientClasses(const ClientClasses &cclasses) const
Validates an OptionDescriptor's client-classes against a list of classes.
ClientClassesPtr copyClientClasses() const
Get a copy of client classes.
bool cancelled_
Cancelled flag.
std::string formatted_value_
Option value in textual (CSV) format.
static OptionDescriptorPtr create(const OptionPtr &opt, bool persist, bool cancel, const std::string &formatted_value="", data::ConstElementPtr user_context=data::ConstElementPtr())
Factory function creating an instance of the OptionDescriptor.
ClientClasses client_classes_
Collection of classes for the which option is allowed.
bool persistent_
Persistence flag.
Simple container for option spaces holding various items.
void clearItems()
Remove all items from the container.
static bool validateName(const std::string &name)
Checks that the provided option space name is valid.
Universe
defines option universe DHCPv4 or DHCPv6
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
std::string ClientClass
Defines a single class name.
boost::multi_index_container< OptionDescriptor, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_non_unique< KeyFromKeyExtractor< boost::multi_index::const_mem_fun< Option, uint16_t, &Option::getType >, boost::multi_index::member< OptionDescriptor, OptionPtr, &OptionDescriptor::option_ > > >, boost::multi_index::hashed_non_unique< boost::multi_index::member< OptionDescriptor, bool, &OptionDescriptor::persistent_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< OptionIdIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, uint64_t, &data::BaseStampedElement::getId > >, boost::multi_index::hashed_non_unique< boost::multi_index::member< OptionDescriptor, bool, &OptionDescriptor::cancelled_ > >, boost::multi_index::hashed_non_unique< boost::multi_index::composite_key< OptionDescriptor, KeyFromKeyExtractor< boost::multi_index::const_mem_fun< Option, uint16_t, &Option::getType >, boost::multi_index::member< OptionDescriptor, OptionPtr, &OptionDescriptor::option_ > >, boost::multi_index::member< OptionDescriptor, ClientClasses, &OptionDescriptor::client_classes_ > > > > > OptionContainer
Multi index container for DHCP option descriptors.
std::pair< OptionContainerTypeIndex::const_iterator, OptionContainerTypeIndex::const_iterator > OptionContainerTypeRange
Pair of iterators to represent the range of options having the same option type value.
OptionContainer::nth_index< 1 >::type OptionContainerTypeIndex
Type of the index #1 - option type.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClasses > ClientClassesPtr
Smart pointer to ClientClasses object.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< OptionDescriptor > OptionDescriptorPtr
A pointer to option descriptor.
boost::shared_ptr< OptionContainer > OptionContainerPtr
Pointer to the OptionContainer object.
boost::shared_ptr< Option > OptionPtr
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
string trim(const string &input)
Trim leading and trailing spaces.
Defines the logger used by the top-level component of kea-lfc.
#define DHCP4_OPTION_SPACE
global std option spaces
#define DHCP6_OPTION_SPACE