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 if (vertex
->firsthops
) {
245 hash_clean(vertex
->firsthops
, NULL
);
246 hash_free(vertex
->firsthops
);
247 vertex
->firsthops
= NULL
;
250 memset(vertex
, 0, sizeof(struct isis_vertex
));
251 XFREE(MTYPE_ISIS_VERTEX
, vertex
);
254 struct isis_vertex_adj
*
255 isis_vertex_adj_add(struct isis_spftree
*spftree
, struct isis_vertex
*vertex
,
256 struct list
*vadj_list
, struct isis_spf_adj
*sadj
,
257 struct isis_prefix_sid
*psid
, bool last_hop
)
259 struct isis_vertex_adj
*vadj
;
261 vadj
= XCALLOC(MTYPE_ISIS_VERTEX_ADJ
, sizeof(*vadj
));
263 if (spftree
->area
->srdb
.enabled
&& psid
) {
264 if (vertex
->N
.ip
.sr
.present
265 && vertex
->N
.ip
.sr
.sid
.value
!= psid
->value
)
267 "ISIS-SPF: ignoring different Prefix-SID for route %pFX",
268 &vertex
->N
.ip
.p
.dest
);
270 vadj
->sr
.sid
= *psid
;
271 vadj
->sr
.label
= sr_prefix_out_label(
272 spftree
->lspdb
, vertex
->N
.ip
.p
.dest
.family
,
273 psid
, sadj
->id
, last_hop
);
274 if (vadj
->sr
.label
!= MPLS_INVALID_LABEL
)
275 vadj
->sr
.present
= true;
278 listnode_add(vadj_list
, vadj
);
283 static void isis_vertex_adj_del(struct isis_vertex
*vertex
,
284 struct isis_adjacency
*adj
)
286 struct isis_vertex_adj
*vadj
;
287 struct listnode
*node
, *nextnode
;
292 for (ALL_LIST_ELEMENTS(vertex
->Adj_N
, node
, nextnode
, vadj
)) {
293 if (vadj
->sadj
->adj
== adj
) {
294 listnode_delete(vertex
->Adj_N
, vadj
);
295 isis_vertex_adj_free(vadj
);
301 bool isis_vertex_adj_exists(const struct isis_spftree
*spftree
,
302 const struct isis_vertex
*vertex
,
303 const struct isis_spf_adj
*sadj
)
305 struct isis_vertex_adj
*tmp
;
306 struct listnode
*node
;
308 for (ALL_LIST_ELEMENTS_RO(vertex
->Adj_N
, node
, tmp
)) {
309 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
)) {
310 if (memcmp(sadj
->id
, tmp
->sadj
->id
, sizeof(sadj
->id
))
314 if (sadj
->adj
== tmp
->sadj
->adj
)
322 static void isis_spf_adj_free(void *arg
)
324 struct isis_spf_adj
*sadj
= arg
;
326 XFREE(MTYPE_ISIS_SPF_ADJ
, sadj
);
329 struct isis_spftree
*isis_spftree_new(struct isis_area
*area
,
330 struct lspdb_head
*lspdb
,
331 const uint8_t *sysid
, int level
,
332 enum spf_tree_id tree_id
,
333 enum spf_type type
, uint8_t flags
)
335 struct isis_spftree
*tree
;
337 tree
= XCALLOC(MTYPE_ISIS_SPFTREE
, sizeof(struct isis_spftree
));
339 isis_vertex_queue_init(&tree
->tents
, "IS-IS SPF tents", true);
340 isis_vertex_queue_init(&tree
->paths
, "IS-IS SPF paths", false);
341 tree
->route_table
= srcdest_table_init();
342 tree
->route_table
->cleanup
= isis_route_node_cleanup
;
343 tree
->route_table_backup
= srcdest_table_init();
344 tree
->route_table_backup
->cleanup
= isis_route_node_cleanup
;
347 tree
->prefix_sids
= hash_create(prefix_sid_key_make
, prefix_sid_cmp
,
348 "SR Prefix-SID Entries");
349 tree
->sadj_list
= list_new();
350 tree
->sadj_list
->del
= isis_spf_adj_free
;
351 tree
->last_run_timestamp
= 0;
352 tree
->last_run_monotime
= 0;
353 tree
->last_run_duration
= 0;
356 memcpy(tree
->sysid
, sysid
, ISIS_SYS_ID_LEN
);
358 tree
->tree_id
= tree_id
;
359 tree
->family
= (tree
->tree_id
== SPFTREE_IPV4
) ? AF_INET
: AF_INET6
;
361 isis_rlfa_list_init(tree
);
362 tree
->lfa
.remote
.pc_spftrees
= list_new();
363 tree
->lfa
.remote
.pc_spftrees
->del
= (void (*)(void *))isis_spftree_del
;
364 if (tree
->type
== SPF_TYPE_RLFA
|| tree
->type
== SPF_TYPE_TI_LFA
) {
365 isis_spf_node_list_init(&tree
->lfa
.p_space
);
366 isis_spf_node_list_init(&tree
->lfa
.q_space
);
372 void isis_spftree_del(struct isis_spftree
*spftree
)
374 hash_clean(spftree
->prefix_sids
, NULL
);
375 hash_free(spftree
->prefix_sids
);
376 isis_zebra_rlfa_unregister_all(spftree
);
377 isis_rlfa_list_clear(spftree
);
378 list_delete(&spftree
->lfa
.remote
.pc_spftrees
);
379 if (spftree
->type
== SPF_TYPE_RLFA
380 || spftree
->type
== SPF_TYPE_TI_LFA
) {
381 isis_spf_node_list_clear(&spftree
->lfa
.q_space
);
382 isis_spf_node_list_clear(&spftree
->lfa
.p_space
);
384 isis_spf_node_list_clear(&spftree
->adj_nodes
);
385 list_delete(&spftree
->sadj_list
);
386 isis_vertex_queue_free(&spftree
->tents
);
387 isis_vertex_queue_free(&spftree
->paths
);
388 route_table_finish(spftree
->route_table
);
389 route_table_finish(spftree
->route_table_backup
);
390 spftree
->route_table
= NULL
;
392 XFREE(MTYPE_ISIS_SPFTREE
, spftree
);
396 static void isis_spftree_adj_del(struct isis_spftree
*spftree
,
397 struct isis_adjacency
*adj
)
399 struct listnode
*node
;
400 struct isis_vertex
*v
;
403 assert(!isis_vertex_queue_count(&spftree
->tents
));
404 for (ALL_QUEUE_ELEMENTS_RO(&spftree
->paths
, node
, v
))
405 isis_vertex_adj_del(v
, adj
);
409 void spftree_area_init(struct isis_area
*area
)
411 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
412 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
413 if (!(area
->is_type
& level
))
415 if (area
->spftree
[tree
][level
- 1])
418 area
->spftree
[tree
][level
- 1] =
419 isis_spftree_new(area
, &area
->lspdb
[level
- 1],
420 area
->isis
->sysid
, level
, tree
,
421 SPF_TYPE_FORWARD
, 0);
426 void spftree_area_del(struct isis_area
*area
)
428 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
429 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
430 if (!(area
->is_type
& level
))
432 if (!area
->spftree
[tree
][level
- 1])
435 isis_spftree_del(area
->spftree
[tree
][level
- 1]);
440 static int spf_adj_state_change(struct isis_adjacency
*adj
)
442 struct isis_area
*area
= adj
->circuit
->area
;
444 if (adj
->adj_state
== ISIS_ADJ_UP
)
447 /* Remove adjacency from all SPF trees. */
448 for (int tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
449 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
450 if (!(area
->is_type
& level
))
452 if (!area
->spftree
[tree
][level
- 1])
454 isis_spftree_adj_del(area
->spftree
[tree
][level
- 1],
459 if (fabricd_spftree(area
) != NULL
)
460 isis_spftree_adj_del(fabricd_spftree(area
), adj
);
466 * Find the system LSP: returns the LSP in our LSP database
467 * associated with the given system ID.
469 struct isis_lsp
*isis_root_system_lsp(struct lspdb_head
*lspdb
,
470 const uint8_t *sysid
)
472 struct isis_lsp
*lsp
;
473 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
475 memcpy(lspid
, sysid
, ISIS_SYS_ID_LEN
);
476 LSP_PSEUDO_ID(lspid
) = 0;
477 LSP_FRAGMENT(lspid
) = 0;
478 lsp
= lsp_search(lspdb
, lspid
);
479 if (lsp
&& lsp
->hdr
.rem_lifetime
!= 0)
485 * Add this IS to the root of SPT
487 static struct isis_vertex
*isis_spf_add_root(struct isis_spftree
*spftree
)
489 struct isis_vertex
*vertex
;
491 char buff
[VID2STR_BUFFER
];
492 #endif /* EXTREME_DEBUG */
494 vertex
= isis_vertex_new(spftree
, spftree
->sysid
,
495 spftree
->area
->oldmetric
497 : VTYPE_NONPSEUDO_TE_IS
);
498 isis_vertex_queue_append(&spftree
->paths
, vertex
);
501 if (IS_DEBUG_SPF_EVENTS
)
503 "ISIS-SPF: added this IS %s %s depth %d dist %d to PATHS",
504 vtype2string(vertex
->type
),
505 vid2string(vertex
, buff
, sizeof(buff
)), vertex
->depth
,
507 #endif /* EXTREME_DEBUG */
512 static void vertex_add_parent_firsthop(struct hash_bucket
*bucket
, void *arg
)
514 struct isis_vertex
*vertex
= arg
;
515 struct isis_vertex
*hop
= bucket
->data
;
517 (void)hash_get(vertex
->firsthops
, hop
, hash_alloc_intern
);
520 static void vertex_update_firsthops(struct isis_vertex
*vertex
,
521 struct isis_vertex
*parent
)
523 if (vertex
->d_N
<= 2)
524 (void)hash_get(vertex
->firsthops
, vertex
, hash_alloc_intern
);
526 if (vertex
->d_N
< 2 || !parent
)
529 hash_iterate(parent
->firsthops
, vertex_add_parent_firsthop
, vertex
);
533 * Add a vertex to TENT sorted by cost and by vertextype on tie break situation
535 static struct isis_vertex
*
536 isis_spf_add2tent(struct isis_spftree
*spftree
, enum vertextype vtype
, void *id
,
537 uint32_t cost
, int depth
, struct isis_spf_adj
*sadj
,
538 struct isis_prefix_sid
*psid
, struct isis_vertex
*parent
)
540 struct isis_vertex
*vertex
;
541 struct listnode
*node
;
543 char buff
[VID2STR_BUFFER
];
545 vertex
= isis_find_vertex(&spftree
->paths
, id
, vtype
);
546 if (vertex
!= NULL
) {
548 "%s: vertex %s of type %s already in PATH; check for sysId collisions with established neighbors",
549 __func__
, vid2string(vertex
, buff
, sizeof(buff
)),
550 vtype2string(vertex
->type
));
553 vertex
= isis_find_vertex(&spftree
->tents
, id
, vtype
);
554 if (vertex
!= NULL
) {
556 "%s: vertex %s of type %s already in TENT; check for sysId collisions with established neighbors",
557 __func__
, vid2string(vertex
, buff
, sizeof(buff
)),
558 vtype2string(vertex
->type
));
562 vertex
= isis_vertex_new(spftree
, id
, vtype
);
564 vertex
->depth
= depth
;
565 if (VTYPE_IP(vtype
) && spftree
->area
->srdb
.enabled
&& psid
) {
566 struct isis_area
*area
= spftree
->area
;
567 struct isis_vertex
*vertex_psid
;
570 * Check if the Prefix-SID is already in use by another prefix.
572 vertex_psid
= isis_spf_prefix_sid_lookup(spftree
, psid
);
574 && !prefix_same(&vertex_psid
->N
.ip
.p
.dest
,
575 &vertex
->N
.ip
.p
.dest
)) {
577 EC_ISIS_SID_COLLISION
,
578 "ISIS-Sr (%s): collision detected, prefixes %pFX and %pFX share the same SID %s (%u)",
579 area
->area_tag
, &vertex
->N
.ip
.p
.dest
,
580 &vertex_psid
->N
.ip
.p
.dest
,
581 CHECK_FLAG(psid
->flags
, ISIS_PREFIX_SID_VALUE
)
589 local
= (vertex
->depth
== 1);
590 vertex
->N
.ip
.sr
.sid
= *psid
;
591 vertex
->N
.ip
.sr
.label
=
592 sr_prefix_in_label(area
, psid
, local
);
593 if (vertex
->N
.ip
.sr
.label
!= MPLS_INVALID_LABEL
)
594 vertex
->N
.ip
.sr
.present
= true;
596 (void)hash_get(spftree
->prefix_sids
, vertex
,
602 listnode_add(vertex
->parents
, parent
);
605 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
))
606 vertex_update_firsthops(vertex
, parent
);
608 last_hop
= (vertex
->depth
== 2);
609 if (parent
&& parent
->Adj_N
&& listcount(parent
->Adj_N
) > 0) {
610 struct isis_vertex_adj
*parent_vadj
;
612 for (ALL_LIST_ELEMENTS_RO(parent
->Adj_N
, node
, parent_vadj
))
613 isis_vertex_adj_add(spftree
, vertex
, vertex
->Adj_N
,
614 parent_vadj
->sadj
, psid
, last_hop
);
616 isis_vertex_adj_add(spftree
, vertex
, vertex
->Adj_N
, sadj
, psid
,
621 if (IS_DEBUG_SPF_EVENTS
)
623 "ISIS-SPF: add to TENT %s %s %s depth %d dist %d adjcount %d",
624 print_sys_hostname(vertex
->N
.id
),
625 vtype2string(vertex
->type
),
626 vid2string(vertex
, buff
, sizeof(buff
)), vertex
->depth
,
627 vertex
->d_N
, listcount(vertex
->Adj_N
));
628 #endif /* EXTREME_DEBUG */
630 isis_vertex_queue_insert(&spftree
->tents
, vertex
);
634 static void isis_spf_add_local(struct isis_spftree
*spftree
,
635 enum vertextype vtype
, void *id
,
636 struct isis_spf_adj
*sadj
, uint32_t cost
,
637 struct isis_prefix_sid
*psid
,
638 struct isis_vertex
*parent
)
640 struct isis_vertex
*vertex
;
642 vertex
= isis_find_vertex(&spftree
->tents
, id
, vtype
);
646 if (vertex
->d_N
== cost
) {
648 bool last_hop
= (vertex
->depth
== 2);
650 isis_vertex_adj_add(spftree
, vertex
,
651 vertex
->Adj_N
, sadj
, psid
,
655 if (!CHECK_FLAG(spftree
->flags
,
656 F_SPFTREE_NO_ADJACENCIES
)
657 && listcount(vertex
->Adj_N
) > ISIS_MAX_PATH_SPLITS
)
658 remove_excess_adjs(vertex
->Adj_N
);
659 if (parent
&& (listnode_lookup(vertex
->parents
, parent
)
661 listnode_add(vertex
->parents
, parent
);
663 } else if (vertex
->d_N
< cost
) {
666 } else { /* vertex->d_N > cost */
668 isis_vertex_queue_delete(&spftree
->tents
, vertex
);
669 isis_vertex_del(vertex
);
673 isis_spf_add2tent(spftree
, vtype
, id
, cost
, 1, sadj
, psid
, parent
);
677 static void process_N(struct isis_spftree
*spftree
, enum vertextype vtype
,
678 void *id
, uint32_t dist
, uint16_t depth
,
679 struct isis_prefix_sid
*psid
, struct isis_vertex
*parent
)
681 struct isis_vertex
*vertex
;
683 char buff
[VID2STR_BUFFER
];
686 assert(spftree
&& parent
);
688 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)
692 struct prefix_pair p
;
693 if (vtype
>= VTYPE_IPREACH_INTERNAL
) {
694 memcpy(&p
, id
, sizeof(p
));
700 /* RFC3787 section 5.1 */
701 if (spftree
->area
->newmetric
== 1) {
702 if (dist
> MAX_WIDE_PATH_METRIC
)
706 else if (spftree
->area
->oldmetric
== 1) {
707 if (dist
> MAX_NARROW_PATH_METRIC
)
712 vertex
= isis_find_vertex(&spftree
->paths
, id
, vtype
);
715 if (IS_DEBUG_SPF_EVENTS
)
717 "ISIS-SPF: process_N %s %s %s dist %d already found from PATH",
718 print_sys_hostname(vertex
->N
.id
),
720 vid2string(vertex
, buff
, sizeof(buff
)), dist
);
721 #endif /* EXTREME_DEBUG */
722 assert(dist
>= vertex
->d_N
);
726 vertex
= isis_find_vertex(&spftree
->tents
, id
, vtype
);
731 if (IS_DEBUG_SPF_EVENTS
)
733 "ISIS-SPF: process_N %s %s %s dist %d parent %s adjcount %d",
734 print_sys_hostname(vertex
->N
.id
),
736 vid2string(vertex
, buff
, sizeof(buff
)), dist
,
737 (parent
? print_sys_hostname(parent
->N
.id
)
739 (parent
? listcount(parent
->Adj_N
) : 0));
740 #endif /* EXTREME_DEBUG */
741 if (vertex
->d_N
== dist
) {
742 struct listnode
*node
;
743 struct isis_vertex_adj
*parent_vadj
;
744 for (ALL_LIST_ELEMENTS_RO(parent
->Adj_N
, node
,
746 if (!isis_vertex_adj_exists(
748 parent_vadj
->sadj
)) {
749 bool last_hop
= (vertex
->depth
== 2);
751 isis_vertex_adj_add(spftree
, vertex
,
756 if (CHECK_FLAG(spftree
->flags
,
757 F_SPFTREE_HOPCOUNT_METRIC
))
758 vertex_update_firsthops(vertex
, parent
);
760 if (!CHECK_FLAG(spftree
->flags
,
761 F_SPFTREE_NO_ADJACENCIES
)
762 && listcount(vertex
->Adj_N
) > ISIS_MAX_PATH_SPLITS
)
763 remove_excess_adjs(vertex
->Adj_N
);
764 if (listnode_lookup(vertex
->parents
, parent
) == NULL
)
765 listnode_add(vertex
->parents
, parent
);
767 } else if (vertex
->d_N
< dist
) {
771 isis_vertex_queue_delete(&spftree
->tents
, vertex
);
772 isis_vertex_del(vertex
);
777 if (IS_DEBUG_SPF_EVENTS
)
779 "ISIS-SPF: process_N add2tent %s %s dist %d parent %s",
780 print_sys_hostname(id
), vtype2string(vtype
), dist
,
781 (parent
? print_sys_hostname(parent
->N
.id
) : "null"));
782 #endif /* EXTREME_DEBUG */
784 isis_spf_add2tent(spftree
, vtype
, id
, dist
, depth
, NULL
, psid
, parent
);
791 static int isis_spf_process_lsp(struct isis_spftree
*spftree
,
792 struct isis_lsp
*lsp
, uint32_t cost
,
793 uint16_t depth
, uint8_t *root_sysid
,
794 struct isis_vertex
*parent
)
796 bool pseudo_lsp
= LSP_PSEUDO_ID(lsp
->hdr
.lsp_id
);
797 struct listnode
*fragnode
= NULL
;
799 enum vertextype vtype
;
800 static const uint8_t null_sysid
[ISIS_SYS_ID_LEN
];
801 struct isis_mt_router_info
*mt_router_info
= NULL
;
802 struct prefix_pair ip_info
;
805 if (isis_lfa_excise_node_check(spftree
, lsp
->hdr
.lsp_id
)) {
807 zlog_debug("ISIS-LFA: excising node %s",
808 print_sys_hostname(lsp
->hdr
.lsp_id
));
815 if (spftree
->mtid
!= ISIS_MT_IPV4_UNICAST
)
816 mt_router_info
= isis_tlvs_lookup_mt_router_info(lsp
->tlvs
,
819 if (!pseudo_lsp
&& (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
820 && !speaks(lsp
->tlvs
->protocols_supported
.protocols
,
821 lsp
->tlvs
->protocols_supported
.count
,
826 /* RFC3787 section 4 SHOULD ignore overload bit in pseudo LSPs */
827 bool no_overload
= (pseudo_lsp
828 || (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
829 && !ISIS_MASK_LSP_OL_BIT(lsp
->hdr
.lsp_bits
))
830 || (mt_router_info
&& !mt_router_info
->overload
));
833 if (lsp
->hdr
.seqno
== 0) {
834 zlog_warn("%s: lsp with 0 seq_num - ignore", __func__
);
839 if (IS_DEBUG_SPF_EVENTS
)
840 zlog_debug("ISIS-SPF: process_lsp %s",
841 print_sys_hostname(lsp
->hdr
.lsp_id
));
842 #endif /* EXTREME_DEBUG */
845 if ((pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
846 && spftree
->area
->oldmetric
) {
847 struct isis_oldstyle_reach
*r
;
848 for (r
= (struct isis_oldstyle_reach
*)
849 lsp
->tlvs
->oldstyle_reach
.head
;
855 /* Two way connectivity */
856 if (!LSP_PSEUDO_ID(r
->id
)
857 && !memcmp(r
->id
, root_sysid
,
861 && !memcmp(r
->id
, null_sysid
,
864 dist
= cost
+ r
->metric
;
868 : VTYPE_NONPSEUDO_IS
,
869 (void *)r
->id
, dist
, depth
+ 1, NULL
,
874 if (spftree
->area
->newmetric
) {
875 struct isis_item_list
*te_neighs
= NULL
;
876 if (pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
877 te_neighs
= &lsp
->tlvs
->extended_reach
;
879 te_neighs
= isis_lookup_mt_items(
880 &lsp
->tlvs
->mt_reach
, spftree
->mtid
);
882 struct isis_extended_reach
*er
;
883 for (er
= te_neighs
? (struct isis_extended_reach
*)
888 /* Two way connectivity */
889 if (!LSP_PSEUDO_ID(er
->id
)
890 && !memcmp(er
->id
, root_sysid
,
894 && !memcmp(er
->id
, null_sysid
,
898 + (CHECK_FLAG(spftree
->flags
,
899 F_SPFTREE_HOPCOUNT_METRIC
)
903 LSP_PSEUDO_ID(er
->id
)
905 : VTYPE_NONPSEUDO_TE_IS
,
906 (void *)er
->id
, dist
, depth
+ 1, NULL
,
912 if (!fabricd
&& !pseudo_lsp
&& spftree
->family
== AF_INET
913 && spftree
->mtid
== ISIS_MT_IPV4_UNICAST
914 && spftree
->area
->oldmetric
) {
915 struct isis_item_list
*reachs
[] = {
916 &lsp
->tlvs
->oldstyle_ip_reach
,
917 &lsp
->tlvs
->oldstyle_ip_reach_ext
};
919 for (unsigned int i
= 0; i
< array_size(reachs
); i
++) {
920 vtype
= i
? VTYPE_IPREACH_EXTERNAL
921 : VTYPE_IPREACH_INTERNAL
;
923 memset(&ip_info
, 0, sizeof(ip_info
));
924 ip_info
.dest
.family
= AF_INET
;
926 struct isis_oldstyle_ip_reach
*r
;
927 for (r
= (struct isis_oldstyle_ip_reach
*)reachs
[i
]
930 dist
= cost
+ r
->metric
;
931 ip_info
.dest
.u
.prefix4
= r
->prefix
.prefix
;
932 ip_info
.dest
.prefixlen
= r
->prefix
.prefixlen
;
933 process_N(spftree
, vtype
, &ip_info
,
934 dist
, depth
+ 1, NULL
, parent
);
939 /* we can skip all the rest if we're using metric style narrow */
940 if (!spftree
->area
->newmetric
)
943 if (!pseudo_lsp
&& spftree
->family
== AF_INET
) {
944 struct isis_item_list
*ipv4_reachs
;
945 if (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
946 ipv4_reachs
= &lsp
->tlvs
->extended_ip_reach
;
948 ipv4_reachs
= isis_lookup_mt_items(
949 &lsp
->tlvs
->mt_ip_reach
, spftree
->mtid
);
951 memset(&ip_info
, 0, sizeof(ip_info
));
952 ip_info
.dest
.family
= AF_INET
;
954 struct isis_extended_ip_reach
*r
;
956 ? (struct isis_extended_ip_reach
*)
960 dist
= cost
+ r
->metric
;
961 ip_info
.dest
.u
.prefix4
= r
->prefix
.prefix
;
962 ip_info
.dest
.prefixlen
= r
->prefix
.prefixlen
;
964 /* Parse list of Prefix-SID subTLVs if SR is enabled */
965 has_valid_psid
= false;
966 if (spftree
->area
->srdb
.enabled
&& r
->subtlvs
) {
967 for (struct isis_item
*i
=
968 r
->subtlvs
->prefix_sids
.head
;
970 struct isis_prefix_sid
*psid
=
971 (struct isis_prefix_sid
*)i
;
973 if (psid
->algorithm
!= SR_ALGORITHM_SPF
)
976 has_valid_psid
= true;
977 process_N(spftree
, VTYPE_IPREACH_TE
,
978 &ip_info
, dist
, depth
+ 1,
981 * Stop the Prefix-SID iteration since
982 * we only support the SPF algorithm for
989 process_N(spftree
, VTYPE_IPREACH_TE
, &ip_info
,
990 dist
, depth
+ 1, NULL
, parent
);
994 if (!pseudo_lsp
&& spftree
->family
== AF_INET6
) {
995 struct isis_item_list
*ipv6_reachs
;
996 if (spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
997 ipv6_reachs
= &lsp
->tlvs
->ipv6_reach
;
999 ipv6_reachs
= isis_lookup_mt_items(
1000 &lsp
->tlvs
->mt_ipv6_reach
, spftree
->mtid
);
1002 struct isis_ipv6_reach
*r
;
1003 for (r
= ipv6_reachs
1004 ? (struct isis_ipv6_reach
*)ipv6_reachs
->head
1007 dist
= cost
+ r
->metric
;
1008 vtype
= r
->external
? VTYPE_IP6REACH_EXTERNAL
1009 : VTYPE_IP6REACH_INTERNAL
;
1010 memset(&ip_info
, 0, sizeof(ip_info
));
1011 ip_info
.dest
.family
= AF_INET6
;
1012 ip_info
.dest
.u
.prefix6
= r
->prefix
.prefix
;
1013 ip_info
.dest
.prefixlen
= r
->prefix
.prefixlen
;
1015 if (spftree
->area
->srdb
.enabled
&& r
->subtlvs
&&
1016 r
->subtlvs
->source_prefix
&&
1017 r
->subtlvs
->source_prefix
->prefixlen
) {
1018 if (spftree
->tree_id
!= SPFTREE_DSTSRC
) {
1019 char buff
[VID2STR_BUFFER
];
1020 zlog_warn("Ignoring dest-src route %s in non dest-src topology",
1023 r
->subtlvs
->source_prefix
,
1029 ip_info
.src
= *r
->subtlvs
->source_prefix
;
1032 /* Parse list of Prefix-SID subTLVs */
1033 has_valid_psid
= false;
1035 for (struct isis_item
*i
=
1036 r
->subtlvs
->prefix_sids
.head
;
1038 struct isis_prefix_sid
*psid
=
1039 (struct isis_prefix_sid
*)i
;
1041 if (psid
->algorithm
!= SR_ALGORITHM_SPF
)
1044 has_valid_psid
= true;
1045 process_N(spftree
, vtype
, &ip_info
,
1046 dist
, depth
+ 1, psid
,
1049 * Stop the Prefix-SID iteration since
1050 * we only support the SPF algorithm for
1056 if (!has_valid_psid
)
1057 process_N(spftree
, vtype
, &ip_info
, dist
,
1058 depth
+ 1, NULL
, parent
);
1064 /* if attach bit set in LSP, attached-bit receive ignore is
1065 * not configured, we are a level-1 area and we have no other
1066 * level-2 | level1-2 areas then add a default route toward
1069 if ((lsp
->hdr
.lsp_bits
& LSPBIT_ATT
) == LSPBIT_ATT
1070 && !spftree
->area
->attached_bit_rcv_ignore
1071 && (spftree
->area
->is_type
& IS_LEVEL_1
)
1072 && !isis_level2_adj_up(spftree
->area
)) {
1073 struct prefix_pair ip_info
= { {0} };
1074 if (IS_DEBUG_RTE_EVENTS
)
1075 zlog_debug("ISIS-Spf (%s): add default %s route",
1076 rawlspid_print(lsp
->hdr
.lsp_id
),
1077 spftree
->family
== AF_INET
? "ipv4"
1080 if (spftree
->family
== AF_INET
) {
1081 ip_info
.dest
.family
= AF_INET
;
1082 vtype
= VTYPE_IPREACH_INTERNAL
;
1084 ip_info
.dest
.family
= AF_INET6
;
1085 vtype
= VTYPE_IP6REACH_INTERNAL
;
1087 process_N(spftree
, vtype
, &ip_info
, cost
, depth
+ 1, NULL
,
1091 if (fragnode
== NULL
)
1092 fragnode
= listhead(lsp
->lspu
.frags
);
1094 fragnode
= listnextnode(fragnode
);
1097 lsp
= listgetdata(fragnode
);
1104 static struct isis_adjacency
*adj_find(struct list
*adj_list
, const uint8_t *id
,
1105 int level
, uint16_t mtid
, int family
)
1107 struct isis_adjacency
*adj
;
1108 struct listnode
*node
;
1110 for (ALL_LIST_ELEMENTS_RO(adj_list
, node
, adj
)) {
1111 if (!(adj
->level
& level
))
1113 if (memcmp(adj
->sysid
, id
, ISIS_SYS_ID_LEN
) != 0)
1115 if (adj
->adj_state
!= ISIS_ADJ_UP
)
1117 if (!adj_has_mt(adj
, mtid
))
1119 if (mtid
== ISIS_MT_IPV4_UNICAST
1120 && !speaks(adj
->nlpids
.nlpids
, adj
->nlpids
.count
, family
))
1128 struct spf_preload_tent_ip_reach_args
{
1129 struct isis_spftree
*spftree
;
1130 struct isis_vertex
*parent
;
1133 static int isis_spf_preload_tent_ip_reach_cb(const struct prefix
*prefix
,
1134 uint32_t metric
, bool external
,
1135 struct isis_subtlvs
*subtlvs
,
1138 struct spf_preload_tent_ip_reach_args
*args
= arg
;
1139 struct isis_spftree
*spftree
= args
->spftree
;
1140 struct isis_vertex
*parent
= args
->parent
;
1141 struct prefix_pair ip_info
;
1142 enum vertextype vtype
;
1143 bool has_valid_psid
= false;
1146 return LSP_ITER_CONTINUE
;
1148 assert(spftree
->family
== prefix
->family
);
1149 memset(&ip_info
, 0, sizeof(ip_info
));
1150 prefix_copy(&ip_info
.dest
, prefix
);
1151 apply_mask(&ip_info
.dest
);
1153 if (prefix
->family
== AF_INET
)
1154 vtype
= VTYPE_IPREACH_INTERNAL
;
1156 vtype
= VTYPE_IP6REACH_INTERNAL
;
1158 /* Parse list of Prefix-SID subTLVs if SR is enabled */
1159 if (spftree
->area
->srdb
.enabled
&& subtlvs
) {
1160 for (struct isis_item
*i
= subtlvs
->prefix_sids
.head
; i
;
1162 struct isis_prefix_sid
*psid
=
1163 (struct isis_prefix_sid
*)i
;
1165 if (psid
->algorithm
!= SR_ALGORITHM_SPF
)
1168 has_valid_psid
= true;
1169 isis_spf_add_local(spftree
, vtype
, &ip_info
, NULL
, 0,
1173 * Stop the Prefix-SID iteration since we only support
1174 * the SPF algorithm for now.
1179 if (!has_valid_psid
)
1180 isis_spf_add_local(spftree
, vtype
, &ip_info
, NULL
, 0, NULL
,
1183 return LSP_ITER_CONTINUE
;
1186 static void isis_spf_preload_tent(struct isis_spftree
*spftree
,
1187 uint8_t *root_sysid
,
1188 struct isis_lsp
*root_lsp
,
1189 struct isis_vertex
*parent
)
1191 struct spf_preload_tent_ip_reach_args ip_reach_args
;
1192 struct isis_spf_adj
*sadj
;
1193 struct listnode
*node
;
1195 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)) {
1196 ip_reach_args
.spftree
= spftree
;
1197 ip_reach_args
.parent
= parent
;
1198 isis_lsp_iterate_ip_reach(
1199 root_lsp
, spftree
->family
, spftree
->mtid
,
1200 isis_spf_preload_tent_ip_reach_cb
, &ip_reach_args
);
1203 /* Iterate over adjacencies. */
1204 for (ALL_LIST_ELEMENTS_RO(spftree
->sadj_list
, node
, sadj
)) {
1205 const uint8_t *adj_id
;
1208 if (CHECK_FLAG(sadj
->flags
, F_ISIS_SPF_ADJ_BROADCAST
))
1209 adj_id
= sadj
->lan
.desig_is_id
;
1213 if (isis_lfa_excise_adj_check(spftree
, adj_id
)) {
1215 zlog_debug("ISIS-SPF: excising adjacency %s",
1216 isis_format_id(sadj
->id
,
1217 ISIS_SYS_ID_LEN
+ 1));
1221 metric
= CHECK_FLAG(spftree
->flags
, F_SPFTREE_HOPCOUNT_METRIC
)
1224 if (!LSP_PSEUDO_ID(sadj
->id
)) {
1225 isis_spf_add_local(spftree
,
1226 CHECK_FLAG(sadj
->flags
,
1227 F_ISIS_SPF_ADJ_OLDMETRIC
)
1228 ? VTYPE_NONPSEUDO_IS
1229 : VTYPE_NONPSEUDO_TE_IS
,
1230 sadj
->id
, sadj
, metric
, NULL
,
1232 } else if (sadj
->lsp
) {
1233 isis_spf_process_lsp(spftree
, sadj
->lsp
, metric
, 0,
1234 spftree
->sysid
, parent
);
1239 struct spf_adj_find_reverse_metric_args
{
1240 const uint8_t *id_self
;
1241 uint32_t reverse_metric
;
1244 static int spf_adj_find_reverse_metric_cb(const uint8_t *id
, uint32_t metric
,
1246 struct isis_ext_subtlvs
*subtlvs
,
1249 struct spf_adj_find_reverse_metric_args
*args
= arg
;
1251 if (memcmp(id
, args
->id_self
, ISIS_SYS_ID_LEN
))
1252 return LSP_ITER_CONTINUE
;
1254 args
->reverse_metric
= metric
;
1256 return LSP_ITER_STOP
;
1260 * Change all SPF adjacencies to use the link cost in the direction from the
1261 * next hop back towards root in place of the link cost in the direction away
1262 * from root towards the next hop.
1264 static void spf_adj_get_reverse_metrics(struct isis_spftree
*spftree
)
1266 struct isis_spf_adj
*sadj
;
1267 struct listnode
*node
, *nnode
;
1269 for (ALL_LIST_ELEMENTS(spftree
->sadj_list
, node
, nnode
, sadj
)) {
1270 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1271 struct isis_lsp
*lsp_adj
;
1272 const uint8_t *id_self
;
1273 struct spf_adj_find_reverse_metric_args args
;
1275 /* Skip pseudonodes. */
1276 if (LSP_PSEUDO_ID(sadj
->id
))
1279 /* Find LSP of the corresponding adjacency. */
1280 memcpy(lspid
, sadj
->id
, ISIS_SYS_ID_LEN
);
1281 LSP_PSEUDO_ID(lspid
) = 0;
1282 LSP_FRAGMENT(lspid
) = 0;
1283 lsp_adj
= lsp_search(spftree
->lspdb
, lspid
);
1284 if (lsp_adj
== NULL
|| lsp_adj
->hdr
.rem_lifetime
== 0) {
1285 /* Delete one-way adjacency. */
1286 listnode_delete(spftree
->sadj_list
, sadj
);
1287 isis_spf_adj_free(sadj
);
1291 /* Find root node in the LSP of the adjacent router. */
1292 if (CHECK_FLAG(sadj
->flags
, F_ISIS_SPF_ADJ_BROADCAST
))
1293 id_self
= sadj
->lan
.desig_is_id
;
1295 id_self
= spftree
->sysid
;
1296 args
.id_self
= id_self
;
1297 args
.reverse_metric
= UINT32_MAX
;
1298 isis_lsp_iterate_is_reach(lsp_adj
, spftree
->mtid
,
1299 spf_adj_find_reverse_metric_cb
,
1301 if (args
.reverse_metric
== UINT32_MAX
) {
1302 /* Delete one-way adjacency. */
1303 listnode_delete(spftree
->sadj_list
, sadj
);
1304 isis_spf_adj_free(sadj
);
1307 sadj
->metric
= args
.reverse_metric
;
1311 static void spf_adj_list_parse_tlv(struct isis_spftree
*spftree
,
1312 struct list
*adj_list
, const uint8_t *id
,
1313 const uint8_t *desig_is_id
,
1314 uint32_t pseudo_metric
, uint32_t metric
,
1316 struct isis_ext_subtlvs
*subtlvs
)
1318 struct isis_spf_adj
*sadj
;
1319 uint8_t lspid
[ISIS_SYS_ID_LEN
+ 2];
1320 struct isis_lsp
*lsp
;
1323 /* Skip self in the pseudonode. */
1324 if (desig_is_id
&& !memcmp(id
, spftree
->sysid
, ISIS_SYS_ID_LEN
))
1327 /* Find LSP from the adjacency. */
1328 memcpy(lspid
, id
, ISIS_SYS_ID_LEN
+ 1);
1329 LSP_FRAGMENT(lspid
) = 0;
1330 lsp
= lsp_search(spftree
->lspdb
, lspid
);
1331 if (lsp
== NULL
|| lsp
->hdr
.rem_lifetime
== 0) {
1332 zlog_warn("ISIS-SPF: No LSP found from root to L%d %s",
1333 spftree
->level
, rawlspid_print(lspid
));
1337 sadj
= XCALLOC(MTYPE_ISIS_SPF_ADJ
, sizeof(*sadj
));
1338 memcpy(sadj
->id
, id
, sizeof(sadj
->id
));
1340 memcpy(sadj
->lan
.desig_is_id
, desig_is_id
,
1341 sizeof(sadj
->lan
.desig_is_id
));
1342 SET_FLAG(flags
, F_ISIS_SPF_ADJ_BROADCAST
);
1343 sadj
->metric
= pseudo_metric
;
1345 sadj
->metric
= metric
;
1347 SET_FLAG(flags
, F_ISIS_SPF_ADJ_OLDMETRIC
);
1349 sadj
->subtlvs
= subtlvs
;
1350 sadj
->flags
= flags
;
1352 if ((oldmetric
&& metric
== ISIS_NARROW_METRIC_INFINITY
)
1353 || (!oldmetric
&& metric
== ISIS_WIDE_METRIC_INFINITY
))
1354 SET_FLAG(flags
, F_ISIS_SPF_ADJ_METRIC_INFINITY
);
1356 /* Set real adjacency. */
1357 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
)
1358 && !LSP_PSEUDO_ID(id
)) {
1359 struct isis_adjacency
*adj
;
1361 adj
= adj_find(adj_list
, id
, spftree
->level
, spftree
->mtid
,
1364 XFREE(MTYPE_ISIS_SPF_ADJ
, sadj
);
1368 listnode_delete(adj_list
, adj
);
1372 /* Add adjacency to the list. */
1373 listnode_add(spftree
->sadj_list
, sadj
);
1375 if (!LSP_PSEUDO_ID(id
)) {
1376 struct isis_spf_node
*node
;
1378 node
= isis_spf_node_find(&spftree
->adj_nodes
, id
);
1380 node
= isis_spf_node_new(&spftree
->adj_nodes
, id
);
1381 if (node
->best_metric
== 0 || sadj
->metric
< node
->best_metric
)
1382 node
->best_metric
= sadj
->metric
;
1383 listnode_add(node
->adjacencies
, sadj
);
1386 /* Parse pseudonode LSP too. */
1387 if (LSP_PSEUDO_ID(id
))
1388 spf_adj_list_parse_lsp(spftree
, adj_list
, lsp
, id
, metric
);
1391 static void spf_adj_list_parse_lsp(struct isis_spftree
*spftree
,
1392 struct list
*adj_list
, struct isis_lsp
*lsp
,
1393 const uint8_t *pseudo_nodeid
,
1394 uint32_t pseudo_metric
)
1396 bool pseudo_lsp
= LSP_PSEUDO_ID(lsp
->hdr
.lsp_id
);
1397 struct isis_lsp
*frag
;
1398 struct listnode
*node
;
1399 struct isis_item
*head
;
1400 struct isis_item_list
*te_neighs
;
1402 if (lsp
->hdr
.seqno
== 0 || lsp
->hdr
.rem_lifetime
== 0)
1407 if (pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
) {
1408 head
= lsp
->tlvs
->oldstyle_reach
.head
;
1409 for (struct isis_oldstyle_reach
*reach
=
1410 (struct isis_oldstyle_reach
*)head
;
1411 reach
; reach
= reach
->next
) {
1412 spf_adj_list_parse_tlv(
1413 spftree
, adj_list
, reach
->id
,
1414 pseudo_nodeid
, pseudo_metric
,
1415 reach
->metric
, true, NULL
);
1419 if (pseudo_lsp
|| spftree
->mtid
== ISIS_MT_IPV4_UNICAST
)
1420 te_neighs
= &lsp
->tlvs
->extended_reach
;
1422 te_neighs
= isis_get_mt_items(&lsp
->tlvs
->mt_reach
,
1425 head
= te_neighs
->head
;
1426 for (struct isis_extended_reach
*reach
=
1427 (struct isis_extended_reach
*)head
;
1428 reach
; reach
= reach
->next
) {
1429 spf_adj_list_parse_tlv(
1430 spftree
, adj_list
, reach
->id
,
1431 pseudo_nodeid
, pseudo_metric
,
1432 reach
->metric
, false, reach
->subtlvs
);
1437 if (LSP_FRAGMENT(lsp
->hdr
.lsp_id
))
1440 /* Parse LSP fragments. */
1441 for (ALL_LIST_ELEMENTS_RO(lsp
->lspu
.frags
, node
, frag
)) {
1445 spf_adj_list_parse_lsp(spftree
, adj_list
, frag
, pseudo_nodeid
,
1450 static void isis_spf_build_adj_list(struct isis_spftree
*spftree
,
1451 struct isis_lsp
*lsp
)
1453 struct list
*adj_list
= NULL
;
1455 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
1456 adj_list
= list_dup(spftree
->area
->adjacency_list
);
1458 spf_adj_list_parse_lsp(spftree
, adj_list
, lsp
, NULL
, 0);
1460 if (!CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
1461 list_delete(&adj_list
);
1463 if (spftree
->type
== SPF_TYPE_REVERSE
)
1464 spf_adj_get_reverse_metrics(spftree
);
1468 * The parent(s) for vertex is set when added to TENT list
1469 * now we just put the child pointer(s) in place
1471 static void add_to_paths(struct isis_spftree
*spftree
,
1472 struct isis_vertex
*vertex
)
1474 #ifdef EXTREME_DEBUG
1475 char buff
[VID2STR_BUFFER
];
1476 #endif /* EXTREME_DEBUG */
1478 if (isis_find_vertex(&spftree
->paths
, &vertex
->N
, vertex
->type
))
1480 isis_vertex_queue_append(&spftree
->paths
, vertex
);
1482 #ifdef EXTREME_DEBUG
1483 if (IS_DEBUG_SPF_EVENTS
)
1484 zlog_debug("ISIS-SPF: added %s %s %s depth %d dist %d to PATHS",
1485 print_sys_hostname(vertex
->N
.id
),
1486 vtype2string(vertex
->type
),
1487 vid2string(vertex
, buff
, sizeof(buff
)),
1488 vertex
->depth
, vertex
->d_N
);
1489 #endif /* EXTREME_DEBUG */
1492 static void init_spt(struct isis_spftree
*spftree
, int mtid
)
1494 /* Clear data from previous run. */
1495 hash_clean(spftree
->prefix_sids
, NULL
);
1496 isis_spf_node_list_clear(&spftree
->adj_nodes
);
1497 list_delete_all_node(spftree
->sadj_list
);
1498 isis_vertex_queue_clear(&spftree
->tents
);
1499 isis_vertex_queue_clear(&spftree
->paths
);
1500 isis_zebra_rlfa_unregister_all(spftree
);
1501 isis_rlfa_list_clear(spftree
);
1502 list_delete_all_node(spftree
->lfa
.remote
.pc_spftrees
);
1503 memset(&spftree
->lfa
.protection_counters
, 0,
1504 sizeof(spftree
->lfa
.protection_counters
));
1506 spftree
->mtid
= mtid
;
1509 static enum spf_prefix_priority
1510 spf_prefix_priority(struct isis_spftree
*spftree
, struct isis_vertex
*vertex
)
1512 struct isis_area
*area
= spftree
->area
;
1513 struct prefix
*prefix
= &vertex
->N
.ip
.p
.dest
;
1515 for (int priority
= SPF_PREFIX_PRIO_CRITICAL
;
1516 priority
<= SPF_PREFIX_PRIO_MEDIUM
; priority
++) {
1517 struct spf_prefix_priority_acl
*ppa
;
1518 enum filter_type ret
= FILTER_PERMIT
;
1520 ppa
= &area
->spf_prefix_priorities
[priority
];
1521 switch (spftree
->family
) {
1523 ret
= access_list_apply(ppa
->list_v4
, prefix
);
1526 ret
= access_list_apply(ppa
->list_v6
, prefix
);
1532 if (ret
== FILTER_PERMIT
)
1536 /* Assign medium priority to loopback prefixes by default. */
1537 if (is_host_route(prefix
))
1538 return SPF_PREFIX_PRIO_MEDIUM
;
1540 return SPF_PREFIX_PRIO_LOW
;
1543 static void spf_path_process(struct isis_spftree
*spftree
,
1544 struct isis_vertex
*vertex
)
1546 struct isis_area
*area
= spftree
->area
;
1547 int level
= spftree
->level
;
1548 char buff
[VID2STR_BUFFER
];
1550 if (spftree
->type
== SPF_TYPE_TI_LFA
&& VTYPE_IS(vertex
->type
)
1551 && !CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
)) {
1552 if (listcount(vertex
->Adj_N
) > 0) {
1553 struct isis_adjacency
*adj
;
1555 if (isis_tilfa_check(spftree
, vertex
) != 0)
1558 adj
= isis_adj_find(area
, level
, vertex
->N
.id
);
1560 sr_adj_sid_add_single(adj
, spftree
->family
,
1561 true, vertex
->Adj_N
);
1562 } else if (IS_DEBUG_SPF_EVENTS
)
1564 "ISIS-SPF: no adjacencies, do not install backup Adj-SID for %s depth %d dist %d",
1565 vid2string(vertex
, buff
, sizeof(buff
)),
1566 vertex
->depth
, vertex
->d_N
);
1569 if (VTYPE_IP(vertex
->type
)
1570 && !CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ROUTES
)) {
1571 enum spf_prefix_priority priority
;
1573 priority
= spf_prefix_priority(spftree
, vertex
);
1574 vertex
->N
.ip
.priority
= priority
;
1575 if (vertex
->depth
== 1 || listcount(vertex
->Adj_N
) > 0) {
1576 struct isis_spftree
*pre_spftree
;
1577 struct route_table
*route_table
= NULL
;
1578 bool allow_ecmp
= false;
1580 switch (spftree
->type
) {
1582 case SPF_TYPE_TI_LFA
:
1584 > area
->lfa_priority_limit
[level
- 1]) {
1587 "ISIS-LFA: skipping %s %s (low prefix priority)",
1596 case SPF_TYPE_FORWARD
:
1597 case SPF_TYPE_REVERSE
:
1601 switch (spftree
->type
) {
1603 isis_rlfa_check(spftree
, vertex
);
1605 case SPF_TYPE_TI_LFA
:
1606 if (isis_tilfa_check(spftree
, vertex
) != 0)
1609 pre_spftree
= spftree
->lfa
.old
.spftree
;
1610 route_table
= pre_spftree
->route_table_backup
;
1611 allow_ecmp
= area
->lfa_load_sharing
[level
- 1];
1612 pre_spftree
->lfa
.protection_counters
1613 .tilfa
[vertex
->N
.ip
.priority
] += 1;
1615 case SPF_TYPE_FORWARD
:
1616 case SPF_TYPE_REVERSE
:
1617 route_table
= spftree
->route_table
;
1621 * Update LFA protection counters (ignore local
1624 if (vertex
->depth
> 1) {
1625 spftree
->lfa
.protection_counters
1626 .total
[priority
] += 1;
1627 if (listcount(vertex
->Adj_N
) > 1)
1628 spftree
->lfa
.protection_counters
1629 .ecmp
[priority
] += 1;
1635 &vertex
->N
.ip
.p
.dest
, &vertex
->N
.ip
.p
.src
,
1636 vertex
->d_N
, vertex
->depth
, &vertex
->N
.ip
.sr
,
1637 vertex
->Adj_N
, allow_ecmp
, area
, route_table
);
1638 } else if (IS_DEBUG_SPF_EVENTS
)
1640 "ISIS-SPF: no adjacencies, do not install route for %s depth %d dist %d",
1641 vid2string(vertex
, buff
, sizeof(buff
)),
1642 vertex
->depth
, vertex
->d_N
);
1646 static void isis_spf_loop(struct isis_spftree
*spftree
,
1647 uint8_t *root_sysid
)
1649 struct isis_vertex
*vertex
;
1650 struct isis_lsp
*lsp
;
1651 struct listnode
*node
;
1653 while (isis_vertex_queue_count(&spftree
->tents
)) {
1654 vertex
= isis_vertex_queue_pop(&spftree
->tents
);
1656 #ifdef EXTREME_DEBUG
1657 if (IS_DEBUG_SPF_EVENTS
)
1659 "ISIS-SPF: get TENT node %s %s depth %d dist %d to PATHS",
1660 print_sys_hostname(vertex
->N
.id
),
1661 vtype2string(vertex
->type
), vertex
->depth
,
1663 #endif /* EXTREME_DEBUG */
1665 add_to_paths(spftree
, vertex
);
1666 if (!VTYPE_IS(vertex
->type
))
1669 lsp
= lsp_for_vertex(spftree
, vertex
);
1671 zlog_warn("ISIS-SPF: No LSP found for %s",
1672 isis_format_id(vertex
->N
.id
,
1673 sizeof(vertex
->N
.id
)));
1677 isis_spf_process_lsp(spftree
, lsp
, vertex
->d_N
, vertex
->depth
,
1678 root_sysid
, vertex
);
1681 /* Generate routes once the SPT is formed. */
1682 for (ALL_QUEUE_ELEMENTS_RO(&spftree
->paths
, node
, vertex
)) {
1683 /* New-style TLVs take precedence over the old-style TLVs. */
1684 switch (vertex
->type
) {
1685 case VTYPE_IPREACH_INTERNAL
:
1686 case VTYPE_IPREACH_EXTERNAL
:
1687 if (isis_find_vertex(&spftree
->paths
, &vertex
->N
,
1691 case VTYPE_PSEUDO_IS
:
1692 case VTYPE_PSEUDO_TE_IS
:
1693 case VTYPE_NONPSEUDO_IS
:
1694 case VTYPE_NONPSEUDO_TE_IS
:
1696 case VTYPE_IPREACH_TE
:
1697 case VTYPE_IP6REACH_INTERNAL
:
1698 case VTYPE_IP6REACH_EXTERNAL
:
1702 spf_path_process(spftree
, vertex
);
1706 struct isis_spftree
*isis_run_hopcount_spf(struct isis_area
*area
,
1708 struct isis_spftree
*spftree
)
1711 spftree
= isis_spftree_new(area
, &area
->lspdb
[IS_LEVEL_2
- 1],
1712 sysid
, ISIS_LEVEL2
, SPFTREE_IPV4
,
1714 F_SPFTREE_HOPCOUNT_METRIC
);
1716 init_spt(spftree
, ISIS_MT_IPV4_UNICAST
);
1717 if (!memcmp(sysid
, area
->isis
->sysid
, ISIS_SYS_ID_LEN
)) {
1718 struct isis_lsp
*root_lsp
;
1719 struct isis_vertex
*root_vertex
;
1721 root_lsp
= isis_root_system_lsp(spftree
->lspdb
, spftree
->sysid
);
1724 * If we are running locally, initialize with
1725 * information from adjacencies
1727 root_vertex
= isis_spf_add_root(spftree
);
1729 isis_spf_preload_tent(spftree
, sysid
, root_lsp
,
1733 isis_vertex_queue_insert(
1735 isis_vertex_new(spftree
, sysid
, VTYPE_NONPSEUDO_TE_IS
));
1738 isis_spf_loop(spftree
, sysid
);
1743 void isis_run_spf(struct isis_spftree
*spftree
)
1745 struct isis_lsp
*root_lsp
;
1746 struct isis_vertex
*root_vertex
;
1747 struct timeval time_start
;
1748 struct timeval time_end
;
1749 struct isis_mt_router_info
*mt_router_info
;
1752 /* Get time that can't roll backwards. */
1753 monotime(&time_start
);
1755 root_lsp
= isis_root_system_lsp(spftree
->lspdb
, spftree
->sysid
);
1756 if (root_lsp
== NULL
) {
1757 zlog_err("ISIS-SPF: could not find own l%d LSP!",
1762 /* Get Multi-Topology ID. */
1763 switch (spftree
->tree_id
) {
1765 mtid
= ISIS_MT_IPV4_UNICAST
;
1768 mt_router_info
= isis_tlvs_lookup_mt_router_info(
1769 root_lsp
->tlvs
, ISIS_MT_IPV6_UNICAST
);
1771 mtid
= ISIS_MT_IPV6_UNICAST
;
1773 mtid
= ISIS_MT_IPV4_UNICAST
;
1775 case SPFTREE_DSTSRC
:
1776 mtid
= ISIS_MT_IPV6_DSTSRC
;
1780 "%s should never be called with SPFTREE_COUNT as argument!",
1788 init_spt(spftree
, mtid
);
1790 root_vertex
= isis_spf_add_root(spftree
);
1792 isis_spf_build_adj_list(spftree
, root_lsp
);
1793 isis_spf_preload_tent(spftree
, spftree
->sysid
, root_lsp
, root_vertex
);
1798 if (!isis_vertex_queue_count(&spftree
->tents
)
1799 && (IS_DEBUG_SPF_EVENTS
)) {
1800 zlog_warn("ISIS-SPF: TENT is empty SPF-root:%s",
1801 print_sys_hostname(spftree
->sysid
));
1804 isis_spf_loop(spftree
, spftree
->sysid
);
1805 spftree
->runcount
++;
1806 spftree
->last_run_timestamp
= time(NULL
);
1807 spftree
->last_run_monotime
= monotime(&time_end
);
1808 spftree
->last_run_duration
=
1809 ((time_end
.tv_sec
- time_start
.tv_sec
) * 1000000)
1810 + (time_end
.tv_usec
- time_start
.tv_usec
);
1813 static void isis_run_spf_with_protection(struct isis_area
*area
,
1814 struct isis_spftree
*spftree
)
1816 /* Run forward SPF locally. */
1817 memcpy(spftree
->sysid
, area
->isis
->sysid
, ISIS_SYS_ID_LEN
);
1818 isis_run_spf(spftree
);
1820 /* Run LFA protection if configured. */
1821 if (area
->lfa_protected_links
[spftree
->level
- 1] > 0
1822 || area
->tilfa_protected_links
[spftree
->level
- 1] > 0)
1823 isis_spf_run_lfa(area
, spftree
);
1826 void isis_spf_verify_routes(struct isis_area
*area
, struct isis_spftree
**trees
)
1828 if (area
->is_type
== IS_LEVEL_1
) {
1829 isis_route_verify_table(area
, trees
[0]->route_table
,
1830 trees
[0]->route_table_backup
);
1831 } else if (area
->is_type
== IS_LEVEL_2
) {
1832 isis_route_verify_table(area
, trees
[1]->route_table
,
1833 trees
[1]->route_table_backup
);
1835 isis_route_verify_merge(area
, trees
[0]->route_table
,
1836 trees
[0]->route_table_backup
,
1837 trees
[1]->route_table
,
1838 trees
[1]->route_table_backup
);
1842 void isis_spf_invalidate_routes(struct isis_spftree
*tree
)
1844 isis_route_invalidate_table(tree
->area
, tree
->route_table
);
1846 /* Delete backup routes. */
1847 route_table_finish(tree
->route_table_backup
);
1848 tree
->route_table_backup
= srcdest_table_init();
1849 tree
->route_table_backup
->cleanup
= isis_route_node_cleanup
;
1852 void isis_spf_switchover_routes(struct isis_area
*area
,
1853 struct isis_spftree
**trees
, int family
,
1854 union g_addr
*nexthop_ip
, ifindex_t ifindex
,
1857 isis_route_switchover_nexthop(area
, trees
[level
- 1]->route_table
,
1858 family
, nexthop_ip
, ifindex
);
1861 static void isis_run_spf_cb(struct thread
*thread
)
1863 struct isis_spf_run
*run
= THREAD_ARG(thread
);
1864 struct isis_area
*area
= run
->area
;
1865 int level
= run
->level
;
1868 XFREE(MTYPE_ISIS_SPF_RUN
, run
);
1870 if (!(area
->is_type
& level
)) {
1871 if (IS_DEBUG_SPF_EVENTS
)
1872 zlog_warn("ISIS-SPF (%s) area does not share level",
1877 isis_area_delete_backup_adj_sids(area
, level
);
1878 isis_area_invalidate_routes(area
, level
);
1880 if (IS_DEBUG_SPF_EVENTS
)
1881 zlog_debug("ISIS-SPF (%s) L%d SPF needed, periodic SPF",
1882 area
->area_tag
, level
);
1884 if (area
->ip_circuits
) {
1885 isis_run_spf_with_protection(
1886 area
, area
->spftree
[SPFTREE_IPV4
][level
- 1]);
1889 if (area
->ipv6_circuits
) {
1890 isis_run_spf_with_protection(
1891 area
, area
->spftree
[SPFTREE_IPV6
][level
- 1]);
1894 if (area
->ipv6_circuits
&& isis_area_ipv6_dstsrc_enabled(area
)) {
1895 isis_run_spf_with_protection(
1896 area
, area
->spftree
[SPFTREE_DSTSRC
][level
- 1]);
1901 area
->spf_run_count
[level
]++;
1903 isis_area_verify_routes(area
);
1905 /* walk all circuits and reset any spf specific flags */
1906 struct listnode
*node
;
1907 struct isis_circuit
*circuit
;
1908 for (ALL_LIST_ELEMENTS_RO(area
->circuit_list
, node
, circuit
))
1909 UNSET_FLAG(circuit
->flags
, ISIS_CIRCUIT_FLAPPED_AFTER_SPF
);
1911 fabricd_run_spf(area
);
1914 static struct isis_spf_run
*isis_run_spf_arg(struct isis_area
*area
, int level
)
1916 struct isis_spf_run
*run
= XMALLOC(MTYPE_ISIS_SPF_RUN
, sizeof(*run
));
1924 void isis_spf_timer_free(void *run
)
1926 XFREE(MTYPE_ISIS_SPF_RUN
, run
);
1929 int _isis_spf_schedule(struct isis_area
*area
, int level
,
1930 const char *func
, const char *file
, int line
)
1932 struct isis_spftree
*spftree
;
1934 long tree_diff
, diff
;
1937 now
= monotime(NULL
);
1939 for (tree
= SPFTREE_IPV4
; tree
< SPFTREE_COUNT
; tree
++) {
1940 spftree
= area
->spftree
[tree
][level
- 1];
1941 tree_diff
= difftime(now
- spftree
->last_run_monotime
, 0);
1942 if (tree_diff
!= now
&& (diff
== 0 || tree_diff
< diff
))
1946 if (CHECK_FLAG(im
->options
, F_ISIS_UNIT_TEST
))
1950 assert(area
->is_type
& level
);
1952 if (IS_DEBUG_SPF_EVENTS
) {
1954 "ISIS-SPF (%s) L%d SPF schedule called, lastrun %ld sec ago Caller: %s %s:%d",
1955 area
->area_tag
, level
, diff
, func
, file
, line
);
1958 THREAD_OFF(area
->t_rlfa_rib_update
);
1959 if (area
->spf_delay_ietf
[level
- 1]) {
1960 /* Need to call schedule function also if spf delay is running
1962 * restart holdoff timer - compare
1963 * draft-ietf-rtgwg-backoff-algo-04 */
1965 spf_backoff_schedule(area
->spf_delay_ietf
[level
- 1]);
1966 if (area
->spf_timer
[level
- 1])
1969 thread_add_timer_msec(master
, isis_run_spf_cb
,
1970 isis_run_spf_arg(area
, level
), delay
,
1971 &area
->spf_timer
[level
- 1]);
1975 if (area
->spf_timer
[level
- 1])
1978 /* wait configured min_spf_interval before doing the SPF */
1980 if (diff
>= area
->min_spf_interval
[level
- 1]
1981 || area
->bfd_force_spf_refresh
) {
1983 * Last run is more than min interval ago or BFD signalled a
1984 * 'down' message, schedule immediate run
1988 if (area
->bfd_force_spf_refresh
) {
1990 "ISIS-SPF (%s) L%d SPF scheduled immediately due to BFD 'down' message",
1991 area
->area_tag
, level
);
1992 area
->bfd_force_spf_refresh
= false;
1995 timer
= area
->min_spf_interval
[level
- 1] - diff
;
1998 thread_add_timer(master
, isis_run_spf_cb
, isis_run_spf_arg(area
, level
),
1999 timer
, &area
->spf_timer
[level
- 1]);
2001 if (IS_DEBUG_SPF_EVENTS
)
2002 zlog_debug("ISIS-SPF (%s) L%d SPF scheduled %ld sec from now",
2003 area
->area_tag
, level
, timer
);
2008 static void isis_print_paths(struct vty
*vty
, struct isis_vertex_queue
*queue
,
2009 uint8_t *root_sysid
)
2011 struct listnode
*node
;
2012 struct isis_vertex
*vertex
;
2013 char buff
[VID2STR_BUFFER
];
2016 "Vertex Type Metric Next-Hop Interface Parent\n");
2018 for (ALL_QUEUE_ELEMENTS_RO(queue
, node
, vertex
)) {
2019 if (VTYPE_IS(vertex
->type
)
2020 && memcmp(vertex
->N
.id
, root_sysid
, ISIS_SYS_ID_LEN
) == 0) {
2021 vty_out(vty
, "%-20s %-12s %-6s",
2022 print_sys_hostname(root_sysid
), "", "");
2023 vty_out(vty
, "%-30s\n", "");
2028 struct listnode
*anode
= listhead(vertex
->Adj_N
);
2029 struct listnode
*pnode
= listhead(vertex
->parents
);
2030 struct isis_vertex_adj
*vadj
;
2031 struct isis_vertex
*pvertex
;
2033 vty_out(vty
, "%-20s %-12s %-6u ",
2034 vid2string(vertex
, buff
, sizeof(buff
)),
2035 vtype2string(vertex
->type
), vertex
->d_N
);
2036 for (unsigned int i
= 0;
2037 i
< MAX(vertex
->Adj_N
? listcount(vertex
->Adj_N
) : 0,
2038 vertex
->parents
? listcount(vertex
->parents
) : 0);
2041 vadj
= listgetdata(anode
);
2042 anode
= anode
->next
;
2048 pvertex
= listgetdata(pnode
);
2049 pnode
= pnode
->next
;
2056 vty_out(vty
, "%-20s %-12s %-6s ", "", "", "");
2060 struct isis_spf_adj
*sadj
= vadj
->sadj
;
2062 vty_out(vty
, "%-20s %-9s ",
2063 print_sys_hostname(sadj
->id
),
2064 sadj
->adj
? sadj
->adj
->circuit
2071 vty_out(vty
, "%-20s %-9s ", "", "");
2073 vty_out(vty
, "%s(%d)",
2074 vid2string(pvertex
, buff
, sizeof(buff
)),
2084 void isis_print_spftree(struct vty
*vty
, struct isis_spftree
*spftree
)
2086 const char *tree_id_text
= NULL
;
2088 if (!spftree
|| !isis_vertex_queue_count(&spftree
->paths
))
2091 switch (spftree
->tree_id
) {
2093 tree_id_text
= "that speak IP";
2096 tree_id_text
= "that speak IPv6";
2098 case SPFTREE_DSTSRC
:
2099 tree_id_text
= "that support IPv6 dst-src routing";
2102 assert(!"isis_print_spftree shouldn't be called with SPFTREE_COUNT as type");
2106 vty_out(vty
, "IS-IS paths to level-%d routers %s\n", spftree
->level
,
2108 isis_print_paths(vty
, &spftree
->paths
, spftree
->sysid
);
2112 static void show_isis_topology_common(struct vty
*vty
, int levels
,
2115 struct listnode
*node
;
2116 struct isis_area
*area
;
2118 if (!isis
->area_list
|| isis
->area_list
->count
== 0)
2121 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
2122 vty_out(vty
, "Area %s:\n",
2123 area
->area_tag
? area
->area_tag
: "null");
2125 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
; level
++) {
2126 if ((level
& levels
) == 0)
2129 if (area
->ip_circuits
> 0) {
2132 area
->spftree
[SPFTREE_IPV4
][level
- 1]);
2134 if (area
->ipv6_circuits
> 0) {
2137 area
->spftree
[SPFTREE_IPV6
][level
- 1]);
2139 if (isis_area_ipv6_dstsrc_enabled(area
)) {
2140 isis_print_spftree(vty
,
2141 area
->spftree
[SPFTREE_DSTSRC
]
2146 if (fabricd_spftree(area
)) {
2148 "IS-IS paths to level-2 routers with hop-by-hop metric\n");
2149 isis_print_paths(vty
, &fabricd_spftree(area
)->paths
, isis
->sysid
);
2157 DEFUN(show_isis_topology
, show_isis_topology_cmd
,
2159 " [vrf <NAME|all>] topology"
2161 " [<level-1|level-2>]"
2164 SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
2166 "IS-IS paths to Intermediate Systems\n"
2168 "Paths to all level-1 routers in the area\n"
2169 "Paths to all level-2 routers in the domain\n"
2173 int levels
= ISIS_LEVELS
;
2174 struct listnode
*node
;
2175 struct isis
*isis
= NULL
;
2177 const char *vrf_name
= VRF_DEFAULT_NAME
;
2178 bool all_vrf
= false;
2181 if (argv_find(argv
, argc
, "topology", &idx
)) {
2183 levels
= ISIS_LEVEL1
| ISIS_LEVEL2
;
2184 else if (strmatch(argv
[idx
+ 1]->arg
, "level-1"))
2185 levels
= ISIS_LEVEL1
;
2187 levels
= ISIS_LEVEL2
;
2191 vty_out(vty
, "IS-IS Routing Process not enabled\n");
2194 ISIS_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
2198 for (ALL_LIST_ELEMENTS_RO(im
->isis
, node
, isis
))
2199 show_isis_topology_common(vty
, levels
, isis
);
2202 isis
= isis_lookup_by_vrfname(vrf_name
);
2204 show_isis_topology_common(vty
, levels
, isis
);
2210 static void isis_print_route(struct ttable
*tt
, const struct prefix
*prefix
,
2211 struct isis_route_info
*rinfo
, bool prefix_sid
,
2212 bool no_adjacencies
)
2214 struct isis_nexthop
*nexthop
;
2215 struct listnode
*node
;
2217 char buf_prefix
[BUFSIZ
];
2219 (void)prefix2str(prefix
, buf_prefix
, sizeof(buf_prefix
));
2220 for (ALL_LIST_ELEMENTS_RO(rinfo
->nexthops
, node
, nexthop
)) {
2221 struct interface
*ifp
;
2222 char buf_iface
[BUFSIZ
];
2223 char buf_nhop
[BUFSIZ
];
2225 if (!no_adjacencies
) {
2226 inet_ntop(nexthop
->family
, &nexthop
->ip
, buf_nhop
,
2228 ifp
= if_lookup_by_index(nexthop
->ifindex
, VRF_DEFAULT
);
2230 strlcpy(buf_iface
, ifp
->name
,
2233 snprintf(buf_iface
, sizeof(buf_iface
),
2234 "ifindex %u", nexthop
->ifindex
);
2236 strlcpy(buf_nhop
, print_sys_hostname(nexthop
->sysid
),
2238 strlcpy(buf_iface
, "-", sizeof(buf_iface
));
2242 char buf_sid
[BUFSIZ
] = {};
2243 char buf_lblop
[BUFSIZ
] = {};
2245 if (nexthop
->sr
.present
) {
2246 snprintf(buf_sid
, sizeof(buf_sid
), "%u",
2247 nexthop
->sr
.sid
.value
);
2248 sr_op2str(buf_lblop
, sizeof(buf_lblop
),
2249 rinfo
->sr
.label
, nexthop
->sr
.label
);
2251 strlcpy(buf_sid
, "-", sizeof(buf_sid
));
2252 strlcpy(buf_lblop
, "-", sizeof(buf_lblop
));
2256 ttable_add_row(tt
, "%s|%u|%s|%s|%s|%s",
2257 buf_prefix
, rinfo
->cost
,
2258 buf_iface
, buf_nhop
, buf_sid
,
2262 ttable_add_row(tt
, "||%s|%s|%s|%s", buf_iface
,
2263 buf_nhop
, buf_sid
, buf_lblop
);
2265 char buf_labels
[BUFSIZ
] = {};
2267 if (nexthop
->label_stack
) {
2269 i
< nexthop
->label_stack
->num_labels
;
2271 char buf_label
[BUFSIZ
];
2274 nexthop
->label_stack
->label
[i
],
2278 strlcat(buf_labels
, "/",
2279 sizeof(buf_labels
));
2280 strlcat(buf_labels
, buf_label
,
2281 sizeof(buf_labels
));
2283 } else if (nexthop
->sr
.present
)
2284 label2str(nexthop
->sr
.label
, 0, buf_labels
,
2285 sizeof(buf_labels
));
2287 strlcpy(buf_labels
, "-", sizeof(buf_labels
));
2290 ttable_add_row(tt
, "%s|%u|%s|%s|%s", buf_prefix
,
2291 rinfo
->cost
, buf_iface
, buf_nhop
,
2295 ttable_add_row(tt
, "||%s|%s|%s", buf_iface
,
2296 buf_nhop
, buf_labels
);
2299 if (list_isempty(rinfo
->nexthops
)) {
2301 char buf_sid
[BUFSIZ
] = {};
2302 char buf_lblop
[BUFSIZ
] = {};
2304 if (rinfo
->sr
.present
) {
2305 snprintf(buf_sid
, sizeof(buf_sid
), "%u",
2306 rinfo
->sr
.sid
.value
);
2307 sr_op2str(buf_lblop
, sizeof(buf_lblop
),
2309 MPLS_LABEL_IMPLICIT_NULL
);
2311 strlcpy(buf_sid
, "-", sizeof(buf_sid
));
2312 strlcpy(buf_lblop
, "-", sizeof(buf_lblop
));
2315 ttable_add_row(tt
, "%s|%u|%s|%s|%s|%s", buf_prefix
,
2316 rinfo
->cost
, "-", "-", buf_sid
,
2319 ttable_add_row(tt
, "%s|%u|%s|%s|%s", buf_prefix
,
2320 rinfo
->cost
, "-", "-", "-");
2324 void isis_print_routes(struct vty
*vty
, struct isis_spftree
*spftree
,
2325 bool prefix_sid
, bool backup
)
2327 struct route_table
*route_table
;
2329 struct route_node
*rn
;
2330 bool no_adjacencies
= false;
2331 const char *tree_id_text
= NULL
;
2336 switch (spftree
->tree_id
) {
2338 tree_id_text
= "IPv4";
2341 tree_id_text
= "IPv6";
2343 case SPFTREE_DSTSRC
:
2344 tree_id_text
= "IPv6 (dst-src routing)";
2347 assert(!"isis_print_routes shouldn't be called with SPFTREE_COUNT as type");
2351 vty_out(vty
, "IS-IS %s %s routing table:\n\n",
2352 circuit_t2string(spftree
->level
), tree_id_text
);
2354 /* Prepare table. */
2355 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2357 ttable_add_row(tt
, "Prefix|Metric|Interface|Nexthop|SID|Label Op.");
2359 ttable_add_row(tt
, "Prefix|Metric|Interface|Nexthop|Label(s)");
2360 tt
->style
.cell
.rpad
= 2;
2361 tt
->style
.corner
= '+';
2363 ttable_rowseps(tt
, 0, BOTTOM
, true, '-');
2365 if (CHECK_FLAG(spftree
->flags
, F_SPFTREE_NO_ADJACENCIES
))
2366 no_adjacencies
= true;
2369 (backup
) ? spftree
->route_table_backup
: spftree
->route_table
;
2370 for (rn
= route_top(route_table
); rn
; rn
= route_next(rn
)) {
2371 struct isis_route_info
*rinfo
;
2377 isis_print_route(tt
, &rn
->p
, rinfo
, prefix_sid
, no_adjacencies
);
2380 /* Dump the generated table. */
2381 if (tt
->nrows
> 1) {
2384 table
= ttable_dump(tt
, "\n");
2385 vty_out(vty
, "%s\n", table
);
2386 XFREE(MTYPE_TMP
, table
);
2391 static void show_isis_route_common(struct vty
*vty
, int levels
,
2392 struct isis
*isis
, bool prefix_sid
,
2395 struct listnode
*node
;
2396 struct isis_area
*area
;
2398 if (!isis
->area_list
|| isis
->area_list
->count
== 0)
2401 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
2402 vty_out(vty
, "Area %s:\n",
2403 area
->area_tag
? area
->area_tag
: "null");
2405 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
; level
++) {
2406 if ((level
& levels
) == 0)
2409 if (area
->ip_circuits
> 0) {
2412 area
->spftree
[SPFTREE_IPV4
][level
- 1],
2413 prefix_sid
, backup
);
2415 if (area
->ipv6_circuits
> 0) {
2418 area
->spftree
[SPFTREE_IPV6
][level
- 1],
2419 prefix_sid
, backup
);
2421 if (isis_area_ipv6_dstsrc_enabled(area
)) {
2422 isis_print_routes(vty
,
2423 area
->spftree
[SPFTREE_DSTSRC
]
2425 prefix_sid
, backup
);
2431 DEFUN(show_isis_route
, show_isis_route_cmd
,
2433 " [vrf <NAME|all>] route"
2435 " [<level-1|level-2>]"
2437 " [<prefix-sid|backup>]",
2438 SHOW_STR PROTO_HELP VRF_FULL_CMD_HELP_STR
2439 "IS-IS routing table\n"
2444 "Show Prefix-SID information\n"
2445 "Show backup routes\n")
2449 struct listnode
*node
;
2450 const char *vrf_name
= VRF_DEFAULT_NAME
;
2451 bool all_vrf
= false;
2452 bool prefix_sid
= false;
2453 bool backup
= false;
2456 if (argv_find(argv
, argc
, "level-1", &idx
))
2457 levels
= ISIS_LEVEL1
;
2458 else if (argv_find(argv
, argc
, "level-2", &idx
))
2459 levels
= ISIS_LEVEL2
;
2461 levels
= ISIS_LEVEL1
| ISIS_LEVEL2
;
2464 vty_out(vty
, "IS-IS Routing Process not enabled\n");
2467 ISIS_FIND_VRF_ARGS(argv
, argc
, idx
, vrf_name
, all_vrf
);
2469 if (argv_find(argv
, argc
, "prefix-sid", &idx
))
2471 if (argv_find(argv
, argc
, "backup", &idx
))
2476 for (ALL_LIST_ELEMENTS_RO(im
->isis
, node
, isis
))
2477 show_isis_route_common(vty
, levels
, isis
,
2478 prefix_sid
, backup
);
2481 isis
= isis_lookup_by_vrfname(vrf_name
);
2483 show_isis_route_common(vty
, levels
, isis
, prefix_sid
,
2490 static void isis_print_frr_summary_line(struct ttable
*tt
,
2491 const char *protection
,
2492 uint32_t counters
[SPF_PREFIX_PRIO_MAX
])
2494 uint32_t critical
, high
, medium
, low
, total
;
2496 critical
= counters
[SPF_PREFIX_PRIO_CRITICAL
];
2497 high
= counters
[SPF_PREFIX_PRIO_HIGH
];
2498 medium
= counters
[SPF_PREFIX_PRIO_MEDIUM
];
2499 low
= counters
[SPF_PREFIX_PRIO_LOW
];
2500 total
= critical
+ high
+ medium
+ low
;
2502 ttable_add_row(tt
, "%s|%u|%u|%u|%u|%u", protection
, critical
, high
,
2503 medium
, low
, total
);
2507 isis_print_frr_summary_line_coverage(struct ttable
*tt
, const char *protection
,
2508 double counters
[SPF_PREFIX_PRIO_MAX
],
2511 double critical
, high
, medium
, low
;
2513 critical
= counters
[SPF_PREFIX_PRIO_CRITICAL
] * 100;
2514 high
= counters
[SPF_PREFIX_PRIO_HIGH
] * 100;
2515 medium
= counters
[SPF_PREFIX_PRIO_MEDIUM
] * 100;
2516 low
= counters
[SPF_PREFIX_PRIO_LOW
] * 100;
2519 ttable_add_row(tt
, "%s|%.2f%%|%.2f%%|%.2f%%|%.2f%%|%.2f%%", protection
,
2520 critical
, high
, medium
, low
, total
);
2523 static void isis_print_frr_summary(struct vty
*vty
,
2524 struct isis_spftree
*spftree
)
2528 const char *tree_id_text
= NULL
;
2529 uint32_t protectd
[SPF_PREFIX_PRIO_MAX
] = {0};
2530 uint32_t unprotected
[SPF_PREFIX_PRIO_MAX
] = {0};
2531 double coverage
[SPF_PREFIX_PRIO_MAX
] = {0};
2532 uint32_t protected_total
= 0, grand_total
= 0;
2533 double coverage_total
;
2538 switch (spftree
->tree_id
) {
2540 tree_id_text
= "IPv4";
2543 tree_id_text
= "IPv6";
2545 case SPFTREE_DSTSRC
:
2546 tree_id_text
= "IPv6 (dst-src routing)";
2549 assert(!"isis_print_frr_summary shouldn't be called with SPFTREE_COUNT as type");
2553 vty_out(vty
, " IS-IS %s %s Fast ReRoute summary:\n\n",
2554 circuit_t2string(spftree
->level
), tree_id_text
);
2556 /* Prepare table. */
2557 tt
= ttable_new(&ttable_styles
[TTSTYLE_BLANK
]);
2560 "Protection \\ Priority|Critical|High |Medium |Low |Total");
2561 tt
->style
.cell
.rpad
= 2;
2562 tt
->style
.corner
= '+';
2564 ttable_rowseps(tt
, 0, BOTTOM
, true, '-');
2566 /* Compute unprotected and coverage totals. */
2567 for (int priority
= SPF_PREFIX_PRIO_CRITICAL
;
2568 priority
< SPF_PREFIX_PRIO_MAX
; priority
++) {
2569 uint32_t *lfa
= spftree
->lfa
.protection_counters
.lfa
;
2570 uint32_t *rlfa
= spftree
->lfa
.protection_counters
.rlfa
;
2571 uint32_t *tilfa
= spftree
->lfa
.protection_counters
.tilfa
;
2572 uint32_t *ecmp
= spftree
->lfa
.protection_counters
.ecmp
;
2573 uint32_t *total
= spftree
->lfa
.protection_counters
.total
;
2575 protectd
[priority
] = lfa
[priority
] + rlfa
[priority
]
2576 + tilfa
[priority
] + ecmp
[priority
];
2577 /* Safeguard to protect against possible inconsistencies. */
2578 if (protectd
[priority
] > total
[priority
])
2579 protectd
[priority
] = total
[priority
];
2580 unprotected
[priority
] = total
[priority
] - protectd
[priority
];
2581 protected_total
+= protectd
[priority
];
2582 grand_total
+= total
[priority
];
2584 if (!total
[priority
])
2585 coverage
[priority
] = 0;
2587 coverage
[priority
] =
2588 protectd
[priority
] / (double)total
[priority
];
2594 coverage_total
= protected_total
/ (double)grand_total
;
2597 isis_print_frr_summary_line(tt
, "Classic LFA",
2598 spftree
->lfa
.protection_counters
.lfa
);
2599 isis_print_frr_summary_line(tt
, "Remote LFA",
2600 spftree
->lfa
.protection_counters
.rlfa
);
2601 isis_print_frr_summary_line(tt
, "Topology Independent LFA",
2602 spftree
->lfa
.protection_counters
.tilfa
);
2603 isis_print_frr_summary_line(tt
, "ECMP",
2604 spftree
->lfa
.protection_counters
.ecmp
);
2605 isis_print_frr_summary_line(tt
, "Unprotected", unprotected
);
2606 isis_print_frr_summary_line_coverage(tt
, "Protection coverage",
2607 coverage
, coverage_total
);
2609 /* Dump the generated table. */
2610 table
= ttable_dump(tt
, "\n");
2611 vty_out(vty
, "%s\n", table
);
2612 XFREE(MTYPE_TMP
, table
);
2616 static void show_isis_frr_summary_common(struct vty
*vty
, int levels
,
2619 struct listnode
*node
;
2620 struct isis_area
*area
;
2622 if (!isis
->area_list
|| isis
->area_list
->count
== 0)
2625 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
2626 vty_out(vty
, "Area %s:\n",
2627 area
->area_tag
? area
->area_tag
: "null");
2629 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVELS
; level
++) {
2630 if ((level
& levels
) == 0)
2633 if (area
->ip_circuits
> 0) {
2634 isis_print_frr_summary(
2636 area
->spftree
[SPFTREE_IPV4
][level
- 1]);
2638 if (area
->ipv6_circuits
> 0) {
2639 isis_print_frr_summary(
2641 area
->spftree
[SPFTREE_IPV6
][level
- 1]);
2643 if (isis_area_ipv6_dstsrc_enabled(area
)) {
2644 isis_print_frr_summary(
2645 vty
, area
->spftree
[SPFTREE_DSTSRC
]
2652 DEFUN(show_isis_frr_summary
, show_isis_frr_summary_cmd
,
2654 " [vrf <NAME|all>] fast-reroute summary"
2656 " [<level-1|level-2>]"
2659 SHOW_STR PROTO_HELP VRF_FULL_CMD_HELP_STR
2660 "IS-IS FRR information\n"
2670 struct listnode
*node
;
2671 const char *vrf_name
= VRF_DEFAULT_NAME
;
2672 bool all_vrf
= false;
2675 if (argv_find(argv
, argc
, "level-1", &idx
))
2676 levels
= ISIS_LEVEL1
;
2677 else if (argv_find(argv
, argc
, "level-2", &idx
))
2678 levels
= ISIS_LEVEL2
;
2680 levels
= ISIS_LEVEL1
| ISIS_LEVEL2
;
2683 vty_out(vty
, "IS-IS Routing Process not enabled\n");
2686 ISIS_FIND_VRF_ARGS(argv
, argc
, idx
, vrf_name
, all_vrf
);
2690 for (ALL_LIST_ELEMENTS_RO(im
->isis
, node
, isis
))
2691 show_isis_frr_summary_common(vty
, levels
, isis
);
2694 isis
= isis_lookup_by_vrfname(vrf_name
);
2696 show_isis_frr_summary_common(vty
, levels
, isis
);
2702 void isis_spf_init(void)
2704 install_element(VIEW_NODE
, &show_isis_topology_cmd
);
2705 install_element(VIEW_NODE
, &show_isis_route_cmd
);
2706 install_element(VIEW_NODE
, &show_isis_frr_summary_cmd
);
2708 /* Register hook(s). */
2709 hook_register(isis_adj_state_change_hook
, spf_adj_state_change
);
2712 void isis_spf_print(struct isis_spftree
*spftree
, struct vty
*vty
)
2714 uint64_t last_run_duration
= spftree
->last_run_duration
;
2716 vty_out(vty
, " last run elapsed : ");
2717 vty_out_timestr(vty
, spftree
->last_run_timestamp
);
2720 vty_out(vty
, " last run duration : %" PRIu64
" usec\n",
2723 vty_out(vty
, " run count : %u\n", spftree
->runcount
);
2725 void isis_spf_print_json(struct isis_spftree
*spftree
, struct json_object
*json
)
2727 char uptime
[MONOTIME_STRLEN
];
2730 cur
-= spftree
->last_run_timestamp
;
2731 frrtime_to_interval(cur
, uptime
, sizeof(uptime
));
2732 json_object_string_add(json
, "last-run-elapsed", uptime
);
2733 json_object_int_add(json
, "last-run-duration-usec",
2734 spftree
->last_run_duration
);
2735 json_object_int_add(json
, "last-run-count", spftree
->runcount
);