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/tap.api.vapi.hpp>
29 #include <vapi/vhost_user.api.vapi.hpp>
30 #include <vapi/vpe.api.vapi.hpp>
34 namespace interface_cmds {
36 * Factory method to construct a new interface from the VPP record
38 std::unique_ptr<interface> new_interface(
39 const vapi_payload_sw_interface_details& vd);
42 * A command class to create Loopback interfaces in VPP
44 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
48 * Constructor taking the HW::item to update
49 * and the name of the interface to create
51 loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
52 ~loopback_create_cmd() = default;
55 * Issue the command to VPP/HW
57 rc_t issue(connection& con);
60 * convert to string format for debug purposes
62 std::string to_string() const;
66 * A command class to create af_packet interfaces in VPP
68 class af_packet_create_cmd
69 : public interface::create_cmd<vapi::Af_packet_create>
73 * Constructor taking the HW::item to update
74 * and the name of the interface to create
76 af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
77 ~af_packet_create_cmd() = default;
79 * Issue the command to VPP/HW
81 rc_t issue(connection& con);
83 * convert to string format for debug purposes
85 std::string to_string() const;
89 * A functor class that creates an interface
91 class vhost_create_cmd
92 : public interface::create_cmd<vapi::Create_vhost_user_if>
95 vhost_create_cmd(HW::item<handle_t>& item,
96 const std::string& name,
97 const std::string& tag);
100 * Issue the command to VPP/HW
102 rc_t issue(connection& con);
104 * convert to string format for debug purposes
106 std::string to_string() const;
109 const std::string m_tag;
113 * A command class to delete loopback interfaces in VPP
115 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
119 * Constructor taking the HW::item to update
121 loopback_delete_cmd(HW::item<handle_t>& item);
124 * Issue the command to VPP/HW
126 rc_t issue(connection& con);
128 * convert to string format for debug purposes
130 std::string to_string() const;
134 * A command class to delete af-packet interfaces in VPP
136 class af_packet_delete_cmd
137 : public interface::delete_cmd<vapi::Af_packet_delete>
141 * Constructor taking the HW::item to update
142 * and the name of the interface to delete
144 af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
147 * Issue the command to VPP/HW
149 rc_t issue(connection& con);
151 * convert to string format for debug purposes
153 std::string to_string() const;
157 * A functor class that deletes a Vhost interface
159 class vhost_delete_cmd
160 : public interface::delete_cmd<vapi::Delete_vhost_user_if>
163 vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
166 * Issue the command to VPP/HW
168 rc_t issue(connection& con);
170 * convert to string format for debug purposes
172 std::string to_string() const;
176 * A command class to set tag on interfaces
179 : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
183 * Constructor taking the HW::item to update
185 set_tag(HW::item<handle_t>& item, const std::string& name);
188 * Issue the command to VPP/HW
190 rc_t issue(connection& con);
193 * convert to string format for debug purposes
195 std::string to_string() const;
198 * Comparison operator - only used for UT
200 bool operator==(const set_tag& i) const;
206 const std::string m_name;
210 * A cmd class that changes the admin state
212 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
213 vapi::Sw_interface_set_flags>
217 * Constructor taking the HW::item to update
218 * and the name handle of the interface whose state is to change
220 state_change_cmd(HW::item<interface::admin_state_t>& s,
221 const HW::item<handle_t>& h);
224 * Issue the command to VPP/HW
226 rc_t issue(connection& con);
228 * convert to string format for debug purposes
230 std::string to_string() const;
233 * Comparison operator - only used for UT
235 bool operator==(const state_change_cmd& i) const;
239 * the handle of the interface to update
241 const HW::item<handle_t>& m_hdl;
245 * A command class that binds an interface to an L3 table
248 : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
252 * Constructor taking the HW::item to update
253 * and the name handle of the interface whose table is to change
255 set_table_cmd(HW::item<route::table_id_t>& item,
256 const l3_proto_t& proto,
257 const HW::item<handle_t>& h);
260 * Issue the command to VPP/HW
262 rc_t issue(connection& con);
265 * convert to string format for debug purposes
267 std::string to_string() const;
270 * Comparison operator - only used for UT
272 bool operator==(const set_table_cmd& i) const;
276 * the handle of the interface to update
278 const HW::item<handle_t>& m_hdl;
281 * The L3 protocol of the table
287 * A command class that changes the MAC address on an interface
290 : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
294 * Constructor taking the HW::item to update
295 * and the handle of the interface
297 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
300 * Issue the command to VPP/HW
302 rc_t issue(connection& con);
305 * convert to string format for debug purposes
307 std::string to_string() const;
310 * Comparison operator - only used for UT
312 bool operator==(const set_mac_cmd& i) const;
316 * the handle of the interface to update
318 const HW::item<handle_t>& m_hdl;
322 * A command class that enables detailed stats collection on an interface
324 class collect_detail_stats_change_cmd
325 : public rpc_cmd<HW::item<interface::stats_type_t>,
326 vapi::Collect_detailed_interface_stats>
330 * Constructor taking the HW::item to update
331 * and the handle of the interface
333 collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
338 * Issue the command to VPP/HW
340 rc_t issue(connection& con);
343 * convert to string format for debug purposes
345 std::string to_string() const;
348 * Comparison operator - only used for UT
350 bool operator==(const collect_detail_stats_change_cmd& i) const;
354 * the handle of the interface to update
356 const handle_t& m_hdl;
359 * enable or disable the detailed stats collection
365 * A command class represents our desire to recieve interface events
368 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
372 * Constructor taking the listner to notify
374 events_cmd(interface::event_listener& el);
377 * Issue the command to VPP/HW
379 rc_t issue(connection& con);
382 * Retires the command - unsubscribe from the events.
384 void retire(connection& con);
387 * convert to string format for debug purposes
389 std::string to_string() const;
392 * Comparison operator - only used for UT
394 bool operator==(const events_cmd& i) const;
397 * Called when it's time to poke the listeners
403 * The listeners to notify when data/events arrive
405 interface::event_listener& m_listener;
409 * A cmd class that Dumps all the Vpp interfaces
411 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
415 * Default Constructor
420 * Issue the command to VPP/HW
422 rc_t issue(connection& con);
424 * convert to string format for debug purposes
426 std::string to_string() const;
429 * Comparison operator - only used for UT
431 bool operator==(const dump_cmd& i) const;
435 * A cmd class that Dumps all the Vpp Interfaces
437 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
441 * Default Constructor
446 * Issue the command to VPP/HW
448 rc_t issue(connection& con);
450 * convert to string format for debug purposes
452 std::string to_string() const;
455 * Comparison operator - only used for UT
457 bool operator==(const vhost_dump_cmd& i) const;
461 * A cmd class that Dumps all the Vpp interfaces
463 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
467 * Default Constructor
469 af_packet_dump_cmd() = default;
472 * Issue the command to VPP/HW
474 rc_t issue(connection& con);
476 * convert to string format for debug purposes
478 std::string to_string() const;
481 * Comparison operator - only used for UT
483 bool operator==(const af_packet_dump_cmd& i) const;
488 * fd.io coding-style-patch-verification: ON
491 * eval: (c-set-style "mozilla")