FD.io VPP  v18.04-17-g3a0d853
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 command class to create TAP interfaces in VPP
91 */
92 class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect>
93 {
94 public:
95  /**
96  * Constructor taking the HW::item to update
97  * and the name of the interface to create
98  */
99  tap_create_cmd(HW::item<handle_t>& item, const std::string& name);
100  ~tap_create_cmd() = default;
101 
102  /**
103  * Issue the command to VPP/HW
104  */
105  rc_t issue(connection& con);
106 
107  /**
108  * convert to string format for debug purposes
109  */
110  std::string to_string() const;
111 };
112 
113 /**
114  * A functor class that creates an interface
115  */
117  : public interface::create_cmd<vapi::Create_vhost_user_if>
118 {
119 public:
121  const std::string& name,
122  const std::string& tag);
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 private:
134  const std::string m_tag;
135 };
136 
137 /**
138  * A command class to delete loopback interfaces in VPP
139  */
140 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
141 {
142 public:
143  /**
144  * Constructor taking the HW::item to update
145  */
147 
148  /**
149  * Issue the command to VPP/HW
150  */
151  rc_t issue(connection& con);
152  /**
153  * convert to string format for debug purposes
154  */
155  std::string to_string() const;
156 };
157 
158 /**
159  * A command class to delete af-packet interfaces in VPP
160  */
162  : public interface::delete_cmd<vapi::Af_packet_delete>
163 {
164 public:
165  /**
166  * Constructor taking the HW::item to update
167  * and the name of the interface to delete
168  */
169  af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
170 
171  /**
172  * Issue the command to VPP/HW
173  */
174  rc_t issue(connection& con);
175  /**
176  * convert to string format for debug purposes
177  */
178  std::string to_string() const;
179 };
180 
181 /**
182 * A command class to delete TAP interfaces in VPP
183 */
184 class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete>
185 {
186 public:
187  /**
188  * Constructor taking the HW::item to update
189  */
191 
192  /**
193  * Issue the command to VPP/HW
194  */
195  rc_t issue(connection& con);
196  /**
197  * convert to string format for debug purposes
198  */
199  std::string to_string() const;
200 };
201 
202 /**
203  * A functor class that deletes a Vhost interface
204  */
206  : public interface::delete_cmd<vapi::Delete_vhost_user_if>
207 {
208 public:
209  vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
210 
211  /**
212  * Issue the command to VPP/HW
213  */
214  rc_t issue(connection& con);
215  /**
216  * convert to string format for debug purposes
217  */
218  std::string to_string() const;
219 };
220 
221 /**
222  * A command class to set tag on interfaces
223  */
224 class set_tag
225  : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del>
226 {
227 public:
228  /**
229  * Constructor taking the HW::item to update
230  */
231  set_tag(HW::item<handle_t>& item, const std::string& name);
232 
233  /**
234  * Issue the command to VPP/HW
235  */
236  rc_t issue(connection& con);
237 
238  /**
239  * convert to string format for debug purposes
240  */
241  std::string to_string() const;
242 
243  /**
244  * Comparison operator - only used for UT
245  */
246  bool operator==(const set_tag& i) const;
247 
248 private:
249  /**
250  * The tag to add
251  */
252  const std::string m_name;
253 };
254 
255 /**
256  * A cmd class that changes the admin state
257  */
258 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
259  rc_t,
260  vapi::Sw_interface_set_flags>
261 {
262 public:
263  /**
264  * Constructor taking the HW::item to update
265  * and the name handle of the interface whose state is to change
266  */
268  const HW::item<handle_t>& h);
269 
270  /**
271  * Issue the command to VPP/HW
272  */
273  rc_t issue(connection& con);
274  /**
275  * convert to string format for debug purposes
276  */
277  std::string to_string() const;
278 
279  /**
280  * Comparison operator - only used for UT
281  */
282  bool operator==(const state_change_cmd& i) const;
283 
284 private:
285  /**
286  * the handle of the interface to update
287  */
288  const HW::item<handle_t>& m_hdl;
289 };
290 
291 /**
292  * A command class that binds an interface to an L3 table
293  */
294 class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
295  rc_t,
296  vapi::Sw_interface_set_table>
297 {
298 public:
299  /**
300  * Constructor taking the HW::item to update
301  * and the name handle of the interface whose table is to change
302  */
304  const l3_proto_t& proto,
305  const HW::item<handle_t>& h);
306 
307  /**
308  * Issue the command to VPP/HW
309  */
310  rc_t issue(connection& con);
311 
312  /**
313  * convert to string format for debug purposes
314  */
315  std::string to_string() const;
316 
317  /**
318  * Comparison operator - only used for UT
319  */
320  bool operator==(const set_table_cmd& i) const;
321 
322 private:
323  /**
324  * the handle of the interface to update
325  */
326  const HW::item<handle_t>& m_hdl;
327 
328  /**
329  * The L3 protocol of the table
330  */
331  l3_proto_t m_proto;
332 };
333 
334 /**
335  * A command class that changes the MAC address on an interface
336  */
337 class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
338  rc_t,
339  vapi::Sw_interface_set_mac_address>
340 {
341 public:
342  /**
343  * Constructor taking the HW::item to update
344  * and the handle of the interface
345  */
347 
348  /**
349  * Issue the command to VPP/HW
350  */
351  rc_t issue(connection& con);
352 
353  /**
354  * convert to string format for debug purposes
355  */
356  std::string to_string() const;
357 
358  /**
359  * Comparison operator - only used for UT
360  */
361  bool operator==(const set_mac_cmd& i) const;
362 
363 private:
364  /**
365  * the handle of the interface to update
366  */
367  const HW::item<handle_t>& m_hdl;
368 };
369 
370 /**
371  * A command class that enables detailed stats collection on an interface
372  */
374  : public rpc_cmd<HW::item<interface::stats_type_t>,
375  rc_t,
376  vapi::Collect_detailed_interface_stats>
377 {
378 public:
379  /**
380  * Constructor taking the HW::item to update
381  * and the handle of the interface
382  */
384  const handle_t& h,
385  bool enable);
386 
387  /**
388  * Issue the command to VPP/HW
389  */
390  rc_t issue(connection& con);
391 
392  /**
393  * convert to string format for debug purposes
394  */
395  std::string to_string() const;
396 
397  /**
398  * Comparison operator - only used for UT
399  */
400  bool operator==(const collect_detail_stats_change_cmd& i) const;
401 
402 private:
403  /**
404  * the handle of the interface to update
405  */
406  const handle_t& m_hdl;
407 
408  /**
409  * enable or disable the detailed stats collection
410  */
411  bool m_enable;
412 };
413 
414 /**
415  * A command class represents our desire to recieve interface events
416  */
418  : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
419 {
420 public:
421  /**
422  * Constructor taking the listner to notify
423  */
425 
426  /**
427  * Issue the command to VPP/HW
428  */
429  rc_t issue(connection& con);
430 
431  /**
432  * Retires the command - unsubscribe from the events.
433  */
434  void retire(connection& con);
435 
436  /**
437  * convert to string format for debug purposes
438  */
439  std::string to_string() const;
440 
441  /**
442  * Comparison operator - only used for UT
443  */
444  bool operator==(const events_cmd& i) const;
445 
446  /**
447  * Called when it's time to poke the listeners
448  */
449  void notify();
450 
451 private:
452  /**
453  * The listeners to notify when data/events arrive
454  */
455  interface::event_listener& m_listener;
456 };
457 
458 /**
459  * A command class represents our desire to recieve interface stats
460  */
462  : public event_cmd<vapi::Want_per_interface_combined_stats,
463  vapi::Vnet_per_interface_combined_counters>
464 {
465 public:
466  /**
467  * Constructor taking the listner to notify
468  */
470 
471  /**
472  * Issue the command to VPP/HW
473  */
474  rc_t issue(connection& con);
475 
476  /**
477  * Retires the command - unsubscribe from the stats.
478  */
479  void retire(connection& con);
480 
481  /**
482  * convert to string format for debug purposes
483  */
484  std::string to_string() const;
485 
486  /**
487  * (re)set status
488  */
489  void set(const rc_t& rc);
490 
491  /**
492  * get listener
493  */
494  interface::stat_listener& listener() const;
495 
496  /**
497  * Comparison operator - only used for UT
498  */
499  bool operator==(const stats_enable_cmd& i) const;
500 
501  /**
502  * Called when it's time to poke the listeners
503  */
504  void notify();
505 
506 private:
507  /**
508  * The listeners to notify when data/stats arrive
509  */
510  interface::stat_listener& m_listener;
511 
512  /**
513  * The interface on which we are enabling states
514  */
515  const handle_t& m_swifindex;
516 };
517 
518 /**
519  * A command class represents our desire to recieve interface stats
520  */
522  : public rpc_cmd<HW::item<bool>,
523  rc_t,
524  vapi::Want_per_interface_combined_stats>
525 {
526 public:
527  /**
528  * Constructor taking the listner to notify
529  */
530  stats_disable_cmd(const handle_t& handle);
531 
532  /**
533  * Issue the command to VPP/HW
534  */
535  rc_t issue(connection& con);
536 
537  /**
538  * convert to string format for debug purposes
539  */
540  std::string to_string() const;
541 
542  /**
543  * Comparison operator - only used for UT
544  */
545  bool operator==(const stats_disable_cmd& i) const;
546 
547 private:
548  HW::item<bool> m_res;
549  /**
550  * The interface on which we are disabling states
551  */
552  handle_t m_swifindex;
553 };
554 
555 /**
556  * A cmd class that Dumps all the Vpp interfaces
557  */
558 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
559 {
560 public:
561  /**
562  * Default Constructor
563  */
564  dump_cmd();
565 
566  /**
567  * Issue the command to VPP/HW
568  */
569  rc_t issue(connection& con);
570  /**
571  * convert to string format for debug purposes
572  */
573  std::string to_string() const;
574 
575  /**
576  * Comparison operator - only used for UT
577  */
578  bool operator==(const dump_cmd& i) const;
579 };
580 
581 /**
582  * A cmd class that Dumps all the Vpp Interfaces
583  */
584 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
585 {
586 public:
587  /**
588  * Default Constructor
589  */
590  vhost_dump_cmd();
591 
592  /**
593  * Issue the command to VPP/HW
594  */
595  rc_t issue(connection& con);
596  /**
597  * convert to string format for debug purposes
598  */
599  std::string to_string() const;
600 
601  /**
602  * Comparison operator - only used for UT
603  */
604  bool operator==(const vhost_dump_cmd& i) const;
605 };
606 };
607 };
608 /*
609  * fd.io coding-style-patch-verification: ON
610  *
611  * Local Variables:
612  * eval: (c-set-style "mozilla")
613  * End:
614  */
615 #endif
std::string to_string() const
convert to string format for debug purposes
A command class represents our desire to recieve interface stats.
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:90
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
A command class to create TAP interfaces in VPP.
A command class that enables detailed stats collection on an interface.
C++ VPP API.
virtual void retire(connection &con)
Retire/cancel a long running command.
Definition: rpc_cmd.hpp:129
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:330
A representation of the connection to VPP.
Definition: connection.hpp:33
A command class to delete TAP interfaces in VPP.
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:414
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
A class that listens to interface Events.
Definition: interface.hpp:385
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:286
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:337
A command class to create af_packet interfaces in VPP.
A type declaration of an interface handle in VPP.
Definition: types.hpp:236
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:269
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
rc_t issue(connection &con)
Issue the command to VPP/HW.