From patchwork Wed Nov 11 23:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1398582 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org 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 4CWgkv4Zstz9sPB for ; Thu, 12 Nov 2020 10:23:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 77B2720474; Wed, 11 Nov 2020 23:23:01 +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 pTwlhXuiMeim; Wed, 11 Nov 2020 23:22:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 798F6203A5; Wed, 11 Nov 2020 23:22:59 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 62A7DC088B; Wed, 11 Nov 2020 23:22:59 +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 BBA30C016F for ; Wed, 11 Nov 2020 23:22:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 9E7FD8729B for ; Wed, 11 Nov 2020 23:22:58 +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 HMqWB9-NiDHQ for ; Wed, 11 Nov 2020 23:22:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by hemlock.osuosl.org (Postfix) with ESMTPS id A1CCB8726D for ; Wed, 11 Nov 2020 23:22:55 +0000 (UTC) X-Originating-IP: 75.54.222.30 Received: from sigfpe.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id E4173FF805; Wed, 11 Nov 2020 23:22:50 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Wed, 11 Nov 2020 15:22:44 -0800 Message-Id: <20201111232244.628803-1-blp@ovn.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] db-ctl-base: Add {in} and {not-in} set relational operators. 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" I would have found these useful for the OVN tests. The {in} operator is the same as {<=}, but it's still useful to have the alternate syntax because most of the time we think of set inclusion separately from set subsets. The {not-in} operator is different from any existing operator though. Signed-off-by: Ben Pfaff Acked-by: Ilya Maximets --- NEWS | 2 ++ lib/db-ctl-base.c | 10 ++++++++-- lib/db-ctl-base.man | 18 ++++++++++++------ lib/db-ctl-base.xml | 29 +++++++++++++++++++++++------ tests/ovs-vsctl.at | 22 +++++++++++++++++++++- 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 2860a8e9ce63..057a5cdb7045 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ Post-v2.14.0 "secondary", respectively, for OpenFlow connection roles. * The term "slave" has been replaced by "member", for bonds, LACP, and OpenFlow bundle actions. + - In ovs-vsctl and vtep-ctl, the "find" command now accept new + operators {in} and {not-in}. v2.14.0 - 17 Aug 2020 diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index ab2af9edadf4..e95c77da2cf6 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -698,7 +698,9 @@ check_mutable(const struct ovsdb_idl_row *row, RELOP(RELOP_SET_LT, "{<}") \ RELOP(RELOP_SET_GT, "{>}") \ RELOP(RELOP_SET_LE, "{<=}") \ - RELOP(RELOP_SET_GE, "{>=}") + RELOP(RELOP_SET_GE, "{>=}") \ + RELOP(RELOP_SET_IN, "{in}") \ + RELOP(RELOP_SET_NOT_IN, "{not-in}") enum relop { #define RELOP(ENUM, STRING) ENUM, @@ -711,7 +713,8 @@ is_set_operator(enum relop op) { return (op == RELOP_SET_EQ || op == RELOP_SET_NE || op == RELOP_SET_LT || op == RELOP_SET_GT || - op == RELOP_SET_LE || op == RELOP_SET_GE); + op == RELOP_SET_LE || op == RELOP_SET_GE || + op == RELOP_SET_IN || op == RELOP_SET_NOT_IN); } static bool @@ -739,9 +742,12 @@ evaluate_relop(const struct ovsdb_datum *a, const struct ovsdb_datum *b, case RELOP_SET_GT: return a->n > b->n && ovsdb_datum_includes_all(b, a, type); case RELOP_SET_LE: + case RELOP_SET_IN: return ovsdb_datum_includes_all(a, b, type); case RELOP_SET_GE: return ovsdb_datum_includes_all(b, a, type); + case RELOP_SET_NOT_IN: + return ovsdb_datum_excludes_all(a, b, type); default: OVS_NOT_REACHED(); diff --git a/lib/db-ctl-base.man b/lib/db-ctl-base.man index 2414ae3c2028..b77f5d106448 100644 --- a/lib/db-ctl-base.man +++ b/lib/db-ctl-base.man @@ -98,6 +98,15 @@ Same as \fB{<=}\fR and \fB{<}\fR, respectively, except that the relationship is reversed. For example, \fBflood-vlans{>=}1,2\fR selects records in which the \fBflood-vlans\fR column contains both 1 and 2. +.PP +The following operators are available only in Open vSwitch 2.15 and +later: +.IP "\fB{in}\fR" +Selects records in which every element in \fIcolumn\fR[\fB:\fIkey\fR] +is also in \fIvalue\fR. (This is the same as \fB{<=}\fR.) +.IP "\fB{not-in}\fR" +Selects records in which every element in \fIcolumn\fR[\fB:\fIkey\fR] +is not in \fIvalue\fR. .RE .IP For arithmetic operators (\fB= != < > <= >=\fR), when \fIkey\fR is @@ -240,12 +249,9 @@ in these tables, \fBdestroy\fR is silently ignored. See the .IP "\fBwait\-until \fItable record \fR[\fIcolumn\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR]..." Waits until \fItable\fR contains a record named \fIrecord\fR whose \fIcolumn\fR equals \fIvalue\fR or, if \fIkey\fR is specified, whose -\fIcolumn\fR contains a \fIkey\fR with the specified \fIvalue\fR. Any -of the operators \fB!=\fR, \fB<\fR, \fB>\fR, \fB<=\fR, or \fB>=\fR may -be substituted for \fB=\fR to test for inequality, less than, greater -than, less than or equal to, or greater than or equal to, -respectively. (Don't forget to escape \fB<\fR or \fB>\fR from -interpretation by the shell.) +\fIcolumn\fR contains a \fIkey\fR with the specified \fIvalue\fR. This +command supports the same operators and semantics described for the +\fBfind\fR command above. .IP If no \fIcolumn\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR arguments are given, this command waits only until \fIrecord\fR exists. If more than one diff --git a/lib/db-ctl-base.xml b/lib/db-ctl-base.xml index 10124c3ad01c..73da44f32323 100644 --- a/lib/db-ctl-base.xml +++ b/lib/db-ctl-base.xml @@ -145,7 +145,27 @@ selects records in which the flood-vlans column contains both 1 and 2. + + +

