From patchwork Fri Jul 29 11:16:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: miter X-Patchwork-Id: 1661986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=Q4q3KYa1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LvQ2l6PmPz9sGC for ; Fri, 29 Jul 2022 21:17:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1988784001; Fri, 29 Jul 2022 11:17:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1988784001 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=Q4q3KYa1 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N-UVARuLqnbo; Fri, 29 Jul 2022 11:17:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 3677C83FFB; Fri, 29 Jul 2022 11:16:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 3677C83FFB Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E5D4FC0035; Fri, 29 Jul 2022 11:16:58 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id DEAAFC002D for ; Fri, 29 Jul 2022 11:16:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 90AAB83FFB for ; Fri, 29 Jul 2022 11:16:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 90AAB83FFB X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mDmaz3qpP5PM for ; Fri, 29 Jul 2022 11:16:53 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 8DAA483FF8 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2173.outbound.protection.outlook.com [40.92.63.173]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8DAA483FF8 for ; Fri, 29 Jul 2022 11:16:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2GyWwiaxL/DAhrayJGbwkuw9RZBvCwSmK08kZEEJKO1Q4SATiCReQO8Qgo8vja2aaqo6ngtbD0FFBMz0AMocC7cFdMc6o0CF8X97RdYKemgpIYNV73R0mNSlLfQcqaWRVYcx4YNfhb0rOMPKzTT8UgnFfI0fFcEZBdN5tRjDSfQO/I/vvacV4qSSG6G42FVdtkc47xYNXcOx5/rgfttcNEVOfucUa1shbUZ2IggBReUYHETalv6piEd45yLDAQD2J2c2LyeKF5f7tefaS8um81FJ939SNH/ZFVQk5hMF/PYbG74OJ8aA7MPgdGLZ0pD4gNAbGVzfy+W5gxbeDm72w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=S9bdGl76cMukF1MBKYwX1DWOdk87y2esaKz3pJz2zD0=; b=hNXpLJUWnTp62lTYWO9YVjOmBO/kcJI/6FWZKqw00HDI2GBY9HHMcezCeqsjYvgdWaNAE9DHrKpD/zLNhWUqywrbqkyWPuh/YWZXEwqdF0WxzNyJbndZxrsmi574hJWsZixEny7UKs+61qzdR0vZZY64yJ0uW3B39AF4/X0F4lHzBHCLn7KgAjSXcQ05WhcthMWkUo0j8Re+k1EkeyyZ0WgRFQ0R+md8s12hM8ti26QmjhqofW7Sk9QpVAr0jDoeoHsfU2Ke9DhERC5huz06SAIyJWeKU4zK0HQYbqntP62O+HB5BPiOgQXGC2YtLbUmMqq98wEoS2Xiz1o10z1Qpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S9bdGl76cMukF1MBKYwX1DWOdk87y2esaKz3pJz2zD0=; b=Q4q3KYa1JTgyCq5cpnlHpWgIZHECGoe9vnarydsKSxhNFKOdj6EuPqx75LFXZHJ8AJfTyCrcE6zxXnXJ9IsegDumQHhbv6XWaGcgNFZGizfKDx7461QA/kMTsqUvRTEq7qJ4rHVPi/OhPf52s5tKom1tbj9xGu2BSH/0o7FwYRsUtMPegPRfsqSUNXTDMBbiLtsOwrqjnfH1RygBeLeASoG5Ny2w7snhNfnKFFqU9+AT/ih9hd3dC5thCLD/7Ecrt5ZrYowjZLuxXNP1laWXgTtLNsdZ2GBMQvb2lbLiVmWZwHIzSmQqP07uFG7O0k53lLj/BD+cHLSibLkuRBGJxg== Received: from MEYP282MB3499.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:17d::5) by SYBP282MB4023.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:1a6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.10; Fri, 29 Jul 2022 11:16:43 +0000 Received: from MEYP282MB3499.AUSP282.PROD.OUTLOOK.COM ([fe80::69fb:883:9c35:5416]) by MEYP282MB3499.AUSP282.PROD.OUTLOOK.COM ([fe80::69fb:883:9c35:5416%6]) with mapi id 15.20.5482.011; Fri, 29 Jul 2022 11:16:43 +0000 From: miterv@outlook.com To: ovs-dev@openvswitch.org, echaudro@redhat.com, i.maximets@ovn.org, vdasari@gmail.com Date: Fri, 29 Jul 2022 19:16:20 +0800 Message-ID: X-Mailer: git-send-email 2.32.0.windows.2 X-TMN: [TG/GkgEfmO/3g7eLOP1Qt38VfQd3pCWA] X-ClientProxiedBy: SG2PR02CA0085.apcprd02.prod.outlook.com (2603:1096:4:90::25) To MEYP282MB3499.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:17d::5) X-Microsoft-Original-Message-ID: <20220729111620.2238-1-miterv@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 51b63221-9425-4812-6bc8-08da7153d0a1 X-MS-TrafficTypeDiagnostic: SYBP282MB4023:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tNublvFW0Yzu+leghLCEdNzZxW9MqVDC5nv7dbQQ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bB7dbmp5vkqK7cTaGzsav/5dPjyQ6iXGCtjJarhTKKvSvAGYAumT/xQp9TpSJcE2Hn4hbvpInu/lMmbuzXSYVAcd0w7vWWIPci88cWcCJsq61bkInc4n9yPD9P0E8UwavAfZMGP5ufK1sqwaLo9L5RkurkCNJYIHZNUbYD88Bhufn2VTzD9ihA41+TaejKgfJw/ctKHO/Fzg2yHvwC7+AZl47HnVCim5IrhQwQHJPQU4RVvO+7g5xMnuaGdYoF5VJOipxLjcR/FGPrsTnUsLtxpqlN1YgCqMKJLIKsuKQOiW0vHoXlOHjetIgdZtoSuTuAU+BqKtKZRKF9yEuVzl+YzQrk8FDj88AICaUW74m7rdUFyaTlCx9LvW3QRToiH+0g4D08ZV7xaFMy6Gfq6GK9Smts0rAl9sMSF50XGQWGTzTFV5Iw3rHqjVml4pPQPqkc1jELBXySX2lYNIaHas9Di7pWb9CSQd1Y3a1YjVa1DlyS0H/m+ERWUDspnaVsDoOjCW00qc+qbX6ckCu26I9PGxPNmeKyZXwOvwt7NPnZ2cmoC9tGnqlmwl3Tn3QaoEHCXkjeQHCwmS5YYtuho6FGSDzrnownwwTN3ie3a1TGnbpg/fQAJ4FdbUE9tiQzFj6+zjvqeawd1xnVT9PnVC69GfmDpA8warX9oe/NI4JuaxgC5WGwhAZLhpKosXgd4gpZiV8TXaPmtgY+1GD6oAPThx0JBgVwS45jocXGDbHD+A3R9j3YFD9+gwxI+MqFa+MXovtWVCGqIuuJVVCk2LEd4M39I3eecROmLLRknoaYkpbOfPcHEwdkUJTRfn5727o4yTjY1wTZkm22zuKnXaAsLKAFhF6WmGJF4TF6Xo22WF7/h3nFVY667LmA/VwGxFyum89lcxsSWcA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51b63221-9425-4812-6bc8-08da7153d0a1 X-MS-Exchange-CrossTenant-AuthSource: MEYP282MB3499.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2022 11:16:43.4384 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SYBP282MB4023 Cc: Lin Huang , Zhang Yuhuang Subject: [ovs-dev] [PATCH] mac-learning: Fix learned fdb entries are not age out issue. 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: Lin Huang After user add a static fdb entry, the get_lru() function will always return the static fdb entry. That's normal fdb entries will not age out through mac_learning_run(). Fix the issue by modify the get_lru() function to check the entry->expires field and not return the entry which entry->expires is MAC_ENTRY_AGE_STATIC_ENTRY. Adding a unit test for this. Fixes: ccc24fc88d59 ("ofproto-dpif: APIs and CLI option to add/delete static fdb entry.") Tested-by: Zhang Yuhuang Signed-off-by: Lin Huang --- lib/mac-learning.c | 37 ++++++++++++++----------------------- tests/ofproto-dpif.at | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/lib/mac-learning.c b/lib/mac-learning.c index a60794fb2..713f81e63 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -175,13 +175,19 @@ static bool get_lru(struct mac_learning *ml, struct mac_entry **e) OVS_REQ_RDLOCK(ml->rwlock) { + struct mac_entry *entry; + if (!ovs_list_is_empty(&ml->lrus)) { - *e = mac_entry_from_lru_node(ml->lrus.next); - return true; - } else { - *e = NULL; - return false; + LIST_FOR_EACH (entry, lru_node, &ml->lrus) { + if (entry->expires != MAC_ENTRY_AGE_STATIC_ENTRY) { + *e = entry; + return true; + } + } } + + *e = NULL; + return false; } static unsigned int @@ -618,25 +624,10 @@ mac_learning_expire(struct mac_learning *ml, struct mac_entry *e) void mac_learning_flush(struct mac_learning *ml) { - struct mac_entry *e, *first_static_mac = NULL; - - while (get_lru(ml, &e) && (e != first_static_mac)) { - - /* Static mac should not be evicted. */ - if (MAC_ENTRY_AGE_STATIC_ENTRY == e->expires) { - - /* Make note of first static-mac encountered, so that this while - * loop will break on visting this mac again via get_lru(). */ - if (!first_static_mac) { - first_static_mac = e; - } + struct mac_entry *e; - /* Remove from lru head and append it to tail. */ - ovs_list_remove(&e->lru_node); - ovs_list_push_back(&ml->lrus, &e->lru_node); - } else { - mac_learning_expire(ml, e); - } + while (get_lru(ml, &e)) { + mac_learning_expire(ml, e); } hmap_shrink(&ml->table); } diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index 2e91ae1a1..4b455315d 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -7195,6 +7195,29 @@ AT_CHECK([ovs-appctl coverage/read-counter mac_learning_static_none_move], [0], OVS_VSWITCHD_STOP AT_CLEANUP +AT_SETUP([ofproto-dpif - static-mac learned mac age out]) +OVS_VSWITCHD_START([set bridge br0 fail-mode=standalone -- set bridge br0 other_config:mac-aging-time=5]) +add_of_ports br0 1 2 + +dnl Add some static mac entries. +AT_CHECK([ovs-appctl fdb/add br0 p1 0 50:54:00:00:01:01]) +AT_CHECK([ovs-appctl fdb/add br0 p2 0 50:54:00:00:02:02]) + +dnl Generate some dynamic fdb entries on some ports. +OFPROTO_TRACE([ovs-dummy], [in_port(1),eth(src=50:54:00:00:00:01)], [-generate], [100,2]) +OFPROTO_TRACE([ovs-dummy], [in_port(2),eth(src=50:54:00:00:00:02)], [-generate], [100,1]) + +dnl Waiting for aging out. +sleep 16 + +dnl Count number of static entries remaining. +AT_CHECK_UNQUOTED([ovs-appctl fdb/stats-show br0 | grep expired], [0], [dnl + Total number of expired MAC entries : 2 +]) + +OVS_VSWITCHD_STOP +AT_CLEANUP + AT_SETUP([ofproto-dpif - basic truncate action]) OVS_VSWITCHD_START add_of_ports br0 1 2 3 4 5