Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp371728lqp; Tue, 11 Jun 2024 07:06:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX0Ed/KSck5WcuC5p6PwoeOeeWgzl3qmlOHJeL2gNh5OFkcsxILMn2fPip2QqBOj/S+zxz1155aW5+phf7e7xA2AGSfXwSHFi/VE7lzjA== X-Google-Smtp-Source: AGHT+IGs9hlip80KE3CnYmnkpzWmm8hgZvNr0w3MHBVAsq0ADwY7Tq2GC8LxWxPA+G7xLx3GW/ig X-Received: by 2002:a5b:70e:0:b0:df4:a7d7:1112 with SMTP id 3f1490d57ef6-dfaf665a2bfmr14014594276.60.1718114786905; Tue, 11 Jun 2024 07:06:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718114786; cv=pass; d=google.com; s=arc-20160816; b=lFi+XyVAsZfb6z69YpDr63noSGfRwClVCiwAxLTdHheM4zGlq2v9ldvNjn70vQy7Af UcNHPaX9mO55yFVWRvy+xDB4kdpf4yFTHZkisN4Szxyex8m+cWl4nRfQAlTyCWazthQr QD+JXuavhvl9aXMTJiRypJNOaN9bVEQDqyyPTZjTyNv7uY63dBjYtfJcfXthWM4uGKtF sxAiPKRufXJDJzISonEst+rbs/ISbghivuyFUvLUHMeSk/P6r6aium3WvIWuateuXcAt 9vRiCyXNkFF0m+EQ3Ii7gEqVpI2v3pA3tgaD6ZIbeh8OfUMhBXlMnI5IoGNo3g89pcL5 tcEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=cAPflhf5z7yrHuZp8DNchU9pFtrCYnF+364utpEHSM8=; fh=ayqqqar9vZ3uSEexk/Ee85nTsUibBSUwY/vkE0D5fZ0=; b=fD6Od+8dHWF1HOlzKmiMbrEONJqpiEuNAAgq7IaPuZXwIgun7+ymF3l0zybckTziPd cEAL9Xb8QqJVlsj5+A5bSU8ttv1AjCKV+UBZN+X/Tc5d0gwsOtXd2gtO5vbz2iOuR+si VzKlLpIT/DsqYGb1iFtD3cq0aXuB2MamyJma2uVp5CX/7zRQ8+dtnZvj5xmTI/L5JFPi zHP79pKCeKH7JgfLdAVw8S26Wel93GBvdwvaxL0kec2LitqhGeDLCIY4ZrWpFvo66trz 5UaEAa1nqVAdw1Akl60PtMeKlUIYdXYRUP5BxPw/eZaRBf2hinaKcBkEBtFvibsm7jkf /Htg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="jLOfO/Hl"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-210031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 3f1490d57ef6-dfaff2403f2si3715892276.400.2024.06.11.07.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 07:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="jLOfO/Hl"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-210031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C200B1C23FA5 for ; Tue, 11 Jun 2024 14:04:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C558A17D8A1; Tue, 11 Jun 2024 14:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jLOfO/Hl" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3949817B437 for ; Tue, 11 Jun 2024 14:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718114680; cv=none; b=j/1LwJy3Er/KTMRPxMY0Lsc8PBdlE0GSY6fXdV/h+VnqHB4sZymhRcP39D6nTTwWsGrwhSVPc6SSAYTJPEAqdq/MC8/FA1r1NPQCwY1aHgbx9vI6gbo+KW4RbadaynVqMCqSZuVMYRAHic/LrnFCyPuA4irbk6wU6Q/62CSL+KA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718114680; c=relaxed/simple; bh=trGiPJjAG5Lg9A+UiUTAr6m2HCDMuWyJu8Xi/VJCwmY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=VgDNmtoPnH1vHspBju2+GTRcxCU4ASYMYmxjAehmw7lt+YPUdVnz5UZUOlD3fPbFmKYuJzWcV49Y/2HpM5CWHUKQ6xZ72Wj6dCiy8Q7xF4kUBaS14wKYHun3NXlb2OYrR+6u0+LEHAimksudqynmBhvii3NsbS8f6bjdrFVB0pQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jLOfO/Hl; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718114678; 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: in-reply-to:in-reply-to:references:references; bh=cAPflhf5z7yrHuZp8DNchU9pFtrCYnF+364utpEHSM8=; b=jLOfO/HlmgO++2GHzjn+sRp8FQyk8wg4w4+8wsrghbOet4zW1jwtUlaNvsUY4gPCz5FD4u sLLzy0gcEum+Q4/Tfif5DRH8TaQh/xVeL8wmHZ0RxXPOsP9F2mddkjJbjviiQmuALvtng7 3mK02XEb7CnpL/aC/+Kwla+vecTJEZg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-HJAMWWwDOJS9XCUUIumP0Q-1; Tue, 11 Jun 2024 10:04:34 -0400 X-MC-Unique: HJAMWWwDOJS9XCUUIumP0Q-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AE43E1955D82; Tue, 11 Jun 2024 14:04:23 +0000 (UTC) Received: from RHTRH0061144 (dhcp-17-72.bos.redhat.com [10.18.17.72]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7BC9A1955E80; Tue, 11 Jun 2024 14:04:16 +0000 (UTC) From: Aaron Conole To: =?utf-8?Q?Adri=C3=A1n?= Moreno Cc: netdev@vger.kernel.org, Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , dev@openvswitch.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman Subject: Re: [PATCH net-next 1/2] selftests: openvswitch: fix action formatting In-Reply-To: (=?utf-8?Q?=22Adri=C3=A1n?= Moreno"'s message of "Thu, 6 Jun 2024 09:05:01 +0000") References: <20240603183121.2305013-1-amorenoz@redhat.com> Date: Tue, 11 Jun 2024 10:04:14 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Adri=C3=A1n Moreno writes: > On Mon, Jun 03, 2024 at 03:00:03PM GMT, Aaron Conole wrote: >> Adrian Moreno writes: >> >> > In the action formatting function ("dpstr"), the iteration is made over >> > the nla_map, so if there are more than one attribute from the same type >> > we only print the first one. >> > >> > Fix this by iterating over the actual attributes. >> > >> > Signed-off-by: Adrian Moreno >> > --- >> > .../selftests/net/openvswitch/ovs-dpctl.py | 48 +++++++++++-------- >> > 1 file changed, 27 insertions(+), 21 deletions(-) >> > >> > diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/to= ols/testing/selftests/net/openvswitch/ovs-dpctl.py >> > index 1dd057afd3fb..b76907ac0092 100644 >> > --- a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py >> > +++ b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py >> > @@ -437,40 +437,46 @@ class ovsactions(nla): >> > def dpstr(self, more=3DFalse): >> > print_str =3D "" >> > >> > - for field in self.nla_map: >> > - if field[1] =3D=3D "none" or self.get_attr(field[0]) is N= one: >> > + for attr_name, value in self["attrs"]: >> > + attr_desc =3D next(filter(lambda x: x[0] =3D=3D attr_name= , self.nla_map), >> > + None) >> > + if not attr_desc: >> > + raise ValueError("Unknown attribute: %s" % attr) >> > + >> > + attr_type =3D attr_desc[1] >> > + >> > + if attr_type =3D=3D "none": >> >> I agree, this is an issue. BUT I think it might be better to just >> filter by field type up front. See: >> >> https://github.com/apconole/linux-next-work/commit/7262107de7170d44b6dbf= 6c5ea6f7e6c0bb71d36#diff-3e72e7405c6bb4e9842bed5f63883ca930387086bb40d4034e= 92ed83a5decb4bR441 >> >> That version I think ends up being much easier to follow. If you want >> to take it for your series, feel free. If you disagree, maybe there's >> something I'm not considering about it. >> > > I agree. It's better to check field attribute names first. I found this > during manual testing of the "emit_sample" series but I ended up not > needing it for the automated one, so I'm OK waiting for your cleanup > series. I'll get stuff out this week for it. > In fact, I also have some patches that try some rework of this part. In > particular, I tried to unify all attributes under a common base class > that would handle printing and parsing. That way, most cases would fall > into "print_str +=3D datum.dpstr(more)" and the "if/elif" block would > shrink significantly. That sounds very good. >> NOTE that version is just a bunch of independent changes that are >> squashed together. I have a cleaner version. >> >> I can also bundle up the series I have so far and submit, but I didn't >> want to do that until I got all the pmtu.sh support working. Maybe it >> makes sense to send it now though. Simon, Jakub - wdyt? >> >> > continue >> > if print_str !=3D "": >> > print_str +=3D "," >> > >> > - if field[1] =3D=3D "uint32": >> > - if field[0] =3D=3D "OVS_ACTION_ATTR_OUTPUT": >> > - print_str +=3D "%d" % int(self.get_attr(field[0])) >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_RECIRC": >> > - print_str +=3D "recirc(0x%x)" % int(self.get_attr= (field[0])) >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_TRUNC": >> > - print_str +=3D "trunc(%d)" % int(self.get_attr(fi= eld[0])) >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_DROP": >> > - print_str +=3D "drop(%d)" % int(self.get_attr(fie= ld[0])) >> > - elif field[1] =3D=3D "flag": >> > - if field[0] =3D=3D "OVS_ACTION_ATTR_CT_CLEAR": >> > + if attr_type =3D=3D "uint32": >> > + if attr_name =3D=3D "OVS_ACTION_ATTR_OUTPUT": >> > + print_str +=3D "%d" % int(value) >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_RECIRC": >> > + print_str +=3D "recirc(0x%x)" % int(value) >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_TRUNC": >> > + print_str +=3D "trunc(%d)" % int(value) >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_DROP": >> > + print_str +=3D "drop(%d)" % int(value) >> > + elif attr_type =3D=3D "flag": >> > + if attr_name =3D=3D "OVS_ACTION_ATTR_CT_CLEAR": >> > print_str +=3D "ct_clear" >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_POP_VLAN": >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_POP_VLAN": >> > print_str +=3D "pop_vlan" >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_POP_ETH": >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_POP_ETH": >> > print_str +=3D "pop_eth" >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_POP_NSH": >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_POP_NSH": >> > print_str +=3D "pop_nsh" >> > - elif field[0] =3D=3D "OVS_ACTION_ATTR_POP_MPLS": >> > + elif attr_name =3D=3D "OVS_ACTION_ATTR_POP_MPLS": >> > print_str +=3D "pop_mpls" >> > else: >> > - datum =3D self.get_attr(field[0]) >> > - if field[0] =3D=3D "OVS_ACTION_ATTR_CLONE": >> > + if attr_name =3D=3D "OVS_ACTION_ATTR_CLONE": >> > print_str +=3D "clone(" >> > - print_str +=3D datum.dpstr(more) >> > + print_str +=3D value.dpstr(more) >> > print_str +=3D ")" >> > else: >> > - print_str +=3D datum.dpstr(more) >> > + print_str +=3D value.dpstr(more) >> > >> > return print_str >>