From patchwork Thu Dec 15 17:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Odintsov X-Patchwork-Id: 1716214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TcrfpjC+; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NXz891C6gz2403 for ; Fri, 16 Dec 2022 04:03:21 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 6AAD46107D; Thu, 15 Dec 2022 17:03:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 6AAD46107D Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TcrfpjC+ X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oSrZg7bzvdf1; Thu, 15 Dec 2022 17:03:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5C8E46105C; Thu, 15 Dec 2022 17:03:17 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5C8E46105C Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DE4ACC0035; Thu, 15 Dec 2022 17:03:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 50100C002D for ; Thu, 15 Dec 2022 17:03:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 87DBA61076 for ; Thu, 15 Dec 2022 17:02:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 87DBA61076 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MLqXrxpQQjlI for ; Thu, 15 Dec 2022 17:02:43 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4E5246106F Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4E5246106F for ; Thu, 15 Dec 2022 17:02:43 +0000 (UTC) Received: by mail-wr1-x433.google.com with SMTP id h7so3764949wrs.6 for ; Thu, 15 Dec 2022 09:02:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/0FCgq37J0KJIFTc4tV69Tf7q/FXzaV16M0B3YFyT5c=; b=TcrfpjC+UnempR2dAvxNx5rK7KPP9SFIn8tjTz2Mx+l46TAv3iuUbXnFAY6gwzfiY7 efwdQQh4lKHG/7qnrG9oiQzGLFzohpA6iz/9Im+QbLL9xirkASTzT7KrW09/TqhzmeNP cGL6Y24Cd+O9YUf15sJ/ty3/zWSimVwcThh8LUGtES4vFlFhfQ7sT2LSwnEs9q4PsNwo fZuync8/FLcSoTZojeHYfNk9GA9bco6aBEKP9GdI6HqaZ/TXQWI15b0R7bNY/k5f+JFr 05seMkjP94cH79H57sQVs10bDWgxZkbgzQqxCgCvjB9QMrVI0wiTeniheUHCoJJI59ti 4HuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/0FCgq37J0KJIFTc4tV69Tf7q/FXzaV16M0B3YFyT5c=; b=sdqu7/sIF+jPEeCkNpdMR54meMFzpO2dq7RniUSguoU+6QRaNJPbrVvZYuuArYCKKa OvX7Qq3j5VzQz8KOxYMWItlJAi+pffgzhN8c/LskpJu3AQ5M3FduytZOoOnzocte34uU vjGdgploL4H57Su8aBOXAzVg4+39d/R0U/bSRw2FCWrxBG4sG04rytKNVwPoT4LVXSjP Tzfyxksfzhve+GcMYvGW33eZvi2vDIpdPbCBPsltxX215gzh2wm0xs/z4iGfPDo9Ohfi SeflXV/FobpKV4VDZy1Xs4bTG5xhvsqMelk/dYfdm5KW8I7Z6kwWSNbR8JKNtVofaJqS evRg== X-Gm-Message-State: ANoB5pkzgRX88u5zW8nfBLfBbgPTKMThSLeomkf4LEpVoIFYt0D/V1Zf nlz7qIiIuV8Oy9SQsTS3aAZHXDY9VEZzJRGt X-Google-Smtp-Source: AA0mqf4EMZBIdU8wBMUC1vW7bCxhf3qRnglio5ULu6XnKj3MKg1yMEwqOtfJlgv6Jqr1Lk6WJyOwqA== X-Received: by 2002:adf:f14c:0:b0:24f:dbcd:7726 with SMTP id y12-20020adff14c000000b0024fdbcd7726mr11819249wro.5.1671123762574; Thu, 15 Dec 2022 09:02:42 -0800 (PST) Received: from ip-10-70-112-12.vpc-1e810be1.internal (c2-178-216-98-9.elastic.cloud.croc.ru. [178.216.98.9]) by smtp.gmail.com with ESMTPSA id q6-20020adff506000000b0022e57e66824sm7429148wro.99.2022.12.15.09.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 09:02:42 -0800 (PST) From: Vladislav Odintsov To: dev@openvswitch.org Date: Thu, 15 Dec 2022 20:02:17 +0300 Message-Id: <20221215170219.3072151-4-odivlad@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221215170219.3072151-1-odivlad@gmail.com> References: <20221215170219.3072151-1-odivlad@gmail.com> MIME-Version: 1.0 Cc: Vladislav Odintsov Subject: [ovs-dev] [PATCH ovn v3 3/5] ic: prevent advertising/learning multiple same routes X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Advertize one route (ip_prefix, nexthop, route_table, transit_switch, availability_zone) only once. Signed-off-by: Vladislav Odintsov --- ic/ovn-ic.c | 84 ++++++++++++++++++++++++++++++------------------- tests/ovn-ic.at | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 33 deletions(-) diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c index 0d5e5f5d9..518796149 100644 --- a/ic/ovn-ic.c +++ b/ic/ovn-ic.c @@ -884,10 +884,12 @@ ic_route_hash(const struct in6_addr *prefix, unsigned int plen, static struct ic_route_info * ic_route_find(struct hmap *routes, const struct in6_addr *prefix, unsigned int plen, const struct in6_addr *nexthop, - const char *origin, char *route_table) + const char *origin, const char *route_table, uint32_t hash) { struct ic_route_info *r; - uint32_t hash = ic_route_hash(prefix, plen, nexthop, origin, route_table); + if (!hash) { + hash = ic_route_hash(prefix, plen, nexthop, origin, route_table); + } HMAP_FOR_EACH_WITH_HASH (r, node, hash, routes) { if (ipv6_addr_equals(&r->prefix, prefix) && r->plen == plen && @@ -945,8 +947,8 @@ add_to_routes_learned(struct hmap *routes_learned, } const char *origin = smap_get_def(&nb_route->options, "origin", ""); if (ic_route_find(routes_learned, &prefix, plen, &nexthop, origin, - nb_route->route_table)) { - /* Route is already added to learned in previous iteration. */ + nb_route->route_table, 0)) { + /* Route was added to learned on previous iteration. */ return true; } @@ -1093,10 +1095,43 @@ route_need_advertise(const char *policy, } static void -add_to_routes_ad(struct hmap *routes_ad, - const struct nbrec_logical_router_static_route *nb_route, - const struct lport_addresses *nexthop_addresses, - const struct smap *nb_options, const char *route_table) +add_to_routes_ad(struct hmap *routes_ad, const struct in6_addr prefix, + unsigned int plen, const struct in6_addr nexthop, + const char *origin, const char *route_table, + const struct nbrec_logical_router_port *nb_lrp, + const struct nbrec_logical_router_static_route *nb_route) +{ + if (route_table == NULL) { + route_table = ""; + } + + uint hash = ic_route_hash(&prefix, plen, &nexthop, origin, route_table); + + if (!ic_route_find(routes_ad, &prefix, plen, &nexthop, origin, route_table, + hash)) { + struct ic_route_info *ic_route = xzalloc(sizeof *ic_route); + ic_route->prefix = prefix; + ic_route->plen = plen; + ic_route->nexthop = nexthop; + ic_route->nb_route = nb_route; + ic_route->origin = origin; + ic_route->route_table = route_table; + ic_route->nb_lrp = nb_lrp; + hmap_insert(routes_ad, &ic_route->node, hash); + } else { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "Duplicate route advertisement was suppressed! NB " + "route uuid: "UUID_FMT, + UUID_ARGS(&nb_route->header_.uuid)); + } +} + +static void +add_static_to_routes_ad( + struct hmap *routes_ad, + const struct nbrec_logical_router_static_route *nb_route, + const struct lport_addresses *nexthop_addresses, + const struct smap *nb_options, const char *route_table) { if (strcmp(route_table, nb_route->route_table)) { if (VLOG_IS_DBG_ENABLED()) { @@ -1145,16 +1180,8 @@ add_to_routes_ad(struct hmap *routes_ad, ds_destroy(&msg); } - struct ic_route_info *ic_route = xzalloc(sizeof *ic_route); - ic_route->prefix = prefix; - ic_route->plen = plen; - ic_route->nexthop = nexthop; - ic_route->nb_route = nb_route; - ic_route->origin = ROUTE_ORIGIN_STATIC; - ic_route->route_table = nb_route->route_table; - hmap_insert(routes_ad, &ic_route->node, - ic_route_hash(&prefix, plen, &nexthop, ROUTE_ORIGIN_STATIC, - nb_route->route_table)); + add_to_routes_ad(routes_ad, prefix, plen, nexthop, ROUTE_ORIGIN_STATIC, + nb_route->route_table, NULL, nb_route); } static void @@ -1198,18 +1225,9 @@ add_network_to_routes_ad(struct hmap *routes_ad, const char *network, ds_destroy(&msg); } - struct ic_route_info *ic_route = xzalloc(sizeof *ic_route); - ic_route->prefix = prefix; - ic_route->plen = plen; - ic_route->nexthop = nexthop; - ic_route->nb_lrp = nb_lrp; - ic_route->origin = ROUTE_ORIGIN_CONNECTED; - /* directly-connected routes go to
route table */ - ic_route->route_table = NULL; - hmap_insert(routes_ad, &ic_route->node, - ic_route_hash(&prefix, plen, &nexthop, - ROUTE_ORIGIN_CONNECTED, "")); + add_to_routes_ad(routes_ad, prefix, plen, nexthop, ROUTE_ORIGIN_CONNECTED, + NULL, nb_lrp, NULL); } static bool @@ -1369,7 +1387,7 @@ sync_learned_routes(struct ic_context *ctx, struct ic_route_info *route_learned = ic_route_find(&ic_lr->routes_learned, &prefix, plen, &nexthop, isb_route->origin, - isb_route->route_table); + isb_route->route_table, 0); if (route_learned) { /* Sync external-ids */ struct uuid ext_id; @@ -1468,7 +1486,7 @@ advertise_routes(struct ic_context *ctx, } struct ic_route_info *route_adv = ic_route_find(routes_ad, &prefix, plen, &nexthop, - isb_route->origin, isb_route->route_table); + isb_route->origin, isb_route->route_table, 0); if (!route_adv) { /* Delete the extra route from IC-SB. */ VLOG_DBG("Delete route %s -> %s from IC-SB, which is not found" @@ -1550,8 +1568,8 @@ build_ts_routes_to_adv(struct ic_context *ctx, } } else { /* It may be a route to be advertised */ - add_to_routes_ad(routes_ad, nb_route, ts_port_addrs, - &nb_global->options, ts_route_table); + add_static_to_routes_ad(routes_ad, nb_route, ts_port_addrs, + &nb_global->options, ts_route_table); } } diff --git a/tests/ovn-ic.at b/tests/ovn-ic.at index e234b7fb9..ceee45092 100644 --- a/tests/ovn-ic.at +++ b/tests/ovn-ic.at @@ -194,6 +194,66 @@ OVN_CLEANUP_IC AT_CLEANUP ]) +OVN_FOR_EACH_NORTHD([ +AT_SETUP([ovn-ic -- duplicate NB route adv/learn]) + +ovn_init_ic_db +net_add n1 + +# 1 GW per AZ +for i in 1 2; do + az=az$i + ovn_start $az + sim_add gw-$az + as gw-$az + check ovs-vsctl add-br br-phys + ovn_az_attach $az n1 br-phys 192.168.1.$i + check ovs-vsctl set open . external-ids:ovn-is-interconn=true + check ovn-nbctl set nb-global . \ + options:ic-route-adv=true \ + options:ic-route-adv-default=true \ + options:ic-route-learn=true \ + options:ic-route-learn-default=true +done + +ovn_as az1 + +# create transit switch and connect to LR +check ovn-ic-nbctl ts-add ts1 +for i in 1 2; do + ovn_as az$i + + check ovn-nbctl lr-add lr1 + check ovn-nbctl lrp-add lr1 lrp$i 00:00:00:00:0$i:01 10.0.$i.1/24 + check ovn-nbctl lrp-set-gateway-chassis lrp$i gw-az$i + + check ovn-nbctl lsp-add ts1 lsp$i -- \ + lsp-set-addresses lsp$i router -- \ + lsp-set-type lsp$i router -- \ + lsp-set-options lsp$i router-port=lrp$i +done + +ovn_as az1 + +ovn-nbctl \ + --id=@id create logical-router-static-route ip_prefix=1.1.1.1/32 nexthop=10.0.1.10 -- \ + add logical-router lr1 static_routes @id +ovn-nbctl \ + --id=@id create logical-router-static-route ip_prefix=1.1.1.1/32 nexthop=10.0.1.10 -- \ + add logical-router lr1 static_routes @id + +wait_row_count ic-sb:route 1 ip_prefix=1.1.1.1/32 + +for i in 1 2; do + az=az$i + OVN_CLEANUP_SBOX(gw-$az) + OVN_CLEANUP_AZ([$az]) +done + +OVN_CLEANUP_IC +AT_CLEANUP +]) + OVN_FOR_EACH_NORTHD([ AT_SETUP([ovn-ic -- gateway sync])