From patchwork Tue Feb 18 11:03:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 2048789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=iQWRio0G; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YxxVW215Zz1ybl for ; Tue, 18 Feb 2025 22:04:18 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id B1EB0411CB; Tue, 18 Feb 2025 11:04:18 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Aby6E5MWAYWs; Tue, 18 Feb 2025 11:04:16 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org B3627400FD Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=iQWRio0G Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id B3627400FD; Tue, 18 Feb 2025 11:04:16 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9E3B2C0A49; Tue, 18 Feb 2025 11:04:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3B714C0A48 for ; Tue, 18 Feb 2025 11:04:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 1C55B40DBB for ; Tue, 18 Feb 2025 11:04:15 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id FmZOZ_UV4d7f for ; Tue, 18 Feb 2025 11:04:14 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a01:111:f403:2406::60c; helo=nam02-sn1-obe.outbound.protection.outlook.com; envelope-from=roid@nvidia.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org A2C7D40E07 Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A2C7D40E07 Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=iQWRio0G Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060c.outbound.protection.outlook.com [IPv6:2a01:111:f403:2406::60c]) by smtp4.osuosl.org (Postfix) with ESMTPS id A2C7D40E07 for ; Tue, 18 Feb 2025 11:04:13 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RBJzyjFCOBNxCw9H55N/mSgZnMin2HHK2ZZqAeCmpVhUEciWv+vf3SzDCxnMZ/OICS19vB/kxJZ4eJaCXY9cPvAzhfe5taJRls+bgMMEFG8UYR1dKryL78aVbHeQB18JR92bnlGn0ylfWiRe6mPoRw/xHyyteIR9uZd4fpPcaaifeMZX/X7KY73CkUx9Q+bKo0wYtPiwfvelyqaojJjJchMmRvgpShGpionyrpwAWI6rhCY3sPX1EpWOiUAGS/zMHhZXZQuNkpbojsUvFNg3NIdkc/1M14HoZ8uDkC8RbtpeCIDKXW6klhIPPNlAVDBFsyA7+YFl7MvxvoLu5ej50g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kIMswqDD4Lzb+vf6LVVpt/SyuCtQkW74V2UqzgNenp8=; b=KTM5kwk96YBNPwW9hwREhgZWqvItdohS2W4207hyXDeRuPjEtN1iTtXEM55qJRCH8Vf8jKVZ7lXhx9bClBWYJBeprmJR6b4Ak8wgoDypRR0RoIML77ZYNsyfV32cn4VeL5FMIU4KGIOUP/8doQwkcxxO/G6pt431csu8ChDm6TaPGlEfWDtBbrhy8YSwrX3SgEGOky8BIfdEyr2QeUXiNRw6Dvxh0wkLjAux9bVYMf4rYJUzr/hkqwkj4XGal86+2z1UzACU+Kq0kD5Qo0Ed8UljwOR9Og2Hg0EbnNxh3u28MEz5D/PsAb2jeClK+ka2t//B1liZaAw6VGByrQ0Mng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=openvswitch.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kIMswqDD4Lzb+vf6LVVpt/SyuCtQkW74V2UqzgNenp8=; b=iQWRio0GzWVj6LJZcaspi9AAy3MNOV3uneI7AxXbxDRR6uLM5SSs/xEaTA8+GAO9tXkQBG39+dGlWEljhx0C/Pd6xNnYGKuM6XtHQuAjGZJC7ClezMLmVDAtPBFWhC4bk3ooGLN7AIZDGrrsYY6BB3JUNdR55QvWth/mNv/+OB+Nu6XHdkM/sJ8Hv4XQc9vbBm56zKi2Jkg89Mctdkvz3PjIzv5hGVjkGWD9trQtLB9qw9i33XaXP+bVV/4PDHRhSi/Q5xlPxdWwvHVKiMerokHtycheoBRp0P+7FnejAH2DPIdZe2SFITFdyTL3CcRFK4CSm/94yfa8U6ArWskiGw== Received: from BY3PR03CA0010.namprd03.prod.outlook.com (2603:10b6:a03:39a::15) by CH3PR12MB8354.namprd12.prod.outlook.com (2603:10b6:610:12f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Tue, 18 Feb 2025 11:03:57 +0000 Received: from SJ5PEPF000001D5.namprd05.prod.outlook.com (2603:10b6:a03:39a:cafe::dc) by BY3PR03CA0010.outlook.office365.com (2603:10b6:a03:39a::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8445.16 via Frontend Transport; Tue, 18 Feb 2025 11:03:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ5PEPF000001D5.mail.protection.outlook.com (10.167.242.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.11 via Frontend Transport; Tue, 18 Feb 2025 11:03:55 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 18 Feb 2025 03:03:48 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 18 Feb 2025 03:03:48 -0800 Received: from c-237-143-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Tue, 18 Feb 2025 03:03:47 -0800 From: Roi Dayan To: , Roi Dayan Date: Tue, 18 Feb 2025 13:03:41 +0200 Message-ID: <20250218110341.1998114-1-roid@nvidia.com> X-Mailer: git-send-email 2.18.2 MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D5:EE_|CH3PR12MB8354:EE_ X-MS-Office365-Filtering-Correlation-Id: 083ffcc7-91e2-439e-08fe-08dd500bf005 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: zFUafEFemKFIN7VwqXo7czfawRt49ohiNfVlX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XFfywCRFPlc01A10NTASO1OlfCcxA7mJhPgEfXrbrcWvE4xDGaBZPE41aU5xw0NJfpFqWAJTTIZlOf8F8tz9IHSZzdxAcQeWGigE+2rx9IHIqR0+XYz1vpwbbRx6kbKXjc9IQdUz8iysoGNY5/ggDxghXEPynE3Gf7giIDcAuw7tsBYAaKYFoYwq4f8Tek1JC0CYi5FlhnopAkOshnjdUH4qKyUqqCvVzvu0UItWcG/HmAATVr9klsFE7gKojnwHOyHCct5GwA+OnpIxsWYfo2cdfjoSwK5rwTkCm6iU2a2DE0WrBXSsutbrwWRhdG5BtDKz+TVtmoyAT3+pMIAhaUpyxg10okajo41DXCW9HcL4sjyJkktBTNyfHsCeRAhig= X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2025 11:03:55.8046 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 083ffcc7-91e2-439e-08fe-08dd500bf005 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001D5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8354 Subject: [ovs-dev] [PATCH v3] ofproto: Add JSON output for 'fdb/show' command. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maor Dickman Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Dima Chumak The 'fdb/show' command now supports machine-readable JSON output in addition to the plain-text output for humans. An example would be: ovs-appctl --format=json --pretty fdb/show br-phy [ { "age": "static", "mac": "e4:8c:07:08:00:02", "port": 2, "vlan": 0 }, { "age": 14, "mac": "e4:8c:07:08:00:03", "port": 3, "vlan": 0 } ] Signed-off-by: Dima Chumak Acked-by: Roi Dayan --- Notes: v3 - Fix assert. No need to call json_destroy() after unixctl_command_reply_json() as it takes ownership of the allocated body. v2 - Fix sparse check error. - Add case checking fdb/show json output. ofproto/ofproto-dpif.c | 85 ++++++++++++++++++++++++++++++++++-------- tests/ofproto-dpif.at | 10 +++++ 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index bf43d5d4bc59..9926c016fb00 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -6151,20 +6151,12 @@ ofbundle_get_a_port(const struct ofbundle *bundle) } static void -ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, - const char *argv[], void *aux OVS_UNUSED) +ofproto_unixctl_fdb_show_text(const struct ofproto_dpif *ofproto, + struct ds *ds) { - struct ds ds = DS_EMPTY_INITIALIZER; - const struct ofproto_dpif *ofproto; const struct mac_entry *e; - ofproto = ofproto_dpif_lookup_by_name(argv[1]); - if (!ofproto) { - unixctl_command_reply_error(conn, "no such bridge"); - return; - } - - ds_put_cstr(&ds, " port VLAN MAC Age\n"); + ds_put_cstr(ds, " port VLAN MAC Age\n"); ovs_rwlock_rdlock(&ofproto->ml->rwlock); LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) { struct ofbundle *bundle = mac_entry_get_port(ofproto->ml, e); @@ -6173,17 +6165,78 @@ ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, NULL, name, sizeof name); - ds_put_format(&ds, "%5s %4d "ETH_ADDR_FMT" ", + ds_put_format(ds, "%5s %4d "ETH_ADDR_FMT" ", name, e->vlan, ETH_ADDR_ARGS(e->mac)); if (MAC_ENTRY_AGE_STATIC_ENTRY == age) { - ds_put_format(&ds, "static\n"); + ds_put_format(ds, "static\n"); } else { - ds_put_format(&ds, "%3d\n", age); + ds_put_format(ds, "%3d\n", age); } } ovs_rwlock_unlock(&ofproto->ml->rwlock); - unixctl_command_reply(conn, ds_cstr(&ds)); - ds_destroy(&ds); +} + +static void +ofproto_unixctl_fdb_show_json(const struct ofproto_dpif *ofproto, + struct json **fdb_entries) +{ + size_t num_entries = hmap_count(&ofproto->ml->table); + struct json **json_entries = NULL; + const struct mac_entry *entry; + int i = 0; + + if (!num_entries) { + goto done; + } + + json_entries = xmalloc(num_entries * sizeof *json_entries); + ovs_rwlock_rdlock(&ofproto->ml->rwlock); + LIST_FOR_EACH (entry, lru_node, &ofproto->ml->lrus) { + struct ofbundle *bundle = mac_entry_get_port(ofproto->ml, entry); + struct json *json_entry = json_object_create(); + int age = mac_entry_age(ofproto->ml, entry); + long long port; + + port = (OVS_FORCE long long) ofbundle_get_a_port(bundle)->up.ofp_port; + json_object_put(json_entry, "port", json_integer_create(port)); + json_object_put(json_entry, "vlan", json_integer_create(entry->vlan)); + json_object_put_format(json_entry, "mac", ETH_ADDR_FMT, + ETH_ADDR_ARGS(entry->mac)); + if (MAC_ENTRY_AGE_STATIC_ENTRY == age) { + json_object_put_string(json_entry, "age", "static"); + } else { + json_object_put(json_entry, "age", json_integer_create(age)); + } + json_entries[i++] = json_entry; + } + ovs_rwlock_unlock(&ofproto->ml->rwlock); +done: + *fdb_entries = json_array_create(json_entries, num_entries); +} + +static void +ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) +{ + const struct ofproto_dpif *ofproto = ofproto_dpif_lookup_by_name(argv[1]); + + if (!ofproto) { + unixctl_command_reply_error(conn, "no such bridge"); + return; + } + + if (unixctl_command_get_output_format(conn) == UNIXCTL_OUTPUT_FMT_JSON) { + struct json *fdb_entries; + + ofproto_unixctl_fdb_show_json(ofproto, &fdb_entries); + unixctl_command_reply_json(conn, fdb_entries); + } else { + struct ds ds = DS_EMPTY_INITIALIZER; + + ofproto_unixctl_fdb_show_text(ofproto, &ds); + unixctl_command_reply(conn, ds_cstr(&ds)); + ds_destroy(&ds); + } } static void diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index fa5f148b4c28..8a975e6ffd9c 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -7085,6 +7085,16 @@ AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]\{1,\}$/?/'], [0], [d 3 0 50:54:00:00:00:05 ? ]) +dnl Check json output. +AT_CHECK([ovs-appctl --format json --pretty fdb/show br0], [0], [dnl +[[ + { + "age": 0, + "mac": "50:54:00:00:00:05", + "port": 3, + "vlan": 0}]] +]) + # Trace a packet arrival destined for the learned MAC. # (This will also learn a MAC.) OFPROTO_TRACE(