1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IS-IS Rout(e)ing protocol - isis_spf.c
6 * Copyright (C) 2001,2002 Sampo Saaristo
7 * Tampere University of Technology
8 * Institute of Communications Engineering
9 * Copyright (C) 2017 Christian Franke <chris@opensourcerouting.org>
19 #include "termtable.h"
26 #include "spf_backoff.h"
27 #include "srcdest_table.h"
30 #include "isis_errors.h"
31 #include "isis_constants.h"
32 #include "isis_common.h"
33 #include "isis_flags.h"
35 #include "isis_misc.h"
36 #include "isis_adjacency.h"
37 #include "isis_circuit.h"
40 #include "isis_dynhn.h"
42 #include "isis_route.h"
45 #include "isis_tlvs.h"
46 #include "isis_zebra.h"
48 #include "isis_spf_private.h"
50 DEFINE_MTYPE_STATIC(ISISD
, ISIS_SPFTREE
, "ISIS SPFtree");
51 DEFINE_MTYPE_STATIC(ISISD
, ISIS_SPF_RUN
, "ISIS SPF Run Info");
52 DEFINE_MTYPE_STATIC(ISISD
, ISIS_SPF_ADJ
, "ISIS SPF Adjacency");
53 DEFINE_MTYPE_STATIC(ISISD
, ISIS_VERTEX
, "ISIS vertex");
54 DEFINE_MTYPE_STATIC(ISISD
, ISIS_VERTEX_ADJ
, "ISIS SPF Vertex Adjacency");
56 static void spf_adj_list_parse_lsp(struct isis_spftree
*spftree
,
57 struct list
*adj_list
, struct isis_lsp
*lsp
,
58 const uint8_t *pseudo_nodeid
,
59 uint32_t pseudo_metric
);
62 * supports the given af ?
64 static bool speaks(uint8_t *protocols
, uint8_t count
, int family
)
66 for (uint8_t i
= 0; i
< count
; i
++) {
67 if (family
== AF_INET
&& protocols
[i
] == NLPID_IP
)
69 if (family
== AF_INET6
&& protocols
[i
] == NLPID_IPV6
)
76 struct isis_area
*area
;
81 static void remove_excess_adjs(struct list
*adjs
)
83 struct listnode
*node
, *excess
= NULL
;
84 struct isis_vertex_adj
*vadj
, *candidate
= NULL
;
87 for (ALL_LIST_ELEMENTS_RO(adjs
, node
, vadj
)) {
88 struct isis_adjacency
*adj
, *candidate_adj
;
90 adj
= vadj
->sadj
->adj
;
95 candidate
= listgetdata(excess
);
96 candidate_adj
= candidate
->sadj
->adj
;
98 if (candidate_adj
->sys_type
< adj
->sys_type
) {
102 if (candidate_adj
->sys_type
> adj
->sys_type
)
105 comp
= memcmp(candidate_adj
->sysid
, adj
->sysid
,
114 if (candidate_adj
->circuit
->idx
> adj
->circuit
->idx
) {
119 if (candidate_adj
->circuit
->idx
< adj
->circuit
->idx
)
122 comp
= memcmp(candidate_adj
->snpa
, adj
->snpa
, ETH_ALEN
);
129 list_delete_node(adjs
, excess
);
134 const char *vtype2string(enum vertextype vtype
)
137 case VTYPE_PSEUDO_IS
:
139 case VTYPE_PSEUDO_TE_IS
:
140 return "pseudo_TE-IS";
141 case VTYPE_NONPSEUDO_IS
:
143 case VTYPE_NONPSEUDO_TE_IS
:
147 case VTYPE_IPREACH_INTERNAL
:
148 return "IP internal";
149 case VTYPE_IPREACH_EXTERNAL
:
150 return "IP external";
151 case VTYPE_IPREACH_TE
:
153 case VTYPE_IP6REACH_INTERNAL
:
154 return "IP6 internal";
155 case VTYPE_IP6REACH_EXTERNAL
:
156 return "IP6 external";
160 return NULL
; /* Not reached */
163 const char *vid2string(const struct isis_vertex
*vertex
, char *buff
, int size
)
165 if (VTYPE_IS(vertex
->type
) || VTYPE_ES(vertex
->type
)) {
166 const char *hostname
= print_sys_hostname(vertex
->N
.id
);
167 strlcpy(buff
, hostname
, size
);
171 if (VTYPE_IP(vertex
->type
)) {
172 srcdest2str(&vertex
->N
.ip
.p
.dest
, &vertex
->N
.ip
.p
.src
, buff
,
180 static bool prefix_sid_cmp(const void *value1
, const void *value2
)
182 const struct isis_vertex
*c1
= value1
;
183 const struct isis_vertex
*c2
= value2
;
185 if (CHECK_FLAG(c1
->N
.ip
.sr
.sid
.flags
,
186 ISIS_PREFIX_SID_VALUE
| ISIS_PREFIX_SID_LOCAL
)
187 != CHECK_FLAG(c2
->N
.ip
.sr
.sid
.flags
,
188 ISIS_PREFIX_SID_VALUE
| ISIS_PREFIX_SID_LOCAL
))
191 return c1
->N
.ip
.sr
.sid
.value
== c2
->N
.ip
.sr
.sid
.value
;
194 static unsigned int prefix_sid_key_make(const void *value
)
196 const struct isis_vertex
*vertex
= value
;
198 return jhash_1word(vertex
->N
.ip
.sr
.sid
.value
, 0);
201 struct isis_vertex
*isis_spf_prefix_sid_lookup(struct isis_spftree
*spftree
,
202 struct isis_prefix_sid
*psid
)
204 struct isis_vertex lookup
= {};
206 lookup
.N
.ip
.sr
.sid
= *psid
;
207 return hash_lookup(spftree
->prefix_sids
, &lookup
);
210 void isis_vertex_adj_free(void *arg
)
212 struct isis_vertex_adj
*vadj
= arg
;
214 XFREE(MTYPE_ISIS_VERTEX_ADJ
, vadj
);
217 static struct isis_vertex
*isis_vertex_new(struct isis_spftree
*spftree
,
219 enum vertextype vtype
)
221 struct isis_vertex
*vertex
;
223 vertex
= XCALLOC(MTYPE_ISIS_VERTEX
, sizeof(struct isis_vertex
));
225 isis_vertex_id_init(vertex
, id
, vtype
);
227 vertex
->Adj_N
= list_new();
228 vertex
->Adj_N
->del
= isis_vertex_adj_free
;
229 vertex
->parents
= list_new();
231 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)) {
232 vertex
->firsthops
= hash_create(isis_vertex_queue_hash_key
,
233 isis_vertex_queue_hash_cmp
,
240 void isis_vertex_del(struct isis_vertex
*vertex
)
242 list_delete(&vertex
->Adj_N
);
243 list_delete(&vertex
->parents
);
244 hash_clean_and_free(&vertex
->firsthops
, NULL
);
246 memset(vertex
, 0, sizeof(struct isis_vertex
));
247 XFREE(MTYPE_ISIS_VERTEX
, vertex
);
250 struct isis_vertex_adj
*
251 isis_vertex_adj_add(struct isis_spftree
*spftree
, struct isis_vertex
*vertex
,
252 struct list
*vadj_list
, struct isis_spf_adj
*sadj
,
253 struct isis_prefix_sid
*psid
, bool last_hop
)
255 struct isis_vertex_adj
*vadj
;
257 vadj
= XCALLOC(MTYPE_ISIS_VERTEX_ADJ
, sizeof(*vadj
));
259 if (spftree
->area
->srdb
.enabled
&& psid
) {
260 if (vertex
->N
.ip
.sr
.present
261 && vertex
->N
.ip
.sr
.sid
.value
!= psid
->value
)
263 "ISIS-SPF: ignoring different Prefix-SID for route %pFX",
264 &vertex
->N
.ip
.p
.dest
);
266 vadj
->sr
.sid
= *psid
;
267 vadj
->sr
.label
= sr_prefix_out_label(
268 spftree
->lspdb
, vertex
->N
.ip
.p
.dest
.family
,
269 psid
, sadj
->id
, last_hop
);
270 if (vadj
->sr
.label
!= MPLS_INVALID_LABEL
)
271 vadj
->sr
.present
= true;
274 listnode_add(vadj_list
, vadj
);
279 static void isis_vertex_adj_del(struct isis_vertex
*vertex
,
280 struct isis_adjacency
*adj
)
282 struct isis_vertex_adj
*vadj
;
283 struct listnode
*node
, *nextnode
;
288 for (ALL_LIST_ELEMENTS(vertex
->Adj_N
, node
, nextnode
, vadj
)) {
289 if (vadj
->sadj
->adj
== adj
) {
290 listnode_delete(vertex
->Adj_N
, vadj
);
291 isis_vertex_adj_free(vadj
);
297 bool isis_vertex_adj_exists(const struct isis_spftree
*spftree
,
298 const struct isis_vertex
*vertex
,
299 const struct isis_spf_adj
*sadj
)
301 struct isis_vertex_adj
*tmp
;
302 struct listnode
*node
;
304 for (ALL_LIST_ELEMENTS_RO(vertex
->Adj_N
, node
, tmp
)) {
305 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
)) {
306 if (memcmp(sadj
->id
, tmp
->sadj
->id
, sizeof(sadj
->id
))
310 if (sadj
->adj
== tmp
->sadj
->adj
)
318 static void isis_spf_adj_free(void *arg
)
320 struct isis_spf_adj
*sadj
= arg
;
322 XFREE(MTYPE_ISIS_SPF_ADJ
, sadj
);
325 struct isis_spftree
*isis_spftree_new(struct isis_area
*area
,
326 struct lspdb_head
*lspdb
,
327 const uint8_t *sysid
, int level
,
328 enum spf_tree_id tree_id
,
329 enum spf_type type
, uint8_t flags
)
331 struct isis_spftree
*tree
;
333 tree
= XCALLOC(MTYPE_ISIS_SPFTREE
, sizeof(struct isis_spftree
));
335 isis_vertex_queue_init(&tree
->tents
, "IS-IS SPF tents", true);
336 isis_vertex_queue_init(&tree
->paths
, "IS-IS SPF paths", false);
337 tree
->route_table
= srcdest_table_init();
338 tree
->route_table
->cleanup
= isis_route_node_cleanup
;
339 tree
->route_table_backup
= srcdest_table_init();
340 tree
->route_table_backup
->cleanup
= isis_route_node_cleanup
;
343 tree
->prefix_sids
= hash_create(prefix_sid_key_make
, prefix_sid_cmp
,
344 "SR Prefix-SID Entries");
345 tree
->sadj_list
= list_new();
346 tree
->sadj_list
->del
= isis_spf_adj_free
;
347 tree
->last_run_timestamp
= 0;
348 tree
->last_run_monotime
= 0;
349 tree
->last_run_duration
= 0;
352 memcpy(tree
->sysid
, sysid
, ISIS_SYS_ID_LEN
);
354 tree
->tree_id
= tree_id
;
355 tree
->family
= (tree
->tree_id
== SPFTREE_IPV4
) ? AF_INET
: AF_INET6
;
357 isis_rlfa_list_init(tree
);
358 tree
->lfa
.remote
.pc_spftrees
= list_new();
359 tree
->lfa
.remote
.pc_spftrees
->del
= (void (*)(void *))isis_spftree_del
;
360 if (tree
->type
== SPF_TYPE_RLFA
|| tree
->type
== SPF_TYPE_TI_LFA
) {
361 isis_spf_node_list_init(&tree
->lfa
.p_space
);
362 isis_spf_node_list_init(&tree
->lfa
.q_space
);
368 void isis_spftree_del(struct isis_spftree
*spftree
)
370 hash_clean_and_free(&spftree
->prefix_sids
, NULL
);
371 isis_zebra_rlfa_unregister_all(spftree
);
372 isis_rlfa_list_clear(spftree
);
373 list_delete(&spftree
->lfa
.remote
.pc_spftrees
);
374 if (spftree
->type
== SPF_TYPE_RLFA
375 || spftree
->type
== SPF_TYPE_TI_LFA
) {
376 isis_spf_node_list_clear(&spftree
->lfa
.q_space
);
377 isis_spf_node_list_clear(&spftree
->lfa
.p_space
);
379 isis_spf_node_list_clear(&spftree
->adj_nodes
);
380 list_delete(&spftree
->sadj_list
);
381 isis_vertex_queue_free(&spftree
->tents
);
382 isis_vertex_queue_free(&spftree
->paths
);
383 route_table_finish(spftree
->route_table
);
384 route_table_finish(spftree
->route_table_backup
);
385 spftree
->route_table
= NULL
;
387 XFREE(MTYPE_ISIS_SPFTREE
, spftree
);
391 static void isis_spftree_adj_del(struct isis_spftree
*spftree
,
392 struct isis_adjacency
*adj
)
394 struct listnode
*node
;
395 struct isis_vertex
*v
;
398 assert(!isis_vertex_queue_count(&spftree
->tents
));
399 for (ALL_QUEUE_ELEMENTS_RO(&spftree
->paths
, node
, v
))
400 isis_vertex_adj_del(v
, adj
);
404 void spftree_area_init(struct isis_area
*area
)
406 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
407 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
408 if (!(area
->is_type
& level
))
410 if (area
->spftree
[tree
][level
- 1])
413 area
->spftree
[tree
][level
- 1] =
414 isis_spftree_new(area
, &area
->lspdb
[level
- 1],
415 area
->isis
->sysid
, level
, tree
,
416 SPF_TYPE_FORWARD
, 0);
421 void spftree_area_del(struct isis_area
*area
)
423 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
424 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
425 if (!(area
->is_type
& level
))
427 if (!area
->spftree
[tree
][level
- 1])
430 isis_spftree_del(area
->spftree
[tree
][level
- 1]);
435 static int spf_adj_state_change(struct isis_adjacency
*adj
)
437 struct isis_area
*area
= adj
->circuit
->area
;
439 if (adj
->adj_state
== ISIS_ADJ_UP
)
442 /* Remove adjacency from all SPF trees. */
443 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
444 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
445 if (!(area
->is_type
& level
))
447 if (!area
->spftree
[tree
][level
- 1])
449 isis_spftree_adj_del(area
->spftree
[tree
][level
- 1],
454 if (fabricd_spftree(area
) != NULL
)
455 isis_spftree_adj_del(fabricd_spftree(area
), adj
);
461 * Find the system LSP: returns the LSP in our LSP database
462 * associated with the given system ID.
464 struct isis_lsp
*isis_root_system_lsp(struct lspdb_head
*lspdb
,
465 const uint8_t *sysid
)
467 struct isis_lsp
*lsp
;
468 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
470 memcpy(lspid
, sysid
, ISIS_SYS_ID_LEN
);
471 LSP_PSEUDO_ID(lspid
) = 0;
472 LSP_FRAGMENT(lspid
) = 0;
473 lsp
= lsp_search(lspdb
, lspid
);
474 if (lsp
&& lsp
->hdr
.rem_lifetime
!= 0)
480 * Add this IS to the root of SPT
482 static struct isis_vertex
*isis_spf_add_root(struct isis_spftree
*spftree
)
484 struct isis_vertex
*vertex
;
486 char buff
[VID2STR_BUFFER
];
487 #endif /* EXTREME_DEBUG */
489 vertex
= isis_vertex_new(spftree
, spftree
->sysid
,
490 spftree
->area
->oldmetric
492 : VTYPE_NONPSEUDO_TE_IS
);
493 isis_vertex_queue_append(&spftree
->paths
, vertex
);
496 if (IS_DEBUG_SPF_EVENTS
)
498 "ISIS-SPF: added this IS %s %s depth %d dist %d to PATHS",
499 vtype2string(vertex
->type
),
500 vid2string(vertex
, buff
, sizeof(buff
)), vertex
->depth
,
502 #endif /* EXTREME_DEBUG */
507 static void vertex_add_parent_firsthop(struct hash_bucket
*bucket
, void *arg
)
509 struct isis_vertex
*vertex
= arg
;
510 struct isis_vertex
*hop
= bucket
->data
;
512 (void)hash_get(vertex
->firsthops
, hop
, hash_alloc_intern
);
515 static void vertex_update_firsthops(struct isis_vertex
*vertex
,
516 struct isis_vertex
*parent
)
518 if (vertex
->d_N
<= 2)
519 (void)hash_get(vertex
->firsthops
, vertex
, hash_alloc_intern
);
521 if (vertex
->d_N
< 2 || !parent
)
524 hash_iterate(parent
->firsthops
, vertex_add_parent_firsthop
, vertex
);
528 * Add a vertex to TENT sorted by cost and by vertextype on tie break situation
530 static struct isis_vertex
*
531 isis_spf_add2tent(struct isis_spftree
*spftree
, enum vertextype vtype
, void *id
,
532 uint32_t cost
, int depth
, struct isis_spf_adj
*sadj
,
533 struct isis_prefix_sid
*psid
, struct isis_vertex
*parent
)
535 struct isis_vertex
*vertex
;
536 struct listnode
*node
;
538 char buff
[VID2STR_BUFFER
];
540 vertex
= isis_find_vertex(&spftree
->paths
, id
, vtype
);
541 if (vertex
!= NULL
) {
543 "%s: vertex %s of type %s already in PATH; check for sysId collisions with established neighbors",
544 __func__
, vid2string(vertex
, buff
, sizeof(buff
)),
545 vtype2string(vertex
->type
));
548 vertex
= isis_find_vertex(&spftree
->tents
, id
, vtype
);
549 if (vertex
!= NULL
) {
551 "%s: vertex %s of type %s already in TENT; check for sysId collisions with established neighbors",
552 __func__
, vid2string(vertex
, buff
, sizeof(buff
)),
553 vtype2string(vertex
->type
));
557 vertex
= isis_vertex_new(spftree
, id
, vtype
);
559 vertex
->depth
= depth
;
560 if (VTYPE_IP(vtype
) && spftree
->area
->srdb
.enabled
&& psid
) {
561 struct isis_area
*area
= spftree
->area
;
562 struct isis_vertex
*vertex_psid
;
565 * Check if the Prefix-SID is already in use by another prefix.
567 vertex_psid
= isis_spf_prefix_sid_lookup(spftree
, psid
);
569 && !prefix_same(&vertex_psid
->N
.ip
.p
.dest
,
570 &vertex
->N
.ip
.p
.dest
)) {
572 EC_ISIS_SID_COLLISION
,
573 "ISIS-Sr (%s): collision detected, prefixes %pFX and %pFX share the same SID %s (%u)",
574 area
->area_tag
, &vertex
->N
.ip
.p
.dest
,
575 &vertex_psid
->N
.ip
.p
.dest
,
576 CHECK_FLAG(psid
->flags
, ISIS_PREFIX_SID_VALUE
)
584 local
= (vertex
->depth
== 1);
585 vertex
->N
.ip
.sr
.sid
= *psid
;
586 vertex
->N
.ip
.sr
.label
=
587 sr_prefix_in_label(area
, psid
, local
);
588 if (vertex
->N
.ip
.sr
.label
!= MPLS_INVALID_LABEL
)
589 vertex
->N
.ip
.sr
.present
= true;
591 (void)hash_get(spftree
->prefix_sids
, vertex
,
597 listnode_add(vertex
->parents
, parent
);
600 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
))
601 vertex_update_firsthops(vertex
, parent
);
603 last_hop
= (vertex
->depth
== 2);
604 if (parent
&& parent
->Adj_N
&& listcount(parent
->Adj_N
) > 0) {
605 struct isis_vertex_adj
*parent_vadj
;
607 for (ALL_LIST_ELEMENTS_RO(parent
->Adj_N
, node
, parent_vadj
))
608 isis_vertex_adj_add(spftree
, vertex
, vertex
->Adj_N
,
609 parent_vadj
->sadj
, psid
, last_hop
);
611 isis_vertex_adj_add(spftree
, vertex
, vertex
->Adj_N
, sadj
, psid
,
616 if (IS_DEBUG_SPF_EVENTS
)
618 "ISIS-SPF: add to TENT %s %s %s depth %d dist %d adjcount %d",
619 print_sys_hostname(vertex
->N
.id
),
620 vtype2string(vertex
->type
),
621 vid2string(vertex
, buff
, sizeof(buff
)), vertex
->depth
,
622 vertex
->d_N
, listcount(vertex
->Adj_N
));
623 #endif /* EXTREME_DEBUG */
625 isis_vertex_queue_insert(&spftree
->tents
, vertex
);
629 static void isis_spf_add_local(struct isis_spftree
*spftree
,
630 enum vertextype vtype
, void *id
,
631 struct isis_spf_adj
*sadj
, uint32_t cost
,
632 struct isis_prefix_sid
*psid
,
633 struct isis_vertex
*parent
)
635 struct isis_vertex
*vertex
;
637 vertex
= isis_find_vertex(&spftree
->tents
, id
, vtype
);
641 if (vertex
->d_N
== cost
) {
643 bool last_hop
= (vertex
->depth
== 2);
645 isis_vertex_adj_add(spftree
, vertex
,
646 vertex
->Adj_N
, sadj
, psid
,
650 if (!CHECK_FLAG(spftree
->flags
,
651 F_SPFTREE_NO_ADJACENCIES
)
652 && listcount(vertex
->Adj_N
) > ISIS_MAX_PATH_SPLITS
)
653 remove_excess_adjs(vertex
->Adj_N
);
654 if (parent
&& (listnode_lookup(vertex
->parents
, parent
)
656 listnode_add(vertex
->parents
, parent
);
658 } else if (vertex
->d_N
< cost
) {
661 } else { /* vertex->d_N > cost */
663 isis_vertex_queue_delete(&spftree
->tents
, vertex
);
664 isis_vertex_del(vertex
);
668 isis_spf_add2tent(spftree
, vtype
, id
, cost
, 1, sadj
, psid
, parent
);
672 static void process_N(struct isis_spftree
*spftree
, enum vertextype vtype
,
673 void *id
, uint32_t dist
, uint16_t depth
,
674 struct isis_prefix_sid
*psid
, struct isis_vertex
*parent
)
676 struct isis_vertex
*vertex
;
678 char buff
[VID2STR_BUFFER
];
681 assert(spftree
&& parent
);
683 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)
687 struct prefix_pair p
;
688 if (vtype
>= VTYPE_IPREACH_INTERNAL
) {
689 memcpy(&p
, id
, sizeof(p
));
695 /* RFC3787 section 5.1 */
696 if (spftree
->area
->newmetric
== 1) {
697 if (dist
> MAX_WIDE_PATH_METRIC
)
701 else if (spftree
->area
->oldmetric
== 1) {
702 if (dist
> MAX_NARROW_PATH_METRIC
)
707 vertex
= isis_find_vertex(&spftree
->paths
, id
, vtype
);
710 if (IS_DEBUG_SPF_EVENTS
)
712 "ISIS-SPF: process_N %s %s %s dist %d already found from PATH",
713 print_sys_hostname(vertex
->N
.id
),
715 vid2string(vertex
, buff
, sizeof(buff
)), dist
);
716 #endif /* EXTREME_DEBUG */
717 assert(dist
>= vertex
->d_N
);
721 vertex
= isis_find_vertex(&spftree
->tents
, id
, vtype
);
726 if (IS_DEBUG_SPF_EVENTS
)
728 "ISIS-SPF: process_N %s %s %s dist %d parent %s adjcount %d",
729 print_sys_hostname(vertex
->N
.id
),
731 vid2string(vertex
, buff
, sizeof(buff
)), dist
,
732 (parent
? print_sys_hostname(parent
->N
.id
)
734 (parent
? listcount(parent
->Adj_N
) : 0));
735 #endif /* EXTREME_DEBUG */
736 if (vertex
->d_N
== dist
) {
737 struct listnode
*node
;
738 struct isis_vertex_adj
*parent_vadj
;
739 for (ALL_LIST_ELEMENTS_RO(parent
->Adj_N
, node
,
741 if (!isis_vertex_adj_exists(
743 parent_vadj
->sadj
)) {
744 bool last_hop
= (vertex
->depth
== 2);
746 isis_vertex_adj_add(spftree
, vertex
,
751 if (CHECK_FLAG(spftree
->flags
,
752 F_SPFTREE_HOPCOUNT_METRIC
))
753 vertex_update_firsthops(vertex
, parent
);
755 if (!CHECK_FLAG(spftree
->flags
,
756 F_SPFTREE_NO_ADJACENCIES
)
757 && listcount(vertex
->Adj_N
) > ISIS_MAX_PATH_SPLITS
)
758 remove_excess_adjs(vertex
->Adj_N
);
759 if (listnode_lookup(vertex
->parents
, parent
) == NULL
)
760 listnode_add(vertex
->parents
, parent
);
762 } else if (vertex
->d_N
< dist
) {
766 isis_vertex_queue_delete(&spftree
->tents
, vertex
);
767 isis_vertex_del(vertex
);
772 if (IS_DEBUG_SPF_EVENTS
)
774 "ISIS-SPF: process_N add2tent %s %s dist %d parent %s",
775 print_sys_hostname(id
), vtype2string(vtype
), dist
,
776 (parent
? print_sys_hostname(parent
->N
.id
) : "null"));
777 #endif /* EXTREME_DEBUG */
779 isis_spf_add2tent(spftree
, vtype
, id
, dist
, depth
, NULL
, psid
, parent
);
786 static int isis_spf_process_lsp(struct isis_spftree
*spftree
,
787 struct isis_lsp
*lsp
, uint32_t cost
,
788 uint16_t depth
, uint8_t *root_sysid
,
789 struct isis_vertex
*parent
)
791 bool pseudo_lsp
= LSP_PSEUDO_ID(lsp
->hdr
.lsp_id
);
792 struct listnode
*fragnode
= NULL
;
794 enum vertextype vtype
;
795 static const uint8_t null_sysid
[ISIS_SYS_ID_LEN
];
796 struct isis_mt_router_info
*mt_router_info
= NULL
;
797 struct prefix_pair ip_info
;
800 if (isis_lfa_excise_node_check(spftree
, lsp
->hdr
.lsp_id
)) {
802 zlog_debug("ISIS-LFA: excising node %s",
803 print_sys_hostname(lsp
->hdr
.lsp_id
));
810 if (spftree
->mtid
!= ISIS_MT_IPV4_UNICAST
)
811 mt_router_info
= isis_tlvs_lookup_mt_router_info(lsp
->tlvs
,
814 if (!pseudo_lsp
&& (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
815 && !speaks(lsp
->tlvs
->protocols_supported
.protocols
,
816 lsp
->tlvs
->protocols_supported
.count
,
821 /* RFC3787 section 4 SHOULD ignore overload bit in pseudo LSPs */
822 bool no_overload
= (pseudo_lsp
823 || (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
824 && !ISIS_MASK_LSP_OL_BIT(lsp
->hdr
.lsp_bits
))
825 || (mt_router_info
&& !mt_router_info
->overload
));
828 if (lsp
->hdr
.seqno
== 0) {
829 zlog_warn("%s: lsp with 0 seq_num - ignore", __func__
);
834 if (IS_DEBUG_SPF_EVENTS
)
835 zlog_debug("ISIS-SPF: process_lsp %s",
836 print_sys_hostname(lsp
->hdr
.lsp_id
));
837 #endif /* EXTREME_DEBUG */
840 if ((pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
841 && spftree
->area
->oldmetric
) {
842 struct isis_oldstyle_reach
*r
;
843 for (r
= (struct isis_oldstyle_reach
*)
844 lsp
->tlvs
->oldstyle_reach
.head
;
850 /* Two way connectivity */
851 if (!LSP_PSEUDO_ID(r
->id
)
852 && !memcmp(r
->id
, root_sysid
,
856 && !memcmp(r
->id
, null_sysid
,
859 dist
= cost
+ r
->metric
;
863 : VTYPE_NONPSEUDO_IS
,
864 (void *)r
->id
, dist
, depth
+ 1, NULL
,
869 if (spftree
->area
->newmetric
) {
870 struct isis_item_list
*te_neighs
= NULL
;
871 if (pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
872 te_neighs
= &lsp
->tlvs
->extended_reach
;
874 te_neighs
= isis_lookup_mt_items(
875 &lsp
->tlvs
->mt_reach
, spftree
->mtid
);
877 struct isis_extended_reach
*er
;
878 for (er
= te_neighs
? (struct isis_extended_reach
*)
883 /* Two way connectivity */
884 if (!LSP_PSEUDO_ID(er
->id
)
885 && !memcmp(er
->id
, root_sysid
,
889 && !memcmp(er
->id
, null_sysid
,
893 + (CHECK_FLAG(spftree
->flags
,
894 F_SPFTREE_HOPCOUNT_METRIC
)
898 LSP_PSEUDO_ID(er
->id
)
900 : VTYPE_NONPSEUDO_TE_IS
,
901 (void *)er
->id
, dist
, depth
+ 1, NULL
,
907 if (!fabricd
&& !pseudo_lsp
&& spftree
->family
== AF_INET
908 && spftree
->mtid
== ISIS_MT_IPV4_UNICAST
909 && spftree
->area
->oldmetric
) {
910 struct isis_item_list
*reachs
[] = {
911 &lsp
->tlvs
->oldstyle_ip_reach
,
912 &lsp
->tlvs
->oldstyle_ip_reach_ext
};
914 for (unsigned int i
= 0; i
< array_size(reachs
); i
++) {
915 vtype
= i
? VTYPE_IPREACH_EXTERNAL
916 : VTYPE_IPREACH_INTERNAL
;
918 memset(&ip_info
, 0, sizeof(ip_info
));
919 ip_info
.dest
.family
= AF_INET
;
921 struct isis_oldstyle_ip_reach
*r
;
922 for (r
= (struct isis_oldstyle_ip_reach
*)reachs
[i
]
925 dist
= cost
+ r
->metric
;
926 ip_info
.dest
.u
.prefix4
= r
->prefix
.prefix
;
927 ip_info
.dest
.prefixlen
= r
->prefix
.prefixlen
;
928 process_N(spftree
, vtype
, &ip_info
,
929 dist
, depth
+ 1, NULL
, parent
);
934 /* we can skip all the rest if we're using metric style narrow */
935 if (!spftree
->area
->newmetric
)
938 if (!pseudo_lsp
&& spftree
->family
== AF_INET
) {
939 struct isis_item_list
*ipv4_reachs
;
940 if (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
941 ipv4_reachs
= &lsp
->tlvs
->extended_ip_reach
;
943 ipv4_reachs
= isis_lookup_mt_items(
944 &lsp
->tlvs
->mt_ip_reach
, spftree
->mtid
);
946 memset(&ip_info
, 0, sizeof(ip_info
));
947 ip_info
.dest
.family
= AF_INET
;
949 struct isis_extended_ip_reach
*r
;
951 ? (struct isis_extended_ip_reach
*)
955 dist
= cost
+ r
->metric
;
956 ip_info
.dest
.u
.prefix4
= r
->prefix
.prefix
;
957 ip_info
.dest
.prefixlen
= r
->prefix
.prefixlen
;
959 /* Parse list of Prefix-SID subTLVs if SR is enabled */
960 has_valid_psid
= false;
961 if (spftree
->area
->srdb
.enabled
&& r
->subtlvs
) {
962 for (struct isis_item
*i
=
963 r
->subtlvs
->prefix_sids
.head
;
965 struct isis_prefix_sid
*psid
=
966 (struct isis_prefix_sid
*)i
;
968 if (psid
->algorithm
!= SR_ALGORITHM_SPF
)
971 has_valid_psid
= true;
972 process_N(spftree
, VTYPE_IPREACH_TE
,
973 &ip_info
, dist
, depth
+ 1,
976 * Stop the Prefix-SID iteration since
977 * we only support the SPF algorithm for
984 process_N(spftree
, VTYPE_IPREACH_TE
, &ip_info
,
985 dist
, depth
+ 1, NULL
, parent
);
989 if (!pseudo_lsp
&& spftree
->family
== AF_INET6
) {
990 struct isis_item_list
*ipv6_reachs
;
991 if (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
992 ipv6_reachs
= &lsp
->tlvs
->ipv6_reach
;
994 ipv6_reachs
= isis_lookup_mt_items(
995 &lsp
->tlvs
->mt_ipv6_reach
, spftree
->mtid
);
997 struct isis_ipv6_reach
*r
;
999 ? (struct isis_ipv6_reach
*)ipv6_reachs
->head
1002 dist
= cost
+ r
->metric
;
1003 vtype
= r
->external
? VTYPE_IP6REACH_EXTERNAL
1004 : VTYPE_IP6REACH_INTERNAL
;
1005 memset(&ip_info
, 0, sizeof(ip_info
));
1006 ip_info
.dest
.family
= AF_INET6
;
1007 ip_info
.dest
.u
.prefix6
= r
->prefix
.prefix
;
1008 ip_info
.dest
.prefixlen
= r
->prefix
.prefixlen
;
1010 if (spftree
->area
->srdb
.enabled
&& r
->subtlvs
&&
1011 r
->subtlvs
->source_prefix
&&
1012 r
->subtlvs
->source_prefix
->prefixlen
) {
1013 if (spftree
->tree_id
!= SPFTREE_DSTSRC
) {
1014 char buff
[VID2STR_BUFFER
];
1015 zlog_warn("Ignoring dest-src route %s in non dest-src topology",
1018 r
->subtlvs
->source_prefix
,
1024 ip_info
.src
= *r
->subtlvs
->source_prefix
;
1027 /* Parse list of Prefix-SID subTLVs */
1028 has_valid_psid
= false;
1030 for (struct isis_item
*i
=
1031 r
->subtlvs
->prefix_sids
.head
;
1033 struct isis_prefix_sid
*psid
=
1034 (struct isis_prefix_sid
*)i
;
1036 if (psid
->algorithm
!= SR_ALGORITHM_SPF
)
1039 has_valid_psid
= true;
1040 process_N(spftree
, vtype
, &ip_info
,
1041 dist
, depth
+ 1, psid
,
1044 * Stop the Prefix-SID iteration since
1045 * we only support the SPF algorithm for
1051 if (!has_valid_psid
)
1052 process_N(spftree
, vtype
, &ip_info
, dist
,
1053 depth
+ 1, NULL
, parent
);
1059 /* if attach bit set in LSP, attached-bit receive ignore is
1060 * not configured, we are a level-1 area and we have no other
1061 * level-2 | level1-2 areas then add a default route toward
1064 if ((lsp
->hdr
.lsp_bits
& LSPBIT_ATT
) == LSPBIT_ATT
1065 && !spftree
->area
->attached_bit_rcv_ignore
1066 && (spftree
->area
->is_type
& IS_LEVEL_1
)
1067 && !isis_level2_adj_up(spftree
->area
)) {
1068 struct prefix_pair ip_info
= { {0} };
1069 if (IS_DEBUG_RTE_EVENTS
)
1070 zlog_debug("ISIS-Spf (%s): add default %s route",
1071 rawlspid_print(lsp
->hdr
.lsp_id
),
1072 spftree
->family
== AF_INET
? "ipv4"
1075 if (spftree
->family
== AF_INET
) {
1076 ip_info
.dest
.family
= AF_INET
;
1077 vtype
= VTYPE_IPREACH_INTERNAL
;
1079 ip_info
.dest
.family
= AF_INET6
;
1080 vtype
= VTYPE_IP6REACH_INTERNAL
;
1082 process_N(spftree
, vtype
, &ip_info
, cost
, depth
+ 1, NULL
,
1086 if (fragnode
== NULL
)
1087 fragnode
= listhead(lsp
->lspu
.frags
);
1089 fragnode
= listnextnode(fragnode
);
1092 lsp
= listgetdata(fragnode
);
1099 static struct isis_adjacency
*adj_find(struct list
*adj_list
, const uint8_t *id
,
1100 int level
, uint16_t mtid
, int family
)
1102 struct isis_adjacency
*adj
;
1103 struct listnode
*node
;
1105 for (ALL_LIST_ELEMENTS_RO(adj_list
, node
, adj
)) {
1106 if (!(adj
->level
& level
))
1108 if (memcmp(adj
->sysid
, id
, ISIS_SYS_ID_LEN
) != 0)
1110 if (adj
->adj_state
!= ISIS_ADJ_UP
)
1112 if (!adj_has_mt(adj
, mtid
))
1114 if (mtid
== ISIS_MT_IPV4_UNICAST
1115 && !speaks(adj
->nlpids
.nlpids
, adj
->nlpids
.count
, family
))
1123 struct spf_preload_tent_ip_reach_args
{
1124 struct isis_spftree
*spftree
;
1125 struct isis_vertex
*parent
;
1128 static int isis_spf_preload_tent_ip_reach_cb(const struct prefix
*prefix
,
1129 uint32_t metric
, bool external
,
1130 struct isis_subtlvs
*subtlvs
,
1133 struct spf_preload_tent_ip_reach_args
*args
= arg
;
1134 struct isis_spftree
*spftree
= args
->spftree
;
1135 struct isis_vertex
*parent
= args
->parent
;
1136 struct prefix_pair ip_info
;
1137 enum vertextype vtype
;
1138 bool has_valid_psid
= false;
1141 return LSP_ITER_CONTINUE
;
1143 assert(spftree
->family
== prefix
->family
);
1144 memset(&ip_info
, 0, sizeof(ip_info
));
1145 prefix_copy(&ip_info
.dest
, prefix
);
1146 apply_mask(&ip_info
.dest
);
1148 if (prefix
->family
== AF_INET
)
1149 vtype
= VTYPE_IPREACH_INTERNAL
;
1151 vtype
= VTYPE_IP6REACH_INTERNAL
;
1153 /* Parse list of Prefix-SID subTLVs if SR is enabled */
1154 if (spftree
->area
->srdb
.enabled
&& subtlvs
) {
1155 for (struct isis_item
*i
= subtlvs
->prefix_sids
.head
; i
;
1157 struct isis_prefix_sid
*psid
=
1158 (struct isis_prefix_sid
*)i
;
1160 if (psid
->algorithm
!= SR_ALGORITHM_SPF
)
1163 has_valid_psid
= true;
1164 isis_spf_add_local(spftree
, vtype
, &ip_info
, NULL
, 0,
1168 * Stop the Prefix-SID iteration since we only support
1169 * the SPF algorithm for now.
1174 if (!has_valid_psid
)
1175 isis_spf_add_local(spftree
, vtype
, &ip_info
, NULL
, 0, NULL
,
1178 return LSP_ITER_CONTINUE
;
1181 static void isis_spf_preload_tent(struct isis_spftree
*spftree
,
1182 uint8_t *root_sysid
,
1183 struct isis_lsp
*root_lsp
,
1184 struct isis_vertex
*parent
)
1186 struct spf_preload_tent_ip_reach_args ip_reach_args
;
1187 struct isis_spf_adj
*sadj
;
1188 struct listnode
*node
;
1190 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)) {
1191 ip_reach_args
.spftree
= spftree
;
1192 ip_reach_args
.parent
= parent
;
1193 isis_lsp_iterate_ip_reach(
1194 root_lsp
, spftree
->family
, spftree
->mtid
,
1195 isis_spf_preload_tent_ip_reach_cb
, &ip_reach_args
);
1198 /* Iterate over adjacencies. */
1199 for (ALL_LIST_ELEMENTS_RO(spftree
->sadj_list
, node
, sadj
)) {
1200 const uint8_t *adj_id
;
1203 if (CHECK_FLAG(sadj
->flags
, F_ISIS_SPF_ADJ_BROADCAST
))
1204 adj_id
= sadj
->lan
.desig_is_id
;
1208 if (isis_lfa_excise_adj_check(spftree
, adj_id
)) {
1210 zlog_debug("ISIS-SPF: excising adjacency %s",
1211 isis_format_id(sadj
->id
,
1212 ISIS_SYS_ID_LEN
+ 1));
1216 metric
= CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)
1219 if (!LSP_PSEUDO_ID(sadj
->id
)) {
1220 isis_spf_add_local(spftree
,
1221 CHECK_FLAG(sadj
->flags
,
1222 F_ISIS_SPF_ADJ_OLDMETRIC
)
1223 ? VTYPE_NONPSEUDO_IS
1224 : VTYPE_NONPSEUDO_TE_IS
,
1225 sadj
->id
, sadj
, metric
, NULL
,
1227 } else if (sadj
->lsp
) {
1228 isis_spf_process_lsp(spftree
, sadj
->lsp
, metric
, 0,
1229 spftree
->sysid
, parent
);
1234 struct spf_adj_find_reverse_metric_args
{
1235 const uint8_t *id_self
;
1236 uint32_t reverse_metric
;
1239 static int spf_adj_find_reverse_metric_cb(const uint8_t *id
, uint32_t metric
,
1241 struct isis_ext_subtlvs
*subtlvs
,
1244 struct spf_adj_find_reverse_metric_args
*args
= arg
;
1246 if (memcmp(id
, args
->id_self
, ISIS_SYS_ID_LEN
))
1247 return LSP_ITER_CONTINUE
;
1249 args
->reverse_metric
= metric
;
1251 return LSP_ITER_STOP
;
1255 * Change all SPF adjacencies to use the link cost in the direction from the
1256 * next hop back towards root in place of the link cost in the direction away
1257 * from root towards the next hop.
1259 static void spf_adj_get_reverse_metrics(struct isis_spftree
*spftree
)
1261 struct isis_spf_adj
*sadj
;
1262 struct listnode
*node
, *nnode
;
1264 for (ALL_LIST_ELEMENTS(spftree
->sadj_list
, node
, nnode
, sadj
)) {
1265 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1266 struct isis_lsp
*lsp_adj
;
1267 const uint8_t *id_self
;
1268 struct spf_adj_find_reverse_metric_args args
;
1270 /* Skip pseudonodes. */
1271 if (LSP_PSEUDO_ID(sadj
->id
))
1274 /* Find LSP of the corresponding adjacency. */
1275 memcpy(lspid
, sadj
->id
, ISIS_SYS_ID_LEN
);
1276 LSP_PSEUDO_ID(lspid
) = 0;
1277 LSP_FRAGMENT(lspid
) = 0;
1278 lsp_adj
= lsp_search(spftree
->lspdb
, lspid
);
1279 if (lsp_adj
== NULL
|| lsp_adj
->hdr
.rem_lifetime
== 0) {
1280 /* Delete one-way adjacency. */
1281 listnode_delete(spftree
->sadj_list
, sadj
);
1282 isis_spf_adj_free(sadj
);
1286 /* Find root node in the LSP of the adjacent router. */
1287 if (CHECK_FLAG(sadj
->flags
, F_ISIS_SPF_ADJ_BROADCAST
))
1288 id_self
= sadj
->lan
.desig_is_id
;
1290 id_self
= spftree
->sysid
;
1291 args
.id_self
= id_self
;
1292 args
.reverse_metric
= UINT32_MAX
;
1293 isis_lsp_iterate_is_reach(lsp_adj
, spftree
->mtid
,
1294 spf_adj_find_reverse_metric_cb
,
1296 if (args
.reverse_metric
== UINT32_MAX
) {
1297 /* Delete one-way adjacency. */
1298 listnode_delete(spftree
->sadj_list
, sadj
);
1299 isis_spf_adj_free(sadj
);
1302 sadj
->metric
= args
.reverse_metric
;
1306 static void spf_adj_list_parse_tlv(struct isis_spftree
*spftree
,
1307 struct list
*adj_list
, const uint8_t *id
,
1308 const uint8_t *desig_is_id
,
1309 uint32_t pseudo_metric
, uint32_t metric
,
1311 struct isis_ext_subtlvs
*subtlvs
)
1313 struct isis_spf_adj
*sadj
;
1314 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1315 struct isis_lsp
*lsp
;
1318 /* Skip self in the pseudonode. */
1319 if (desig_is_id
&& !memcmp(id
, spftree
->sysid
, ISIS_SYS_ID_LEN
))
1322 /* Find LSP from the adjacency. */
1323 memcpy(lspid
, id
, ISIS_SYS_ID_LEN
+ 1);
1324 LSP_FRAGMENT(lspid
) = 0;
1325 lsp
= lsp_search(spftree
->lspdb
, lspid
);
1326 if (lsp
== NULL
|| lsp
->hdr
.rem_lifetime
== 0) {
1327 zlog_warn("ISIS-SPF: No LSP found from root to L%d %s",
1328 spftree
->level
, rawlspid_print(lspid
));
1332 sadj
= XCALLOC(MTYPE_ISIS_SPF_ADJ
, sizeof(*sadj
));
1333 memcpy(sadj
->id
, id
, sizeof(sadj
->id
));
1335 memcpy(sadj
->lan
.desig_is_id
, desig_is_id
,
1336 sizeof(sadj
->lan
.desig_is_id
));
1337 SET_FLAG(flags
, F_ISIS_SPF_ADJ_BROADCAST
);
1338 sadj
->metric
= pseudo_metric
;
1340 sadj
->metric
= metric
;
1342 SET_FLAG(flags
, F_ISIS_SPF_ADJ_OLDMETRIC
);
1344 sadj
->subtlvs
= subtlvs
;
1345 sadj
->flags
= flags
;
1347 if ((oldmetric
&& metric
== ISIS_NARROW_METRIC_INFINITY
)
1348 || (!oldmetric
&& metric
== ISIS_WIDE_METRIC_INFINITY
))
1349 SET_FLAG(flags
, F_ISIS_SPF_ADJ_METRIC_INFINITY
);
1351 /* Set real adjacency. */
1352 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
)
1353 && !LSP_PSEUDO_ID(id
)) {
1354 struct isis_adjacency
*adj
;
1356 adj
= adj_find(adj_list
, id
, spftree
->level
, spftree
->mtid
,
1359 XFREE(MTYPE_ISIS_SPF_ADJ
, sadj
);
1363 listnode_delete(adj_list
, adj
);
1367 /* Add adjacency to the list. */
1368 listnode_add(spftree
->sadj_list
, sadj
);
1370 if (!LSP_PSEUDO_ID(id
)) {
1371 struct isis_spf_node
*node
;
1373 node
= isis_spf_node_find(&spftree
->adj_nodes
, id
);
1375 node
= isis_spf_node_new(&spftree
->adj_nodes
, id
);
1376 if (node
->best_metric
== 0 || sadj
->metric
< node
->best_metric
)
1377 node
->best_metric
= sadj
->metric
;
1378 listnode_add(node
->adjacencies
, sadj
);
1381 /* Parse pseudonode LSP too. */
1382 if (LSP_PSEUDO_ID(id
))
1383 spf_adj_list_parse_lsp(spftree
, adj_list
, lsp
, id
, metric
);
1386 static void spf_adj_list_parse_lsp(struct isis_spftree
*spftree
,
1387 struct list
*adj_list
, struct isis_lsp
*lsp
,
1388 const uint8_t *pseudo_nodeid
,
1389 uint32_t pseudo_metric
)
1391 bool pseudo_lsp
= LSP_PSEUDO_ID(lsp
->hdr
.lsp_id
);
1392 struct isis_lsp
*frag
;
1393 struct listnode
*node
;
1394 struct isis_item
*head
;
1395 struct isis_item_list
*te_neighs
;
1397 if (lsp
->hdr
.seqno
== 0 || lsp
->hdr
.rem_lifetime
== 0)
1402 if (pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
) {
1403 head
= lsp
->tlvs
->oldstyle_reach
.head
;
1404 for (struct isis_oldstyle_reach
*reach
=
1405 (struct isis_oldstyle_reach
*)head
;
1406 reach
; reach
= reach
->next
) {
1407 spf_adj_list_parse_tlv(
1408 spftree
, adj_list
, reach
->id
,
1409 pseudo_nodeid
, pseudo_metric
,
1410 reach
->metric
, true, NULL
);
1414 if (pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
1415 te_neighs
= &lsp
->tlvs
->extended_reach
;
1417 te_neighs
= isis_get_mt_items(&lsp
->tlvs
->mt_reach
,
1420 head
= te_neighs
->head
;
1421 for (struct isis_extended_reach
*reach
=
1422 (struct isis_extended_reach
*)head
;
1423 reach
; reach
= reach
->next
) {
1424 spf_adj_list_parse_tlv(
1425 spftree
, adj_list
, reach
->id
,
1426 pseudo_nodeid
, pseudo_metric
,
1427 reach
->metric
, false, reach
->subtlvs
);
1432 if (LSP_FRAGMENT(lsp
->hdr
.lsp_id
))
1435 /* Parse LSP fragments. */
1436 for (ALL_LIST_ELEMENTS_RO(lsp
->lspu
.frags
, node
, frag
)) {
1440 spf_adj_list_parse_lsp(spftree
, adj_list
, frag
, pseudo_nodeid
,
1445 static void isis_spf_build_adj_list(struct isis_spftree
*spftree
,
1446 struct isis_lsp
*lsp
)
1448 struct list
*adj_list
= NULL
;
1450 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
1451 adj_list
= list_dup(spftree
->area
->adjacency_list
);
1453 spf_adj_list_parse_lsp(spftree
, adj_list
, lsp
, NULL
, 0);
1455 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
1456 list_delete(&adj_list
);
1458 if (spftree
->type
== SPF_TYPE_REVERSE
)
1459 spf_adj_get_reverse_metrics(spftree
);
1463 * The parent(s) for vertex is set when added to TENT list
1464 * now we just put the child pointer(s) in place
1466 static void add_to_paths(struct isis_spftree
*spftree
,
1467 struct isis_vertex
*vertex
)
1469 #ifdef EXTREME_DEBUG
1470 char buff
[VID2STR_BUFFER
];
1471 #endif /* EXTREME_DEBUG */
1473 if (isis_find_vertex(&spftree
->paths
, &vertex
->N
, vertex
->type
))
1475 isis_vertex_queue_append(&spftree
->paths
, vertex
);
1477 #ifdef EXTREME_DEBUG
1478 if (IS_DEBUG_SPF_EVENTS
)
1479 zlog_debug("ISIS-SPF: added %s %s %s depth %d dist %d to PATHS",
1480 print_sys_hostname(vertex
->N
.id
),
1481 vtype2string(vertex
->type
),
1482 vid2string(vertex
, buff
, sizeof(buff
)),
1483 vertex
->depth
, vertex
->d_N
);
1484 #endif /* EXTREME_DEBUG */
1487 static void init_spt(struct isis_spftree
*spftree
, int mtid
)
1489 /* Clear data from previous run. */
1490 hash_clean(spftree
->prefix_sids
, NULL
);
1491 isis_spf_node_list_clear(&spftree
->adj_nodes
);
1492 list_delete_all_node(spftree
->sadj_list
);
1493 isis_vertex_queue_clear(&spftree
->tents
);
1494 isis_vertex_queue_clear(&spftree
->paths
);
1495 isis_zebra_rlfa_unregister_all(spftree
);
1496 isis_rlfa_list_clear(spftree
);
1497 list_delete_all_node(spftree
->lfa
.remote
.pc_spftrees
);
1498 memset(&spftree
->lfa
.protection_counters
, 0,
1499 sizeof(spftree
->lfa
.protection_counters
));
1501 spftree
->mtid
= mtid
;
1504 static enum spf_prefix_priority
1505 spf_prefix_priority(struct isis_spftree
*spftree
, struct isis_vertex
*vertex
)
1507 struct isis_area
*area
= spftree
->area
;
1508 struct prefix
*prefix
= &vertex
->N
.ip
.p
.dest
;
1510 for (int priority
= SPF_PREFIX_PRIO_CRITICAL
;
1511 priority
<= SPF_PREFIX_PRIO_MEDIUM
; priority
++) {
1512 struct spf_prefix_priority_acl
*ppa
;
1513 enum filter_type ret
= FILTER_PERMIT
;
1515 ppa
= &area
->spf_prefix_priorities
[priority
];
1516 switch (spftree
->family
) {
1518 ret
= access_list_apply(ppa
->list_v4
, prefix
);
1521 ret
= access_list_apply(ppa
->list_v6
, prefix
);
1527 if (ret
== FILTER_PERMIT
)
1531 /* Assign medium priority to loopback prefixes by default. */
1532 if (is_host_route(prefix
))
1533 return SPF_PREFIX_PRIO_MEDIUM
;
1535 return SPF_PREFIX_PRIO_LOW
;
1538 static void spf_path_process(struct isis_spftree
*spftree
,
1539 struct isis_vertex
*vertex
)
1541 struct isis_area
*area
= spftree
->area
;
1542 int level
= spftree
->level
;
1543 char buff
[VID2STR_BUFFER
];
1545 if (spftree
->type
== SPF_TYPE_TI_LFA
&& VTYPE_IS(vertex
->type
)
1546 && !CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
)) {
1547 if (listcount(vertex
->Adj_N
) > 0) {
1548 struct isis_adjacency
*adj
;
1550 if (isis_tilfa_check(spftree
, vertex
) != 0)
1553 adj
= isis_adj_find(area
, level
, vertex
->N
.id
);
1555 sr_adj_sid_add_single(adj
, spftree
->family
,
1556 true, vertex
->Adj_N
);
1557 } else if (IS_DEBUG_SPF_EVENTS
)
1559 "ISIS-SPF: no adjacencies, do not install backup Adj-SID for %s depth %d dist %d",
1560 vid2string(vertex
, buff
, sizeof(buff
)),
1561 vertex
->depth
, vertex
->d_N
);
1564 if (VTYPE_IP(vertex
->type
)
1565 && !CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ROUTES
)) {
1566 enum spf_prefix_priority priority
;
1568 priority
= spf_prefix_priority(spftree
, vertex
);
1569 vertex
->N
.ip
.priority
= priority
;
1570 if (vertex
->depth
== 1 || listcount(vertex
->Adj_N
) > 0) {
1571 struct isis_spftree
*pre_spftree
;
1572 struct route_table
*route_table
= NULL
;
1573 bool allow_ecmp
= false;
1575 switch (spftree
->type
) {
1577 case SPF_TYPE_TI_LFA
:
1579 > area
->lfa_priority_limit
[level
- 1]) {
1582 "ISIS-LFA: skipping %s %s (low prefix priority)",
1591 case SPF_TYPE_FORWARD
:
1592 case SPF_TYPE_REVERSE
:
1596 switch (spftree
->type
) {
1598 isis_rlfa_check(spftree
, vertex
);
1600 case SPF_TYPE_TI_LFA
:
1601 if (isis_tilfa_check(spftree
, vertex
) != 0)
1604 pre_spftree
= spftree
->lfa
.old
.spftree
;
1605 route_table
= pre_spftree
->route_table_backup
;
1606 allow_ecmp
= area
->lfa_load_sharing
[level
- 1];
1607 pre_spftree
->lfa
.protection_counters
1608 .tilfa
[vertex
->N
.ip
.priority
] += 1;
1610 case SPF_TYPE_FORWARD
:
1611 case SPF_TYPE_REVERSE
:
1612 route_table
= spftree
->route_table
;
1616 * Update LFA protection counters (ignore local
1619 if (vertex
->depth
> 1) {
1620 spftree
->lfa
.protection_counters
1621 .total
[priority
] += 1;
1622 if (listcount(vertex
->Adj_N
) > 1)
1623 spftree
->lfa
.protection_counters
1624 .ecmp
[priority
] += 1;
1630 &vertex
->N
.ip
.p
.dest
, &vertex
->N
.ip
.p
.src
,
1631 vertex
->d_N
, vertex
->depth
, &vertex
->N
.ip
.sr
,
1632 vertex
->Adj_N
, allow_ecmp
, area
, route_table
);
1633 } else if (IS_DEBUG_SPF_EVENTS
)
1635 "ISIS-SPF: no adjacencies, do not install route for %s depth %d dist %d",
1636 vid2string(vertex
, buff
, sizeof(buff
)),
1637 vertex
->depth
, vertex
->d_N
);
1641 static void isis_spf_loop(struct isis_spftree
*spftree
,
1642 uint8_t *root_sysid
)
1644 struct isis_vertex
*vertex
;
1645 struct isis_lsp
*lsp
;
1646 struct listnode
*node
;
1648 while (isis_vertex_queue_count(&spftree
->tents
)) {
1649 vertex
= isis_vertex_queue_pop(&spftree
->tents
);
1651 #ifdef EXTREME_DEBUG
1652 if (IS_DEBUG_SPF_EVENTS
)
1654 "ISIS-SPF: get TENT node %s %s depth %d dist %d to PATHS",
1655 print_sys_hostname(vertex
->N
.id
),
1656 vtype2string(vertex
->type
), vertex
->depth
,
1658 #endif /* EXTREME_DEBUG */
1660 add_to_paths(spftree
, vertex
);
1661 if (!VTYPE_IS(vertex
->type
))
1664 lsp
= lsp_for_vertex(spftree
, vertex
);
1666 zlog_warn("ISIS-SPF: No LSP found for %s",
1667 isis_format_id(vertex
->N
.id
,
1668 sizeof(vertex
->N
.id
)));
1672 isis_spf_process_lsp(spftree
, lsp
, vertex
->d_N
, vertex
->depth
,
1673 root_sysid
, vertex
);
1676 /* Generate routes once the SPT is formed. */
1677 for (ALL_QUEUE_ELEMENTS_RO(&spftree
->paths
, node
, vertex
)) {
1678 /* New-style TLVs take precedence over the old-style TLVs. */
1679 switch (vertex
->type
) {
1680 case VTYPE_IPREACH_INTERNAL
:
1681 case VTYPE_IPREACH_EXTERNAL
:
1682 if (isis_find_vertex(&spftree
->paths
, &vertex
->N
,
1686 case VTYPE_PSEUDO_IS
:
1687 case VTYPE_PSEUDO_TE_IS
:
1688 case VTYPE_NONPSEUDO_IS
:
1689 case VTYPE_NONPSEUDO_TE_IS
:
1691 case VTYPE_IPREACH_TE
:
1692 case VTYPE_IP6REACH_INTERNAL
:
1693 case VTYPE_IP6REACH_EXTERNAL
:
1697 spf_path_process(spftree
, vertex
);
1701 struct isis_spftree
*isis_run_hopcount_spf(struct isis_area
*area
,
1703 struct isis_spftree
*spftree
)
1706 spftree
= isis_spftree_new(area
, &area
->lspdb
[IS_LEVEL_2
- 1],
1707 sysid
, ISIS_LEVEL2
, SPFTREE_IPV4
,
1709 F_SPFTREE_HOPCOUNT_METRIC
);
1711 init_spt(spftree
, ISIS_MT_IPV4_UNICAST
);
1712 if (!memcmp(sysid
, area
->isis
->sysid
, ISIS_SYS_ID_LEN
)) {
1713 struct isis_lsp
*root_lsp
;
1714 struct isis_vertex
*root_vertex
;
1716 root_lsp
= isis_root_system_lsp(spftree
->lspdb
, spftree
->sysid
);
1719 * If we are running locally, initialize with
1720 * information from adjacencies
1722 root_vertex
= isis_spf_add_root(spftree
);
1724 isis_spf_preload_tent(spftree
, sysid
, root_lsp
,
1728 isis_vertex_queue_insert(
1730 isis_vertex_new(spftree
, sysid
, VTYPE_NONPSEUDO_TE_IS
));
1733 isis_spf_loop(spftree
, sysid
);
1738 void isis_run_spf(struct isis_spftree
*spftree
)
1740 struct isis_lsp
*root_lsp
;
1741 struct isis_vertex
*root_vertex
;
1742 struct timeval time_start
;
1743 struct timeval time_end
;
1744 struct isis_mt_router_info
*mt_router_info
;
1747 /* Get time that can't roll backwards. */
1748 monotime(&time_start
);
1750 root_lsp
= isis_root_system_lsp(spftree
->lspdb
, spftree
->sysid
);
1751 if (root_lsp
== NULL
) {
1752 zlog_err("ISIS-SPF: could not find own l%d LSP!",
1757 /* Get Multi-Topology ID. */
1758 switch (spftree
->tree_id
) {
1760 mtid
= ISIS_MT_IPV4_UNICAST
;
1763 mt_router_info
= isis_tlvs_lookup_mt_router_info(
1764 root_lsp
->tlvs
, ISIS_MT_IPV6_UNICAST
);
1766 mtid
= ISIS_MT_IPV6_UNICAST
;
1768 mtid
= ISIS_MT_IPV4_UNICAST
;
1770 case SPFTREE_DSTSRC
:
1771 mtid
= ISIS_MT_IPV6_DSTSRC
;
1775 "%s should never be called with SPFTREE_COUNT as argument!",
1783 init_spt(spftree
, mtid
);
1785 root_vertex
= isis_spf_add_root(spftree
);
1787 isis_spf_build_adj_list(spftree
, root_lsp
);
1788 isis_spf_preload_tent(spftree
, spftree
->sysid
, root_lsp
, root_vertex
);
1793 if (!isis_vertex_queue_count(&spftree
->tents
)
1794 && (IS_DEBUG_SPF_EVENTS
)) {
1795 zlog_warn("ISIS-SPF: TENT is empty SPF-root:%s",
1796 print_sys_hostname(spftree
->sysid
));
1799 isis_spf_loop(spftree
, spftree
->sysid
);
1800 spftree
->runcount
++;
1801 spftree
->last_run_timestamp
= time(NULL
);
1802 spftree
->last_run_monotime
= monotime(&time_end
);
1803 spftree
->last_run_duration
=
1804 ((time_end
.tv_sec
- time_start
.tv_sec
) * 1000000)
1805 + (time_end
.tv_usec
- time_start
.tv_usec
);
1808 static void isis_run_spf_with_protection(struct isis_area
*area
,
1809 struct isis_spftree
*spftree
)
1811 /* Run forward SPF locally. */
1812 memcpy(spftree
->sysid
, area
->isis
->sysid
, ISIS_SYS_ID_LEN
);
1813 isis_run_spf(spftree
);
1815 /* Run LFA protection if configured. */
1816 if (area
->lfa_protected_links
[spftree
->level
- 1] > 0
1817 || area
->tilfa_protected_links
[spftree
->level
- 1] > 0)
1818 isis_spf_run_lfa(area
, spftree
);
1821 void isis_spf_verify_routes(struct isis_area
*area
, struct isis_spftree
**trees
)
1823 if (area
->is_type
== IS_LEVEL_1
) {
1824 isis_route_verify_table(area
, trees
[0]->route_table
,
1825 trees
[0]->route_table_backup
);
1826 } else if (area
->is_type
== IS_LEVEL_2
) {
1827 isis_route_verify_table(area
, trees
[1]->route_table
,
1828 trees
[1]->route_table_backup
);
1830 isis_route_verify_merge(area
, trees
[0]->route_table
,
1831 trees
[0]->route_table_backup
,
1832 trees
[1]->route_table
,
1833 trees
[1]->route_table_backup
);
1837 void isis_spf_invalidate_routes(struct isis_spftree
*tree
)
1839 isis_route_invalidate_table(tree
->area
, tree
->route_table
);
1841 /* Delete backup routes. */
1842 route_table_finish(tree
->route_table_backup
);
1843 tree
->route_table_backup
= srcdest_table_init();
1844 tree
->route_table_backup
->cleanup
= isis_route_node_cleanup
;
1847 void isis_spf_switchover_routes(struct isis_area
*area
,
1848 struct isis_spftree
**trees
, int family
,
1849 union g_addr
*nexthop_ip
, ifindex_t ifindex
,
1852 isis_route_switchover_nexthop(area
, trees
[level
- 1]->route_table
,
1853 family
, nexthop_ip
, ifindex
);
1856 static void isis_run_spf_cb(struct event
*thread
)
1858 struct isis_spf_run
*run
= EVENT_ARG(thread
);
1859 struct isis_area
*area
= run
->area
;
1860 int level
= run
->level
;
1863 XFREE(MTYPE_ISIS_SPF_RUN
, run
);
1865 if (!(area
->is_type
& level
)) {
1866 if (IS_DEBUG_SPF_EVENTS
)
1867 zlog_warn("ISIS-SPF (%s) area does not share level",
1872 isis_area_delete_backup_adj_sids(area
, level
);
1873 isis_area_invalidate_routes(area
, level
);
1875 if (IS_DEBUG_SPF_EVENTS
)
1876 zlog_debug("ISIS-SPF (%s) L%d SPF needed, periodic SPF",
1877 area
->area_tag
, level
);
1879 if (area
->ip_circuits
) {
1880 isis_run_spf_with_protection(
1881 area
, area
->spftree
[SPFTREE_IPV4
][level
- 1]);
1884 if (area
->ipv6_circuits
) {
1885 isis_run_spf_with_protection(
1886 area
, area
->spftree
[SPFTREE_IPV6
][level
- 1]);
1889 if (area
->ipv6_circuits
&& isis_area_ipv6_dstsrc_enabled(area
)) {
1890 isis_run_spf_with_protection(
1891 area
, area
->spftree
[SPFTREE_DSTSRC
][level
- 1]);
1896 area
->spf_run_count
[level
]++;
1898 isis_area_verify_routes(area
);
1900 /* walk all circuits and reset any spf specific flags */
1901 struct listnode
*node
;
1902 struct isis_circuit
*circuit
;
1903 for (ALL_LIST_ELEMENTS_RO(area
->circuit_list
, node
, circuit
))
1904 UNSET_FLAG(circuit
->flags
, ISIS_CIRCUIT_FLAPPED_AFTER_SPF
);
1906 fabricd_run_spf(area
);
1909 static struct isis_spf_run
*isis_run_spf_arg(struct isis_area
*area
, int level
)
1911 struct isis_spf_run
*run
= XMALLOC(MTYPE_ISIS_SPF_RUN
, sizeof(*run
));
1919 void isis_spf_timer_free(void *run
)
1921 XFREE(MTYPE_ISIS_SPF_RUN
, run
);
1924 int _isis_spf_schedule(struct isis_area
*area
, int level
,
1925 const char *func
, const char *file
, int line
)
1927 struct isis_spftree
*spftree
;
1929 long tree_diff
, diff
;
1932 now
= monotime(NULL
);
1934 for (tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
1935 spftree
= area
->spftree
[tree
][level
- 1];
1936 tree_diff
= difftime(now
- spftree
->last_run_monotime
, 0);
1937 if (tree_diff
!= now
&& (diff
== 0 || tree_diff
< diff
))
1941 if (CHECK_FLAG(im
->options
, F_ISIS_UNIT_TEST
))
1945 assert(area
->is_type
& level
);
1947 if (IS_DEBUG_SPF_EVENTS
) {
1949 "ISIS-SPF (%s) L%d SPF schedule called, lastrun %ld sec ago Caller: %s %s:%d",
1950 area
->area_tag
, level
, diff
, func
, file
, line
);
1953 EVENT_OFF(area
->t_rlfa_rib_update
);
1954 if (area
->spf_delay_ietf
[level
- 1]) {
1955 /* Need to call schedule function also if spf delay is running
1957 * restart holdoff timer - compare
1958 * draft-ietf-rtgwg-backoff-algo-04 */
1960 spf_backoff_schedule(area
->spf_delay_ietf
[level
- 1]);
1961 if (area
->spf_timer
[level
- 1])
1964 event_add_timer_msec(master
, isis_run_spf_cb
,
1965 isis_run_spf_arg(area
, level
), delay
,
1966 &area
->spf_timer
[level
- 1]);
1970 if (area
->spf_timer
[level
- 1])
1973 /* wait configured min_spf_interval before doing the SPF */
1975 if (diff
>= area
->min_spf_interval
[level
- 1]
1976 || area
->bfd_force_spf_refresh
) {
1978 * Last run is more than min interval ago or BFD signalled a
1979 * 'down' message, schedule immediate run
1983 if (area
->bfd_force_spf_refresh
) {
1985 "ISIS-SPF (%s) L%d SPF scheduled immediately due to BFD 'down' message",
1986 area
->area_tag
, level
);
1987 area
->bfd_force_spf_refresh
= false;
1990 timer
= area
->min_spf_interval
[level
- 1] - diff
;
1993 event_add_timer(master
, isis_run_spf_cb
, isis_run_spf_arg(area
, level
),
1994 timer
, &area
->spf_timer
[level
- 1]);
1996 if (IS_DEBUG_SPF_EVENTS
)
1997 zlog_debug("ISIS-SPF (%s) L%d SPF scheduled %ld sec from now",
1998 area
->area_tag
, level
, timer
);
2003 static void isis_print_paths(struct vty
*vty
, struct isis_vertex_queue
*queue
,
2004 uint8_t *root_sysid
)
2006 struct listnode
*node
;
2007 struct isis_vertex
*vertex
;
2008 char buff
[VID2STR_BUFFER
];
2011 "Vertex Type Metric Next-Hop Interface Parent\n");
2013 for (ALL_QUEUE_ELEMENTS_RO(queue
, node
, vertex
)) {
2014 if (VTYPE_IS(vertex
->type
)
2015 && memcmp(vertex
->N
.id
, root_sysid
, ISIS_SYS_ID_LEN
) == 0) {
2016 vty_out(vty
, "%-20s %-12s %-6s",
2017 print_sys_hostname(root_sysid
), "", "");
2018 vty_out(vty
, "%-30s\n", "");
2023 struct listnode
*anode
= listhead(vertex
->Adj_N
);
2024 struct listnode
*pnode
= listhead(vertex
->parents
);
2025 struct isis_vertex_adj
*vadj
;
2026 struct isis_vertex
*pvertex
;
2028 vty_out(vty
, "%-20s %-12s %-6u ",
2029 vid2string(vertex
, buff
, sizeof(buff
)),
2030 vtype2string(vertex
->type
), vertex
->d_N
);
2031 for (unsigned int i
= 0;
2032 i
< MAX(vertex
->Adj_N
? listcount(vertex
->Adj_N
) : 0,
2033 vertex
->parents
? listcount(vertex
->parents
) : 0);
2036 vadj
= listgetdata(anode
);
2037 anode
= anode
->next
;
2043 pvertex
= listgetdata(pnode
);
2044 pnode
= pnode
->next
;
2051 vty_out(vty
, "%-20s %-12s %-6s ", "", "", "");
2055 struct isis_spf_adj
*sadj
= vadj
->sadj
;
2057 vty_out(vty
, "%-20s %-9s ",
2058 print_sys_hostname(sadj
->id
),
2059 sadj
->adj
? sadj
->adj
->circuit
2066 vty_out(vty
, "%-20s %-9s ", "", "");
2068 vty_out(vty
, "%s(%d)",
2069 vid2string(pvertex
, buff
, sizeof(buff
)),
2079 void isis_print_spftree(struct vty
*vty
, struct isis_spftree
*spftree
)
2081 const char *tree_id_text
= NULL
;
2083 if (!spftree
|| !isis_vertex_queue_count(&spftree
->paths
))
2086 switch (spftree
->tree_id
) {
2088 tree_id_text
= "that speak IP";
2091 tree_id_text
= "that speak IPv6";
2093 case SPFTREE_DSTSRC
:
2094 tree_id_text
= "that support IPv6 dst-src routing";
2097 assert(!"isis_print_spftree shouldn't be called with SPFTREE_COUNT as type");
2101 vty_out(vty
, "IS-IS paths to level-%d routers %s\n", spftree
->level
,
2103 isis_print_paths(vty
, &spftree
->paths
, spftree
->sysid
);
2107 static void show_isis_topology_common(struct vty
*vty
, int levels
,
2110 struct listnode
*node
;
2111 struct isis_area
*area
;
2113 if (!isis
->area_list
|| isis
->area_list
->count
== 0)
2116 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
2117 vty_out(vty
, "Area %s:\n",
2118 area
->area_tag
? area
->area_tag
: "null");
2120 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
; level
++) {
2121 if ((level
& levels
) == 0)
2124 if (area
->ip_circuits
> 0) {
2127 area
->spftree
[SPFTREE_IPV4
][level
- 1]);
2129 if (area
->ipv6_circuits
> 0) {
2132 area
->spftree
[SPFTREE_IPV6
][level
- 1]);
2134 if (isis_area_ipv6_dstsrc_enabled(area
)) {
2135 isis_print_spftree(vty
,
2136 area
->spftree
[SPFTREE_DSTSRC
]
2141 if (fabricd_spftree(area
)) {
2143 "IS-IS paths to level-2 routers with hop-by-hop metric\n");
2144 isis_print_paths(vty
, &fabricd_spftree(area
)->paths
, isis
->sysid
);
2152 DEFUN(show_isis_topology
, show_isis_topology_cmd
,
2154 " [vrf <NAME|all>] topology"
2156 " [<level-1|level-2>]"
2159 SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
2161 "IS-IS paths to Intermediate Systems\n"
2163 "Paths to all level-1 routers in the area\n"
2164 "Paths to all level-2 routers in the domain\n"
2168 int levels
= ISIS_LEVELS
;
2169 struct listnode
*node
;
2170 struct isis
*isis
= NULL
;
2172 const char *vrf_name
= VRF_DEFAULT_NAME
;
2173 bool all_vrf
= false;
2176 if (argv_find(argv
, argc
, "topology", &idx
)) {
2178 levels
= ISIS_LEVEL1
| ISIS_LEVEL2
;
2179 else if (strmatch(argv
[idx
+ 1]->arg
, "level-1"))
2180 levels
= ISIS_LEVEL1
;
2182 levels
= ISIS_LEVEL2
;
2186 vty_out(vty
, "IS-IS Routing Process not enabled\n");
2189 ISIS_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
2193 for (ALL_LIST_ELEMENTS_RO(im
->isis
, node
, isis
))
2194 show_isis_topology_common(vty
, levels
, isis
);
2197 isis
= isis_lookup_by_vrfname(vrf_name
);
2199 show_isis_topology_common(vty
, levels
, isis
);
2205 static void isis_print_route(struct ttable
*tt
, const struct prefix
*prefix
,
2206 struct isis_route_info
*rinfo
, bool prefix_sid
,
2207 bool no_adjacencies
)
2209 struct isis_nexthop
*nexthop
;
2210 struct listnode
*node
;
2212 char buf_prefix
[BUFSIZ
];
2214 (void)prefix2str(prefix
, buf_prefix
, sizeof(buf_prefix
));
2215 for (ALL_LIST_ELEMENTS_RO(rinfo
->nexthops
, node
, nexthop
)) {
2216 struct interface
*ifp
;
2217 char buf_iface
[BUFSIZ
];
2218 char buf_nhop
[BUFSIZ
];
2220 if (!no_adjacencies
) {
2221 inet_ntop(nexthop
->family
, &nexthop
->ip
, buf_nhop
,
2223 ifp
= if_lookup_by_index(nexthop
->ifindex
, VRF_DEFAULT
);
2225 strlcpy(buf_iface
, ifp
->name
,
2228 snprintf(buf_iface
, sizeof(buf_iface
),
2229 "ifindex %u", nexthop
->ifindex
);
2231 strlcpy(buf_nhop
, print_sys_hostname(nexthop
->sysid
),
2233 strlcpy(buf_iface
, "-", sizeof(buf_iface
));
2237 char buf_sid
[BUFSIZ
] = {};
2238 char buf_lblop
[BUFSIZ
] = {};
2240 if (nexthop
->sr
.present
) {
2241 snprintf(buf_sid
, sizeof(buf_sid
), "%u",
2242 nexthop
->sr
.sid
.value
);
2243 sr_op2str(buf_lblop
, sizeof(buf_lblop
),
2244 rinfo
->sr
.label
, nexthop
->sr
.label
);
2246 strlcpy(buf_sid
, "-", sizeof(buf_sid
));
2247 strlcpy(buf_lblop
, "-", sizeof(buf_lblop
));
2251 ttable_add_row(tt
, "%s|%u|%s|%s|%s|%s",
2252 buf_prefix
, rinfo
->cost
,
2253 buf_iface
, buf_nhop
, buf_sid
,
2257 ttable_add_row(tt
, "||%s|%s|%s|%s", buf_iface
,
2258 buf_nhop
, buf_sid
, buf_lblop
);
2260 char buf_labels
[BUFSIZ
] = {};
2262 if (nexthop
->label_stack
) {
2264 i
< nexthop
->label_stack
->num_labels
;
2266 char buf_label
[BUFSIZ
];
2269 nexthop
->label_stack
->label
[i
],
2273 strlcat(buf_labels
, "/",
2274 sizeof(buf_labels
));
2275 strlcat(buf_labels
, buf_label
,
2276 sizeof(buf_labels
));
2278 } else if (nexthop
->sr
.present
)
2279 label2str(nexthop
->sr
.label
, 0, buf_labels
,
2280 sizeof(buf_labels
));
2282 strlcpy(buf_labels
, "-", sizeof(buf_labels
));
2285 ttable_add_row(tt
, "%s|%u|%s|%s|%s", buf_prefix
,
2286 rinfo
->cost
, buf_iface
, buf_nhop
,
2290 ttable_add_row(tt
, "||%s|%s|%s", buf_iface
,
2291 buf_nhop
, buf_labels
);
2294 if (list_isempty(rinfo
->nexthops
)) {
2296 char buf_sid
[BUFSIZ
] = {};
2297 char buf_lblop
[BUFSIZ
] = {};
2299 if (rinfo
->sr
.present
) {
2300 snprintf(buf_sid
, sizeof(buf_sid
), "%u",
2301 rinfo
->sr
.sid
.value
);
2302 sr_op2str(buf_lblop
, sizeof(buf_lblop
),
2304 MPLS_LABEL_IMPLICIT_NULL
);
2306 strlcpy(buf_sid
, "-", sizeof(buf_sid
));
2307 strlcpy(buf_lblop
, "-", sizeof(buf_lblop
));
2310 ttable_add_row(tt
, "%s|%u|%s|%s|%s|%s", buf_prefix
,
2311 rinfo
->cost
, "-", "-", buf_sid
,
2314 ttable_add_row(tt
, "%s|%u|%s|%s|%s", buf_prefix
,
2315 rinfo
->cost
, "-", "-", "-");
2319 void isis_print_routes(struct vty
*vty
, struct isis_spftree
*spftree
,
2320 bool prefix_sid
, bool backup
)
2322 struct route_table
*route_table
;
2324 struct route_node
*rn
;
2325 bool no_adjacencies
= false;
2326 const char *tree_id_text
= NULL
;
2331 switch (spftree
->tree_id
) {
2333 tree_id_text
= "IPv4";
2336 tree_id_text
= "IPv6";
2338 case SPFTREE_DSTSRC
:
2339 tree_id_text
= "IPv6 (dst-src routing)";
2342 assert(!"isis_print_routes shouldn't be called with SPFTREE_COUNT as type");
2346 vty_out(vty
, "IS-IS %s %s routing table:\n\n",
2347 circuit_t2string(spftree
->level
), tree_id_text
);
2349 /* Prepare table. */
2350 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2352 ttable_add_row(tt
, "Prefix|Metric|Interface|Nexthop|SID|Label Op.");
2354 ttable_add_row(tt
, "Prefix|Metric|Interface|Nexthop|Label(s)");
2355 tt
->style
.cell
.rpad
= 2;
2356 tt
->style
.corner
= '+';
2358 ttable_rowseps(tt
, 0, BOTTOM
, true, '-');
2360 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
2361 no_adjacencies
= true;
2364 (backup
) ? spftree
->route_table_backup
: spftree
->route_table
;
2365 for (rn
= route_top(route_table
); rn
; rn
= route_next(rn
)) {
2366 struct isis_route_info
*rinfo
;
2372 isis_print_route(tt
, &rn
->p
, rinfo
, prefix_sid
, no_adjacencies
);
2375 /* Dump the generated table. */
2376 if (tt
->nrows
> 1) {
2379 table
= ttable_dump(tt
, "\n");
2380 vty_out(vty
, "%s\n", table
);
2381 XFREE(MTYPE_TMP
, table
);
2386 static void show_isis_route_common(struct vty
*vty
, int levels
,
2387 struct isis
*isis
, bool prefix_sid
,
2390 struct listnode
*node
;
2391 struct isis_area
*area
;
2393 if (!isis
->area_list
|| isis
->area_list
->count
== 0)
2396 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
2397 vty_out(vty
, "Area %s:\n",
2398 area
->area_tag
? area
->area_tag
: "null");
2400 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
; level
++) {
2401 if ((level
& levels
) == 0)
2404 if (area
->ip_circuits
> 0) {
2407 area
->spftree
[SPFTREE_IPV4
][level
- 1],
2408 prefix_sid
, backup
);
2410 if (area
->ipv6_circuits
> 0) {
2413 area
->spftree
[SPFTREE_IPV6
][level
- 1],
2414 prefix_sid
, backup
);
2416 if (isis_area_ipv6_dstsrc_enabled(area
)) {
2417 isis_print_routes(vty
,
2418 area
->spftree
[SPFTREE_DSTSRC
]
2420 prefix_sid
, backup
);
2426 DEFUN(show_isis_route
, show_isis_route_cmd
,
2428 " [vrf <NAME|all>] route"
2430 " [<level-1|level-2>]"
2432 " [<prefix-sid|backup>]",
2433 SHOW_STR PROTO_HELP VRF_FULL_CMD_HELP_STR
2434 "IS-IS routing table\n"
2439 "Show Prefix-SID information\n"
2440 "Show backup routes\n")
2444 struct listnode
*node
;
2445 const char *vrf_name
= VRF_DEFAULT_NAME
;
2446 bool all_vrf
= false;
2447 bool prefix_sid
= false;
2448 bool backup
= false;
2451 if (argv_find(argv
, argc
, "level-1", &idx
))
2452 levels
= ISIS_LEVEL1
;
2453 else if (argv_find(argv
, argc
, "level-2", &idx
))
2454 levels
= ISIS_LEVEL2
;
2456 levels
= ISIS_LEVEL1
| ISIS_LEVEL2
;
2459 vty_out(vty
, "IS-IS Routing Process not enabled\n");
2462 ISIS_FIND_VRF_ARGS(argv
, argc
, idx
, vrf_name
, all_vrf
);
2464 if (argv_find(argv
, argc
, "prefix-sid", &idx
))
2466 if (argv_find(argv
, argc
, "backup", &idx
))
2471 for (ALL_LIST_ELEMENTS_RO(im
->isis
, node
, isis
))
2472 show_isis_route_common(vty
, levels
, isis
,
2473 prefix_sid
, backup
);
2476 isis
= isis_lookup_by_vrfname(vrf_name
);
2478 show_isis_route_common(vty
, levels
, isis
, prefix_sid
,
2485 static void isis_print_frr_summary_line(struct ttable
*tt
,
2486 const char *protection
,
2487 uint32_t counters
[SPF_PREFIX_PRIO_MAX
])
2489 uint32_t critical
, high
, medium
, low
, total
;
2491 critical
= counters
[SPF_PREFIX_PRIO_CRITICAL
];
2492 high
= counters
[SPF_PREFIX_PRIO_HIGH
];
2493 medium
= counters
[SPF_PREFIX_PRIO_MEDIUM
];
2494 low
= counters
[SPF_PREFIX_PRIO_LOW
];
2495 total
= critical
+ high
+ medium
+ low
;
2497 ttable_add_row(tt
, "%s|%u|%u|%u|%u|%u", protection
, critical
, high
,
2498 medium
, low
, total
);
2502 isis_print_frr_summary_line_coverage(struct ttable
*tt
, const char *protection
,
2503 double counters
[SPF_PREFIX_PRIO_MAX
],
2506 double critical
, high
, medium
, low
;
2508 critical
= counters
[SPF_PREFIX_PRIO_CRITICAL
] * 100;
2509 high
= counters
[SPF_PREFIX_PRIO_HIGH
] * 100;
2510 medium
= counters
[SPF_PREFIX_PRIO_MEDIUM
] * 100;
2511 low
= counters
[SPF_PREFIX_PRIO_LOW
] * 100;
2514 ttable_add_row(tt
, "%s|%.2f%%|%.2f%%|%.2f%%|%.2f%%|%.2f%%", protection
,
2515 critical
, high
, medium
, low
, total
);
2518 static void isis_print_frr_summary(struct vty
*vty
,
2519 struct isis_spftree
*spftree
)
2523 const char *tree_id_text
= NULL
;
2524 uint32_t protectd
[SPF_PREFIX_PRIO_MAX
] = {0};
2525 uint32_t unprotected
[SPF_PREFIX_PRIO_MAX
] = {0};
2526 double coverage
[SPF_PREFIX_PRIO_MAX
] = {0};
2527 uint32_t protected_total
= 0, grand_total
= 0;
2528 double coverage_total
;
2533 switch (spftree
->tree_id
) {
2535 tree_id_text
= "IPv4";
2538 tree_id_text
= "IPv6";
2540 case SPFTREE_DSTSRC
:
2541 tree_id_text
= "IPv6 (dst-src routing)";
2544 assert(!"isis_print_frr_summary shouldn't be called with SPFTREE_COUNT as type");
2548 vty_out(vty
, " IS-IS %s %s Fast ReRoute summary:\n\n",
2549 circuit_t2string(spftree
->level
), tree_id_text
);
2551 /* Prepare table. */
2552 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2555 "Protection \\ Priority|Critical|High |Medium |Low |Total");
2556 tt
->style
.cell
.rpad
= 2;
2557 tt
->style
.corner
= '+';
2559 ttable_rowseps(tt
, 0, BOTTOM
, true, '-');
2561 /* Compute unprotected and coverage totals. */
2562 for (int priority
= SPF_PREFIX_PRIO_CRITICAL
;
2563 priority
< SPF_PREFIX_PRIO_MAX
; priority
++) {
2564 uint32_t *lfa
= spftree
->lfa
.protection_counters
.lfa
;
2565 uint32_t *rlfa
= spftree
->lfa
.protection_counters
.rlfa
;
2566 uint32_t *tilfa
= spftree
->lfa
.protection_counters
.tilfa
;
2567 uint32_t *ecmp
= spftree
->lfa
.protection_counters
.ecmp
;
2568 uint32_t *total
= spftree
->lfa
.protection_counters
.total
;
2570 protectd
[priority
] = lfa
[priority
] + rlfa
[priority
]
2571 + tilfa
[priority
] + ecmp
[priority
];
2572 /* Safeguard to protect against possible inconsistencies. */
2573 if (protectd
[priority
] > total
[priority
])
2574 protectd
[priority
] = total
[priority
];
2575 unprotected
[priority
] = total
[priority
] - protectd
[priority
];
2576 protected_total
+= protectd
[priority
];
2577 grand_total
+= total
[priority
];
2579 if (!total
[priority
])
2580 coverage
[priority
] = 0;
2582 coverage
[priority
] =
2583 protectd
[priority
] / (double)total
[priority
];
2589 coverage_total
= protected_total
/ (double)grand_total
;
2592 isis_print_frr_summary_line(tt
, "Classic LFA",
2593 spftree
->lfa
.protection_counters
.lfa
);
2594 isis_print_frr_summary_line(tt
, "Remote LFA",
2595 spftree
->lfa
.protection_counters
.rlfa
);
2596 isis_print_frr_summary_line(tt
, "Topology Independent LFA",
2597 spftree
->lfa
.protection_counters
.tilfa
);
2598 isis_print_frr_summary_line(tt
, "ECMP",
2599 spftree
->lfa
.protection_counters
.ecmp
);
2600 isis_print_frr_summary_line(tt
, "Unprotected", unprotected
);
2601 isis_print_frr_summary_line_coverage(tt
, "Protection coverage",
2602 coverage
, coverage_total
);
2604 /* Dump the generated table. */
2605 table
= ttable_dump(tt
, "\n");
2606 vty_out(vty
, "%s\n", table
);
2607 XFREE(MTYPE_TMP
, table
);
2611 static void show_isis_frr_summary_common(struct vty
*vty
, int levels
,
2614 struct listnode
*node
;
2615 struct isis_area
*area
;
2617 if (!isis
->area_list
|| isis
->area_list
->count
== 0)
2620 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
2621 vty_out(vty
, "Area %s:\n",
2622 area
->area_tag
? area
->area_tag
: "null");
2624 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
; level
++) {
2625 if ((level
& levels
) == 0)
2628 if (area
->ip_circuits
> 0) {
2629 isis_print_frr_summary(
2631 area
->spftree
[SPFTREE_IPV4
][level
- 1]);
2633 if (area
->ipv6_circuits
> 0) {
2634 isis_print_frr_summary(
2636 area
->spftree
[SPFTREE_IPV6
][level
- 1]);
2638 if (isis_area_ipv6_dstsrc_enabled(area
)) {
2639 isis_print_frr_summary(
2640 vty
, area
->spftree
[SPFTREE_DSTSRC
]
2647 DEFUN(show_isis_frr_summary
, show_isis_frr_summary_cmd
,
2649 " [vrf <NAME|all>] fast-reroute summary"
2651 " [<level-1|level-2>]"
2654 SHOW_STR PROTO_HELP VRF_FULL_CMD_HELP_STR
2655 "IS-IS FRR information\n"
2665 struct listnode
*node
;
2666 const char *vrf_name
= VRF_DEFAULT_NAME
;
2667 bool all_vrf
= false;
2670 if (argv_find(argv
, argc
, "level-1", &idx
))
2671 levels
= ISIS_LEVEL1
;
2672 else if (argv_find(argv
, argc
, "level-2", &idx
))
2673 levels
= ISIS_LEVEL2
;
2675 levels
= ISIS_LEVEL1
| ISIS_LEVEL2
;
2678 vty_out(vty
, "IS-IS Routing Process not enabled\n");
2681 ISIS_FIND_VRF_ARGS(argv
, argc
, idx
, vrf_name
, all_vrf
);
2685 for (ALL_LIST_ELEMENTS_RO(im
->isis
, node
, isis
))
2686 show_isis_frr_summary_common(vty
, levels
, isis
);
2689 isis
= isis_lookup_by_vrfname(vrf_name
);
2691 show_isis_frr_summary_common(vty
, levels
, isis
);
2697 void isis_spf_init(void)
2699 install_element(VIEW_NODE
, &show_isis_topology_cmd
);
2700 install_element(VIEW_NODE
, &show_isis_route_cmd
);
2701 install_element(VIEW_NODE
, &show_isis_frr_summary_cmd
);
2703 /* Register hook(s). */
2704 hook_register(isis_adj_state_change_hook
, spf_adj_state_change
);
2707 void isis_spf_print(struct isis_spftree
*spftree
, struct vty
*vty
)
2709 uint64_t last_run_duration
= spftree
->last_run_duration
;
2711 vty_out(vty
, " last run elapsed : ");
2712 vty_out_timestr(vty
, spftree
->last_run_timestamp
);
2715 vty_out(vty
, " last run duration : %" PRIu64
" usec\n",
2718 vty_out(vty
, " run count : %u\n", spftree
->runcount
);
2720 void isis_spf_print_json(struct isis_spftree
*spftree
, struct json_object
*json
)
2722 char uptime
[MONOTIME_STRLEN
];
2725 cur
-= spftree
->last_run_timestamp
;
2726 frrtime_to_interval(cur
, uptime
, sizeof(uptime
));
2727 json_object_string_add(json
, "last-run-elapsed", uptime
);
2728 json_object_int_add(json
, "last-run-duration-usec",
2729 spftree
->last_run_duration
);
2730 json_object_int_add(json
, "last-run-count", spftree
->runcount
);