Kea 1.5.0
adaptor_option.cc
Go to the documentation of this file.
1// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
10
11using namespace std;
12using namespace isc::data;
13using namespace isc::dhcp;
14
15namespace isc {
16namespace yang {
17
19}
20
22}
23
24void
25AdaptorOption::setSpace(ElementPtr option, const string& space) {
26 if (!option->contains("space")) {
27 option->set("space", Element::create(space));
28 }
29}
30
31void
33 if (!option->contains("type")) {
34 isc_throw(MissingKey, "missing type in option definition "
35 << option->str());
36 }
37}
38
39void
41 if (!option->contains("code")) {
42 isc_throw(MissingKey, "missing code in option " << option->str());
43 }
44}
45
46void
48 ConstElementPtr name = option->get("name");
49 if (name) {
50 ConstElementPtr space = option->get("space");
51 ConstElementPtr code = option->get("code");
52 string index = space->stringValue() + "@" + name->stringValue();
53 uint16_t val = static_cast<uint16_t>(code->intValue());
54 codes.insert(std::pair<string, uint16_t>(index, val));
55 }
56}
57
58void
60 ConstElementPtr code = option->get("code");
61 if (!code) {
62 ConstElementPtr name = option->get("name");
63 if (!name) {
64 isc_throw(MissingKey, "missing name and code in option "
65 << option->str());
66 }
67 ConstElementPtr space = option->get("space");
68 string index = space->stringValue() + "@" + name->stringValue();
69 OptionCodes::const_iterator it = codes.find(index);
70 if (it == codes.end()) {
71 isc_throw(MissingKey, "can't get code from option "
72 << option->str());
73 }
74 option->set("code", Element::create(static_cast<int>(it->second)));
75 }
76}
77
78void
79AdaptorOption::initCodes(OptionCodes& codes, const string& space) {
80 if (space == "dhcp4") {
81 initCodesInternal(codes, space, STANDARD_V4_OPTION_DEFINITIONS,
82 STANDARD_V4_OPTION_DEFINITIONS_SIZE);
83 initCodesInternal(codes, space, LAST_RESORT_V4_OPTION_DEFINITIONS,
84 LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
85 initCodesInternal(codes, "vendor-4491",
87 } else if (space == "dhcp6") {
88 initCodesInternal(codes, space, STANDARD_V6_OPTION_DEFINITIONS,
89 STANDARD_V6_OPTION_DEFINITIONS_SIZE);
90 initCodesInternal(codes, "vendor-4491",
93 MAPE_V6_OPTION_DEFINITIONS,
94 MAPE_V6_OPTION_DEFINITIONS_SIZE);
96 MAPT_V6_OPTION_DEFINITIONS,
97 MAPT_V6_OPTION_DEFINITIONS_SIZE);
99 LW_V6_OPTION_DEFINITIONS,
100 LW_V6_OPTION_DEFINITIONS_SIZE);
102 V4V6_RULE_OPTION_DEFINITIONS,
103 V4V6_RULE_OPTION_DEFINITIONS_SIZE);
105 V4V6_BIND_OPTION_DEFINITIONS,
106 V4V6_BIND_OPTION_DEFINITIONS_SIZE);
107 initCodesInternal(codes, "vendor-2495",
108 ISC_V6_OPTION_DEFINITIONS,
109 ISC_V6_OPTION_DEFINITIONS_SIZE);
110 }
111}
112
113void
115 const OptionDefParams* params,
116 size_t params_size) {
117 for (size_t i = 0; i < params_size; ++i) {
118 string index = space + "@" + params[i].name;
119 codes.insert(std::pair<string, uint16_t>(index, params[i].code));
120 }
121}
122
123}; // end of namespace isc::yang
124}; // end of namespace isc
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:223
static void setCode(isc::data::ElementPtr option, const OptionCodes &codes)
Set code from name and definitions.
static void initCodes(OptionCodes &codes, const std::string &space)
Initialize code map.
static void setSpace(isc::data::ElementPtr option, const std::string &space)
Set space.
static void checkType(isc::data::ConstElementPtr option)
Checks if type is specified in option definition.
static void initCodesInternal(OptionCodes &codes, const std::string &space, const isc::dhcp::OptionDefParams *params, size_t params_size)
Initialize code map from option definition parameters.
virtual ~AdaptorOption()
Destructor.
static void collect(isc::data::ConstElementPtr option, OptionCodes &codes)
Collect definition.
static void checkCode(isc::data::ConstElementPtr option)
Check if code is specified in option defintion.
Missing key error.
Definition: adaptor.h:17
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
const int DOCSIS3_V6_DEFS_SIZE
Number of option definitions defined.
const OptionDefParams DOCSIS3_V6_DEFS[]
Definitions of standard DHCPv6 options.
const int DOCSIS3_V4_DEFS_SIZE
Number of option definitions defined.
const OptionDefParams DOCSIS3_V4_DEFS[]
Definitions of standard DHCPv4 options.
std::map< std::string, uint16_t > OptionCodes
Map for DHCP option definitions handling code and an index built from space and name.
Defines the logger used by the top-level component of kea-dhcp-ddns.
#define V4V6_BIND_OPTION_SPACE
Definition: option_space.h:22
#define V4V6_RULE_OPTION_SPACE
Definition: option_space.h:21
#define MAPE_V6_OPTION_SPACE
Definition: option_space.h:18
#define LW_V6_OPTION_SPACE
Definition: option_space.h:20
#define MAPT_V6_OPTION_SPACE
Definition: option_space.h:19
Parameters being used to make up an option definition.