The lflow_table had separate ls and lr datapath groups as individual
pointers. If we expand to allow new types of datapaths, then this is
overly restrictive. Using an array allows us to automatically expand as
new datapath types are added.

Signed-off-by: Mark Michelson <[email protected]>
---
 northd/lflow-mgr.c | 39 ++++++++++++++++++++++-----------------
 northd/lflow-mgr.h |  3 +--
 northd/northd.c    |  3 +--
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/northd/lflow-mgr.c b/northd/lflow-mgr.c
index 1f1a6d9bc..a1b1d876e 100644
--- a/northd/lflow-mgr.c
+++ b/northd/lflow-mgr.c
@@ -207,8 +207,9 @@ lflow_table_init(struct lflow_table *lflow_table)
 {
     fast_hmap_size_for(&lflow_table->entries,
                        lflow_table->max_seen_lflow_size);
-    ovn_dp_groups_init(&lflow_table->ls_dp_groups);
-    ovn_dp_groups_init(&lflow_table->lr_dp_groups);
+    for (enum ovn_datapath_type i = DP_MIN; i < DP_MAX; i++) {
+        ovn_dp_groups_init(&lflow_table->dp_groups[i]);
+    }
 }
 
 void
@@ -223,8 +224,9 @@ lflow_table_clear(struct lflow_table *lflow_table, bool 
destroy_all)
         }
     }
 
-    ovn_dp_groups_clear(&lflow_table->ls_dp_groups);
-    ovn_dp_groups_clear(&lflow_table->lr_dp_groups);
+    for (enum ovn_datapath_type i = DP_MIN; i < DP_MAX; i++) {
+        ovn_dp_groups_clear(&lflow_table->dp_groups[i]);
+    }
 }
 
 void
@@ -232,8 +234,9 @@ lflow_table_destroy(struct lflow_table *lflow_table)
 {
     lflow_table_clear(lflow_table, true);
     hmap_destroy(&lflow_table->entries);
-    ovn_dp_groups_destroy(&lflow_table->ls_dp_groups);
-    ovn_dp_groups_destroy(&lflow_table->lr_dp_groups);
+    for (enum ovn_datapath_type i = DP_MIN; i < DP_MAX; i++) {
+        ovn_dp_groups_destroy(&lflow_table->dp_groups[i]);
+    }
     free(lflow_table);
 }
 
@@ -288,12 +291,13 @@ lflow_table_sync_to_sb(struct lflow_table *lflow_table,
         }
         const struct ovn_datapaths *datapaths;
         struct hmap *dp_groups;
-        if (ovn_stage_to_datapath_type(lflow->stage) == DP_SWITCH) {
+        enum ovn_datapath_type dp_type =
+            ovn_stage_to_datapath_type(lflow->stage);
+        dp_groups = &lflow_table->dp_groups[dp_type];
+        if (dp_type == DP_SWITCH) {
             datapaths = ls_datapaths;
-            dp_groups = &lflow_table->ls_dp_groups;
         } else {
             datapaths = lr_datapaths;
-            dp_groups = &lflow_table->lr_dp_groups;
         }
         sync_lflow_to_sb(lflow, ovnsb_txn, dp_groups, datapaths,
                          ovn_internal_version_changed,
@@ -369,12 +373,11 @@ lflow_table_sync_to_sb(struct lflow_table *lflow_table,
         if (lflow) {
             const struct ovn_datapaths *datapaths;
             struct hmap *dp_groups;
+            dp_groups = &lflow_table->dp_groups[dp_type];
             if (dp_type == DP_SWITCH) {
                 datapaths = ls_datapaths;
-                dp_groups = &lflow_table->ls_dp_groups;
             } else {
                 datapaths = lr_datapaths;
-                dp_groups = &lflow_table->lr_dp_groups;
             }
             sync_lflow_to_sb(lflow, ovnsb_txn, dp_groups, datapaths,
                              ovn_internal_version_changed,
@@ -394,12 +397,13 @@ lflow_table_sync_to_sb(struct lflow_table *lflow_table,
         }
         const struct ovn_datapaths *datapaths;
         struct hmap *dp_groups;
-        if (ovn_stage_to_datapath_type(lflow->stage) == DP_SWITCH) {
+        enum ovn_datapath_type dp_type =
+            ovn_stage_to_datapath_type(lflow->stage);
+        dp_groups = &lflow_table->dp_groups[dp_type];
+        if (dp_type == DP_SWITCH) {
             datapaths = ls_datapaths;
-            dp_groups = &lflow_table->ls_dp_groups;
         } else {
             datapaths = lr_datapaths;
-            dp_groups = &lflow_table->lr_dp_groups;
         }
         sync_lflow_to_sb(lflow, ovnsb_txn, dp_groups, datapaths,
                          ovn_internal_version_changed, NULL, dpgrp_table);
@@ -1361,11 +1365,12 @@ lflow_ref_sync_lflows__(struct lflow_ref  *lflow_ref,
 
         struct hmap *dp_groups = NULL;
         const struct ovn_datapaths *datapaths;
-        if (ovn_stage_to_datapath_type(lflow->stage) == DP_SWITCH) {
-            dp_groups = &lflow_table->ls_dp_groups;
+        enum ovn_datapath_type dp_type =
+            ovn_stage_to_datapath_type(lflow->stage);
+        dp_groups = &lflow_table->dp_groups[dp_type];
+        if (dp_type == DP_SWITCH) {
             datapaths = ls_datapaths;
         } else {
-            dp_groups = &lflow_table->lr_dp_groups;
             datapaths = lr_datapaths;
         }
 
diff --git a/northd/lflow-mgr.h b/northd/lflow-mgr.h
index d4d98390b..cbd9f9e03 100644
--- a/northd/lflow-mgr.h
+++ b/northd/lflow-mgr.h
@@ -28,8 +28,7 @@ struct ovsdb_idl_row;
 /* lflow map which stores the logical flows. */
 struct lflow_table {
     struct hmap entries; /* hmap of lflows. */
-    struct hmap ls_dp_groups; /* hmap of logical switch dp groups. */
-    struct hmap lr_dp_groups; /* hmap of logical router dp groups. */
+    struct hmap dp_groups[DP_MAX];
     ssize_t max_seen_lflow_size;
 };
 
diff --git a/northd/northd.c b/northd/northd.c
index e869b8dd5..a98a09ae2 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -19847,8 +19847,7 @@ lflow_handle_ls_stateful_changes(struct ovsdb_idl_txn 
*ovnsb_txn,
 
         if (!lflow_ref_resync_flows(
                     ls_stateful_rec->lflow_ref, lflows, ovnsb_txn,
-                    lflow_input->ls_datapaths,
-                    lflow_input->lr_datapaths,
+                    lflow_input->ls_datapaths, lflow_input->lr_datapaths,
                     lflow_input->ovn_internal_version_changed,
                     lflow_input->sbrec_logical_flow_table,
                     lflow_input->sbrec_logical_dp_group_table)) {
-- 
2.51.1

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

Reply via email to