blob: 4178be38e0450ac6f4fb249b9aab1632ec339934 [file] [log] [blame]
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#ifndef __VOM_INTERFACE_CMDS_H__
17#define __VOM_INTERFACE_CMDS_H__
18
19#include <vapi/vapi.hpp>
20
21#include "vom/dump_cmd.hpp"
22#include "vom/event_cmd.hpp"
23#include "vom/interface.hpp"
24#include "vom/rpc_cmd.hpp"
25
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>
31
32namespace VOM {
33
34namespace interface_cmds {
35/**
36 * Factory method to construct a new interface from the VPP record
37 */
38std::unique_ptr<interface> new_interface(
39 const vapi_payload_sw_interface_details& vd);
40
41/**
42 * A command class to create Loopback interfaces in VPP
43 */
44class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
45{
46public:
47 /**
48 * Constructor taking the HW::item to update
49 * and the name of the interface to create
50 */
51 loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
52 ~loopback_create_cmd() = default;
53
54 /**
55 * Issue the command to VPP/HW
56 */
57 rc_t issue(connection& con);
58
59 /**
60 * convert to string format for debug purposes
61 */
62 std::string to_string() const;
63};
64
65/**
66 * A command class to create af_packet interfaces in VPP
67 */
68class af_packet_create_cmd
69 : public interface::create_cmd<vapi::Af_packet_create>
70{
71public:
72 /**
73 * Constructor taking the HW::item to update
74 * and the name of the interface to create
75 */
76 af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
77 ~af_packet_create_cmd() = default;
78 /**
79 * Issue the command to VPP/HW
80 */
81 rc_t issue(connection& con);
82 /**
83 * convert to string format for debug purposes
84 */
85 std::string to_string() const;
86};
87
88/**
89* A command class to create TAP interfaces in VPP
90*/
91class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect>
92{
93public:
94 /**
95 * Constructor taking the HW::item to update
96 * and the name of the interface to create
97 */
98 tap_create_cmd(HW::item<handle_t>& item, const std::string& name);
99 ~tap_create_cmd() = default;
100
101 /**
102 * Issue the command to VPP/HW
103 */
104 rc_t issue(connection& con);
105
106 /**
107 * convert to string format for debug purposes
108 */
109 std::string to_string() const;
110};
111
112/**
113 * A command class to delete loopback interfaces in VPP
114 */
115class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
116{
117public:
118 /**
119 * Constructor taking the HW::item to update
120 */
121 loopback_delete_cmd(HW::item<handle_t>& item);
122
123 /**
124 * Issue the command to VPP/HW
125 */
126 rc_t issue(connection& con);
127 /**
128 * convert to string format for debug purposes
129 */
130 std::string to_string() const;
131};
132
133/**
134 * A command class to delete af-packet interfaces in VPP
135 */
136class af_packet_delete_cmd
137 : public interface::delete_cmd<vapi::Af_packet_delete>
138{
139public:
140 /**
141 * Constructor taking the HW::item to update
142 * and the name of the interface to delete
143 */
144 af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
145
146 /**
147 * Issue the command to VPP/HW
148 */
149 rc_t issue(connection& con);
150 /**
151 * convert to string format for debug purposes
152 */
153 std::string to_string() const;
154};
155
156/**
157* A command class to delete TAP interfaces in VPP
158*/
159class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete>
160{
161public:
162 /**
163 * Constructor taking the HW::item to update
164 */
165 tap_delete_cmd(HW::item<handle_t>& item);
166
167 /**
168 * Issue the command to VPP/HW
169 */
170 rc_t issue(connection& con);
171 /**
172 * convert to string format for debug purposes
173 */
174 std::string to_string() const;
175};
176
177/**
178 * A command class to set tag on interfaces
179 */
180class set_tag
181 : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del>
182{
183public:
184 /**
185 * Constructor taking the HW::item to update
186 */
187 set_tag(HW::item<handle_t>& item, const std::string& name);
188
189 /**
190 * Issue the command to VPP/HW
191 */
192 rc_t issue(connection& con);
193
194 /**
195 * convert to string format for debug purposes
196 */
197 std::string to_string() const;
198
199 /**
200 * Comparison operator - only used for UT
201 */
202 bool operator==(const set_tag& i) const;
203
204private:
205 /**
206 * The tag to add
207 */
208 const std::string m_name;
209};
210
211/**
212 * A cmd class that changes the admin state
213 */
214class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
215 rc_t,
216 vapi::Sw_interface_set_flags>
217{
218public:
219 /**
220 * Constructor taking the HW::item to update
221 * and the name handle of the interface whose state is to change
222 */
223 state_change_cmd(HW::item<interface::admin_state_t>& s,
224 const HW::item<handle_t>& h);
225
226 /**
227 * Issue the command to VPP/HW
228 */
229 rc_t issue(connection& con);
230 /**
231 * convert to string format for debug purposes
232 */
233 std::string to_string() const;
234
235 /**
236 * Comparison operator - only used for UT
237 */
238 bool operator==(const state_change_cmd& i) const;
239
240private:
241 /**
242 * the handle of the interface to update
243 */
244 const HW::item<handle_t>& m_hdl;
245};
246
247/**
248 * A command class that binds an interface to an L3 table
249 */
250class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
251 rc_t,
252 vapi::Sw_interface_set_table>
253{
254public:
255 /**
256 * Constructor taking the HW::item to update
257 * and the name handle of the interface whose table is to change
258 */
259 set_table_cmd(HW::item<route::table_id_t>& item,
260 const l3_proto_t& proto,
261 const HW::item<handle_t>& h);
262
263 /**
264 * Issue the command to VPP/HW
265 */
266 rc_t issue(connection& con);
267
268 /**
269 * convert to string format for debug purposes
270 */
271 std::string to_string() const;
272
273 /**
274 * Comparison operator - only used for UT
275 */
276 bool operator==(const set_table_cmd& i) const;
277
278private:
279 /**
280 * the handle of the interface to update
281 */
282 const HW::item<handle_t>& m_hdl;
283
284 /**
285 * The L3 protocol of the table
286 */
287 l3_proto_t m_proto;
288};
289
290/**
291 * A command class that binds an interface to an L3 table
292 */
293class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
294 rc_t,
295 vapi::Sw_interface_set_mac_address>
296{
297public:
298 /**
299 * Constructor taking the HW::item to update
300 * and the handle of the interface
301 */
302 set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
303
304 /**
305 * Issue the command to VPP/HW
306 */
307 rc_t issue(connection& con);
308
309 /**
310 * convert to string format for debug purposes
311 */
312 std::string to_string() const;
313
314 /**
315 * Comparison operator - only used for UT
316 */
317 bool operator==(const set_mac_cmd& i) const;
318
319private:
320 /**
321 * the handle of the interface to update
322 */
323 const HW::item<handle_t>& m_hdl;
324};
325
326/**
327 * A command class represents our desire to recieve interface events
328 */
329class events_cmd
330 : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
331{
332public:
333 /**
334 * Constructor taking the listner to notify
335 */
336 events_cmd(interface::event_listener& el);
337
338 /**
339 * Issue the command to VPP/HW
340 */
341 rc_t issue(connection& con);
342
343 /**
344 * Retires the command - unsubscribe from the events.
345 */
346 void retire(connection& con);
347
348 /**
349 * convert to string format for debug purposes
350 */
351 std::string to_string() const;
352
353 /**
354 * Comparison operator - only used for UT
355 */
356 bool operator==(const events_cmd& i) const;
357
358 /**
359 * Called when it's time to poke the listeners
360 */
361 void notify();
362
363private:
364 /**
365 * The listeners to notify when data/events arrive
366 */
367 interface::interface::event_listener& m_listener;
368};
369
370/**
371 * A command class represents our desire to recieve interface stats
372 */
373class stats_cmd : public event_cmd<vapi::Want_per_interface_combined_stats,
374 vapi::Vnet_per_interface_combined_counters>
375{
376public:
377 /**
378 * Constructor taking the listner to notify
379 */
380 stats_cmd(interface::stat_listener& el,
381 const std::vector<handle_t>& interfaces);
382
383 /**
384 * Issue the command to VPP/HW
385 */
386 rc_t issue(connection& con);
387
388 /**
389 * Retires the command - unsubscribe from the stats.
390 */
391 void retire(connection& con);
392
393 /**
394 * convert to string format for debug purposes
395 */
396 std::string to_string() const;
397
398 /**
399 * Comparison operator - only used for UT
400 */
401 bool operator==(const stats_cmd& i) const;
402
403 /**
404 * Called when it's time to poke the listeners
405 */
406 void notify();
407
408private:
409 /**
410 * The listeners to notify when data/stats arrive
411 */
412 interface::interface::stat_listener& m_listener;
413
414 std::vector<handle_t> m_swifindex;
415};
416
417/**
418 * A cmd class that Dumps all the Vpp interfaces
419 */
420class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
421{
422public:
423 /**
424 * Default Constructor
425 */
426 dump_cmd();
427
428 /**
429 * Issue the command to VPP/HW
430 */
431 rc_t issue(connection& con);
432 /**
433 * convert to string format for debug purposes
434 */
435 std::string to_string() const;
436
437 /**
438 * Comparison operator - only used for UT
439 */
440 bool operator==(const dump_cmd& i) const;
441};
442};
443};
444/*
445 * fd.io coding-style-patch-verification: ON
446 *
447 * Local Variables:
448 * eval: (c-set-style "mozilla")
449 * End:
450 */
451#endif