Kea 2.7.5
adaptor_option.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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
7#include <config.h>
8
11#include <yang/adaptor_option.h>
12#include <yang/netconf_error.h>
13
14using namespace std;
15using namespace isc::data;
16using namespace isc::dhcp;
17
18namespace isc {
19namespace yang {
20
21void
22AdaptorOption::setSpace(ElementPtr option, const string& space) {
23 if (!option->contains("space")) {
24 option->set("space", Element::create(space));
25 }
26}
27
28void
30 if (!option->contains("type")) {
31 isc_throw(MissingKey, "missing type in option definition "
32 << option->str());
33 }
34}
35
36void
38 if (!option->contains("code")) {
39 isc_throw(MissingKey, "missing code in option " << option->str());
40 }
41}
42
43void
45 ConstElementPtr name = option->get("name");
46 if (name) {
47 ConstElementPtr space = option->get("space");
48 ConstElementPtr code = option->get("code");
49 string index = space->stringValue() + "@" + name->stringValue();
50 uint16_t val = static_cast<uint16_t>(code->intValue());
51 codes.insert(pair<string, uint16_t>(index, val));
52 }
53}
54
55void
57 ConstElementPtr code = option->get("code");
58 if (!code) {
59 ConstElementPtr name = option->get("name");
60 if (!name) {
61 isc_throw(MissingKey, "missing name and code in option "
62 << option->str());
63 }
64 ConstElementPtr space = option->get("space");
65 string index = space->stringValue() + "@" + name->stringValue();
66 OptionCodes::const_iterator it = codes.find(index);
67 if (it == codes.end()) {
68 isc_throw(MissingKey, "can't get code from option "
69 << option->str());
70 }
71 option->set("code", Element::create(static_cast<int>(it->second)));
72 }
73}
74
75void
76AdaptorOption::initCodes(OptionCodes& codes, const string& space) {
77 if (space == DHCP4_OPTION_SPACE) {
78 initCodesInternal(codes, space, STANDARD_V4_OPTION_DEFINITIONS,
79 STANDARD_V4_OPTION_DEFINITIONS_SIZE);
80 initCodesInternal(codes, space, LAST_RESORT_V4_OPTION_DEFINITIONS,
81 LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
82 initCodesInternal(codes, "vendor-4491",
85 } else if (space == DHCP6_OPTION_SPACE) {
86 initCodesInternal(codes, space, STANDARD_V6_OPTION_DEFINITIONS,
87 STANDARD_V6_OPTION_DEFINITIONS_SIZE);
88 initCodesInternal(codes, "vendor-4491",
92 MAPE_V6_OPTION_DEFINITIONS,
93 MAPE_V6_OPTION_DEFINITIONS_SIZE);
95 MAPT_V6_OPTION_DEFINITIONS,
96 MAPT_V6_OPTION_DEFINITIONS_SIZE);
98 LW_V6_OPTION_DEFINITIONS,
99 LW_V6_OPTION_DEFINITIONS_SIZE);
101 V4V6_RULE_OPTION_DEFINITIONS,
102 V4V6_RULE_OPTION_DEFINITIONS_SIZE);
104 V4V6_BIND_OPTION_DEFINITIONS,
105 V4V6_BIND_OPTION_DEFINITIONS_SIZE);
106 initCodesInternal(codes, "vendor-2495",
107 ISC_V6_OPTION_DEFINITIONS,
108 ISC_V6_OPTION_DEFINITIONS_SIZE);
109 }
110}
111
112void
114 const OptionDefParams* params,
115 size_t params_size) {
116 for (size_t i = 0; i < params_size; ++i) {
117 string index = space + "@" + params[i].name;
118 codes.insert(pair<string, uint16_t>(index, params[i].code));
119 }
120}
121
122} // namespace yang
123} // namespace isc
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
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.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
const OptionDefParams DOCSIS3_V4_OPTION_DEFINITIONS[]
Definitions of standard DHCPv4 options.
const int DOCSIS3_V6_OPTION_DEFINITIONS_SIZE
Number of option definitions defined.
const int DOCSIS3_V4_OPTION_DEFINITIONS_SIZE
Number of option definitions defined.
const OptionDefParams DOCSIS3_V6_OPTION_DEFINITIONS[]
Definitions of standard DHCPv6 options.
std::unordered_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-lfc.
#define V4V6_BIND_OPTION_SPACE
#define DHCP4_OPTION_SPACE
global std option spaces
#define V4V6_RULE_OPTION_SPACE
#define MAPE_V6_OPTION_SPACE
#define LW_V6_OPTION_SPACE
#define DHCP6_OPTION_SPACE
#define MAPT_V6_OPTION_SPACE
Parameters being used to make up an option definition.
Missing key error.