28 option_->equals(other.
option_));
31 CfgOption::CfgOption() {
35 CfgOption::empty()
const {
36 return (options_.empty() && vendor_options_.empty());
41 return (options_.equals(other.options_) &&
42 vendor_options_.equals(other.vendor_options_));
46 CfgOption::add(
const OptionPtr& option,
const bool persistent,
47 const std::string& option_space) {
56 }
else if (!OptionSpace::validateName(option_space)) {
58 << option_space <<
"'");
61 const uint32_t vendor_id = LibDHCP::optionSpaceToVendorId(option_space);
63 vendor_options_.addItem(desc, vendor_id);
65 options_.addItem(desc, option_space);
69 std::list<std::string>
70 CfgOption::getVendorIdsSpaceNames()
const {
71 std::list<uint32_t> ids = getVendorIds();
72 std::list<std::string> names;
73 for (std::list<uint32_t>::const_iterator
id = ids.begin();
74 id != ids.end(); ++id) {
78 s <<
"vendor-" << *id;
79 names.push_back(s.str());
87 mergeInternal(options_, other.options_);
89 mergeInternal(vendor_options_, other.vendor_options_);
101 CfgOption::encapsulate() {
109 CfgOption::encapsulateInternal(
const std::string& option_space) {
114 for (OptionContainer::const_iterator opt = options->begin();
115 opt != options->end(); ++opt) {
116 encapsulateInternal(opt->option_);
121 CfgOption::encapsulateInternal(
const OptionPtr& option) {
123 const std::string& encap_space = option->getEncapsulatedSpace();
125 if (!encap_space.empty()) {
128 for (OptionContainer::const_iterator encap_opt =
129 encap_options->begin(); encap_opt != encap_options->end();
132 if (!option->getOption(encap_opt->option_->getType())) {
133 option->addOption(encap_opt->option_);
140 encapsulateInternal(encap_opt->option_);
146 template <
typename Selector>
149 OptionDescriptor, Selector>& src_container,
151 OptionDescriptor, Selector>& dest_container)
const {
153 std::list<Selector> selectors = src_container.getOptionSpaceNames();
158 for (
typename std::list<Selector>::const_iterator it = selectors.begin();
159 it != selectors.end(); ++it) {
167 for (OptionContainer::const_iterator src_opt = src_all->begin();
168 src_opt != src_all->end(); ++src_opt) {
171 idx.equal_range(src_opt->option_->getType());
174 if (std::distance(range.first, range.second) == 0) {
175 dest_container.addItem(OptionDescriptor(*src_opt), *it);
183 CfgOption::getAll(
const std::string& option_space)
const {
184 return (options_.getItems(option_space));
188 CfgOption::getAll(
const uint32_t vendor_id)
const {
189 return (vendor_options_.getItems(vendor_id));
193 CfgOption::toElement()
const {
197 const std::list<std::string>& names = options_.getOptionSpaceNames();
198 for (std::list<std::string>::const_iterator name = names.begin();
199 name != names.end(); ++name) {
201 for (OptionContainer::const_iterator opt = opts->begin();
202 opt != opts->end(); ++opt) {
206 opt->contextToElement(map);
210 uint16_t code = opt->option_->getType();
215 def = LibDHCP::getRuntimeOptionDef(*name, code);
218 def = LibDHCP::getLastResortOptionDef(*name, code);
224 if (!opt->formatted_value_.empty()) {
229 std::vector<uint8_t> bin = opt->option_->toBinary();
240 const std::list<uint32_t>& ids = vendor_options_.getOptionSpaceNames();
241 for (std::list<uint32_t>::const_iterator
id = ids.begin();
242 id != ids.end(); ++id) {
244 for (OptionContainer::const_iterator opt = opts->begin();
245 opt != opts->end(); ++opt) {
249 opt->contextToElement(map);
251 std::ostringstream oss;
252 oss <<
"vendor-" << *id;
255 uint16_t code = opt->option_->getType();
260 LibDHCP::getVendorOptionDef(universe, *
id, code);
263 def = LibDHCP::getRuntimeOptionDef(oss.str(), code);
269 if (!opt->formatted_value_.empty()) {
274 std::vector<uint8_t> bin = opt->option_->toBinary();
OptionContainer::nth_index< 1 >::type OptionContainerTypeIndex
Type of the index #1 - option type.
#define DHCP6_OPTION_SPACE
boost::shared_ptr< Option > OptionPtr
Universe
defines option universe DHCPv4 or DHCPv6
boost::shared_ptr< Element > ElementPtr
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.
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_ > > >> 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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
std::string formatted_value_
Option value in textual (CSV) format.
Represents option data configuration for the DHCP server.
bool persistent_
Persistence flag.
#define DHCP4_OPTION_SPACE
std::string space_name_
Option space name.
OptionPtr option_
Option instance.
void clearItems()
Remove all items from the container.
Defines the logger used by the top-level component of kea-dhcp-ddns.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
static ElementPtr create(const Position &pos=ZERO_POSITION())
boost::shared_ptr< OptionContainer > OptionContainerPtr
Pointer to the OptionContainer object.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.