+ The following operators are available only in Open vSwitch 2.15 and + later: +

+
{in} +
+ Selects records in which every element in + column[:key] is also in + value. (This is the same as {<=}.) +
+ +
{not-in}
+
+ Selects records in which every element in + column[:key] is not in + value. +

@@ -352,12 +372,9 @@

Waits until table contains a record named record whose column equals value or, if key is specified, whose - column contains a key with the specified value. Any - of the operators !=, <, >, <=, or >= may - be substituted for = to test for inequality, less than, greater - than, less than or equal to, or greater than or equal to, - respectively. (Don't forget to escape < or > from - interpretation by the shell.) + column contains a key with the specified value. This + command supports the same operators and semantics described for the + find command above.

If no column[:key]=value arguments are given, diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index c8babe36120a..d2cb414038d5 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -1048,7 +1048,7 @@ AT_CHECK([RUN_OVS_VSCTL([set controller x connection_mode=standalone])], [1], [], [ovs-vsctl: no row "x" in table Controller ]) AT_CHECK([RUN_OVS_VSCTL([wait-until bridge br0 datapath_id:y,z])], - [1], [], [ovs-vsctl: datapath_id:y,z: argument does not end in "=", "!=", "<", ">", "<=", ">=", "{=}", "{!=}", "{<}", "{>}", "{<=}", or "{>=}" followed by a value. + [1], [], [ovs-vsctl: datapath_id:y,z: argument does not end in "=", "!=", "<", ">", "<=", ">=", "{=}", "{!=}", "{<}", "{>}", "{<=}", "{>=}", "{in}", or "{not-in}" followed by a value. ]) AT_CHECK([RUN_OVS_VSCTL([get bridge br0 datapath_id::])], [1], [], [ovs-vsctl: datapath_id::: trailing garbage ":" in argument @@ -1198,10 +1198,16 @@ VSCTL_CHECK_FIND([flood_vlans{!=}3], [br0 br1 br2 br3 br4 br5 br6 br7]) VSCTL_CHECK_FIND([flood_vlans{<}[[]]], []) VSCTL_CHECK_FIND([flood_vlans{<=}[[]]], [br0]) +VSCTL_CHECK_FIND([flood_vlans{in}[[]]], [br0]) +VSCTL_CHECK_FIND([flood_vlans{not-in}[[]]], [br0 br1 br2 br3 br4 br5 br6 br7]) VSCTL_CHECK_FIND([flood_vlans{<}0], [br0]) VSCTL_CHECK_FIND([flood_vlans{<=}0], [br0 br1]) +VSCTL_CHECK_FIND([flood_vlans{in}0], [br0 br1]) +VSCTL_CHECK_FIND([flood_vlans{not-in}0], [br0 br2 br4 br6]) VSCTL_CHECK_FIND([flood_vlans{<}1,2], [br0 br2 br4]) VSCTL_CHECK_FIND([flood_vlans{<=}1,2], [br0 br2 br4 br6]) +VSCTL_CHECK_FIND([flood_vlans{in}1,2], [br0 br2 br4 br6]) +VSCTL_CHECK_FIND([flood_vlans{not-in}1,2], [br0 br1]) VSCTL_CHECK_FIND([flood_vlans{>}[[]]], [br1 br2 br3 br4 br5 br6 br7]) VSCTL_CHECK_FIND([flood_vlans{>=}[[]]], [br0 br1 br2 br3 br4 br5 br6 br7]) @@ -1260,6 +1266,20 @@ VSCTL_CHECK_FIND([other-config:x{>}x], []) VSCTL_CHECK_FIND([other-config:x{>}""], []) VSCTL_CHECK_FIND([other-config:x{>}y], []) VSCTL_CHECK_FIND([other-config:x{>}z], []) + +VSCTL_CHECK_FIND([other-config:x{in}[[]]], [br0 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{in}x], [br0 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{in}""], [br0 br1 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{in}y], [br0 br2 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{in}z], [br0 br3 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{in}x,y,z], [br0 br2 br3 br4 br5 br6 br7]) + +VSCTL_CHECK_FIND([other-config:x{not-in}[[]]], [br0 br1 br2 br3 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{not-in}x], [br0 br1 br2 br3 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{not-in}""], [br0 br2 br3 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{not-in}y], [br0 br1 br3 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{not-in}z], [br0 br1 br2 br4 br5 br6 br7]) +VSCTL_CHECK_FIND([other-config:x{not-in}x,y,z], [br0 br1 br4 br5 br6 br7]) OVS_VSCTL_CLEANUP AT_CLEANUP