From 97b58dde0f92fc83165a6db816456073f5ddf727 Mon Sep 17 00:00:00 2001 Message-Id: <97b58dde0f92fc83165a6db816456073f5ddf727.1612349784.git.lorenzo.bianconi@redhat.com> From: Lorenzo Bianconi Date: Fri, 29 Jan 2021 23:45:19 +0100 Subject: [PATCH] ovn-nbctl: add --bfd option to lr-route-add Introduce the --bfd option to lr-route-add command. If the BFD session UUID is provided, it will be used for the OVN route otherwise the next-hop will be used to perform a lookup in the OVN BFD table. If the lookup fails and outport is specified, a new entry in the BFD table will be created using the nexthop as dst_ip and outport as logical_port. Signed-off-by: Lorenzo Bianconi Signed-off-by: Numan Siddique --- tests/ovn-northd.at | 17 ++++++++++---- tests/system-ovn.at | 5 ++-- utilities/ovn-nbctl.8.xml | 11 +++++++++ utilities/ovn-nbctl.c | 49 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 9 deletions(-) --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -2342,7 +2342,7 @@ AT_KEYWORDS([northd-bfd]) ovn_start check ovn-nbctl --wait=sb lr-add r0 -for i in $(seq 1 4); do +for i in $(seq 1 5); do check ovn-nbctl --wait=sb lrp-add r0 r0-sw$i 00:00:00:00:00:0$i 192.168.$i.1/24 check ovn-nbctl --wait=sb ls-add sw$i check ovn-nbctl --wait=sb lsp-add sw$i sw$i-r0 @@ -2387,17 +2387,24 @@ check_column 1000 bfd min_tx logical_por check_column 1000 bfd min_rx logical_port=r0-sw1 check_column 100 bfd detect_mult logical_port=r0-sw1 -check ovn-nbctl lr-route-add r0 100.0.0.0/8 192.168.10.2 -route_uuid=$(fetch_column nb:logical_router_static_route _uuid ip_prefix="100.0.0.0/8") -check ovn-nbctl set logical_router_static_route $route_uuid bfd=$uuid +check ovn-nbctl --bfd=$uuid lr-route-add r0 100.0.0.0/8 192.168.10.2 check_column down bfd status logical_port=r0-sw1 AT_CHECK([ovn-nbctl lr-route-list r0 | grep 192.168.10.2 | grep -q bfd],[0]) +check ovn-nbctl --bfd lr-route-add r0 200.0.0.0/8 192.168.20.2 +check_column down bfd status logical_port=r0-sw2 +AT_CHECK([ovn-nbctl lr-route-list r0 | grep 192.168.20.2 | grep -q bfd],[0]) + +check ovn-nbctl --bfd lr-route-add r0 240.0.0.0/8 192.168.50.2 r0-sw5 +check_column down bfd status logical_port=r0-sw5 +AT_CHECK([ovn-nbctl lr-route-list r0 | grep 192.168.50.2 | grep -q bfd],[0]) + +route_uuid=$(fetch_column nb:logical_router_static_route _uuid ip_prefix="100.0.0.0/8") check ovn-nbctl clear logical_router_static_route $route_uuid bfd check_column admin_down bfd status logical_port=r0-sw1 ovn-nbctl destroy bfd $uuid -check_row_count bfd 2 +check_row_count bfd 3 AT_CLEANUP --- a/tests/system-ovn.at +++ b/tests/system-ovn.at @@ -5606,10 +5606,9 @@ NS_CHECK_EXEC([server], [bfdd-control al Allowing connections from 172.16.1.1 ]) -uuid=$(ovn-nbctl create bfd logical_port=rp-public dst_ip=172.16.1.50 min_tx=250 min_rx=250 detect_mult=10) -check ovn-nbctl lr-route-add R1 100.0.0.0/8 172.16.1.50 +check ovn-nbctl --bfd lr-route-add R1 100.0.0.0/8 172.16.1.50 rp-public +uuid=$(fetch_column nb:bfd _uuid logical_port="rp-public") route_uuid=$(fetch_column nb:logical_router_static_route _uuid ip_prefix="100.0.0.0/8") -check ovn-nbctl set logical_router_static_route $route_uuid bfd=$uuid check ovn-nbctl --wait=hv sync wait_column "up" nb:bfd status logical_port=rp-public --- a/utilities/ovn-nbctl.8.xml +++ b/utilities/ovn-nbctl.8.xml @@ -659,6 +659,7 @@
[--may-exist] [--policy=POLICY] [--ecmp] [--ecmp-symmetric-reply] + [--bfd[=UUID]] lr-route-add router prefix nexthop [port]
@@ -696,6 +697,16 @@

