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 functor class that creates an interface
92 class vhost_create_cmd
93 : public interface::create_cmd<vapi::Create_vhost_user_if>
96 vhost_create_cmd(HW::item<handle_t>& item,
97 const std::string& name,
98 const std::string& tag);
101 * Issue the command to VPP/HW
103 rc_t issue(connection& con);
105 * convert to string format for debug purposes
107 std::string to_string() const;
110 const std::string m_tag;
114 * A command class to delete loopback interfaces in VPP
116 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
120 * Constructor taking the HW::item to update
122 loopback_delete_cmd(HW::item<handle_t>& item);
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;
135 * A command class to delete af-packet interfaces in VPP
137 class af_packet_delete_cmd
138 : public interface::delete_cmd<vapi::Af_packet_delete>
142 * Constructor taking the HW::item to update
143 * and the name of the interface to delete
145 af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
148 * Issue the command to VPP/HW
150 rc_t issue(connection& con);
152 * convert to string format for debug purposes
154 std::string to_string() const;
158 * A functor class that deletes a Vhost interface
160 class vhost_delete_cmd
161 : public interface::delete_cmd<vapi::Delete_vhost_user_if>
164 vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
167 * Issue the command to VPP/HW
169 rc_t issue(connection& con);
171 * convert to string format for debug purposes
173 std::string to_string() const;
177 * A command class to set tag on interfaces
180 : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
184 * Constructor taking the HW::item to update
186 set_tag(HW::item<handle_t>& item, const std::string& name);
189 * Issue the command to VPP/HW
191 rc_t issue(connection& con);
194 * convert to string format for debug purposes
196 std::string to_string() const;
199 * Comparison operator - only used for UT
201 bool operator==(const set_tag& i) const;
207 const std::string m_name;
211 * A cmd class that changes the admin state
213 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
214 vapi::Sw_interface_set_flags>
218 * Constructor taking the HW::item to update
219 * and the name handle of the interface whose state is to change
221 state_change_cmd(HW::item<interface::admin_state_t>& s,
222 const HW::item<handle_t>& h);
225 * Issue the command to VPP/HW
227 rc_t issue(connection& con);
229 * convert to string format for debug purposes
231 std::string to_string() const;
234 * Comparison operator - only used for UT
236 bool operator==(const state_change_cmd& i) const;
240 * the handle of the interface to update
242 const HW::item<handle_t>& m_hdl;
246 * A command class that binds an interface to an L3 table
249 : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
253 * Constructor taking the HW::item to update
254 * and the name handle of the interface whose table is to change
256 set_table_cmd(HW::item<route::table_id_t>& item,
257 const l3_proto_t& proto,
258 const HW::item<handle_t>& h);
261 * Issue the command to VPP/HW
263 rc_t issue(connection& con);
266 * convert to string format for debug purposes
268 std::string to_string() const;
271 * Comparison operator - only used for UT
273 bool operator==(const set_table_cmd& i) const;
277 * the handle of the interface to update
279 const HW::item<handle_t>& m_hdl;
282 * The L3 protocol of the table
288 * A command class that changes the MAC address on an interface
291 : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
295 * Constructor taking the HW::item to update
296 * and the handle of the interface
298 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
301 * Issue the command to VPP/HW
303 rc_t issue(connection& con);
306 * convert to string format for debug purposes
308 std::string to_string() const;
311 * Comparison operator - only used for UT
313 bool operator==(const set_mac_cmd& i) const;
317 * the handle of the interface to update
319 const HW::item<handle_t>& m_hdl;
323 * A command class that enables detailed stats collection on an interface
325 class collect_detail_stats_change_cmd
326 : public rpc_cmd<HW::item<interface::stats_type_t>,
327 vapi::Collect_detailed_interface_stats>
331 * Constructor taking the HW::item to update
332 * and the handle of the interface
334 collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
339 * Issue the command to VPP/HW
341 rc_t issue(connection& con);
344 * convert to string format for debug purposes
346 std::string to_string() const;
349 * Comparison operator - only used for UT
351 bool operator==(const collect_detail_stats_change_cmd& i) const;
355 * the handle of the interface to update
357 const handle_t& m_hdl;
360 * enable or disable the detailed stats collection
366 * A command class represents our desire to recieve interface events
369 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
373 * Constructor taking the listner to notify
375 events_cmd(interface::event_listener& el);
378 * Issue the command to VPP/HW
380 rc_t issue(connection& con);
383 * Retires the command - unsubscribe from the events.
385 void retire(connection& con);
388 * convert to string format for debug purposes
390 std::string to_string() const;
393 * Comparison operator - only used for UT
395 bool operator==(const events_cmd& i) const;
398 * Called when it's time to poke the listeners
404 * The listeners to notify when data/events arrive
406 interface::event_listener& m_listener;
410 * A command class represents our desire to recieve interface stats
412 class stats_enable_cmd
413 : public event_cmd<vapi::Want_per_interface_combined_stats,
414 vapi::Vnet_per_interface_combined_counters>
418 * Constructor taking the listner to notify
420 stats_enable_cmd(interface::stat_listener& el, const handle_t& handle);
423 * Issue the command to VPP/HW
425 rc_t issue(connection& con);
428 * Retires the command - unsubscribe from the stats.
430 void retire(connection& con);
433 * convert to string format for debug purposes
435 std::string to_string() const;
440 void set(const rc_t& rc);
445 interface::stat_listener& listener() const;
448 * Comparison operator - only used for UT
450 bool operator==(const stats_enable_cmd& i) const;
453 * Called when it's time to poke the listeners
459 * The listeners to notify when data/stats arrive
461 interface::stat_listener& m_listener;
464 * The interface on which we are enabling states
466 const handle_t& m_swifindex;
470 * A command class represents our desire to recieve interface stats
472 class stats_disable_cmd
473 : public rpc_cmd<HW::item<bool>, vapi::Want_per_interface_combined_stats>
477 * Constructor taking the listner to notify
479 stats_disable_cmd(const handle_t& handle);
482 * Issue the command to VPP/HW
484 rc_t issue(connection& con);
487 * convert to string format for debug purposes
489 std::string to_string() const;
492 * Comparison operator - only used for UT
494 bool operator==(const stats_disable_cmd& i) const;
497 HW::item<bool> m_res;
499 * The interface on which we are disabling states
501 handle_t m_swifindex;
505 * A cmd class that Dumps all the Vpp interfaces
507 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
511 * Default Constructor
516 * Issue the command to VPP/HW
518 rc_t issue(connection& con);
520 * convert to string format for debug purposes
522 std::string to_string() const;
525 * Comparison operator - only used for UT
527 bool operator==(const dump_cmd& i) const;
531 * A cmd class that Dumps all the Vpp Interfaces
533 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
537 * Default Constructor
542 * Issue the command to VPP/HW
544 rc_t issue(connection& con);
546 * convert to string format for debug purposes
548 std::string to_string() const;
551 * Comparison operator - only used for UT
553 bool operator==(const vhost_dump_cmd& i) const;
557 * A cmd class that Dumps all the Vpp interfaces
559 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
563 * Default Constructor
565 af_packet_dump_cmd() = default;
568 * Issue the command to VPP/HW
570 rc_t issue(connection& con);
572 * convert to string format for debug purposes
574 std::string to_string() const;
577 * Comparison operator - only used for UT
579 bool operator==(const af_packet_dump_cmd& i) const;
584 * fd.io coding-style-patch-verification: ON
587 * eval: (c-set-style "mozilla")