7#ifndef OPTION_DEFINITION_H
8#define OPTION_DEFINITION_H
16#include <boost/multi_index/hashed_index.hpp>
17#include <boost/multi_index/mem_fun.hpp>
18#include <boost/multi_index/ordered_index.hpp>
19#include <boost/multi_index/sequenced_index.hpp>
20#include <boost/multi_index_container.hpp>
21#include <boost/shared_ptr.hpp>
52class OptionDefinition;
156 const std::string& space,
157 const std::string& type,
158 const bool array_type =
false);
170 const std::string& space,
172 const bool array_type =
false);
191 const std::string& space,
192 const std::string& type,
193 const char* encapsulated_space);
212 const std::string& space,
214 const char* encapsulated_space);
233 const std::string& space,
234 const std::string& type,
235 const bool array_type =
false);
254 const std::string& space,
256 const bool array_type =
false);
275 const std::string& space,
276 const std::string& type,
277 const char* encapsulated_space);
296 const std::string& space,
298 const char* encapsulated_space);
362 return (encapsulated_space_);
368 std::string
getName()
const {
return (name_); }
374 return (record_fields_);
381 return (option_space_name_);
391 return (user_context_.getContext());
397 user_context_.setContext(ctx);
407 user_context_.contextToElement(map);
448 bool convenient_notation =
false,
449 size_t rec_level = 0)
const;
495 const std::vector<std::string>& values)
const;
553 size_t rec_level = 0);
567 size_t rec_level = 0);
581 size_t rec_level = 0);
631 const std::string& encapsulated_space,
634 size_t rec_level = 0) {
635 boost::shared_ptr<OptionInt<T> > option(
new OptionInt<T>(u, type, 0));
636 option->setEncapsulatedSpace(encapsulated_space);
637 option->unpack(begin, end, rec_level);
662 bool haveCompressedFqdnListFormat()
const;
701 bool convenient_notation =
false,
702 size_t rec_level = 0)
const;
708 return (type == type_);
714 inline bool haveSpace(
const std::string& space)
const {
715 return (space == option_space_name_);
736 bool convertToBool(
const std::string& value_str)
const;
751 T lexicalCastWithRangeCheck(
const std::string& value_str)
const;
781 std::string encapsulated_space_;
785 data::UserContext user_context_;
787 std::string option_space_name_;
805typedef boost::multi_index_container<
809 boost::multi_index::indexed_by<
812 boost::multi_index::sequenced<>,
814 boost::multi_index::hashed_non_unique<
821 boost::multi_index::const_mem_fun<
828 boost::multi_index::hashed_non_unique<
832 boost::multi_index::const_mem_fun<
839 boost::multi_index::ordered_non_unique<
842 boost::multi_index::const_mem_fun<
843 data::BaseStampedElement,
844 boost::posix_time::ptime,
850 boost::multi_index::hashed_non_unique<
851 boost::multi_index::tag<OptionIdIndexTag>,
852 boost::multi_index::const_mem_fun<data::BaseStampedElement, uint64_t,
873typedef std::pair<OptionDefContainerTypeIndex::const_iterator,
882typedef std::pair<OptionDefContainerNameIndex::const_iterator,
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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,...
DuplicateOptionDefinition(const char *file, size_t line, const char *what)
InvalidOptionValue(const char *file, size_t line, const char *what)
LengthFieldType
Size of the length field in the tuple.
Class of option definition space container.
void addItem(const OptionDefinitionPtr &def)
Adds a new option definition to the container.
Base class representing a DHCP option definition.
uint16_t getCode() const
Return option code.
bool operator==(const OptionDefinition &other) const
Equality operator.
static OptionPtr factoryInteger(Option::Universe u, uint16_t type, const std::string &encapsulated_space, OptionBufferConstIter begin, OptionBufferConstIter end, size_t rec_level=0)
Factory function to create option with integer value.
static OptionPtr factoryEmpty(Option::Universe u, uint16_t type)
Empty option factory.
static OptionPtr factoryIntegerArray(Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
Factory function to create option with array of integer values.
OptionDefinition(const std::string &name, const uint16_t code, const std::string &space, const std::string &type, const bool array_type=false)
Constructor.
static OptionPtr factoryIAPrefix6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end, size_t rec_level=0)
Factory for IAPREFIX-type of option.
bool operator!=(const OptionDefinition &other) const
Inequality operator.
OptionDataType getType() const
Return option data type.
static OptionPtr factoryIA6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end, size_t rec_level=0)
Factory for IA-type of option.
static OptionPtr factoryAddrList6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
Factory to create option with address list.
OptionPtr optionFactory(Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end, bool convenient_notation=false, size_t rec_level=0) const
Option factory.
static OptionPtr factoryAddrList4(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
Factory to create option with address list.
void setContext(const data::ConstElementPtr &ctx)
Sets user context.
std::string getOptionSpaceName() const
Returns option space name.
std::vector< OptionDataType >::const_iterator RecordFieldsConstIter
Const iterator for record data fields.
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
static OptionPtr factoryIAAddr6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end, size_t rec_level=0)
Factory for IAADDR-type of option.
void addRecordField(const std::string &data_type_name)
Adds data field to the record.
bool equals(const OptionDefinition &other) const
Check if option definition is equal to other.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
std::string getName() const
Return option name.
const RecordFieldsCollection & getRecordFields() const
Return list of record fields.
void validate() const
Check if the option definition is valid.
std::vector< OptionDataType > RecordFieldsCollection
List of fields within the record.
std::string getEncapsulatedSpace() const
Return name of the encapsulated option space.
static OptionDefinitionPtr create(const std::string &name, const uint16_t code, const std::string &space, const std::string &type, const bool array_type=false)
Factory function creating an instance of the OptionDefinition.
static OptionPtr factoryOpaqueDataTuples(Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
Factory to create option with tuple list.
bool getArrayType() const
Return array type indicator.
static OptionPtr factoryGeneric(Option::Universe u, uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
Factory to create generic option.
Forward declaration to OptionIntArray.
Forward declaration to OptionInt.
Simple container for option spaces holding various items.
void addItem(const OptionDefinitionPtr &item, const std::string &option_space)
Universe
defines option universe DHCPv4 or DHCPv6
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
OptionSpaceContainer< OptionDefContainer, OptionDefinitionPtr, std::string > BaseOptionDefSpaceContainer
Base type of option definition space container.
std::map< uint32_t, OptionDefContainerPtr > VendorOptionDefContainers
Container that holds various vendor option containers.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
std::pair< OptionDefContainerNameIndex::const_iterator, OptionDefContainerNameIndex::const_iterator > OptionDefContainerNameRange
Pair of iterators to represent the range of options definitions having the same option name.
std::map< std::string, OptionDefContainerPtr > OptionDefContainers
Container that holds option definitions for various option spaces.
OptionDefContainer::nth_index< 2 >::type OptionDefContainerNameIndex
Type of the index #2 - option name.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
std::pair< OptionDefContainerTypeIndex::const_iterator, OptionDefContainerTypeIndex::const_iterator > OptionDefContainerTypeRange
Pair of iterators to represent the range of options definitions having the same option type value.
boost::multi_index_container< OptionDefinitionPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_non_unique< boost::multi_index::const_mem_fun< OptionDefinition, uint16_t, &OptionDefinition::getCode > >, boost::multi_index::hashed_non_unique< boost::multi_index::const_mem_fun< OptionDefinition, std::string, &OptionDefinition::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::StampedElement::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 > > > > OptionDefContainer
Multi index container for DHCP option definitions.
OptionDataType
Data types of DHCP option fields.
OptionDefContainer::nth_index< 1 >::type OptionDefContainerTypeIndex
Type of the index #1 - option type.
boost::shared_ptr< Option > OptionPtr
boost::shared_ptr< OptionDefContainer > OptionDefContainerPtr
Pointer to an option definition container.
Defines the logger used by the top-level component of kea-lfc.