diff mbox series

[ovs-dev,v2] ovn-nbctl: report peer addresses running lsp-get-addresses for patch ports

Message ID ef35a598c1703fc77907bc016ad51b9077516703.1642694860.git.lorenzo.bianconi@redhat.com
State Accepted
Headers show
Series [ovs-dev,v2] ovn-nbctl: report peer addresses running lsp-get-addresses for patch ports | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Lorenzo Bianconi Jan. 20, 2022, 4:09 p.m. UTC
Report logical router port addresses running lsp-get-addresses if the
logical switch port address is set to "router".

Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2028040
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
Changes since v1:
- rely on lrp_by_name_or_uuid
---
 tests/ovn-nbctl.at    | 10 ++++++++++
 utilities/ovn-nbctl.c | 29 +++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 4 deletions(-)

Comments

Numan Siddique Feb. 11, 2022, 6:17 p.m. UTC | #1
On Thu, Jan 20, 2022 at 11:09 AM Lorenzo Bianconi
<lorenzo.bianconi@redhat.com> wrote:
>
> Report logical router port addresses running lsp-get-addresses if the
> logical switch port address is set to "router".
>
> Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2028040
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
> Changes since v1:
> - rely on lrp_by_name_or_uuid

Thanks for v2.  I applied this patch to the main branch.

Numan

> ---
>  tests/ovn-nbctl.at    | 10 ++++++++++
>  utilities/ovn-nbctl.c | 29 +++++++++++++++++++++++++----
>  2 files changed, 35 insertions(+), 4 deletions(-)
>
> diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
> index a43a1ce8f..539a121c0 100644
> --- a/tests/ovn-nbctl.at
> +++ b/tests/ovn-nbctl.at
> @@ -181,6 +181,16 @@ unknown
>
>  AT_CHECK([ovn-nbctl lsp-set-addresses lp0])
>  AT_CHECK([ovn-nbctl lsp-get-addresses lp0], [0], [dnl
> +])
> +
> +AT_CHECK([ovn-nbctl lr-add lr0])
> +AT_CHECK([ovn-nbctl lrp-add lr0 rp-ls0 aa:bb:bb:00:00:01 192.168.0.1/24])
> +AT_CHECK([ovn-nbctl lsp-add ls0 ls0-rp])
> +AT_CHECK([ovn-nbctl lsp-set-addresses ls0-rp router])
> +AT_CHECK([ovn-nbctl lsp-set-type ls0-rp router])
> +AT_CHECK([ovn-nbctl lsp-set-options ls0-rp router-port=rp-ls0])
> +AT_CHECK([ovn-nbctl lsp-get-addresses ls0-rp], [0], [dnl
> +aa:bb:bb:00:00:01 192.168.0.1/24
>  ])])
>
>  dnl ---------------------------------------------------------------------
> diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
> index 55b0f5124..f3209417a 100644
> --- a/utilities/ovn-nbctl.c
> +++ b/utilities/ovn-nbctl.c
> @@ -1494,8 +1494,18 @@ nbctl_pre_lsp_get_addresses(struct ctl_context *ctx)
>  {
>      ovsdb_idl_add_column(ctx->idl, &nbrec_logical_switch_port_col_name);
>      ovsdb_idl_add_column(ctx->idl, &nbrec_logical_switch_port_col_addresses);
> +    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_switch_port_col_options);
> +
> +    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_col_ports);
> +    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_port_col_name);
> +    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_port_col_mac);
> +    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_port_col_networks);
>  }
>
> +static char * OVS_WARN_UNUSED_RESULT
> +lrp_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
> +                    const struct nbrec_logical_router_port **lrp_p);
> +
>  static void
>  nbctl_lsp_get_addresses(struct ctl_context *ctx)
>  {
> @@ -1511,6 +1521,21 @@ nbctl_lsp_get_addresses(struct ctl_context *ctx)
>          return;
>      }
>
> +    const char *router_port = smap_get(&lsp->options, "router-port");
> +    if (lsp->n_addresses == 1 && !strcmp(lsp->addresses[0], "router") &&
> +        router_port) {
> +        const struct nbrec_logical_router_port *lrp;
> +        error = lrp_by_name_or_uuid(ctx, router_port, false, &lrp);
> +        if (lrp) {
> +            ds_put_format(&ctx->output, "%s", lrp->mac);
> +            for (size_t j = 0; j < lrp->n_networks; j++) {
> +                ds_put_format(&ctx->output, " %s", lrp->networks[j]);
> +            }
> +            ds_put_cstr(&ctx->output, "\n");
> +            return;
> +        }
> +    }
> +
>      svec_init(&addresses);
>      for (i = 0; i < lsp->n_addresses; i++) {
>          svec_add(&addresses, lsp->addresses[i]);
> @@ -4108,10 +4133,6 @@ nbctl_pre_lr_route_add(struct ctl_context *ctx)
>                           &nbrec_logical_router_static_route_col_external_ids);
>  }
>
> -static char * OVS_WARN_UNUSED_RESULT
> -lrp_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
> -                    const struct nbrec_logical_router_port **lrp_p);
> -
>  static void
>  nbctl_lr_route_add(struct ctl_context *ctx)
>  {
> --
> 2.34.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox series

Patch

diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
index a43a1ce8f..539a121c0 100644
--- a/tests/ovn-nbctl.at
+++ b/tests/ovn-nbctl.at
@@ -181,6 +181,16 @@  unknown
 
 AT_CHECK([ovn-nbctl lsp-set-addresses lp0])
 AT_CHECK([ovn-nbctl lsp-get-addresses lp0], [0], [dnl
+])
+
+AT_CHECK([ovn-nbctl lr-add lr0])
+AT_CHECK([ovn-nbctl lrp-add lr0 rp-ls0 aa:bb:bb:00:00:01 192.168.0.1/24])
+AT_CHECK([ovn-nbctl lsp-add ls0 ls0-rp])
+AT_CHECK([ovn-nbctl lsp-set-addresses ls0-rp router])
+AT_CHECK([ovn-nbctl lsp-set-type ls0-rp router])
+AT_CHECK([ovn-nbctl lsp-set-options ls0-rp router-port=rp-ls0])
+AT_CHECK([ovn-nbctl lsp-get-addresses ls0-rp], [0], [dnl
+aa:bb:bb:00:00:01 192.168.0.1/24
 ])])
 
 dnl ---------------------------------------------------------------------
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
index 55b0f5124..f3209417a 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -1494,8 +1494,18 @@  nbctl_pre_lsp_get_addresses(struct ctl_context *ctx)
 {
     ovsdb_idl_add_column(ctx->idl, &nbrec_logical_switch_port_col_name);
     ovsdb_idl_add_column(ctx->idl, &nbrec_logical_switch_port_col_addresses);
+    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_switch_port_col_options);
+
+    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_col_ports);
+    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_port_col_name);
+    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_port_col_mac);
+    ovsdb_idl_add_column(ctx->idl, &nbrec_logical_router_port_col_networks);
 }
 
