]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd: make use of advanced concepts like arrays and loops
authorChristian Franke <chris@opensourcerouting.org>
Thu, 26 Jul 2018 10:57:38 +0000 (12:57 +0200)
committerChristian Franke <chris@opensourcerouting.org>
Fri, 3 Aug 2018 11:25:39 +0000 (13:25 +0200)
Have an array of spftrees instead of a separate spftree and an
spftree6 for which all the code gets duplicated.

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
isisd/isis_spf.c
isisd/isisd.c
isisd/isisd.h

index 13be8bac5306da3888a5ced52e138c145df1a6fb..6c83f292579193e653295fedfa136be8f20ce475 100644 (file)
@@ -508,67 +508,44 @@ static void isis_spftree_adj_del(struct isis_spftree *spftree,
 
 void spftree_area_init(struct isis_area *area)
 {
-       if (area->is_type & IS_LEVEL_1) {
-               if (area->spftree[0] == NULL)
-                       area->spftree[0] = isis_spftree_new(area);
-               if (area->spftree6[0] == NULL)
-                       area->spftree6[0] = isis_spftree_new(area);
-       }
+       for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
+               for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
+                       if (!(area->is_type & level))
+                               continue;
+                       if (area->spftree[tree][level - 1])
+                               continue;
 
-       if (area->is_type & IS_LEVEL_2) {
-               if (area->spftree[1] == NULL)
-                       area->spftree[1] = isis_spftree_new(area);
-               if (area->spftree6[1] == NULL)
-                       area->spftree6[1] = isis_spftree_new(area);
+                       area->spftree[tree][level - 1] = isis_spftree_new(area);
+               }
        }
-
-       return;
 }
 
 void spftree_area_del(struct isis_area *area)
 {
-       if (area->is_type & IS_LEVEL_1) {
-               if (area->spftree[0] != NULL) {
-                       isis_spftree_del(area->spftree[0]);
-                       area->spftree[0] = NULL;
-               }
-               if (area->spftree6[0]) {
-                       isis_spftree_del(area->spftree6[0]);
-                       area->spftree6[0] = NULL;
-               }
-       }
+       for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
+               for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
+                       if (!(area->is_type & level))
+                               continue;
+                       if (!area->spftree[tree][level - 1])
+                               continue;
 
-       if (area->is_type & IS_LEVEL_2) {
-               if (area->spftree[1] != NULL) {
-                       isis_spftree_del(area->spftree[1]);
-                       area->spftree[1] = NULL;
-               }
-               if (area->spftree6[1] != NULL) {
-                       isis_spftree_del(area->spftree6[1]);
-                       area->spftree6[1] = NULL;
+                       isis_spftree_del(area->spftree[tree][level - 1]);
                }
        }
-
-       return;
 }
 
 void spftree_area_adj_del(struct isis_area *area, struct isis_adjacency *adj)
 {
-       if (area->is_type & IS_LEVEL_1) {
-               if (area->spftree[0] != NULL)
-                       isis_spftree_adj_del(area->spftree[0], adj);
-               if (area->spftree6[0] != NULL)
-                       isis_spftree_adj_del(area->spftree6[0], adj);
-       }
-
-       if (area->is_type & IS_LEVEL_2) {
-               if (area->spftree[1] != NULL)
-                       isis_spftree_adj_del(area->spftree[1], adj);
-               if (area->spftree6[1] != NULL)
-                       isis_spftree_adj_del(area->spftree6[1], adj);
+       for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
+               for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
+                       if (!(area->is_type & level))
+                               continue;
+                       if (!area->spftree[tree][level - 1])
+                               continue;
+                       isis_spftree_adj_del(area->spftree[tree][level - 1],
+                                            adj);
+               }
        }
