vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / interface_cmds.hpp
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/l2.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 bvi interfaces in VPP
43  */
44 class bvi_create_cmd : public interface::create_cmd<vapi::Bvi_create>
45 {
46 public:
47   /**
48    * Constructor taking the HW::item to update
49    * and the name of the interface to create
50    */
51   bvi_create_cmd(HW::item<handle_t>& item, const std::string& name);
52   ~bvi_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 Loopback interfaces in VPP
67  */
68 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
69 {
70 public:
71   /**
72    * Constructor taking the HW::item to update
73    * and the name of the interface to create
74    */
75   loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
76   ~loopback_create_cmd() = default;
77
78   /**
79    * Issue the command to VPP/HW
80    */
81   rc_t issue(connection& con);
82
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 af_packet interfaces in VPP
91  */
92 class af_packet_create_cmd
93   : public interface::create_cmd<vapi::Af_packet_create>
94 {
95 public:
96   /**
97    * Constructor taking the HW::item to update
98    * and the name of the interface to create
99    */
100   af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
101   ~af_packet_create_cmd() = default;
102   /**
103    * Issue the command to VPP/HW
104    */
105   rc_t issue(connection& con);
106   /**
107    * convert to string format for debug purposes
108    */
109   std::string to_string() const;
110 };
111
112 /**
113  * A functor class that creates an interface
114  */
115 class vhost_create_cmd
116   : public interface::create_cmd<vapi::Create_vhost_user_if>
117 {
118 public:
119   vhost_create_cmd(HW::item<handle_t>& item,
120                    const std::string& name,
121                    const std::string& tag);
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 private:
133   const std::string m_tag;
134 };
135
136 /**
137  * A command class to delete bvi interfaces in VPP
138  */
139 class bvi_delete_cmd : public interface::delete_cmd<vapi::Bvi_delete>
140 {
141 public:
142   /**
143    * Constructor taking the HW::item to update
144    */
145   bvi_delete_cmd(HW::item<handle_t>& item);
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 command class to delete loopback interfaces in VPP
159  */
160 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
161 {
162 public:
163   /**
164    * Constructor taking the HW::item to update
165    */
166   loopback_delete_cmd(HW::item<handle_t>& item);
167
168   /**
169    * Issue the command to VPP/HW
170    */
171   rc_t issue(connection& con);
172   /**
173    * convert to string format for debug purposes
174    */
175   std::string to_string() const;
176 };
177
178 /**
179  * A command class to delete af-packet interfaces in VPP
180  */
181 class af_packet_delete_cmd
182   : public interface::delete_cmd<vapi::Af_packet_delete>
183 {
184 public:
185   /**
186    * Constructor taking the HW::item to update
187    * and the name of the interface to delete
188    */
189   af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
190
191   /**
192    * Issue the command to VPP/HW
193    */
194   rc_t issue(connection& con);
195   /**
196    * convert to string format for debug purposes
197    */
198   std::string to_string() const;
199 };
200
201 /**
202  * A functor class that deletes a Vhost interface
203  */
204 class vhost_delete_cmd
205   : public interface::delete_cmd<vapi::Delete_vhost_user_if>
206 {
207 public:
208   vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
209
210   /**
211    * Issue the command to VPP/HW
212    */
213   rc_t issue(connection& con);
214   /**
215    * convert to string format for debug purposes
216    */
217   std::string to_string() const;
218 };
219
220 /**
221  * A command class to set tag on interfaces
222  */
223 class set_tag
224   : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
225 {
226 public:
227   /**
228    * Constructor taking the HW::item to update
229    */
230   set_tag(HW::item<handle_t>& item, const std::string& name);
231
232   /**
233    * Issue the command to VPP/HW
234    */
235   rc_t issue(connection& con);
236
237   /**
238    * convert to string format for debug purposes
239    */
240   std::string to_string() const;
241
242   /**
243    * Comparison operator - only used for UT
244    */
245   bool operator==(const set_tag& i) const;
246
247 private:
248   /**
249    * The tag to add
250    */
251   const std::string m_name;
252 };
253
254 /**
255  * A cmd class that changes the admin state
256  */
257 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
258                                         vapi::Sw_interface_set_flags>
259 {
260 public:
261   /**
262    * Constructor taking the HW::item to update
263    * and the name handle of the interface whose state is to change
264    */
265   state_change_cmd(HW::item<interface::admin_state_t>& s,
266                    const HW::item<handle_t>& h);
267
268   /**
269    * Issue the command to VPP/HW
270    */
271   rc_t issue(connection& con);
272   /**
273    * convert to string format for debug purposes
274    */
275   std::string to_string() const;
276
277   /**
278    * Comparison operator - only used for UT
279    */
280   bool operator==(const state_change_cmd& i) const;
281
282 private:
283   /**
284    * the handle of the interface to update
285    */
286   const HW::item<handle_t>& m_hdl;
287 };
288
289 /**
290  * A command class that binds an interface to an L3 table
291  */
292 class set_table_cmd
293   : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
294 {
295 public:
296   /**
297    * Constructor taking the HW::item to update
298    * and the name handle of the interface whose table is to change
299    */
300   set_table_cmd(HW::item<route::table_id_t>& item,
301                 const l3_proto_t& proto,
302                 const HW::item<handle_t>& h);
303
304   /**
305    * Issue the command to VPP/HW
306    */
307   rc_t issue(connection& con);
308
309   /**
310    * convert to string format for debug purposes
311    */
312   std::string to_string() const;
313
314   /**
315    * Comparison operator - only used for UT
316    */
317   bool operator==(const set_table_cmd& i) const;
318
319 private:
320   /**
321    * the handle of the interface to update
322    */
323   const HW::item<handle_t>& m_hdl;
324
325   /**
326    * The L3 protocol of the table
327    */
328   l3_proto_t m_proto;
329 };
330
331 /**
332  * A command class that changes the MAC address on an interface
333  */
334 class set_mac_cmd
335   : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
336 {
337 public:
338   /**
339    * Constructor taking the HW::item to update
340    * and the handle of the interface
341    */
342   set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
343
344   /**
345    * Issue the command to VPP/HW
346    */
347   rc_t issue(connection& con);
348
349   /**
350    * convert to string format for debug purposes
351    */
352   std::string to_string() const;
353
354   /**
355    * Comparison operator - only used for UT
356    */
357   bool operator==(const set_mac_cmd& i) const;
358
359 private:
360   /**
361    * the handle of the interface to update
362    */
363   const HW::item<handle_t>& m_hdl;
364 };
365
366 /**
367  * A command class that enables detailed stats collection on an interface
368  */
369 class collect_detail_stats_change_cmd
370   : public rpc_cmd<HW::item<interface::stats_type_t>,
371                    vapi::Collect_detailed_interface_stats>
372 {
373 public:
374   /**
375    * Constructor taking the HW::item to update
376    * and the handle of the interface
377    */
378   collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
379                                   const handle_t& h,
380                                   bool enable);
381
382   /**
383    * Issue the command to VPP/HW
384    */
385   rc_t issue(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 collect_detail_stats_change_cmd& i) const;
396
397 private:
398   /**
399    * the handle of the interface to update
400    */
401   const handle_t& m_hdl;
402
403   /**
404    * enable or disable the detailed stats collection
405    */
406   bool m_enable;
407 };
408
409 /**
410  * A command class represents our desire to recieve interface events
411  */
412 class events_cmd
413   : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
414 {
415 public:
416   /**
417    * Constructor taking the listner to notify
418    */
419   events_cmd(interface::event_listener& el);
420
421   /**
422    * Issue the command to VPP/HW
423    */
424   rc_t issue(connection& con);
425
426   /**
427    * Retires the command - unsubscribe from the events.
428    */
429   void retire(connection& con);
430
431   /**
432    * convert to string format for debug purposes
433    */
434   std::string to_string() const;
435
436   /**
437    * Comparison operator - only used for UT
438    */
439   bool operator==(const events_cmd& i) const;
440
441   /**
442    * Called when it's time to poke the listeners
443    */
444   void notify();
445
446 private:
447   /**
448    * The listeners to notify when data/events arrive
449    */
450   interface::event_listener& m_listener;
451 };
452
453 /**
454  * A cmd class that Dumps all the Vpp interfaces
455  */
456 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
457 {
458 public:
459   /**
460    * Default Constructor
461    */
462   dump_cmd();
463
464   /**
465    * Issue the command to VPP/HW
466    */
467   rc_t issue(connection& con);
468   /**
469    * convert to string format for debug purposes
470    */
471   std::string to_string() const;
472
473   /**
474    * Comparison operator - only used for UT
475    */
476   bool operator==(const dump_cmd& i) const;
477 };
478
479 /**
480  * A cmd class that Dumps all the Vpp Interfaces
481  */
482 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
483 {
484 public:
485   /**
486    * Default Constructor
487    */
488   vhost_dump_cmd();
489
490   /**
491    * Issue the command to VPP/HW
492    */
493   rc_t issue(connection& con);
494   /**
495    * convert to string format for debug purposes
496    */
497   std::string to_string() const;
498
499   /**
500    * Comparison operator - only used for UT
501    */
502   bool operator==(const vhost_dump_cmd& i) const;
503 };
504
505 /**
506  * A cmd class that Dumps all the Vpp interfaces
507  */
508 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
509 {
510 public:
511   /**
512    * Default Constructor
513    */
514   af_packet_dump_cmd() = default;
515
516   /**
517    * Issue the command to VPP/HW
518    */
519   rc_t issue(connection& con);
520   /**
521    * convert to string format for debug purposes
522    */
523   std::string to_string() const;
524
525   /**
526    * Comparison operator - only used for UT
527    */
528   bool operator==(const af_packet_dump_cmd& i) const;
529 };
530 };
531 };
532 /*
533  * fd.io coding-style-patch-verification: ON
534  *
535  * Local Variables:
536  * eval: (c-set-style "mozilla")
537  * End:
538  */
539 #endif