+static char * OVS_WARN_UNUSED_RESULT
+lrp_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
+                    const struct nbrec_logical_router_port **lrp_p);
+
 static void
 nbctl_lsp_get_addresses(struct ctl_context *ctx)
 {
@@ -1511,6 +1521,21 @@  nbctl_lsp_get_addresses(struct ctl_context *ctx)
         return;
     }
 
+    const char *router_port = smap_get(&lsp->options, "router-port");
+    if (lsp->n_addresses == 1 && !strcmp(lsp->addresses[0], "router") &&
+        router_port) {
+        const struct nbrec_logical_router_port *lrp;
+        error = lrp_by_name_or_uuid(ctx, router_port, false, &lrp);
+        if (lrp) {
+            ds_put_format(&ctx->output, "%s", lrp->mac);
+            for (size_t j = 0; j < lrp->n_networks; j++) {
+                ds_put_format(&ctx->output, " %s", lrp->networks[j]);
+            }
+            ds_put_cstr(&ctx->output, "\n");
+            return;
+        }
+    }
+
     svec_init(&addresses);
     for (i = 0; i < lsp->n_addresses; i++) {
         svec_add(&addresses, lsp->addresses[i]);
@@ -4108,10 +4133,6 @@  nbctl_pre_lr_route_add(struct ctl_context *ctx)
                          &nbrec_logical_router_static_route_col_external_ids);
 }
 
-static char * OVS_WARN_UNUSED_RESULT
-lrp_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
-                    const struct nbrec_logical_router_port **lrp_p);
-
 static void
 nbctl_lr_route_add(struct ctl_context *ctx)
 {