-
-       return;
 }
 
 /*
@@ -1274,9 +1251,9 @@ static int isis_run_spf(struct isis_area *area, int level, int family,
        start_time = (start_time * 1000000) + nowtv->tv_usec;
 
        if (family == AF_INET)
-               spftree = area->spftree[level - 1];
+               spftree = area->spftree[SPFTREE_IPV4][level - 1];
        else if (family == AF_INET6)
-               spftree = area->spftree6[level - 1];
+               spftree = area->spftree[SPFTREE_IPV6][level - 1];
        assert(spftree);
        assert(sysid);
 
@@ -1417,7 +1394,7 @@ static struct isis_spf_run *isis_run_spf_arg(struct isis_area *area, int level)
 
 int isis_spf_schedule(struct isis_area *area, int level)
 {
-       struct isis_spftree *spftree = area->spftree[level - 1];
+       struct isis_spftree *spftree = area->spftree[SPFTREE_IPV4][level - 1];
        time_t now = monotime(NULL);
        int diff = now - spftree->last_run_monotime;
 
@@ -1569,23 +1546,23 @@ DEFUN (show_isis_topology,
                        if ((level & levels) == 0)
                                continue;
 
-                       if (area->ip_circuits > 0 && area->spftree[level - 1]
-                           && isis_vertex_queue_count(&area->spftree[level - 1]->paths) > 0) {
+                       if (area->ip_circuits > 0 && area->spftree[SPFTREE_IPV4][level - 1]
+                           && isis_vertex_queue_count(&area->spftree[SPFTREE_IPV4][level - 1]->paths) > 0) {
                                vty_out(vty,
                                        "IS-IS paths to level-%d routers that speak IP\n",
                                        level);
                                isis_print_paths(
-                                       vty, &area->spftree[level - 1]->paths,
+                                       vty, &area->spftree[SPFTREE_IPV4][level - 1]->paths,
                                        isis->sysid);
                                vty_out(vty, "\n");
                        }
-                       if (area->ipv6_circuits > 0 && area->spftree6[level - 1]
-                           && isis_vertex_queue_count(&area->spftree6[level - 1]->paths) > 0) {
+                       if (area->ipv6_circuits > 0 && area->spftree[SPFTREE_IPV6][level - 1]
+                           && isis_vertex_queue_count(&area->spftree[SPFTREE_IPV6][level - 1]->paths) > 0) {
                                vty_out(vty,
                                        "IS-IS paths to level-%d routers that speak IPv6\n",
                                        level);
                                isis_print_paths(
-                                       vty, &area->spftree6[level - 1]->paths,
+                                       vty, &area->spftree[SPFTREE_IPV6][level - 1]->paths,
                                        isis->sysid);
                                vty_out(vty, "\n");
                        }
index 0094b30c28cae5bad8ec19be47b8899fc6312302..ec71c224dd81d5155ce36ffc2fb384e2df601c4b 100644 (file)
@@ -1319,10 +1319,12 @@ DEFUN (show_isis_summary,
                        vty_out(vty, "\n");
 
                        vty_out(vty, "    IPv4 route computation:\n");
-                       isis_spf_print(area->spftree[level - 1], vty);
+                       isis_spf_print(area->spftree[SPFTREE_IPV4][level - 1],
+                                      vty);
 
                        vty_out(vty, "    IPv6 route computation:\n");
-                       isis_spf_print(area->spftree6[level - 1], vty);
+                       isis_spf_print(area->spftree[SPFTREE_IPV6][level - 1],
+                                      vty);
                }
        }
        vty_out(vty, "\n");
@@ -1664,15 +1666,17 @@ void isis_area_invalidate_routes(struct isis_area *area, int levels)
        for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
                if (!(level & levels))
                        continue;
-               isis_spf_invalidate_routes(area->spftree[level - 1]);
-               isis_spf_invalidate_routes(area->spftree6[level - 1]);
+               for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
+                       isis_spf_invalidate_routes(
+                                       area->spftree[tree][level - 1]);
+               }
        }
 }
 
 void isis_area_verify_routes(struct isis_area *area)
 {
-       isis_spf_verify_routes(area, area->spftree);
-       isis_spf_verify_routes(area, area->spftree6);
+       for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++)
+               isis_spf_verify_routes(area, area->spftree[tree]);
 }
 
 static void area_resign_level(struct isis_area *area, int level)
@@ -1684,14 +1688,14 @@ static void area_resign_level(struct isis_area *area, int level)
                lsp_db_destroy(area->lspdb[level - 1]);
                area->lspdb[level - 1] = NULL;
        }
-       if (area->spftree[level - 1]) {
-               isis_spftree_del(area->spftree[level - 1]);
-               area->spftree[level - 1] = NULL;
-       }
-       if (area->spftree6[level - 1]) {
-               isis_spftree_del(area->spftree6[level - 1]);
-               area->spftree6[level - 1] = NULL;
+
+       for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
+               if (area->spftree[tree][level - 1]) {
+                       isis_spftree_del(area->spftree[tree][level - 1]);
+                       area->spftree[tree][level - 1] = NULL;
+               }
        }
+
        THREAD_TIMER_OFF(area->spf_timer[level - 1]);
 
        sched_debug(
index c1bf6bc9764069aaa6296f20fea97788c3a74e4f..fef18ed6fc274d16d496290723102ce49a82a331 100644 (file)
@@ -63,11 +63,16 @@ struct isis {
 extern struct isis *isis;
 DECLARE_QOBJ_TYPE(isis_area)
 
+enum spf_tree_id {
+       SPFTREE_IPV4 = 0,
+       SPFTREE_IPV6,
+       SPFTREE_COUNT
+};
+
 struct isis_area {
        struct isis *isis;                             /* back pointer */
        dict_t *lspdb[ISIS_LEVELS];                    /* link-state dbs */
-       struct isis_spftree *spftree[ISIS_LEVELS];     /* The v4 SPTs */
-       struct isis_spftree *spftree6[ISIS_LEVELS];    /* The v6 SPTs */
+       struct isis_spftree *spftree[SPFTREE_COUNT][ISIS_LEVELS];
 #define DEFAULT_LSP_MTU 1497
        unsigned int lsp_mtu;      /* Size of LSPs to generate */
        struct list *circuit_list; /* IS-IS circuits */