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/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 command class to create TAP interfaces in VPP
91 class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect>
95 * Constructor taking the HW::item to update
96 * and the name of the interface to create
98 tap_create_cmd(HW::item<handle_t>& item, const std::string& name);
99 ~tap_create_cmd() = default;
102 * Issue the command to VPP/HW
104 rc_t issue(connection& con);
107 * convert to string format for debug purposes
109 std::string to_string() const;
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 command class to delete TAP interfaces in VPP
159 class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete>
163 * Constructor taking the HW::item to update
165 tap_delete_cmd(HW::item<handle_t>& item);
168 * Issue the command to VPP/HW
170 rc_t issue(connection& con);
172 * convert to string format for debug purposes
174 std::string to_string() const;
178 * A command class to set tag on interfaces
181 : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del>
185 * Constructor taking the HW::item to update
187 set_tag(HW::item<handle_t>& item, const std::string& name);
190 * Issue the command to VPP/HW
192 rc_t issue(connection& con);
195 * convert to string format for debug purposes
197 std::string to_string() const;
200 * Comparison operator - only used for UT
202 bool operator==(const set_tag& i) const;
208 const std::string m_name;
212 * A cmd class that changes the admin state
214 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
216 vapi::Sw_interface_set_flags>
220 * Constructor taking the HW::item to update
221 * and the name handle of the interface whose state is to change
223 state_change_cmd(HW::item<interface::admin_state_t>& s,
224 const HW::item<handle_t>& h);
227 * Issue the command to VPP/HW
229 rc_t issue(connection& con);
231 * convert to string format for debug purposes
233 std::string to_string() const;
236 * Comparison operator - only used for UT
238 bool operator==(const state_change_cmd& i) const;
242 * the handle of the interface to update
244 const HW::item<handle_t>& m_hdl;
248 * A command class that binds an interface to an L3 table
250 class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
252 vapi::Sw_interface_set_table>
256 * Constructor taking the HW::item to update
257 * and the name handle of the interface whose table is to change
259 set_table_cmd(HW::item<route::table_id_t>& item,
260 const l3_proto_t& proto,
261 const HW::item<handle_t>& h);
264 * Issue the command to VPP/HW
266 rc_t issue(connection& con);
269 * convert to string format for debug purposes
271 std::string to_string() const;
274 * Comparison operator - only used for UT
276 bool operator==(const set_table_cmd& i) const;
280 * the handle of the interface to update
282 const HW::item<handle_t>& m_hdl;
285 * The L3 protocol of the table
291 * A command class that binds an interface to an L3 table
293 class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
295 vapi::Sw_interface_set_mac_address>
299 * Constructor taking the HW::item to update
300 * and the handle of the interface
302 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
305 * Issue the command to VPP/HW
307 rc_t issue(connection& con);
310 * convert to string format for debug purposes
312 std::string to_string() const;
315 * Comparison operator - only used for UT
317 bool operator==(const set_mac_cmd& i) const;
321 * the handle of the interface to update
323 const HW::item<handle_t>& m_hdl;
327 * A command class represents our desire to recieve interface events
330 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
334 * Constructor taking the listner to notify
336 events_cmd(interface::event_listener& el);
339 * Issue the command to VPP/HW
341 rc_t issue(connection& con);
344 * Retires the command - unsubscribe from the events.
346 void retire(connection& con);
349 * convert to string format for debug purposes
351 std::string to_string() const;
354 * Comparison operator - only used for UT
356 bool operator==(const events_cmd& i) const;
359 * Called when it's time to poke the listeners
365 * The listeners to notify when data/events arrive
367 interface::interface::event_listener& m_listener;
371 * A command class represents our desire to recieve interface stats
373 class stats_cmd : public event_cmd<vapi::Want_per_interface_combined_stats,
374 vapi::Vnet_per_interface_combined_counters>
378 * Constructor taking the listner to notify
380 stats_cmd(interface::stat_listener& el,
381 const std::vector<handle_t>& interfaces);
384 * Issue the command to VPP/HW
386 rc_t issue(connection& con);
389 * Retires the command - unsubscribe from the stats.
391 void retire(connection& con);
394 * convert to string format for debug purposes
396 std::string to_string() const;
399 * Comparison operator - only used for UT
401 bool operator==(const stats_cmd& i) const;
404 * Called when it's time to poke the listeners
410 * The listeners to notify when data/stats arrive
412 interface::interface::stat_listener& m_listener;
414 std::vector<handle_t> m_swifindex;
418 * A cmd class that Dumps all the Vpp interfaces
420 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
424 * Default Constructor
429 * Issue the command to VPP/HW
431 rc_t issue(connection& con);
433 * convert to string format for debug purposes
435 std::string to_string() const;
438 * Comparison operator - only used for UT
440 bool operator==(const dump_cmd& i) const;
445 * fd.io coding-style-patch-verification: ON
448 * eval: (c-set-style "mozilla")