Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 32 | namespace VOM { |
| 33 | |
| 34 | namespace interface_cmds { |
| 35 | /** |
| 36 | * Factory method to construct a new interface from the VPP record |
| 37 | */ |
| 38 | std::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 | */ |
| 44 | class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback> |
| 45 | { |
| 46 | public: |
| 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 | */ |
| 68 | class af_packet_create_cmd |
| 69 | : public interface::create_cmd<vapi::Af_packet_create> |
| 70 | { |
| 71 | public: |
| 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 | */ |
| 91 | class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect> |
| 92 | { |
| 93 | public: |
| 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 | */ |
| 115 | class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback> |
| 116 | { |
| 117 | public: |
| 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 | */ |
| 136 | class af_packet_delete_cmd |
| 137 | : public interface::delete_cmd<vapi::Af_packet_delete> |
| 138 | { |
| 139 | public: |
| 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 | */ |
| 159 | class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete> |
| 160 | { |
| 161 | public: |
| 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 | */ |
| 180 | class set_tag |
| 181 | : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del> |
| 182 | { |
| 183 | public: |
| 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 | |
| 204 | private: |
| 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 | */ |
| 214 | class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>, |
| 215 | rc_t, |
| 216 | vapi::Sw_interface_set_flags> |
| 217 | { |
| 218 | public: |
| 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 | |
| 240 | private: |
| 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 | */ |
| 250 | class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>, |
| 251 | rc_t, |
| 252 | vapi::Sw_interface_set_table> |
| 253 | { |
| 254 | public: |
| 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 | |
| 278 | private: |
| 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 | */ |
| 293 | class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>, |
| 294 | rc_t, |
| 295 | vapi::Sw_interface_set_mac_address> |
| 296 | { |
| 297 | public: |
| 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 | |
| 319 | private: |
| 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 | */ |
| 329 | class events_cmd |
| 330 | : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event> |
| 331 | { |
| 332 | public: |
| 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 | |
| 363 | private: |
| 364 | /** |
| 365 | * The listeners to notify when data/events arrive |
| 366 | */ |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 367 | interface::event_listener& m_listener; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 368 | }; |
| 369 | |
| 370 | /** |
| 371 | * A command class represents our desire to recieve interface stats |
| 372 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame^] | 373 | class stats_enable_cmd |
| 374 | : public event_cmd<vapi::Want_per_interface_combined_stats, |
| 375 | vapi::Vnet_per_interface_combined_counters> |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 376 | { |
| 377 | public: |
| 378 | /** |
| 379 | * Constructor taking the listner to notify |
| 380 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame^] | 381 | stats_enable_cmd(interface::stat_listener& el, const handle_t& handle); |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 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 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame^] | 401 | bool operator==(const stats_enable_cmd& i) const; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 402 | |
| 403 | /** |
| 404 | * Called when it's time to poke the listeners |
| 405 | */ |
| 406 | void notify(); |
| 407 | |
| 408 | private: |
| 409 | /** |
| 410 | * The listeners to notify when data/stats arrive |
| 411 | */ |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 412 | interface::stat_listener& m_listener; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 413 | |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame^] | 414 | /** |
| 415 | * The interface on which we are enabling states |
| 416 | */ |
| 417 | handle_t m_swifindex; |
| 418 | }; |
| 419 | |
| 420 | /** |
| 421 | * A command class represents our desire to recieve interface stats |
| 422 | */ |
| 423 | class stats_disable_cmd |
| 424 | : public rpc_cmd<HW::item<bool>, |
| 425 | rc_t, |
| 426 | vapi::Want_per_interface_combined_stats> |
| 427 | { |
| 428 | public: |
| 429 | /** |
| 430 | * Constructor taking the listner to notify |
| 431 | */ |
| 432 | stats_disable_cmd(const handle_t& handle); |
| 433 | |
| 434 | /** |
| 435 | * Issue the command to VPP/HW |
| 436 | */ |
| 437 | rc_t issue(connection& con); |
| 438 | |
| 439 | /** |
| 440 | * convert to string format for debug purposes |
| 441 | */ |
| 442 | std::string to_string() const; |
| 443 | |
| 444 | /** |
| 445 | * Comparison operator - only used for UT |
| 446 | */ |
| 447 | bool operator==(const stats_disable_cmd& i) const; |
| 448 | |
| 449 | private: |
| 450 | HW::item<bool> m_res; |
| 451 | /** |
| 452 | * The interface on which we are disabling states |
| 453 | */ |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 454 | handle_t m_swifindex; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
| 457 | /** |
| 458 | * A cmd class that Dumps all the Vpp interfaces |
| 459 | */ |
| 460 | class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump> |
| 461 | { |
| 462 | public: |
| 463 | /** |
| 464 | * Default Constructor |
| 465 | */ |
| 466 | dump_cmd(); |
| 467 | |
| 468 | /** |
| 469 | * Issue the command to VPP/HW |
| 470 | */ |
| 471 | rc_t issue(connection& con); |
| 472 | /** |
| 473 | * convert to string format for debug purposes |
| 474 | */ |
| 475 | std::string to_string() const; |
| 476 | |
| 477 | /** |
| 478 | * Comparison operator - only used for UT |
| 479 | */ |
| 480 | bool operator==(const dump_cmd& i) const; |
| 481 | }; |
| 482 | }; |
| 483 | }; |
| 484 | /* |
| 485 | * fd.io coding-style-patch-verification: ON |
| 486 | * |
| 487 | * Local Variables: |
| 488 | * eval: (c-set-style "mozilla") |
| 489 | * End: |
| 490 | */ |
| 491 | #endif |