FD.io VPP  v21.01.1
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  */
48  rc_t issue(connection& con);
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  */
102  rc_t issue(connection& con);
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  */
140  rc_t issue(connection& con);
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  */
184  rc_t issue(connection& con);
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  */
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
string hostname[64]
Definition: dhcp.api:159
const char *const string
Definition: cJSON.h:172
A functor class represents our desire to recieve interface events.
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
virtual void retire(connection &con)
Retire/cancel a long running command.
Definition: rpc_cmd.hpp:128
A class that listens to DHCP Events.
Definition: dhcp_client.hpp:83
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
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.
A representation of the connection to VPP.
Definition: connection.hpp:33
vl_api_ip_dscp_t dscp
Definition: dhcp.api:163
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
virtual void succeeded()
Called by the HW Command Q when it is disabled to indicate the command can be considered successful w...
Definition: rpc_cmd.hpp:103
IP DSCP values.
Definition: prefix.hpp:81
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
std::string to_string() const
convert to string format for debug purposes
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
An Event command base class.
Definition: event_cmd.hpp:39
rc_t issue(connection &con)
Issue the command to VPP/HW.
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
A cmd class that Unbinds Dhcp Config from an interface.
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
A command class that binds the DHCP config to the interface.
A cmd class that Dumps all the DHCP clients.
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66