5f9769
From 5e1bb597df512510dc82ce47f9b65a02e2fb5c0b Mon Sep 17 00:00:00 2001
5f9769
Message-Id: <5e1bb597df512510dc82ce47f9b65a02e2fb5c0b.1611833004.git.lorenzo.bianconi@redhat.com>
5f9769
In-Reply-To: <8770192b3b4732e02679f723ea5903a515c6bd8a.1611833004.git.lorenzo.bianconi@redhat.com>
5f9769
References: <8770192b3b4732e02679f723ea5903a515c6bd8a.1611833004.git.lorenzo.bianconi@redhat.com>
5f9769
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
5f9769
Date: Mon, 25 Jan 2021 14:51:13 +0100
5f9769
Subject: [PATCH 2/2] ovn-nbctl: add ecmp/ecmp-symmetric-reply to lr-route-list
5f9769
 command
5f9769
5f9769
Explicitly add ecmp/ecmp-symmetric-reply info to ovn-nbctl
5f9769
lr-route-list command
5f9769
5f9769
https://bugzilla.redhat.com/show_bug.cgi?id=1915958
5f9769
5f9769
Acked-by: Mark Michelson <mmichels@redhat.com>
5f9769
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
5f9769
Signed-off-by: Numan Siddique <numans@ovn.org>
5f9769
---
5f9769
 tests/ovn-nbctl.at    | 36 ++++++++++++++---------
5f9769
 utilities/ovn-nbctl.c | 67 +++++++++++++++++++++++++++++++++++--------
5f9769
 2 files changed, 78 insertions(+), 25 deletions(-)
