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/l2.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 bvi interfaces in VPP
44 class bvi_create_cmd : public interface::create_cmd<vapi::Bvi_create>
48 * Constructor taking the HW::item to update
49 * and the name of the interface to create
51 bvi_create_cmd(HW::item<handle_t>& item, const std::string& name);
52 ~bvi_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 Loopback interfaces in VPP
68 class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
72 * Constructor taking the HW::item to update
73 * and the name of the interface to create
75 loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
76 ~loopback_create_cmd() = default;
79 * Issue the command to VPP/HW
81 rc_t issue(connection& con);
84 * convert to string format for debug purposes
86 std::string to_string() const;
90 * A command class to create af_packet interfaces in VPP
92 class af_packet_create_cmd
93 : public interface::create_cmd<vapi::Af_packet_create>
97 * Constructor taking the HW::item to update
98 * and the name of the interface to create
100 af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
101 ~af_packet_create_cmd() = default;
103 * Issue the command to VPP/HW
105 rc_t issue(connection& con);
107 * convert to string format for debug purposes
109 std::string to_string() const;
113 * A functor class that creates an interface
115 class vhost_create_cmd
116 : public interface::create_cmd<vapi::Create_vhost_user_if>
119 vhost_create_cmd(HW::item<handle_t>& item,
120 const std::string& name,
121 const std::string& tag);
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;
133 const std::string m_tag;
137 * A command class to delete bvi interfaces in VPP
139 class bvi_delete_cmd : public interface::delete_cmd<vapi::Bvi_delete>
143 * Constructor taking the HW::item to update
145 bvi_delete_cmd(HW::item<handle_t>& item);
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 command class to delete loopback interfaces in VPP
160 class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
164 * Constructor taking the HW::item to update
166 loopback_delete_cmd(HW::item<handle_t>& item);
169 * Issue the command to VPP/HW
171 rc_t issue(connection& con);
173 * convert to string format for debug purposes
175 std::string to_string() const;
179 * A command class to delete af-packet interfaces in VPP
181 class af_packet_delete_cmd
182 : public interface::delete_cmd<vapi::Af_packet_delete>
186 * Constructor taking the HW::item to update
187 * and the name of the interface to delete
189 af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
192 * Issue the command to VPP/HW
194 rc_t issue(connection& con);
196 * convert to string format for debug purposes
198 std::string to_string() const;
202 * A functor class that deletes a Vhost interface
204 class vhost_delete_cmd
205 : public interface::delete_cmd<vapi::Delete_vhost_user_if>
208 vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name);
211 * Issue the command to VPP/HW
213 rc_t issue(connection& con);
215 * convert to string format for debug purposes
217 std::string to_string() const;
221 * A command class to set tag on interfaces
224 : public rpc_cmd<HW::item<handle_t>, vapi::Sw_interface_tag_add_del>
228 * Constructor taking the HW::item to update
230 set_tag(HW::item<handle_t>& item, const std::string& name);
233 * Issue the command to VPP/HW
235 rc_t issue(connection& con);
238 * convert to string format for debug purposes
240 std::string to_string() const;
243 * Comparison operator - only used for UT
245 bool operator==(const set_tag& i) const;
251 const std::string m_name;
255 * A cmd class that changes the admin state
257 class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
258 vapi::Sw_interface_set_flags>
262 * Constructor taking the HW::item to update
263 * and the name handle of the interface whose state is to change
265 state_change_cmd(HW::item<interface::admin_state_t>& s,
266 const HW::item<handle_t>& h);
269 * Issue the command to VPP/HW
271 rc_t issue(connection& con);
273 * convert to string format for debug purposes
275 std::string to_string() const;
278 * Comparison operator - only used for UT
280 bool operator==(const state_change_cmd& i) const;
284 * the handle of the interface to update
286 const HW::item<handle_t>& m_hdl;
290 * A command class that binds an interface to an L3 table
293 : public rpc_cmd<HW::item<route::table_id_t>, vapi::Sw_interface_set_table>
297 * Constructor taking the HW::item to update
298 * and the name handle of the interface whose table is to change
300 set_table_cmd(HW::item<route::table_id_t>& item,
301 const l3_proto_t& proto,
302 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_table_cmd& i) const;
321 * the handle of the interface to update
323 const HW::item<handle_t>& m_hdl;
326 * The L3 protocol of the table
332 * A command class that changes the MAC address on an interface
335 : public rpc_cmd<HW::item<l2_address_t>, vapi::Sw_interface_set_mac_address>
339 * Constructor taking the HW::item to update
340 * and the handle of the interface
342 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
345 * Issue the command to VPP/HW
347 rc_t issue(connection& con);
350 * convert to string format for debug purposes
352 std::string to_string() const;
355 * Comparison operator - only used for UT
357 bool operator==(const set_mac_cmd& i) const;
361 * the handle of the interface to update
363 const HW::item<handle_t>& m_hdl;
367 * A command class that enables detailed stats collection on an interface
369 class collect_detail_stats_change_cmd
370 : public rpc_cmd<HW::item<interface::stats_type_t>,
371 vapi::Collect_detailed_interface_stats>
375 * Constructor taking the HW::item to update
376 * and the handle of the interface
378 collect_detail_stats_change_cmd(HW::item<interface::stats_type_t>& item,
383 * Issue the command to VPP/HW
385 rc_t issue(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 collect_detail_stats_change_cmd& i) const;
399 * the handle of the interface to update
401 const handle_t& m_hdl;
404 * enable or disable the detailed stats collection
410 * A command class represents our desire to recieve interface events
413 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
417 * Constructor taking the listner to notify
419 events_cmd(interface::event_listener& el);
422 * Issue the command to VPP/HW
424 rc_t issue(connection& con);
427 * Retires the command - unsubscribe from the events.
429 void retire(connection& con);
432 * convert to string format for debug purposes
434 std::string to_string() const;
437 * Comparison operator - only used for UT
439 bool operator==(const events_cmd& i) const;
442 * Called when it's time to poke the listeners
448 * The listeners to notify when data/events arrive
450 interface::event_listener& m_listener;
454 * A cmd class that Dumps all the Vpp interfaces
456 class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
460 * Default Constructor
465 * Issue the command to VPP/HW
467 rc_t issue(connection& con);
469 * convert to string format for debug purposes
471 std::string to_string() const;
474 * Comparison operator - only used for UT
476 bool operator==(const dump_cmd& i) const;
480 * A cmd class that Dumps all the Vpp Interfaces
482 class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump>
486 * Default Constructor
491 * Issue the command to VPP/HW
493 rc_t issue(connection& con);
495 * convert to string format for debug purposes
497 std::string to_string() const;
500 * Comparison operator - only used for UT
502 bool operator==(const vhost_dump_cmd& i) const;
506 * A cmd class that Dumps all the Vpp interfaces
508 class af_packet_dump_cmd : public VOM::dump_cmd<vapi::Af_packet_dump>
512 * Default Constructor
514 af_packet_dump_cmd() = default;
517 * Issue the command to VPP/HW
519 rc_t issue(connection& con);
521 * convert to string format for debug purposes
523 std::string to_string() const;
526 * Comparison operator - only used for UT
528 bool operator==(const af_packet_dump_cmd& i) const;
533 * fd.io coding-style-patch-verification: ON
536 * eval: (c-set-style "mozilla")