mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-01 22:00:22 +00:00
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>
This commit is contained in:
parent
26b0598f6b
commit
be985ba059
@ -508,67 +508,44 @@ static void isis_spftree_adj_del(struct isis_spftree *spftree,
|
|||||||
|
|
||||||
void spftree_area_init(struct isis_area *area)
|
void spftree_area_init(struct isis_area *area)
|
||||||
{
|
{
|
||||||
if (area->is_type & IS_LEVEL_1) {
|
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
|
||||||
if (area->spftree[0] == NULL)
|
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
|
||||||
area->spftree[0] = isis_spftree_new(area);
|
if (!(area->is_type & level))
|
||||||
if (area->spftree6[0] == NULL)
|
continue;
|
||||||
area->spftree6[0] = isis_spftree_new(area);
|
if (area->spftree[tree][level - 1])
|
||||||
}
|
continue;
|
||||||
|
|
||||||
if (area->is_type & IS_LEVEL_2) {
|
area->spftree[tree][level - 1] = isis_spftree_new(area);
|
||||||
if (area->spftree[1] == NULL)
|
}
|
||||||
area->spftree[1] = isis_spftree_new(area);
|
|
||||||
if (area->spftree6[1] == NULL)
|
|
||||||
area->spftree6[1] = isis_spftree_new(area);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void spftree_area_del(struct isis_area *area)
|
void spftree_area_del(struct isis_area *area)
|
||||||
{
|
{
|
||||||
if (area->is_type & IS_LEVEL_1) {
|
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
|
||||||
if (area->spftree[0] != NULL) {
|
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
|
||||||
isis_spftree_del(area->spftree[0]);
|
if (!(area->is_type & level))
|
||||||
area->spftree[0] = NULL;
|
continue;
|
||||||
}
|
if (!area->spftree[tree][level - 1])
|
||||||
if (area->spftree6[0]) {
|
continue;
|
||||||
isis_spftree_del(area->spftree6[0]);
|
|
||||||
area->spftree6[0] = NULL;
|
isis_spftree_del(area->spftree[tree][level - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void spftree_area_adj_del(struct isis_area *area, struct isis_adjacency *adj)
|
void spftree_area_adj_del(struct isis_area *area, struct isis_adjacency *adj)
|
||||||
{
|
{
|
||||||
if (area->is_type & IS_LEVEL_1) {
|
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
|
||||||
if (area->spftree[0] != NULL)
|
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
|
||||||
isis_spftree_adj_del(area->spftree[0], adj);
|
if (!(area->is_type & level))
|
||||||
if (area->spftree6[0] != NULL)
|
continue;
|
||||||
isis_spftree_adj_del(area->spftree6[0], adj);
|
if (!area->spftree[tree][level - 1])
|
||||||
|
continue;
|
||||||
|
isis_spftree_adj_del(area->spftree[tree][level - 1],
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
start_time = (start_time * 1000000) + nowtv->tv_usec;
|
||||||
|
|
||||||
if (family == AF_INET)
|
if (family == AF_INET)
|
||||||
spftree = area->spftree[level - 1];
|
spftree = area->spftree[SPFTREE_IPV4][level - 1];
|
||||||
else if (family == AF_INET6)
|
else if (family == AF_INET6)
|
||||||
spftree = area->spftree6[level - 1];
|
spftree = area->spftree[SPFTREE_IPV6][level - 1];
|
||||||
assert(spftree);
|
assert(spftree);
|
||||||
assert(sysid);
|
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)
|
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);
|
time_t now = monotime(NULL);
|
||||||
int diff = now - spftree->last_run_monotime;
|
int diff = now - spftree->last_run_monotime;
|
||||||
|
|
||||||
@ -1569,23 +1546,23 @@ DEFUN (show_isis_topology,
|
|||||||
if ((level & levels) == 0)
|
if ((level & levels) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (area->ip_circuits > 0 && area->spftree[level - 1]
|
if (area->ip_circuits > 0 && area->spftree[SPFTREE_IPV4][level - 1]
|
||||||
&& isis_vertex_queue_count(&area->spftree[level - 1]->paths) > 0) {
|
&& isis_vertex_queue_count(&area->spftree[SPFTREE_IPV4][level - 1]->paths) > 0) {
|
||||||
vty_out(vty,
|
vty_out(vty,
|
||||||
"IS-IS paths to level-%d routers that speak IP\n",
|
"IS-IS paths to level-%d routers that speak IP\n",
|
||||||
level);
|
level);
|
||||||
isis_print_paths(
|
isis_print_paths(
|
||||||
vty, &area->spftree[level - 1]->paths,
|
vty, &area->spftree[SPFTREE_IPV4][level - 1]->paths,
|
||||||
isis->sysid);
|
isis->sysid);
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
}
|
}
|
||||||
if (area->ipv6_circuits > 0 && area->spftree6[level - 1]
|
if (area->ipv6_circuits > 0 && area->spftree[SPFTREE_IPV6][level - 1]
|
||||||
&& isis_vertex_queue_count(&area->spftree6[level - 1]->paths) > 0) {
|
&& isis_vertex_queue_count(&area->spftree[SPFTREE_IPV6][level - 1]->paths) > 0) {
|
||||||
vty_out(vty,
|
vty_out(vty,
|
||||||
"IS-IS paths to level-%d routers that speak IPv6\n",
|
"IS-IS paths to level-%d routers that speak IPv6\n",
|
||||||
level);
|
level);
|
||||||
isis_print_paths(
|
isis_print_paths(
|
||||||
vty, &area->spftree6[level - 1]->paths,
|
vty, &area->spftree[SPFTREE_IPV6][level - 1]->paths,
|
||||||
isis->sysid);
|
isis->sysid);
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
}
|
}
|
||||||
|
@ -1319,10 +1319,12 @@ DEFUN (show_isis_summary,
|
|||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
|
|
||||||
vty_out(vty, " IPv4 route computation:\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");
|
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");
|
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++) {
|
for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
|
||||||
if (!(level & levels))
|
if (!(level & levels))
|
||||||
continue;
|
continue;
|
||||||
isis_spf_invalidate_routes(area->spftree[level - 1]);
|
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
|
||||||
isis_spf_invalidate_routes(area->spftree6[level - 1]);
|
isis_spf_invalidate_routes(
|
||||||
|
area->spftree[tree][level - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void isis_area_verify_routes(struct isis_area *area)
|
void isis_area_verify_routes(struct isis_area *area)
|
||||||
{
|
{
|
||||||
isis_spf_verify_routes(area, area->spftree);
|
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++)
|
||||||
isis_spf_verify_routes(area, area->spftree6);
|
isis_spf_verify_routes(area, area->spftree[tree]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void area_resign_level(struct isis_area *area, int level)
|
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]);
|
lsp_db_destroy(area->lspdb[level - 1]);
|
||||||
area->lspdb[level - 1] = NULL;
|
area->lspdb[level - 1] = NULL;
|
||||||
}
|
}
|
||||||
if (area->spftree[level - 1]) {
|
|
||||||
isis_spftree_del(area->spftree[level - 1]);
|
for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
|
||||||
area->spftree[level - 1] = NULL;
|
if (area->spftree[tree][level - 1]) {
|
||||||
}
|
isis_spftree_del(area->spftree[tree][level - 1]);
|
||||||
if (area->spftree6[level - 1]) {
|
area->spftree[tree][level - 1] = NULL;
|
||||||
isis_spftree_del(area->spftree6[level - 1]);
|
}
|
||||||
area->spftree6[level - 1] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
THREAD_TIMER_OFF(area->spf_timer[level - 1]);
|
THREAD_TIMER_OFF(area->spf_timer[level - 1]);
|
||||||
|
|
||||||
sched_debug(
|
sched_debug(
|
||||||
|
@ -63,11 +63,16 @@ struct isis {
|
|||||||
extern struct isis *isis;
|
extern struct isis *isis;
|
||||||
DECLARE_QOBJ_TYPE(isis_area)
|
DECLARE_QOBJ_TYPE(isis_area)
|
||||||
|
|
||||||
|
enum spf_tree_id {
|
||||||
|
SPFTREE_IPV4 = 0,
|
||||||
|
SPFTREE_IPV6,
|
||||||
|
SPFTREE_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
struct isis_area {
|
struct isis_area {
|
||||||
struct isis *isis; /* back pointer */
|
struct isis *isis; /* back pointer */
|
||||||
dict_t *lspdb[ISIS_LEVELS]; /* link-state dbs */
|
dict_t *lspdb[ISIS_LEVELS]; /* link-state dbs */
|
||||||
struct isis_spftree *spftree[ISIS_LEVELS]; /* The v4 SPTs */
|
struct isis_spftree *spftree[SPFTREE_COUNT][ISIS_LEVELS];
|
||||||
struct isis_spftree *spftree6[ISIS_LEVELS]; /* The v6 SPTs */
|
|
||||||
#define DEFAULT_LSP_MTU 1497
|
#define DEFAULT_LSP_MTU 1497
|
||||||
unsigned int lsp_mtu; /* Size of LSPs to generate */
|
unsigned int lsp_mtu; /* Size of LSPs to generate */
|
||||||
struct list *circuit_list; /* IS-IS circuits */
|
struct list *circuit_list; /* IS-IS circuits */
|
||||||
|
Loading…
Reference in New Issue
Block a user