From 17a918133ba056851c848cbd95dcd241b900cd3d Mon Sep 17 00:00:00 2001 From: Abdel Baig Date: Tue, 3 Sep 2024 11:52:20 -0400 Subject: bfd: add support for multihop Type: feature Change-Id: If23f9cc9317e7528f3c8d66303457206843a12c5 Signed-off-by: Abdel Baig --- src/vnet/bfd/bfd.api | 10 + src/vnet/bfd/bfd_api.c | 61 ++- src/vnet/bfd/bfd_api.h | 63 +-- src/vnet/bfd/bfd_cli.c | 150 +++--- src/vnet/bfd/bfd_main.c | 62 ++- src/vnet/bfd/bfd_main.h | 17 +- src/vnet/bfd/bfd_udp.c | 520 ++++++++++++------- src/vnet/bfd/bfd_udp.h | 10 +- src/vnet/udp/udp_local.h | 71 +-- test/bfd.py | 57 ++- test/test_bfd.py | 1232 +++++++++++++++++++++++++++++++++++++++------- 11 files changed, 1734 insertions(+), 519 deletions(-) diff --git a/src/vnet/bfd/bfd.api b/src/vnet/bfd/bfd.api index d3b3ed21a26..cf14455f391 100644 --- a/src/vnet/bfd/bfd.api +++ b/src/vnet/bfd/bfd.api @@ -359,6 +359,16 @@ autoreply define bfd_udp_auth_deactivate bool is_delayed; }; +/** \brief BFD UDP - enable multihop support + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +autoreply define bfd_udp_enable_multihop +{ + u32 client_index; + u32 context; +}; + /* must be compatible with bfd_error_t */ counters bfd_udp { none { diff --git a/src/vnet/bfd/bfd_api.c b/src/vnet/bfd/bfd_api.c index 816e71081ff..bccf58ba4bb 100644 --- a/src/vnet/bfd/bfd_api.c +++ b/src/vnet/bfd/bfd_api.c @@ -46,8 +46,24 @@ pub_sub_handler (bfd_events, BFD_EVENTS); ip_address_decode(&mp->local_addr, &local_addr); \ ip_address_decode(&mp->peer_addr, &peer_addr); -#define BFD_UDP_API_PARAM_FROM_MP(mp) \ - clib_net_to_host_u32 (mp->sw_if_index), &local_addr, &peer_addr +#define BFD_UDP_API_PARAM_IS_MH(mp) \ + bfd_main.multihop_enabled && (mp->sw_if_index == ~0) + +#define BFD_UDP_API_PARAM_FROM_MP(mp) \ + BFD_UDP_API_PARAM_IS_MH (mp) ? true : false, \ + BFD_UDP_API_PARAM_IS_MH (mp) ? ~0 : \ + clib_net_to_host_u32 (mp->sw_if_index), \ + &local_addr, &peer_addr + +#define COND_VALIDATE_SW_IF_INDEX(mp) \ + do \ + { \ + if (!(bfd_main.multihop_enabled && mp->sw_if_index == ~0)) \ + { \ + VALIDATE_SW_IF_INDEX (mp) \ + } \ + } \ + while (0); static void vl_api_bfd_udp_add_t_handler (vl_api_bfd_udp_add_t * mp) @@ -55,7 +71,7 @@ vl_api_bfd_udp_add_t_handler (vl_api_bfd_udp_add_t * mp) vl_api_bfd_udp_add_reply_t *rmp; int rv; - VALIDATE_SW_IF_INDEX (mp); + COND_VALIDATE_SW_IF_INDEX (mp); BFD_UDP_API_PARAM_COMMON_CODE; @@ -76,7 +92,7 @@ vl_api_bfd_udp_upd_t_handler (vl_api_bfd_udp_add_t *mp) vl_api_bfd_udp_upd_reply_t *rmp; int rv; - VALIDATE_SW_IF_INDEX (mp); + COND_VALIDATE_SW_IF_INDEX (mp); BFD_UDP_API_PARAM_COMMON_CODE; @@ -97,7 +113,7 @@ vl_api_bfd_udp_mod_t_handler (vl_api_bfd_udp_mod_t * mp) vl_api_bfd_udp_mod_reply_t *rmp; int rv; - VALIDATE_SW_IF_INDEX (mp); + COND_VALIDATE_SW_IF_INDEX (mp); BFD_UDP_API_PARAM_COMMON_CODE; @@ -116,7 +132,7 @@ vl_api_bfd_udp_del_t_handler (vl_api_bfd_udp_del_t * mp) vl_api_bfd_udp_del_reply_t *rmp; int rv; - VALIDATE_SW_IF_INDEX (mp); + COND_VALIDATE_SW_IF_INDEX (mp); BFD_UDP_API_PARAM_COMMON_CODE; @@ -143,7 +159,14 @@ send_bfd_udp_session_details (vl_api_registration_t * reg, u32 context, mp->state = clib_host_to_net_u32 (bs->local_state); bfd_udp_session_t *bus = &bs->udp; bfd_udp_key_t *key = &bus->key; - mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index); + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + mp->sw_if_index = ~0; + } + else + { + mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index); + } if ((!bs->auth.is_delayed && bs->auth.curr_key) || (bs->auth.is_delayed && bs->auth.next_key)) { @@ -186,7 +209,14 @@ send_bfd_udp_session_event (vl_api_registration_t *reg, u32 pid, mp->state = clib_host_to_net_u32 (bs->local_state); bfd_udp_session_t *bus = &bs->udp; bfd_udp_key_t *key = &bus->key; - mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index); + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + mp->sw_if_index = ~0; + } + else + { + mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index); + } if ((!bs->auth.is_delayed && bs->auth.curr_key) || (bs->auth.is_delayed && bs->auth.next_key)) { @@ -315,7 +345,7 @@ vl_api_bfd_udp_auth_activate_t_handler (vl_api_bfd_udp_auth_activate_t * mp) vl_api_bfd_udp_auth_activate_reply_t *rmp; int rv; - VALIDATE_SW_IF_INDEX (mp); + COND_VALIDATE_SW_IF_INDEX (mp); BFD_UDP_API_PARAM_COMMON_CODE; @@ -334,7 +364,7 @@ vl_api_bfd_udp_auth_deactivate_t_handler (vl_api_bfd_udp_auth_deactivate_t * vl_api_bfd_udp_auth_deactivate_reply_t *rmp; int rv; - VALIDATE_SW_IF_INDEX (mp); + COND_VALIDATE_SW_IF_INDEX (mp); BFD_UDP_API_PARAM_COMMON_CODE; @@ -423,6 +453,17 @@ vl_api_bfd_udp_get_echo_source_t_handler (vl_api_bfd_udp_get_echo_source_t * })) } +static void +vl_api_bfd_udp_enable_multihop_t_handler (vl_api_bfd_udp_enable_multihop_t *mp) +{ + vl_api_bfd_udp_enable_multihop_reply_t *rmp; + int rv = 0; + + bfd_main.multihop_enabled = true; + + REPLY_MACRO (VL_API_BFD_UDP_ENABLE_MULTIHOP_REPLY); +} + #include static clib_error_t * bfd_api_hookup (vlib_main_t * vm) diff --git a/src/vnet/bfd/bfd_api.h b/src/vnet/bfd/bfd_api.h index f051e6b679c..16501fcd272 100644 --- a/src/vnet/bfd/bfd_api.h +++ b/src/vnet/bfd/bfd_api.h @@ -37,44 +37,49 @@ typedef enum /** * @brief create a new bfd session */ -vnet_api_error_t -bfd_udp_add_session (u32 sw_if_index, const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, - u32 desired_min_tx_usec, u32 required_min_rx_usec, - u8 detect_mult, u8 is_authenticated, u32 conf_key_id, - u8 bfd_key_id); +vnet_api_error_t bfd_udp_add_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, + u32 desired_min_tx_usec, + u32 required_min_rx_usec, u8 detect_mult, + u8 is_authenticated, u32 conf_key_id, + u8 bfd_key_id); /** - * @brief create a new or modify and existing bfd session + * @brief create a new or modify an existing bfd session */ -vnet_api_error_t -bfd_udp_upd_session (u32 sw_if_index, const ip46_address_t *local_addr, - const ip46_address_t *peer_addr, u32 desired_min_tx_usec, - u32 required_min_rx_usec, u8 detect_mult, - u8 is_authenticated, u32 conf_key_id, u8 bfd_key_id); +vnet_api_error_t bfd_udp_upd_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, + u32 desired_min_tx_usec, + u32 required_min_rx_usec, u8 detect_mult, + u8 is_authenticated, u32 conf_key_id, + u8 bfd_key_id); /** * @brief modify existing session */ -vnet_api_error_t -bfd_udp_mod_session (u32 sw_if_index, const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, - u32 desired_min_tx_usec, u32 required_min_rx_usec, - u8 detect_mult); +vnet_api_error_t bfd_udp_mod_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, + u32 desired_min_tx_usec, + u32 required_min_rx_usec, + u8 detect_mult); /** * @brief delete existing session */ -vnet_api_error_t bfd_udp_del_session (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr); +vnet_api_error_t bfd_udp_del_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr); /** * @brief set session admin down/up */ -vnet_api_error_t bfd_udp_session_set_flags (vlib_main_t * vm, u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, +vnet_api_error_t bfd_udp_session_set_flags (vlib_main_t *vm, bool multihop, + u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u8 admin_up_down); /** @@ -91,18 +96,18 @@ vnet_api_error_t bfd_auth_del_key (u32 conf_key_id); /** * @brief activate authentication for existing session */ -vnet_api_error_t bfd_udp_auth_activate (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, +vnet_api_error_t bfd_udp_auth_activate (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u32 conf_key_id, u8 bfd_key_id, u8 is_delayed); /** * @brief deactivate authentication for existing session */ -vnet_api_error_t bfd_udp_auth_deactivate (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, +vnet_api_error_t bfd_udp_auth_deactivate (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u8 is_delayed); /** diff --git a/src/vnet/bfd/bfd_cli.c b/src/vnet/bfd/bfd_cli.c index 33942bb89e6..194c62b507c 100644 --- a/src/vnet/bfd/bfd_cli.c +++ b/src/vnet/bfd/bfd_cli.c @@ -26,11 +26,39 @@ #include #include +#define BFD_MULTIHOP_CLI_CHECK \ + do \ + { \ + multihop = have_multihop; \ + if (multihop) \ + { \ + sw_if_index = ~0; \ + } \ + if (multihop && have_sw_if_index) \ + { \ + ret = clib_error_return ( \ + 0, "Incompatible parameter combination, " \ + "interface cannot be specified when multihop is enabled"); \ + goto out; \ + } \ + if (!multihop && !have_sw_if_index) \ + { \ + ret = \ + clib_error_return (0, "Incompatible parameter combination, " \ + "interface must be set if not multihop"); \ + goto out; \ + } \ + } \ + while (0); + static u8 * format_bfd_session_cli (u8 * s, va_list * args) { vlib_main_t *vm = va_arg (*args, vlib_main_t *); bfd_session_t *bs = va_arg (*args, bfd_session_t *); + s = format (s, "%10s %-32s %20s\n", "", "Hop Type", + bfd_hop_type_string (bs->hop_type)); + switch (bs->transport) { case BFD_TRANSPORT_UDP4: @@ -52,6 +80,8 @@ format_bfd_session_cli (u8 * s, va_list * args) bfd_diag_code_string (bs->remote_diag)); s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier", bs->local_detect_mult, bs->remote_detect_mult); + s = format (s, "%10s %-32s %20llu\n", "", "Detection Time (usec)", + bfd_nsec_to_usec (bs->detection_time_nsec)); s = format (s, "%10s %-32s %20u %20llu\n", "", "Required Min Rx Interval (usec)", bs->config_required_min_rx_usec, bs->remote_min_rx_usec); @@ -363,6 +393,7 @@ VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = { #define DETECT_MULT_STR "detect-mult" #define ADMIN_STR "admin" #define DELAYED_STR "delayed" +#define MULTIHOP_STR "multihop" static const unsigned mandatory = 1; static const unsigned optional = 0; @@ -401,7 +432,8 @@ bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input, clib_error_t *ret = NULL; unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_add_cli_param(F) \ - F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ + F (bool, multihop, MULTIHOP_STR, optional, "%_") \ + F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \ bfd_cli_unformat_ip46_address) \ @@ -433,6 +465,7 @@ bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input, } foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY); + BFD_MULTIHOP_CLI_CHECK if (1 == have_conf_key_id + have_bfd_key_id) { @@ -456,11 +489,9 @@ bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input, goto out; } - vnet_api_error_t rv = - bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx, - required_min_rx, - detect_mult, have_conf_key_id, conf_key_id, - bfd_key_id); + vnet_api_error_t rv = bfd_udp_add_session ( + multihop, sw_if_index, &local_addr, &peer_addr, desired_min_tx, + required_min_rx, detect_mult, have_conf_key_id, conf_key_id, bfd_key_id); if (rv) { ret = @@ -477,16 +508,16 @@ out: VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = { .path = "bfd udp session add", .short_help = "bfd udp session add" - " interface " - " local-addr " - " peer-addr " - " desired-min-tx " - " required-min-rx " - " detect-mult " - "[" - " conf-key-id " - " bfd-key-id " - "]", + " >" + " local-addr " + " peer-addr " + " desired-min-tx " + " required-min-rx " + " detect-mult " + "[" + " conf-key-id " + " bfd-key-id " + "]", .function = bfd_cli_udp_session_add, }; @@ -497,7 +528,8 @@ bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input, clib_error_t *ret = NULL; unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_mod_cli_param(F) \ - F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ + F (bool, multihop, MULTIHOP_STR, optional, "%_") \ + F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \ bfd_cli_unformat_ip46_address) \ @@ -527,6 +559,7 @@ bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input, } foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY); + BFD_MULTIHOP_CLI_CHECK if (detect_mult > 255) { @@ -536,7 +569,7 @@ bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input, } vnet_api_error_t rv = - bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr, + bfd_udp_mod_session (multihop, sw_if_index, &local_addr, &peer_addr, desired_min_tx, required_min_rx, detect_mult); if (rv) { @@ -553,13 +586,13 @@ out: VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = { .path = "bfd udp session mod", - .short_help = "bfd udp session mod interface" - " local-addr" - " peer-addr" - " desired-min-tx" - " required-min-rx" - " detect-mult" - " ", + .short_help = "bfd udp session mod " + " >" + " peer-addr" + " desired-min-tx" + " required-min-rx" + " detect-mult" + " ", .function = bfd_cli_udp_session_mod, }; @@ -570,7 +603,8 @@ bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input, clib_error_t *ret = NULL; unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_del_cli_param(F) \ - F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ + F (bool, multihop, MULTIHOP_STR, optional, "%_") \ + F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \ bfd_cli_unformat_ip46_address) \ @@ -597,9 +631,10 @@ bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input, } foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY); + BFD_MULTIHOP_CLI_CHECK vnet_api_error_t rv = - bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr); + bfd_udp_del_session (multihop, sw_if_index, &local_addr, &peer_addr); if (rv) { ret = @@ -615,10 +650,10 @@ out: VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = { .path = "bfd udp session del", - .short_help = "bfd udp session del interface" - " local-addr" - " peer-addr" - " ", + .short_help = "bfd udp session del > local-addr" + " peer-addr" + " ", .function = bfd_cli_udp_session_del, }; @@ -629,7 +664,8 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, clib_error_t *ret = NULL; unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \ - F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ + F (bool, multihop, MULTIHOP_STR, optional, "%_") \ + F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \ bfd_cli_unformat_ip46_address) \ @@ -658,6 +694,7 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, } foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY); + BFD_MULTIHOP_CLI_CHECK u8 admin_up_down; static const char up[] = "up"; @@ -677,9 +714,8 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, ADMIN_STR, admin_up_down_token); goto out; } - vnet_api_error_t rv = - bfd_udp_session_set_flags (vm, sw_if_index, &local_addr, - &peer_addr, admin_up_down); + vnet_api_error_t rv = bfd_udp_session_set_flags ( + vm, multihop, sw_if_index, &local_addr, &peer_addr, admin_up_down); if (rv) { ret = @@ -696,10 +732,10 @@ out: VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = { .path = "bfd udp session set-flags", .short_help = "bfd udp session set-flags" - " interface " - " local-addr " - " peer-addr " - " admin ", + " >" + " local-addr " + " peer-addr " + " admin ", .function = bfd_cli_udp_session_set_flags, }; @@ -711,7 +747,8 @@ bfd_cli_udp_session_auth_activate (vlib_main_t * vm, clib_error_t *ret = NULL; unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \ - F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ + F (bool, multihop, MULTIHOP_STR, optional, "%_") \ + F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \ bfd_cli_unformat_ip46_address) \ @@ -741,6 +778,7 @@ bfd_cli_udp_session_auth_activate (vlib_main_t * vm, } foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY); + BFD_MULTIHOP_CLI_CHECK u8 is_delayed = 0; if (have_delayed_token) @@ -773,8 +811,8 @@ bfd_cli_udp_session_auth_activate (vlib_main_t * vm, } vnet_api_error_t rv = - bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id, - bfd_key_id, is_delayed); + bfd_udp_auth_activate (multihop, sw_if_index, &local_addr, &peer_addr, + conf_key_id, bfd_key_id, is_delayed); if (rv) { ret = @@ -791,12 +829,12 @@ out: VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = { .path = "bfd udp session auth activate", .short_help = "bfd udp session auth activate" - " interface " - " local-addr " - " peer-addr " - " conf-key-id " - " bfd-key-id " - " [ delayed ]", + " >" + " local-addr " + " peer-addr " + " conf-key-id " + " bfd-key-id " + " [ delayed ]", .function = bfd_cli_udp_session_auth_activate, }; @@ -807,7 +845,8 @@ bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input, clib_error_t *ret = NULL; unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \ - F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ + F (bool, multihop, MULTIHOP_STR, optional, "%_") \ + F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \ bfd_cli_unformat_ip46_address) \ @@ -835,6 +874,7 @@ bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input, } foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY); + BFD_MULTIHOP_CLI_CHECK u8 is_delayed = 0; if (have_delayed_token) @@ -858,8 +898,8 @@ bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input, } } - vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr, - &peer_addr, is_delayed); + vnet_api_error_t rv = bfd_udp_auth_deactivate ( + multihop, sw_if_index, &local_addr, &peer_addr, is_delayed); if (rv) { ret = clib_error_return ( @@ -875,10 +915,10 @@ out: VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = { .path = "bfd udp session auth deactivate", .short_help = "bfd udp session auth deactivate" - " interface " - " local-addr " - " peer-addr " - "[ delayed ]", + " >" + " local-addr " + " peer-addr " + "[ delayed ]", .function = bfd_cli_udp_session_auth_deactivate, }; diff --git a/src/vnet/bfd/bfd_main.c b/src/vnet/bfd/bfd_main.c index 1423da91158..4ad0a16830f 100644 --- a/src/vnet/bfd/bfd_main.c +++ b/src/vnet/bfd/bfd_main.c @@ -30,6 +30,20 @@ #include #include +const char * +bfd_hop_type_string (bfd_hop_type_e hoptype) +{ + switch (hoptype) + { +#define F(x) \ + case BFD_HOP_TYPE_##x: \ + return "BFD_HOP_TYPE_" #x; + foreach_bfd_hop (F) +#undef F + } + return "UNKNOWN"; +} + static void bfd_validate_counters (bfd_main_t *bm) { @@ -1353,6 +1367,8 @@ VLIB_REGISTER_NODE (bfd_process_node, static) = [BFD_TX_IP6_REWRITE] = "ip6-rewrite", [BFD_TX_IP4_MIDCHAIN] = "ip4-midchain", [BFD_TX_IP6_MIDCHAIN] = "ip6-midchain", + [BFD_TX_IP4_LOOKUP] = "ip4-lookup", + [BFD_TX_IP6_LOOKUP] = "ip6-lookup", } }; // clang-format on @@ -2049,29 +2065,29 @@ u8 * format_bfd_session (u8 * s, va_list * args) { const bfd_session_t *bs = va_arg (*args, bfd_session_t *); - s = format (s, "bs_idx=%u local-state=%s remote-state=%s\n" - "local-discriminator=%u remote-discriminator=%u\n" - "local-diag=%s echo-active=%s\n" - "desired-min-tx=%u required-min-rx=%u\n" - "required-min-echo-rx=%u detect-mult=%u\n" - "remote-min-rx=%u remote-min-echo-rx=%u\n" - "remote-demand=%s poll-state=%s\n" - "auth: local-seq-num=%u remote-seq-num=%u\n" - " is-delayed=%s\n" - " curr-key=%U\n" - " next-key=%U", - bs->bs_idx, bfd_state_string (bs->local_state), - bfd_state_string (bs->remote_state), bs->local_discr, - bs->remote_discr, bfd_diag_code_string (bs->local_diag), - (bs->echo ? "yes" : "no"), bs->config_desired_min_tx_usec, - bs->config_required_min_rx_usec, 1, bs->local_detect_mult, - bs->remote_min_rx_usec, bs->remote_min_echo_rx_usec, - (bs->remote_demand ? "yes" : "no"), - bfd_poll_state_string (bs->poll_state), - bs->auth.local_seq_number, bs->auth.remote_seq_number, - (bs->auth.is_delayed ? "yes" : "no"), - format_bfd_auth_key, bs->auth.curr_key, format_bfd_auth_key, - bs->auth.next_key); + s = format ( + s, + "bs_idx=%u hop-type=%s local-state=%s remote-state=%s\n" + "local-discriminator=%u remote-discriminator=%u\n" + "local-diag=%s echo-active=%s\n" + "desired-min-tx=%u required-min-rx=%u\n" + "required-min-echo-rx=%u detect-mult=%u\n" + "remote-min-rx=%u remote-min-echo-rx=%u\n" + "remote-demand=%s poll-state=%s\n" + "auth: local-seq-num=%u remote-seq-num=%u\n" + " is-delayed=%s\n" + " curr-key=%U\n" + " next-key=%U", + bs->bs_idx, bfd_hop_type_string (bs->hop_type), + bfd_state_string (bs->local_state), bfd_state_string (bs->remote_state), + bs->local_discr, bs->remote_discr, bfd_diag_code_string (bs->local_diag), + (bs->echo ? "yes" : "no"), bs->config_desired_min_tx_usec, + bs->config_required_min_rx_usec, 1, bs->local_detect_mult, + bs->remote_min_rx_usec, bs->remote_min_echo_rx_usec, + (bs->remote_demand ? "yes" : "no"), bfd_poll_state_string (bs->poll_state), + bs->auth.local_seq_number, bs->auth.remote_seq_number, + (bs->auth.is_delayed ? "yes" : "no"), format_bfd_auth_key, + bs->auth.curr_key, format_bfd_auth_key, bs->auth.next_key); return s; } diff --git a/src/vnet/bfd/bfd_main.h b/src/vnet/bfd/bfd_main.h index 1d4617e1d7c..7d9253983ce 100644 --- a/src/vnet/bfd/bfd_main.h +++ b/src/vnet/bfd/bfd_main.h @@ -71,13 +71,13 @@ typedef enum /** * hop types */ -#define foreach_bfd_hop(F) \ - F (SINGLE, "single") \ - F (MULTI, "multi") \ +#define foreach_bfd_hop(F) \ + F (SINGLE) \ + F (MULTI) typedef enum { -#define F(sym, str) BFD_HOP_TYPE_##sym, +#define F(sym) BFD_HOP_TYPE_##sym, foreach_bfd_hop (F) #undef F } bfd_hop_type_e; @@ -318,6 +318,12 @@ typedef struct /** vector of callback notification functions */ bfd_notify_fn_t *listeners; + /** + * true if multihop support is enabled so sw_if_index of ~0 + * represents a multihop session + */ + bool multihop_enabled; + /** log class */ vlib_log_class_t log_class; @@ -449,6 +455,7 @@ vnet_api_error_t bfd_session_set_params (bfd_main_t * bm, bfd_session_t * bs, u32 bfd_nsec_to_usec (u64 nsec); const char *bfd_poll_state_string (bfd_poll_state_e state); +const char *bfd_hop_type_string (bfd_hop_type_e state); #define USEC_PER_MS (1000LL) #define MSEC_PER_SEC (1000LL) @@ -482,6 +489,8 @@ typedef enum BFD_TX_IP6_REWRITE, BFD_TX_IP4_MIDCHAIN, BFD_TX_IP6_MIDCHAIN, + BFD_TX_IP4_LOOKUP, + BFD_TX_IP6_LOOKUP, BFD_TX_N_NEXT, } bfd_tx_next_t; diff --git a/src/vnet/bfd/bfd_udp.c b/src/vnet/bfd/bfd_udp.c index ec42cda1bc4..6d3202cc55c 100644 --- a/src/vnet/bfd/bfd_udp.c +++ b/src/vnet/bfd/bfd_udp.c @@ -64,12 +64,18 @@ typedef struct u32 echo_source_sw_if_index; /* log class */ vlib_log_class_t log_class; - /* number of active udp4 sessions */ - u32 udp4_sessions_count; - u32 udp4_sessions_count_stat_seg_entry; - /* number of active udp6 sessions */ - u32 udp6_sessions_count; - u32 udp6_sessions_count_stat_seg_entry; + /* number of active udp4 single-hop sessions */ + u32 udp4_sh_sessions_count; + u32 udp4_sh_sessions_count_stat_seg_entry; + /* number of active udp6 single-hop sessions */ + u32 udp6_sh_sessions_count; + u32 udp6_sh_sessions_count_stat_seg_entry; + /* number of active udp4 multi-hop sessions */ + u32 udp4_mh_sessions_count; + u32 udp4_mh_sessions_count_stat_seg_entry; + /* number of active udp6 multi-hop sessions */ + u32 udp6_mh_sessions_count; + u32 udp6_mh_sessions_count_stat_seg_entry; } bfd_udp_main_t; static vlib_node_registration_t bfd_udp4_input_node; @@ -258,8 +264,11 @@ bfd_add_udp4_transport (vlib_main_t * vm, u32 bi, const bfd_session_t * bs, vlib_buffer_t *b = vlib_get_buffer (vm, bi); b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; - vnet_buffer (b)->ip.adj_index[VLIB_RX] = bus->adj_index; - vnet_buffer (b)->ip.adj_index[VLIB_TX] = bus->adj_index; + if (bs->hop_type == BFD_HOP_TYPE_SINGLE) + { + vnet_buffer (b)->ip.adj_index[VLIB_RX] = bus->adj_index; + vnet_buffer (b)->ip.adj_index[VLIB_TX] = bus->adj_index; + } vnet_buffer (b)->sw_if_index[VLIB_RX] = 0; vnet_buffer (b)->sw_if_index[VLIB_TX] = ~0; typedef struct @@ -290,7 +299,14 @@ bfd_add_udp4_transport (vlib_main_t * vm, u32 bi, const bfd_session_t * bs, { headers->ip4.src_address.as_u32 = key->local_addr.ip4.as_u32; headers->ip4.dst_address.as_u32 = key->peer_addr.ip4.as_u32; - headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4); + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4_mh); + } + else + { + headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4); + } } /* fix ip length, checksum and udp length */ @@ -313,8 +329,11 @@ bfd_add_udp6_transport (vlib_main_t * vm, u32 bi, const bfd_session_t * bs, vlib_buffer_t *b = vlib_get_buffer (vm, bi); b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; - vnet_buffer (b)->ip.adj_index[VLIB_RX] = bus->adj_index; - vnet_buffer (b)->ip.adj_index[VLIB_TX] = bus->adj_index; + if (bs->hop_type == BFD_HOP_TYPE_SINGLE) + { + vnet_buffer (b)->ip.adj_index[VLIB_RX] = bus->adj_index; + vnet_buffer (b)->ip.adj_index[VLIB_TX] = bus->adj_index; + } vnet_buffer (b)->sw_if_index[VLIB_RX] = 0; vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; typedef struct @@ -350,7 +369,14 @@ bfd_add_udp6_transport (vlib_main_t * vm, u32 bi, const bfd_session_t * bs, sizeof (headers->ip6.src_address)); clib_memcpy_fast (&headers->ip6.dst_address, &key->peer_addr.ip6, sizeof (headers->ip6.dst_address)); - headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd6); + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd6_mh); + } + else + { + headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd6); + } } /* fix ip payload length and udp length */ @@ -398,9 +424,25 @@ bfd_udp_calc_next_node (const struct bfd_session_s *bs, u32 * next_node) { vnet_main_t *vnm = vnet_get_main (); const bfd_udp_session_t *bus = &bs->udp; - ip_adjacency_t *adj = adj_get (bus->adj_index); - /* don't try to send the buffer if the interface is not up */ + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + switch (bs->transport) + { + case BFD_TRANSPORT_UDP4: + *next_node = BFD_TX_IP4_LOOKUP; + return 1; + case BFD_TRANSPORT_UDP6: + *next_node = BFD_TX_IP6_LOOKUP; + return 1; + default: + /* drop */ + return 0; + } + } + + ip_adjacency_t *adj = adj_get (bus->adj_index); + /* For single-hop, don't try to send the buffer if the interface is not up */ if (!vnet_sw_interface_is_up (vnm, bus->key.sw_if_index)) return 0; @@ -495,7 +537,7 @@ bfd_udp_key_init (bfd_udp_key_t * key, u32 sw_if_index, const ip46_address_t * peer_addr) { clib_memset (key, 0, sizeof (*key)); - key->sw_if_index = sw_if_index; + key->sw_if_index = sw_if_index & 0xFFFF; key->local_addr.as_u64[0] = local_addr->as_u64[0]; key->local_addr.as_u64[1] = local_addr->as_u64[1]; key->peer_addr.as_u64[0] = peer_addr->as_u64[0]; @@ -503,12 +545,13 @@ bfd_udp_key_init (bfd_udp_key_t * key, u32 sw_if_index, } static vnet_api_error_t -bfd_udp_add_session_internal (vlib_main_t * vm, bfd_udp_main_t * bum, - u32 sw_if_index, u32 desired_min_tx_usec, +bfd_udp_add_session_internal (vlib_main_t *vm, bfd_udp_main_t *bum, + bool multihop, u32 sw_if_index, + u32 desired_min_tx_usec, u32 required_min_rx_usec, u8 detect_mult, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, - bfd_session_t ** bs_out) + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, + bfd_session_t **bs_out) { /* get a pool entry and if we end up not needing it, give it back */ bfd_transport_e t = BFD_TRANSPORT_UDP4; @@ -536,8 +579,9 @@ bfd_udp_add_session_internal (vlib_main_t * vm, bfd_udp_main_t * bum, return VNET_API_ERROR_BFD_EEXIST; } mhash_set (&bum->bfd_session_idx_by_bfd_key, key, bs->bs_idx, NULL); - BFD_DBG ("session created, bs_idx=%u, sw_if_index=%d, local=%U, peer=%U", - bs->bs_idx, key->sw_if_index, format_ip46_address, + BFD_DBG ("session created, bs_idx=%u, multihop=%u, sw_if_index=%d, " + "local=%U, peer=%U", + bs->bs_idx, multihop, key->sw_if_index, format_ip46_address, &key->local_addr, IP46_TYPE_ANY, format_ip46_address, &key->peer_addr, IP46_TYPE_ANY); vlib_log_info (bum->log_class, "create BFD session: %U", @@ -548,41 +592,82 @@ bfd_udp_add_session_internal (vlib_main_t * vm, bfd_udp_main_t * bum, &key->peer_addr); if (BFD_TRANSPORT_UDP4 == t) { - bus->adj_index = adj_nbr_add_or_lock (FIB_PROTOCOL_IP4, VNET_LINK_IP4, - peer, key->sw_if_index); - BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, VNET_LINK_IP4, %U, %d) " - "returns %d", - format_ip46_address, peer, IP46_TYPE_ANY, key->sw_if_index, - bus->adj_index); - ++bum->udp4_sessions_count; - bfd_udp_update_stat_segment_entry ( - bum->udp4_sessions_count_stat_seg_entry, bum->udp4_sessions_count); - if (1 == bum->udp4_sessions_count) + if (multihop) { - udp_register_dst_port (vm, UDP_DST_PORT_bfd4, - bfd_udp4_input_node.index, 1); - udp_register_dst_port (vm, UDP_DST_PORT_bfd_echo4, - bfd_udp_echo4_input_node.index, 1); + ++bum->udp4_mh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp4_mh_sessions_count_stat_seg_entry, + bum->udp4_mh_sessions_count); + if (1 == bum->udp4_mh_sessions_count) + { + udp_register_dst_port (vm, UDP_DST_PORT_bfd4_mh, + bfd_udp4_input_node.index, 1); + } + } + else + { + bus->adj_index = adj_nbr_add_or_lock ( + FIB_PROTOCOL_IP4, VNET_LINK_IP4, peer, key->sw_if_index); + BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, VNET_LINK_IP4, " + " %U, %d) returns %d", + format_ip46_address, peer, IP46_TYPE_ANY, key->sw_if_index, + bus->adj_index); + ++bum->udp4_sh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp4_sh_sessions_count_stat_seg_entry, + bum->udp4_sh_sessions_count); + if (1 == bum->udp4_sh_sessions_count) + { + udp_register_dst_port (vm, UDP_DST_PORT_bfd4, + bfd_udp4_input_node.index, 1); + udp_register_dst_port (vm, UDP_DST_PORT_bfd_echo4, + bfd_udp_echo4_input_node.index, 1); + } } } else { - bus->adj_index = adj_nbr_add_or_lock (FIB_PROTOCOL_IP6, VNET_LINK_IP6, - peer, key->sw_if_index); - BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, VNET_LINK_IP6, %U, %d) " - "returns %d", - format_ip46_address, peer, IP46_TYPE_ANY, key->sw_if_index, - bus->adj_index); - ++bum->udp6_sessions_count; - bfd_udp_update_stat_segment_entry ( - bum->udp6_sessions_count_stat_seg_entry, bum->udp6_sessions_count); - if (1 == bum->udp6_sessions_count) + if (multihop) { - udp_register_dst_port (vm, UDP_DST_PORT_bfd6, - bfd_udp6_input_node.index, 0); - udp_register_dst_port (vm, UDP_DST_PORT_bfd_echo6, - bfd_udp_echo6_input_node.index, 0); + ++bum->udp6_mh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp6_mh_sessions_count_stat_seg_entry, + bum->udp6_mh_sessions_count); + if (1 == bum->udp6_mh_sessions_count) + { + udp_register_dst_port (vm, UDP_DST_PORT_bfd6_mh, + bfd_udp6_input_node.index, 0); + } } + else + { + bus->adj_index = adj_nbr_add_or_lock ( + FIB_PROTOCOL_IP6, VNET_LINK_IP6, peer, key->sw_if_index); + BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, VNET_LINK_IP6, " + "%U, %d) returns %d", + format_ip46_address, peer, IP46_TYPE_ANY, key->sw_if_index, + bus->adj_index); + ++bum->udp6_sh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp6_sh_sessions_count_stat_seg_entry, + bum->udp6_sh_sessions_count); + if (1 == bum->udp6_sh_sessions_count) + { + udp_register_dst_port (vm, UDP_DST_PORT_bfd6, + bfd_udp6_input_node.index, 0); + udp_register_dst_port (vm, UDP_DST_PORT_bfd_echo6, + bfd_udp_echo6_input_node.index, 0); + } + } + } + + if (multihop) + { + bs->hop_type = BFD_HOP_TYPE_MULTI; + } + else + { + bs->hop_type = BFD_HOP_TYPE_SINGLE; } *bs_out = bs; return bfd_session_set_params (bum->bfd_main, bs, desired_min_tx_usec, @@ -590,20 +675,24 @@ bfd_udp_add_session_internal (vlib_main_t * vm, bfd_udp_main_t * bum, } static vnet_api_error_t -bfd_udp_validate_api_input (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr) +bfd_udp_validate_api_input (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr) { bfd_udp_main_t *bum = &bfd_udp_main; - vnet_sw_interface_t *sw_if = - vnet_get_sw_interface_or_null (bfd_udp_main.vnet_main, sw_if_index); - if (!sw_if) + if (!multihop) { - vlib_log_err (bum->log_class, - "got NULL sw_if when getting interface by index %u", - sw_if_index); - return VNET_API_ERROR_INVALID_SW_IF_INDEX; + vnet_sw_interface_t *sw_if = + vnet_get_sw_interface_or_null (bfd_udp_main.vnet_main, sw_if_index); + if (!sw_if) + { + vlib_log_err (bum->log_class, + "got NULL sw_if when getting interface by index %u", + sw_if_index); + return VNET_API_ERROR_INVALID_SW_IF_INDEX; + } } + if (ip46_address_is_ip4 (local_addr)) { if (!ip46_address_is_ip4 (peer_addr)) @@ -627,13 +716,13 @@ bfd_udp_validate_api_input (u32 sw_if_index, } static vnet_api_error_t -bfd_udp_find_session_by_api_input (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, - bfd_session_t ** bs_out) +bfd_udp_find_session_by_api_input (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, + bfd_session_t **bs_out) { vnet_api_error_t rv = - bfd_udp_validate_api_input (sw_if_index, local_addr, peer_addr); + bfd_udp_validate_api_input (multihop, sw_if_index, local_addr, peer_addr); if (!rv) { bfd_udp_main_t *bum = &bfd_udp_main; @@ -647,8 +736,9 @@ bfd_udp_find_session_by_api_input (u32 sw_if_index, else { vlib_log_err (bum->log_class, - "BFD session not found, sw_if_index=%u, local=%U, peer=%U", - sw_if_index, format_ip46_address, local_addr, + "BFD session not found, multihop=%d, sw_if_index=%u, " + "local=%U, peer=%U", + multihop, sw_if_index, format_ip46_address, local_addr, IP46_TYPE_ANY, format_ip46_address, peer_addr, IP46_TYPE_ANY); return VNET_API_ERROR_BFD_ENOENT; @@ -658,13 +748,13 @@ bfd_udp_find_session_by_api_input (u32 sw_if_index, } static vnet_api_error_t -bfd_api_verify_common (u32 sw_if_index, u32 desired_min_tx_usec, +bfd_api_verify_common (bool multihop, u32 sw_if_index, u32 desired_min_tx_usec, u8 detect_mult, const ip46_address_t *local_addr, const ip46_address_t *peer_addr) { bfd_udp_main_t *bum = &bfd_udp_main; vnet_api_error_t rv = - bfd_udp_validate_api_input (sw_if_index, local_addr, peer_addr); + bfd_udp_validate_api_input (multihop, sw_if_index, local_addr, peer_addr); if (rv) { return rv; @@ -693,31 +783,62 @@ bfd_udp_del_session_internal (vlib_main_t * vm, bfd_session_t * bs) switch (bs->transport) { case BFD_TRANSPORT_UDP4: - --bum->udp4_sessions_count; - bfd_udp_update_stat_segment_entry ( - bum->udp4_sessions_count_stat_seg_entry, bum->udp4_sessions_count); - if (!bum->udp4_sessions_count) + if (bs->hop_type == BFD_HOP_TYPE_MULTI) { - udp_unregister_dst_port (vm, UDP_DST_PORT_bfd4, 1); - udp_unregister_dst_port (vm, UDP_DST_PORT_bfd_echo4, 1); + --bum->udp4_mh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp4_mh_sessions_count_stat_seg_entry, + bum->udp4_mh_sessions_count); + if (!bum->udp4_mh_sessions_count) + { + udp_unregister_dst_port (vm, UDP_DST_PORT_bfd4_mh, 1); + } + } + else + { + --bum->udp4_sh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp4_sh_sessions_count_stat_seg_entry, + bum->udp4_sh_sessions_count); + if (!bum->udp4_sh_sessions_count) + { + udp_unregister_dst_port (vm, UDP_DST_PORT_bfd4, 1); + udp_unregister_dst_port (vm, UDP_DST_PORT_bfd_echo4, 1); + } } break; case BFD_TRANSPORT_UDP6: - --bum->udp6_sessions_count; - bfd_udp_update_stat_segment_entry ( - bum->udp6_sessions_count_stat_seg_entry, bum->udp6_sessions_count); - if (!bum->udp6_sessions_count) + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + --bum->udp6_mh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp6_mh_sessions_count_stat_seg_entry, + bum->udp6_mh_sessions_count); + if (!bum->udp6_mh_sessions_count) + { + udp_unregister_dst_port (vm, UDP_DST_PORT_bfd6_mh, 0); + } + } + else { - udp_unregister_dst_port (vm, UDP_DST_PORT_bfd6, 0); - udp_unregister_dst_port (vm, UDP_DST_PORT_bfd_echo6, 0); + --bum->udp6_sh_sessions_count; + bfd_udp_update_stat_segment_entry ( + bum->udp6_sh_sessions_count_stat_seg_entry, + bum->udp6_sh_sessions_count); + if (!bum->udp6_sh_sessions_count) + { + udp_unregister_dst_port (vm, UDP_DST_PORT_bfd6, 0); + udp_unregister_dst_port (vm, UDP_DST_PORT_bfd_echo6, 0); + } } + break; } bfd_put_session (bum->bfd_main, bs); } static vnet_api_error_t -bfd_udp_add_and_start_session (u32 sw_if_index, +bfd_udp_add_and_start_session (bool multihop, u32 sw_if_index, const ip46_address_t *local_addr, const ip46_address_t *peer_addr, u32 desired_min_tx_usec, @@ -728,9 +849,10 @@ bfd_udp_add_and_start_session (u32 sw_if_index, bfd_session_t *bs = NULL; vnet_api_error_t rv; - rv = bfd_udp_add_session_internal ( - vlib_get_main (), &bfd_udp_main, sw_if_index, desired_min_tx_usec, - required_min_rx_usec, detect_mult, local_addr, peer_addr, &bs); + rv = bfd_udp_add_session_internal (vlib_get_main (), &bfd_udp_main, multihop, + sw_if_index, desired_min_tx_usec, + required_min_rx_usec, detect_mult, + local_addr, peer_addr, &bs); if (!rv && is_authenticated) { @@ -750,21 +872,22 @@ bfd_udp_add_and_start_session (u32 sw_if_index, } vnet_api_error_t -bfd_udp_add_session (u32 sw_if_index, const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, - u32 desired_min_tx_usec, u32 required_min_rx_usec, - u8 detect_mult, u8 is_authenticated, u32 conf_key_id, - u8 bfd_key_id) +bfd_udp_add_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u32 desired_min_tx_usec, + u32 required_min_rx_usec, u8 detect_mult, + u8 is_authenticated, u32 conf_key_id, u8 bfd_key_id) { bfd_main_t *bm = &bfd_main; bfd_lock (bm); - vnet_api_error_t rv = bfd_api_verify_common ( - sw_if_index, desired_min_tx_usec, detect_mult, local_addr, peer_addr); + vnet_api_error_t rv = + bfd_api_verify_common (multihop, sw_if_index, desired_min_tx_usec, + detect_mult, local_addr, peer_addr); if (!rv) rv = bfd_udp_add_and_start_session ( - sw_if_index, local_addr, peer_addr, desired_min_tx_usec, + multihop, sw_if_index, local_addr, peer_addr, desired_min_tx_usec, required_min_rx_usec, detect_mult, is_authenticated, conf_key_id, bfd_key_id); @@ -773,7 +896,8 @@ bfd_udp_add_session (u32 sw_if_index, const ip46_address_t * local_addr, } vnet_api_error_t -bfd_udp_upd_session (u32 sw_if_index, const ip46_address_t *local_addr, +bfd_udp_upd_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, const ip46_address_t *peer_addr, u32 desired_min_tx_usec, u32 required_min_rx_usec, u8 detect_mult, u8 is_authenticated, u32 conf_key_id, u8 bfd_key_id) @@ -781,17 +905,18 @@ bfd_udp_upd_session (u32 sw_if_index, const ip46_address_t *local_addr, bfd_main_t *bm = &bfd_main; bfd_lock (bm); - vnet_api_error_t rv = bfd_api_verify_common ( - sw_if_index, desired_min_tx_usec, detect_mult, local_addr, peer_addr); + vnet_api_error_t rv = + bfd_api_verify_common (multihop, sw_if_index, desired_min_tx_usec, + detect_mult, local_addr, peer_addr); if (!rv) { bfd_session_t *bs = NULL; - rv = bfd_udp_find_session_by_api_input (sw_if_index, local_addr, - peer_addr, &bs); + rv = bfd_udp_find_session_by_api_input (multihop, sw_if_index, + local_addr, peer_addr, &bs); if (VNET_API_ERROR_BFD_ENOENT == rv) rv = bfd_udp_add_and_start_session ( - sw_if_index, local_addr, peer_addr, desired_min_tx_usec, + multihop, sw_if_index, local_addr, peer_addr, desired_min_tx_usec, required_min_rx_usec, detect_mult, is_authenticated, conf_key_id, bfd_key_id); else @@ -805,7 +930,8 @@ bfd_udp_upd_session (u32 sw_if_index, const ip46_address_t *local_addr, } vnet_api_error_t -bfd_udp_mod_session (u32 sw_if_index, const ip46_address_t *local_addr, +bfd_udp_mod_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, const ip46_address_t *peer_addr, u32 desired_min_tx_usec, u32 required_min_rx_usec, u8 detect_mult) { @@ -813,9 +939,8 @@ bfd_udp_mod_session (u32 sw_if_index, const ip46_address_t *local_addr, bfd_main_t *bm = &bfd_main; vnet_api_error_t error; bfd_lock (bm); - vnet_api_error_t rv = - bfd_udp_find_session_by_api_input (sw_if_index, local_addr, peer_addr, - &bs); + vnet_api_error_t rv = bfd_udp_find_session_by_api_input ( + multihop, sw_if_index, local_addr, peer_addr, &bs); if (rv) { bfd_unlock (bm); @@ -830,16 +955,15 @@ bfd_udp_mod_session (u32 sw_if_index, const ip46_address_t *local_addr, } vnet_api_error_t -bfd_udp_del_session (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr) +bfd_udp_del_session (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr) { bfd_session_t *bs = NULL; bfd_main_t *bm = &bfd_main; bfd_lock (bm); - vnet_api_error_t rv = - bfd_udp_find_session_by_api_input (sw_if_index, local_addr, peer_addr, - &bs); + vnet_api_error_t rv = bfd_udp_find_session_by_api_input ( + multihop, sw_if_index, local_addr, peer_addr, &bs); if (rv) { bfd_unlock (bm); @@ -851,16 +975,15 @@ bfd_udp_del_session (u32 sw_if_index, } vnet_api_error_t -bfd_udp_session_set_flags (vlib_main_t * vm, u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, u8 admin_up_down) +bfd_udp_session_set_flags (vlib_main_t *vm, bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u8 admin_up_down) { bfd_session_t *bs = NULL; bfd_main_t *bm = &bfd_main; bfd_lock (bm); - vnet_api_error_t rv = - bfd_udp_find_session_by_api_input (sw_if_index, local_addr, peer_addr, - &bs); + vnet_api_error_t rv = bfd_udp_find_session_by_api_input ( + multihop, sw_if_index, local_addr, peer_addr, &bs); if (rv) { bfd_unlock (bm); @@ -872,19 +995,18 @@ bfd_udp_session_set_flags (vlib_main_t * vm, u32 sw_if_index, } vnet_api_error_t -bfd_udp_auth_activate (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, - u32 conf_key_id, u8 key_id, u8 is_delayed) +bfd_udp_auth_activate (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u32 conf_key_id, + u8 key_id, u8 is_delayed) { bfd_main_t *bm = &bfd_main; bfd_lock (bm); vnet_api_error_t error; bfd_session_t *bs = NULL; - vnet_api_error_t rv = - bfd_udp_find_session_by_api_input (sw_if_index, local_addr, peer_addr, - &bs); + vnet_api_error_t rv = bfd_udp_find_session_by_api_input ( + multihop, sw_if_index, local_addr, peer_addr, &bs); if (rv) { bfd_unlock (bm); @@ -896,17 +1018,16 @@ bfd_udp_auth_activate (u32 sw_if_index, } vnet_api_error_t -bfd_udp_auth_deactivate (u32 sw_if_index, - const ip46_address_t * local_addr, - const ip46_address_t * peer_addr, u8 is_delayed) +bfd_udp_auth_deactivate (bool multihop, u32 sw_if_index, + const ip46_address_t *local_addr, + const ip46_address_t *peer_addr, u8 is_delayed) { bfd_main_t *bm = &bfd_main; vnet_api_error_t error; bfd_lock (bm); bfd_session_t *bs = NULL; - vnet_api_error_t rv = - bfd_udp_find_session_by_api_input (sw_if_index, local_addr, peer_addr, - &bs); + vnet_api_error_t rv = bfd_udp_find_session_by_api_input ( + multihop, sw_if_index, local_addr, peer_addr, &bs); if (rv) { bfd_unlock (bm); @@ -985,13 +1106,19 @@ bfd_udp4_verify_transport (const ip4_header_t *ip4, const udp_header_t *udp, key->local_addr.ip4.as_u8); return BFD_UDP_ERROR_DST_MISMATCH; } - const u8 expected_ttl = 255; - if (ip4->ttl != expected_ttl) + + // For single-hop, TTL must be 255 + if (bs->hop_type == BFD_HOP_TYPE_SINGLE) { - BFD_ERR ("IPv4 unexpected TTL value %u, expected %u", ip4->ttl, - expected_ttl); - return BFD_UDP_ERROR_TTL; + const u8 expected_ttl = 255; + if (ip4->ttl != expected_ttl) + { + BFD_ERR ("IPv4 unexpected TTL value %u, expected %u", ip4->ttl, + expected_ttl); + return BFD_UDP_ERROR_TTL; + } } + if (clib_net_to_host_u16 (udp->src_port) < 49152) { BFD_ERR ("Invalid UDP src port %u, out of range <49152,65535>", @@ -1062,7 +1189,14 @@ bfd_udp4_scan (vlib_main_t *vm, vlib_buffer_t *b, bfd_session_t **bs_out) { bfd_udp_key_t key; clib_memset (&key, 0, sizeof (key)); - key.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + if (udp->dst_port == clib_host_to_net_u16 (UDP_DST_PORT_bfd4_mh)) + { + key.sw_if_index = ~0; + } + else + { + key.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + } key.local_addr.ip4.as_u32 = ip4->dst_address.as_u32; key.peer_addr.ip4.as_u32 = ip4->src_address.as_u32; BFD_DBG ("Looking up BFD session using key (sw_if_index=%u, local=%U, " @@ -1145,13 +1279,19 @@ bfd_udp6_verify_transport (const ip6_header_t *ip6, const udp_header_t *udp, &key->local_addr.ip6); return BFD_UDP_ERROR_DST_MISMATCH; } - const u8 expected_hop_limit = 255; - if (ip6->hop_limit != expected_hop_limit) + + // For single-hop, hop-limit must be 255 + if (bs->hop_type == BFD_HOP_TYPE_SINGLE) { - BFD_ERR ("IPv6 unexpected hop-limit value %u, expected %u", - ip6->hop_limit, expected_hop_limit); - return BFD_UDP_ERROR_TTL; + const u8 expected_hop_limit = 255; + if (ip6->hop_limit != expected_hop_limit) + { + BFD_ERR ("IPv6 unexpected hop-limit value %u, expected %u", + ip6->hop_limit, expected_hop_limit); + return BFD_UDP_ERROR_TTL; + } } + if (clib_net_to_host_u16 (udp->src_port) < 49152) { BFD_ERR ("Invalid UDP src port %u, out of range <49152,65535>", @@ -1204,15 +1344,22 @@ bfd_udp6_scan (vlib_main_t *vm, vlib_buffer_t *b, bfd_session_t **bs_out) { bfd_udp_key_t key; clib_memset (&key, 0, sizeof (key)); - key.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + if (udp->dst_port == clib_host_to_net_u16 (UDP_DST_PORT_bfd6_mh)) + { + key.sw_if_index = ~0; + } + else + { + key.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + } key.local_addr.ip6.as_u64[0] = ip6->dst_address.as_u64[0]; key.local_addr.ip6.as_u64[1] = ip6->dst_address.as_u64[1]; key.peer_addr.ip6.as_u64[0] = ip6->src_address.as_u64[0]; key.peer_addr.ip6.as_u64[1] = ip6->src_address.as_u64[1]; - BFD_DBG ("Looking up BFD session using key (sw_if_index=%u, local=%U, " - "peer=%U)", - key.sw_if_index, format_ip6_address, &key.local_addr, - format_ip6_address, &key.peer_addr); + BFD_DBG ("Looking up BFD session using discriminator %u", + pkt->your_disc); + bs = bfd_find_session_by_disc (bfd_udp_main.bfd_main, pkt->your_disc); + bs = bfd_lookup_session (&bfd_udp_main, &key); } if (!bs) @@ -1266,8 +1413,8 @@ bfd_udp_input (vlib_main_t * vm, vlib_node_runtime_t * rt, { u64 len; t0 = vlib_add_trace (vm, rt, b0, sizeof (*t0)); - len = (b0->current_length < sizeof (t0->data)) ? b0->current_length - : sizeof (t0->data); + len = (b0->current_length < sizeof (t0->data)) ? b0->current_length : + sizeof (t0->data); t0->len = len; clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0), len); } @@ -1311,25 +1458,35 @@ bfd_udp_input (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_node_increment_counter (vm, bfd_udp4_input_node.index, error0, 1); } + const bfd_udp_session_t *bus = &bs->udp; - ip_adjacency_t *adj = adj_get (bus->adj_index); - switch (adj->lookup_next_index) + + if (bs->hop_type == BFD_HOP_TYPE_MULTI) { - case IP_LOOKUP_NEXT_ARP: - next0 = BFD_UDP_INPUT_NEXT_REPLY_ARP; - break; - case IP_LOOKUP_NEXT_REWRITE: next0 = BFD_UDP_INPUT_NEXT_REPLY_REWRITE; - break; - case IP_LOOKUP_NEXT_MIDCHAIN: - next0 = BFD_UDP_INPUT_NEXT_REPLY_MIDCHAIN; - break; - default: - /* drop */ - break; + } + else + { + ip_adjacency_t *adj = adj_get (bus->adj_index); + switch (adj->lookup_next_index) + { + case IP_LOOKUP_NEXT_ARP: + next0 = BFD_UDP_INPUT_NEXT_REPLY_ARP; + break; + case IP_LOOKUP_NEXT_REWRITE: + next0 = BFD_UDP_INPUT_NEXT_REPLY_REWRITE; + break; + case IP_LOOKUP_NEXT_MIDCHAIN: + next0 = BFD_UDP_INPUT_NEXT_REPLY_MIDCHAIN; + break; + default: + /* drop */ + break; + } } } } + bfd_unlock (bm); vlib_set_next_frame_buffer (vm, rt, next0, bi0); @@ -1566,6 +1723,10 @@ bfd_udp_sw_if_add_del (CLIB_UNUSED (vnet_main_t *vnm), u32 sw_if_index, { continue; } + if (bs->hop_type == BFD_HOP_TYPE_MULTI) + { + continue; + } if (bs->udp.key.sw_if_index != sw_if_index) { continue; @@ -1593,24 +1754,47 @@ clib_error_t * bfd_udp_stats_init (bfd_udp_main_t *bum) { const char *name4 = "/bfd/udp4/sessions"; - bum->udp4_sessions_count_stat_seg_entry = vlib_stats_add_gauge ("%s", name4); + bum->udp4_sh_sessions_count_stat_seg_entry = + vlib_stats_add_gauge ("%s", name4); - vlib_stats_set_gauge (bum->udp4_sessions_count_stat_seg_entry, 0); - if (~0 == bum->udp4_sessions_count_stat_seg_entry) + vlib_stats_set_gauge (bum->udp4_sh_sessions_count_stat_seg_entry, 0); + if (~0 == bum->udp4_sh_sessions_count_stat_seg_entry) { return clib_error_return ( 0, "Could not create stat segment entry for %s", name4); } const char *name6 = "/bfd/udp6/sessions"; - bum->udp6_sessions_count_stat_seg_entry = vlib_stats_add_gauge ("%s", name6); + bum->udp6_sh_sessions_count_stat_seg_entry = + vlib_stats_add_gauge ("%s", name6); - vlib_stats_set_gauge (bum->udp6_sessions_count_stat_seg_entry, 0); - if (~0 == bum->udp6_sessions_count_stat_seg_entry) + vlib_stats_set_gauge (bum->udp6_sh_sessions_count_stat_seg_entry, 0); + if (~0 == bum->udp6_sh_sessions_count_stat_seg_entry) { return clib_error_return ( 0, "Could not create stat segment entry for %s", name6); } + const char *name4_mh = "/bfd/udp4/sessions_mh"; + bum->udp4_mh_sessions_count_stat_seg_entry = + vlib_stats_add_gauge ("%s", name4_mh); + + vlib_stats_set_gauge (bum->udp4_mh_sessions_count_stat_seg_entry, 0); + if (~0 == bum->udp4_mh_sessions_count_stat_seg_entry) + { + return clib_error_return ( + 0, "Could not create stat segment entry for %s", name4_mh); + } + const char *name6_mh = "/bfd/udp6/sessions_mh"; + bum->udp6_mh_sessions_count_stat_seg_entry = + vlib_stats_add_gauge ("%s", name6_mh); + + vlib_stats_set_gauge (bum->udp6_mh_sessions_count_stat_seg_entry, 0); + if (~0 == bum->udp6_mh_sessions_count_stat_seg_entry) + { + return clib_error_return ( + 0, "Could not create stat segment entry for %s", name6_mh); + } + return 0; } @@ -1620,8 +1804,10 @@ bfd_udp_stats_init (bfd_udp_main_t *bum) static clib_error_t * bfd_udp_init (vlib_main_t * vm) { - bfd_udp_main.udp4_sessions_count = 0; - bfd_udp_main.udp6_sessions_count = 0; + bfd_udp_main.udp4_sh_sessions_count = 0; + bfd_udp_main.udp6_sh_sessions_count = 0; + bfd_udp_main.udp4_mh_sessions_count = 0; + bfd_udp_main.udp6_mh_sessions_count = 0; mhash_init (&bfd_udp_main.bfd_session_idx_by_bfd_key, sizeof (uword), sizeof (bfd_udp_key_t)); bfd_udp_main.bfd_main = &bfd_main; diff --git a/src/vnet/bfd/bfd_udp.h b/src/vnet/bfd/bfd_udp.h index 8f4bfee2bd7..362e9541dfe 100644 --- a/src/vnet/bfd/bfd_udp.h +++ b/src/vnet/bfd/bfd_udp.h @@ -26,12 +26,10 @@ /** identifier of BFD session based on UDP transport only */ typedef CLIB_PACKED (struct { - union { - /** interface to which the session is tied - single-hop */ - u32 sw_if_index; - /** the FIB index the peer is in - multi-hop*/ - u32 fib_index; - }; + /** interface to which the session is tied - single-hop */ + u16 sw_if_index; + /** the FIB index the peer is in - multi-hop*/ + u16 fib_index; /** local address */ ip46_address_t local_addr; /** peer address */ diff --git a/src/vnet/udp/udp_local.h b/src/vnet/udp/udp_local.h index 16286824ef2..06c7b3f1758 100644 --- a/src/vnet/udp/udp_local.h +++ b/src/vnet/udp/udp_local.h @@ -18,42 +18,43 @@ #include -#define foreach_udp4_dst_port \ -_ (53, dns) \ -_ (67, dhcp_to_server) \ -_ (68, dhcp_to_client) \ -_ (500, ikev2) \ -_ (2152, GTPU) \ -_ (3784, bfd4) \ -_ (3785, bfd_echo4) \ -_ (4341, lisp_gpe) \ -_ (4342, lisp_cp) \ -_ (4500, ipsec) \ -_ (4739, ipfix) \ -_ (4789, vxlan) \ -_ (4789, vxlan6) \ -_ (48879, vxlan_gbp) \ -_ (4790, VXLAN_GPE) \ -_ (6633, vpath_3) \ -_ (6081, geneve) \ -_ (53053, dns_reply) +#define foreach_udp4_dst_port \ + _ (53, dns) \ + _ (67, dhcp_to_server) \ + _ (68, dhcp_to_client) \ + _ (500, ikev2) \ + _ (2152, GTPU) \ + _ (3784, bfd4) \ + _ (3785, bfd_echo4) \ + _ (4341, lisp_gpe) \ + _ (4342, lisp_cp) \ + _ (4500, ipsec) \ + _ (4739, ipfix) \ + _ (4784, bfd4_mh) \ + _ (4789, vxlan) \ + _ (4789, vxlan6) \ + _ (48879, vxlan_gbp) \ + _ (4790, VXLAN_GPE) \ + _ (6633, vpath_3) \ + _ (6081, geneve) \ + _ (53053, dns_reply) - -#define foreach_udp6_dst_port \ -_ (53, dns6) \ -_ (547, dhcpv6_to_server) \ -_ (546, dhcpv6_to_client) \ -_ (2152, GTPU6) \ -_ (3784, bfd6) \ -_ (3785, bfd_echo6) \ -_ (4341, lisp_gpe6) \ -_ (4342, lisp_cp6) \ -_ (48879, vxlan6_gbp) \ -_ (4790, VXLAN6_GPE) \ -_ (6633, vpath6_3) \ -_ (6081, geneve6) \ -_ (8138, BIER) \ -_ (53053, dns_reply6) +#define foreach_udp6_dst_port \ + _ (53, dns6) \ + _ (547, dhcpv6_to_server) \ + _ (546, dhcpv6_to_client) \ + _ (2152, GTPU6) \ + _ (3784, bfd6) \ + _ (3785, bfd_echo6) \ + _ (4341, lisp_gpe6) \ + _ (4342, lisp_cp6) \ + _ (48879, vxlan6_gbp) \ + _ (4784, bfd6_mh) \ + _ (4790, VXLAN6_GPE) \ + _ (6633, vpath6_3) \ + _ (6081, geneve6) \ + _ (8138, BIER) \ + _ (53053, dns_reply6) typedef enum { diff --git a/test/bfd.py b/test/bfd.py index 4189983b430..ebe4e5f95f2 100644 --- a/test/bfd.py +++ b/test/bfd.py @@ -17,6 +17,9 @@ from vpp_object import VppObject from util import NumericConstant from vpp_papi import VppEnum +BFD_UDP_SH_PORT = 3784 +BFD_UDP_MH_PORT = 4784 + class BFDDiagCode(NumericConstant): """BFD Diagnostic Code""" @@ -153,7 +156,8 @@ class BFD(Packet): # glue the BFD packet class to scapy parser -bind_layers(UDP, BFD, dport=BFD.udp_dport) +bind_layers(UDP, BFD, dport=BFD_UDP_SH_PORT) +bind_layers(UDP, BFD, dport=BFD_UDP_MH_PORT) class BFD_vpp_echo(Packet): @@ -248,6 +252,7 @@ class VppBFDUDPSession(VppObject): test, interface, peer_addr, + multihop=False, local_addr=None, af=AF_INET, desired_min_tx=300000, @@ -258,12 +263,24 @@ class VppBFDUDPSession(VppObject): is_tunnel=False, ): self._test = test + self._multihop = multihop self._interface = interface self._af = af + + if multihop: + self._sw_if_index = 0xFFFFFFFF + self.test.vapi.bfd_udp_enable_multihop() + else: + self._sw_if_index = self._interface.sw_if_index + if local_addr: self._local_addr = local_addr else: - self._local_addr = None + if self.af == AF_INET: + self._local_addr = self.interface.local_ip4 + else: + self._local_addr = self.interface.local_ip6 + self._peer_addr = peer_addr self._desired_min_tx = desired_min_tx self._required_min_rx = required_min_rx @@ -312,17 +329,10 @@ class VppBFDUDPSession(VppObject): result = self.test.vapi.bfd_udp_session_dump() for s in result: self.test.logger.debug("session entry: %s" % str(s)) - if s.sw_if_index == self.interface.sw_if_index: - if ( - self.af == AF_INET - and self.interface.local_ip4 == str(s.local_addr) - and self.interface.remote_ip4 == str(s.peer_addr) - ): - return s - if ( - self.af == AF_INET6 - and self.interface.local_ip6 == str(s.local_addr) - and self.interface.remote_ip6 == str(s.peer_addr) + multihop = s.sw_if_index == ~0 + if multihop or s.sw_if_index == self._sw_if_index: + if self._local_addr == str(s.local_addr) and self._peer_addr == str( + s.peer_addr ): return s return None @@ -371,7 +381,7 @@ class VppBFDUDPSession(VppObject): conf_key_id = self._sha1_key.conf_key_id is_delayed = 1 if delayed else 0 self.test.vapi.bfd_udp_auth_activate( - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, local_addr=self.local_addr, peer_addr=self.peer_addr, bfd_key_id=self._bfd_key_id, @@ -385,7 +395,7 @@ class VppBFDUDPSession(VppObject): self._sha1_key = None is_delayed = 1 if delayed else 0 self.test.vapi.bfd_udp_auth_deactivate( - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, local_addr=self.local_addr, peer_addr=self.peer_addr, is_delayed=is_delayed, @@ -402,7 +412,7 @@ class VppBFDUDPSession(VppObject): if required_min_rx: self._required_min_rx = required_min_rx self.test.vapi.bfd_udp_mod( - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, desired_min_tx=self.desired_min_tx, required_min_rx=self.required_min_rx, detect_mult=self.detect_mult, @@ -415,7 +425,7 @@ class VppBFDUDPSession(VppObject): conf_key_id = self._sha1_key.conf_key_id if self._sha1_key else None is_authenticated = True if self._sha1_key else False self.test.vapi.bfd_udp_add( - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, desired_min_tx=self.desired_min_tx, required_min_rx=self.required_min_rx, detect_mult=self.detect_mult, @@ -440,7 +450,7 @@ class VppBFDUDPSession(VppObject): conf_key_id = self._sha1_key.conf_key_id if self._sha1_key else None is_authenticated = True if self._sha1_key else False self.test.vapi.bfd_udp_upd( - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, desired_min_tx=self.desired_min_tx, required_min_rx=self.required_min_rx, detect_mult=self.detect_mult, @@ -458,14 +468,15 @@ class VppBFDUDPSession(VppObject): def remove_vpp_config(self): self.test.vapi.bfd_udp_del( - self._interface.sw_if_index, + sw_if_index=self._sw_if_index, local_addr=self.local_addr, peer_addr=self.peer_addr, ) def object_id(self): - return "bfd-udp-%s-%s-%s-%s" % ( - self._interface.sw_if_index, + return "bfd-udp-%s-%s-%s-%s-%s" % ( + self._multihop, + self._sw_if_index, self.local_addr, self.peer_addr, self.af, @@ -475,7 +486,7 @@ class VppBFDUDPSession(VppObject): """set bfd session admin-up""" self.test.vapi.bfd_udp_session_set_flags( flags=VppEnum.vl_api_if_status_flags_t.IF_STATUS_API_FLAG_ADMIN_UP, - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, local_addr=self.local_addr, peer_addr=self.peer_addr, ) @@ -484,7 +495,7 @@ class VppBFDUDPSession(VppObject): """set bfd session admin-down""" self.test.vapi.bfd_udp_session_set_flags( flags=0, - sw_if_index=self._interface.sw_if_index, + sw_if_index=self._sw_if_index, local_addr=self.local_addr, peer_addr=self.peer_addr, ) diff --git a/test/test_bfd.py b/test/test_bfd.py index 0842fd77429..ebc815cb701 100644 --- a/test/test_bfd.py +++ b/test/test_bfd.py @@ -12,6 +12,7 @@ import time import unittest from random import randint, shuffle, getrandbits from socket import AF_INET, AF_INET6 +from parameterized import parameterized, parameterized_class import scapy.compat from scapy.layers.inet import UDP, IP @@ -28,6 +29,8 @@ from bfd import ( BFDDiagCode, BFDState, BFD_vpp_echo, + BFD_UDP_SH_PORT, + BFD_UDP_MH_PORT, ) from framework import VppTestCase from asfframework import ( @@ -45,6 +48,64 @@ from vpp_pg_interface import CaptureTimeoutError, is_ipv6_misc from vpp_gre_interface import VppGreInterface USEC_IN_SEC = 1000000 +BFD_STATS_V4_SH_PATH = "/bfd/udp4/sessions" +BFD_STATS_V6_SH_PATH = "/bfd/udp6/sessions" +BFD_STATS_V4_MH_PATH = "/bfd/udp4/sessions_mh" +BFD_STATS_V6_MH_PATH = "/bfd/udp6/sessions_mh" +BFD_IPV4_REMOTE_ADDR = "2.2.2.2" +BFD_IPV6_REMOTE_ADDR = "2::2" +BFD_IPV4_REMOTE_ADDR2 = "3.3.3.3" +BFD_IPV6_REMOTE_ADDR2 = "3::3" + + +def set_ipv4_pfx_route_info(cls, pg_if, dst_ip, set_src): + try: + if cls.multihop: + paths = [] + # Get list of all the next hops + for nh_host in pg_if.remote_hosts: + nh_host_ip = nh_host.ip4 + paths.append(VppRoutePath(nh_host_ip, pg_if.sw_if_index)) + cls.dst_ip_net = dst_ip + # Create a route pointing to list of next hops + if paths: + rip = VppIpRoute(cls, cls.dst_ip_net, 32, paths) + rip.add_vpp_config() + cls.logger.info("Route via %s on %s created" % (paths, pg_if.name)) + if set_src: + cls.src_ip_net = cls.loopback0.local_ip4 + else: + cls.dst_ip_net = pg_if.remote_ip4 + if set_src: + cls.src_ip_net = pg_if.local_ip4 + except BaseException: + cls.vapi.want_bfd_events(enable_disable=0) + raise + + +def set_ipv6_pfx_route_info(cls, pg_if, dst_ip, set_src): + try: + if cls.multihop: + paths = [] + # Get list of all the next hops + for nh_host in pg_if.remote_hosts: + nh_host_ip = nh_host.ip6 + paths.append(VppRoutePath(nh_host_ip, pg_if.sw_if_index)) + cls.dst_ip6_net = dst_ip + # Create a route pointing to list of next hops + if paths: + rip = VppIpRoute(cls, cls.dst_ip6_net, 128, paths) + rip.add_vpp_config() + cls.logger.info("Route via %s on %s created" % (paths, pg_if.name)) + if set_src: + cls.src_ip6_net = cls.loopback0.local_ip6 + else: + cls.dst_ip6_net = cls.pg0.remote_ip6 + if set_src: + cls.src_ip6_net = cls.pg0.local_ip6 + except BaseException: + cls.vapi.want_bfd_events(enable_disable=0) + raise class AuthKeyFactory(object): @@ -67,18 +128,44 @@ class AuthKeyFactory(object): ) +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) class BFDAPITestCase(VppTestCase): - """Bidirectional Forwarding Detection (BFD) - API""" pg0 = None pg1 = None + interface0 = None + interface1 = None + src_ip_net = "" + dst_ip_net = "" + src_ip_net2 = "" + dst_ip_net2 = "" + src_ip6_net = "" + dst_ip6_net = "" + src_ip6_net2 = "" + dst_ip6_net2 = "" @classmethod def setUpClass(cls): super(BFDAPITestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = ( + f"""""Bidirectional Forwarding Detection (BFD) - API, {hoptype_str}""" + ) cls.vapi.cli("set log class bfd level debug") try: cls.create_pg_interfaces(range(2)) + cls.create_loopback_interfaces(2) + cls.loopback0 = cls.lo_interfaces[0] + cls.loopback0.config_ip4() + cls.loopback0.admin_up() + cls.loopback1 = cls.lo_interfaces[1] + cls.loopback1.config_ip4() + cls.loopback1.admin_up() for i in cls.pg_interfaces: i.config_ip4() i.config_ip6() @@ -96,9 +183,38 @@ class BFDAPITestCase(VppTestCase): super(BFDAPITestCase, self).setUp() self.factory = AuthKeyFactory() + if self.multihop: + self.interface0 = None + self.interface1 = None + self.src_ip_net = self.loopback0.local_ip4 + self.src_ip6_net = self.loopback0.local_ip6 + self.dst_ip_net = BFD_IPV4_REMOTE_ADDR + self.dst_ip6_net = BFD_IPV6_REMOTE_ADDR + self.src_ip_net2 = self.loopback1.local_ip4 + self.src_ip6_net2 = self.loopback1.local_ip6 + self.dst_ip_net2 = BFD_IPV4_REMOTE_ADDR2 + self.dst_ip6_net2 = BFD_IPV6_REMOTE_ADDR2 + else: + self.interface0 = self.pg0 + self.interface1 = self.pg1 + self.src_ip_net = self.pg0.local_ip4 + self.src_ip6_net = self.pg0.local_ip6 + self.dst_ip_net = self.pg0.remote_ip4 + self.dst_ip6_net = self.pg0.remote_ip6 + self.src_ip_net2 = self.pg1.local_ip4 + self.src_ip6_net2 = self.pg1.local_ip6 + self.dst_ip_net2 = BFD_IPV4_REMOTE_ADDR2 + self.dst_ip6_net2 = BFD_IPV6_REMOTE_ADDR2 + def test_add_bfd(self): """create a BFD session""" - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) session.add_vpp_config() self.logger.debug("Session state is %s", session.state) session.remove_vpp_config() @@ -108,7 +224,13 @@ class BFDAPITestCase(VppTestCase): def test_double_add(self): """create the same BFD session twice (negative case)""" - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) session.add_vpp_config() with self.vapi.assert_negative_api_retval(): @@ -118,7 +240,14 @@ class BFDAPITestCase(VppTestCase): def test_add_bfd6(self): """create IPv6 BFD session""" - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip6, af=AF_INET6) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + ) session.add_vpp_config() self.logger.debug("Session state is %s", session.state) session.remove_vpp_config() @@ -130,8 +259,10 @@ class BFDAPITestCase(VppTestCase): """modify BFD session parameters""" session = VppBFDUDPSession( self, - self.pg0, - self.pg0.remote_ip4, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, desired_min_tx=50000, required_min_rx=10000, detect_mult=1, @@ -163,8 +294,10 @@ class BFDAPITestCase(VppTestCase): """Create/Modify w/ Update BFD session parameters""" session = VppBFDUDPSession( self, - self.pg0, - self.pg0.remote_ip4, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, desired_min_tx=50000, required_min_rx=10000, detect_mult=1, @@ -234,7 +367,14 @@ class BFDAPITestCase(VppTestCase): """create a BFD session (SHA1)""" key = self.factory.create_random_key(self) key.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4, sha1_key=key) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, + ) session.add_vpp_config() self.logger.debug("Session state is %s", session.state) session.remove_vpp_config() @@ -246,7 +386,14 @@ class BFDAPITestCase(VppTestCase): """create the same BFD session twice (negative case) (SHA1)""" key = self.factory.create_random_key(self) key.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4, sha1_key=key) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, + ) session.add_vpp_config() with self.assertRaises(Exception): session.add_vpp_config() @@ -255,10 +402,19 @@ class BFDAPITestCase(VppTestCase): """create BFD session using non-existent SHA1 (negative case)""" session = VppBFDUDPSession( self, - self.pg0, - self.pg0.remote_ip4, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, sha1_key=self.factory.create_random_key(self), ) + self.session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) with self.assertRaises(Exception): session.add_vpp_config() @@ -267,13 +423,39 @@ class BFDAPITestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() sessions = [ - VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4, sha1_key=key), VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip6, sha1_key=key, af=AF_INET6 + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ), - VppBFDUDPSession(self, self.pg1, self.pg1.remote_ip4, sha1_key=key), VppBFDUDPSession( - self, self.pg1, self.pg1.remote_ip6, sha1_key=key, af=AF_INET6 + self, + self.interface0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + sha1_key=key, + ), + VppBFDUDPSession( + self, + self.interface1, + self.dst_ip_net2, + local_addr=self.src_ip_net2, + multihop=self.multihop, + sha1_key=key, + ), + VppBFDUDPSession( + self, + self.interface1, + self.dst_ip6_net2, + local_addr=self.src_ip6_net2, + af=AF_INET6, + multihop=self.multihop, + sha1_key=key, ), ] for s in sessions: @@ -295,7 +477,13 @@ class BFDAPITestCase(VppTestCase): """activate SHA1 authentication""" key = self.factory.create_random_key(self) key.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) session.add_vpp_config() session.activate_auth(key) @@ -303,7 +491,13 @@ class BFDAPITestCase(VppTestCase): """deactivate SHA1 authentication""" key = self.factory.create_random_key(self) key.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) session.add_vpp_config() session.activate_auth(key) session.deactivate_auth() @@ -316,12 +510,25 @@ class BFDAPITestCase(VppTestCase): key2 = self.factory.create_random_key(self) key1.add_vpp_config() key2.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4, sha1_key=key1) + session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key1, + ) session.add_vpp_config() session.activate_auth(key2) def test_set_del_udp_echo_source(self): """set/del udp echo source""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + self.create_loopback_interfaces(1) self.loopback0 = self.lo_interfaces[0] self.loopback0.admin_up() @@ -382,6 +589,9 @@ class BFDTestSession(object): our_seq_number=None, tunnel_header=None, phy_interface=None, + multihop=False, + local_addr=None, + peer_addr=None, ): self.test = test self.af = af @@ -413,6 +623,29 @@ class BFDTestSession(object): self.tx_packets_echo = 0 self.rx_packets_echo = 0 + if multihop: + self.sw_if_index = 0 + BFD.udp_dport = BFD_UDP_MH_PORT + else: + BFD.udp_dport = BFD_UDP_SH_PORT + self.sw_if_index = self.interface.sw_if_index + + if local_addr: + self.local_addr = local_addr + else: + if self.af == AF_INET: + self.local_addr = self.interface.local_ip4 + else: + self.local_addr = self.interface.local_ip6 + + if peer_addr: + self.peer_addr = peer_addr + else: + if self.af == AF_INET: + self.peer_addr = self.interface.remote_ip4 + else: + self.peer_addr = self.interface.remote_ip6 + def inc_seq_num(self): """increment sequence number, wrapping if needed""" if self.our_seq_number == 0xFFFFFFFF: @@ -516,8 +749,8 @@ class BFDTestSession(object): packet = ( packet / IPv6( - src=self.interface.remote_ip6, - dst=self.interface.local_ip6, + src=self.peer_addr, + dst=self.local_addr, hlim=255, ) / UDP(sport=self.udp_sport, dport=BFD.udp_dport) @@ -526,9 +759,7 @@ class BFDTestSession(object): else: packet = ( packet - / IP( - src=self.interface.remote_ip4, dst=self.interface.local_ip4, ttl=255 - ) + / IP(src=self.peer_addr, dst=self.local_addr, ttl=255) / UDP(sport=self.udp_sport, dport=BFD.udp_dport) / bfd ) @@ -709,13 +940,13 @@ def verify_ip(test, packet): """Verify correctness of IP layer.""" if test.vpp_session.af == AF_INET6: ip = packet[IPv6] - local_ip = test.vpp_session.interface.local_ip6 - remote_ip = test.vpp_session.interface.remote_ip6 + local_ip = test.vpp_session.local_addr + remote_ip = test.vpp_session.peer_addr test.assert_equal(ip.hlim, 255, "IPv6 hop limit") else: ip = packet[IP] - local_ip = test.vpp_session.interface.local_ip4 - remote_ip = test.vpp_session.interface.remote_ip4 + local_ip = test.vpp_session.local_addr + remote_ip = test.vpp_session.peer_addr test.assert_equal(ip.ttl, 255, "IPv4 TTL") test.assert_equal(ip.src, local_ip, "IP source address") test.assert_equal(ip.dst, remote_ip, "IP destination address") @@ -735,7 +966,7 @@ def verify_event(test, event, expected_state): e = event test.logger.debug("BFD: Event: %s" % reprlib.repr(e)) test.assert_equal( - e.sw_if_index, test.vpp_session.interface.sw_if_index, "BFD interface index" + e.sw_if_index, test.vpp_session._sw_if_index, "BFD interface index" ) test.assert_equal( @@ -819,19 +1050,30 @@ def bfd_stats_diff(stats_before, stats_after): return BFDStats(rx, rx_echo, tx, tx_echo) +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) @tag_run_solo @tag_fixme_debian11 class BFD4TestCase(VppTestCase): - """Bidirectional Forwarding Detection (BFD)""" - pg0 = None + interface0 = None vpp_clock_offset = None vpp_session = None test_session = None + src_ip_net = "" + dst_ip_net = "" @classmethod def setUpClass(cls): super(BFD4TestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = ( + f"""""Bidirectional Forwarding Detection (BFD) - IPv4, {hoptype_str}""" + ) cls.vapi.cli("set log class bfd level debug") try: cls.create_pg_interfaces([0]) @@ -857,14 +1099,36 @@ class BFD4TestCase(VppTestCase): self.factory = AuthKeyFactory() self.vapi.want_bfd_events() self.pg0.enable_capture() + set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) + try: - self.bfd_udp4_sessions = self.statistics["/bfd/udp4/sessions"] - self.bfd_udp6_sessions = self.statistics["/bfd/udp6/sessions"] + if self.multihop: + self.interface0 = None + self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] + self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] + else: + self.interface0 = self.pg0 + self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] + self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] + self.vapi.cli("trace add bfd-process 500") - self.vpp_session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + self.vpp_session = VppBFDUDPSession( + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() - self.test_session = BFDTestSession(self, self.pg0, AF_INET) + self.test_session = BFDTestSession( + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + ) except BaseException: self.vapi.want_bfd_events(enable_disable=0) raise @@ -878,8 +1142,13 @@ class BFD4TestCase(VppTestCase): def test_session_up(self): """bring BFD session up""" bfd_session_up(self) - bfd_udp4_sessions = self.statistics["/bfd/udp4/sessions"] - bfd_udp6_sessions = self.statistics["/bfd/udp6/sessions"] + if self.multihop: + bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] + bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] + else: + bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] + bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] + self.assert_equal(bfd_udp4_sessions - self.bfd_udp4_sessions, 1) self.assert_equal(bfd_udp6_sessions, self.bfd_udp6_sessions) @@ -1020,7 +1289,12 @@ class BFD4TestCase(VppTestCase): """immediately honor remote required min rx reduction""" self.vpp_session.remove_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, desired_min_tx=10000 + self, + self.interface0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + desired_min_tx=10000, ) self.pg0.enable_capture() self.vpp_session.add_vpp_config() @@ -1265,6 +1539,12 @@ class BFD4TestCase(VppTestCase): def test_echo_looped_back(self): """echo packets looped back""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) stats_before = bfd_grab_stats_snapshot(self) self.pg0.enable_capture() @@ -1329,6 +1609,12 @@ class BFD4TestCase(VppTestCase): def test_echo(self): """echo function""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + stats_before = bfd_grab_stats_snapshot(self) bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) @@ -1420,6 +1706,12 @@ class BFD4TestCase(VppTestCase): def test_echo_fail(self): """session goes down if echo function fails""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) self.test_session.send_packet() @@ -1462,6 +1754,12 @@ class BFD4TestCase(VppTestCase): def test_echo_stop(self): """echo function stops if peer sets required min echo rx zero""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) self.test_session.send_packet() @@ -1492,6 +1790,12 @@ class BFD4TestCase(VppTestCase): def test_echo_source_removed(self): """echo function stops if echo source is removed""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) self.test_session.send_packet() @@ -1522,6 +1826,12 @@ class BFD4TestCase(VppTestCase): def test_stale_echo(self): """stale echo packets don't keep a session up""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) @@ -1581,6 +1891,12 @@ class BFD4TestCase(VppTestCase): def test_invalid_echo_checksum(self): """echo packets with invalid checksum don't keep a session up""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) self.vapi.bfd_udp_set_echo_source(sw_if_index=self.loopback0.sw_if_index) @@ -1713,28 +2029,55 @@ class BFD4TestCase(VppTestCase): intf.config_ip4() intf.admin_up() sw_if_index = intf.sw_if_index - vpp_session = VppBFDUDPSession(self, intf, intf.remote_ip4) + + # Setup routing info for multihop + set_ipv4_pfx_route_info(self, intf, BFD_IPV4_REMOTE_ADDR2, False) + + vpp_session = VppBFDUDPSession( + self, + intf, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) + vpp_session.add_vpp_config() vpp_session.admin_up() intf.remove_vpp_config() - e = self.vapi.wait_for_event(1, "bfd_udp_session_event") - self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index") - self.assertFalse(vpp_session.query_vpp_config()) + + # BFD session is removed only for single-hop session + if self.multihop: + self.assertTrue(vpp_session.query_vpp_config()) + else: + e = self.vapi.wait_for_event(1, "bfd_udp_session_event") + self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index") + self.assertFalse(vpp_session.query_vpp_config()) +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) @tag_run_solo @tag_fixme_vpp_workers class BFD6TestCase(VppTestCase): - """Bidirectional Forwarding Detection (BFD) (IPv6)""" - pg0 = None + interface0 = None vpp_clock_offset = None vpp_session = None test_session = None + src_ip6_net = "" + dst_ip6_net = "" @classmethod def setUpClass(cls): super(BFD6TestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = ( + f"""""Bidirectional Forwarding Detection (BFD) - IPv6, {hoptype_str}""" + ) cls.vapi.cli("set log class bfd level debug") try: cls.create_pg_interfaces([0]) @@ -1760,21 +2103,43 @@ class BFD6TestCase(VppTestCase): self.factory = AuthKeyFactory() self.vapi.want_bfd_events() self.pg0.enable_capture() + set_ipv6_pfx_route_info(self, self.pg0, BFD_IPV6_REMOTE_ADDR, True) + try: - self.bfd_udp4_sessions = self.statistics["/bfd/udp4/sessions"] - self.bfd_udp6_sessions = self.statistics["/bfd/udp6/sessions"] + if self.multihop: + self.interface0 = None + self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] + self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] + else: + self.interface0 = self.pg0 + self.bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] + self.bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] + self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip6, af=AF_INET6 + self, + self.interface0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() - self.test_session = BFDTestSession(self, self.pg0, AF_INET6) + self.test_session = BFDTestSession( + self, + self.pg0, + AF_INET6, + local_addr=self.src_ip6_net, + peer_addr=self.dst_ip6_net, + multihop=self.multihop, + ) self.logger.debug(self.vapi.cli("show adj nbr")) except BaseException: self.vapi.want_bfd_events(enable_disable=0) raise def tearDown(self): + self.vpp_session.remove_vpp_config() if not self.vpp_dead: self.vapi.want_bfd_events(enable_disable=0) self.vapi.collect_events() # clear the event queue @@ -1783,8 +2148,13 @@ class BFD6TestCase(VppTestCase): def test_session_up(self): """bring BFD session up""" bfd_session_up(self) - bfd_udp4_sessions = self.statistics["/bfd/udp4/sessions"] - bfd_udp6_sessions = self.statistics["/bfd/udp6/sessions"] + if self.multihop: + bfd_udp4_sessions = self.statistics[BFD_STATS_V4_MH_PATH] + bfd_udp6_sessions = self.statistics[BFD_STATS_V6_MH_PATH] + else: + bfd_udp4_sessions = self.statistics[BFD_STATS_V4_SH_PATH] + bfd_udp6_sessions = self.statistics[BFD_STATS_V6_SH_PATH] + self.assert_equal(bfd_udp4_sessions, self.bfd_udp4_sessions) self.assert_equal(bfd_udp6_sessions - self.bfd_udp6_sessions, 1) @@ -1828,6 +2198,12 @@ class BFD6TestCase(VppTestCase): def test_echo_looped_back(self): """echo packets looped back""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + bfd_session_up(self) stats_before = bfd_grab_stats_snapshot(self) self.pg0.enable_capture() @@ -1891,6 +2267,12 @@ class BFD6TestCase(VppTestCase): def test_echo(self): """echo function""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + stats_before = bfd_grab_stats_snapshot(self) bfd_session_up(self) self.test_session.update(required_min_echo_rx=150000) @@ -1988,25 +2370,53 @@ class BFD6TestCase(VppTestCase): intf.config_ip6() intf.admin_up() sw_if_index = intf.sw_if_index - vpp_session = VppBFDUDPSession(self, intf, intf.remote_ip6, af=AF_INET6) + + # Setup routing info for multihop + set_ipv6_pfx_route_info(self, intf, BFD_IPV6_REMOTE_ADDR2, False) + + vpp_session = VppBFDUDPSession( + self, + intf, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + ) + vpp_session.add_vpp_config() vpp_session.admin_up() intf.remove_vpp_config() - e = self.vapi.wait_for_event(1, "bfd_udp_session_event") - self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index") - self.assertFalse(vpp_session.query_vpp_config()) + # BFD session is removed only for single-hop session + if self.multihop: + self.assertTrue(vpp_session.query_vpp_config()) + else: + e = self.vapi.wait_for_event(1, "bfd_udp_session_event") + self.assert_equal(e.sw_if_index, sw_if_index, "sw_if_index") + self.assertFalse(vpp_session.query_vpp_config()) + +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) @tag_run_solo class BFDFIBTestCase(VppTestCase): """BFD-FIB interactions (IPv6)""" vpp_session = None test_session = None + src_ip6_net = "" + dst_ip6_net = "" @classmethod def setUpClass(cls): super(BFDFIBTestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = f"""""BFD-FIB interactions (IPv6) - {hoptype_str}""" + cls.vapi.cli("set log class bfd level debug") @classmethod def tearDownClass(cls): @@ -2015,6 +2425,10 @@ class BFDFIBTestCase(VppTestCase): def setUp(self): super(BFDFIBTestCase, self).setUp() self.create_pg_interfaces(range(1)) + self.create_loopback_interfaces(1) + self.loopback0 = self.lo_interfaces[0] + self.loopback0.config_ip6() + self.loopback0.admin_up() self.vapi.want_bfd_events() self.pg0.enable_capture() @@ -2024,6 +2438,8 @@ class BFDFIBTestCase(VppTestCase): i.config_ip6() i.configure_ipv6_neighbors() + set_ipv6_pfx_route_info(self, self.pg0, BFD_IPV6_REMOTE_ADDR, True) + def tearDown(self): if not self.vpp_dead: self.vapi.want_bfd_events(enable_disable=False) @@ -2056,27 +2472,44 @@ class BFDFIBTestCase(VppTestCase): ), ] - # A recursive and a non-recursive route via a next-hop that - # will have a BFD session + # Two different routes via a next-hop that will have a BFD session. + # One of the routes is non-recursive route only for single-hop. + if self.multihop: + intf_index = 0xFFFFFFFF + else: + intf_index = self.pg0.sw_if_index + ip_2001_s_64 = VppIpRoute( self, "2001::", 64, - [VppRoutePath(self.pg0.remote_ip6, self.pg0.sw_if_index)], + [VppRoutePath(self.dst_ip6_net, intf_index)], ) ip_2002_s_64 = VppIpRoute( - self, "2002::", 64, [VppRoutePath(self.pg0.remote_ip6, 0xFFFFFFFF)] + self, "2002::", 64, [VppRoutePath(self.dst_ip6_net, 0xFFFFFFFF)] ) ip_2001_s_64.add_vpp_config() ip_2002_s_64.add_vpp_config() # bring the session up now the routes are present self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip6, af=AF_INET6 + self, + self.pg0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() - self.test_session = BFDTestSession(self, self.pg0, AF_INET6) + self.test_session = BFDTestSession( + self, + self.pg0, + AF_INET6, + local_addr=self.src_ip6_net, + peer_addr=self.dst_ip6_net, + multihop=self.multihop, + ) # session is up - traffic passes bfd_session_up(self) @@ -2089,7 +2522,7 @@ class BFDFIBTestCase(VppTestCase): ) self.assertEqual(captured[IPv6].dst, packet[IPv6].dst) - # session is up - traffic is dropped + # session is down - traffic is dropped bfd_session_down(self) self.pg0.add_stream(p) @@ -2192,22 +2625,35 @@ class BFDTunTestCase(VppTestCase): bfd_session_down(self) +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) @tag_run_solo class BFDSHA1TestCase(VppTestCase): - """Bidirectional Forwarding Detection (BFD) (SHA1 auth)""" - pg0 = None vpp_clock_offset = None vpp_session = None test_session = None + src_ip_net = "" + dst_ip_net = "" @classmethod def setUpClass(cls): super(BFDSHA1TestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = f"""""Bidirectional Forwarding Detection (BFD) - SHA1 auth - {hoptype_str}""" cls.vapi.cli("set log class bfd level debug") try: cls.create_pg_interfaces([0]) + cls.create_loopback_interfaces(1) + cls.loopback0 = cls.lo_interfaces[0] + cls.loopback0.config_ip4() + cls.loopback0.admin_up() cls.pg0.config_ip4() + cls.pg0.configure_ipv4_neighbors() cls.pg0.admin_up() cls.pg0.resolve_arp() @@ -2224,6 +2670,7 @@ class BFDSHA1TestCase(VppTestCase): self.factory = AuthKeyFactory() self.vapi.want_bfd_events() self.pg0.enable_capture() + set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) def tearDown(self): if not self.vpp_dead: @@ -2236,7 +2683,12 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() @@ -2244,6 +2696,9 @@ class BFDSHA1TestCase(VppTestCase): self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2254,7 +2709,12 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() @@ -2262,6 +2722,9 @@ class BFDSHA1TestCase(VppTestCase): self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2276,7 +2739,12 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self, BFDAuthType.meticulous_keyed_sha1) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() @@ -2285,6 +2753,9 @@ class BFDSHA1TestCase(VppTestCase): self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, our_seq_number=0xFFFFFFFF - 4, @@ -2301,13 +2772,21 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self, BFDAuthType.meticulous_keyed_sha1) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.test_session = BFDTestSession( self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2376,12 +2855,31 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) legitimate_test_session = BFDTestSession( - self, self.pg0, AF_INET, sha1_key=key, bfd_key_id=vpp_session.bfd_key_id + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + sha1_key=key, + bfd_key_id=vpp_session.bfd_key_id, + ) + rogue_test_session = BFDTestSession( + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, ) - rogue_test_session = BFDTestSession(self, self.pg0, AF_INET) self.execute_rogue_session_scenario( vpp_session, legitimate_test_session, rogue_test_session ) @@ -2391,17 +2889,36 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) # pick a different random bfd key id x = randint(0, 255) while x == vpp_session.bfd_key_id: x = randint(0, 255) legitimate_test_session = BFDTestSession( - self, self.pg0, AF_INET, sha1_key=key, bfd_key_id=vpp_session.bfd_key_id + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + sha1_key=key, + bfd_key_id=vpp_session.bfd_key_id, ) rogue_test_session = BFDTestSession( - self, self.pg0, AF_INET, sha1_key=key, bfd_key_id=x + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + sha1_key=key, + bfd_key_id=x, ) self.execute_rogue_session_scenario( vpp_session, legitimate_test_session, rogue_test_session @@ -2412,13 +2929,32 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) legitimate_test_session = BFDTestSession( - self, self.pg0, AF_INET, sha1_key=key, bfd_key_id=vpp_session.bfd_key_id + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + sha1_key=key, + bfd_key_id=vpp_session.bfd_key_id, ) rogue_test_session = BFDTestSession( - self, self.pg0, AF_INET, sha1_key=key, bfd_key_id=vpp_session.bfd_key_id + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + sha1_key=key, + bfd_key_id=vpp_session.bfd_key_id, ) self.execute_rogue_session_scenario( vpp_session, @@ -2432,13 +2968,21 @@ class BFDSHA1TestCase(VppTestCase): key = self.factory.create_random_key(self, BFDAuthType.meticulous_keyed_sha1) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.test_session = BFDTestSession( self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, our_seq_number=0, @@ -2464,10 +3008,14 @@ class BFDSHA1TestCase(VppTestCase): bfd_session_up(self) +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) @tag_run_solo class BFDAuthOnOffTestCase(VppTestCase): - """Bidirectional Forwarding Detection (BFD) (changing auth)""" - pg0 = None vpp_session = None test_session = None @@ -2475,10 +3023,17 @@ class BFDAuthOnOffTestCase(VppTestCase): @classmethod def setUpClass(cls): super(BFDAuthOnOffTestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = f"""""Bidirectional Forwarding Detection (BFD) - changing auth - {hoptype_str}""" cls.vapi.cli("set log class bfd level debug") try: cls.create_pg_interfaces([0]) + cls.create_loopback_interfaces(1) + cls.loopback0 = cls.lo_interfaces[0] + cls.loopback0.config_ip4() + cls.loopback0.admin_up() cls.pg0.config_ip4() + cls.pg0.configure_ipv4_neighbors() cls.pg0.admin_up() cls.pg0.resolve_arp() @@ -2495,6 +3050,7 @@ class BFDAuthOnOffTestCase(VppTestCase): self.factory = AuthKeyFactory() self.vapi.want_bfd_events() self.pg0.enable_capture() + set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) def tearDown(self): if not self.vpp_dead: @@ -2506,9 +3062,22 @@ class BFDAuthOnOffTestCase(VppTestCase): """turn auth on without disturbing session state (immediate)""" key = self.factory.create_random_key(self) key.add_vpp_config() - self.vpp_session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + self.vpp_session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) self.vpp_session.add_vpp_config() - self.test_session = BFDTestSession(self, self.pg0, AF_INET) + self.test_session = BFDTestSession( + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + ) bfd_session_up(self) for dummy in range(self.test_session.detect_mult * 2): p = wait_for_bfd_packet(self) @@ -2529,13 +3098,21 @@ class BFDAuthOnOffTestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.test_session = BFDTestSession( self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2564,13 +3141,21 @@ class BFDAuthOnOffTestCase(VppTestCase): key2 = self.factory.create_random_key(self) key2.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key1 + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key1, ) self.vpp_session.add_vpp_config() self.test_session = BFDTestSession( self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key1, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2593,9 +3178,22 @@ class BFDAuthOnOffTestCase(VppTestCase): """turn auth on without disturbing session state (delayed)""" key = self.factory.create_random_key(self) key.add_vpp_config() - self.vpp_session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + self.vpp_session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) self.vpp_session.add_vpp_config() - self.test_session = BFDTestSession(self, self.pg0, AF_INET) + self.test_session = BFDTestSession( + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + ) bfd_session_up(self) for dummy in range(self.test_session.detect_mult * 2): wait_for_bfd_packet(self) @@ -2620,13 +3218,21 @@ class BFDAuthOnOffTestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.vpp_session.add_vpp_config() self.test_session = BFDTestSession( self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2657,7 +3263,12 @@ class BFDAuthOnOffTestCase(VppTestCase): key2 = self.factory.create_random_key(self) key2.add_vpp_config() self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key1 + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key1, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() @@ -2665,6 +3276,9 @@ class BFDAuthOnOffTestCase(VppTestCase): self, self.pg0, AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, sha1_key=key1, bfd_key_id=self.vpp_session.bfd_key_id, ) @@ -2689,6 +3303,12 @@ class BFDAuthOnOffTestCase(VppTestCase): self.assert_equal(len(self.vapi.collect_events()), 0, "number of bfd events") +@parameterized_class( + [ + {"multihop": False}, + {"multihop": True}, + ] +) @tag_run_solo class BFDCLITestCase(VppTestCase): """Bidirectional Forwarding Detection (BFD) (CLI)""" @@ -2698,11 +3318,22 @@ class BFDCLITestCase(VppTestCase): @classmethod def setUpClass(cls): super(BFDCLITestCase, cls).setUpClass() + hoptype_str = "MultiHop" if cls.multihop else "SingleHop" + cls.__doc__ = ( + f"""""Bidirectional Forwarding Detection (BFD) - CLI - {hoptype_str}""" + ) cls.vapi.cli("set log class bfd level debug") try: - cls.create_pg_interfaces((0,)) + cls.create_pg_interfaces([0]) + cls.create_loopback_interfaces(1) + cls.loopback0 = cls.lo_interfaces[0] + cls.loopback0.config_ip4() + cls.loopback0.config_ip6() + cls.loopback0.admin_up() cls.pg0.config_ip4() cls.pg0.config_ip6() + cls.pg0.configure_ipv4_neighbors() + cls.pg0.admin_up() cls.pg0.resolve_arp() cls.pg0.resolve_ndp() @@ -2718,6 +3349,13 @@ class BFDCLITestCase(VppTestCase): super(BFDCLITestCase, self).setUp() self.factory = AuthKeyFactory() self.pg0.enable_capture() + set_ipv4_pfx_route_info(self, self.pg0, BFD_IPV4_REMOTE_ADDR, True) + set_ipv6_pfx_route_info(self, self.pg0, BFD_IPV6_REMOTE_ADDR, True) + + if self.multihop: + self.cli_str = "multihop" + else: + self.cli_str = "interface %s" % self.pg0.name def tearDown(self): try: @@ -2748,10 +3386,22 @@ class BFDCLITestCase(VppTestCase): self, auth_type=BFDAuthType.meticulous_keyed_sha1 ) k2.add_vpp_config() - s1 = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + s1 = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) s1.add_vpp_config() s2 = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip6, af=AF_INET6, sha1_key=k2 + self, + self.pg0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + sha1_key=k2, ) s2.add_vpp_config() self.logger.info(self.vapi.ppcli("show bfd keys")) @@ -2771,11 +3421,23 @@ class BFDCLITestCase(VppTestCase): ) self.assertTrue(k.query_vpp_config()) self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=k + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=k, ) self.vpp_session.add_vpp_config() self.test_session = BFDTestSession( - self, self.pg0, AF_INET, sha1_key=k, bfd_key_id=self.vpp_session.bfd_key_id + self, + self.pg0, + AF_INET, + local_addr=self.src_ip_net, + peer_addr=self.dst_ip_net, + multihop=self.multihop, + sha1_key=k, + bfd_key_id=self.vpp_session.bfd_key_id, ) self.vapi.want_bfd_events() bfd_session_up(self) @@ -2814,12 +3476,25 @@ class BFDCLITestCase(VppTestCase): ) self.assertTrue(k.query_vpp_config()) self.vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip6, af=AF_INET6, sha1_key=k + self, + self.pg0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + sha1_key=k, ) self.vpp_session.add_vpp_config() self.vpp_session.admin_up() self.test_session = BFDTestSession( - self, self.pg0, AF_INET6, sha1_key=k, bfd_key_id=self.vpp_session.bfd_key_id + self, + self.pg0, + AF_INET6, + local_addr=self.src_ip6_net, + peer_addr=self.dst_ip6_net, + multihop=self.multihop, + sha1_key=k, + bfd_key_id=self.vpp_session.bfd_key_id, ) self.vapi.want_bfd_events() bfd_session_up(self) @@ -2845,16 +3520,22 @@ class BFDCLITestCase(VppTestCase): def test_add_mod_del_bfd_udp(self): """create/modify/delete IPv4 BFD UDP session""" - vpp_session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + vpp_session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) self.registry.register(vpp_session, self.logger) cli_add_cmd = ( - "bfd udp session add interface %s local-addr %s " + "bfd udp session add %s local-addr %s " "peer-addr %s desired-min-tx %s required-min-rx %s " "detect-mult %s" % ( - self.pg0.name, - self.pg0.local_ip4, - self.pg0.remote_ip4, + self.cli_str, + self.src_ip_net, + self.dst_ip_net, vpp_session.desired_min_tx, vpp_session.required_min_rx, vpp_session.detect_mult, @@ -2868,30 +3549,34 @@ class BFDCLITestCase(VppTestCase): " failed, rv=-101:Duplicate BFD object", ) verify_bfd_session_config(self, vpp_session) + mod_session = VppBFDUDPSession( self, self.pg0, - self.pg0.remote_ip4, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, required_min_rx=2 * vpp_session.required_min_rx, desired_min_tx=3 * vpp_session.desired_min_tx, detect_mult=4 * vpp_session.detect_mult, ) self.cli_verify_no_response( - "bfd udp session mod interface %s local-addr %s peer-addr %s " + "bfd udp session mod %s local-addr %s peer-addr %s " "desired-min-tx %s required-min-rx %s detect-mult %s" % ( - self.pg0.name, - self.pg0.local_ip4, - self.pg0.remote_ip4, + self.cli_str, + self.src_ip_net, + self.dst_ip_net, mod_session.desired_min_tx, mod_session.required_min_rx, mod_session.detect_mult, ) ) verify_bfd_session_config(self, mod_session) - cli_del_cmd = ( - "bfd udp session del interface %s local-addr %s " - "peer-addr %s" % (self.pg0.name, self.pg0.local_ip4, self.pg0.remote_ip4) + cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( + self.cli_str, + self.src_ip_net, + self.dst_ip_net, ) self.cli_verify_no_response(cli_del_cmd) # 2nd del is expected to fail @@ -2902,18 +3587,83 @@ class BFDCLITestCase(VppTestCase): ) self.assertFalse(vpp_session.query_vpp_config()) + if self.multihop: + # specifying multihop and interface should fail + cli_add_cmd = ( + "bfd udp session add multihop interface %s local-addr 1.1.1.1 " + "peer-addr 2.2.2.2 desired-min-tx 50000 required-min-rx 1000 " + "detect-mult 3" % (self.pg0.name) + ) + self.cli_verify_response( + cli_add_cmd, + "bfd udp session add: Incompatible parameter combination, " + "interface cannot be specified when multihop is enabled", + ) + cli_mod_cmd = ( + "bfd udp session mod multihop interface %s local-addr 1.1.1.1 " + "peer-addr 2.2.2.2 desired-min-tx 50000 required-min-rx 1000 " + "detect-mult 3" % (self.pg0.name) + ) + self.cli_verify_response( + cli_mod_cmd, + "bfd udp session mod: Incompatible parameter combination, " + "interface cannot be specified when multihop is enabled", + ) + cli_del_cmd = ( + "bfd udp session del multihop interface %s local-addr 1.1.1.1 " + "peer-addr 2.2.2.2" % (self.pg0.name) + ) + self.cli_verify_response( + cli_del_cmd, + "bfd udp session del: Incompatible parameter combination, " + "interface cannot be specified when multihop is enabled", + ) + + # Not specifying multihop or interface should fail + cli_add_cmd = ( + "bfd udp session add local-addr 1.1.1.1 peer-addr 2.2.2.2 " + "desired-min-tx 50000 required-min-rx 1000 detect-mult 3" + ) + self.cli_verify_response( + cli_add_cmd, + "bfd udp session add: Incompatible parameter combination, " + "interface must be set if not multihop", + ) + cli_mod_cmd = ( + "bfd udp session mod local-addr 1.1.1.1 peer-addr 2.2.2.2 " + "desired-min-tx 50000 required-min-rx 1000 detect-mult 3" + ) + self.cli_verify_response( + cli_mod_cmd, + "bfd udp session mod: Incompatible parameter combination, " + "interface must be set if not multihop", + ) + cli_del_cmd = "bfd udp session del local-addr 1.1.1.1 peer-addr 2.2.2.2 " + self.cli_verify_response( + cli_del_cmd, + "bfd udp session del: Incompatible parameter combination, " + "interface must be set if not multihop", + ) + def test_add_mod_del_bfd_udp6(self): """create/modify/delete IPv6 BFD UDP session""" - vpp_session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip6, af=AF_INET6) + vpp_session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + ) self.registry.register(vpp_session, self.logger) cli_add_cmd = ( - "bfd udp session add interface %s local-addr %s " + "bfd udp session add %s local-addr %s " "peer-addr %s desired-min-tx %s required-min-rx %s " "detect-mult %s" % ( - self.pg0.name, - self.pg0.local_ip6, - self.pg0.remote_ip6, + self.cli_str, + self.src_ip6_net, + self.dst_ip6_net, vpp_session.desired_min_tx, vpp_session.required_min_rx, vpp_session.detect_mult, @@ -2930,28 +3680,31 @@ class BFDCLITestCase(VppTestCase): mod_session = VppBFDUDPSession( self, self.pg0, - self.pg0.remote_ip6, + self.dst_ip6_net, + local_addr=self.src_ip6_net, af=AF_INET6, + multihop=self.multihop, required_min_rx=2 * vpp_session.required_min_rx, desired_min_tx=3 * vpp_session.desired_min_tx, detect_mult=4 * vpp_session.detect_mult, ) self.cli_verify_no_response( - "bfd udp session mod interface %s local-addr %s peer-addr %s " + "bfd udp session mod %s local-addr %s peer-addr %s " "desired-min-tx %s required-min-rx %s detect-mult %s" % ( - self.pg0.name, - self.pg0.local_ip6, - self.pg0.remote_ip6, + self.cli_str, + self.src_ip6_net, + self.dst_ip6_net, mod_session.desired_min_tx, mod_session.required_min_rx, mod_session.detect_mult, ) ) verify_bfd_session_config(self, mod_session) - cli_del_cmd = ( - "bfd udp session del interface %s local-addr %s " - "peer-addr %s" % (self.pg0.name, self.pg0.local_ip6, self.pg0.remote_ip6) + cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( + self.cli_str, + self.src_ip6_net, + self.dst_ip6_net, ) self.cli_verify_no_response(cli_del_cmd) # 2nd del is expected to fail @@ -2967,17 +3720,22 @@ class BFDCLITestCase(VppTestCase): key = self.factory.create_random_key(self) key.add_vpp_config() vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) self.registry.register(vpp_session, self.logger) cli_add_cmd = ( - "bfd udp session add interface %s local-addr %s " + "bfd udp session add %s local-addr %s " "peer-addr %s desired-min-tx %s required-min-rx %s " "detect-mult %s conf-key-id %s bfd-key-id %s" % ( - self.pg0.name, - self.pg0.local_ip4, - self.pg0.remote_ip4, + self.cli_str, + self.src_ip_net, + self.dst_ip_net, vpp_session.desired_min_tx, vpp_session.required_min_rx, vpp_session.detect_mult, @@ -2996,7 +3754,9 @@ class BFDCLITestCase(VppTestCase): mod_session = VppBFDUDPSession( self, self.pg0, - self.pg0.remote_ip4, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, sha1_key=key, bfd_key_id=vpp_session.bfd_key_id, required_min_rx=2 * vpp_session.required_min_rx, @@ -3004,21 +3764,22 @@ class BFDCLITestCase(VppTestCase): detect_mult=4 * vpp_session.detect_mult, ) self.cli_verify_no_response( - "bfd udp session mod interface %s local-addr %s peer-addr %s " + "bfd udp session mod %s local-addr %s peer-addr %s " "desired-min-tx %s required-min-rx %s detect-mult %s" % ( - self.pg0.name, - self.pg0.local_ip4, - self.pg0.remote_ip4, + self.cli_str, + self.src_ip_net, + self.dst_ip_net, mod_session.desired_min_tx, mod_session.required_min_rx, mod_session.detect_mult, ) ) verify_bfd_session_config(self, mod_session) - cli_del_cmd = ( - "bfd udp session del interface %s local-addr %s " - "peer-addr %s" % (self.pg0.name, self.pg0.local_ip4, self.pg0.remote_ip4) + cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( + self.cli_str, + self.src_ip_net, + self.dst_ip_net, ) self.cli_verify_no_response(cli_del_cmd) # 2nd del is expected to fail @@ -3036,17 +3797,23 @@ class BFDCLITestCase(VppTestCase): ) key.add_vpp_config() vpp_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip6, af=AF_INET6, sha1_key=key + self, + self.pg0, + self.dst_ip6_net, + local_addr=self.src_ip6_net, + af=AF_INET6, + multihop=self.multihop, + sha1_key=key, ) self.registry.register(vpp_session, self.logger) cli_add_cmd = ( - "bfd udp session add interface %s local-addr %s " + "bfd udp session add %s local-addr %s " "peer-addr %s desired-min-tx %s required-min-rx %s " "detect-mult %s conf-key-id %s bfd-key-id %s" % ( - self.pg0.name, - self.pg0.local_ip6, - self.pg0.remote_ip6, + self.cli_str, + self.src_ip6_net, + self.dst_ip6_net, vpp_session.desired_min_tx, vpp_session.required_min_rx, vpp_session.detect_mult, @@ -3065,8 +3832,10 @@ class BFDCLITestCase(VppTestCase): mod_session = VppBFDUDPSession( self, self.pg0, - self.pg0.remote_ip6, + self.dst_ip6_net, + local_addr=self.src_ip6_net, af=AF_INET6, + multihop=self.multihop, sha1_key=key, bfd_key_id=vpp_session.bfd_key_id, required_min_rx=2 * vpp_session.required_min_rx, @@ -3074,21 +3843,22 @@ class BFDCLITestCase(VppTestCase): detect_mult=4 * vpp_session.detect_mult, ) self.cli_verify_no_response( - "bfd udp session mod interface %s local-addr %s peer-addr %s " + "bfd udp session mod %s local-addr %s peer-addr %s " "desired-min-tx %s required-min-rx %s detect-mult %s" % ( - self.pg0.name, - self.pg0.local_ip6, - self.pg0.remote_ip6, + self.cli_str, + self.src_ip6_net, + self.dst_ip6_net, mod_session.desired_min_tx, mod_session.required_min_rx, mod_session.detect_mult, ) ) verify_bfd_session_config(self, mod_session) - cli_del_cmd = ( - "bfd udp session del interface %s local-addr %s " - "peer-addr %s" % (self.pg0.name, self.pg0.local_ip6, self.pg0.remote_ip6) + cli_del_cmd = "bfd udp session del %s local-addr %s peer-addr %s" % ( + self.cli_str, + self.src_ip6_net, + self.dst_ip6_net, ) self.cli_verify_no_response(cli_del_cmd) # 2nd del is expected to fail @@ -3105,18 +3875,29 @@ class BFDCLITestCase(VppTestCase): self, auth_type=BFDAuthType.meticulous_keyed_sha1 ) key.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) auth_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) session.add_vpp_config() cli_activate = ( - "bfd udp session auth activate interface %s local-addr %s " + "bfd udp session auth activate %s local-addr %s " "peer-addr %s conf-key-id %s bfd-key-id %s" % ( - self.pg0.name, - self.pg0.local_ip4, - self.pg0.remote_ip4, + self.cli_str, + self.src_ip_net, + self.dst_ip_net, key.conf_key_id, auth_session.bfd_key_id, ) @@ -3126,32 +3907,106 @@ class BFDCLITestCase(VppTestCase): self.cli_verify_no_response(cli_activate) verify_bfd_session_config(self, auth_session) cli_deactivate = ( - "bfd udp session auth deactivate interface %s local-addr %s " - "peer-addr %s " % (self.pg0.name, self.pg0.local_ip4, self.pg0.remote_ip4) + "bfd udp session auth deactivate %s local-addr %s " + "peer-addr %s" % (self.cli_str, self.src_ip_net, self.dst_ip_net) ) self.cli_verify_no_response(cli_deactivate) verify_bfd_session_config(self, session) self.cli_verify_no_response(cli_deactivate) verify_bfd_session_config(self, session) + if self.multihop: + # specifying multihop and interface should fail + cli_activate = ( + "bfd udp session auth activate multihop interface %s " + "local-addr %s peer-addr %s conf-key-id %s bfd-key-id %s" + % ( + self.pg0.name, + self.src_ip_net, + self.dst_ip_net, + key.conf_key_id, + auth_session.bfd_key_id, + ) + ) + self.cli_verify_response( + cli_activate, + "bfd udp session auth activate: Incompatible parameter " + "combination, interface cannot be specified when multihop " + "is enabled", + ) + cli_deactivate = ( + "bfd udp session auth deactivate multihop interface %s " + "local-addr %s peer-addr %s" + % ( + self.pg0.name, + self.src_ip_net, + self.dst_ip_net, + ) + ) + self.cli_verify_response( + cli_deactivate, + "bfd udp session auth deactivate: Incompatible parameter " + "combination, interface cannot be specified when multihop " + "is enabled", + ) + # Not specifying multihop or interface should fail + cli_activate = ( + "bfd udp session auth activate local-addr %s peer-addr %s " + "conf-key-id %s bfd-key-id %s" + % ( + self.src_ip_net, + self.dst_ip_net, + key.conf_key_id, + auth_session.bfd_key_id, + ) + ) + self.cli_verify_response( + cli_activate, + "bfd udp session auth activate: Incompatible parameter " + "combination, interface must be set if not multihop", + ) + cli_deactivate = ( + "bfd udp session auth deactivate local-addr %s peer-addr %s " + % ( + self.src_ip_net, + self.dst_ip_net, + ) + ) + self.cli_verify_response( + cli_deactivate, + "bfd udp session auth deactivate: Incompatible parameter " + "combination, interface must be set if not multihop", + ) + def test_auth_on_off_delayed(self): """turn authentication on and off (delayed)""" key = self.factory.create_random_key( self, auth_type=BFDAuthType.meticulous_keyed_sha1 ) key.add_vpp_config() - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) auth_session = VppBFDUDPSession( - self, self.pg0, self.pg0.remote_ip4, sha1_key=key + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + sha1_key=key, ) session.add_vpp_config() cli_activate = ( - "bfd udp session auth activate interface %s local-addr %s " + "bfd udp session auth activate %s local-addr %s " "peer-addr %s conf-key-id %s bfd-key-id %s delayed yes" % ( - self.pg0.name, - self.pg0.local_ip4, - self.pg0.remote_ip4, + self.cli_str, + self.src_ip_net, + self.dst_ip_net, key.conf_key_id, auth_session.bfd_key_id, ) @@ -3161,9 +4016,9 @@ class BFDCLITestCase(VppTestCase): self.cli_verify_no_response(cli_activate) verify_bfd_session_config(self, auth_session) cli_deactivate = ( - "bfd udp session auth deactivate interface %s local-addr %s " + "bfd udp session auth deactivate %s local-addr %s " "peer-addr %s delayed yes" - % (self.pg0.name, self.pg0.local_ip4, self.pg0.remote_ip4) + % (self.cli_str, self.src_ip_net, self.dst_ip_net) ) self.cli_verify_no_response(cli_deactivate) verify_bfd_session_config(self, session) @@ -3172,23 +4027,66 @@ class BFDCLITestCase(VppTestCase): def test_admin_up_down(self): """put session admin-up and admin-down""" - session = VppBFDUDPSession(self, self.pg0, self.pg0.remote_ip4) + session = VppBFDUDPSession( + self, + self.pg0, + self.dst_ip_net, + local_addr=self.src_ip_net, + multihop=self.multihop, + ) session.add_vpp_config() cli_down = ( - "bfd udp session set-flags admin down interface %s local-addr %s " - "peer-addr %s " % (self.pg0.name, self.pg0.local_ip4, self.pg0.remote_ip4) + "bfd udp session set-flags admin down %s local-addr %s " + "peer-addr %s " % (self.cli_str, self.src_ip_net, self.dst_ip_net) ) cli_up = ( - "bfd udp session set-flags admin up interface %s local-addr %s " - "peer-addr %s " % (self.pg0.name, self.pg0.local_ip4, self.pg0.remote_ip4) + "bfd udp session set-flags admin up %s local-addr %s " + "peer-addr %s " % (self.cli_str, self.src_ip_net, self.dst_ip_net) ) self.cli_verify_no_response(cli_down) verify_bfd_session_config(self, session, state=BFDState.admin_down) self.cli_verify_no_response(cli_up) verify_bfd_session_config(self, session, state=BFDState.down) + if self.multihop: + # specifying multihop and interface should fail + cli_up = ( + "bfd udp session set-flags admin up multihop interface %s " + "local-addr %s peer-addr %s" + % ( + self.pg0.name, + self.src_ip_net, + self.dst_ip_net, + ) + ) + self.cli_verify_response( + cli_up, + "bfd udp session set-flags: Incompatible parameter " + "combination, interface cannot be specified when multihop " + "is enabled", + ) + # Not specifying multihop or interface should fail + cli_up = ( + "bfd udp session set-flags admin up local-addr %s peer-addr %s " + % ( + self.src_ip_net, + self.dst_ip_net, + ) + ) + self.cli_verify_response( + cli_up, + "bfd udp session set-flags: Incompatible parameter " + "combination, interface must be set if not multihop", + ) + def test_set_del_udp_echo_source(self): """set/del udp echo source""" + + if self.multihop: + self.skipTest( + f"Skipping because echo functionality is not supported with multihop" + ) + self.create_loopback_interfaces(1) self.loopback0 = self.lo_interfaces[0] self.loopback0.admin_up() -- cgit 1.2.3-korg