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