5f9769
From 8bcee6092b931caa936ee8ac715cf6ec89d3f18d Mon Sep 17 00:00:00 2001
5f9769
Message-Id: <8bcee6092b931caa936ee8ac715cf6ec89d3f18d.1611836178.git.lorenzo.bianconi@redhat.com>
5f9769
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
5f9769
Date: Fri, 22 Jan 2021 18:25:54 +0100
5f9769
Subject: [PATCH] northd: add --event option to enable controller_event for
5f9769
 empty_lb
5f9769
5f9769
Introduce the --event option to enable empty_lb controller event for a
5f9769
load_balancer with no backends (doing so the option is per-lb and not
5f9769
global).
5f9769
5f9769
$ovn-nbctl --event lb-add lb0 192.168.0.100:80 ""
5f9769
5f9769
controller_event_en global variable is not removed for backward
5f9769
compatibility but it is deprecated
5f9769
5f9769
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
5f9769
Signed-off-by: Numan Siddique <numans@ovn.org>
5f9769
---
5f9769
 northd/ovn-northd.c       |  5 ++++-
5f9769
 tests/ovn.at              |  7 +++----
5f9769
 utilities/ovn-nbctl.8.xml | 10 +++++++++-
5f9769
 utilities/ovn-nbctl.c     | 13 ++++++++++++-
5f9769
 4 files changed, 28 insertions(+), 7 deletions(-)
5f9769
5f9769
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
5f9769
index f11894a4d..9f8fb3b95 100644
5f9769
--- a/northd/ovn-northd.c
5f9769
+++ b/northd/ovn-northd.c
5f9769
@@ -5110,7 +5110,9 @@ build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows,
5f9769
                           struct nbrec_load_balancer *lb,
5f9769
                           int pl, struct shash *meter_groups)
