FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
interface_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_INTERFACE_CMDS_H__
17 #define __VOM_INTERFACE_CMDS_H__
18 
19 #include <vapi/vapi.hpp>
20 
21 #include "vom/dump_cmd.hpp"
22 #include "vom/event_cmd.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/rpc_cmd.hpp"
25 
26 #include <vapi/af_packet.api.vapi.hpp>
27 #include <vapi/interface.api.vapi.hpp>
28 #include <vapi/tap.api.vapi.hpp>
29 #include <vapi/vhost_user.api.vapi.hpp>
30 #include <vapi/vpe.api.vapi.hpp>
31 
32 namespace VOM {
33 
34 namespace interface_cmds {
35 /**
36  * Factory method to construct a new interface from the VPP record
37  */
38 std::unique_ptr<interface> new_interface(
39  const vapi_payload_sw_interface_details& vd);
40 
41 /**
42  * A command class to create Loopback interfaces in VPP
43  */
44 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
45 {
46 public:
47  /**
48  * Constructor taking the HW::item to update
49  * and the name of the interface to create
50  */
51  loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
52  ~loopback_create_cmd() = default;
53 
54  /**
55  * Issue the command to VPP/HW
56  */
57  rc_t issue(connection& con);
58 
59  /**
60  * convert to string format for debug purposes
61  */
62  std::string to_string() const;
63 };
64 
65 /**
66  * A command class to create af_packet interfaces in VPP
67  */
69  : public interface::create_cmd<vapi::Af_packet_create>
70 {
71 public:
72  /**
73  * Constructor taking the HW::item to update
74  * and the name of the interface to create
75  */
76  af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
77  ~af_packet_create_cmd() = default;
78  /**
79  * Issue the command to VPP/HW
80  */
81  rc_t issue(connection& con);
82  /**
83  * convert to string format for debug purposes
84  */
85  std::string to_string() const;
86 };
87 
88 /**
89  * A functor class that creates an interface
90  */
92  : public interface::create_cmd<vapi::Create_vhost_user_if>
93 {
94 public:
96  const std::string& name,
97  const std::string& tag);
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 private:
109  const std::string m_tag;
110 };
111 
112 /**
113  * A command class to delete loopback interfaces in VPP
114  */
115 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
116 {
117 public:
118  /**
119  * Constructor taking the HW::item to update
120  */
122 
123  /**
124  * Issue the command to VPP/HW
125  */
126  rc_t issue(connection& con);
127  /**
128  * convert to string format for debug purposes
129  */
130  std::string to_string() const;
131 };
132 
133 /**
134  * A command class to delete af-packet interfaces in VPP
135  */
137  : public interface::delete_cmd<vapi::Af_packet_delete>
138 {
139 public:
140  /**
141  * Constructor taking the HW::item to update
142  * and the name of the interface to delete
143  */
144  af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
145 
146  /**
147  * Issue the command to VPP/HW
148  */
149  rc_t issue(connection& con);
150  /**
151  * convert to string format for debug purposes
152  */
153  std::string to_string() const;
154 };
155 
156 /**
157  * A functor class that deletes a Vhost interface
158  */
160  : public interface::delete_cmd<vapi::Delete_vhost_user_if>
161 {
162 public:
163  vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
164 
165  /**
166  * Issue the command to VPP/HW
167  */
168  rc_t issue(connection& con);
169  /**
170  * convert to string format for debug purposes
171  */
172  std::string to_string() const;
173 };
174 
175 /**
176  * A command class to set tag on interfaces
177  */
178 class set_tag
179  : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
180 {
181 public:
182  /**
183  * Constructor taking the HW::item to update
184  */
185  set_tag(HW::item<handle_t>& item, const std::string& name);
186 
187  /**
188  * Issue the command to VPP/HW
189  */
190  rc_t issue(connection& con);
191 
192  /**
193  * convert to string format for debug purposes
194  */
195  std::string to_string() const;
196 
197  /**
198  * Comparison operator - only used for UT
199  */
200  bool operator==(const set_tag& i) const;
201 
202 private:
203  /**
204  * The tag to add
205  */
206  const std::string m_name;
207 };
208 
209 /**
210  * A cmd class that changes the admin state
211  */
212 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
213  vapi::Sw_interface_set_flags>
214 {
215 public:
216  /**
217  * Constructor taking the HW::item to update
218  * and the name handle of the interface whose state is to change
219  */
221  const HW::item<handle_t>& h);
222 
223  /**
224  * Issue the command to VPP/HW
225  */
226  rc_t issue(connection& con);
227  /**
228  * convert to string format for debug purposes
229  */
230  std::string to_string() const;
231 
232  /**
233  * Comparison operator - only used for UT
234  */
235  bool operator==(const state_change_cmd& i) const;
236 
237 private:
238  /**
239  * the handle of the interface to update
240  */
241  const HW::item<handle_t>& m_hdl;
242 };
243 
244 /**
245  * A command class that binds an interface to an L3 table
246  */
248  : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
249 {
250 public:
251  /**
252  * Constructor taking the HW::item to update
253  * and the name handle of the interface whose table is to change
254  */
256  const l3_proto_t& proto,
257  const HW::item<handle_t>& h);
258 
259  /**
260  * Issue the command to VPP/HW
261  */
262  rc_t issue(connection& con);
263 
264  /**
265  * convert to string format for debug purposes
266  */
267  std::string to_string() const;
268 
269  /**
270  * Comparison operator - only used for UT
271  */
272  bool operator==(const set_table_cmd& i) const;
273 
274 private:
275  /**
276  * the handle of the interface to update
277  */
278  const HW::item<handle_t>& m_hdl;
279 
280  /**
281  * The L3 protocol of the table
282  */
283  l3_proto_t m_proto;
284 };
285 
286 /**
287  * A command class that changes the MAC address on an interface
288  */
290  : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
291 {
292 public:
293  /**
294  * Constructor taking the HW::item to update
295  * and the handle of the interface
296  */
298 
299  /**
300  * Issue the command to VPP/HW
301  */
302  rc_t issue(connection& con);
303 
304  /**
305  * convert to string format for debug purposes
306  */
307  std::string to_string() const;
308 
309  /**
310  * Comparison operator - only used for UT
311  */
312  bool operator==(const set_mac_cmd& i) const;
313 
314 private:
315  /**
316  * the handle of the interface to update
317  */
318  const HW::item<handle_t>& m_hdl;
319 };
320 
321 /**
322  * A command class that enables detailed stats collection on an interface
323  */
325  : public rpc_cmd<HW::item<interface::stats_type_t>,
326  vapi::Collect_detailed_interface_stats>
327 {
328 public:
329  /**
330  * Constructor taking the HW::item to update
331  * and the handle of the interface
332  */
334  const handle_t& h,
335  bool enable);
336 
337  /**
338  * Issue the command to VPP/HW
339  */
340  rc_t issue(connection& con);
341 
342  /**
343  * convert to string format for debug purposes
344  */
345  std::string to_string() const;
346 
347  /**
348  * Comparison operator - only used for UT
349  */
350  bool operator==(const collect_detail_stats_change_cmd& i) const;
351 
352 private:
353  /**
354  * the handle of the interface to update
355  */
356  const handle_t& m_hdl;
357 
358  /**
359  * enable or disable the detailed stats collection
360  */
361  bool m_enable;
362 };
363 
364 /**
365  * A command class represents our desire to recieve interface events
366  */
368  : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
369 {
370 public:
371  /**
372  * Constructor taking the listner to notify
373  */
375 
376  /**
377  * Issue the command to VPP/HW
378  */
379  rc_t issue(connection& con);
380 
381  /**
382  * Retires the command - unsubscribe from the events.
383  */
384  void retire(connection& con);
385 
386  /**
387  * convert to string format for debug purposes
388  */
389  std::string to_string() const;
390 
391  /**
392  * Comparison operator - only used for UT
393  */
394  bool operator==(const events_cmd& i) const;
395 
396  /**
397  * Called when it's time to poke the listeners
398  */
399  void notify();
400 
401 private:
402  /**
403  * The listeners to notify when data/events arrive
404  */
405  interface::event_listener& m_listener;
406 };
407 
408 /**
409  * A cmd class that Dumps all the Vpp interfaces
410  */
411 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
412 {
413 public:
414  /**
415  * Default Constructor
416  */
417  dump_cmd();
418 
419  /**
420  * Issue the command to VPP/HW
421  */
422  rc_t issue(connection& con);
423  /**
424  * convert to string format for debug purposes
425  */
426  std::string to_string() const;
427 
428  /**
429  * Comparison operator - only used for UT
430  */
431  bool operator==(const dump_cmd& i) const;
432 };
433 
434 /**
435  * A cmd class that Dumps all the Vpp Interfaces
436  */
437 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
438 {
439 public:
440  /**
441  * Default Constructor
442  */
443  vhost_dump_cmd();
444 
445  /**
446  * Issue the command to VPP/HW
447  */
448  rc_t issue(connection& con);
449  /**
450  * convert to string format for debug purposes
451  */
452  std::string to_string() const;
453 
454  /**
455  * Comparison operator - only used for UT
456  */
457  bool operator==(const vhost_dump_cmd& i) const;
458 };
459 
460 /**
461  * A cmd class that Dumps all the Vpp interfaces
462  */
463 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
464 {
465 public:
466  /**
467  * Default Constructor
468  */
469  af_packet_dump_cmd() = default;
470 
471  /**
472  * Issue the command to VPP/HW
473  */
474  rc_t issue(connection& con);
475  /**
476  * convert to string format for debug purposes
477  */
478  std::string to_string() const;
479 
480  /**
481  * Comparison operator - only used for UT
482  */
483  bool operator==(const af_packet_dump_cmd& i) const;
484 };
485 };
486 };
487 /*
488  * fd.io coding-style-patch-verification: ON
489  *
490  * Local Variables:
491  * eval: (c-set-style "mozilla")
492  * End:
493  */
494 #endif
std::string to_string() const
convert to string format for debug purposes
A cmd class that Dumps all the Vpp interfaces.
static clib_error_t * set_tag(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int i
A command class to set tag on interfaces.
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route...
Definition: prefix.hpp:52
virtual void retire(connection &con)
Retire/cancel a long running command.
Definition: rpc_cmd.hpp:128
A command class that enables detailed stats collection on an interface.
C++ VPP API.
A command class that changes the MAC address on an interface.
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:361
A representation of the connection to VPP.
Definition: connection.hpp:33
std::unique_ptr< interface > new_interface(const vapi_payload_sw_interface_details &vd)
Factory method to construct a new interface from the VPP record.
A class that listens to interface Events.
Definition: interface.hpp:428
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
u8 name[64]
Definition: memclnt.api:152
A command class to create Loopback interfaces in VPP.
A cmd class that changes the admin state.
A command class that binds an interface to an L3 table.
virtual bool operator==(const create_cmd &o) const
Comparison operator - only used for UT.
Definition: interface.hpp:318
A command class represents our desire to recieve interface events.
A cmd class that Dumps all the Vpp Interfaces.
Base class for intterface Delete commands.
Definition: interface.hpp:368
A command class to create af_packet interfaces in VPP.
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
A functor class that deletes a Vhost interface.
A command class to delete af-packet interfaces in VPP.
A base class for interface Create commands.
Definition: interface.hpp:301
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A command class to delete loopback interfaces in VPP.
A functor class that creates an interface.
An Event command base class.
Definition: event_cmd.hpp:39
A cmd class that Dumps all the Vpp interfaces.
loopback_create_cmd(HW::item< handle_t > &item, const std::string &name)
Constructor taking the HW::item to update and the name of the interface to create.
A base class for VPP dump commands.
Definition: dump_cmd.hpp:43
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
rc_t issue(connection &con)
Issue the command to VPP/HW.