Blob Blame History Raw
From 8bcee6092b931caa936ee8ac715cf6ec89d3f18d Mon Sep 17 00:00:00 2001
Message-Id: <8bcee6092b931caa936ee8ac715cf6ec89d3f18d.1611836178.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Fri, 22 Jan 2021 18:25:54 +0100
Subject: [PATCH] northd: add --event option to enable controller_event for
 empty_lb

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@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 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 f11894a4d..9f8fb3b95 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -5110,7 +5110,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;
     }
@@ -12853,6 +12855,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 aab749300..a4fafa5a8 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -16856,16 +16856,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 f61982879..47cb8db9d 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);
 
@@ -6564,7 +6575,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