diff mbox series

[ovs-dev] db-ctl-base: Add {in} and {not-in} set relational operators.

Message ID 20201111232244.628803-1-blp@ovn.org
State New
Headers show
Series [ovs-dev] db-ctl-base: Add {in} and {not-in} set relational operators. | expand

Commit Message

Ben Pfaff Nov. 11, 2020, 11:22 p.m. UTC
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 <blp@ovn.org>
---
 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(-)

Comments

0-day Robot Nov. 11, 2020, 11:59 p.m. UTC | #1
Bleep bloop.  Greetings Ben Pfaff, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line has non-spaces leading whitespace
WARNING: Line has trailing whitespace
#130 FILE: lib/db-ctl-base.xml:162:
        

WARNING: Line is 94 characters long (recommended limit is 79)
#150 FILE: lib/db-ctl-base.xml:375:
        <var>column</var> contains a <var>key</var> with the specified <var>value</var>.  This

Lines checked: 209, Warnings: 3, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

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 <code>flood-vlans</code> column contains both 1
           and 2.
         </dd>
+      </dl>
+
+      <p>
+        The following operators are available only in Open vSwitch 2.15 and
+        later:
+      </p>
 
+      <dl
+        <dt><code>{in}</code></dt>
+        <dd>
+          Selects records in which every element in
+          <var>column</var>[<code>:</code><var>key</var>] is also in
+          <var>value</var>.  (This is the same as <code>{&lt;=}</code>.)
+        </dd>
+        
+        <dt><code>{not-in}</code></dt>
+        <dd>
+          Selects records in which every element in
+          <var>column</var>[<code>:</code><var>key</var>] is not in
+          <var>value</var>.
+        </dd>
       </dl>
 
       <p>
@@ -352,12 +372,9 @@ 
       <p>
         Waits until <var>table</var> contains a record named <var>record</var> whose
         <var>column</var> equals <var>value</var> or, if <var>key</var> is specified, whose
-        <var>column</var> contains a <var>key</var> with the specified <var>value</var>.  Any
-        of the operators <code>!=</code>, <code>&lt;</code>, <code>&gt;</code>, <code>&lt;=</code>, or <code>&gt;=</code> may
-        be substituted for <code>=</code> 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 <code>&lt;</code> or <code>&gt;</code> from
-        interpretation by the shell.)
+        <var>column</var> contains a <var>key</var> with the specified <var>value</var>.  This
+        command supports the same operators and semantics described for the
+        <code>find</code> command above.
       </p>
       <p>
         If no <var>column</var>[<code>:</code><var>key</var>]<code>=</code><var>value</var> 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