[ovs-dev] [PATCH ovn] northd: add --event option to enable controller_event for empty_lb

Lorenzo Bianconi lorenzo.bianconi at redhat.com
Fri Jan 22 17:25:54 UTC 2021


Introduce the --event option to enable empty_lb controller event for a
load_balancer with no backends (doing so the option is per-lb and not
global).

$ovn-nbctl --event lb-add lb0 192.168.0.100:80 ""

controller_event_en global variable is not removed for backward
compatibility but it is deprecated

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at redhat.com>
---
 northd/ovn-northd.c       |  5 ++++-
 tests/ovn.at              |  7 +++----
 utilities/ovn-nbctl.8.xml | 10 +++++++++-
 utilities/ovn-nbctl.c     | 13 ++++++++++++-
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index 27df6a379..e92c75726 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -4860,7 +4860,9 @@ build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows,
                           struct nbrec_load_balancer *lb,
                           int pl, struct shash *meter_groups)
 {
-    if (!controller_event_en || lb_vip->n_backends ||
+    bool controller_event = smap_get_bool(&lb->options, "event", false) ||
+                            controller_event_en; /* deprecated */
+    if (!controller_event || lb_vip->n_backends ||
         lb_vip->empty_backend_rej) {
         return;
     }
@@ -12611,6 +12613,7 @@ ovnnb_db_run(struct northd_context *ctx,
 
     use_logical_dp_groups = smap_get_bool(&nb->options,
                                           "use_logical_dp_groups", false);
+    /* deprecated, use --event instead */
     controller_event_en = smap_get_bool(&nb->options,
                                         "controller_event", false);
     check_lsp_is_up = !smap_get_bool(&nb->options,
diff --git a/tests/ovn.at b/tests/ovn.at
index 8f884241d..5bc8331b1 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -16947,16 +16947,15 @@ ovs-vsctl -- add-port br-int vif33 -- \
         options:rxq_pcap=hv$i/vif33-rx.pcap \
         ofport-request=33
 
-ovn-nbctl --wait=hv set NB_Global . options:controller_event=true
-ovn-nbctl lb-add lb0 192.168.1.100:80 ""
+ovn-nbctl --event lb-add lb0 192.168.1.100:80 ""
 ovn-nbctl ls-lb-add sw0 lb0
 uuid_lb0=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb0)
 
-ovn-nbctl lb-add lb1 192.168.2.100:80 ""
+ovn-nbctl --event lb-add lb1 192.168.2.100:80 ""
 ovn-nbctl lr-lb-add lr0 lb1
 uuid_lb1=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb1)
 
-ovn-nbctl lb-add lb2 [[2001::10]]:50051 ""
+ovn-nbctl --event lb-add lb2 [[2001::10]]:50051 ""
 ovn-nbctl ls-lb-add sw0 lb2
 uuid_lb2=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb2)
 
diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml
index e6fec9980..6ed8bcb75 100644
--- a/utilities/ovn-nbctl.8.xml
+++ b/utilities/ovn-nbctl.8.xml
@@ -905,7 +905,7 @@
 
     <h1>Load Balancer Commands</h1>
     <dl>
-        <dt>[<code>--may-exist</code> | <code>--add-duplicate</code> | <code>--reject</code>] <code>lb-add</code> <var>lb</var> <var>vip</var> <var>ips</var> [<var>protocol</var>]</dt>
+        <dt>[<code>--may-exist</code> | <code>--add-duplicate</code> | <code>--reject</code> | <code>--event</code>] <code>lb-add</code> <var>lb</var> <var>vip</var> <var>ips</var> [<var>protocol</var>]</dt>
       <dd>
         <p>
          Creates a new load balancer named <var>lb</var> with the provided
@@ -947,6 +947,14 @@
          empty_lb SB controller event for this load balancer.
         </p>
 
+        <p>
+         If the load balancer is created with <code>--event</code> option and
+         it has no active backends, whenever the lb receives traffic, the event
+         is reported in the Controller_Event table in the SB db.
+         Please note <code>--event</code> option can't be specified with
+         <code>--reject</code> one.
+        </p>
+
         <p>
          The following example adds a load balancer.
         </p>
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
index 2342ead4e..6eaae0866 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -2836,6 +2836,13 @@ nbctl_lb_add(struct ctl_context *ctx)
     bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
     bool add_duplicate = shash_find(&ctx->options, "--add-duplicate") != NULL;
     bool empty_backend_rej = shash_find(&ctx->options, "--reject") != NULL;
+    bool empty_backend_event = shash_find(&ctx->options, "--event") != NULL;
+
+    if (empty_backend_event && empty_backend_rej) {
+            ctl_error(ctx,
+                      "--reject and --event can't specified at the same time");
+            return;
+    }
 
     const char *lb_proto;
     bool is_update_proto = false;
@@ -2953,6 +2960,10 @@ nbctl_lb_add(struct ctl_context *ctx)
         const struct smap options = SMAP_CONST1(&options, "reject", "true");
         nbrec_load_balancer_set_options(lb, &options);
     }
+    if (empty_backend_event) {
+        const struct smap options = SMAP_CONST1(&options, "event", "true");
+        nbrec_load_balancer_set_options(lb, &options);
+    }
 out:
     ds_destroy(&lb_ips_new);
 
@@ -6517,7 +6528,7 @@ static const struct ctl_command_syntax nbctl_commands[] = {
       nbctl_lr_nat_set_ext_ips, NULL, "--is-exempted", RW},
     /* load balancer commands. */
     { "lb-add", 3, 4, "LB VIP[:PORT] IP[:PORT]... [PROTOCOL]", NULL,
-      nbctl_lb_add, NULL, "--may-exist,--add-duplicate,--reject", RW },
+      nbctl_lb_add, NULL, "--may-exist,--add-duplicate,--reject,--event", RW },
     { "lb-del", 1, 2, "LB [VIP]", NULL, nbctl_lb_del, NULL,
         "--if-exists", RW },
     { "lb-list", 0, 1, "[LB]", NULL, nbctl_lb_list, NULL, "", RO },
-- 
2.29.2



More information about the dev mailing list