18#include <boost/foreach.hpp>
19#include <boost/multi_index_container.hpp>
20#include <boost/multi_index/hashed_index.hpp>
21#include <boost/multi_index/ordered_index.hpp>
22#include <boost/multi_index/sequenced_index.hpp>
23#include <boost/multi_index/mem_fun.hpp>
24#include <boost/multi_index/member.hpp>
25#include <boost/multi_index/composite_key.hpp>
26#include <boost/shared_ptr.hpp>
107 const std::string& formatted_value =
"",
141 if (
this != &other) {
143 data::StampedElement::operator=(other);
167 const std::string& formatted_value =
"",
259typedef boost::multi_index_container<
263 boost::multi_index::indexed_by<
267 boost::multi_index::sequenced<>,
269 boost::multi_index::hashed_non_unique<
277 boost::multi_index::const_mem_fun<
284 boost::multi_index::member<
293 boost::multi_index::hashed_non_unique<
294 boost::multi_index::member<
302 boost::multi_index::ordered_non_unique<
303 boost::multi_index::const_mem_fun<
305 boost::posix_time::ptime,
312 boost::multi_index::hashed_non_unique<
313 boost::multi_index::tag<OptionIdIndexTag>,
319 boost::multi_index::hashed_non_unique<
320 boost::multi_index::member<
327 boost::multi_index::hashed_non_unique<
328 boost::multi_index::composite_key<
331 boost::multi_index::const_mem_fun<
336 boost::multi_index::member<
342 boost::multi_index::member<OptionDescriptor,
357typedef std::pair<OptionContainerTypeIndex::const_iterator,
364typedef std::pair<OptionContainerPersistIndex::const_iterator,
371typedef std::pair<OptionContainerCancelIndex::const_iterator,
376typedef std::pair<OptionContainerTypeClassesIndex::const_iterator,
471 void add(
const OptionPtr& option,
const bool persistent,
472 const bool cancelled,
const std::string& option_space,
473 const uint64_t
id = 0);
604 return (encapsulated_);
661 template<
typename Selector>
663 const uint16_t option_code)
const {
667 if (!options || options->empty()) {
673 OptionContainerTypeIndex::const_iterator od_itr = idx.find(option_code);
674 if (od_itr == idx.end()) {
692 template<
typename Selector>
694 const uint16_t option_code)
const {
699 if (!options || options->empty()) {
707 BOOST_FOREACH(
auto const& od_itr, range) {
708 list.push_back(od_itr);
727 template<
typename Selector>
729 const uint16_t option_code,
734 if (!options || options->empty()) {
740 auto& idx6 = options->get<6>();
741 auto const& od_itr6 = idx6.find(boost::make_tuple(option_code, client_classes));
742 if (od_itr6 == idx6.end()) {
759 template<
typename Selector>
761 const uint16_t option_code,
765 if (!options || options->empty()) {
773 auto & index = options->get<1>();
774 auto range = index.equal_range(option_code);
775 switch (std::distance(range.first, range.second)) {
779 if ((*range.first).allowedForClientClasses(cclasses)) {
780 return (*range.first);
785 auto default_opt = index.end();
786 auto otr = range.first;
787 while (otr != range.second) {
788 if ((*otr).allowedForClientClasses(cclasses)) {
789 if (!(*otr).client_classes_.empty()) {
800 if (default_opt != index.end()) {
801 return (*default_opt);
819 size_t del(
const std::string& option_space,
const uint16_t option_code);
832 size_t del(
const std::string& option_space,
const uint16_t option_code,
841 size_t del(
const uint32_t vendor_id,
const uint16_t option_code);
864 size_t del(
const uint64_t
id);
874 return (options_.getOptionSpaceNames());
879 return (vendor_options_.getOptionSpaceNames());
927 void encapsulateInternal(
const std::string& option_space);
937 void encapsulateInternal(
const OptionPtr& option);
942 void decapsulateInternal(
const OptionPtr& option);
957 template <
typename Selector>
974 uint32_t> VendorOptionSpaceCollection;
976 VendorOptionSpaceCollection vendor_options_;
boost::shared_ptr< Option > OptionPtr
Defines elements for storing the names of client classes.
This class represents configuration element which is associated with database identifier and the modi...
boost::posix_time::ptime getModificationTime() const
Returns timestamp.
uint64_t getId() const
Returns element's database identifier.
This class represents configuration element which is associated with database identifier,...
StampedElement()
Constructor.
Represents option data configuration for the DHCP server.
bool isEncapsulated() const
Checks if options have been encapsulated.
OptionDescriptor allowedForClientClasses(const Selector &key, const uint16_t option_code, const ClientClasses &cclasses) const
Fetches an option for a given code if it is allowed for the given list of client classes.
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.
static std::set< std::string > multiple_encapsulating_spaces_
Option spaces which can encapsulate multiple sub-options of the same type.
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.
OptionDescriptor get(const Selector &key, const uint16_t option_code) const
Returns option for the specified key and option code.
isc::data::ElementPtr toElementWithMetadata(const bool include_metadata, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr()) const
Unparse a configuration object with optionally including the metadata.
OptionDescriptorList getList(const Selector &key, const uint16_t option_code) const
Returns options for the specified key and option code.
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.
bool operator==(const CfgOption &other) const
Equality operator.
bool operator!=(const CfgOption &other) const
Inequality operator.
OptionDescriptor get(const Selector &key, const uint16_t option_code, const ClientClasses &client_classes) const
Returns option for the specified key, option code and client classes tag.
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.
OptionPtr option_
Option instance.
bool operator!=(const OptionDescriptor &other) const
Inequality operator.
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 & operator=(const OptionDescriptor &other)
Assignment operator.
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.
OptionDescriptor(bool persist, bool cancel)
Constructor.
bool operator==(const OptionDescriptor &other) const
Equality operator.
OptionDescriptor(const OptionDescriptor &desc)
Copy constructor.
bool persistent_
Persistence flag.
Simple container for option spaces holding various items.
uint16_t getType() const
Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6).
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
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.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
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.
std::pair< OptionContainerTypeClassesIndex::const_iterator, OptionContainerTypeClassesIndex::const_iterator > OptionContainerTypeClassesRange
std::map< std::string, OptionSpacePtr > OptionSpaceCollection
A collection of option spaces.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClasses > ClientClassesPtr
Smart pointer to ClientClasses object.
std::vector< OptionDescriptor > OptionDescriptorList
A list of option descriptors.
OptionContainer::nth_index< 5 >::type OptionContainerCancelIndex
Type of the index #5 - option cancellation flag.
std::pair< OptionContainerPersistIndex::const_iterator, OptionContainerPersistIndex::const_iterator > OptionContainerPersistRange
Pair of iterators to represent the range of options having the same persistency flag.
boost::shared_ptr< OptionDescriptor > OptionDescriptorPtr
A pointer to option descriptor.
OptionContainer::nth_index< 6 >::type OptionContainerTypeClassesIndex
Type of the index #6 - option type + client_classes.
boost::shared_ptr< OptionContainer > OptionContainerPtr
Pointer to the OptionContainer object.
OptionContainer::nth_index< 2 >::type OptionContainerPersistIndex
Type of the index #2 - option persistency flag.
std::pair< OptionContainerCancelIndex::const_iterator, OptionContainerCancelIndex::const_iterator > OptionContainerCancelRange
Pair of iterators to represent the range of options having the same cancellation flag.
boost::shared_ptr< Option > OptionPtr
std::list< ConstCfgOptionPtr > CfgOptionList
Const pointer list.
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
void setContext(const data::ConstElementPtr &ctx)
Sets user context.