summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <chris@opensourcerouting.org>2018-07-26 12:57:38 +0200
committerChristian Franke <chris@opensourcerouting.org>2018-08-03 13:25:39 +0200
commitbe985ba0599c1b08252e9215de54e74833d41ffe (patch)
tree84c6eedbf8d429ba331d7c2f07f07ae24ce06279
parent26b0598f6b6f55b33e225cb96012fa0e18b23e92 (diff)
isisd: make use of advanced concepts like arrays and loops
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>
-rw-r--r--isisd/isis_spf.c89
-rw-r--r--isisd/isisd.c30
-rw-r--r--isisd/isisd.h9
3 files changed, 57 insertions, 71 deletions
diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c
index 13be8bac53..6c83f29257 100644
--- a/isisd/isis_spf.c
+++ b/isisd/isis_spf.c
@@ -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");
}
diff --git a/isisd/isisd.c b/isisd/isisd.c
index 0094b30c28..ec71c224dd 100644
--- a/isisd/isisd.c
+++ b/isisd/isisd.c
@@ -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(
diff --git a/isisd/isisd.h b/isisd/isisd.h
index c1bf6bc976..fef18ed6fc 100644
--- a/isisd/isisd.h
+++ b/isisd/isisd.h
@@ -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 */