From patchwork Fri Feb 5 07:00:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1436464 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DX5t92lp8z9sWg for ; Fri, 5 Feb 2021 18:01:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D00A12E105; Fri, 5 Feb 2021 07:01:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ER6hHl+qGhS7; Fri, 5 Feb 2021 07:00:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id A02C22E10B; Fri, 5 Feb 2021 07:00:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 83EC2C08A1; Fri, 5 Feb 2021 07:00:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 47BA8C0174 for ; Fri, 5 Feb 2021 07:00:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 37D2E872BD for ; Fri, 5 Feb 2021 07:00:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eANaAo877weg for ; Fri, 5 Feb 2021 07:00:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by hemlock.osuosl.org (Postfix) with ESMTPS id AE86D872EF for ; Fri, 5 Feb 2021 07:00:42 +0000 (UTC) X-Originating-IP: 115.99.223.251 Received: from nusiddiq.home.org.com (unknown [115.99.223.251]) (Authenticated sender: numans@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 151102000A; Fri, 5 Feb 2021 07:00:37 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Fri, 5 Feb 2021 12:30:33 +0530 Message-Id: <20210205070033.40429-1-numans@ovn.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210205065622.39226-1-numans@ovn.org> References: <20210205065622.39226-1-numans@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 6/6] northd: Cleanup stale FDB entries. 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" From: Numan Siddique Signed-off-by: Numan Siddique --- lib/ovn-util.c | 20 ++++++++++++--- lib/ovn-util.h | 1 + northd/ovn-northd.c | 40 ++++++++++++++++++++++++++++++ tests/ovn-northd.at | 60 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 4 deletions(-) diff --git a/lib/ovn-util.c b/lib/ovn-util.c index b6471063ef..8f6719471d 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -580,18 +580,30 @@ ovn_destroy_tnlids(struct hmap *tnlids) hmap_destroy(tnlids); } +/* Returns true if 'tnlid' is present in the hmap 'tnlids'. */ bool -ovn_add_tnlid(struct hmap *set, uint32_t tnlid) +ovn_tnlid_present(struct hmap *tnlids, uint32_t tnlid) { uint32_t hash = hash_int(tnlid, 0); struct tnlid_node *node; - HMAP_FOR_EACH_IN_BUCKET (node, hmap_node, hash, set) { + HMAP_FOR_EACH_IN_BUCKET (node, hmap_node, hash, tnlids) { if (node->tnlid == tnlid) { - return false; + return true; } } - node = xmalloc(sizeof *node); + return false; +} + +bool +ovn_add_tnlid(struct hmap *set, uint32_t tnlid) +{ + if (ovn_tnlid_present(set, tnlid)) { + return false; + } + + uint32_t hash = hash_int(tnlid, 0); + struct tnlid_node *node = xmalloc(sizeof *node); hmap_insert(set, &node->hmap_node, hash); node->tnlid = tnlid; return true; diff --git a/lib/ovn-util.h b/lib/ovn-util.h index df4b0bc989..40ecafe57e 100644 --- a/lib/ovn-util.h +++ b/lib/ovn-util.h @@ -126,6 +126,7 @@ void ovn_conn_show(struct unixctl_conn *conn, int argc OVS_UNUSED, struct hmap; void ovn_destroy_tnlids(struct hmap *tnlids); bool ovn_add_tnlid(struct hmap *set, uint32_t tnlid); +bool ovn_tnlid_present(struct hmap *tnlids, uint32_t tnlid); uint32_t ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min, uint32_t max, uint32_t *hint); diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 23c26de36f..7b6f86802a 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -851,6 +851,20 @@ ovn_datapath_find(struct hmap *datapaths, const struct uuid *uuid) return NULL; } +static struct ovn_datapath * +ovn_datapath_find_by_key(struct hmap *datapaths, uint32_t dp_key) +{ + struct ovn_datapath *od; + + HMAP_FOR_EACH (od, key_node, datapaths) { + if (od->tunnel_key == dp_key) { + return od; + } + } + + return NULL; +} + static bool ovn_datapath_is_stale(const struct ovn_datapath *od) { @@ -3144,6 +3158,26 @@ cleanup_sb_ha_chassis_groups(struct northd_context *ctx, } } +static void +cleanup_stale_fdp_entries(struct northd_context *ctx, struct hmap *datapaths) +{ + const struct sbrec_fdb *fdb_e, *next; + SBREC_FDB_FOR_EACH_SAFE (fdb_e, next, ctx->ovnsb_idl) { + bool delete = true; + struct ovn_datapath *od + = ovn_datapath_find_by_key(datapaths, fdb_e->dp_key); + if (od) { + if (ovn_tnlid_present(&od->port_tnlids, fdb_e->port_key)) { + delete = false; + } + } + + if (delete) { + sbrec_fdb_delete(fdb_e); + } + } +} + struct service_monitor_info { struct hmap_node hmap_node; const struct sbrec_service_monitor *sbrec_mon; @@ -12714,6 +12748,7 @@ ovnnb_db_run(struct northd_context *ctx, sync_port_groups(ctx, &port_groups); sync_meters(ctx, datapaths, &meter_groups, &port_groups); sync_dns_entries(ctx, datapaths); + cleanup_stale_fdp_entries(ctx, datapaths); struct ovn_northd_lb *lb; HMAP_FOR_EACH_POP (lb, hmap_node, &lbs) { @@ -13701,6 +13736,11 @@ main(int argc, char *argv[]) ovsdb_idl_add_column(ovnsb_idl_loop.idl, &sbrec_bfd_col_disc); ovsdb_idl_add_column(ovnsb_idl_loop.idl, &sbrec_bfd_col_src_port); + ovsdb_idl_add_table(ovnsb_idl_loop.idl, &sbrec_table_fdb); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_fdb_col_mac); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_fdb_col_dp_key); + add_column_noalert(ovnsb_idl_loop.idl, &sbrec_fdb_col_port_key); + struct ovsdb_idl_index *sbrec_chassis_by_name = chassis_index_create(ovnsb_idl_loop.idl); diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index 1b4160cfa0..76634043cc 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -2443,3 +2443,63 @@ check ovn-sbctl set chassis hv1 other_config:port-up-notif=true wait_row_count nb:Logical_Switch_Port 1 up=false name=lsp1 AT_CLEANUP + +AT_SETUP([ovn -- FDB cleanup]) + +ovn_start + +ovn-nbctl ls-add sw0 +ovn-nbctl lsp-add sw0 sw0-p1 +ovn-nbctl lsp-add sw0 sw0-p2 +ovn-nbctl lsp-add sw0 sw0-p3 + +ovn-nbctl ls-add sw1 +ovn-nbctl lsp-add sw1 sw1-p1 +ovn-nbctl lsp-add sw1 sw1-p2 +ovn-nbctl --wait=sb lsp-add sw1 sw1-p3 + +sw0_key=$(fetch_column datapath_binding tunnel_key external_ids:name=sw0) +sw1_key=$(fetch_column datapath_binding tunnel_key external_ids:name=sw1) +sw0p1_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p1) +sw0p2_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p2) +sw1p1_key=$(fetch_column port_binding tunnel_key logical_port=sw1-p1) + +ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:01" dp_key=$sw0_key port_key=$sw0p1_key +ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:02" dp_key=$sw0_key port_key=$sw0p1_key +ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:03" dp_key=$sw0_key port_key=$sw0p2_key +ovn-sbctl create FDB mac="00\:00\:00\:00\:01\:01" dp_key=$sw1_key port_key=$sw1p1_key +ovn-sbctl create FDB mac="00\:00\:00\:00\:01\:02" dp_key=$sw1_key port_key=$sw1p1_key +ovn-sbctl create FDB mac="00\:00\:00\:00\:01\:03" dp_key=$sw1_key port_key=$sw1p1_key + +wait_row_count FDB 6 + +ovn-sbctl create fdb mac="00\:00\:00\:00\:01\:03" dp_key=$sw1_key port_key=10 +wait_row_count FDB 6 +ovn-sbctl create fdb mac="00\:00\:00\:00\:01\:03" dp_key=4 port_key=10 +wait_row_count FDB 6 + +ovn-nbctl --wait=sb ls-del sw1 +wait_row_count FDB 3 + +ovn-nbctl lsp-del sw0-p3 +wait_row_count FDB 3 + +ovn-nbctl lsp-del sw0-p1 +wait_row_count FDB 1 + +check_column '00:00:00:00:00:03' FDB mac +ovn-sbctl list fdb + +check_column $sw0_key FDB dp_key +check_column $sw0p2_key FDB port_key + +ovn-nbctl --wait=sb lsp-add sw0-p1 +wait_row_count FDB 1 + +ovn-nbctl lsp-del sw0-p2 +ovn-nbctl lsp-add sw0-p2 +wait_row_count FDB 0 + +ovn-sbctl list FDB + +AT_CLEANUP