This is a cosmetic change that establishes a clearer way to iterate over
all known OVN datapath types. Some for loops started iterating with "0",
and others started with "DP_SWITCH" since it was the first value in the
enum. Neither of these is great. 0 is not an enum value in
ovn_datpaath_type. DP_SWITCH is not a clear way of indicating the first
value in the enum, and it's vulnerable to enum changes that might not
keep DP_SWITCH as the first value.

This change introduces "DP_MIN" as the first value in the enum, and
aliases DP_SWITCH to be the same as DP_MIN. This way, for loops can
start with DP_MIN instead of 0 or DP_SWITCH.

Signed-off-by: Mark Michelson <[email protected]>
---
 northd/datapath-sync.c    | 2 +-
 northd/datapath-sync.h    | 3 ++-
 northd/en-datapath-sync.c | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/northd/datapath-sync.c b/northd/datapath-sync.c
index 40f1761db..459d304e6 100644
--- a/northd/datapath-sync.c
+++ b/northd/datapath-sync.c
@@ -28,7 +28,7 @@ static const char *ovn_datapath_strings[] = {
 enum ovn_datapath_type
 ovn_datapath_type_from_string(const char *type_str)
 {
-    for (enum ovn_datapath_type i = DP_SWITCH; i < DP_MAX; i++) {
+    for (enum ovn_datapath_type i = DP_MIN; i < DP_MAX; i++) {
         if (!strcmp(type_str, ovn_datapath_strings[i])) {
             return i;
         }
diff --git a/northd/datapath-sync.h b/northd/datapath-sync.h
index 9bd0b7e5a..f54b79fab 100644
--- a/northd/datapath-sync.h
+++ b/northd/datapath-sync.h
@@ -39,7 +39,8 @@
  */
 
 enum ovn_datapath_type {
-    DP_SWITCH,
+    DP_MIN = 0,
+    DP_SWITCH = DP_MIN,
     DP_ROUTER,
     DP_MAX,
 };
diff --git a/northd/en-datapath-sync.c b/northd/en-datapath-sync.c
index 1c997d242..40ff6b027 100644
--- a/northd/en-datapath-sync.c
+++ b/northd/en-datapath-sync.c
@@ -218,7 +218,7 @@ create_synced_datapath_candidates_from_nb(
     struct uuidset *visited,
     struct vector *candidate_sdps)
 {
-    for (size_t i = 0; i < DP_MAX; i++) {
+    for (enum ovn_datapath_type i = DP_MIN; i < DP_MAX; i++) {
         const struct ovn_unsynced_datapath_map *map = input_maps[i];
         struct ovn_unsynced_datapath *udp;
         HMAP_FOR_EACH (udp, hmap_node, &map->dps) {
@@ -554,7 +554,7 @@ en_datapath_sync_run(struct engine_node *node , void *data)
     input_maps[unsynced_lr_map->dp_type] = unsynced_lr_map;
 
     size_t num_datapaths = 0;
-    for (enum ovn_datapath_type i = 0; i < DP_MAX; i++) {
+    for (enum ovn_datapath_type i = DP_MIN; i < DP_MAX; i++) {
         ovs_assert(input_maps[i]);
         num_datapaths += hmap_count(&input_maps[i]->dps);
     }
-- 
2.51.1

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

Reply via email to