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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_INTERFACE_CMDS_H__
17 #define __VOM_INTERFACE_CMDS_H__
19 #include <vapi/vapi.hpp>
21 #include "vom/dump_cmd.hpp"
22 #include "vom/event_cmd.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/rpc_cmd.hpp"
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>
35 namespace interface_cmds {
37 * Factory method to construct a new interface from the VPP record
39 std::unique_ptr<interface> new_interface(
40 const vapi_payload_sw_interface_details& vd);
43 * A command class to create Loopback interfaces in VPP
45 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
49 * Constructor taking the HW::item to update
50 * and the name of the interface to create
52 loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
53 ~loopback_create_cmd() = default;
56 * Issue the command to VPP/HW
58 rc_t issue(connection& con);
61 * convert to string format for debug purposes
63 std::string to_string() const;
67 * A command class to create af_packet interfaces in VPP
69 class af_packet_create_cmd
70 : public interface::create_cmd<vapi::Af_packet_create>
74 * Constructor taking the HW::item to update
75 * and the name of the interface to create
77 af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
78 ~af_packet_create_cmd() = default;
80 * Issue the command to VPP/HW
82 rc_t issue(connection& con);
84 * convert to string format for debug purposes
86 std::string to_string() const;
90 * A command class to create TAP interfaces in VPP
92 class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect>
96 * Constructor taking the HW::item to update
97 * and the name of the interface to create
99 tap_create_cmd(HW::item<handle_t>& item, const std::string& name);
100 ~tap_create_cmd() = default;
103 * Issue the command to VPP/HW
105 rc_t issue(connection& con);
108 * convert to string format for debug purposes
110 std::string to_string() const;
114 * A functor class that creates an interface
116 class vhost_create_cmd
117 : public interface::create_cmd<vapi::Create_vhost_user_if>
120 vhost_create_cmd(HW::item<handle_t>& item,
121 const std::string& name,
122 const std::string& tag);
125 * Issue the command to VPP/HW
127 rc_t issue(connection& con);
129 * convert to string format for debug purposes
131 std::string to_string() const;
134 const std::string m_tag;
138 * A command class to delete loopback interfaces in VPP
140 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
144 * Constructor taking the HW::item to update
146 loopback_delete_cmd(HW::item<handle_t>& item);
149 * Issue the command to VPP/HW
151 rc_t issue(connection& con);
153 * convert to string format for debug purposes
155 std::string to_string() const;
159 * A command class to delete af-packet interfaces in VPP
161 class af_packet_delete_cmd
162 : public interface::delete_cmd<vapi::Af_packet_delete>
166 * Constructor taking the HW::item to update
167 * and the name of the interface to delete
169 af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
172 * Issue the command to VPP/HW
174 rc_t issue(connection& con);
176 * convert to string format for debug purposes
178 std::string to_string() const;
182 * A command class to delete TAP interfaces in VPP
184 class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete>
188 * Constructor taking the HW::item to update
190 tap_delete_cmd(HW::item<handle_t>& item);
193 * Issue the command to VPP/HW
195 rc_t issue(connection& con);
197 * convert to string format for debug purposes
199 std::string to_string() const;
203 * A functor class that deletes a Vhost interface
205 class vhost_delete_cmd
206 : public interface::delete_cmd<vapi::Delete_vhost_user_if>
209 vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
212 * Issue the command to VPP/HW
214 rc_t issue(connection& con);
216 * convert to string format for debug purposes
218 std::string to_string() const;
222 * A command class to set tag on interfaces
225 : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del>
229 * Constructor taking the HW::item to update
231 set_tag(HW::item<handle_t>& item, const std::string& name);
234 * Issue the command to VPP/HW
236 rc_t issue(connection& con);
239 * convert to string format for debug purposes
241 std::string to_string() const;
244 * Comparison operator - only used for UT
246 bool operator==(const set_tag& i) const;
252 const std::string m_name;
256 * A cmd class that changes the admin state
258 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
260 vapi::Sw_interface_set_flags>
264 * Constructor taking the HW::item to update
265 * and the name handle of the interface whose state is to change
267 state_change_cmd(HW::item<interface::admin_state_t>& s,
268 const HW::item<handle_t>& h);
271 * Issue the command to VPP/HW
273 rc_t issue(connection& con);
275 * convert to string format for debug purposes
277 std::string to_string() const;
280 * Comparison operator - only used for UT
282 bool operator==(const state_change_cmd& i) const;
286 * the handle of the interface to update
288 const HW::item<handle_t>& m_hdl;
292 * A command class that binds an interface to an L3 table
294 class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
296 vapi::Sw_interface_set_table>
300 * Constructor taking the HW::item to update
301 * and the name handle of the interface whose table is to change
303 set_table_cmd(HW::item<route::table_id_t>& item,
304 const l3_proto_t& proto,
305 const HW::item<handle_t>& h);
308 * Issue the command to VPP/HW
310 rc_t issue(connection& con);
313 * convert to string format for debug purposes
315 std::string to_string() const;
318 * Comparison operator - only used for UT
320 bool operator==(const set_table_cmd& i) const;
324 * the handle of the interface to update
326 const HW::item<handle_t>& m_hdl;
329 * The L3 protocol of the table
335 * A command class that changes the MAC address on an interface
337 class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
339 vapi::Sw_interface_set_mac_address>
343 * Constructor taking the HW::item to update
344 * and the handle of the interface
346 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
349 * Issue the command to VPP/HW
351 rc_t issue(connection& con);
354 * convert to string format for debug purposes
356 std::string to_string() const;
359 * Comparison operator - only used for UT
361 bool operator==(const set_mac_cmd& i) const;
365 * the handle of the interface to update
367 const HW::item<handle_t>& m_hdl;
371 * A command class that enables detailed stats collection on an interface
373 class collect_detail_stats_change_cmd
374 : public rpc_cmd<HW::item<interface::stats_type_t>,
376 vapi::Collect_detailed_interface_stats>
380 * Constructor taking the HW::item to update
381 * and the handle of the interface
383 collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
388 * Issue the command to VPP/HW
390 rc_t issue(connection& con);
393 * convert to string format for debug purposes
395 std::string to_string() const;
398 * Comparison operator - only used for UT
400 bool operator==(const collect_detail_stats_change_cmd& i) const;
404 * the handle of the interface to update
406 const handle_t& m_hdl;
409 * enable or disable the detailed stats collection
415 * A command class represents our desire to recieve interface events
418 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
422 * Constructor taking the listner to notify
424 events_cmd(interface::event_listener& el);
427 * Issue the command to VPP/HW
429 rc_t issue(connection& con);
432 * Retires the command - unsubscribe from the events.
434 void retire(connection& con);
437 * convert to string format for debug purposes
439 std::string to_string() const;
442 * Comparison operator - only used for UT
444 bool operator==(const events_cmd& i) const;
447 * Called when it's time to poke the listeners
453 * The listeners to notify when data/events arrive
455 interface::event_listener& m_listener;
459 * A command class represents our desire to recieve interface stats
461 class stats_enable_cmd
462 : public event_cmd<vapi::Want_per_interface_combined_stats,
463 vapi::Vnet_per_interface_combined_counters>
467 * Constructor taking the listner to notify
469 stats_enable_cmd(interface::stat_listener& el, const handle_t& handle);
472 * Issue the command to VPP/HW
474 rc_t issue(connection& con);
477 * Retires the command - unsubscribe from the stats.
479 void retire(connection& con);
482 * convert to string format for debug purposes
484 std::string to_string() const;
487 * Comparison operator - only used for UT
489 bool operator==(const stats_enable_cmd& i) const;
492 * Called when it's time to poke the listeners
498 * The listeners to notify when data/stats arrive
500 interface::stat_listener& m_listener;
503 * The interface on which we are enabling states
505 handle_t m_swifindex;
509 * A command class represents our desire to recieve interface stats
511 class stats_disable_cmd
512 : public rpc_cmd<HW::item<bool>,
514 vapi::Want_per_interface_combined_stats>
518 * Constructor taking the listner to notify
520 stats_disable_cmd(const handle_t& handle);
523 * Issue the command to VPP/HW
525 rc_t issue(connection& con);
528 * convert to string format for debug purposes
530 std::string to_string() const;
533 * Comparison operator - only used for UT
535 bool operator==(const stats_disable_cmd& i) const;
538 HW::item<bool> m_res;
540 * The interface on which we are disabling states
542 handle_t m_swifindex;
546 * A cmd class that Dumps all the Vpp interfaces
548 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
552 * Default Constructor
557 * Issue the command to VPP/HW
559 rc_t issue(connection& con);
561 * convert to string format for debug purposes
563 std::string to_string() const;
566 * Comparison operator - only used for UT
568 bool operator==(const dump_cmd& i) const;
572 * A cmd class that Dumps all the Vpp Interfaces
574 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
578 * Default Constructor
583 * Issue the command to VPP/HW
585 rc_t issue(connection& con);
587 * convert to string format for debug purposes
589 std::string to_string() const;
592 * Comparison operator - only used for UT
594 bool operator==(const vhost_dump_cmd& i) const;
599 * fd.io coding-style-patch-verification: ON
602 * eval: (c-set-style "mozilla")