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 | // Copyright (C) 2018-2022 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_CONTROL_SOCKET_H
#define ISC_TRANSLATOR_CONTROL_SOCKET_H 1
#include <yang/translator.h>
namespace isc {
namespace yang {
/// Control socket translation between YANG and JSON
///
/// JSON syntax for all Kea servers with command channel is:
/// @code
/// "control-socket": {
/// "socket-type": "<socket type>",
/// "socket-name": "<socket name>",
/// "user-context": { <json map> },
/// "comment": "<comment>"
/// }
/// @endcode
///
/// YANG syntax is:
/// @code
/// +--rw control-socket!
/// +--rw socket-name string
/// +--rw socket-type enumeration
/// +--rw user-context? user-context
/// @endcode
///
/// An example in JSON and YANG formats:
/// @code
/// {
/// "socket-name": "/tmp/kea.sock",
/// "socket-type": "unix",
/// "user-context": { "foo": 1 }
/// }
/// @endcode
/// @code
/// /kea-ctrl-agent:config (container)
/// /kea-ctrl-agent:config/control-sockets (container)
/// /kea-ctrl-agent:config/control-sockets/
/// socket[server-type='dhcp4'] (list instance)
/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
/// server-type = dhcp4
/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
/// control-socket (container)
/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
/// control-socket/socket-name = /tmp/kea.sock
/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
/// control-socket/socket-type = unix
/// /kea-ctrl-agent:config/control-sockets/socket[server-type='dhcp4']/
/// control-socket/user-context = { \"foo\": 1 }
/// @endcode
/// @brief A translator class for converting a control socket between
/// YANG and JSON.
///
/// Supports the following models:
/// - kea-dhcp4-server
/// - kea-dhcp6-server
/// - kea-dhcp-ddns
/// - kea-ctrl-agent
class TranslatorControlSocket : virtual public Translator {
public:
/// @brief Constructor.
///
/// @param session Sysrepo session.
/// @param model Model name.
TranslatorControlSocket(sysrepo::Session session,
const std::string& model);
/// @brief Destructor.
virtual ~TranslatorControlSocket() = default;<--- Destructor in derived class
/// @brief Translate a control socket from YANG to JSON.
///
/// @param data_node the YANG node representing the control socket
///
/// @return the JSON representation of the control socket
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ElementPtr getControlSocket(libyang::DataNode const& data_node);
/// @brief Translate a control socket from YANG to JSON.
///
/// @note This is a computationally expensive operation that makes a lookup in the sysrepo
/// datastore by calling Session::getData(). It should be used sparingly in production code,
/// mainly to get an initial data node to work with. It may be used at will in unit tests.
/// Use getControlSocket(libyang::DataNode) as a scalable alternative.
///
/// @param xpath The xpath of the control socket.
///
/// @return JSON representation of the control socket
///
/// @throw NetconfError when sysrepo raises an error.
isc::data::ElementPtr getControlSocketFromAbsoluteXpath(std::string const& xpath);
/// @brief Translate and set control socket from JSON to YANG.
///
/// @param xpath The xpath of the control socket.
/// @param elem The JSON element.
void setControlSocket(const std::string& xpath,
isc::data::ConstElementPtr elem);
protected:
/// @brief getControlSocket JSON for kea models.
///
/// @param data_node the YANG node representing the control socket
/// @return JSON representation of the control socket.
/// @throw NetconfError when sysrepo raises an error.
isc::data::ElementPtr getControlSocketKea(libyang::DataNode const& data_node);
/// @brief setControlSocket for kea models.
///
/// Null elem argument removes the container.
/// Required parameters passed in elem are: socket-name, socket-type.
/// Optional parameters are: user-context.
///
/// @param xpath The xpath of the control socket.
/// @param elem The JSON element.
/// @throw BadValue on control socket without socket type or name.
void setControlSocketKea(const std::string& xpath,
isc::data::ConstElementPtr elem);
}; // TranslatorControlSocket
} // namespace yang
} // namespace isc
#endif // ISC_TRANSLATOR_CONTROL_SOCKET_H
|