1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 | // Copyright (C) 2018-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef ISC_TRANSLATOR_OPTION_DATA_H
#define ISC_TRANSLATOR_OPTION_DATA_H 1
#include <yang/translator.h>
namespace isc {
namespace yang {
/// Option data translation between YANG and JSON
///
/// JSON syntax for Kea DHCP with command channel is:
/// @code
/// {
/// "code": <code>,
/// "name": <name>,
/// "space": <space>,
/// "csv-format": <csv format flag>,
/// "data": <value>,
/// "always-send": <always send flag>,
/// "never-send": <never send flag>,
/// "user-context": { <json map> },
/// "comment": "<comment>"
/// }
/// @endcode
///
/// YANG syntax for kea-dhcp[46] with code and space as keys is:
/// @code
/// +--rw option-data* [code space]
/// +--rw code uint8
/// +--rw space string
/// +--rw name? string
/// +--rw data? string
/// +--rw csv-format? boolean
/// +--rw always-send? boolean
/// +--rw never-send? boolean
/// +--rw user-context? user-context
/// @endcode
///
/// An example in JSON and YANG formats:
/// @code
/// [
/// {
/// "code": 100,
/// "space": "dns",
/// "csv-format": false,
/// "data": "12121212",
/// "always-send": false,
/// "never-send": false
/// }
/// ]
/// @endcode
/// @code
/// /kea-dhcp6-server:config (container)
/// /kea-dhcp6-server:config/
/// option-data[code='100'][space='dns'][data='12121212'] (list instance)
/// /kea-dhcp6-server:config/
/// option-data[code='100'][space='dns'][data='12121212']/code = 100
/// /kea-dhcp6-server:config/
/// option-data[code='100'][space='dns'][data='12121212']/space = dns
/// /kea-dhcp6-server:config/
/// option-data[code='100'][space='dns'][data='12121212']/csv-format = false
/// /kea-dhcp6-server:config/
/// option-data[code='100'][space='dns'][data='12121212']/always-send = false
/// /kea-dhcp6-server:config/
/// option-data[code='100'][space='dns'][data='12121212']/never-send = false
/// @endcode
/// @brief A translator class for converting an option data between
/// YANG and JSON.
///
/// Currently supports on kea-dhcp[46]-server, not yet ietf-dhcpv6-server.
class TranslatorOptionData : virtual public Translator {
public:
/// @brief Constructor.
///
/// @param session Sysrepo session.
/// @param model Model name.
TranslatorOptionData(sysrepo::Session session, const std::string& model);
/// @brief Destructor.
virtual ~TranslatorOptionData() = default;<--- Destructor in derived class<--- Virtual destructor in base class
/// @brief Translate an option data from YANG to JSON.
///
/// @param data_node the YANG node representing the option data
///
/// @return the JSON representation of the option data
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ElementPtr getOptionData(libyang::DataNode const& data_node);
/// @brief Translate an option data from YANG to JSON.
///
/// @param xpath The xpath of the option data.
///
/// @return JSON representation of the option data.
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ElementPtr getOptionDataFromAbsoluteXpath(std::string const& xpath);
/// @brief Translate and set option data from JSON to YANG.
///
/// @param xpath The xpath of the option data.
/// @param elem The JSON element.
void setOptionData(const std::string& xpath,
isc::data::ConstElementPtr elem);
protected:
/// @brief getOptionData JSON for kea-dhcp[46].
///
/// @param data_node the YANG node representing the option data
///
/// @return JSON representation of the option data.
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ElementPtr getOptionDataKea(libyang::DataNode const& data_node);
/// @brief setOptionData for kea-dhcp[46].
///
/// @param xpath The xpath of the option data.
/// @param elem The JSON element.
void setOptionDataKea(const std::string& xpath,
isc::data::ConstElementPtr elem);
}; // TranslatorOptionData
/// @brief A translator class for converting an option data list between
/// YANG and JSON.
///
/// Currently supports on kea-dhcp[46]-server, not yet ietf-dhcpv6-server.
class TranslatorOptionDataList : virtual public TranslatorOptionData {
public:
/// @brief Constructor.
///
/// @param session Sysrepo session.
/// @param model Model name.
TranslatorOptionDataList(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
virtual ~TranslatorOptionDataList() = default;<--- Destructor in derived class
/// @brief Translate option data list from YANG to JSON.
///
/// @param data_node the YANG node representing the list of option data
///
/// @return the JSON representation of the list of option data
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const& data_node);
/// @brief Translate option data list from YANG to JSON.
///
/// @param xpath The xpath of the option data list.
///
/// @return the JSON representation of the list of option data
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ConstElementPtr getOptionDataListFromAbsoluteXpath(std::string const& xpath);
/// @brief Translate and set option data list from JSON to YANG.
///
/// @param xpath The xpath of the option data list.
/// @param elem The JSON element.
void setOptionDataList(const std::string& xpath,
isc::data::ConstElementPtr elem);
protected:
/// @brief getOptionDataList for kea-dhcp[46].
///
/// @param data_node the YANG node representing the list of option data
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ConstElementPtr getOptionDataListKea(libyang::DataNode const& data_node);
/// @brief setOptionDataList for kea-dhcp[46].
///
/// @param xpath The xpath of the option data list.
/// @param elem The JSON element.
/// @throw BadValue on option data without code or space.
void setOptionDataListKea(const std::string& xpath,
isc::data::ConstElementPtr elem);
}; // TranslatorOptionDataList
} // namespace yang
} // namespace isc
#endif // ISC_TRANSLATOR_OPTION_DATA_H
|