FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
dhcp_client_cmds.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __VOM_DHCP_CLIENT_CMDS_H__
17 #define __VOM_DHCP_CLIENT_CMDS_H__
18 
19 #include "vom/dhcp_client.hpp"
20 #include "vom/dump_cmd.hpp"
21 #include "vom/event_cmd.hpp"
22 
23 #include <vapi/dhcp.api.vapi.hpp>
24 #include <vapi/vpe.api.vapi.hpp>
25 
26 namespace VOM {
27 namespace dhcp_client_cmds {
28 
29 /**
30  * A command class that binds the DHCP config to the interface
31  */
32 class bind_cmd : public rpc_cmd<HW::item<bool>, vapi::Dhcp_client_config>
33 {
34 public:
35  /**
36  * Constructor
37  */
39  const handle_t& itf,
40  const std::string& hostname,
41  const l2_address_t& client_id,
42  bool set_braodcast_flag,
43  const ip_dscp_t& dscp);
44 
45  /**
46  * Issue the command to VPP/HW
47  */
49  /**
50  * convert to string format for debug purposes
51  */
52  std::string to_string() const;
53 
54  /**
55  * Comparison operator - only used for UT
56  */
57  bool operator==(const bind_cmd& i) const;
58 
59 private:
60  /**
61  * Reference to the HW::item of the interface to bind
62  */
63  const handle_t& m_itf;
64 
65  /**
66  * The DHCP client's hostname
67  */
68  const std::string m_hostname;
69 
70  /**
71  * The DHCP client's ID
72  */
73  const l2_address_t m_client_id;
74 
75  /**
76  * Flag to control the setting the of DHCP discover's broadcast flag
77  */
78  const bool m_set_broadcast_flag;
79 
80  /**
81  * DSCP bits
82  */
83  const ip_dscp_t& m_dscp;
84 };
85 
86 /**
87  * A cmd class that Unbinds Dhcp Config from an interface
88  */
89 class unbind_cmd : public rpc_cmd<HW::item<bool>, vapi::Dhcp_client_config>
90 {
91 public:
92  /**
93  * Constructor
94  */
96  const handle_t& itf,
97  const std::string& hostname);
98 
99  /**
100  * Issue the command to VPP/HW
101  */
103  /**
104  * convert to string format for debug purposes
105  */
106  std::string to_string() const;
107 
108  /**
109  * Comparison operator - only used for UT
110  */
111  bool operator==(const unbind_cmd& i) const;
112 
113 private:
114  /**
115  * Reference to the HW::item of the interface to unbind
116  */
117  const handle_t& m_itf;
118 
119  /**
120  * The DHCP client's hostname
121  */
122  const std::string m_hostname;
123 };
124 
125 /**
126  * A functor class represents our desire to recieve interface events
127  */
128 class events_cmd : public event_cmd<vapi::Control_ping, vapi::Dhcp_compl_event>
129 {
130 public:
131  /**
132  * Constructor
133  */
135  ~events_cmd();
136 
137  /**
138  * Issue the command to VPP/HW - subscribe to DHCP events
139  */
141 
142  /**
143  * Retire the command - unsubscribe
144  */
145  void retire(connection& con);
146  /**
147  * convert to string format for debug purposes
148  */
149  std::string to_string() const;
150 
151  /**
152  * Comparison operator - only used for UT
153  */
154  bool operator==(const events_cmd& i) const;
155 
156  /**
157  * called in the VAPI RX thread when data is available.
158  */
159  void notify();
160 
161 private:
162  void succeeded() {}
163  /**
164  * The listner of this command
165  */
166  dhcp_client::event_listener& m_listener;
167 };
168 
169 /**
170  * A cmd class that Dumps all the DHCP clients
171  */
172 class dump_cmd : public VOM::dump_cmd<vapi::Dhcp_client_dump>
173 {
174 public:
175  /**
176  * Constructor
177  */
178  dump_cmd();
179  dump_cmd(const dump_cmd& d);
180 
181  /**
182  * Issue the command to VPP/HW
183  */
185  /**
186  * convert to string format for debug purposes
187  */
188  std::string to_string() const;
189 
190  /**
191  * Comparison operator - only used for UT
192  */
193  bool operator==(const dump_cmd& i) const;
194 
195 private:
196  /**
197  * HW reutrn code
198  */
199  HW::item<bool> item;
200 };
201 
202 }; // namespace dhcp_client_cmds
203 }; // namespace VOM
204 
205 /*
206  * fd.io coding-style-patch-verification: OFF
207  *
208  * Local Variables:
209  * eval: (c-set-style "mozilla")
210  * End:
211  */
212 
213 #endif
VOM::HW::item< bool >
VOM::dhcp_client_cmds::dump_cmd
A cmd class that Dumps all the DHCP clients.
Definition: dhcp_client_cmds.hpp:172
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::dhcp_client_cmds::events_cmd::retire
void retire(connection &con)
Retire the command - unsubscribe.
Definition: dhcp_client_cmds.cpp:164
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
VOM::dhcp_client_cmds::events_cmd::notify
void notify()
called in the VAPI RX thread when data is available.
Definition: dhcp_client_cmds.cpp:169
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::dhcp_client_cmds::events_cmd
A functor class represents our desire to recieve interface events.
Definition: dhcp_client_cmds.hpp:128
VOM::dhcp_client_cmds::bind_cmd
A command class that binds the DHCP config to the interface.
Definition: dhcp_client_cmds.hpp:32
VOM::dhcp_client_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: dhcp_client_cmds.cpp:228
VOM::dhcp_client_cmds::events_cmd::~events_cmd
~events_cmd()
Definition: dhcp_client_cmds.cpp:138
VOM::dhcp_client_cmds::dump_cmd::dump_cmd
dump_cmd()
Constructor.
Definition: dhcp_client_cmds.cpp:205
hostname
string hostname[64]
Definition: dhcp.api:159
VOM::event_cmd
An Event command base class.
Definition: event_cmd.hpp:39
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::dhcp_client_cmds::events_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: dhcp_client_cmds.cpp:200
VOM::dhcp_client_cmds::events_cmd::operator==
bool operator==(const events_cmd &i) const
Comparison operator - only used for UT.
Definition: dhcp_client_cmds.cpp:144
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::dhcp_client_cmds::bind_cmd::bind_cmd
bind_cmd(HW::item< bool > &item, const handle_t &itf, const std::string &hostname, const l2_address_t &client_id, bool set_braodcast_flag, const ip_dscp_t &dscp)
Constructor.
Definition: dhcp_client_cmds.cpp:24
VOM::dhcp_client::event_listener
A class that listens to DHCP Events.
Definition: dhcp_client.hpp:83
dump_cmd.hpp
VOM::dhcp_client_cmds::unbind_cmd
A cmd class that Unbinds Dhcp Config from an interface.
Definition: dhcp_client_cmds.hpp:89
VOM::dhcp_client_cmds::unbind_cmd::unbind_cmd
unbind_cmd(HW::item< bool > &item, const handle_t &itf, const std::string &hostname)
Constructor.
Definition: dhcp_client_cmds.cpp:85
VOM::l2_address_t
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
VOM::rpc_cmd< HW::item< bool >, vapi::Dhcp_client_config >::item
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
VOM::ip_dscp_t
IP DSCP values.
Definition: prefix.hpp:81
VOM::dhcp_client_cmds::bind_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: dhcp_client_cmds.cpp:46
VOM::dhcp_client_cmds::bind_cmd::operator==
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
Definition: dhcp_client_cmds.cpp:40
VOM::dhcp_client_cmds::unbind_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: dhcp_client_cmds.cpp:123
VOM::dhcp_client_cmds::bind_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: dhcp_client_cmds.cpp:74
event_cmd.hpp
VOM::dhcp_client_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: dhcp_client_cmds.cpp:210
i
int i
Definition: flowhash_template.h:376
VOM::dhcp_client_cmds::events_cmd::events_cmd
events_cmd(dhcp_client::event_listener &el)
Constructor.
Definition: dhcp_client_cmds.cpp:132
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::dump_cmd
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
dhcp_client.hpp
VOM::dhcp_client_cmds::events_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW - subscribe to DHCP events.
Definition: dhcp_client_cmds.cpp:150
dscp
vl_api_ip_dscp_t dscp
Definition: dhcp.api:163
VOM::dhcp_client_cmds::unbind_cmd::operator==
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
Definition: dhcp_client_cmds.cpp:95
VOM::dhcp_client_cmds::unbind_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: dhcp_client_cmds.cpp:101
VOM::dhcp_client_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: dhcp_client_cmds.cpp:216
string
const char *const string
Definition: cJSON.h:172