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/vhost_user.api.vapi.hpp>
29 #include <vapi/vpe.api.vapi.hpp>
33 namespace interface_cmds {
35 * Factory method to construct a new interface from the VPP record
37 std::unique_ptr<interface> new_interface(
38 const vapi_payload_sw_interface_details& vd);
41 * A command class to create Loopback interfaces in VPP
43 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
47 * Constructor taking the HW::item to update
48 * and the name of the interface to create
50 loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
51 ~loopback_create_cmd() = default;
54 * Issue the command to VPP/HW
56 rc_t issue(connection& con);
59 * convert to string format for debug purposes
61 std::string to_string() const;
65 * A command class to create af_packet interfaces in VPP
67 class af_packet_create_cmd
68 : public interface::create_cmd<vapi::Af_packet_create>
72 * Constructor taking the HW::item to update
73 * and the name of the interface to create
75 af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
76 ~af_packet_create_cmd() = default;
78 * Issue the command to VPP/HW
80 rc_t issue(connection& con);
82 * convert to string format for debug purposes
84 std::string to_string() const;
88 * A functor class that creates an interface
90 class vhost_create_cmd
91 : public interface::create_cmd<vapi::Create_vhost_user_if>
94 vhost_create_cmd(HW::item<handle_t>& item,
95 const std::string& name,
96 const std::string& tag);
99 * Issue the command to VPP/HW
101 rc_t issue(connection& con);
103 * convert to string format for debug purposes
105 std::string to_string() const;
108 const std::string m_tag;
112 * A command class to delete loopback interfaces in VPP
114 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
118 * Constructor taking the HW::item to update
120 loopback_delete_cmd(HW::item<handle_t>& item);
123 * Issue the command to VPP/HW
125 rc_t issue(connection& con);
127 * convert to string format for debug purposes
129 std::string to_string() const;
133 * A command class to delete af-packet interfaces in VPP
135 class af_packet_delete_cmd
136 : public interface::delete_cmd<vapi::Af_packet_delete>
140 * Constructor taking the HW::item to update
141 * and the name of the interface to delete
143 af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
146 * Issue the command to VPP/HW
148 rc_t issue(connection& con);
150 * convert to string format for debug purposes
152 std::string to_string() const;
156 * A functor class that deletes a Vhost interface
158 class vhost_delete_cmd
159 : public interface::delete_cmd<vapi::Delete_vhost_user_if>
162 vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
165 * Issue the command to VPP/HW
167 rc_t issue(connection& con);
169 * convert to string format for debug purposes
171 std::string to_string() const;
175 * A command class to set tag on interfaces
178 : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
182 * Constructor taking the HW::item to update
184 set_tag(HW::item<handle_t>& item, const std::string& name);
187 * Issue the command to VPP/HW
189 rc_t issue(connection& con);
192 * convert to string format for debug purposes
194 std::string to_string() const;
197 * Comparison operator - only used for UT
199 bool operator==(const set_tag& i) const;
205 const std::string m_name;
209 * A cmd class that changes the admin state
211 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
212 vapi::Sw_interface_set_flags>
216 * Constructor taking the HW::item to update
217 * and the name handle of the interface whose state is to change
219 state_change_cmd(HW::item<interface::admin_state_t>& s,
220 const HW::item<handle_t>& h);
223 * Issue the command to VPP/HW
225 rc_t issue(connection& con);
227 * convert to string format for debug purposes
229 std::string to_string() const;
232 * Comparison operator - only used for UT
234 bool operator==(const state_change_cmd& i) const;
238 * the handle of the interface to update
240 const HW::item<handle_t>& m_hdl;
244 * A command class that binds an interface to an L3 table
247 : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
251 * Constructor taking the HW::item to update
252 * and the name handle of the interface whose table is to change
254 set_table_cmd(HW::item<route::table_id_t>& item,
255 const l3_proto_t& proto,
256 const HW::item<handle_t>& h);
259 * Issue the command to VPP/HW
261 rc_t issue(connection& con);
264 * convert to string format for debug purposes
266 std::string to_string() const;
269 * Comparison operator - only used for UT
271 bool operator==(const set_table_cmd& i) const;
275 * the handle of the interface to update
277 const HW::item<handle_t>& m_hdl;
280 * The L3 protocol of the table
286 * A command class that changes the MAC address on an interface
289 : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
293 * Constructor taking the HW::item to update
294 * and the handle of the interface
296 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
299 * Issue the command to VPP/HW
301 rc_t issue(connection& con);
304 * convert to string format for debug purposes
306 std::string to_string() const;
309 * Comparison operator - only used for UT
311 bool operator==(const set_mac_cmd& i) const;
315 * the handle of the interface to update
317 const HW::item<handle_t>& m_hdl;
321 * A command class that enables detailed stats collection on an interface
323 class collect_detail_stats_change_cmd
324 : public rpc_cmd<HW::item<interface::stats_type_t>,
325 vapi::Collect_detailed_interface_stats>
329 * Constructor taking the HW::item to update
330 * and the handle of the interface
332 collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
337 * Issue the command to VPP/HW
339 rc_t issue(connection& con);
342 * convert to string format for debug purposes
344 std::string to_string() const;
347 * Comparison operator - only used for UT
349 bool operator==(const collect_detail_stats_change_cmd& i) const;
353 * the handle of the interface to update
355 const handle_t& m_hdl;
358 * enable or disable the detailed stats collection
364 * A command class represents our desire to recieve interface events
367 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
371 * Constructor taking the listner to notify
373 events_cmd(interface::event_listener& el);
376 * Issue the command to VPP/HW
378 rc_t issue(connection& con);
381 * Retires the command - unsubscribe from the events.
383 void retire(connection& con);
386 * convert to string format for debug purposes
388 std::string to_string() const;
391 * Comparison operator - only used for UT
393 bool operator==(const events_cmd& i) const;
396 * Called when it's time to poke the listeners
402 * The listeners to notify when data/events arrive
404 interface::event_listener& m_listener;
408 * A cmd class that Dumps all the Vpp interfaces
410 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
414 * Default Constructor
419 * Issue the command to VPP/HW
421 rc_t issue(connection& con);
423 * convert to string format for debug purposes
425 std::string to_string() const;
428 * Comparison operator - only used for UT
430 bool operator==(const dump_cmd& i) const;
434 * A cmd class that Dumps all the Vpp Interfaces
436 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
440 * Default Constructor
445 * Issue the command to VPP/HW
447 rc_t issue(connection& con);
449 * convert to string format for debug purposes
451 std::string to_string() const;
454 * Comparison operator - only used for UT
456 bool operator==(const vhost_dump_cmd& i) const;
460 * A cmd class that Dumps all the Vpp interfaces
462 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
466 * Default Constructor
468 af_packet_dump_cmd() = default;
471 * Issue the command to VPP/HW
473 rc_t issue(connection& con);
475 * convert to string format for debug purposes
477 std::string to_string() const;
480 * Comparison operator - only used for UT
482 bool operator==(const af_packet_dump_cmd& i) const;
487 * fd.io coding-style-patch-verification: ON
490 * eval: (c-set-style "mozilla")