diff mbox series

[ovs-dev,5/6] utilities: Add support for Logical Datapath Groups.

Message ID 20201114075653.9142-6-i.maximets@ovn.org
State New
Headers show
Series Combine Logical Flows by Logical Datapath. | expand

Commit Message

Ilya Maximets Nov. 14, 2020, 7:56 a.m. UTC
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 utilities/ovn-sbctl.c | 57 ++++++++++++++++++++++++++++++-------------
 utilities/ovn-trace.c | 35 ++++++++++++++++++--------
 2 files changed, 65 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c
index 85e448ec0..bd8c00918 100644
--- a/utilities/ovn-sbctl.c
+++ b/utilities/ovn-sbctl.c
@@ -520,7 +520,8 @@  pre_get_info(struct ctl_context *ctx)
     ovsdb_idl_add_column(ctx->idl, &sbrec_port_binding_col_chassis);
     ovsdb_idl_add_column(ctx->idl, &sbrec_port_binding_col_datapath);
 
-    ovsdb_idl_add_column(ctx->idl, &sbrec_logical_flow_col_logical_datapath);
+    ovsdb_idl_add_column(ctx->idl,
+                         &sbrec_logical_flow_col_logical_datapath_group);
     ovsdb_idl_add_column(ctx->idl, &sbrec_logical_flow_col_pipeline);
     ovsdb_idl_add_column(ctx->idl, &sbrec_logical_flow_col_actions);
     ovsdb_idl_add_column(ctx->idl, &sbrec_logical_flow_col_priority);
@@ -528,6 +529,9 @@  pre_get_info(struct ctl_context *ctx)
     ovsdb_idl_add_column(ctx->idl, &sbrec_logical_flow_col_match);
     ovsdb_idl_add_column(ctx->idl, &sbrec_logical_flow_col_external_ids);
 
+    ovsdb_idl_add_column(ctx->idl,
+                         &sbrec_logical_datapath_group_col_datapaths);
+
     ovsdb_idl_add_column(ctx->idl, &sbrec_datapath_binding_col_external_ids);
 
     ovsdb_idl_add_column(ctx->idl, &sbrec_ip_multicast_col_datapath);
@@ -713,16 +717,10 @@  lflow_cmp(const void *a_, const void *b_)
     const struct sbrec_logical_flow *a = *ap;
     const struct sbrec_logical_flow *b = *bp;
 
-    const struct sbrec_datapath_binding *adb = a->logical_datapath;
-    const struct sbrec_datapath_binding *bdb = b->logical_datapath;
-    const char *a_name = smap_get_def(&adb->external_ids, "name", "");
-    const char *b_name = smap_get_def(&bdb->external_ids, "name", "");
-    int cmp = strcmp(a_name, b_name);
-    if (cmp) {
-        return cmp;
-    }
+    const struct sbrec_logical_datapath_group *adb = a->logical_datapath_group;
+    const struct sbrec_logical_datapath_group *bdb = b->logical_datapath_group;
 
-    cmp = uuid_compare_3way(&adb->header_.uuid, &bdb->header_.uuid);
+    int cmp = uuid_compare_3way(&adb->header_.uuid, &bdb->header_.uuid);
     if (cmp) {
         return cmp;
     }
@@ -1009,6 +1007,21 @@  cmd_lflow_list_chassis(struct ctl_context *ctx, struct vconn *vconn,
     }
 }
 