+ --bfd option is used to link a BFD session to the + OVN route. If the BFD session UUID is provided, it will be used + for the OVN route otherwise the next-hop will be used to perform + a lookup in the OVN BFD table. + If the lookup fails and port is specified, a new entry + in the BFD table will be created using the nexthop as + dst_ip and port as logical_port. +

+ +

It is an error if a route with prefix and POLICY already exists, unless --may-exist, --ecmp, or --ecmp-symmetric-reply is --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -3957,6 +3957,29 @@ nbctl_lr_route_add(struct ctl_context *c goto cleanup; } + struct shash_node *bfd = shash_find(&ctx->options, "--bfd"); + const struct nbrec_bfd *nb_bt = NULL; + if (bfd) { + if (bfd->data) { + struct uuid bfd_uuid; + if (uuid_from_string(&bfd_uuid, bfd->data)) { + nb_bt = nbrec_bfd_get_for_uuid(ctx->idl, &bfd_uuid); + } + if (!nb_bt) { + ctl_error(ctx, "no entry found in the BFD table"); + goto cleanup; + } + } else { + const struct nbrec_bfd *iter; + NBREC_BFD_FOR_EACH (iter, ctx->idl) { + if (!strcmp(iter->dst_ip, next_hop)) { + nb_bt = iter; + break; + } + } + } + } + bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; bool ecmp_symmetric_reply = shash_find(&ctx->options, "--ecmp-symmetric-reply") != NULL; @@ -4011,6 +4034,18 @@ nbctl_lr_route_add(struct ctl_context *c if (policy) { nbrec_logical_router_static_route_set_policy(route, policy); } + if (bfd) { + if (!nb_bt) { + if (ctx->argc != 5) { + ctl_error(ctx, "insert entry in the BFD table failed"); + goto cleanup; + } + nb_bt = nbrec_bfd_insert(ctx->txn); + nbrec_bfd_set_dst_ip(nb_bt, next_hop); + nbrec_bfd_set_logical_port(nb_bt, ctx->argv[4]); + } + nbrec_logical_router_static_route_set_bfd(route, nb_bt); + } free(rt_prefix); goto cleanup; } @@ -4035,6 +4070,18 @@ nbctl_lr_route_add(struct ctl_context *c } nbrec_logical_router_update_static_routes_addvalue(lr, route); + if (bfd) { + if (!nb_bt) { + if (ctx->argc != 5) { + ctl_error(ctx, "insert entry in the BFD table failed"); + goto cleanup; + } + nb_bt = nbrec_bfd_insert(ctx->txn); + nbrec_bfd_set_dst_ip(nb_bt, next_hop); + nbrec_bfd_set_logical_port(nb_bt, ctx->argv[4]); + } + nbrec_logical_router_static_route_set_bfd(route, nb_bt); + } cleanup: free(next_hop); @@ -6548,7 +6595,7 @@ static const struct ctl_command_syntax n /* logical router route commands. */ { "lr-route-add", 3, 4, "ROUTER PREFIX NEXTHOP [PORT]", NULL, nbctl_lr_route_add, NULL, "--may-exist,--ecmp,--ecmp-symmetric-reply," - "--policy=", RW }, + "--policy=,--bfd?", RW }, { "lr-route-del", 1, 4, "ROUTER [PREFIX [NEXTHOP [PORT]]]", NULL, nbctl_lr_route_del, NULL, "--if-exists,--policy=", RW }, { "lr-route-list", 1, 1, "ROUTER", NULL, nbctl_lr_route_list, NULL,