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

Ilya Maximets i.maximets at ovn.org
Tue Feb 2 16:27:08 UTC 2021


On 11/12/20 12:22 AM, Ben Pfaff wrote:
> 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.

Comparison operators for set inclusion was always confusing for me.
Thanks for this change!

There are 3 things that should be done:
1. NEWS entry should moved to Post-v2.15.0 section
2. 2.15 replaced with 2.16 in lib/db-ctl-base.xml
3. whitespace issues reported by checkpatch fixed

With above changes:
Acked-by: Ilya Maximets <i.maximets at ovn.org>

> 
> Signed-off-by: Ben Pfaff <blp at 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(-)
> 
> 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>{<=}</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><</code>, <code>></code>, <code><=</code>, or <code>>=</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><</code> or <code>></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
>  
> 



More information about the dev mailing list