Introduce the LB.option.dynamic-routing-advertise parameter in order to
enable/disable the advertisement of a specific LB VIP if the CMS
configures LRP dynamic-routing-redistribute option to lb.

Reported-at: https://redhat.atlassian.net/browse/FDP-2743
Signed-off-by: Lorenzo Bianconi <[email protected]>
---
 northd/en-advertised-route-sync.c |  4 ++--
 northd/en-lr-stateful.c           | 38 ++++++++++++++++++++++++++++++-
 northd/lb.c                       | 22 ++++++++++++++++--
 northd/lb.h                       |  4 +++-
 ovn-nb.xml                        |  7 ++++++
 tests/ovn-northd.at               | 10 ++++++++
 6 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/northd/en-advertised-route-sync.c 
b/northd/en-advertised-route-sync.c
index bb08cda68..adccfd5e3 100644
--- a/northd/en-advertised-route-sync.c
+++ b/northd/en-advertised-route-sync.c
@@ -302,11 +302,11 @@ build_lb_route_for_port(const struct ovn_port 
*advertising_op,
     const struct ovn_datapath *advertising_od = advertising_op->od;
 
     const char *ip_address;
-    SSET_FOR_EACH (ip_address, &lb_ips->ips_v4) {
+    SSET_FOR_EACH (ip_address, &lb_ips->ips_v4_adv) {
         ar_entry_add(routes, advertising_od, advertising_op,
                      ip_address, tracked_port, ROUTE_SOURCE_LB);
     }
-    SSET_FOR_EACH (ip_address, &lb_ips->ips_v6) {
+    SSET_FOR_EACH (ip_address, &lb_ips->ips_v6_adv) {
         ar_entry_add(routes, advertising_od, advertising_op,
                      ip_address, tracked_port, ROUTE_SOURCE_LB);
     }
diff --git a/northd/en-lr-stateful.c b/northd/en-lr-stateful.c
index 97a8d4d96..695c1adab 100644
--- a/northd/en-lr-stateful.c
+++ b/northd/en-lr-stateful.c
@@ -78,6 +78,10 @@ static void remove_lrouter_lb_reachable_ips(struct 
lr_stateful_record *,
                                             enum lb_neighbor_responder_mode,
                                             const struct sset *lb_ips_v4,
                                             const struct sset *lb_ips_v6);
+static void update_lrouter_lb_adv_ips(struct lr_stateful_record *,
+                                      bool advertise,
+                                      const struct sset *lb_ips_v4,
+                                      const struct sset *lb_ips_v6);
 static bool lr_stateful_rebuild_vip_nats(struct lr_stateful_record *);
 
 /* 'lr_stateful' engine node manages the NB logical router LB data.
@@ -242,6 +246,10 @@ lr_stateful_lb_data_handler(struct engine_node *node, void 
*data_)
         const struct uuid *lb_uuid = &clb->lb->nlb->header_.uuid;
         const struct ovn_northd_lb *lb = clb->lb;
 
+        bool advertise = lb->nlb
+            ? smap_get_bool(&lb->nlb->options,
+                            "dynamic-routing-advertise", true)
+            : true;
         const struct ovn_lb_datapaths *lb_dps = ovn_lb_datapaths_find(
             input_data.lb_datapaths_map, lb_uuid);
         ovs_assert(lb_dps);
@@ -260,13 +268,16 @@ lr_stateful_lb_data_handler(struct engine_node *node, 
void *data_)
             remove_ips_from_lb_ip_set(lr_stateful_rec->lb_ips, lb->routable,
                                       &clb->deleted_vips_v4,
                                       &clb->deleted_vips_v6);
-            add_ips_to_lb_ip_set(lr_stateful_rec->lb_ips, lb->routable,
+            add_ips_to_lb_ip_set(lr_stateful_rec->lb_ips,
+                                 lb->routable, advertise,
                                  &clb->inserted_vips_v4,
                                  &clb->inserted_vips_v6);
 
             remove_lrouter_lb_reachable_ips(lr_stateful_rec, lb->neigh_mode,
                                             &clb->deleted_vips_v4,
                                             &clb->deleted_vips_v6);
+            update_lrouter_lb_adv_ips(lr_stateful_rec, advertise,
+                                      &lb->ips_v4, &lb->ips_v6);
             add_neigh_ips_to_lrouter(lr_stateful_rec, od, lb->neigh_mode,
                                      &clb->inserted_vips_v4,
                                      &clb->inserted_vips_v6);
@@ -653,6 +664,31 @@ remove_lrouter_lb_reachable_ips(struct lr_stateful_record 
*lr_stateful_rec,
     }
 }
 
+static void
+update_lrouter_lb_adv_ips(struct lr_stateful_record *lr_stateful_rec,
+                          bool advertise,
+                          const struct sset *lb_ips_v4,
+                          const struct sset *lb_ips_v6)
+{
+    const char *ip_address;
+    SSET_FOR_EACH (ip_address, lb_ips_v4) {
+        if (advertise) {
+            sset_add(&lr_stateful_rec->lb_ips->ips_v4_adv, ip_address);
+        } else {
+            sset_find_and_delete(&lr_stateful_rec->lb_ips->ips_v4_adv,
+                                 ip_address);
+        }
+    }
+    SSET_FOR_EACH (ip_address, lb_ips_v6) {
+        if (advertise) {
+            sset_add(&lr_stateful_rec->lb_ips->ips_v6_adv, ip_address);
+        } else {
+            sset_find_and_delete(&lr_stateful_rec->lb_ips->ips_v6_adv,
+                                 ip_address);
+        }
+    }
+}
+
 static bool
 lr_stateful_rebuild_vip_nats(struct lr_stateful_record *lr_stateful_rec)
 {
diff --git a/northd/lb.c b/northd/lb.c
index 2f683cef1..fab122c9f 100644
--- a/northd/lb.c
+++ b/northd/lb.c
@@ -48,9 +48,11 @@ ovn_lb_ip_set_create(void)
     sset_init(&lb_ip_set->ips_v4);
     sset_init(&lb_ip_set->ips_v4_routable);
     sset_init(&lb_ip_set->ips_v4_reachable);
+    sset_init(&lb_ip_set->ips_v4_adv);
     sset_init(&lb_ip_set->ips_v6);
     sset_init(&lb_ip_set->ips_v6_routable);
     sset_init(&lb_ip_set->ips_v6_reachable);
+    sset_init(&lb_ip_set->ips_v6_adv);
 
     return lb_ip_set;
 }
@@ -64,9 +66,11 @@ ovn_lb_ip_set_destroy(struct ovn_lb_ip_set *lb_ip_set)
     sset_destroy(&lb_ip_set->ips_v4);
     sset_destroy(&lb_ip_set->ips_v4_routable);
     sset_destroy(&lb_ip_set->ips_v4_reachable);
+    sset_destroy(&lb_ip_set->ips_v4_adv);
     sset_destroy(&lb_ip_set->ips_v6);
     sset_destroy(&lb_ip_set->ips_v6_routable);
     sset_destroy(&lb_ip_set->ips_v6_reachable);
+    sset_destroy(&lb_ip_set->ips_v6_adv);
     free(lb_ip_set);
 }
 
@@ -78,9 +82,11 @@ ovn_lb_ip_set_clone(struct ovn_lb_ip_set *lb_ip_set)
     sset_clone(&clone->ips_v4, &lb_ip_set->ips_v4);
     sset_clone(&clone->ips_v4_routable, &lb_ip_set->ips_v4_routable);
     sset_clone(&clone->ips_v4_reachable, &lb_ip_set->ips_v4_reachable);
+    sset_clone(&clone->ips_v4_adv, &lb_ip_set->ips_v4_adv);
     sset_clone(&clone->ips_v6, &lb_ip_set->ips_v6);
     sset_clone(&clone->ips_v6_routable, &lb_ip_set->ips_v6_routable);
     sset_clone(&clone->ips_v6_reachable, &lb_ip_set->ips_v6_reachable);
+    sset_clone(&clone->ips_v6_adv, &lb_ip_set->ips_v6_adv);
 
     return clone;
 }
@@ -639,12 +645,16 @@ void
 build_lrouter_lb_ips(struct ovn_lb_ip_set *lb_ips,
                      const struct ovn_northd_lb *lb)
 {
-    add_ips_to_lb_ip_set(lb_ips, lb->routable, &lb->ips_v4, &lb->ips_v6);
+    bool advertise = lb->nlb
+        ? smap_get_bool(&lb->nlb->options, "dynamic-routing-advertise", true)
+        : true;
+    add_ips_to_lb_ip_set(lb_ips, lb->routable, advertise,
+                         &lb->ips_v4, &lb->ips_v6);
 }
 
 void
 add_ips_to_lb_ip_set(struct ovn_lb_ip_set *lb_ips,
-                     bool is_routable,
+                     bool is_routable, bool advertise,
                      const struct sset *lb_ips_v4,
                      const struct sset *lb_ips_v6)
 {
@@ -655,12 +665,18 @@ add_ips_to_lb_ip_set(struct ovn_lb_ip_set *lb_ips,
         if (is_routable) {
             sset_add(&lb_ips->ips_v4_routable, ip_address);
         }
+        if (advertise) {
+            sset_add(&lb_ips->ips_v4_adv, ip_address);
+        }
     }
     SSET_FOR_EACH (ip_address, lb_ips_v6) {
         sset_add(&lb_ips->ips_v6, ip_address);
         if (is_routable) {
             sset_add(&lb_ips->ips_v6_routable, ip_address);
         }
+        if (advertise) {
+            sset_add(&lb_ips->ips_v6_adv, ip_address);
+        }
     }
 }
 
@@ -674,12 +690,14 @@ remove_ips_from_lb_ip_set(struct ovn_lb_ip_set *lb_ips,
 
     SSET_FOR_EACH (ip_address, lb_ips_v4) {
         sset_find_and_delete(&lb_ips->ips_v4, ip_address);
+        sset_find_and_delete(&lb_ips->ips_v4_adv, ip_address);
         if (is_routable) {
             sset_find_and_delete(&lb_ips->ips_v4_routable, ip_address);
         }
     }
     SSET_FOR_EACH (ip_address, lb_ips_v6) {
         sset_find_and_delete(&lb_ips->ips_v6, ip_address);
+        sset_find_and_delete(&lb_ips->ips_v6_adv, ip_address);
         if (is_routable) {
             sset_find_and_delete(&lb_ips->ips_v6_routable, ip_address);
         }
diff --git a/northd/lb.h b/northd/lb.h
index 97d2c4c36..db665b1d0 100644
--- a/northd/lb.h
+++ b/northd/lb.h
@@ -39,9 +39,11 @@ struct ovn_lb_ip_set {
     struct sset ips_v4;
     struct sset ips_v4_routable;
     struct sset ips_v4_reachable;
+    struct sset ips_v4_adv;
     struct sset ips_v6;
     struct sset ips_v6_routable;
     struct sset ips_v6_reachable;
+    struct sset ips_v6_adv;
 };
 
 struct ovn_lb_ip_set *ovn_lb_ip_set_create(void);
@@ -119,7 +121,7 @@ void ovn_northd_lb_reinit(struct ovn_northd_lb *,
 void build_lrouter_lb_ips(struct ovn_lb_ip_set *,
                           const struct ovn_northd_lb *);
 void add_ips_to_lb_ip_set(struct ovn_lb_ip_set *lb_ips,
-                          bool is_routable,
+                          bool is_routable, bool advertise,
                           const struct sset *lb_ips_v4,
                           const struct sset *lb_ips_v6);
 void remove_ips_from_lb_ip_set(struct ovn_lb_ip_set *lb_ips,
diff --git a/ovn-nb.xml b/ovn-nb.xml
index 28c4ebe4d..c17ab3209 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -2794,6 +2794,13 @@ or
         generated.
       </column>
 
+      <column name="options" key="dynamic-routing-advertise">
+        If the CSM set <ref column="options" key="dynamic-routing-redistribute"
+        table="Logical_Router_Port"/> to <code>lb</code>, this parameter is
+        used by the CMS to enable/disable the advertisement of the current LB
+        Service IP via the <ref table="Advertised_Route" db="OVN_Southbound"/>
+        table.  Default: <code>true</code>.
+      </column>
     </group>
   </table>
 
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index 3dd251250..75b2ea749 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -17809,8 +17809,18 @@ check ovn-nbctl --wait=sb set NAT $lr_ext1_nat_uuid 
options:dynamic-routing-adve
 check ovn-nbctl --wait=sb set NAT $lr_ext2_nat_uuid 
options:dynamic-routing-advertise=false
 check_row_count Advertised_Route $((2 * n_ext_rtrs))
 
+lr_ext1_lb_uuid=$(fetch_column nb:Load_Balancer _uuid name=lb-ext-1)
+lr_ext2_lb_uuid=$(fetch_column nb:Load_Balancer _uuid name=lb-ext-2)
+check ovn-nbctl --wait=sb set Load_Balancer $lr_ext1_lb_uuid 
options:dynamic-routing-advertise=false
+check ovn-nbctl --wait=sb set Load_Balancer $lr_ext2_lb_uuid 
options:dynamic-routing-advertise=false
+check_row_count Advertised_Route $((2 * n_ext_rtrs - 2))
+
 check ovn-nbctl --wait=sb set NAT $lr_ext1_nat_uuid 
options:dynamic-routing-advertise=true
 check ovn-nbctl --wait=sb set NAT $lr_ext2_nat_uuid 
options:dynamic-routing-advertise=true
+check_row_count Advertised_Route $((2 * n_ext_rtrs))
+
+check ovn-nbctl --wait=sb set Load_Balancer $lr_ext1_lb_uuid 
options:dynamic-routing-advertise=true
+check ovn-nbctl --wait=sb set Load_Balancer $lr_ext2_lb_uuid 
options:dynamic-routing-advertise=true
 check_row_count Advertised_Route $n_advertised_routes
 
 OVN_CLEANUP_NORTHD
-- 
2.54.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to