5f9769
 {
5f9769
-    if (!controller_event_en || lb_vip->n_backends ||
5f9769
+    bool controller_event = smap_get_bool(&lb->options, "event", false) ||
5f9769
+                            controller_event_en; /* deprecated */
5f9769
+    if (!controller_event || lb_vip->n_backends ||
5f9769
         lb_vip->empty_backend_rej) {
5f9769
         return;
5f9769
     }
5f9769
@@ -12853,6 +12855,7 @@ ovnnb_db_run(struct northd_context *ctx,
5f9769
 
5f9769
     use_logical_dp_groups = smap_get_bool(&nb->options,
5f9769
                                           "use_logical_dp_groups", false);
5f9769
+    /* deprecated, use --event instead */
5f9769
     controller_event_en = smap_get_bool(&nb->options,
5f9769
                                         "controller_event", false);
5f9769
     check_lsp_is_up = !smap_get_bool(&nb->options,
5f9769
diff --git a/tests/ovn.at b/tests/ovn.at
5f9769
index aab749300..a4fafa5a8 100644
5f9769
--- a/tests/ovn.at
5f9769
+++ b/tests/ovn.at
5f9769
@@ -16856,16 +16856,15 @@ ovs-vsctl -- add-port br-int vif33 -- \
5f9769
         options:rxq_pcap=hv$i/vif33-rx.pcap \
5f9769
         ofport-request=33
5f9769
 
5f9769
-ovn-nbctl --wait=hv set NB_Global . options:controller_event=true
5f9769
-ovn-nbctl lb-add lb0 192.168.1.100:80 ""
5f9769
+ovn-nbctl --event lb-add lb0 192.168.1.100:80 ""
5f9769
 ovn-nbctl ls-lb-add sw0 lb0
5f9769
 uuid_lb0=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb0)
5f9769
 
5f9769
-ovn-nbctl lb-add lb1 192.168.2.100:80 ""
5f9769
+ovn-nbctl --event lb-add lb1 192.168.2.100:80 ""
5f9769
 ovn-nbctl lr-lb-add lr0 lb1
5f9769
 uuid_lb1=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb1)
5f9769
 
5f9769
-ovn-nbctl lb-add lb2 [[2001::10]]:50051 ""
5f9769
+ovn-nbctl --event lb-add lb2 [[2001::10]]:50051 ""
5f9769
 ovn-nbctl ls-lb-add sw0 lb2
5f9769
 uuid_lb2=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb2)
5f9769
 
5f9769
diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml
5f9769
index e6fec9980..6ed8bcb75 100644
5f9769
--- a/utilities/ovn-nbctl.8.xml
5f9769
+++ b/utilities/ovn-nbctl.8.xml
5f9769
@@ -905,7 +905,7 @@
5f9769
 
5f9769
     

Load Balancer Commands

5f9769
     
5f9769
-        
[--may-exist | --add-duplicate | --reject] lb-add lb vip ips [protocol]
5f9769
+        
[--may-exist | --add-duplicate | --reject | --event] lb-add lb vip ips [protocol]
5f9769
       
5f9769
         

5f9769
          Creates a new load balancer named lb with the provided
5f9769
@@ -947,6 +947,14 @@
5f9769
          empty_lb SB controller event for this load balancer.
5f9769
         

5f9769
 
5f9769
+        

5f9769
+         If the load balancer is created with --event option and
5f9769
+         it has no active backends, whenever the lb receives traffic, the event
5f9769
+         is reported in the Controller_Event table in the SB db.
5f9769
+         Please note --event option can't be specified with
5f9769
+         --reject one.
5f9769
+        

5f9769
+
5f9769
         

5f9769
          The following example adds a load balancer.
5f9769
         

5f9769
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
5f9769
index f61982879..47cb8db9d 100644
5f9769
--- a/utilities/ovn-nbctl.c
5f9769
+++ b/utilities/ovn-nbctl.c
5f9769
@@ -2836,6 +2836,13 @@ nbctl_lb_add(struct ctl_context *ctx)
5f9769
     bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
5f9769
     bool add_duplicate = shash_find(&ctx->options, "--add-duplicate") != NULL;
5f9769
     bool empty_backend_rej = shash_find(&ctx->options, "--reject") != NULL;
5f9769
+    bool empty_backend_event = shash_find(&ctx->options, "--event") != NULL;
5f9769
+
5f9769
+    if (empty_backend_event && empty_backend_rej) {
5f9769
+            ctl_error(ctx,
5f9769
+                      "--reject and --event can't specified at the same time");
5f9769
+            return;
5f9769
+    }
5f9769
 
5f9769
     const char *lb_proto;
5f9769
     bool is_update_proto = false;
5f9769
@@ -2953,6 +2960,10 @@ nbctl_lb_add(struct ctl_context *ctx)
5f9769
         const struct smap options = SMAP_CONST1(&options, "reject", "true");
5f9769
         nbrec_load_balancer_set_options(lb, &options);
5f9769
     }
5f9769
+    if (empty_backend_event) {
5f9769
+        const struct smap options = SMAP_CONST1(&options, "event", "true");
5f9769
+        nbrec_load_balancer_set_options(lb, &options);
5f9769
+    }
5f9769
 out:
5f9769
     ds_destroy(&lb_ips_new);
5f9769
 
5f9769
@@ -6564,7 +6575,7 @@ static const struct ctl_command_syntax nbctl_commands[] = {
5f9769
       nbctl_lr_nat_set_ext_ips, NULL, "--is-exempted", RW},
5f9769
     /* load balancer commands. */
5f9769
     { "lb-add", 3, 4, "LB VIP[:PORT] IP[:PORT]... [PROTOCOL]", NULL,
5f9769
-      nbctl_lb_add, NULL, "--may-exist,--add-duplicate,--reject", RW },
5f9769
+      nbctl_lb_add, NULL, "--may-exist,--add-duplicate,--reject,--event", RW },
5f9769
     { "lb-del", 1, 2, "LB [VIP]", NULL, nbctl_lb_del, NULL,
5f9769
         "--if-exists", RW },
5f9769
     { "lb-list", 0, 1, "[LB]", NULL, nbctl_lb_list, NULL, "", RO },
5f9769
-- 
5f9769
2.29.2
5f9769