Filip Tehlar | 1b6fb40 | 2021-07-24 18:10:39 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2021 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #include <vat/vat.h> |
| 6 | #include <vlibapi/api.h> |
| 7 | #include <vlibmemory/api.h> |
| 8 | #include <vppinfra/error.h> |
| 9 | #include <vpp/api/types.h> |
| 10 | #include <inttypes.h> |
| 11 | |
| 12 | #include <vnet/l2/l2_classify.h> |
| 13 | #include <vnet/l2/l2_vtr.h> |
| 14 | #include <vnet/ip/ip_types_api.h> |
| 15 | |
| 16 | #define __plugin_msg_base l2_test_main.msg_id_base |
| 17 | #include <vlibapi/vat_helper_macros.h> |
| 18 | |
| 19 | #include <vlibmemory/vlib.api_enum.h> |
| 20 | #include <vlibmemory/vlib.api_types.h> |
| 21 | |
| 22 | /* Declare message IDs */ |
| 23 | #include <vnet/format_fns.h> |
| 24 | #include <vnet/l2/l2.api_enum.h> |
| 25 | #include <vnet/l2/l2.api_types.h> |
| 26 | |
| 27 | #define vl_endianfun /* define message structures */ |
| 28 | #include <vnet/l2/l2.api.h> |
| 29 | #undef vl_endianfun |
| 30 | |
Klement Sekera | 9b7e8ac | 2021-11-22 21:26:20 +0100 | [diff] [blame^] | 31 | #define vl_calcsizefun |
| 32 | #include <vnet/l2/l2.api.h> |
| 33 | #undef vl_calcsizefun |
| 34 | |
Filip Tehlar | 1b6fb40 | 2021-07-24 18:10:39 +0000 | [diff] [blame] | 35 | typedef struct |
| 36 | { |
| 37 | /* API message ID base */ |
| 38 | u16 msg_id_base; |
| 39 | u32 ping_id; |
| 40 | vat_main_t *vat_main; |
| 41 | } l2_test_main_t; |
| 42 | |
| 43 | static l2_test_main_t l2_test_main; |
| 44 | |
| 45 | static void |
| 46 | vl_api_l2_fib_table_details_t_handler (vl_api_l2_fib_table_details_t *mp) |
| 47 | { |
| 48 | vat_main_t *vam = l2_test_main.vat_main; |
| 49 | |
| 50 | fformat ( |
| 51 | vam->ofp, "%3" PRIu32 " %U %3" PRIu32 " %d %d %d", |
| 52 | ntohl (mp->bd_id), format_ethernet_address, mp->mac, |
| 53 | ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac, mp->bvi_mac); |
| 54 | } |
| 55 | |
| 56 | static int |
| 57 | api_l2_fib_table_dump (vat_main_t *vam) |
| 58 | { |
| 59 | unformat_input_t *i = vam->input; |
| 60 | vl_api_l2_fib_table_dump_t *mp; |
| 61 | vl_api_control_ping_t *mp_ping; |
| 62 | u32 bd_id; |
| 63 | u8 bd_id_set = 0; |
| 64 | int ret; |
| 65 | |
| 66 | /* Parse args required to build the message */ |
| 67 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 68 | { |
| 69 | if (unformat (i, "bd_id %d", &bd_id)) |
| 70 | bd_id_set = 1; |
| 71 | else |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | if (bd_id_set == 0) |
| 76 | { |
| 77 | errmsg ("missing bridge domain"); |
| 78 | return -99; |
| 79 | } |
| 80 | |
| 81 | fformat (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI"); |
| 82 | |
| 83 | /* Get list of l2 fib entries */ |
| 84 | M (L2_FIB_TABLE_DUMP, mp); |
| 85 | |
| 86 | mp->bd_id = ntohl (bd_id); |
| 87 | S (mp); |
| 88 | |
| 89 | /* Use a control ping for synchronization */ |
| 90 | PING (&l2_test_main, mp_ping); |
| 91 | S (mp_ping); |
| 92 | |
| 93 | W (ret); |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | static void |
| 98 | vl_api_l2_xconnect_details_t_handler (vl_api_l2_xconnect_details_t *mp) |
| 99 | { |
| 100 | vat_main_t *vam = l2_test_main.vat_main; |
| 101 | fformat (vam->ofp, "%15d%15d", ntohl (mp->rx_sw_if_index), |
| 102 | ntohl (mp->tx_sw_if_index)); |
| 103 | } |
| 104 | |
| 105 | static int |
| 106 | api_l2_xconnect_dump (vat_main_t *vam) |
| 107 | { |
| 108 | vl_api_l2_xconnect_dump_t *mp; |
| 109 | vl_api_control_ping_t *mp_ping; |
| 110 | int ret; |
| 111 | |
| 112 | if (!vam->json_output) |
| 113 | { |
| 114 | print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index"); |
| 115 | } |
| 116 | |
| 117 | M (L2_XCONNECT_DUMP, mp); |
| 118 | |
| 119 | S (mp); |
| 120 | |
| 121 | /* Use a control ping for synchronization */ |
| 122 | PING (&l2_test_main, mp_ping); |
| 123 | S (mp_ping); |
| 124 | |
| 125 | W (ret); |
| 126 | return ret; |
| 127 | } |
| 128 | |
| 129 | static int |
| 130 | api_want_l2_arp_term_events (vat_main_t *vam) |
| 131 | { |
| 132 | return -1; |
| 133 | } |
| 134 | |
| 135 | static int |
| 136 | api_want_l2_macs_events (vat_main_t *vam) |
| 137 | { |
| 138 | unformat_input_t *line_input = vam->input; |
| 139 | vl_api_want_l2_macs_events_t *mp; |
| 140 | u8 enable_disable = 1; |
| 141 | u32 scan_delay = 0; |
| 142 | u32 max_macs_in_event = 0; |
| 143 | u32 learn_limit = 0; |
| 144 | int ret; |
| 145 | |
| 146 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 147 | { |
| 148 | if (unformat (line_input, "learn-limit %d", &learn_limit)) |
| 149 | ; |
| 150 | else if (unformat (line_input, "scan-delay %d", &scan_delay)) |
| 151 | ; |
| 152 | else if (unformat (line_input, "max-entries %d", &max_macs_in_event)) |
| 153 | ; |
| 154 | else if (unformat (line_input, "disable")) |
| 155 | enable_disable = 0; |
| 156 | else |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | M (WANT_L2_MACS_EVENTS, mp); |
| 161 | mp->enable_disable = enable_disable; |
| 162 | mp->pid = htonl (getpid ()); |
| 163 | mp->learn_limit = htonl (learn_limit); |
| 164 | mp->scan_delay = (u8) scan_delay; |
| 165 | mp->max_macs_in_event = (u8) (max_macs_in_event / 10); |
| 166 | S (mp); |
| 167 | W (ret); |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | static int |
| 172 | api_l2fib_flush_all (vat_main_t *vam) |
| 173 | { |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | static void |
| 178 | increment_mac_address (u8 *mac) |
| 179 | { |
| 180 | u64 tmp = *((u64 *) mac); |
| 181 | tmp = clib_net_to_host_u64 (tmp); |
| 182 | tmp += 1 << 16; /* skip unused (least significant) octets */ |
| 183 | tmp = clib_host_to_net_u64 (tmp); |
| 184 | |
| 185 | clib_memcpy (mac, &tmp, 6); |
| 186 | } |
| 187 | |
| 188 | static int |
| 189 | api_l2fib_add_del (vat_main_t *vam) |
| 190 | { |
| 191 | vnet_main_t *vnm = vnet_get_main (); |
| 192 | unformat_input_t *i = vam->input; |
| 193 | vl_api_l2fib_add_del_t *mp; |
| 194 | f64 timeout; |
Damjan Marion | 60706a2 | 2021-10-31 19:21:31 +0100 | [diff] [blame] | 195 | u8 mac[8] = { 0 }; |
Filip Tehlar | 1b6fb40 | 2021-07-24 18:10:39 +0000 | [diff] [blame] | 196 | u8 mac_set = 0; |
| 197 | u32 bd_id; |
| 198 | u8 bd_id_set = 0; |
| 199 | u32 sw_if_index = 0; |
| 200 | u8 sw_if_index_set = 0; |
| 201 | u8 is_add = 1; |
| 202 | u8 static_mac = 0; |
| 203 | u8 filter_mac = 0; |
| 204 | u8 bvi_mac = 0; |
| 205 | int count = 1; |
| 206 | f64 before = 0; |
| 207 | int j; |
| 208 | |
| 209 | /* Parse args required to build the message */ |
| 210 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 211 | { |
| 212 | if (unformat (i, "mac %U", unformat_ethernet_address, mac)) |
| 213 | mac_set = 1; |
| 214 | else if (unformat (i, "bd_id %d", &bd_id)) |
| 215 | bd_id_set = 1; |
| 216 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 217 | sw_if_index_set = 1; |
| 218 | else if (unformat (i, "sw_if")) |
| 219 | { |
| 220 | if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 221 | { |
| 222 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 223 | &sw_if_index)) |
| 224 | sw_if_index_set = 1; |
| 225 | } |
| 226 | else |
| 227 | break; |
| 228 | } |
| 229 | else if (unformat (i, "static")) |
| 230 | static_mac = 1; |
| 231 | else if (unformat (i, "filter")) |
| 232 | { |
| 233 | filter_mac = 1; |
| 234 | static_mac = 1; |
| 235 | } |
| 236 | else if (unformat (i, "bvi")) |
| 237 | { |
| 238 | bvi_mac = 1; |
| 239 | static_mac = 1; |
| 240 | } |
| 241 | else if (unformat (i, "del")) |
| 242 | is_add = 0; |
| 243 | else if (unformat (i, "count %d", &count)) |
| 244 | ; |
| 245 | else |
| 246 | break; |
| 247 | } |
| 248 | |
| 249 | if (mac_set == 0) |
| 250 | { |
| 251 | errmsg ("missing mac address"); |
| 252 | return -99; |
| 253 | } |
| 254 | |
| 255 | if (bd_id_set == 0) |
| 256 | { |
| 257 | errmsg ("missing bridge domain"); |
| 258 | return -99; |
| 259 | } |
| 260 | |
| 261 | if (is_add && sw_if_index_set == 0 && filter_mac == 0) |
| 262 | { |
| 263 | errmsg ("missing interface name or sw_if_index"); |
| 264 | return -99; |
| 265 | } |
| 266 | |
| 267 | if (count > 1) |
| 268 | { |
| 269 | /* Turn on async mode */ |
| 270 | vam->async_mode = 1; |
| 271 | vam->async_errors = 0; |
| 272 | before = vat_time_now (vam); |
| 273 | } |
| 274 | |
| 275 | for (j = 0; j < count; j++) |
| 276 | { |
| 277 | M (L2FIB_ADD_DEL, mp); |
| 278 | |
| 279 | clib_memcpy (mp->mac, mac, 6); |
| 280 | mp->bd_id = ntohl (bd_id); |
| 281 | mp->is_add = is_add; |
| 282 | mp->sw_if_index = ntohl (sw_if_index); |
| 283 | |
| 284 | if (is_add) |
| 285 | { |
| 286 | mp->static_mac = static_mac; |
| 287 | mp->filter_mac = filter_mac; |
| 288 | mp->bvi_mac = bvi_mac; |
| 289 | } |
| 290 | increment_mac_address (mac); |
| 291 | /* send it... */ |
| 292 | S (mp); |
| 293 | } |
| 294 | |
| 295 | if (count > 1) |
| 296 | { |
| 297 | vl_api_control_ping_t *mp_ping; |
| 298 | f64 after; |
| 299 | |
| 300 | /* Shut off async mode */ |
| 301 | vam->async_mode = 0; |
| 302 | |
| 303 | PING (&l2_test_main, mp_ping); |
| 304 | S (mp_ping); |
| 305 | |
| 306 | timeout = vat_time_now (vam) + 1.0; |
| 307 | while (vat_time_now (vam) < timeout) |
| 308 | if (vam->result_ready == 1) |
| 309 | goto out; |
| 310 | vam->retval = -99; |
| 311 | |
| 312 | out: |
| 313 | if (vam->retval == -99) |
| 314 | errmsg ("timeout"); |
| 315 | |
| 316 | if (vam->async_errors > 0) |
| 317 | { |
| 318 | errmsg ("%d asynchronous errors", vam->async_errors); |
| 319 | vam->retval = -98; |
| 320 | } |
| 321 | vam->async_errors = 0; |
| 322 | after = vat_time_now (vam); |
| 323 | |
| 324 | print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", count, |
| 325 | after - before, count / (after - before)); |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | int ret; |
| 330 | |
| 331 | /* Wait for a reply... */ |
| 332 | W (ret); |
| 333 | return ret; |
| 334 | } |
| 335 | /* Return the good/bad news */ |
| 336 | return (vam->retval); |
| 337 | } |
| 338 | |
| 339 | static int |
| 340 | api_l2fib_flush_int (vat_main_t *vam) |
| 341 | { |
| 342 | vnet_main_t *vnm = vnet_get_main (); |
| 343 | unformat_input_t *i = vam->input; |
| 344 | vl_api_l2fib_flush_int_t *mp; |
| 345 | u32 sw_if_index = ~0; |
| 346 | int ret; |
| 347 | |
| 348 | /* Parse args required to build the message */ |
| 349 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 350 | { |
| 351 | if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 352 | ; |
| 353 | else if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 354 | &sw_if_index)) |
| 355 | ; |
| 356 | else |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | if (sw_if_index == ~0) |
| 361 | { |
| 362 | errmsg ("missing interface name or sw_if_index"); |
| 363 | return -99; |
| 364 | } |
| 365 | |
| 366 | M (L2FIB_FLUSH_INT, mp); |
| 367 | |
| 368 | mp->sw_if_index = ntohl (sw_if_index); |
| 369 | |
| 370 | S (mp); |
| 371 | W (ret); |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | static int |
| 376 | api_l2_fib_clear_table (vat_main_t *vam) |
| 377 | { |
| 378 | vl_api_l2_fib_clear_table_t *mp; |
| 379 | int ret; |
| 380 | |
| 381 | M (L2_FIB_CLEAR_TABLE, mp); |
| 382 | |
| 383 | S (mp); |
| 384 | W (ret); |
| 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | static int |
| 389 | api_bridge_domain_set_mac_age (vat_main_t *vam) |
| 390 | { |
| 391 | unformat_input_t *i = vam->input; |
| 392 | vl_api_bridge_domain_set_mac_age_t *mp; |
| 393 | u32 bd_id = ~0; |
| 394 | u32 mac_age = 0; |
| 395 | int ret; |
| 396 | |
| 397 | /* Parse args required to build the message */ |
| 398 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 399 | { |
| 400 | if (unformat (i, "bd_id %d", &bd_id)) |
| 401 | ; |
| 402 | else if (unformat (i, "mac-age %d", &mac_age)) |
| 403 | ; |
| 404 | else |
| 405 | break; |
| 406 | } |
| 407 | |
| 408 | if (bd_id == ~0) |
| 409 | { |
| 410 | errmsg ("missing bridge domain"); |
| 411 | return -99; |
| 412 | } |
| 413 | |
| 414 | if (mac_age > 255) |
| 415 | { |
| 416 | errmsg ("mac age must be less than 256 "); |
| 417 | return -99; |
| 418 | } |
| 419 | |
| 420 | M (BRIDGE_DOMAIN_SET_MAC_AGE, mp); |
| 421 | |
| 422 | mp->bd_id = htonl (bd_id); |
| 423 | mp->mac_age = (u8) mac_age; |
| 424 | |
| 425 | S (mp); |
| 426 | W (ret); |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | static int |
| 431 | api_l2fib_set_scan_delay (vat_main_t *vam) |
| 432 | { |
| 433 | return -1; |
| 434 | } |
| 435 | |
| 436 | static int |
| 437 | api_want_l2_macs_events2 (vat_main_t *vam) |
| 438 | { |
| 439 | return -1; |
| 440 | } |
| 441 | |
| 442 | static int |
| 443 | api_l2_flags (vat_main_t *vam) |
| 444 | { |
| 445 | vnet_main_t *vnm = vnet_get_main (); |
| 446 | unformat_input_t *i = vam->input; |
| 447 | vl_api_l2_flags_t *mp; |
| 448 | u32 sw_if_index; |
| 449 | u32 flags = 0; |
| 450 | u8 sw_if_index_set = 0; |
| 451 | u8 is_set = 0; |
| 452 | int ret; |
| 453 | |
| 454 | /* Parse args required to build the message */ |
| 455 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 456 | { |
| 457 | if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 458 | sw_if_index_set = 1; |
| 459 | else if (unformat (i, "sw_if")) |
| 460 | { |
| 461 | if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 462 | { |
| 463 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 464 | &sw_if_index)) |
| 465 | sw_if_index_set = 1; |
| 466 | } |
| 467 | else |
| 468 | break; |
| 469 | } |
| 470 | else if (unformat (i, "learn")) |
| 471 | flags |= L2_LEARN; |
| 472 | else if (unformat (i, "forward")) |
| 473 | flags |= L2_FWD; |
| 474 | else if (unformat (i, "flood")) |
| 475 | flags |= L2_FLOOD; |
| 476 | else if (unformat (i, "uu-flood")) |
| 477 | flags |= L2_UU_FLOOD; |
| 478 | else if (unformat (i, "arp-term")) |
| 479 | flags |= L2_ARP_TERM; |
| 480 | else if (unformat (i, "off")) |
| 481 | is_set = 0; |
| 482 | else if (unformat (i, "disable")) |
| 483 | is_set = 0; |
| 484 | else |
| 485 | break; |
| 486 | } |
| 487 | |
| 488 | if (sw_if_index_set == 0) |
| 489 | { |
| 490 | errmsg ("missing interface name or sw_if_index"); |
| 491 | return -99; |
| 492 | } |
| 493 | |
| 494 | M (L2_FLAGS, mp); |
| 495 | |
| 496 | mp->sw_if_index = ntohl (sw_if_index); |
| 497 | mp->feature_bitmap = ntohl (flags); |
| 498 | mp->is_set = is_set; |
| 499 | |
| 500 | S (mp); |
| 501 | W (ret); |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | static void |
| 506 | vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t *mp) |
| 507 | { |
| 508 | vat_main_t *vam = l2_test_main.vat_main; |
| 509 | i32 retval = ntohl (mp->retval); |
| 510 | if (vam->async_mode) |
| 511 | { |
| 512 | vam->async_errors += (retval < 0); |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | vam->retval = retval; |
| 517 | vam->result_ready = 1; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | static int |
| 522 | api_l2fib_flush_bd (vat_main_t *vam) |
| 523 | { |
| 524 | unformat_input_t *i = vam->input; |
| 525 | vl_api_l2fib_flush_bd_t *mp; |
| 526 | u32 bd_id = ~0; |
| 527 | int ret; |
| 528 | |
| 529 | /* Parse args required to build the message */ |
| 530 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 531 | { |
| 532 | if (unformat (i, "bd_id %d", &bd_id)) |
| 533 | ; |
| 534 | else |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | if (bd_id == ~0) |
| 539 | { |
| 540 | errmsg ("missing bridge domain"); |
| 541 | return -99; |
| 542 | } |
| 543 | |
| 544 | M (L2FIB_FLUSH_BD, mp); |
| 545 | |
| 546 | mp->bd_id = htonl (bd_id); |
| 547 | |
| 548 | S (mp); |
| 549 | W (ret); |
| 550 | return ret; |
| 551 | } |
| 552 | |
| 553 | static int |
| 554 | api_bridge_domain_add_del (vat_main_t *vam) |
| 555 | { |
| 556 | unformat_input_t *i = vam->input; |
| 557 | vl_api_bridge_domain_add_del_t *mp; |
| 558 | u32 bd_id = ~0; |
| 559 | u8 is_add = 1; |
| 560 | u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0; |
| 561 | u8 *bd_tag = NULL; |
| 562 | u32 mac_age = 0; |
| 563 | int ret; |
| 564 | |
| 565 | /* Parse args required to build the message */ |
| 566 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 567 | { |
| 568 | if (unformat (i, "bd_id %d", &bd_id)) |
| 569 | ; |
| 570 | else if (unformat (i, "flood %d", &flood)) |
| 571 | ; |
| 572 | else if (unformat (i, "uu-flood %d", &uu_flood)) |
| 573 | ; |
| 574 | else if (unformat (i, "forward %d", &forward)) |
| 575 | ; |
| 576 | else if (unformat (i, "learn %d", &learn)) |
| 577 | ; |
| 578 | else if (unformat (i, "arp-term %d", &arp_term)) |
| 579 | ; |
| 580 | else if (unformat (i, "mac-age %d", &mac_age)) |
| 581 | ; |
| 582 | else if (unformat (i, "bd-tag %s", &bd_tag)) |
| 583 | ; |
| 584 | else if (unformat (i, "del")) |
| 585 | { |
| 586 | is_add = 0; |
| 587 | flood = uu_flood = forward = learn = 0; |
| 588 | } |
| 589 | else |
| 590 | break; |
| 591 | } |
| 592 | |
| 593 | if (bd_id == ~0) |
| 594 | { |
| 595 | errmsg ("missing bridge domain"); |
| 596 | ret = -99; |
| 597 | goto done; |
| 598 | } |
| 599 | |
| 600 | if (mac_age > 255) |
| 601 | { |
| 602 | errmsg ("mac age must be less than 256 "); |
| 603 | ret = -99; |
| 604 | goto done; |
| 605 | } |
| 606 | |
| 607 | if ((bd_tag) && (vec_len (bd_tag) > 63)) |
| 608 | { |
| 609 | errmsg ("bd-tag cannot be longer than 63"); |
| 610 | ret = -99; |
| 611 | goto done; |
| 612 | } |
| 613 | |
| 614 | M (BRIDGE_DOMAIN_ADD_DEL, mp); |
| 615 | |
| 616 | mp->bd_id = ntohl (bd_id); |
| 617 | mp->flood = flood; |
| 618 | mp->uu_flood = uu_flood; |
| 619 | mp->forward = forward; |
| 620 | mp->learn = learn; |
| 621 | mp->arp_term = arp_term; |
| 622 | mp->is_add = is_add; |
| 623 | mp->mac_age = (u8) mac_age; |
| 624 | if (bd_tag) |
| 625 | { |
| 626 | clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag)); |
| 627 | mp->bd_tag[vec_len (bd_tag)] = 0; |
| 628 | } |
| 629 | S (mp); |
| 630 | W (ret); |
| 631 | |
| 632 | done: |
| 633 | vec_free (bd_tag); |
| 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | #define foreach_pbb_vtr_op \ |
| 638 | _ ("disable", L2_VTR_DISABLED) \ |
| 639 | _ ("pop", L2_VTR_POP_2) \ |
| 640 | _ ("push", L2_VTR_PUSH_2) |
| 641 | |
| 642 | static int |
| 643 | api_l2_interface_pbb_tag_rewrite (vat_main_t *vam) |
| 644 | { |
| 645 | vnet_main_t *vnm = vnet_get_main (); |
| 646 | unformat_input_t *i = vam->input; |
| 647 | vl_api_l2_interface_pbb_tag_rewrite_t *mp; |
| 648 | u32 sw_if_index = ~0, vtr_op = ~0; |
| 649 | u16 outer_tag = ~0; |
| 650 | u8 dmac[6], smac[6]; |
| 651 | u8 dmac_set = 0, smac_set = 0; |
| 652 | u16 vlanid = 0; |
| 653 | u32 sid = ~0; |
| 654 | u32 tmp; |
| 655 | int ret; |
| 656 | |
| 657 | /* Shut up coverity */ |
| 658 | clib_memset (dmac, 0, sizeof (dmac)); |
| 659 | clib_memset (smac, 0, sizeof (smac)); |
| 660 | |
| 661 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 662 | { |
| 663 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 664 | ; |
| 665 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 666 | ; |
| 667 | else if (unformat (i, "vtr_op %d", &vtr_op)) |
| 668 | ; |
| 669 | #define _(n, v) \ |
| 670 | else if (unformat (i, n)) { vtr_op = v; } |
| 671 | foreach_pbb_vtr_op |
| 672 | #undef _ |
| 673 | else if (unformat (i, "translate_pbb_stag")) |
| 674 | { |
| 675 | if (unformat (i, "%d", &tmp)) |
| 676 | { |
| 677 | vtr_op = L2_VTR_TRANSLATE_2_1; |
| 678 | outer_tag = tmp; |
| 679 | } |
| 680 | else |
| 681 | { |
| 682 | errmsg ( |
| 683 | "translate_pbb_stag operation requires outer tag definition"); |
| 684 | return -99; |
| 685 | } |
| 686 | } |
| 687 | else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac)) |
| 688 | dmac_set++; |
| 689 | else if (unformat (i, "smac %U", unformat_ethernet_address, smac)) |
| 690 | smac_set++; |
| 691 | else if (unformat (i, "sid %d", &sid)); |
| 692 | else if (unformat (i, "vlanid %d", &tmp)) vlanid = tmp; |
| 693 | else |
| 694 | { |
| 695 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 696 | return -99; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | if ((sw_if_index == ~0) || (vtr_op == ~0)) |
| 701 | { |
| 702 | errmsg ("missing sw_if_index or vtr operation"); |
| 703 | return -99; |
| 704 | } |
| 705 | if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2)) && |
| 706 | ((dmac_set == 0) || (smac_set == 0) || (sid == ~0))) |
| 707 | { |
| 708 | errmsg ("push and translate_qinq operations require dmac, smac, sid and " |
| 709 | "optionally vlanid"); |
| 710 | return -99; |
| 711 | } |
| 712 | |
| 713 | M (L2_INTERFACE_PBB_TAG_REWRITE, mp); |
| 714 | mp->sw_if_index = ntohl (sw_if_index); |
| 715 | mp->vtr_op = ntohl (vtr_op); |
| 716 | mp->outer_tag = ntohs (outer_tag); |
| 717 | clib_memcpy (mp->b_dmac, dmac, sizeof (dmac)); |
| 718 | clib_memcpy (mp->b_smac, smac, sizeof (smac)); |
| 719 | mp->b_vlanid = ntohs (vlanid); |
| 720 | mp->i_sid = ntohl (sid); |
| 721 | |
| 722 | S (mp); |
| 723 | W (ret); |
| 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | static int |
| 728 | api_sw_interface_set_l2_xconnect (vat_main_t *vam) |
| 729 | { |
| 730 | vnet_main_t *vnm = vnet_get_main (); |
| 731 | unformat_input_t *i = vam->input; |
| 732 | vl_api_sw_interface_set_l2_xconnect_t *mp; |
| 733 | u32 rx_sw_if_index; |
| 734 | u8 rx_sw_if_index_set = 0; |
| 735 | u32 tx_sw_if_index; |
| 736 | u8 tx_sw_if_index_set = 0; |
| 737 | u8 enable = 1; |
| 738 | int ret; |
| 739 | |
| 740 | /* Parse args required to build the message */ |
| 741 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 742 | { |
| 743 | if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index)) |
| 744 | rx_sw_if_index_set = 1; |
| 745 | else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index)) |
| 746 | tx_sw_if_index_set = 1; |
| 747 | else if (unformat (i, "rx")) |
| 748 | { |
| 749 | if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 750 | { |
| 751 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 752 | &rx_sw_if_index)) |
| 753 | rx_sw_if_index_set = 1; |
| 754 | } |
| 755 | else |
| 756 | break; |
| 757 | } |
| 758 | else if (unformat (i, "tx")) |
| 759 | { |
| 760 | if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 761 | { |
| 762 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 763 | &tx_sw_if_index)) |
| 764 | tx_sw_if_index_set = 1; |
| 765 | } |
| 766 | else |
| 767 | break; |
| 768 | } |
| 769 | else if (unformat (i, "enable")) |
| 770 | enable = 1; |
| 771 | else if (unformat (i, "disable")) |
| 772 | enable = 0; |
| 773 | else |
| 774 | break; |
| 775 | } |
| 776 | |
| 777 | if (rx_sw_if_index_set == 0) |
| 778 | { |
| 779 | errmsg ("missing rx interface name or rx_sw_if_index"); |
| 780 | return -99; |
| 781 | } |
| 782 | |
| 783 | if (enable && (tx_sw_if_index_set == 0)) |
| 784 | { |
| 785 | errmsg ("missing tx interface name or tx_sw_if_index"); |
| 786 | return -99; |
| 787 | } |
| 788 | |
| 789 | M (SW_INTERFACE_SET_L2_XCONNECT, mp); |
| 790 | |
| 791 | mp->rx_sw_if_index = ntohl (rx_sw_if_index); |
| 792 | mp->tx_sw_if_index = ntohl (tx_sw_if_index); |
| 793 | mp->enable = enable; |
| 794 | |
| 795 | S (mp); |
| 796 | W (ret); |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | static int |
| 801 | api_l2_interface_efp_filter (vat_main_t *vam) |
| 802 | { |
| 803 | vnet_main_t *vnm = vnet_get_main (); |
| 804 | unformat_input_t *i = vam->input; |
| 805 | vl_api_l2_interface_efp_filter_t *mp; |
| 806 | u32 sw_if_index; |
| 807 | u8 enable = 1; |
| 808 | u8 sw_if_index_set = 0; |
| 809 | int ret; |
| 810 | |
| 811 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 812 | { |
| 813 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 814 | sw_if_index_set = 1; |
| 815 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 816 | sw_if_index_set = 1; |
| 817 | else if (unformat (i, "enable")) |
| 818 | enable = 1; |
| 819 | else if (unformat (i, "disable")) |
| 820 | enable = 0; |
| 821 | else |
| 822 | { |
| 823 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 824 | return -99; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | if (sw_if_index_set == 0) |
| 829 | { |
| 830 | errmsg ("missing sw_if_index"); |
| 831 | return -99; |
| 832 | } |
| 833 | |
| 834 | M (L2_INTERFACE_EFP_FILTER, mp); |
| 835 | |
| 836 | mp->sw_if_index = ntohl (sw_if_index); |
| 837 | mp->enable_disable = enable; |
| 838 | |
| 839 | S (mp); |
| 840 | W (ret); |
| 841 | return ret; |
| 842 | } |
| 843 | |
| 844 | static void |
| 845 | vl_api_bd_ip_mac_details_t_handler (vl_api_bd_ip_mac_details_t *mp) |
| 846 | { |
| 847 | vat_main_t *vam = &vat_main; |
| 848 | |
| 849 | print (vam->ofp, "\n%-5d %U %U", ntohl (mp->entry.bd_id), |
| 850 | format_vl_api_mac_address, mp->entry.mac, format_vl_api_address, |
| 851 | &mp->entry.ip); |
| 852 | } |
| 853 | |
| 854 | static void |
| 855 | vl_api_bvi_create_reply_t_handler (vl_api_bvi_create_reply_t *mp) |
| 856 | { |
| 857 | } |
| 858 | |
| 859 | static int |
| 860 | api_sw_interface_set_l2_bridge (vat_main_t *vam) |
| 861 | { |
| 862 | vnet_main_t *vnm = vnet_get_main (); |
| 863 | unformat_input_t *i = vam->input; |
| 864 | vl_api_sw_interface_set_l2_bridge_t *mp; |
| 865 | vl_api_l2_port_type_t port_type; |
| 866 | u32 rx_sw_if_index; |
| 867 | u8 rx_sw_if_index_set = 0; |
| 868 | u32 bd_id; |
| 869 | u8 bd_id_set = 0; |
| 870 | u32 shg = 0; |
| 871 | u8 enable = 1; |
| 872 | int ret; |
| 873 | |
| 874 | port_type = L2_API_PORT_TYPE_NORMAL; |
| 875 | |
| 876 | /* Parse args required to build the message */ |
| 877 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 878 | { |
| 879 | if (unformat (i, "sw_if_index %d", &rx_sw_if_index)) |
| 880 | rx_sw_if_index_set = 1; |
| 881 | else if (unformat (i, "bd_id %d", &bd_id)) |
| 882 | bd_id_set = 1; |
| 883 | else if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 884 | &rx_sw_if_index)) |
| 885 | rx_sw_if_index_set = 1; |
| 886 | else if (unformat (i, "shg %d", &shg)) |
| 887 | ; |
| 888 | else if (unformat (i, "bvi")) |
| 889 | port_type = L2_API_PORT_TYPE_BVI; |
| 890 | else if (unformat (i, "uu-fwd")) |
| 891 | port_type = L2_API_PORT_TYPE_UU_FWD; |
| 892 | else if (unformat (i, "enable")) |
| 893 | enable = 1; |
| 894 | else if (unformat (i, "disable")) |
| 895 | enable = 0; |
| 896 | else |
| 897 | break; |
| 898 | } |
| 899 | |
| 900 | if (rx_sw_if_index_set == 0) |
| 901 | { |
| 902 | errmsg ("missing rx interface name or sw_if_index"); |
| 903 | return -99; |
| 904 | } |
| 905 | |
| 906 | if (enable && (bd_id_set == 0)) |
| 907 | { |
| 908 | errmsg ("missing bridge domain"); |
| 909 | return -99; |
| 910 | } |
| 911 | |
| 912 | M (SW_INTERFACE_SET_L2_BRIDGE, mp); |
| 913 | |
| 914 | mp->rx_sw_if_index = ntohl (rx_sw_if_index); |
| 915 | mp->bd_id = ntohl (bd_id); |
| 916 | mp->shg = (u8) shg; |
| 917 | mp->port_type = ntohl (port_type); |
| 918 | mp->enable = enable; |
| 919 | |
| 920 | S (mp); |
| 921 | W (ret); |
| 922 | return ret; |
| 923 | } |
| 924 | |
| 925 | static int |
| 926 | api_sw_interface_set_vpath (vat_main_t *vam) |
| 927 | { |
| 928 | vnet_main_t *vnm = vnet_get_main (); |
| 929 | unformat_input_t *i = vam->input; |
| 930 | vl_api_sw_interface_set_vpath_t *mp; |
| 931 | u32 sw_if_index = 0; |
| 932 | u8 sw_if_index_set = 0; |
| 933 | u8 is_enable = 0; |
| 934 | int ret; |
| 935 | |
| 936 | /* Parse args required to build the message */ |
| 937 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 938 | { |
| 939 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 940 | sw_if_index_set = 1; |
| 941 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 942 | sw_if_index_set = 1; |
| 943 | else if (unformat (i, "enable")) |
| 944 | is_enable = 1; |
| 945 | else if (unformat (i, "disable")) |
| 946 | is_enable = 0; |
| 947 | else |
| 948 | break; |
| 949 | } |
| 950 | |
| 951 | if (sw_if_index_set == 0) |
| 952 | { |
| 953 | errmsg ("missing interface name or sw_if_index"); |
| 954 | return -99; |
| 955 | } |
| 956 | |
| 957 | /* Construct the API message */ |
| 958 | M (SW_INTERFACE_SET_VPATH, mp); |
| 959 | |
| 960 | mp->sw_if_index = ntohl (sw_if_index); |
| 961 | mp->enable = is_enable; |
| 962 | |
| 963 | /* send it... */ |
| 964 | S (mp); |
| 965 | |
| 966 | /* Wait for a reply... */ |
| 967 | W (ret); |
| 968 | return ret; |
| 969 | } |
| 970 | |
| 971 | static int |
| 972 | api_l2_patch_add_del (vat_main_t *vam) |
| 973 | { |
| 974 | vnet_main_t *vnm = vnet_get_main (); |
| 975 | unformat_input_t *i = vam->input; |
| 976 | vl_api_l2_patch_add_del_t *mp; |
| 977 | u32 rx_sw_if_index; |
| 978 | u8 rx_sw_if_index_set = 0; |
| 979 | u32 tx_sw_if_index; |
| 980 | u8 tx_sw_if_index_set = 0; |
| 981 | u8 is_add = 1; |
| 982 | int ret; |
| 983 | |
| 984 | /* Parse args required to build the message */ |
| 985 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 986 | { |
| 987 | if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index)) |
| 988 | rx_sw_if_index_set = 1; |
| 989 | else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index)) |
| 990 | tx_sw_if_index_set = 1; |
| 991 | else if (unformat (i, "rx")) |
| 992 | { |
| 993 | if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 994 | { |
| 995 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 996 | &rx_sw_if_index)) |
| 997 | rx_sw_if_index_set = 1; |
| 998 | } |
| 999 | else |
| 1000 | break; |
| 1001 | } |
| 1002 | else if (unformat (i, "tx")) |
| 1003 | { |
| 1004 | if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1005 | { |
| 1006 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, |
| 1007 | &tx_sw_if_index)) |
| 1008 | tx_sw_if_index_set = 1; |
| 1009 | } |
| 1010 | else |
| 1011 | break; |
| 1012 | } |
| 1013 | else if (unformat (i, "del")) |
| 1014 | is_add = 0; |
| 1015 | else |
| 1016 | break; |
| 1017 | } |
| 1018 | |
| 1019 | if (rx_sw_if_index_set == 0) |
| 1020 | { |
| 1021 | errmsg ("missing rx interface name or rx_sw_if_index"); |
| 1022 | return -99; |
| 1023 | } |
| 1024 | |
| 1025 | if (tx_sw_if_index_set == 0) |
| 1026 | { |
| 1027 | errmsg ("missing tx interface name or tx_sw_if_index"); |
| 1028 | return -99; |
| 1029 | } |
| 1030 | |
| 1031 | M (L2_PATCH_ADD_DEL, mp); |
| 1032 | |
| 1033 | mp->rx_sw_if_index = ntohl (rx_sw_if_index); |
| 1034 | mp->tx_sw_if_index = ntohl (tx_sw_if_index); |
| 1035 | mp->is_add = is_add; |
| 1036 | |
| 1037 | S (mp); |
| 1038 | W (ret); |
| 1039 | return ret; |
| 1040 | } |
| 1041 | |
| 1042 | static void |
| 1043 | vl_api_bridge_flags_reply_t_handler (vl_api_bridge_flags_reply_t *mp) |
| 1044 | { |
| 1045 | vat_main_t *vam = &vat_main; |
| 1046 | i32 retval = ntohl (mp->retval); |
| 1047 | if (vam->async_mode) |
| 1048 | { |
| 1049 | vam->async_errors += (retval < 0); |
| 1050 | } |
| 1051 | else |
| 1052 | { |
| 1053 | vam->retval = retval; |
| 1054 | vam->result_ready = 1; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | #define foreach_vtr_op \ |
| 1059 | _ ("disable", L2_VTR_DISABLED) \ |
| 1060 | _ ("push-1", L2_VTR_PUSH_1) \ |
| 1061 | _ ("push-2", L2_VTR_PUSH_2) \ |
| 1062 | _ ("pop-1", L2_VTR_POP_1) \ |
| 1063 | _ ("pop-2", L2_VTR_POP_2) \ |
| 1064 | _ ("translate-1-1", L2_VTR_TRANSLATE_1_1) \ |
| 1065 | _ ("translate-1-2", L2_VTR_TRANSLATE_1_2) \ |
| 1066 | _ ("translate-2-1", L2_VTR_TRANSLATE_2_1) \ |
| 1067 | _ ("translate-2-2", L2_VTR_TRANSLATE_2_2) |
| 1068 | |
| 1069 | static int |
| 1070 | api_l2_interface_vlan_tag_rewrite (vat_main_t *vam) |
| 1071 | { |
| 1072 | vnet_main_t *vnm = vnet_get_main (); |
| 1073 | unformat_input_t *i = vam->input; |
| 1074 | vl_api_l2_interface_vlan_tag_rewrite_t *mp; |
| 1075 | u32 sw_if_index; |
| 1076 | u8 sw_if_index_set = 0; |
| 1077 | u8 vtr_op_set = 0; |
| 1078 | u32 vtr_op = 0; |
| 1079 | u32 push_dot1q = 1; |
| 1080 | u32 tag1 = ~0; |
| 1081 | u32 tag2 = ~0; |
| 1082 | int ret; |
| 1083 | |
| 1084 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1085 | { |
| 1086 | if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1087 | sw_if_index_set = 1; |
| 1088 | else if (unformat (i, "sw_if_index %d", &sw_if_index)) |
| 1089 | sw_if_index_set = 1; |
| 1090 | else if (unformat (i, "vtr_op %d", &vtr_op)) |
| 1091 | vtr_op_set = 1; |
| 1092 | #define _(n, v) \ |
| 1093 | else if (unformat (i, n)) \ |
| 1094 | { \ |
| 1095 | vtr_op = v; \ |
| 1096 | vtr_op_set = 1; \ |
| 1097 | } |
| 1098 | foreach_vtr_op |
| 1099 | #undef _ |
| 1100 | else if (unformat (i, "push_dot1q %d", &push_dot1q)); |
| 1101 | else if (unformat (i, "tag1 %d", &tag1)); |
| 1102 | else if (unformat (i, "tag2 %d", &tag2)); |
| 1103 | else |
| 1104 | { |
| 1105 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 1106 | return -99; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | if ((sw_if_index_set == 0) || (vtr_op_set == 0)) |
| 1111 | { |
| 1112 | errmsg ("missing vtr operation or sw_if_index"); |
| 1113 | return -99; |
| 1114 | } |
| 1115 | |
| 1116 | M (L2_INTERFACE_VLAN_TAG_REWRITE, mp); |
| 1117 | mp->sw_if_index = ntohl (sw_if_index); |
| 1118 | mp->vtr_op = ntohl (vtr_op); |
| 1119 | mp->push_dot1q = ntohl (push_dot1q); |
| 1120 | mp->tag1 = ntohl (tag1); |
| 1121 | mp->tag2 = ntohl (tag2); |
| 1122 | |
| 1123 | S (mp); |
| 1124 | W (ret); |
| 1125 | return ret; |
| 1126 | } |
| 1127 | |
| 1128 | static int |
| 1129 | api_bridge_domain_set_learn_limit (vat_main_t *vam) |
| 1130 | { |
| 1131 | return -1; |
| 1132 | } |
| 1133 | |
| 1134 | static int |
| 1135 | api_bd_ip_mac_add_del (vat_main_t *vam) |
| 1136 | { |
| 1137 | vl_api_address_t ip = VL_API_ZERO_ADDRESS; |
| 1138 | vl_api_mac_address_t mac = { 0 }; |
| 1139 | unformat_input_t *i = vam->input; |
| 1140 | vl_api_bd_ip_mac_add_del_t *mp; |
| 1141 | u32 bd_id; |
| 1142 | u8 is_add = 1; |
| 1143 | u8 bd_id_set = 0; |
| 1144 | u8 ip_set = 0; |
| 1145 | u8 mac_set = 0; |
| 1146 | int ret; |
| 1147 | |
| 1148 | /* Parse args required to build the message */ |
| 1149 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1150 | { |
| 1151 | if (unformat (i, "bd_id %d", &bd_id)) |
| 1152 | { |
| 1153 | bd_id_set++; |
| 1154 | } |
| 1155 | else if (unformat (i, "%U", unformat_vl_api_address, &ip)) |
| 1156 | { |
| 1157 | ip_set++; |
| 1158 | } |
| 1159 | else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac)) |
| 1160 | { |
| 1161 | mac_set++; |
| 1162 | } |
| 1163 | else if (unformat (i, "del")) |
| 1164 | is_add = 0; |
| 1165 | else |
| 1166 | break; |
| 1167 | } |
| 1168 | |
| 1169 | if (bd_id_set == 0) |
| 1170 | { |
| 1171 | errmsg ("missing bridge domain"); |
| 1172 | return -99; |
| 1173 | } |
| 1174 | else if (ip_set == 0) |
| 1175 | { |
| 1176 | errmsg ("missing IP address"); |
| 1177 | return -99; |
| 1178 | } |
| 1179 | else if (mac_set == 0) |
| 1180 | { |
| 1181 | errmsg ("missing MAC address"); |
| 1182 | return -99; |
| 1183 | } |
| 1184 | |
| 1185 | M (BD_IP_MAC_ADD_DEL, mp); |
| 1186 | |
| 1187 | mp->entry.bd_id = ntohl (bd_id); |
| 1188 | mp->is_add = is_add; |
| 1189 | |
| 1190 | clib_memcpy (&mp->entry.ip, &ip, sizeof (ip)); |
| 1191 | clib_memcpy (&mp->entry.mac, &mac, sizeof (mac)); |
| 1192 | |
| 1193 | S (mp); |
| 1194 | W (ret); |
| 1195 | return ret; |
| 1196 | } |
| 1197 | |
| 1198 | static void |
| 1199 | vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t *mp) |
| 1200 | { |
| 1201 | vat_main_t *vam = l2_test_main.vat_main; |
| 1202 | u32 n_sw_ifs = ntohl (mp->n_sw_ifs); |
| 1203 | int i; |
| 1204 | |
| 1205 | print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s", " ID", "LRN", "FWD", |
| 1206 | "FLD", "BVI", "UU-FWD", "#IF"); |
| 1207 | |
| 1208 | print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d", ntohl (mp->bd_id), mp->learn, |
| 1209 | mp->forward, mp->flood, ntohl (mp->bvi_sw_if_index), |
| 1210 | ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs); |
| 1211 | |
| 1212 | if (n_sw_ifs) |
| 1213 | { |
| 1214 | vl_api_bridge_domain_sw_if_t *sw_ifs; |
| 1215 | print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG", |
| 1216 | "Interface Name"); |
| 1217 | |
| 1218 | sw_ifs = mp->sw_if_details; |
| 1219 | for (i = 0; i < n_sw_ifs; i++) |
| 1220 | { |
| 1221 | u8 *sw_if_name = 0; |
| 1222 | u32 sw_if_index; |
| 1223 | hash_pair_t *p; |
| 1224 | |
| 1225 | sw_if_index = ntohl (sw_ifs->sw_if_index); |
| 1226 | |
| 1227 | hash_foreach_pair (p, vam->sw_if_index_by_interface_name, ({ |
| 1228 | if ((u32) p->value[0] == sw_if_index) |
| 1229 | { |
| 1230 | sw_if_name = (u8 *) (p->key); |
| 1231 | break; |
| 1232 | } |
| 1233 | })); |
| 1234 | print (vam->ofp, "%7d %3d %s", sw_if_index, sw_ifs->shg, |
| 1235 | sw_if_name ? (char *) sw_if_name : "sw_if_index not found!"); |
| 1236 | |
| 1237 | sw_ifs++; |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | static int |
| 1243 | api_bridge_domain_dump (vat_main_t *vam) |
| 1244 | { |
| 1245 | unformat_input_t *i = vam->input; |
| 1246 | vl_api_bridge_domain_dump_t *mp; |
| 1247 | vl_api_control_ping_t *mp_ping; |
| 1248 | u32 bd_id = ~0; |
| 1249 | int ret; |
| 1250 | |
| 1251 | /* Parse args required to build the message */ |
| 1252 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1253 | { |
| 1254 | if (unformat (i, "bd_id %d", &bd_id)) |
| 1255 | ; |
| 1256 | else |
| 1257 | break; |
| 1258 | } |
| 1259 | |
| 1260 | M (BRIDGE_DOMAIN_DUMP, mp); |
| 1261 | mp->bd_id = ntohl (bd_id); |
| 1262 | S (mp); |
| 1263 | |
| 1264 | /* Use a control ping for synchronization */ |
| 1265 | PING (&l2_test_main, mp_ping); |
| 1266 | S (mp_ping); |
| 1267 | |
| 1268 | W (ret); |
| 1269 | return ret; |
| 1270 | } |
| 1271 | |
| 1272 | static int |
| 1273 | api_bridge_domain_set_default_learn_limit (vat_main_t *vam) |
| 1274 | { |
| 1275 | return -1; |
| 1276 | } |
| 1277 | |
| 1278 | static int |
| 1279 | api_bd_ip_mac_flush (vat_main_t *vam) |
| 1280 | { |
| 1281 | unformat_input_t *i = vam->input; |
| 1282 | vl_api_bd_ip_mac_flush_t *mp; |
| 1283 | u32 bd_id; |
| 1284 | u8 bd_id_set = 0; |
| 1285 | int ret; |
| 1286 | |
| 1287 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1288 | { |
| 1289 | if (unformat (i, "bd_id %d", &bd_id)) |
| 1290 | { |
| 1291 | bd_id_set++; |
| 1292 | } |
| 1293 | else |
| 1294 | break; |
| 1295 | } |
| 1296 | |
| 1297 | if (bd_id_set == 0) |
| 1298 | { |
| 1299 | errmsg ("missing bridge domain"); |
| 1300 | return -99; |
| 1301 | } |
| 1302 | |
| 1303 | M (BD_IP_MAC_FLUSH, mp); |
| 1304 | |
| 1305 | mp->bd_id = ntohl (bd_id); |
| 1306 | |
| 1307 | S (mp); |
| 1308 | W (ret); |
| 1309 | return ret; |
| 1310 | } |
| 1311 | |
| 1312 | static int |
| 1313 | api_bd_ip_mac_dump (vat_main_t *vam) |
| 1314 | { |
| 1315 | unformat_input_t *i = vam->input; |
| 1316 | vl_api_bd_ip_mac_dump_t *mp; |
| 1317 | vl_api_control_ping_t *mp_ping; |
| 1318 | int ret; |
| 1319 | u32 bd_id; |
| 1320 | u8 bd_id_set = 0; |
| 1321 | |
| 1322 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1323 | { |
| 1324 | if (unformat (i, "bd_id %d", &bd_id)) |
| 1325 | { |
| 1326 | bd_id_set++; |
| 1327 | } |
| 1328 | else |
| 1329 | break; |
| 1330 | } |
| 1331 | |
| 1332 | fformat (vam->ofp, "\n%-5s %-7s %-20s %-30s", "bd_id", "is_ipv6", |
| 1333 | "mac_address", "ip_address"); |
| 1334 | |
| 1335 | /* Dump Bridge Domain Ip to Mac entries */ |
| 1336 | M (BD_IP_MAC_DUMP, mp); |
| 1337 | |
| 1338 | if (bd_id_set) |
| 1339 | mp->bd_id = htonl (bd_id); |
| 1340 | else |
| 1341 | mp->bd_id = ~0; |
| 1342 | |
| 1343 | S (mp); |
| 1344 | |
| 1345 | /* Use a control ping for synchronization */ |
| 1346 | PING (&l2_test_main, mp_ping); |
| 1347 | S (mp_ping); |
| 1348 | |
| 1349 | W (ret); |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
| 1353 | static int |
| 1354 | api_bvi_create (vat_main_t *vam) |
| 1355 | { |
| 1356 | return -1; |
| 1357 | } |
| 1358 | |
| 1359 | static int |
| 1360 | api_bvi_delete (vat_main_t *vam) |
| 1361 | { |
| 1362 | return -1; |
| 1363 | } |
| 1364 | |
| 1365 | static int |
| 1366 | api_bridge_flags (vat_main_t *vam) |
| 1367 | { |
| 1368 | unformat_input_t *i = vam->input; |
| 1369 | vl_api_bridge_flags_t *mp; |
| 1370 | u32 bd_id; |
| 1371 | u8 bd_id_set = 0; |
| 1372 | u8 is_set = 1; |
| 1373 | bd_flags_t flags = 0; |
| 1374 | int ret; |
| 1375 | |
| 1376 | /* Parse args required to build the message */ |
| 1377 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 1378 | { |
| 1379 | if (unformat (i, "bd_id %d", &bd_id)) |
| 1380 | bd_id_set = 1; |
| 1381 | else if (unformat (i, "learn")) |
| 1382 | flags |= BRIDGE_API_FLAG_LEARN; |
| 1383 | else if (unformat (i, "forward")) |
| 1384 | flags |= BRIDGE_API_FLAG_FWD; |
| 1385 | else if (unformat (i, "flood")) |
| 1386 | flags |= BRIDGE_API_FLAG_FLOOD; |
| 1387 | else if (unformat (i, "uu-flood")) |
| 1388 | flags |= BRIDGE_API_FLAG_UU_FLOOD; |
| 1389 | else if (unformat (i, "arp-term")) |
| 1390 | flags |= BRIDGE_API_FLAG_ARP_TERM; |
| 1391 | else if (unformat (i, "off")) |
| 1392 | is_set = 0; |
| 1393 | else if (unformat (i, "disable")) |
| 1394 | is_set = 0; |
| 1395 | else |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | if (bd_id_set == 0) |
| 1400 | { |
| 1401 | errmsg ("missing bridge domain"); |
| 1402 | return -99; |
| 1403 | } |
| 1404 | |
| 1405 | M (BRIDGE_FLAGS, mp); |
| 1406 | |
| 1407 | mp->bd_id = ntohl (bd_id); |
| 1408 | mp->flags = ntohl (flags); |
| 1409 | mp->is_set = is_set; |
| 1410 | |
| 1411 | S (mp); |
| 1412 | W (ret); |
| 1413 | return ret; |
| 1414 | } |
| 1415 | |
| 1416 | #include <vnet/l2/l2.api_test.c> |
| 1417 | |
| 1418 | /* |
| 1419 | * Local Variables: |
| 1420 | * eval: (c-set-style "gnu") |
| 1421 | * End: |
| 1422 | */ |