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> |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 30 | #include <vapi/vhost_user.api.vapi.hpp> |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 31 | #include <vapi/vpe.api.vapi.hpp> |
| 32 | |
| 33 | namespace VOM { |
| 34 | |
| 35 | namespace interface_cmds { |
| 36 | /** |
| 37 | * Factory method to construct a new interface from the VPP record |
| 38 | */ |
| 39 | std::unique_ptr<interface> new_interface( |
| 40 | const vapi_payload_sw_interface_details& vd); |
| 41 | |
| 42 | /** |
| 43 | * A command class to create Loopback interfaces in VPP |
| 44 | */ |
| 45 | class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback> |
| 46 | { |
| 47 | public: |
| 48 | /** |
| 49 | * Constructor taking the HW::item to update |
| 50 | * and the name of the interface to create |
| 51 | */ |
| 52 | loopback_create_cmd(HW::item<handle_t>& item, const std::string& name); |
| 53 | ~loopback_create_cmd() = default; |
| 54 | |
| 55 | /** |
| 56 | * Issue the command to VPP/HW |
| 57 | */ |
| 58 | rc_t issue(connection& con); |
| 59 | |
| 60 | /** |
| 61 | * convert to string format for debug purposes |
| 62 | */ |
| 63 | std::string to_string() const; |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * A command class to create af_packet interfaces in VPP |
| 68 | */ |
| 69 | class af_packet_create_cmd |
| 70 | : public interface::create_cmd<vapi::Af_packet_create> |
| 71 | { |
| 72 | public: |
| 73 | /** |
| 74 | * Constructor taking the HW::item to update |
| 75 | * and the name of the interface to create |
| 76 | */ |
| 77 | af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name); |
| 78 | ~af_packet_create_cmd() = default; |
| 79 | /** |
| 80 | * Issue the command to VPP/HW |
| 81 | */ |
| 82 | rc_t issue(connection& con); |
| 83 | /** |
| 84 | * convert to string format for debug purposes |
| 85 | */ |
| 86 | std::string to_string() const; |
| 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * A command class to create TAP interfaces in VPP |
| 91 | */ |
| 92 | class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect> |
| 93 | { |
| 94 | public: |
| 95 | /** |
| 96 | * Constructor taking the HW::item to update |
| 97 | * and the name of the interface to create |
| 98 | */ |
| 99 | tap_create_cmd(HW::item<handle_t>& item, const std::string& name); |
| 100 | ~tap_create_cmd() = default; |
| 101 | |
| 102 | /** |
| 103 | * Issue the command to VPP/HW |
| 104 | */ |
| 105 | rc_t issue(connection& con); |
| 106 | |
| 107 | /** |
| 108 | * convert to string format for debug purposes |
| 109 | */ |
| 110 | std::string to_string() const; |
| 111 | }; |
| 112 | |
| 113 | /** |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 114 | * A functor class that creates an interface |
| 115 | */ |
| 116 | class vhost_create_cmd |
| 117 | : public interface::create_cmd<vapi::Create_vhost_user_if> |
| 118 | { |
| 119 | public: |
| 120 | vhost_create_cmd(HW::item<handle_t>& item, |
| 121 | const std::string& name, |
| 122 | const std::string& tag); |
| 123 | |
| 124 | /** |
| 125 | * Issue the command to VPP/HW |
| 126 | */ |
| 127 | rc_t issue(connection& con); |
| 128 | /** |
| 129 | * convert to string format for debug purposes |
| 130 | */ |
| 131 | std::string to_string() const; |
| 132 | |
| 133 | private: |
| 134 | const std::string m_tag; |
| 135 | }; |
| 136 | |
| 137 | /** |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 138 | * A command class to delete loopback interfaces in VPP |
| 139 | */ |
| 140 | class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback> |
| 141 | { |
| 142 | public: |
| 143 | /** |
| 144 | * Constructor taking the HW::item to update |
| 145 | */ |
| 146 | loopback_delete_cmd(HW::item<handle_t>& item); |
| 147 | |
| 148 | /** |
| 149 | * Issue the command to VPP/HW |
| 150 | */ |
| 151 | rc_t issue(connection& con); |
| 152 | /** |
| 153 | * convert to string format for debug purposes |
| 154 | */ |
| 155 | std::string to_string() const; |
| 156 | }; |
| 157 | |
| 158 | /** |
| 159 | * A command class to delete af-packet interfaces in VPP |
| 160 | */ |
| 161 | class af_packet_delete_cmd |
| 162 | : public interface::delete_cmd<vapi::Af_packet_delete> |
| 163 | { |
| 164 | public: |
| 165 | /** |
| 166 | * Constructor taking the HW::item to update |
| 167 | * and the name of the interface to delete |
| 168 | */ |
| 169 | af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name); |
| 170 | |
| 171 | /** |
| 172 | * Issue the command to VPP/HW |
| 173 | */ |
| 174 | rc_t issue(connection& con); |
| 175 | /** |
| 176 | * convert to string format for debug purposes |
| 177 | */ |
| 178 | std::string to_string() const; |
| 179 | }; |
| 180 | |
| 181 | /** |
| 182 | * A command class to delete TAP interfaces in VPP |
| 183 | */ |
| 184 | class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete> |
| 185 | { |
| 186 | public: |
| 187 | /** |
| 188 | * Constructor taking the HW::item to update |
| 189 | */ |
| 190 | tap_delete_cmd(HW::item<handle_t>& item); |
| 191 | |
| 192 | /** |
| 193 | * Issue the command to VPP/HW |
| 194 | */ |
| 195 | rc_t issue(connection& con); |
| 196 | /** |
| 197 | * convert to string format for debug purposes |
| 198 | */ |
| 199 | std::string to_string() const; |
| 200 | }; |
| 201 | |
| 202 | /** |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 203 | * A functor class that deletes a Vhost interface |
| 204 | */ |
| 205 | class vhost_delete_cmd |
| 206 | : public interface::delete_cmd<vapi::Delete_vhost_user_if> |
| 207 | { |
| 208 | public: |
| 209 | vhost_delete_cmd(HW::item<handle_t>& item, const std::string& name); |
| 210 | |
| 211 | /** |
| 212 | * Issue the command to VPP/HW |
| 213 | */ |
| 214 | rc_t issue(connection& con); |
| 215 | /** |
| 216 | * convert to string format for debug purposes |
| 217 | */ |
| 218 | std::string to_string() const; |
| 219 | }; |
| 220 | |
| 221 | /** |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 222 | * A command class to set tag on interfaces |
| 223 | */ |
| 224 | class set_tag |
| 225 | : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del> |
| 226 | { |
| 227 | public: |
| 228 | /** |
| 229 | * Constructor taking the HW::item to update |
| 230 | */ |
| 231 | set_tag(HW::item<handle_t>& item, const std::string& name); |
| 232 | |
| 233 | /** |
| 234 | * Issue the command to VPP/HW |
| 235 | */ |
| 236 | rc_t issue(connection& con); |
| 237 | |
| 238 | /** |
| 239 | * convert to string format for debug purposes |
| 240 | */ |
| 241 | std::string to_string() const; |
| 242 | |
| 243 | /** |
| 244 | * Comparison operator - only used for UT |
| 245 | */ |
| 246 | bool operator==(const set_tag& i) const; |
| 247 | |
| 248 | private: |
| 249 | /** |
| 250 | * The tag to add |
| 251 | */ |
| 252 | const std::string m_name; |
| 253 | }; |
| 254 | |
| 255 | /** |
| 256 | * A cmd class that changes the admin state |
| 257 | */ |
| 258 | class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>, |
| 259 | rc_t, |
| 260 | vapi::Sw_interface_set_flags> |
| 261 | { |
| 262 | public: |
| 263 | /** |
| 264 | * Constructor taking the HW::item to update |
| 265 | * and the name handle of the interface whose state is to change |
| 266 | */ |
| 267 | state_change_cmd(HW::item<interface::admin_state_t>& s, |
| 268 | const HW::item<handle_t>& h); |
| 269 | |
| 270 | /** |
| 271 | * Issue the command to VPP/HW |
| 272 | */ |
| 273 | rc_t issue(connection& con); |
| 274 | /** |
| 275 | * convert to string format for debug purposes |
| 276 | */ |
| 277 | std::string to_string() const; |
| 278 | |
| 279 | /** |
| 280 | * Comparison operator - only used for UT |
| 281 | */ |
| 282 | bool operator==(const state_change_cmd& i) const; |
| 283 | |
| 284 | private: |
| 285 | /** |
| 286 | * the handle of the interface to update |
| 287 | */ |
| 288 | const HW::item<handle_t>& m_hdl; |
| 289 | }; |
| 290 | |
| 291 | /** |
| 292 | * A command class that binds an interface to an L3 table |
| 293 | */ |
| 294 | class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>, |
| 295 | rc_t, |
| 296 | vapi::Sw_interface_set_table> |
| 297 | { |
| 298 | public: |
| 299 | /** |
| 300 | * Constructor taking the HW::item to update |
| 301 | * and the name handle of the interface whose table is to change |
| 302 | */ |
| 303 | set_table_cmd(HW::item<route::table_id_t>& item, |
| 304 | const l3_proto_t& proto, |
| 305 | const HW::item<handle_t>& h); |
| 306 | |
| 307 | /** |
| 308 | * Issue the command to VPP/HW |
| 309 | */ |
| 310 | rc_t issue(connection& con); |
| 311 | |
| 312 | /** |
| 313 | * convert to string format for debug purposes |
| 314 | */ |
| 315 | std::string to_string() const; |
| 316 | |
| 317 | /** |
| 318 | * Comparison operator - only used for UT |
| 319 | */ |
| 320 | bool operator==(const set_table_cmd& i) const; |
| 321 | |
| 322 | private: |
| 323 | /** |
| 324 | * the handle of the interface to update |
| 325 | */ |
| 326 | const HW::item<handle_t>& m_hdl; |
| 327 | |
| 328 | /** |
| 329 | * The L3 protocol of the table |
| 330 | */ |
| 331 | l3_proto_t m_proto; |
| 332 | }; |
| 333 | |
| 334 | /** |
| 335 | * A command class that binds an interface to an L3 table |
| 336 | */ |
| 337 | class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>, |
| 338 | rc_t, |
| 339 | vapi::Sw_interface_set_mac_address> |
| 340 | { |
| 341 | public: |
| 342 | /** |
| 343 | * Constructor taking the HW::item to update |
| 344 | * and the handle of the interface |
| 345 | */ |
| 346 | set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h); |
| 347 | |
| 348 | /** |
| 349 | * Issue the command to VPP/HW |
| 350 | */ |
| 351 | rc_t issue(connection& con); |
| 352 | |
| 353 | /** |
| 354 | * convert to string format for debug purposes |
| 355 | */ |
| 356 | std::string to_string() const; |
| 357 | |
| 358 | /** |
| 359 | * Comparison operator - only used for UT |
| 360 | */ |
| 361 | bool operator==(const set_mac_cmd& i) const; |
| 362 | |
| 363 | private: |
| 364 | /** |
| 365 | * the handle of the interface to update |
| 366 | */ |
| 367 | const HW::item<handle_t>& m_hdl; |
| 368 | }; |
| 369 | |
| 370 | /** |
| 371 | * A command class represents our desire to recieve interface events |
| 372 | */ |
| 373 | class events_cmd |
| 374 | : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event> |
| 375 | { |
| 376 | public: |
| 377 | /** |
| 378 | * Constructor taking the listner to notify |
| 379 | */ |
| 380 | events_cmd(interface::event_listener& el); |
| 381 | |
| 382 | /** |
| 383 | * Issue the command to VPP/HW |
| 384 | */ |
| 385 | rc_t issue(connection& con); |
| 386 | |
| 387 | /** |
| 388 | * Retires the command - unsubscribe from the events. |
| 389 | */ |
| 390 | void retire(connection& con); |
| 391 | |
| 392 | /** |
| 393 | * convert to string format for debug purposes |
| 394 | */ |
| 395 | std::string to_string() const; |
| 396 | |
| 397 | /** |
| 398 | * Comparison operator - only used for UT |
| 399 | */ |
| 400 | bool operator==(const events_cmd& i) const; |
| 401 | |
| 402 | /** |
| 403 | * Called when it's time to poke the listeners |
| 404 | */ |
| 405 | void notify(); |
| 406 | |
| 407 | private: |
| 408 | /** |
| 409 | * The listeners to notify when data/events arrive |
| 410 | */ |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 411 | interface::event_listener& m_listener; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | /** |
| 415 | * A command class represents our desire to recieve interface stats |
| 416 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 417 | class stats_enable_cmd |
| 418 | : public event_cmd<vapi::Want_per_interface_combined_stats, |
| 419 | vapi::Vnet_per_interface_combined_counters> |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 420 | { |
| 421 | public: |
| 422 | /** |
| 423 | * Constructor taking the listner to notify |
| 424 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 425 | stats_enable_cmd(interface::stat_listener& el, const handle_t& handle); |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 426 | |
| 427 | /** |
| 428 | * Issue the command to VPP/HW |
| 429 | */ |
| 430 | rc_t issue(connection& con); |
| 431 | |
| 432 | /** |
| 433 | * Retires the command - unsubscribe from the stats. |
| 434 | */ |
| 435 | void retire(connection& con); |
| 436 | |
| 437 | /** |
| 438 | * convert to string format for debug purposes |
| 439 | */ |
| 440 | std::string to_string() const; |
| 441 | |
| 442 | /** |
| 443 | * Comparison operator - only used for UT |
| 444 | */ |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 445 | bool operator==(const stats_enable_cmd& i) const; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 446 | |
| 447 | /** |
| 448 | * Called when it's time to poke the listeners |
| 449 | */ |
| 450 | void notify(); |
| 451 | |
| 452 | private: |
| 453 | /** |
| 454 | * The listeners to notify when data/stats arrive |
| 455 | */ |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 456 | interface::stat_listener& m_listener; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 457 | |
Neale Ranns | a2ee029 | 2017-11-28 22:29:13 -0800 | [diff] [blame] | 458 | /** |
| 459 | * The interface on which we are enabling states |
| 460 | */ |
| 461 | handle_t m_swifindex; |
| 462 | }; |
| 463 | |
| 464 | /** |
| 465 | * A command class represents our desire to recieve interface stats |
| 466 | */ |
| 467 | class stats_disable_cmd |
| 468 | : public rpc_cmd<HW::item<bool>, |
| 469 | rc_t, |
| 470 | vapi::Want_per_interface_combined_stats> |
| 471 | { |
| 472 | public: |
| 473 | /** |
| 474 | * Constructor taking the listner to notify |
| 475 | */ |
| 476 | stats_disable_cmd(const handle_t& handle); |
| 477 | |
| 478 | /** |
| 479 | * Issue the command to VPP/HW |
| 480 | */ |
| 481 | rc_t issue(connection& con); |
| 482 | |
| 483 | /** |
| 484 | * convert to string format for debug purposes |
| 485 | */ |
| 486 | std::string to_string() const; |
| 487 | |
| 488 | /** |
| 489 | * Comparison operator - only used for UT |
| 490 | */ |
| 491 | bool operator==(const stats_disable_cmd& i) const; |
| 492 | |
| 493 | private: |
| 494 | HW::item<bool> m_res; |
| 495 | /** |
| 496 | * The interface on which we are disabling states |
| 497 | */ |
Mohsin Kazmi | 5a4f96a | 2017-11-20 10:23:47 +0100 | [diff] [blame] | 498 | handle_t m_swifindex; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 499 | }; |
| 500 | |
| 501 | /** |
| 502 | * A cmd class that Dumps all the Vpp interfaces |
| 503 | */ |
| 504 | class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump> |
| 505 | { |
| 506 | public: |
| 507 | /** |
| 508 | * Default Constructor |
| 509 | */ |
| 510 | dump_cmd(); |
| 511 | |
| 512 | /** |
| 513 | * Issue the command to VPP/HW |
| 514 | */ |
| 515 | rc_t issue(connection& con); |
| 516 | /** |
| 517 | * convert to string format for debug purposes |
| 518 | */ |
| 519 | std::string to_string() const; |
| 520 | |
| 521 | /** |
| 522 | * Comparison operator - only used for UT |
| 523 | */ |
| 524 | bool operator==(const dump_cmd& i) const; |
| 525 | }; |
Neale Ranns | 4ef4226 | 2018-02-20 08:10:44 -0800 | [diff] [blame] | 526 | |
| 527 | /** |
| 528 | * A cmd class that Dumps all the Vpp Interfaces |
| 529 | */ |
| 530 | class vhost_dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_vhost_user_dump> |
| 531 | { |
| 532 | public: |
| 533 | /** |
| 534 | * Default Constructor |
| 535 | */ |
| 536 | vhost_dump_cmd(); |
| 537 | |
| 538 | /** |
| 539 | * Issue the command to VPP/HW |
| 540 | */ |
| 541 | rc_t issue(connection& con); |
| 542 | /** |
| 543 | * convert to string format for debug purposes |
| 544 | */ |
| 545 | std::string to_string() const; |
| 546 | |
| 547 | /** |
| 548 | * Comparison operator - only used for UT |
| 549 | */ |
| 550 | bool operator==(const vhost_dump_cmd& i) const; |
| 551 | }; |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 552 | }; |
| 553 | }; |
| 554 | /* |
| 555 | * fd.io coding-style-patch-verification: ON |
| 556 | * |
| 557 | * Local Variables: |
| 558 | * eval: (c-set-style "mozilla") |
| 559 | * End: |
| 560 | */ |
| 561 | #endif |