5f9769
5f9769
--- a/tests/ovn-nbctl.at
5f9769
+++ b/tests/ovn-nbctl.at
5f9769
@@ -1544,27 +1544,27 @@ AT_CHECK([ovn-nbctl --ecmp lr-route-add
5f9769
 AT_CHECK([ovn-nbctl --ecmp lr-route-add lr0 10.0.0.0/24 11.0.0.3 lp0])
5f9769
 AT_CHECK([ovn-nbctl lr-route-list lr0], [0], [dnl
5f9769
 IPv4 Routes
5f9769
-              10.0.0.0/24                  11.0.0.1 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.2 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.2 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.3 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.3 dst-ip lp0
5f9769
+              10.0.0.0/24                  11.0.0.1 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.2 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.2 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.3 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.3 dst-ip lp0 ecmp
5f9769
 ])
5f9769
 
5f9769
 dnl Delete ecmp routes
5f9769
 AT_CHECK([ovn-nbctl lr-route-del lr0 10.0.0.0/24 11.0.0.1])
5f9769
 AT_CHECK([ovn-nbctl lr-route-list lr0], [0], [dnl
5f9769
 IPv4 Routes
5f9769
-              10.0.0.0/24                  11.0.0.2 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.2 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.3 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.3 dst-ip lp0
5f9769
+              10.0.0.0/24                  11.0.0.2 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.2 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.3 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.3 dst-ip lp0 ecmp
5f9769
 ])
5f9769
 AT_CHECK([ovn-nbctl lr-route-del lr0 10.0.0.0/24 11.0.0.2])
5f9769
 AT_CHECK([ovn-nbctl lr-route-list lr0], [0], [dnl
5f9769
 IPv4 Routes
5f9769
-              10.0.0.0/24                  11.0.0.3 dst-ip
5f9769
-              10.0.0.0/24                  11.0.0.3 dst-ip lp0
5f9769
+              10.0.0.0/24                  11.0.0.3 dst-ip ecmp
5f9769
+              10.0.0.0/24                  11.0.0.3 dst-ip lp0 ecmp
5f9769
 ])
5f9769
 AT_CHECK([ovn-nbctl lr-route-del lr0 10.0.0.0/24 11.0.0.3 lp0])
5f9769
 AT_CHECK([ovn-nbctl lr-route-list lr0], [0], [dnl
5f9769
@@ -1605,7 +1605,12 @@ AT_CHECK([ovn-nbctl lr-route-add lr0 10.
5f9769
 AT_CHECK([ovn-nbctl lr-route-add lr0 10.0.0.1/24 11.0.0.1])
5f9769
 AT_CHECK([ovn-nbctl lr-route-add lr0 0:0:0:0:0:0:0:0/0 2001:0db8:0:f101::1])
5f9769
 AT_CHECK([ovn-nbctl lr-route-add lr0 2001:0db8:0::/64 2001:0db8:0:f102::1 lp0])
5f9769
-AT_CHECK([ovn-nbctl lr-route-add lr0 2001:0db8:1::/64 2001:0db8:0:f103::1])
5f9769
+AT_CHECK([ovn-nbctl --ecmp lr-route-add lr0 2001:0db8:1::/64 2001:0db8:0:f103::1])
5f9769
+AT_CHECK([ovn-nbctl --ecmp lr-route-add lr0 2001:0db8:1::/64 2001:0db8:0:f103::2])
5f9769
+AT_CHECK([ovn-nbctl --ecmp lr-route-add lr0 2001:0db8:1::/64 2001:0db8:0:f103::3])
5f9769
+AT_CHECK([ovn-nbctl --ecmp lr-route-add lr0 2001:0db8:1::/64 2001:0db8:0:f103::4])
5f9769
+AT_CHECK([ovn-nbctl lr-route-add lr0 2002:0db8:1::/64 2001:0db8:0:f103::5])
5f9769
+AT_CHECK([ovn-nbctl --ecmp-symmetric-reply lr-route-add lr0 2003:0db8:1::/64 2001:0db8:0:f103::6])
5f9769
 
5f9769
 AT_CHECK([ovn-nbctl lr-route-list lr0], [0], [dnl
5f9769
 IPv4 Routes
5f9769
@@ -1615,7 +1620,12 @@ IPv4 Routes
5f9769
 
5f9769
 IPv6 Routes
5f9769
             2001:db8::/64        2001:db8:0:f102::1 dst-ip lp0
5f9769
-          2001:db8:1::/64        2001:db8:0:f103::1 dst-ip
5f9769
+          2001:db8:1::/64        2001:db8:0:f103::1 dst-ip ecmp
5f9769
+          2001:db8:1::/64        2001:db8:0:f103::2 dst-ip ecmp
5f9769
+          2001:db8:1::/64        2001:db8:0:f103::3 dst-ip ecmp
5f9769
+          2001:db8:1::/64        2001:db8:0:f103::4 dst-ip ecmp
5f9769
+          2002:db8:1::/64        2001:db8:0:f103::5 dst-ip
5f9769
+          2003:db8:1::/64        2001:db8:0:f103::6 dst-ip ecmp-symmetric-reply
5f9769
                      ::/0        2001:db8:0:f101::1 dst-ip
5f9769
 ])
5f9769
 
5f9769
--- a/utilities/ovn-nbctl.c
5f9769
+++ b/utilities/ovn-nbctl.c
5f9769
@@ -5443,16 +5443,26 @@ struct ipv4_route {
5f9769
 };
5f9769
 
5f9769
 static int
5f9769
+__ipv4_route_cmp(const struct ipv4_route *r1, const struct ipv4_route *r2)
5f9769
+{
5f9769
+    if (r1->priority != r2->priority) {
5f9769
+        return r1->priority > r2->priority ? -1 : 1;
5f9769
+    }
5f9769
+    if (r1->addr != r2->addr) {
5f9769
+        return ntohl(r1->addr) < ntohl(r2->addr) ? -1 : 1;
5f9769
+    }
5f9769
+    return 0;
5f9769
+}
5f9769
+
5f9769
+static int
5f9769
 ipv4_route_cmp(const void *route1_, const void *route2_)
5f9769
 {
5f9769
     const struct ipv4_route *route1p = route1_;
5f9769
     const struct ipv4_route *route2p = route2_;
5f9769
 
5f9769
-    if (route1p->priority != route2p->priority) {
5f9769
-        return route1p->priority > route2p->priority ? -1 : 1;
5f9769
-    }
5f9769
-    if (route1p->addr != route2p->addr) {
5f9769
-        return ntohl(route1p->addr) < ntohl(route2p->addr) ? -1 : 1;
5f9769
+    int ret = __ipv4_route_cmp(route1p, route2p);
5f9769
+    if (ret) {
5f9769
+        return ret;
5f9769
     }
5f9769
     return route_cmp_details(route1p->route, route2p->route);
5f9769
 }
5f9769
@@ -5464,15 +5474,21 @@ struct ipv6_route {
5f9769
 };
5f9769
 
5f9769
 static int
5f9769
+__ipv6_route_cmp(const struct ipv6_route *r1, const struct ipv6_route *r2)
5f9769
+{
5f9769
+    if (r1->priority != r2->priority) {
5f9769
+        return r1->priority > r2->priority ? -1 : 1;
5f9769
+    }
5f9769
+    return memcmp(&r1->addr, &r2->addr, sizeof(r1->addr));
5f9769
+}
5f9769
+
5f9769
+static int
5f9769
 ipv6_route_cmp(const void *route1_, const void *route2_)
5f9769
 {
5f9769
     const struct ipv6_route *route1p = route1_;
5f9769
     const struct ipv6_route *route2p = route2_;
5f9769
 
5f9769
-    if (route1p->priority != route2p->priority) {
5f9769
-        return route1p->priority > route2p->priority ? -1 : 1;
5f9769
-    }
5f9769
-    int ret = memcmp(&route1p->addr, &route2p->addr, sizeof(route1p->addr));
5f9769
+    int ret = __ipv6_route_cmp(route1p, route2p);
5f9769
     if (ret) {
5f9769
         return ret;
5f9769
     }
5f9769
@@ -5480,7 +5496,8 @@ ipv6_route_cmp(const void *route1_, cons
5f9769
 }
5f9769
 
5f9769
 static void
5f9769
-print_route(const struct nbrec_logical_router_static_route *route, struct ds *s)
5f9769
+print_route(const struct nbrec_logical_router_static_route *route,
5f9769
+            struct ds *s, bool ecmp)
5f9769
 {
5f9769
 
5f9769
     char *prefix = normalize_prefix_str(route->ip_prefix);
5f9769
@@ -5503,6 +5520,14 @@ print_route(const struct nbrec_logical_r
5f9769
         ds_put_format(s, " (learned)");
5f9769
     }
5f9769
 
5f9769
+    if (ecmp) {
5f9769
+        ds_put_cstr(s, " ecmp");
5f9769
+    }
5f9769
+
5f9769
+    if (smap_get_bool(&route->options, "ecmp_symmetric_reply", false)) {
5f9769
+        ds_put_cstr(s, " ecmp-symmetric-reply");
5f9769
+    }
5f9769
+
5f9769
     if (route->bfd) {
5f9769
         ds_put_cstr(s, " bfd");
5f9769
     }
5f9769
@@ -5572,7 +5597,16 @@ nbctl_lr_route_list(struct ctl_context *
5f9769
         ds_put_cstr(&ctx->output, "IPv4 Routes\n");
5f9769
     }
5f9769
     for (int i = 0; i < n_ipv4_routes; i++) {
5f9769
-        print_route(ipv4_routes[i].route, &ctx->output);
5f9769
+        bool ecmp = false;
5f9769
+        if (i < n_ipv4_routes - 1 &&
5f9769
+            !__ipv4_route_cmp(&ipv4_routes[i], &ipv4_routes[i + 1])) {
5f9769
+            ecmp = true;
5f9769
+        } else if (i > 0 &&
5f9769
+                   !__ipv4_route_cmp(&ipv4_routes[i],
5f9769
+                                     &ipv4_routes[i - 1])) {
5f9769
+            ecmp = true;
5f9769
+        }
5f9769
+        print_route(ipv4_routes[i].route, &ctx->output, ecmp);
5f9769
     }
5f9769
 
5f9769
     if (n_ipv6_routes) {
5f9769
@@ -5580,7 +5614,16 @@ nbctl_lr_route_list(struct ctl_context *
5f9769
                       n_ipv4_routes ?  "\n" : "");
5f9769
     }
5f9769
     for (int i = 0; i < n_ipv6_routes; i++) {
5f9769
-        print_route(ipv6_routes[i].route, &ctx->output);
5f9769
+        bool ecmp = false;
5f9769
+        if (i < n_ipv6_routes - 1 &&
5f9769
+            !__ipv6_route_cmp(&ipv6_routes[i], &ipv6_routes[i + 1])) {
5f9769
+            ecmp = true;
5f9769
+        } else if (i > 0 &&
5f9769
+                   !__ipv6_route_cmp(&ipv6_routes[i],
5f9769
+                                     &ipv6_routes[i - 1])) {
5f9769
+            ecmp = true;
5f9769
+        }
5f9769
+        print_route(ipv6_routes[i].route, &ctx->output, ecmp);
5f9769
     }
5f9769
 
5f9769
     free(ipv4_routes);