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>, rc_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>,
215 vapi::Sw_interface_set_flags>
219 * Constructor taking the HW::item to update
220 * and the name handle of the interface whose state is to change
222 state_change_cmd(HW::item<interface::admin_state_t>& s,
223 const HW::item<handle_t>& h);
226 * Issue the command to VPP/HW
228 rc_t issue(connection& con);
230 * convert to string format for debug purposes
232 std::string to_string() const;
235 * Comparison operator - only used for UT
237 bool operator==(const state_change_cmd& i) const;
241 * the handle of the interface to update
243 const HW::item<handle_t>& m_hdl;
247 * A command class that binds an interface to an L3 table
249 class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
251 vapi::Sw_interface_set_table>
255 * Constructor taking the HW::item to update
256 * and the name handle of the interface whose table is to change
258 set_table_cmd(HW::item<route::table_id_t>& item,
259 const l3_proto_t& proto,
260 const HW::item<handle_t>& h);
263 * Issue the command to VPP/HW
265 rc_t issue(connection& con);
268 * convert to string format for debug purposes
270 std::string to_string() const;
273 * Comparison operator - only used for UT
275 bool operator==(const set_table_cmd& i) const;
279 * the handle of the interface to update
281 const HW::item<handle_t>& m_hdl;
284 * The L3 protocol of the table
290 * A command class that changes the MAC address on an interface
292 class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
294 vapi::Sw_interface_set_mac_address>
298 * Constructor taking the HW::item to update
299 * and the handle of the interface
301 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
304 * Issue the command to VPP/HW
306 rc_t issue(connection& con);
309 * convert to string format for debug purposes
311 std::string to_string() const;
314 * Comparison operator - only used for UT
316 bool operator==(const set_mac_cmd& i) const;
320 * the handle of the interface to update
322 const HW::item<handle_t>& m_hdl;
326 * A command class that enables detailed stats collection on an interface
328 class collect_detail_stats_change_cmd
329 : public rpc_cmd<HW::item<interface::stats_type_t>,
331 vapi::Collect_detailed_interface_stats>
335 * Constructor taking the HW::item to update
336 * and the handle of the interface
338 collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
343 * Issue the command to VPP/HW
345 rc_t issue(connection& con);
348 * convert to string format for debug purposes
350 std::string to_string() const;
353 * Comparison operator - only used for UT
355 bool operator==(const collect_detail_stats_change_cmd& i) const;
359 * the handle of the interface to update
361 const handle_t& m_hdl;
364 * enable or disable the detailed stats collection
370 * A command class represents our desire to recieve interface events
373 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
377 * Constructor taking the listner to notify
379 events_cmd(interface::event_listener& el);
382 * Issue the command to VPP/HW
384 rc_t issue(connection& con);
387 * Retires the command - unsubscribe from the events.
389 void retire(connection& con);
392 * convert to string format for debug purposes
394 std::string to_string() const;
397 * Comparison operator - only used for UT
399 bool operator==(const events_cmd& i) const;
402 * Called when it's time to poke the listeners
408 * The listeners to notify when data/events arrive
410 interface::event_listener& m_listener;
414 * A command class represents our desire to recieve interface stats
416 class stats_enable_cmd
417 : public event_cmd<vapi::Want_per_interface_combined_stats,
418 vapi::Vnet_per_interface_combined_counters>
422 * Constructor taking the listner to notify
424 stats_enable_cmd(interface::stat_listener& el, const handle_t& handle);
427 * Issue the command to VPP/HW
429 rc_t issue(connection& con);
432 * Retires the command - unsubscribe from the stats.
434 void retire(connection& con);
437 * convert to string format for debug purposes
439 std::string to_string() const;
444 void set(const rc_t& rc);
449 interface::stat_listener& listener() const;
452 * Comparison operator - only used for UT
454 bool operator==(const stats_enable_cmd& i) const;
457 * Called when it's time to poke the listeners
463 * The listeners to notify when data/stats arrive
465 interface::stat_listener& m_listener;
468 * The interface on which we are enabling states
470 const handle_t& m_swifindex;
474 * A command class represents our desire to recieve interface stats
476 class stats_disable_cmd
477 : public rpc_cmd<HW::item<bool>,
479 vapi::Want_per_interface_combined_stats>
483 * Constructor taking the listner to notify
485 stats_disable_cmd(const handle_t& handle);
488 * Issue the command to VPP/HW
490 rc_t issue(connection& con);
493 * convert to string format for debug purposes
495 std::string to_string() const;
498 * Comparison operator - only used for UT
500 bool operator==(const stats_disable_cmd& i) const;
503 HW::item<bool> m_res;
505 * The interface on which we are disabling states
507 handle_t m_swifindex;
511 * A cmd class that Dumps all the Vpp interfaces
513 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
517 * Default Constructor
522 * Issue the command to VPP/HW
524 rc_t issue(connection& con);
526 * convert to string format for debug purposes
528 std::string to_string() const;
531 * Comparison operator - only used for UT
533 bool operator==(const dump_cmd& i) const;
537 * A cmd class that Dumps all the Vpp Interfaces
539 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
543 * Default Constructor
548 * Issue the command to VPP/HW
550 rc_t issue(connection& con);
552 * convert to string format for debug purposes
554 std::string to_string() const;
557 * Comparison operator - only used for UT
559 bool operator==(const vhost_dump_cmd& i) const;
563 * A cmd class that Dumps all the Vpp interfaces
565 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
569 * Default Constructor
571 af_packet_dump_cmd() = default;
574 * Issue the command to VPP/HW
576 rc_t issue(connection& con);
578 * convert to string format for debug purposes
580 std::string to_string() const;
583 * Comparison operator - only used for UT
585 bool operator==(const af_packet_dump_cmd& i) const;
590 * fd.io coding-style-patch-verification: ON
593 * eval: (c-set-style "mozilla")