From patchwork Mon Jun 3 08:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ales Musil X-Patchwork-Id: 1942744 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" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aXQ8RKSk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.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 4Vt6Dg3Thcz1ydW for ; Mon, 3 Jun 2024 18:23:15 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 8CA56404F1; Mon, 3 Jun 2024 08:23:12 +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 Vql5wNCSke2C; Mon, 3 Jun 2024 08:23:10 +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 311B440021 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aXQ8RKSk Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 311B440021; Mon, 3 Jun 2024 08:23:10 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 032F1C0077; Mon, 3 Jun 2024 08:23:10 +0000 (UTC) X-Original-To: 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 5E9A9C0037 for ; Mon, 3 Jun 2024 08:23:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4809782257 for ; Mon, 3 Jun 2024 08:23:08 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id kw3SfmBekj8m for ; Mon, 3 Jun 2024 08:23:07 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amusil@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 285378224A Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 285378224A Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aXQ8RKSk Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 285378224A for ; Mon, 3 Jun 2024 08:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717402985; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K/q3lfPDyMNhomo5qxfkpO7MuTYNkwiLtipIBqVk00E=; b=aXQ8RKSkqBAebCARB1T6ql+83JE+cg+k6Vfy7FAV4uHD/phmlDeuGnAuLcAJl4jpzIYZ3s P3q/kjWJZT6+RwmcOPUN4fj0Bh3rBa5FbAAmWZIHeIAiO+nh9CZFDnTiWawmUX6EuE1CP+ EMkDF29uzyEs2tBDJclaPojjbrhd0+M= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-lsPYVovBOoGqqXVqxQWCbw-1; Mon, 03 Jun 2024 04:23:04 -0400 X-MC-Unique: lsPYVovBOoGqqXVqxQWCbw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49B193C025AC for ; Mon, 3 Jun 2024 08:23:04 +0000 (UTC) Received: from amusil.brq.redhat.com (unknown [10.43.17.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id AED05200C6B6; Mon, 3 Jun 2024 08:23:03 +0000 (UTC) From: Ales Musil To: dev@openvswitch.org Date: Mon, 3 Jun 2024 10:23:03 +0200 Message-ID: <20240603082303.193454-1-amusil@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com Subject: [ovs-dev] [PATCH ovn] utilties: Allow ovn-detrace to run on ovs-ofctl dump-flows output. 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" The ovs-ofctl dump-flows output is slightly different from oproto/trace cookie 0xXXX vs. cookie=0xXXX. Update the regex that it also matches on the equals case. This allows us to run ovn-detrace against the ovs-ofctl dump-flows output. Also provide simple, partially hardcoded test case for ovn-detrace. Signed-off-by: Ales Musil Acked-by: Dumitru Ceara --- tests/automake.mk | 3 +- tests/ovn-util.at | 108 ++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + utilities/ovn-debug.c | 18 ++++++ utilities/ovn_detrace.py.in | 5 +- 5 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 tests/ovn-util.at diff --git a/tests/automake.mk b/tests/automake.mk index 1fdc89835..3899c9e80 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -45,7 +45,8 @@ TESTSUITE_AT = \ tests/ovn-lflow-cache.at \ tests/ovn-lflow-conj-ids.at \ tests/ovn-ipsec.at \ - tests/ovn-vif-plug.at + tests/ovn-vif-plug.at \ + tests/ovn-util.at SYSTEM_DPDK_TESTSUITE_AT = \ tests/system-dpdk-testsuite.at \ diff --git a/tests/ovn-util.at b/tests/ovn-util.at new file mode 100644 index 000000000..fd3282548 --- /dev/null +++ b/tests/ovn-util.at @@ -0,0 +1,108 @@ +AT_SETUP([ovn-detrace - simple scenario]) +AT_SKIP_IF([test $HAVE_SCAPY = no]) +ovn_start +net_add n1 + +sim_add hv1 +as hv1 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.1 +ovs-vsctl -- add-port br-int vm0 -- \ + set interface vm0 external-ids:iface-id=vm0 + +ovs-vsctl -- add-port br-int vm1 -- \ + set interface vm1 external-ids:iface-id=vm1 + +ovn-nbctl ls-add ls \ + -- set logical_switch ls other-config:requested-tnl-key=1 + +ovn-nbctl lsp-add ls vm0 \ + -- lsp-set-addresses vm0 "f0:00:00:01:01:00 192.168.1.10" \ + -- set logical_switch_port vm0 options:requested-tnl-key=10 +ovn-nbctl lsp-add ls vm1 \ + -- lsp-set-addresses vm1 "f0:00:00:01:01:01 192.168.1.11" \ + -- set logical_switch_port vm1 options:requested-tnl-key=11 + +# Allow some time for ovn-northd and ovn-controller to catch up. +wait_for_ports_up +check ovn-nbctl --wait=hv sync + +ingress_table=$(ovn-debug lflow-stage-to-ltable ls_in_check_port_sec) +egress_table=$(ovn-debug lflow-stage-to-ltable ls_out_apply_port_sec) +dp_uuid=$(fetch_column datapath _uuid external_ids:name=ls) +pb_vm0=$(ovn-debug uuid-to-cookie $(fetch_column port_binding _uuid \ + logical_port=vm0)) +pb_vm1=$(ovn-debug uuid-to-cookie $(fetch_column port_binding _uuid \ + logical_port=vm1)) +ingress=$(ovn-debug uuid-to-cookie $(fetch_column logical_flow _uuid \ + table_id=$ingress_table pipeline=ingress match="1")) +egress=$(ovn-debug uuid-to-cookie $(fetch_column logical_flow _uuid \ + table_id=$egress_table pipeline=egress match="1")) + +cat << EOF > trace +0. in_port=1, priority 100, cookie $pb_vm0 +set_field:0x4/0xffff->reg13 +set_field:0x1->reg11 +set_field:0x1->reg12 +set_field:0x1->metadata +set_field:0x1->reg14 +set_field:0/0xffff0000->reg13 +resubmit(,??) +8. metadata=0x1, priority 50, cookie $ingress +set_field:0/0x1000->reg10 +resubmit(,??) +51. metadata=0x1, priority 0, cookie $egress +resubmit(,??) +65. reg15=0x2,metadata=0x1, priority 100, cookie $pb_vm1 +output:2 +EOF + +AT_CHECK_UNQUOTED([cat trace | $PYTHON $top_srcdir/utilities/ovn_detrace.py.in], [0], [dnl +0. in_port=1, priority 100, cookie $pb_vm0 +set_field:0x4/0xffff->reg13 +set_field:0x1->reg11 +set_field:0x1->reg12 +set_field:0x1->metadata +set_field:0x1->reg14 +set_field:0/0xffff0000->reg13 +resubmit(,??) + * Logical datapath: "ls" ($dp_uuid) + * Port Binding: logical_port "vm0", tunnel_key 10, chassis-name "hv1", chassis-str "hv1" +8. metadata=0x1, priority 50, cookie $ingress +set_field:0/0x1000->reg10 +resubmit(,??) + * Logical datapaths: + * "ls" ($dp_uuid) [[ingress]] + * Logical flow: table=$ingress_table (ls_in_check_port_sec), priority=50, match=(1), actions=(reg0[[15]] = check_in_port_sec(); next;) +51. metadata=0x1, priority 0, cookie $egress +resubmit(,??) + * Logical datapaths: + * "ls" ($dp_uuid) [[egress]] + * Logical flow: table=$egress_table (ls_out_apply_port_sec), priority=0, match=(1), actions=(output;) +65. reg15=0x2,metadata=0x1, priority 100, cookie $pb_vm1 +output:2 + * Logical datapath: "ls" ($dp_uuid) + * Port Binding: logical_port "vm1", tunnel_key 11, chassis-name "hv1", chassis-str "hv1" + +]) + +ovs-ofctl dump-flows br-int table=$(ovn-debug lflow-stage-to-oftable ls_in_check_port_sec),cookie=$ingress/0xffffffff >> flows +ovs-ofctl dump-flows br-int table=$(ovn-debug lflow-stage-to-oftable ls_out_apply_port_sec),cookie=$egress/0xffffffff >> flows + +AT_CHECK_UNQUOTED([cat flows | awk '{print $1, $7, $8}' | grep -v "NXST_FLOW" | \ + sed -e "s/resubmit(,[[0-9]]\+)/resubmit(,??)/g" | \ + $PYTHON $top_srcdir/utilities/ovn_detrace.py.in], [0], [dnl +cookie=$ingress, priority=50,metadata=0x1 actions=load:0->NXM_NX_REG10[[12]],resubmit(,??),move:NXM_NX_REG10[[12]]->NXM_NX_XXREG0[[111]],resubmit(,??) + * Logical datapaths: + * "ls" ($dp_uuid) [[ingress]] + * Logical flow: table=$ingress_table (ls_in_check_port_sec), priority=50, match=(1), actions=(reg0[[15]] = check_in_port_sec(); next;) +cookie=$egress, priority=0,metadata=0x1 actions=resubmit(,??) + * Logical datapaths: + * "ls" ($dp_uuid) [[egress]] + * Logical flow: table=$egress_table (ls_out_apply_port_sec), priority=0, match=(1), actions=(output;) + +]) + +OVN_CLEANUP([hv1]) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index d3f00e1bf..8e60bf82e 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -40,3 +40,4 @@ m4_include([tests/ovn-ic.at]) m4_include([tests/checkpatch.at]) m4_include([tests/ovn-ipsec.at]) m4_include([tests/ovn-vif-plug.at]) +m4_include([tests/ovn-util.at]) diff --git a/utilities/ovn-debug.c b/utilities/ovn-debug.c index 0cec9f671..0a0d2202b 100644 --- a/utilities/ovn-debug.c +++ b/utilities/ovn-debug.c @@ -76,6 +76,20 @@ lflow_stage_to_table(struct ovs_cmdl_context *ctx) exit(EXIT_SUCCESS); } +static void +uuid_to_cookie_str(struct ovs_cmdl_context *ctx) +{ + const char *uuid_str = ctx->argv[1]; + struct uuid uuid = UUID_ZERO; + + if (!uuid_from_string(&uuid, uuid_str)) { + ovs_fatal(0, "Couldn't convert UUID string \"%s\" to UUID", uuid_str); + } + + printf("%#"PRIx32, uuid.parts[0]); + exit(EXIT_SUCCESS); +} + static void usage(void) @@ -88,6 +102,8 @@ lflow-stage-to-ltable STAGE_NAME\n\ Converts STAGE_NAME into logical flow table number.\n\ lflow-stage-to-oftable STAGE_NAME\n\ Converts STAGE_NAME into OpenFlow table number.\n\ +uuid-to-cookie UUID\n\ + Converts UUID into cookie format.\n\ \n\ Options:\n\ -h, --help display this help message\n\ @@ -145,6 +161,8 @@ main(int argc, char *argv[]) OVS_RO}, {"lflow-stage-to-ltable", NULL, 1, 1, lflow_stage_to_table, OVS_RO}, + {"uuid-to-cookie", NULL, 1, 1, uuid_to_cookie_str, + OVS_RO}, { "help", NULL, 0, INT_MAX, help, OVS_RO }, {NULL, NULL, 0, 0, NULL, OVS_RO}, }; diff --git a/utilities/ovn_detrace.py.in b/utilities/ovn_detrace.py.in index 12df6e52a..986c5b8ad 100755 --- a/utilities/ovn_detrace.py.in +++ b/utilities/ovn_detrace.py.in @@ -515,7 +515,7 @@ def main(): printer = Printer() cookie_handlers = get_cookie_handlers(ovsdb_ovnnb, ovsdb_ovnsb, printer) - regex_cookie = re.compile(r'^.*cookie 0x([0-9a-fA-F]+)') + regex_cookie = re.compile(r'^.*cookie[ =]0x([0-9a-fA-F]+)') regex_handlers = [ (regex_cookie, cookie_handlers) ] @@ -537,7 +537,8 @@ def main(): line = sys.stdin.readline() if len(cookies) > 0: # Print record info when the current flow block ends. - if regex_table_id.match(line) or line.strip() == '': + if regex_table_id.match(line) or line.strip() == '' or \ + regex_cookie.match(line): for cookie, handlers in cookies: print_record_from_cookie(ovsdb_ovnnb, handlers, cookie) cookies = []