+static bool
+datapath_group_contains_datapath(const struct sbrec_logical_datapath_group *g,
+                                 const struct sbrec_datapath_binding *dp)
+{
+    if (!g || !dp) {
+        return false;
+    }
+    for (size_t i = 0; i < g->n_datapaths; i++) {
+        if (g->datapaths[i] == dp) {
+            return true;
+        }
+    }
+    return false;
+}
+
 static void
 cmd_lflow_list(struct ctl_context *ctx)
 {
@@ -1045,7 +1058,9 @@  cmd_lflow_list(struct ctl_context *ctx)
     size_t n_capacity = 0;
     const struct sbrec_logical_flow *lflow;
     SBREC_LOGICAL_FLOW_FOR_EACH (lflow, ctx->idl) {
-        if (datapath && lflow->logical_datapath != datapath) {
+        if (datapath
+            && !datapath_group_contains_datapath(lflow->logical_datapath_group,
+                                                 datapath)) {
             continue;
         }
 
@@ -1089,13 +1104,21 @@  cmd_lflow_list(struct ctl_context *ctx)
         /* Print a header line for this datapath or pipeline, if we haven't
          * already done so. */
         if (!prev
-            || prev->logical_datapath != lflow->logical_datapath
+            || prev->logical_datapath_group != lflow->logical_datapath_group
             || strcmp(prev->pipeline, lflow->pipeline)) {
-            printf("Datapath: ");
-            print_datapath_name(lflow->logical_datapath);
-            printf(" ("UUID_FMT")  Pipeline: %s\n",
-                   UUID_ARGS(&lflow->logical_datapath->header_.uuid),
-                   lflow->pipeline);
+            const struct sbrec_logical_datapath_group *g;
+
+            printf("Datapaths: ");
+            g = lflow->logical_datapath_group;
+            for (size_t j = 0; j < g->n_datapaths; j++) {
+                if (j) {
+                    printf("           ");
+                }
+                print_datapath_name(g->datapaths[j]);
+                printf(" ("UUID_FMT")  Pipeline: %s\n",
+                       UUID_ARGS(&g->datapaths[j]->header_.uuid),
+                       lflow->pipeline);
+            }
         }
 
         /* Print the flow. */
diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c
index 29bf7a208..402a0ab71 100644
--- a/utilities/ovn-trace.c
+++ b/utilities/ovn-trace.c
@@ -874,18 +874,14 @@  ovntrace_make_names_friendly(const char *in)
 }
 
 static void
-read_flows(void)
+parse_lflow_for_datpath(const struct sbrec_logical_flow *sblf,
+                        const struct sbrec_datapath_binding *sbdb)
 {
-    ovn_init_symtab(&symtab);
-
-    const struct sbrec_logical_flow *sblf;
-    SBREC_LOGICAL_FLOW_FOR_EACH (sblf, ovnsb_idl) {
-        const struct sbrec_datapath_binding *sbdb = sblf->logical_datapath;
         struct ovntrace_datapath *dp
             = ovntrace_datapath_find_by_sb_uuid(&sbdb->header_.uuid);
         if (!dp) {
             VLOG_WARN("logical flow missing datapath");
-            continue;
+            return;
         }
 
         char *error;
@@ -897,7 +893,7 @@  read_flows(void)
             VLOG_WARN("%s: parsing expression failed (%s)",
                       sblf->match, error);
             free(error);
-            continue;
+            return;
         }
 
         struct ovnact_parse_params pp = {
@@ -919,7 +915,7 @@  read_flows(void)
             VLOG_WARN("%s: parsing actions failed (%s)", sblf->actions, error);
             free(error);
             expr_destroy(match);
-            continue;
+            return;
         }
 
         match = expr_combine(EXPR_T_AND, match, prereqs);
@@ -930,7 +926,7 @@  read_flows(void)
             expr_destroy(match);
             ovnacts_free(ovnacts.data, ovnacts.size);
             ofpbuf_uninit(&ovnacts);
-            continue;
+            return;
         }
         if (match) {
             match = expr_simplify(match);
@@ -960,6 +956,25 @@  read_flows(void)
                                    sizeof *dp->flows);
         }
         dp->flows[dp->n_flows++] = flow;
+}
+
+static void
+read_flows(void)
+{
+    ovn_init_symtab(&symtab);
+
+    const struct sbrec_logical_flow *sblf;
+    SBREC_LOGICAL_FLOW_FOR_EACH (sblf, ovnsb_idl) {
+        const struct sbrec_logical_datapath_group *g;
+
+        g = sblf->logical_datapath_group;
+        if (!g || !g->n_datapaths) {
+            VLOG_WARN("logical flow missing datapath group");
+            continue;
+        }
+        for (size_t i = 0; i < g->n_datapaths; i++) {
+            parse_lflow_for_datpath(sblf, g->datapaths[i]);
+        }
     }
 
     const struct ovntrace_datapath *dp;