FD.io VPP  v18.11-rc0-18-g2a3fb1a
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/stats.api.vapi.hpp>
29 #include <vapi/tap.api.vapi.hpp>
30 #include <vapi/vhost_user.api.vapi.hpp>
31 #include <vapi/vpe.api.vapi.hpp>
32 
33 namespace VOM {
34 
35 namespace interface_cmds {
36 /**
37  * Factory method to construct a new interface from the VPP record
38  */
39 std::unique_ptr<interface> new_interface(
40  const vapi_payload_sw_interface_details& vd);
41 
42 /**
43  * A command class to create Loopback interfaces in VPP
44  */
45 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
46 {
47 public:
48  /**
49  * Constructor taking the HW::item to update
50  * and the name of the interface to create
51  */
52  loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
53  ~loopback_create_cmd() = default;
54 
55  /**
56  * Issue the command to VPP/HW
57  */
58  rc_t issue(connection& con);
59 
60  /**
61  * convert to string format for debug purposes
62  */
63  std::string to_string() const;
64 };
65 
66 /**
67  * A command class to create af_packet interfaces in VPP
68  */
70  : public interface::create_cmd<vapi::Af_packet_create>
71 {
72 public:
73  /**
74  * Constructor taking the HW::item to update
75  * and the name of the interface to create
76  */
77  af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
78  ~af_packet_create_cmd() = default;
79  /**
80  * Issue the command to VPP/HW
81  */
82  rc_t issue(connection& con);
83  /**
84  * convert to string format for debug purposes
85  */
86  std::string to_string() const;
87 };
88 
89 /**
90  * A functor class that creates an interface
91  */
93  : public interface::create_cmd<vapi::Create_vhost_user_if>
94 {
95 public:
97  const std::string& name,
98  const std::string& tag);
99 
100  /**
101  * Issue the command to VPP/HW
102  */
103  rc_t issue(connection& con);
104  /**
105  * convert to string format for debug purposes
106  */
107  std::string to_string() const;
108 
109 private:
110  const std::string m_tag;
111 };
112 
113 /**
114  * A command class to delete loopback interfaces in VPP
115  */
116 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
117 {
118 public:
119  /**
120  * Constructor taking the HW::item to update
121  */
123 
124  /**
125  * Issue the command to VPP/HW
126  */
127  rc_t issue(connection& con);
128  /**
129  * convert to string format for debug purposes
130  */
131  std::string to_string() const;
132 };
133 
134 /**
135  * A command class to delete af-packet interfaces in VPP
136  */
138  : public interface::delete_cmd<vapi::Af_packet_delete>
139 {
140 public:
141  /**
142  * Constructor taking the HW::item to update
143  * and the name of the interface to delete
144  */
145  af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
146 
147  /**
148  * Issue the command to VPP/HW
149  */
150  rc_t issue(connection& con);
151  /**
152  * convert to string format for debug purposes
153  */
154  std::string to_string() const;
155 };
156 
157 /**
158  * A functor class that deletes a Vhost interface
159  */
161  : public interface::delete_cmd<vapi::Delete_vhost_user_if>
162 {
163 public:
164  vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
165 
166  /**
167  * Issue the command to VPP/HW
168  */
169  rc_t issue(connection& con);
170  /**
171  * convert to string format for debug purposes
172  */
173  std::string to_string() const;
174 };
175 
176 /**
177  * A command class to set tag on interfaces
178  */
179 class set_tag
180  : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
181 {
182 public:
183  /**
184  * Constructor taking the HW::item to update
185  */
186  set_tag(HW::item<handle_t>& item, const std::string& name);
187 
188  /**
189  * Issue the command to VPP/HW
190  */
191  rc_t issue(connection& con);
192 
193  /**
194  * convert to string format for debug purposes
195  */
196  std::string to_string() const;
197 
198  /**
199  * Comparison operator - only used for UT
200  */
201  bool operator==(const set_tag& i) const;
202 
203 private:
204  /**
205  * The tag to add
206  */
207  const std::string m_name;
208 };
209 
210 /**
211  * A cmd class that changes the admin state
212  */
213 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
214  vapi::Sw_interface_set_flags>
215 {
216 public:
217  /**
218  * Constructor taking the HW::item to update
219  * and the name handle of the interface whose state is to change
220  */
222  const HW::item<handle_t>& h);
223 
224  /**
225  * Issue the command to VPP/HW
226  */
227  rc_t issue(connection& con);
228  /**
229  * convert to string format for debug purposes
230  */
231  std::string to_string() const;
232 
233  /**
234  * Comparison operator - only used for UT
235  */
236  bool operator==(const state_change_cmd& i) const;
237 
238 private:
239  /**
240  * the handle of the interface to update
241  */
242  const HW::item<handle_t>& m_hdl;
243 };
244 
245 /**
246  * A command class that binds an interface to an L3 table
247  */
249  : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
250 {
251 public:
252  /**
253  * Constructor taking the HW::item to update
254  * and the name handle of the interface whose table is to change
255  */
257  const l3_proto_t& proto,
258  const HW::item<handle_t>& h);
259 
260  /**
261  * Issue the command to VPP/HW
262  */
263  rc_t issue(connection& con);
264 
265  /**
266  * convert to string format for debug purposes
267  */
268  std::string to_string() const;
269 
270  /**
271  * Comparison operator - only used for UT
272  */
273  bool operator==(const set_table_cmd& i) const;
274 
275 private:
276  /**
277  * the handle of the interface to update
278  */
279  const HW::item<handle_t>& m_hdl;
280 
281  /**
282  * The L3 protocol of the table
283  */
284  l3_proto_t m_proto;
285 };
286 
287 /**
288  * A command class that changes the MAC address on an interface
289  */
291  : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
292 {
293 public:
294  /**
295  * Constructor taking the HW::item to update
296  * and the handle of the interface
297  */
299 
300  /**
301  * Issue the command to VPP/HW
302  */
303  rc_t issue(connection& con);
304 
305  /**
306  * convert to string format for debug purposes
307  */
308  std::string to_string() const;
309 
310  /**
311  * Comparison operator - only used for UT
312  */
313  bool operator==(const set_mac_cmd& i) const;
314 
315 private:
316  /**
317  * the handle of the interface to update
318  */
319  const HW::item<handle_t>& m_hdl;
320 };
321 
322 /**
323  * A command class that enables detailed stats collection on an interface
324  */
326  : public rpc_cmd<HW::item<interface::stats_type_t>,
327  vapi::Collect_detailed_interface_stats>
328 {
329 public:
330  /**
331  * Constructor taking the HW::item to update
332  * and the handle of the interface
333  */
335  const handle_t& h,
336  bool enable);
337 
338  /**
339  * Issue the command to VPP/HW
340  */
341  rc_t issue(connection& con);
342 
343  /**
344  * convert to string format for debug purposes
345  */
346  std::string to_string() const;
347 
348  /**
349  * Comparison operator - only used for UT
350  */
351  bool operator==(const collect_detail_stats_change_cmd& i) const;
352 
353 private:
354  /**
355  * the handle of the interface to update
356  */
357  const handle_t& m_hdl;
358 
359  /**
360  * enable or disable the detailed stats collection
361  */
362  bool m_enable;
363 };
364 
365 /**
366  * A command class represents our desire to recieve interface events
367  */
369  : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
370 {
371 public:
372  /**
373  * Constructor taking the listner to notify
374  */
376 
377  /**
378  * Issue the command to VPP/HW
379  */
380  rc_t issue(connection& con);
381 
382  /**
383  * Retires the command - unsubscribe from the events.
384  */
385  void retire(connection& con);
386 
387  /**
388  * convert to string format for debug purposes
389  */
390  std::string to_string() const;
391 
392  /**
393  * Comparison operator - only used for UT
394  */
395  bool operator==(const events_cmd& i) const;
396 
397  /**
398  * Called when it's time to poke the listeners
399  */
400  void notify();
401 
402 private:
403  /**
404  * The listeners to notify when data/events arrive
405  */
406  interface::event_listener& m_listener;
407 };
408 
409 /**
410  * A command class represents our desire to recieve interface stats
411  */
413  : public event_cmd<vapi::Want_per_interface_combined_stats,
414  vapi::Vnet_per_interface_combined_counters>
415 {
416 public:
417  /**
418  * Constructor taking the listner to notify
419  */
421 
422  /**
423  * Issue the command to VPP/HW
424  */
425  rc_t issue(connection& con);
426 
427  /**
428  * Retires the command - unsubscribe from the stats.
429  */
430  void retire(connection& con);
431 
432  /**
433  * convert to string format for debug purposes
434  */
435  std::string to_string() const;
436 
437  /**
438  * (re)set status
439  */
440  void set(const rc_t& rc);
441 
442  /**
443  * get listener
444  */
445  interface::stat_listener& listener() const;
446 
447  /**
448  * Comparison operator - only used for UT
449  */
450  bool operator==(const stats_enable_cmd& i) const;
451 
452  /**
453  * Called when it's time to poke the listeners
454  */
455  void notify();
456 
457 private:
458  /**
459  * The listeners to notify when data/stats arrive
460  */
461  interface::stat_listener& m_listener;
462 
463  /**
464  * The interface on which we are enabling states
465  */
466  const handle_t& m_swifindex;
467 };
468 
469 /**
470  * A command class represents our desire to recieve interface stats
471  */
473  : public rpc_cmd<HW::item<bool>, vapi::Want_per_interface_combined_stats>
474 {
475 public:
476  /**
477  * Constructor taking the listner to notify
478  */
479  stats_disable_cmd(const handle_t& handle);
480 
481  /**
482  * Issue the command to VPP/HW
483  */
484  rc_t issue(connection& con);
485 
486  /**
487  * convert to string format for debug purposes
488  */
489  std::string to_string() const;
490 
491  /**
492  * Comparison operator - only used for UT
493  */
494  bool operator==(const stats_disable_cmd& i) const;
495 
496 private:
497  HW::item<bool> m_res;
498  /**
499  * The interface on which we are disabling states
500  */
501  handle_t m_swifindex;
502 };
503 
504 /**
505  * A cmd class that Dumps all the Vpp interfaces
506  */
507 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
508 {
509 public:
510  /**
511  * Default Constructor
512  */
513  dump_cmd();
514 
515  /**
516  * Issue the command to VPP/HW
517  */
518  rc_t issue(connection& con);
519  /**
520  * convert to string format for debug purposes
521  */
522  std::string to_string() const;
523 
524  /**
525  * Comparison operator - only used for UT
526  */
527  bool operator==(const dump_cmd& i) const;
528 };
529 
530 /**
531  * A cmd class that Dumps all the Vpp Interfaces
532  */
533 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
534 {
535 public:
536  /**
537  * Default Constructor
538  */
539  vhost_dump_cmd();
540 
541  /**
542  * Issue the command to VPP/HW
543  */
544  rc_t issue(connection& con);
545  /**
546  * convert to string format for debug purposes
547  */
548  std::string to_string() const;
549 
550  /**
551  * Comparison operator - only used for UT
552  */
553  bool operator==(const vhost_dump_cmd& i) const;
554 };
555 
556 /**
557  * A cmd class that Dumps all the Vpp interfaces
558  */
559 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
560 {
561 public:
562  /**
563  * Default Constructor
564  */
565  af_packet_dump_cmd() = default;
566 
567  /**
568  * Issue the command to VPP/HW
569  */
570  rc_t issue(connection& con);
571  /**
572  * convert to string format for debug purposes
573  */
574  std::string to_string() const;
575 
576  /**
577  * Comparison operator - only used for UT
578  */
579  bool operator==(const af_packet_dump_cmd& i) const;
580 };
581 };
582 };
583 /*
584  * fd.io coding-style-patch-verification: ON
585  *
586  * Local Variables:
587  * eval: (c-set-style "mozilla")
588  * End:
589  */
590 #endif
std::string to_string() const
convert to string format for debug purposes
A command class represents our desire to recieve interface stats.
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:84
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route...
Definition: prefix.hpp:53
virtual void retire(connection &con)
Retire/cancel a long running command.
Definition: rpc_cmd.hpp:126
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:343
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 Stats.
Definition: interface.hpp:427
A class that listens to interface Events.
Definition: interface.hpp:398
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:38
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:301
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:350
A command class to create af_packet interfaces in VPP.
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
A functor class that deletes a Vhost interface.
A command class represents our desire to recieve interface stats.
A command class to delete af-packet interfaces in VPP.
A base class for interface Create commands.
Definition: interface.hpp:284
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:64
rc_t issue(connection &con)
Issue the command to VPP/HW.