1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
|
/*
* IS-IS Rout(e)ing protocol - isis_spf.c
* The SPT algorithm
*
* Copyright (C) 2001,2002 Sampo Saaristo
* Tampere University of Technology
* Institute of Communications Engineering
* Copyright (C) 2017 Christian Franke <chris@opensourcerouting.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public Licenseas published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "thread.h"
#include "linklist.h"
#include "vty.h"
#include "log.h"
#include "command.h"
#include "memory.h"
#include "prefix.h"
#include "hash.h"
#include "if.h"
#include "table.h"
#include "spf_backoff.h"
#include "isis_constants.h"
#include "isis_common.h"
#include "isis_flags.h"
#include "dict.h"
#include "isisd.h"
#include "isis_misc.h"
#include "isis_adjacency.h"
#include "isis_circuit.h"
#include "isis_tlv.h"
#include "isis_pdu.h"
#include "isis_lsp.h"
#include "isis_dynhn.h"
#include "isis_spf.h"
#include "isis_route.h"
#include "isis_csm.h"
#include "isis_mt.h"
DEFINE_MTYPE_STATIC(ISISD, ISIS_SPF_RUN, "ISIS SPF Run Info");
struct isis_spf_run {
struct isis_area *area;
int level;
};
/* 7.2.7 */
static void remove_excess_adjs(struct list *adjs)
{
struct listnode *node, *excess = NULL;
struct isis_adjacency *adj, *candidate = NULL;
int comp;
for (ALL_LIST_ELEMENTS_RO(adjs, node, adj)) {
if (excess == NULL)
excess = node;
candidate = listgetdata(excess);
if (candidate->sys_type < adj->sys_type) {
excess = node;
continue;
}
if (candidate->sys_type > adj->sys_type)
continue;
comp = memcmp(candidate->sysid, adj->sysid, ISIS_SYS_ID_LEN);
if (comp > 0) {
excess = node;
continue;
}
if (comp < 0)
continue;
if (candidate->circuit->circuit_id > adj->circuit->circuit_id) {
excess = node;
continue;
}
if (candidate->circuit->circuit_id < adj->circuit->circuit_id)
continue;
comp = memcmp(candidate->snpa, adj->snpa, ETH_ALEN);
if (comp > 0) {
excess = node;
continue;
}
}
list_delete_node(adjs, excess);
return;
}
static const char *vtype2string(enum vertextype vtype)
{
switch (vtype) {
case VTYPE_PSEUDO_IS:
return "pseudo_IS";
break;
case VTYPE_PSEUDO_TE_IS:
return "pseudo_TE-IS";
break;
case VTYPE_NONPSEUDO_IS:
return "IS";
break;
case VTYPE_NONPSEUDO_TE_IS:
return "TE-IS";
break;
case VTYPE_ES:
return "ES";
break;
case VTYPE_IPREACH_INTERNAL:
return "IP internal";
break;
case VTYPE_IPREACH_EXTERNAL:
return "IP external";
break;
case VTYPE_IPREACH_TE:
return "IP TE";
break;
case VTYPE_IP6REACH_INTERNAL:
return "IP6 internal";
break;
case VTYPE_IP6REACH_EXTERNAL:
return "IP6 external";
break;
default:
return "UNKNOWN";
}
return NULL; /* Not reached */
}
static const char *vid2string(struct isis_vertex *vertex, char *buff, int size)
{
if (VTYPE_IS(vertex->type) || VTYPE_ES(vertex->type)) {
return print_sys_hostname(vertex->N.id);
}
if (VTYPE_IP(vertex->type)) {
prefix2str((struct prefix *)&vertex->N.prefix, buff, size);
return buff;
}
return "UNKNOWN";
}
static struct isis_vertex *isis_vertex_new(void *id, enum vertextype vtype)
{
struct isis_vertex *vertex;
vertex = XCALLOC(MTYPE_ISIS_VERTEX, sizeof(struct isis_vertex));
vertex->type = vtype;
if (VTYPE_IS(vtype) || VTYPE_ES(vtype)) {
memcpy(vertex->N.id, (u_char *)id, ISIS_SYS_ID_LEN + 1);
} else if (VTYPE_IP(vtype)) {
memcpy(&vertex->N.prefix, (struct prefix *)id,
sizeof(struct prefix));
} else {
zlog_err("WTF!");
}
vertex->Adj_N = list_new();
vertex->parents = list_new();
vertex->children = list_new();
return vertex;
}
static void isis_vertex_del(struct isis_vertex *vertex)
{
list_delete(vertex->Adj_N);
vertex->Adj_N = NULL;
list_delete(vertex->parents);
vertex->parents = NULL;
list_delete(vertex->children);
vertex->children = NULL;
memset(vertex, 0, sizeof(struct isis_vertex));
XFREE(MTYPE_ISIS_VERTEX, vertex);
return;
}
static void isis_vertex_adj_del(struct isis_vertex *vertex,
struct isis_adjacency *adj)
{
struct listnode *node, *nextnode;
if (!vertex)
return;
for (node = listhead(vertex->Adj_N); node; node = nextnode) {
nextnode = listnextnode(node);
if (listgetdata(node) == adj)
list_delete_node(vertex->Adj_N, node);
}
return;
}
struct isis_spftree *isis_spftree_new(struct isis_area *area)
{
struct isis_spftree *tree;
tree = XCALLOC(MTYPE_ISIS_SPFTREE, sizeof(struct isis_spftree));
if (tree == NULL) {
zlog_err("ISIS-Spf: isis_spftree_new Out of memory!");
return NULL;
}
tree->tents = list_new();
tree->paths = list_new();
tree->area = area;
tree->last_run_timestamp = 0;
tree->last_run_duration = 0;
tree->runcount = 0;
return tree;
}
void isis_spftree_del(struct isis_spftree *spftree)
{
spftree->tents->del = (void (*)(void *))isis_vertex_del;
list_delete(spftree->tents);
spftree->tents = NULL;
spftree->paths->del = (void (*)(void *))isis_vertex_del;
list_delete(spftree->paths);
spftree->paths = NULL;
XFREE(MTYPE_ISIS_SPFTREE, spftree);
return;
}
static void isis_spftree_adj_del(struct isis_spftree *spftree,
struct isis_adjacency *adj)
{
struct listnode *node;
if (!adj)
return;
for (node = listhead(spftree->tents); node; node = listnextnode(node))
isis_vertex_adj_del(listgetdata(node), adj);
for (node = listhead(spftree->paths); node; node = listnextnode(node))
isis_vertex_adj_del(listgetdata(node), adj);
return;
}
void spftree_area_init(struct isis_area *area)
{
if (area->is_type & IS_LEVEL_1) {
if (area->spftree[0] == NULL)
area->spftree[0] = isis_spftree_new(area);
if (area->spftree6[0] == NULL)
area->spftree6[0] = isis_spftree_new(area);
}
if (area->is_type & IS_LEVEL_2) {
if (area->spftree[1] == NULL)
area->spftree[1] = isis_spftree_new(area);
if (area->spftree6[1] == NULL)
area->spftree6[1] = isis_spftree_new(area);
}
return;
}
void spftree_area_del(struct isis_area *area)
{
if (area->is_type & IS_LEVEL_1) {
if (area->spftree[0] != NULL) {
isis_spftree_del(area->spftree[0]);
area->spftree[0] = NULL;
}
if (area->spftree6[0]) {
isis_spftree_del(area->spftree6[0]);
area->spftree6[0] = NULL;
}
}
if (area->is_type & IS_LEVEL_2) {
if (area->spftree[1] != NULL) {
isis_spftree_del(area->spftree[1]);
area->spftree[1] = NULL;
}
if (area->spftree6[1] != NULL) {
isis_spftree_del(area->spftree6[1]);
area->spftree6[1] = NULL;
}
}
return;
}
void spftree_area_adj_del(struct isis_area *area, struct isis_adjacency *adj)
{
if (area->is_type & IS_LEVEL_1) {
if (area->spftree[0] != NULL)
isis_spftree_adj_del(area->spftree[0], adj);
if (area->spftree6[0] != NULL)
isis_spftree_adj_del(area->spftree6[0], adj);
}
if (area->is_type & IS_LEVEL_2) {
if (area->spftree[1] != NULL)
isis_spftree_adj_del(area->spftree[1], adj);
if (area->spftree6[1] != NULL)
isis_spftree_adj_del(area->spftree6[1], adj);
}
return;
}
/*
* Find the system LSP: returns the LSP in our LSP database
* associated with the given system ID.
*/
static struct isis_lsp *isis_root_system_lsp(struct isis_area *area, int level,
u_char *sysid)
{
struct isis_lsp *lsp;
u_char lspid[ISIS_SYS_ID_LEN + 2];
memcpy(lspid, sysid, ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(lspid) = 0;
LSP_FRAGMENT(lspid) = 0;
lsp = lsp_search(lspid, area->lspdb[level - 1]);
if (lsp && lsp->lsp_header->rem_lifetime != 0)
return lsp;
return NULL;
}
/*
* Add this IS to the root of SPT
*/
static struct isis_vertex *isis_spf_add_root(struct isis_spftree *spftree,
u_char *sysid)
{
struct isis_vertex *vertex;
struct isis_lsp *lsp;
#ifdef EXTREME_DEBUG
char buff[PREFIX2STR_BUFFER];
#endif /* EXTREME_DEBUG */
u_char id[ISIS_SYS_ID_LEN + 1];
memcpy(id, sysid, ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(id) = 0;
lsp = isis_root_system_lsp(spftree->area, spftree->level, sysid);
if (lsp == NULL)
zlog_warn("ISIS-Spf: could not find own l%d LSP!",
spftree->level);
vertex = isis_vertex_new(id,
spftree->area->oldmetric
? VTYPE_NONPSEUDO_IS
: VTYPE_NONPSEUDO_TE_IS);
listnode_add(spftree->paths, vertex);
#ifdef EXTREME_DEBUG
zlog_debug("ISIS-Spf: added this IS %s %s depth %d dist %d to PATHS",
vtype2string(vertex->type),
vid2string(vertex, buff, sizeof(buff)), vertex->depth,
vertex->d_N);
#endif /* EXTREME_DEBUG */
return vertex;
}
static struct isis_vertex *isis_find_vertex(struct list *list, void *id,
enum vertextype vtype)
{
struct listnode *node;
struct isis_vertex *vertex;
struct prefix *p1, *p2;
for (ALL_LIST_ELEMENTS_RO(list, node, vertex)) {
if (vertex->type != vtype)
continue;
if (VTYPE_IS(vertex->type) || VTYPE_ES(vertex->type)) {
if (memcmp((u_char *)id, vertex->N.id,
ISIS_SYS_ID_LEN + 1)
== 0)
return vertex;
}
if (VTYPE_IP(vertex->type)) {
p1 = (struct prefix *)id;
p2 = (struct prefix *)&vertex->N.id;
if (p1->family == p2->family
&& p1->prefixlen == p2->prefixlen
&& !memcmp(&p1->u.prefix, &p2->u.prefix,
PSIZE(p1->prefixlen))) {
return vertex;
}
}
}
return NULL;
}
/*
* Compares vertizes for sorting in the TENT list. Returns true
* if candidate should be considered before current, false otherwise.
*/
static bool tent_cmp(struct isis_vertex *current, struct isis_vertex *candidate)
{
if (current->d_N > candidate->d_N)
return true;
if (current->d_N == candidate->d_N && current->type > candidate->type)
return true;
return false;
}
/*
* Add a vertex to TENT sorted by cost and by vertextype on tie break situation
*/
static struct isis_vertex *isis_spf_add2tent(struct isis_spftree *spftree,
enum vertextype vtype, void *id,
uint32_t cost, int depth,
struct isis_adjacency *adj,
struct isis_vertex *parent)
{
struct isis_vertex *vertex, *v;
struct listnode *node;
struct isis_adjacency *parent_adj;
#ifdef EXTREME_DEBUG
char buff[PREFIX2STR_BUFFER];
#endif
assert(isis_find_vertex(spftree->paths, id, vtype) == NULL);
assert(isis_find_vertex(spftree->tents, id, vtype) == NULL);
vertex = isis_vertex_new(id, vtype);
vertex->d_N = cost;
vertex->depth = depth;
if (parent) {
listnode_add(vertex->parents, parent);
if (listnode_lookup(parent->children, vertex) == NULL)
listnode_add(parent->children, vertex);
}
if (parent && parent->Adj_N && listcount(parent->Adj_N) > 0) {
for (ALL_LIST_ELEMENTS_RO(parent->Adj_N, node, parent_adj))
listnode_add(vertex->Adj_N, parent_adj);
} else if (adj) {
listnode_add(vertex->Adj_N, adj);
}
#ifdef EXTREME_DEBUG
zlog_debug(
"ISIS-Spf: add to TENT %s %s %s depth %d dist %d adjcount %d",
print_sys_hostname(vertex->N.id), vtype2string(vertex->type),
vid2string(vertex, buff, sizeof(buff)), vertex->depth,
vertex->d_N, listcount(vertex->Adj_N));
#endif /* EXTREME_DEBUG */
if (list_isempty(spftree->tents)) {
listnode_add(spftree->tents, vertex);
return vertex;
}
/* XXX: This cant use the standard ALL_LIST_ELEMENTS macro */
for (node = listhead(spftree->tents); node; node = listnextnode(node)) {
v = listgetdata(node);
if (tent_cmp(v, vertex)) {
listnode_add_before(spftree->tents, node, vertex);
break;
}
}
if (node == NULL)
listnode_add(spftree->tents, vertex);
return vertex;
}
static void isis_spf_add_local(struct isis_spftree *spftree,
enum vertextype vtype, void *id,
struct isis_adjacency *adj, uint32_t cost,
struct isis_vertex *parent)
{
struct isis_vertex *vertex;
vertex = isis_find_vertex(spftree->tents, id, vtype);
if (vertex) {
/* C.2.5 c) */
if (vertex->d_N == cost) {
if (adj)
listnode_add(vertex->Adj_N, adj);
/* d) */
if (listcount(vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
remove_excess_adjs(vertex->Adj_N);
if (parent && (listnode_lookup(vertex->parents, parent)
== NULL))
listnode_add(vertex->parents, parent);
if (parent && (listnode_lookup(parent->children, vertex)
== NULL))
listnode_add(parent->children, vertex);
return;
} else if (vertex->d_N < cost) {
/* e) do nothing */
return;
} else { /* vertex->d_N > cost */
/* f) */
struct listnode *pnode, *pnextnode;
struct isis_vertex *pvertex;
listnode_delete(spftree->tents, vertex);
assert(listcount(vertex->children) == 0);
for (ALL_LIST_ELEMENTS(vertex->parents, pnode,
pnextnode, pvertex))
listnode_delete(pvertex->children, vertex);
isis_vertex_del(vertex);
}
}
isis_spf_add2tent(spftree, vtype, id, cost, 1, adj, parent);
return;
}
static void process_N(struct isis_spftree *spftree, enum vertextype vtype,
void *id, uint32_t dist, uint16_t depth,
struct isis_vertex *parent)
{
struct isis_vertex *vertex;
#ifdef EXTREME_DEBUG
char buff[PREFIX2STR_BUFFER];
#endif
assert(spftree && parent);
/* RFC3787 section 5.1 */
if (spftree->area->newmetric == 1) {
if (dist > MAX_WIDE_PATH_METRIC)
return;
}
/* C.2.6 b) */
else if (spftree->area->oldmetric == 1) {
if (dist > MAX_NARROW_PATH_METRIC)
return;
}
/* c) */
vertex = isis_find_vertex(spftree->paths, id, vtype);
if (vertex) {
#ifdef EXTREME_DEBUG
zlog_debug(
"ISIS-Spf: process_N %s %s %s dist %d already found from PATH",
print_sys_hostname(vertex->N.id), vtype2string(vtype),
vid2string(vertex, buff, sizeof(buff)), dist);
#endif /* EXTREME_DEBUG */
assert(dist >= vertex->d_N);
return;
}
vertex = isis_find_vertex(spftree->tents, id, vtype);
/* d) */
if (vertex) {
/* 1) */
#ifdef EXTREME_DEBUG
zlog_debug(
"ISIS-Spf: process_N %s %s %s dist %d parent %s adjcount %d",
print_sys_hostname(vertex->N.id), vtype2string(vtype),
vid2string(vertex, buff, sizeof(buff)), dist,
(parent ? print_sys_hostname(parent->N.id) : "null"),
(parent ? listcount(parent->Adj_N) : 0));
#endif /* EXTREME_DEBUG */
if (vertex->d_N == dist) {
struct listnode *node;
struct isis_adjacency *parent_adj;
for (ALL_LIST_ELEMENTS_RO(parent->Adj_N, node,
parent_adj))
if (listnode_lookup(vertex->Adj_N, parent_adj)
== NULL)
listnode_add(vertex->Adj_N, parent_adj);
/* 2) */
if (listcount(vertex->Adj_N) > ISIS_MAX_PATH_SPLITS)
remove_excess_adjs(vertex->Adj_N);
if (listnode_lookup(vertex->parents, parent) == NULL)
listnode_add(vertex->parents, parent);
if (listnode_lookup(parent->children, vertex) == NULL)
listnode_add(parent->children, vertex);
/* 3) */
return;
} else if (vertex->d_N < dist) {
return;
/* 4) */
} else {
struct listnode *pnode, *pnextnode;
struct isis_vertex *pvertex;
listnode_delete(spftree->tents, vertex);
assert(listcount(vertex->children) == 0);
for (ALL_LIST_ELEMENTS(vertex->parents, pnode,
pnextnode, pvertex))
listnode_delete(pvertex->children, vertex);
isis_vertex_del(vertex);
}
}
#ifdef EXTREME_DEBUG
zlog_debug("ISIS-Spf: process_N add2tent %s %s dist %d parent %s",
print_sys_hostname(id), vtype2string(vtype), dist,
(parent ? print_sys_hostname(parent->N.id) : "null"));
#endif /* EXTREME_DEBUG */
isis_spf_add2tent(spftree, vtype, id, dist, depth, NULL, parent);
return;
}
/*
* C.2.6 Step 1
*/
static int isis_spf_process_lsp(struct isis_spftree *spftree,
struct isis_lsp *lsp, uint32_t cost,
uint16_t depth, u_char *root_sysid,
struct isis_vertex *parent)
{
bool pseudo_lsp = LSP_PSEUDO_ID(lsp->lsp_header->lsp_id);
struct listnode *node, *fragnode = NULL;
uint32_t dist;
struct is_neigh *is_neigh;
struct te_is_neigh *te_is_neigh;
struct ipv4_reachability *ipreach;
struct te_ipv4_reachability *te_ipv4_reach;
enum vertextype vtype;
struct prefix prefix;
struct ipv6_reachability *ip6reach;
static const u_char null_sysid[ISIS_SYS_ID_LEN];
struct mt_router_info *mt_router_info = NULL;
if (spftree->mtid != ISIS_MT_IPV4_UNICAST)
mt_router_info = tlvs_lookup_mt_router_info(&lsp->tlv_data,
spftree->mtid);
if (!pseudo_lsp && (spftree->mtid == ISIS_MT_IPV4_UNICAST
&& !speaks(lsp->tlv_data.nlpids, spftree->family))
&& !mt_router_info)
return ISIS_OK;
lspfragloop:
if (lsp->lsp_header->seq_num == 0) {
zlog_warn(
"isis_spf_process_lsp(): lsp with 0 seq_num - ignore");
return ISIS_WARNING;
}
#ifdef EXTREME_DEBUG
zlog_debug("ISIS-Spf: process_lsp %s",
print_sys_hostname(lsp->lsp_header->lsp_id));
#endif /* EXTREME_DEBUG */
/* RFC3787 section 4 SHOULD ignore overload bit in pseudo LSPs */
if (pseudo_lsp || (spftree->mtid == ISIS_MT_IPV4_UNICAST
&& !ISIS_MASK_LSP_OL_BIT(lsp->lsp_header->lsp_bits))
|| (mt_router_info && !mt_router_info->overload))
{
if (pseudo_lsp || spftree->mtid == ISIS_MT_IPV4_UNICAST) {
for (ALL_LIST_ELEMENTS_RO(lsp->tlv_data.is_neighs, node,
is_neigh)) {
/* C.2.6 a) */
/* Two way connectivity */
if (!memcmp(is_neigh->neigh_id, root_sysid,
ISIS_SYS_ID_LEN))
continue;
if (!pseudo_lsp
&& !memcmp(is_neigh->neigh_id, null_sysid,
ISIS_SYS_ID_LEN))
continue;
dist = cost + is_neigh->metrics.metric_default;
process_N(spftree,
LSP_PSEUDO_ID(is_neigh->neigh_id)
? VTYPE_PSEUDO_IS
: VTYPE_NONPSEUDO_IS,
(void *)is_neigh->neigh_id, dist,
depth + 1, parent);
}
}
struct list *te_is_neighs = NULL;
if (pseudo_lsp || spftree->mtid == ISIS_MT_IPV4_UNICAST) {
te_is_neighs = lsp->tlv_data.te_is_neighs;
} else {
struct tlv_mt_neighbors *mt_neighbors;
mt_neighbors = tlvs_lookup_mt_neighbors(&lsp->tlv_data,
spftree->mtid);
if (mt_neighbors)
te_is_neighs = mt_neighbors->list;
}
for (ALL_LIST_ELEMENTS_RO(te_is_neighs, node, te_is_neigh)) {
if (!memcmp(te_is_neigh->neigh_id, root_sysid,
ISIS_SYS_ID_LEN))
continue;
if (!pseudo_lsp
&& !memcmp(te_is_neigh->neigh_id, null_sysid,
ISIS_SYS_ID_LEN))
continue;
dist = cost + GET_TE_METRIC(te_is_neigh);
process_N(spftree,
LSP_PSEUDO_ID(te_is_neigh->neigh_id)
? VTYPE_PSEUDO_TE_IS
: VTYPE_NONPSEUDO_TE_IS,
(void *)te_is_neigh->neigh_id, dist,
depth + 1, parent);
}
}
if (!pseudo_lsp && spftree->family == AF_INET
&& spftree->mtid == ISIS_MT_IPV4_UNICAST) {
struct list *reachs[] = {lsp->tlv_data.ipv4_int_reachs,
lsp->tlv_data.ipv4_ext_reachs};
prefix.family = AF_INET;
for (unsigned int i = 0; i < array_size(reachs); i++) {
vtype = (reachs[i] == lsp->tlv_data.ipv4_int_reachs)
? VTYPE_IPREACH_INTERNAL
: VTYPE_IPREACH_EXTERNAL;
for (ALL_LIST_ELEMENTS_RO(reachs[i], node, ipreach)) {
dist = cost + ipreach->metrics.metric_default;
prefix.u.prefix4 = ipreach->prefix;
prefix.prefixlen = ip_masklen(ipreach->mask);
apply_mask(&prefix);
process_N(spftree, vtype, (void *)&prefix, dist,
depth + 1, parent);
}
}
}
if (!pseudo_lsp && spftree->family == AF_INET) {
struct list *ipv4reachs = NULL;
if (spftree->mtid == ISIS_MT_IPV4_UNICAST) {
ipv4reachs = lsp->tlv_data.te_ipv4_reachs;
} else {
struct tlv_mt_ipv4_reachs *mt_reachs;
mt_reachs = tlvs_lookup_mt_ipv4_reachs(&lsp->tlv_data,
spftree->mtid);
if (mt_reachs)
ipv4reachs = mt_reachs->list;
}
prefix.family = AF_INET;
for (ALL_LIST_ELEMENTS_RO(ipv4reachs, node, te_ipv4_reach)) {
assert((te_ipv4_reach->control & 0x3F)
<= IPV4_MAX_BITLEN);
dist = cost + ntohl(te_ipv4_reach->te_metric);
prefix.u.prefix4 =
newprefix2inaddr(&te_ipv4_reach->prefix_start,
te_ipv4_reach->control);
prefix.prefixlen = (te_ipv4_reach->control & 0x3F);
apply_mask(&prefix);
process_N(spftree, VTYPE_IPREACH_TE, (void *)&prefix,
dist, depth + 1, parent);
}
}
if (!pseudo_lsp && spftree->family == AF_INET6) {
struct list *ipv6reachs = NULL;
if (spftree->mtid == ISIS_MT_IPV4_UNICAST) {
ipv6reachs = lsp->tlv_data.ipv6_reachs;
} else {
struct tlv_mt_ipv6_reachs *mt_reachs;
mt_reachs = tlvs_lookup_mt_ipv6_reachs(&lsp->tlv_data,
spftree->mtid);
if (mt_reachs)
ipv6reachs = mt_reachs->list;
}
prefix.family = AF_INET6;
for (ALL_LIST_ELEMENTS_RO(ipv6reachs, node, ip6reach)) {
assert(ip6reach->prefix_len <= IPV6_MAX_BITLEN);
dist = cost + ntohl(ip6reach->metric);
vtype = (ip6reach->control_info
& CTRL_INFO_DISTRIBUTION)
? VTYPE_IP6REACH_EXTERNAL
: VTYPE_IP6REACH_INTERNAL;
prefix.prefixlen = ip6reach->prefix_len;
memcpy(&prefix.u.prefix6.s6_addr, ip6reach->prefix,
PSIZE(ip6reach->prefix_len));
apply_mask(&prefix);
process_N(spftree, vtype, (void *)&prefix, dist,
depth + 1, parent);
}
}
if (fragnode == NULL)
fragnode = listhead(lsp->lspu.frags);
else
fragnode = listnextnode(fragnode);
if (fragnode) {
lsp = listgetdata(fragnode);
goto lspfragloop;
}
return ISIS_OK;
}
static int isis_spf_preload_tent(struct isis_spftree *spftree,
u_char *root_sysid, struct isis_vertex *parent)
{
struct isis_circuit *circuit;
struct listnode *cnode, *anode, *ipnode;
struct isis_adjacency *adj;
struct isis_lsp *lsp;
struct list *adj_list;
struct list *adjdb;
struct prefix_ipv4 *ipv4;
struct prefix prefix;
int retval = ISIS_OK;
u_char lsp_id[ISIS_SYS_ID_LEN + 2];
static u_char null_lsp_id[ISIS_SYS_ID_LEN + 2];
struct prefix_ipv6 *ipv6;
struct isis_circuit_mt_setting *circuit_mt;
for (ALL_LIST_ELEMENTS_RO(spftree->area->circuit_list, cnode,
circuit)) {
circuit_mt = circuit_lookup_mt_setting(circuit, spftree->mtid);
if (circuit_mt && !circuit_mt->enabled)
continue;
if (circuit->state != C_STATE_UP)
continue;
if (!(circuit->is_type & spftree->level))
continue;
if (spftree->family == AF_INET && !circuit->ip_router)
continue;
if (spftree->family == AF_INET6 && !circuit->ipv6_router)
continue;
/*
* Add IP(v6) addresses of this circuit
*/
if (spftree->family == AF_INET) {
prefix.family = AF_INET;
for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, ipnode,
ipv4)) {
prefix.u.prefix4 = ipv4->prefix;
prefix.prefixlen = ipv4->prefixlen;
apply_mask(&prefix);
isis_spf_add_local(spftree,
VTYPE_IPREACH_INTERNAL,
&prefix, NULL, 0, parent);
}
}
if (spftree->family == AF_INET6) {
prefix.family = AF_INET6;
for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link,
ipnode, ipv6)) {
prefix.prefixlen = ipv6->prefixlen;
prefix.u.prefix6 = ipv6->prefix;
apply_mask(&prefix);
isis_spf_add_local(spftree,
VTYPE_IP6REACH_INTERNAL,
&prefix, NULL, 0, parent);
}
}
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
/*
* Add the adjacencies
*/
adj_list = list_new();
adjdb = circuit->u.bc.adjdb[spftree->level - 1];
isis_adj_build_up_list(adjdb, adj_list);
if (listcount(adj_list) == 0) {
list_delete(adj_list);
if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-Spf: no L%d adjacencies on circuit %s",
spftree->level,
circuit->interface->name);
continue;
}
for (ALL_LIST_ELEMENTS_RO(adj_list, anode, adj)) {
if (!adj_has_mt(adj, spftree->mtid))
continue;
if (spftree->mtid == ISIS_MT_IPV4_UNICAST
&& !speaks(&adj->nlpids, spftree->family))
continue;
switch (adj->sys_type) {
case ISIS_SYSTYPE_ES:
memcpy(lsp_id, adj->sysid,
ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(lsp_id) = 0;
isis_spf_add_local(
spftree, VTYPE_ES, lsp_id, adj,
circuit->te_metric
[spftree->level - 1],
parent);
break;
case ISIS_SYSTYPE_IS:
case ISIS_SYSTYPE_L1_IS:
case ISIS_SYSTYPE_L2_IS:
memcpy(lsp_id, adj->sysid,
ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(lsp_id) = 0;
LSP_FRAGMENT(lsp_id) = 0;
isis_spf_add_local(
spftree,
spftree->area->oldmetric
? VTYPE_NONPSEUDO_IS
: VTYPE_NONPSEUDO_TE_IS,
lsp_id, adj,
circuit->te_metric
[spftree->level - 1],
parent);
lsp = lsp_search(
lsp_id,
spftree->area
->lspdb[spftree->level
- 1]);
if (lsp == NULL
|| lsp->lsp_header->rem_lifetime
== 0)
zlog_warn(
"ISIS-Spf: No LSP %s found for IS adjacency "
"L%d on %s (ID %u)",
rawlspid_print(lsp_id),
spftree->level,
circuit->interface->name,
circuit->circuit_id);
break;
case ISIS_SYSTYPE_UNKNOWN:
default:
zlog_warn(
"isis_spf_preload_tent unknow adj type");
}
}
list_delete(adj_list);
/*
* Add the pseudonode
*/
if (spftree->level == 1)
memcpy(lsp_id, circuit->u.bc.l1_desig_is,
ISIS_SYS_ID_LEN + 1);
else
memcpy(lsp_id, circuit->u.bc.l2_desig_is,
ISIS_SYS_ID_LEN + 1);
/* can happen during DR reboot */
if (memcmp(lsp_id, null_lsp_id, ISIS_SYS_ID_LEN + 1)
== 0) {
if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-Spf: No L%d DR on %s (ID %d)",
spftree->level,
circuit->interface->name,
circuit->circuit_id);
continue;
}
adj = isis_adj_lookup(lsp_id, adjdb);
/* if no adj, we are the dis or error */
if (!adj && !circuit->u.bc.is_dr[spftree->level - 1]) {
zlog_warn(
"ISIS-Spf: No adjacency found from root "
"to L%d DR %s on %s (ID %d)",
spftree->level, rawlspid_print(lsp_id),
circuit->interface->name,
circuit->circuit_id);
continue;
}
lsp = lsp_search(
lsp_id,
spftree->area->lspdb[spftree->level - 1]);
if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0) {
zlog_warn(
"ISIS-Spf: No lsp (%p) found from root "
"to L%d DR %s on %s (ID %d)",
(void *)lsp, spftree->level,
rawlspid_print(lsp_id),
circuit->interface->name,
circuit->circuit_id);
continue;
}
isis_spf_process_lsp(
spftree, lsp,
circuit->te_metric[spftree->level - 1], 0,
root_sysid, parent);
} else if (circuit->circ_type == CIRCUIT_T_P2P) {
adj = circuit->u.p2p.neighbor;
if (!adj)
continue;
if (!adj_has_mt(adj, spftree->mtid))
continue;
switch (adj->sys_type) {
case ISIS_SYSTYPE_ES:
memcpy(lsp_id, adj->sysid, ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(lsp_id) = 0;
isis_spf_add_local(
spftree, VTYPE_ES, lsp_id, adj,
circuit->te_metric[spftree->level - 1],
parent);
break;
case ISIS_SYSTYPE_IS:
case ISIS_SYSTYPE_L1_IS:
case ISIS_SYSTYPE_L2_IS:
memcpy(lsp_id, adj->sysid, ISIS_SYS_ID_LEN);
LSP_PSEUDO_ID(lsp_id) = 0;
LSP_FRAGMENT(lsp_id) = 0;
if (spftree->mtid != ISIS_MT_IPV4_UNICAST
|| speaks(&adj->nlpids, spftree->family))
isis_spf_add_local(
spftree,
spftree->area->oldmetric
? VTYPE_NONPSEUDO_IS
: VTYPE_NONPSEUDO_TE_IS,
lsp_id, adj,
circuit->te_metric
[spftree->level - 1],
parent);
break;
case ISIS_SYSTYPE_UNKNOWN:
default:
zlog_warn(
"isis_spf_preload_tent unknown adj type");
break;
}
} else if (circuit->circ_type == CIRCUIT_T_LOOPBACK) {
continue;
} else {
zlog_warn("isis_spf_preload_tent unsupported media");
retval = ISIS_WARNING;
}
}
return retval;
}
/*
* The parent(s) for vertex is set when added to TENT list
* now we just put the child pointer(s) in place
*/
static void add_to_paths(struct isis_spftree *spftree,
struct isis_vertex *vertex)
{
char buff[PREFIX2STR_BUFFER];
if (isis_find_vertex(spftree->paths, vertex->N.id, vertex->type))
return;
listnode_add(spftree->paths, vertex);
#ifdef EXTREME_DEBUG
zlog_debug("ISIS-Spf: added %s %s %s depth %d dist %d to PATHS",
print_sys_hostname(vertex->N.id), vtype2string(vertex->type),
vid2string(vertex, buff, sizeof(buff)), vertex->depth,
vertex->d_N);
#endif /* EXTREME_DEBUG */
if (VTYPE_IP(vertex->type)) {
if (listcount(vertex->Adj_N) > 0)
isis_route_create((struct prefix *)&vertex->N.prefix,
vertex->d_N, vertex->depth,
vertex->Adj_N, spftree->area,
spftree->level);
else if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-Spf: no adjacencies do not install route for "
"%s depth %d dist %d",
vid2string(vertex, buff, sizeof(buff)),
vertex->depth, vertex->d_N);
}
return;
}
static void init_spt(struct isis_spftree *spftree, int mtid, int level,
int family)
{
spftree->tents->del = spftree->paths->del =
(void (*)(void *))isis_vertex_del;
list_delete_all_node(spftree->tents);
list_delete_all_node(spftree->paths);
spftree->tents->del = spftree->paths->del = NULL;
spftree->mtid = mtid;
spftree->level = level;
spftree->family = family;
return;
}
static int isis_run_spf(struct isis_area *area, int level, int family,
u_char *sysid)
{
int retval = ISIS_OK;
struct listnode *node;
struct isis_vertex *vertex;
struct isis_vertex *root_vertex;
struct isis_spftree *spftree = NULL;
u_char lsp_id[ISIS_SYS_ID_LEN + 2];
struct isis_lsp *lsp;
struct route_table *table = NULL;
struct timeval time_now;
unsigned long long start_time, end_time;
uint16_t mtid;
/* Get time that can't roll backwards. */
monotime(&time_now);
start_time = time_now.tv_sec;
start_time = (start_time * 1000000) + time_now.tv_usec;
if (family == AF_INET)
spftree = area->spftree[level - 1];
else if (family == AF_INET6)
spftree = area->spftree6[level - 1];
assert(spftree);
assert(sysid);
/* Make all routes in current route table inactive. */
if (family == AF_INET)
table = area->route_table[level - 1];
else if (family == AF_INET6)
table = area->route_table6[level - 1];
isis_route_invalidate_table(area, table);
/* We only support ipv4-unicast and ipv6-unicast as topologies for now
*/
if (family == AF_INET6)
mtid = isis_area_ipv6_topology(area);
else
mtid = ISIS_MT_IPV4_UNICAST;
/*
* C.2.5 Step 0
*/
init_spt(spftree, mtid, level, family);
/* a) */
root_vertex = isis_spf_add_root(spftree, sysid);
/* b) */
retval = isis_spf_preload_tent(spftree, sysid, root_vertex);
if (retval != ISIS_OK) {
zlog_warn("ISIS-Spf: failed to load TENT SPF-root:%s",
print_sys_hostname(sysid));
goto out;
}
/*
* C.2.7 Step 2
*/
if (listcount(spftree->tents) == 0) {
zlog_warn("ISIS-Spf: TENT is empty SPF-root:%s",
print_sys_hostname(sysid));
goto out;
}
while (listcount(spftree->tents) > 0) {
node = listhead(spftree->tents);
vertex = listgetdata(node);
#ifdef EXTREME_DEBUG
zlog_debug(
"ISIS-Spf: get TENT node %s %s depth %d dist %d to PATHS",
print_sys_hostname(vertex->N.id),
vtype2string(vertex->type), vertex->depth, vertex->d_N);
#endif /* EXTREME_DEBUG */
/* Remove from tent list and add to paths list */
list_delete_node(spftree->tents, node);
add_to_paths(spftree, vertex);
if (VTYPE_IS(vertex->type)) {
memcpy(lsp_id, vertex->N.id, ISIS_SYS_ID_LEN + 1);
LSP_FRAGMENT(lsp_id) = 0;
lsp = lsp_search(lsp_id, area->lspdb[level - 1]);
if (lsp && lsp->lsp_header->rem_lifetime != 0) {
isis_spf_process_lsp(spftree, lsp, vertex->d_N,
vertex->depth, sysid,
vertex);
} else {
zlog_warn("ISIS-Spf: No LSP found for %s",
rawlspid_print(lsp_id));
}
}
}
out:
isis_route_validate(area);
spftree->runcount++;
spftree->last_run_timestamp = time(NULL);
monotime(&time_now);
end_time = time_now.tv_sec;
end_time = (end_time * 1000000) + time_now.tv_usec;
spftree->last_run_duration = end_time - start_time;
return retval;
}
static int isis_run_spf_cb(struct thread *thread)
{
struct isis_spf_run *run = THREAD_ARG(thread);
struct isis_area *area = run->area;
int level = run->level;
int retval = ISIS_OK;
XFREE(MTYPE_ISIS_SPF_RUN, run);
area->spf_timer[level - 1] = NULL;
if (!(area->is_type & level)) {
if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_warn("ISIS-SPF (%s) area does not share level",
area->area_tag);
return ISIS_WARNING;
}
if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_debug("ISIS-Spf (%s) L%d SPF needed, periodic SPF",
area->area_tag, level);
if (area->ip_circuits)
retval = isis_run_spf(area, level, AF_INET, isis->sysid);
if (area->ipv6_circuits)
retval = isis_run_spf(area, level, AF_INET6, isis->sysid);
return retval;
}
static struct isis_spf_run *isis_run_spf_arg(struct isis_area *area, int level)
{
struct isis_spf_run *run = XMALLOC(MTYPE_ISIS_SPF_RUN, sizeof(*run));
run->area = area;
run->level = level;
return run;
}
int isis_spf_schedule(struct isis_area *area, int level)
{
struct isis_spftree *spftree = area->spftree[level - 1];
time_t now = time(NULL);
int diff = now - spftree->last_run_timestamp;
assert(diff >= 0);
assert(area->is_type & level);
if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_debug(
"ISIS-Spf (%s) L%d SPF schedule called, lastrun %d sec ago",
area->area_tag, level, diff);
if (area->spf_delay_ietf[level - 1]) {
/* Need to call schedule function also if spf delay is running
* to
* restart holdoff timer - compare
* draft-ietf-rtgwg-backoff-algo-04 */
long delay =
spf_backoff_schedule(area->spf_delay_ietf[level - 1]);
if (area->spf_timer[level - 1])
return ISIS_OK;
thread_add_timer_msec(master, isis_run_spf_cb,
isis_run_spf_arg(area, level), delay,
&area->spf_timer[level - 1]);
return ISIS_OK;
}
if (area->spf_timer[level - 1])
return ISIS_OK;
/* wait configured min_spf_interval before doing the SPF */
if (diff >= area->min_spf_interval[level - 1]) {
int retval = ISIS_OK;
if (area->ip_circuits)
retval =
isis_run_spf(area, level, AF_INET, isis->sysid);
if (area->ipv6_circuits)
retval = isis_run_spf(area, level, AF_INET6,
isis->sysid);
return retval;
}
thread_add_timer(master, isis_run_spf_cb, isis_run_spf_arg(area, level),
area->min_spf_interval[level - 1] - diff,
&area->spf_timer[level - 1]);
if (isis->debugs & DEBUG_SPF_EVENTS)
zlog_debug("ISIS-Spf (%s) L%d SPF scheduled %d sec from now",
area->area_tag, level,
area->min_spf_interval[level - 1] - diff);
return ISIS_OK;
}
static void isis_print_paths(struct vty *vty, struct list *paths,
u_char *root_sysid)
{
struct listnode *node;
struct listnode *anode;
struct isis_vertex *vertex;
struct isis_adjacency *adj;
char buff[PREFIX2STR_BUFFER];
vty_out(vty,
"Vertex Type Metric Next-Hop Interface Parent\n");
for (ALL_LIST_ELEMENTS_RO(paths, node, vertex)) {
if (memcmp(vertex->N.id, root_sysid, ISIS_SYS_ID_LEN) == 0) {
vty_out(vty, "%-20s %-12s %-6s",
print_sys_hostname(root_sysid), "", "");
vty_out(vty, "%-30s", "");
} else {
int rows = 0;
vty_out(vty, "%-20s %-12s %-6u ",
vid2string(vertex, buff, sizeof(buff)),
vtype2string(vertex->type), vertex->d_N);
for (ALL_LIST_ELEMENTS_RO(vertex->Adj_N, anode, adj)) {
if (adj) {
if (rows) {
vty_out(vty, "\n");
vty_out(vty,
"%-20s %-12s %-6s ", "",
"", "");
}
vty_out(vty, "%-20s %-9s ",
print_sys_hostname(adj->sysid),
adj->circuit->interface->name);
++rows;
}
}
if (rows == 0)
vty_out(vty, "%-30s ", "");
}
/* Print list of parents for the ECMP DAG */
if (listcount(vertex->parents) > 0) {
struct listnode *pnode;
struct isis_vertex *pvertex;
int rows = 0;
for (ALL_LIST_ELEMENTS_RO(vertex->parents, pnode,
pvertex)) {
if (rows) {
vty_out(vty, "\n");
vty_out(vty, "%-72s", "");
}
vty_out(vty, "%s(%d)",
vid2string(pvertex, buff, sizeof(buff)),
pvertex->type);
++rows;
}
} else {
vty_out(vty, " NULL ");
}
vty_out(vty, "\n");
}
}
DEFUN (show_isis_topology,
show_isis_topology_cmd,
"show isis topology [<level-1|level-2>]",
SHOW_STR
"IS-IS information\n"
"IS-IS paths to Intermediate Systems\n"
"Paths to all level-1 routers in the area\n"
"Paths to all level-2 routers in the domain\n")
{
int levels;
struct listnode *node;
struct isis_area *area;
if (argc < 4)
levels = ISIS_LEVEL1 | ISIS_LEVEL2;
else if (strmatch(argv[3]->text, "level-1"))
levels = ISIS_LEVEL1;
else
levels = ISIS_LEVEL2;
if (!isis->area_list || isis->area_list->count == 0)
return CMD_SUCCESS;
for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
vty_out(vty, "Area %s:\n",
area->area_tag ? area->area_tag : "null");
for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS; level++) {
if ((level & levels) == 0)
continue;
if (area->ip_circuits > 0 && area->spftree[level - 1]
&& area->spftree[level - 1]->paths->count > 0) {
vty_out(vty,
"IS-IS paths to level-%d routers that speak IP\n",
level);
isis_print_paths(
vty, area->spftree[level - 1]->paths,
isis->sysid);
vty_out(vty, "\n");
}
if (area->ipv6_circuits > 0 && area->spftree6[level - 1]
&& area->spftree6[level - 1]->paths->count > 0) {
vty_out(vty,
"IS-IS paths to level-%d routers that speak IPv6\n",
level);
isis_print_paths(
vty, area->spftree6[level - 1]->paths,
isis->sysid);
vty_out(vty, "\n");
}
}
vty_out(vty, "\n");
}
return CMD_SUCCESS;
}
void isis_spf_cmds_init()
{
install_element(VIEW_NODE, &show_isis_topology_cmd);
}
|