-
Notifications
You must be signed in to change notification settings - Fork 5
/
spfclihandler.c
1324 lines (1124 loc) · 44.7 KB
/
spfclihandler.c
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
/*
* =====================================================================================
*
* Filename: spfclihandler.c
*
* Description: This file defines the routines to handle show/debug/config/clear etc commands
*
* Version: 1.0
* Created: Sunday 03 September 2017 10:46:52 IST
* Revision: 1.0
* Compiler: gcc
*
* Author: Er. Abhishek Sagar, Networking Developer (AS), [email protected]
* Company: Brocade Communications(Jul 2012- Mar 2016), Current : Juniper Networks(Apr 2017 - Present)
*
* This file is part of the SPFComputation distribution (https://github.com/sachinites).
* Copyright (c) 2017 Abhishek Sagar.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*
* =====================================================================================
*/
#include <stdio.h>
#include "spfclihandler.h"
#include "cmdtlv.h"
#include "routes.h"
#include "bitsop.h"
#include "spfutil.h"
#include "spfcmdcodes.h"
#include "advert.h"
#include "rlfa.h"
#include "spftrace.h"
#include "sr_tlv_api.h"
#include "igp_sr_ext.h"
#include "common.h"
#include "no_warn.h"
#include "complete_spf_path.h"
#include "spring_adjsid.h"
#include "LinuxMemoryManager/uapi_mm.h"
extern instance_t * instance;
extern void
mpls_0_display(rt_un_table_t *rib, mpls_label_t in_label);
extern void
show_mpls_ldp_label_local_bindings(node_t *node);
extern void
show_mpls_rsvp_label_local_bindings(node_t *node);
extern void
transient_mpls_pfe_engine(node_t *node, mpls_label_stack_t *mpls_label_stack,
node_t **next_node);
extern glthread_t *
tilfa_get_post_convergence_spf_path_head(
tilfa_info_t *tilfa_info, LEVEL level);
extern boolean
tilfa_update_config(node_t *plr_node,
char *protected_link,
boolean link_protection,
boolean node_protection);
static void
_run_spf_run_all_nodes(){
LEVEL level_it;
singly_ll_node_t *list_node = NULL;
node_t *node = NULL;;
/*Ist run LEVEL2 spf run on all nodes, so that L1L2 routers would set multi_area bit appropriately*/
for(level_it = LEVEL2; level_it >= LEVEL1; level_it--){
ITERATE_LIST_BEGIN(instance->instance_node_list, list_node){
node = list_node->data;
if(node->node_type[level_it] == PSEUDONODE)
continue;
spf_computation(node, &node->spf_info, level_it, FULL_RUN, 0);
} ITERATE_LIST_END;
}
}
static void
_reconstruct_all_rsvp_tunnels(){
node_t *node = NULL;
singly_ll_node_t *list_node = NULL;
rsvp_tunnel_t *rsvp_tunnel = NULL;
glthread_t *curr = NULL;
rsvp_tunnel_t rsvp_tunnel_data;
int rc = 0;
ITERATE_LIST_BEGIN(instance->instance_node_list, list_node){
node = list_node->data;
ITERATE_GLTHREAD_BEGIN(&node->rsvp_config.lspdb, curr){
rsvp_tunnel = glthread_to_rsvp_tunnel(curr);
rc = create_targeted_rsvp_tunnel(node, rsvp_tunnel->egress_lsr->router_id,
0, 0, 0, &rsvp_tunnel_data);
if(!rc)
memcpy(rsvp_tunnel, &rsvp_tunnel_data, sizeof(rsvp_tunnel_t));
} ITERATE_GLTHREAD_END(&node->rsvp_config.lspdb, curr);
} ITERATE_LIST_END;
}
int
run_spf_run_all_nodes(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
_run_spf_run_all_nodes();
/*now reconstruct all RSVP tunnels*/
//_reconstruct_all_rsvp_tunnels();
return 0;
}
void
spf_node_slot_enable_disable(node_t *node, char *slot_name,
op_mode enable_or_disable){
unsigned int i = 0;
edge_end_t *edge_end = NULL;
edge_t *edge = NULL;
char found = 0;
LEVEL level_it;
for(; i < MAX_NODE_INTF_SLOTS; i++){
edge_end = node->edges[i];
if(!edge_end){
return;
}
if(edge_end->dirn == INCOMING) continue;
if(strncmp(edge_end->intf_name, slot_name, strlen(edge_end->intf_name)) == 0 &&
strlen(edge_end->intf_name) == strlen(slot_name)){
edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
edge->status = (enable_or_disable == CONFIG_DISABLE) ? 0 : 1;
if(edge->status == 0){
/*remove the edge_end prefixes from node*/
dettach_edge_end_prefix_on_node(edge->from.node, &edge->from);
}
else{
/*Attach the edge end prefix to node.*/
attach_edge_end_prefix_on_node(edge->from.node, &edge->from);
}
found = 1;
break;
}
}
if(!found){
printf("%s() : INFO : Node : %s, slot %s not found\n", __FUNCTION__, node->node_name, slot_name);
return;
}
dist_info_hdr_t dist_info_hdr;
node_t *nbr_node = edge->to.node;
unsigned int old_nbr_node_spf_version = 0;
/*Run spf manually when interface state is changed by admin*/
#if 0
for(level_it = LEVEL1; level_it < MAX_LEVEL; level_it++){
if(!IS_LEVEL_SET(edge->level, level_it))
continue;
memset(&dist_info_hdr, 0, sizeof(dist_info_hdr_t));
dist_info_hdr.info_dist_level = level_it;
dist_info_hdr.advert_id = TLV2;
old_nbr_node_spf_version = nbr_node->spf_info.spf_level_info[level_it].version;
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
if(old_nbr_node_spf_version < nbr_node->spf_info.spf_level_info[level_it].version)
continue;
memset(&dist_info_hdr, 0, sizeof(dist_info_hdr_t));
dist_info_hdr.info_dist_level = level_it;
dist_info_hdr.advert_id = TLV2;
generate_lsp(instance, nbr_node, lsp_distribution_routine, &dist_info_hdr);
}
#endif
}
static void
show_node_spring_details(node_t *node, LEVEL level){
if(!node->spring_enabled){
printf("Spring Disabled on this node\n");
return;
}
prefix_t *prefix = NULL;
singly_ll_node_t *list_node = NULL;
srgb_t *srgb = node->srgb;
printf("Node : %s SRGB Details:\n", node->node_name);
printf("\tRange : %u, starting mpls label = %u\n",
node->srgb->range, node->srgb->first_sid.sid);
unsigned int i = 0, in_use_count = 0,
avail_count = 0;
for(; i < srgb->range; i++){
if(is_bit_set(SRGB_INDEX_ARRAY(srgb), i))
in_use_count++;
else
avail_count++;
}
printf("\t# Mpls labels in Use : %u, Available : %u\n", in_use_count, avail_count);
printf("\tPrefix SID Database :\n");
ITERATE_LIST_BEGIN(node->local_prefix_list[level], list_node){
prefix = list_node->data;
diplay_prefix_sid(prefix);
} ITERATE_LIST_END;
}
void
spf_node_slot_metric_change(node_t *node, char *slot_name,
LEVEL level, unsigned int new_metric){
unsigned int i = 0;
edge_end_t *edge_end = NULL;
edge_t *edge = NULL;
boolean found = FALSE;
for(; i < MAX_NODE_INTF_SLOTS; i++){
edge_end = node->edges[i];
if(!edge_end){
return;
}
if(edge_end->dirn != OUTGOING)
continue;
if(!(strncmp(edge_end->intf_name, slot_name, strlen(edge_end->intf_name)) == 0 &&
strlen(edge_end->intf_name) == strlen(slot_name)))
continue;
found = TRUE;
edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
if(!IS_LEVEL_SET(edge->level, level))
continue;
if(edge->metric[level] == new_metric)
return;
edge->metric[level] = new_metric;
break;
}
if(found == FALSE){
printf("Error : node %s, Interface %s not found\n", node->node_name, edge_end->intf_name);
return;
}
dist_info_hdr_t dist_info_hdr;
memset(&dist_info_hdr, 0, sizeof(dist_info_hdr_t));
dist_info_hdr.info_dist_level = level;
dist_info_hdr.advert_id = TLV2;
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
}
void
display_instance_nodes(param_t *param, ser_buff_t *tlv_buf){
singly_ll_node_t *list_node = NULL;
node_t *node = NULL;
ITERATE_LIST_BEGIN(instance->instance_node_list, list_node){
node = (node_t *)list_node->data;
printf(" %s\n", node->node_name);
}ITERATE_LIST_END;
}
void
display_instance_node_interfaces(param_t *param, ser_buff_t *tlv_buf){
tlv_struct_t *tlv = NULL;
unsigned int i = 0;
char *node_name = NULL;
node_t *node = NULL;
edge_end_t *edge_end = NULL;
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
} TLV_LOOP_END;
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
if(!node)
return;
for(i = 0; i < MAX_NODE_INTF_SLOTS; i++){
edge_end = node->edges[i];
if(!edge_end)
break;
if(edge_end->dirn == INCOMING) continue;
printf(" %s %s\n", edge_end->intf_name, (edge_end->dirn == OUTGOING) ? "->" : "<-");
}
}
int
validate_ipv4_mask(char *mask){
int _mask = atoi(mask);
if(_mask >= 0 && _mask <= 32)
return VALIDATION_SUCCESS;
return VALIDATION_FAILED;
}
static void
dump_route_info(routes_t *route){
singly_ll_node_t *list_node = NULL;
prefix_t *prefix = NULL;
nh_type_t nh;
internal_nh_t *nxthop = NULL;
prefix_pref_data_t prefix_pref = {ROUTE_UNKNOWN_PREFERENCE,
"ROUTE_UNKNOWN_PREFERENCE"};
printf("Route : %s/%u, %s\n", route->rt_key.u.prefix.prefix, route->rt_key.u.prefix.mask, get_str_level(route->level));
printf("Version : %d, spf_metric = %u, lsp_metric = %u, ext_metric = %u\n",
route->version, route->spf_metric, route->lsp_metric, route->ext_metric);
printf("flags : up/down : %s , Route : %s, Metric type : %s\n",
IS_BIT_SET(route->flags, PREFIX_DOWNBIT_FLAG) ? "SET" : "NOT SET",
IS_BIT_SET(route->flags, PREFIX_EXTERNABIT_FLAG) ? "EXTERNAL" : "INTERNAL",
IS_BIT_SET(route->flags, PREFIX_METRIC_TYPE_EXT) ? "EXTERNAL" : "INTERNAL");
printf("hosting_node = %s\n", route->hosting_node->node_name);
printf("Like prefix list count : %u\n", GET_NODE_COUNT_SINGLY_LL(route->like_prefix_list));
ITERATE_LIST_BEGIN(route->like_prefix_list, list_node){
prefix = list_node->data;
prefix_pref = route_preference(prefix->prefix_flags, prefix->level);
printf("%s/%u, hosting_node : %s, prefix->metric : %u, prefix->level = %s, pfx preference = %s(%u)\n",
prefix->prefix, prefix->mask, prefix->hosting_node->node_name, prefix->metric,
get_str_level(prefix->level), prefix_pref.pref_str, prefix_pref.pref);
}ITERATE_LIST_END;
ITERATE_NH_TYPE_BEGIN(nh){
printf("%s Primary Nxt Hops count : %u\n",
nh == IPNH ? "IPNH" : "LSPNH", GET_NODE_COUNT_SINGLY_LL(route->primary_nh_list[nh]));
ITERATE_LIST_BEGIN(route->primary_nh_list[nh], list_node){
nxthop = (internal_nh_t *)list_node->data;
PRINT_ONE_LINER_NXT_HOP(nxthop);
}ITERATE_LIST_END;
} ITERATE_NH_TYPE_END;
ITERATE_NH_TYPE_BEGIN(nh){
printf("%s Backup Nxt Hops count : %u\n",
nh == IPNH ? "IPNH" : "LSPNH", GET_NODE_COUNT_SINGLY_LL(route->backup_nh_list[nh]));
ITERATE_LIST_BEGIN(route->backup_nh_list[nh], list_node){
nxthop = (internal_nh_t *)list_node->data;
PRINT_ONE_LINER_NXT_HOP(nxthop);
}ITERATE_LIST_END;
} ITERATE_NH_TYPE_END;
}
static void
dump_spring_route_info(routes_t *route){
singly_ll_node_t *list_node = NULL;
prefix_t *prefix = NULL;
nh_type_t nh;
internal_nh_t *nxthop = NULL;
prefix_pref_data_t prefix_pref = {ROUTE_UNKNOWN_PREFERENCE,
"ROUTE_UNKNOWN_PREFERENCE"};
printf("Route : %s/%u, Inlabel : %u, %s\n", route->rt_key.u.prefix.prefix, route->rt_key.u.prefix.mask,
route->rt_key.u.label, get_str_level(route->level));
printf("Version : %d, spf_metric = %u, lsp_metric = %u, ext_metric = %u\n",
route->version, route->spf_metric, route->lsp_metric, route->ext_metric);
printf("flags : up/down : %s , Route : %s, Metric type : %s\n",
IS_BIT_SET(route->flags, PREFIX_DOWNBIT_FLAG) ? "SET" : "NOT SET",
IS_BIT_SET(route->flags, PREFIX_EXTERNABIT_FLAG) ? "EXTERNAL" : "INTERNAL",
IS_BIT_SET(route->flags, PREFIX_METRIC_TYPE_EXT) ? "EXTERNAL" : "INTERNAL");
printf("hosting_node = %s\n", route->hosting_node->node_name);
printf("Like prefix list count : %u\n", GET_NODE_COUNT_SINGLY_LL(route->like_prefix_list));
ITERATE_LIST_BEGIN(route->like_prefix_list, list_node){
prefix = list_node->data;
prefix_pref = route_preference(prefix->prefix_flags, prefix->level);
printf("prefix SID : %u, %s/%u, hosting_node : %s, prefix->metric : %u, prefix->level = %s, pfx preference = %s(%u)\n",
PREFIX_SID_INDEX(prefix), prefix->prefix, prefix->mask, prefix->hosting_node->node_name, prefix->metric,
get_str_level(prefix->level), prefix_pref.pref_str, prefix_pref.pref);
}ITERATE_LIST_END;
ITERATE_NH_TYPE_BEGIN(nh){
printf("%s Primary Nxt Hops count : %u\n",
nh == IPNH ? "IPNH" : "LSPNH", GET_NODE_COUNT_SINGLY_LL(route->primary_nh_list[nh]));
ITERATE_LIST_BEGIN(route->primary_nh_list[nh], list_node){
nxthop = (internal_nh_t *)list_node->data;
PRINT_ONE_LINER_SPRING_NXT_HOP(nxthop);
}ITERATE_LIST_END;
} ITERATE_NH_TYPE_END;
ITERATE_NH_TYPE_BEGIN(nh){
printf("%s Backup Nxt Hops count : %u\n",
nh == IPNH ? "IPNH" : "LSPNH", GET_NODE_COUNT_SINGLY_LL(route->backup_nh_list[nh]));
ITERATE_LIST_BEGIN(route->backup_nh_list[nh], list_node){
nxthop = (internal_nh_t *)list_node->data;
PRINT_ONE_LINER_SPRING_NXT_HOP(nxthop);
}ITERATE_LIST_END;
} ITERATE_NH_TYPE_END;
}
int
show_route_tree_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
tlv_struct_t *tlv = NULL;
char *node_name = NULL;
node_t *node = NULL;
routes_t *route = NULL;
char *prefix = NULL;
char mask = 0;
singly_ll_node_t *list_node = NULL;
int cmd_code = -1;
char masked_prefix[PREFIX_LEN + 1];
cmd_code = EXTRACT_CMD_CODE(tlv_buf);
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "prefix", strlen("prefix")) ==0)
prefix = tlv->value;
else if(strncmp(tlv->leaf_id, "mask", strlen("mask")) ==0)
mask = atoi(tlv->value);
else
assert(0);
} TLV_LOOP_END;
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
switch(cmd_code){
case CMDCODE_DEBUG_INSTANCE_NODE_ALL_ROUTES:
ITERATE_LIST_BEGIN(node->spf_info.routes_list[UNICAST_T], list_node){
route = (routes_t *)list_node->data;
dump_route_info(route);
printf("\n");
}ITERATE_LIST_END;
break;
case CMDCODE_DEBUG_INSTANCE_NODE_ROUTE:
apply_mask(prefix, mask, masked_prefix);
masked_prefix[PREFIX_LEN] = '\0';
ITERATE_LIST_BEGIN(node->spf_info.routes_list[UNICAST_T], list_node){
route = (routes_t *)list_node->data;
if(strncmp(route->rt_key.u.prefix.prefix, masked_prefix, PREFIX_LEN) != 0)
continue;
dump_route_info(route);
break;
}ITERATE_LIST_END;
break;
case CMDCODE_DEBUG_INSTANCE_NODE_SPRING_ROUTE:
ITERATE_LIST_BEGIN(node->spf_info.routes_list[SPRING_T], list_node){
route = (routes_t *)list_node->data;
apply_mask(prefix, mask, masked_prefix);
if(strncmp(route->rt_key.u.prefix.prefix, masked_prefix, PREFIX_LEN) != 0)
continue;
dump_spring_route_info(route);
break;
}ITERATE_LIST_END;
break;
case CMDCODE_DEBUG_INSTANCE_NODE_ALL_SPRING_ROUTES:
ITERATE_LIST_BEGIN(node->spf_info.routes_list[SPRING_T], list_node){
route = (routes_t *)list_node->data;
dump_spring_route_info(route);
printf("\n");
}ITERATE_LIST_END;
break;
default:
assert(0);
}
return 0;
}
/* level could LEVEL12*/
boolean
insert_lsp_as_forward_adjacency(node_t *ingress_lsr_node,
char *lsp_name,
unsigned int metric,
char *tail_end_ip,
LEVEL level){
rsvp_tunnel_t *rsvp_tunnel = look_up_rsvp_tunnel(ingress_lsr_node, lsp_name);
if(!rsvp_tunnel){
printf("Error : RSVP tunnel : %s do not exist, LSP export into IGP failed.\n", rsvp_tunnel->lsp_name);
return FALSE;
}
edge_t *lsp = create_new_lsp_adj(lsp_name, metric, level);
lsp->fa = rsvp_tunnel;
insert_edge_between_2_nodes(lsp, ingress_lsr_node, lsp->fa->egress_lsr, UNIDIRECTIONAL);
/*RSVP label is to be treated as Adj sid for FAs*/
set_adj_sid(ingress_lsr_node, lsp_name, level,
rsvp_tunnel->rsvp_label,
lsp->fa->egress_lsr->node_name,
CMDCODE_CONFIG_NODE_INTF_P2P_ADJ_SID_UNPROTECTED);
return TRUE;
}
int
lfa_rlfa_config_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
node_t *node = NULL;
char *node_name = NULL;
char *intf_name = NULL;
int cmd_code = -1, i = 0;
tlv_struct_t *tlv = NULL;
edge_t *edge = NULL;
edge_end_t *edge_end = NULL;
cmd_code = EXTRACT_CMD_CODE(tlv_buf);
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "slot-no", strlen("slot-no")) ==0)
intf_name = tlv->value;
} TLV_LOOP_END;
if(node_name == NULL)
node = instance->instance_root;
else
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
for(i = 0; i < MAX_NODE_INTF_SLOTS; i++){
edge_end = node->edges[i];
if(!edge_end){
printf("%s() : Error : Interface %s do not exist\n", __FUNCTION__, intf_name);
return 0;
}
if(edge_end->dirn != OUTGOING)
continue;
if(strncmp(intf_name, edge_end->intf_name, strlen(edge_end->intf_name)))
continue;
edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
break;
}
switch(cmd_code){
case CMDCODE_CONFIG_INTF_LINK_PROTECTION:
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_LINK_PROTECTION_TYPE(edge, LINK_PROTECTION);
tilfa_update_config(node, edge_end->intf_name,
TRUE, DONT_KNOW);
break;
case CONFIG_DISABLE:
UNSET_LINK_PROTECTION_TYPE(edge, LINK_PROTECTION);
tilfa_update_config(node, edge_end->intf_name,
FALSE, DONT_KNOW);
break;
default:
assert(0);
}
break;
case CMDCODE_CONFIG_INTF_NODE_LINK_PROTECTION:
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_LINK_PROTECTION_TYPE(edge, LINK_PROTECTION);
SET_LINK_PROTECTION_TYPE(edge, LINK_NODE_PROTECTION);
tilfa_update_config(node, edge_end->intf_name,
DONT_KNOW, TRUE);
break;
case CONFIG_DISABLE:
UNSET_LINK_PROTECTION_TYPE(edge, LINK_NODE_PROTECTION);
tilfa_update_config(node, edge_end->intf_name,
DONT_KNOW, FALSE);
break;
default:
assert(0);
}
break;
case CMDCODE_CONFIG_INTF_LINK_PROTECTION_RLFA:
{
if(IS_LEVEL_SET(edge->level, LEVEL1))
compute_rlfa(node, edge, LEVEL1, TRUE);
if(IS_LEVEL_SET(edge->level, LEVEL2))
compute_rlfa(node, edge, LEVEL2, TRUE);
}
break;
case CMDCODE_CONFIG_INTF_NO_ELIGIBLE_BACKUP:
{
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_BIT(edge_end->edge_config_flags, NO_ELIGIBLE_BACK_UP);
break;
case CONFIG_DISABLE:
UNSET_BIT(edge_end->edge_config_flags, NO_ELIGIBLE_BACK_UP);
break;
default:
;
}
}
break;
}
return 0;
}
void
show_spf_initialization(node_t *spf_root, LEVEL level){
node_t *phy_nbr = NULL,
*logical_nbr = NULL;
edge_t *edge = NULL, *pn_edge = NULL;
glthread_t *spf_predecessors = NULL;
nh_type_t nh;
glthread_t *curr = NULL;
ITERATE_NODE_PHYSICAL_NBRS_BEGIN(spf_root, phy_nbr, logical_nbr, edge, pn_edge, level){
printf("Nbr = %s, IP Direct NH count = %u, LSP Direct NH count = %u, metric = %u\n",
phy_nbr->node_name, get_nh_count(&phy_nbr->direct_next_hop[level][IPNH][0]),
get_nh_count(&phy_nbr->direct_next_hop[level][LSPNH][0]),
!is_nh_list_empty2(&phy_nbr->direct_next_hop[level][IPNH][0]) ?
get_direct_next_hop_metric(phy_nbr->direct_next_hop[level][IPNH][0], level) :
get_direct_next_hop_metric(phy_nbr->direct_next_hop[level][LSPNH][0], level));
} ITERATE_NODE_PHYSICAL_NBRS_END(spf_root, phy_nbr, logical_nbr, level);
}
int
debug_show_node_impacted_destinations(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
node_t *node = NULL;
char *intf_name = NULL,
*node_name = NULL;
int i = 0;
edge_t *edge = NULL;
edge_end_t *edge_end = NULL;
tlv_struct_t *tlv = NULL;
LEVEL level_it = MAX_LEVEL;
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "slot-no", strlen("slot-no")) ==0)
intf_name = tlv->value;
else
assert(0);
} TLV_LOOP_END;
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
for(i = 0; i < MAX_NODE_INTF_SLOTS; i++){
edge_end = node->edges[i];
if(!edge_end){
printf("%s() : Error : Interface %s do not exist\n", __FUNCTION__, intf_name);
return 0;
}
if(edge_end->dirn != OUTGOING)
continue;
if(strncmp(intf_name, edge_end->intf_name, strlen(edge_end->intf_name)))
continue;
edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
break;
}
spf_result_t *D_res = NULL;
singly_ll_node_t *list_node = NULL;
char impact_reason[STRING_REASON_LEN];
boolean is_impacted = FALSE,
MANDATORY_NODE_PROTECTION = TRUE;
for(level_it = LEVEL1; level_it < MAX_LEVEL; level_it++){
if(!IS_LEVEL_SET(edge->level, level_it)) continue;
Compute_and_Store_Forward_SPF(node, level_it);
Compute_PHYSICAL_Neighbor_SPFs(node, level_it);
printf("Destinations Impact result for %s, PLR = %s, protected link = %s\n",
get_str_level(level_it), node->node_name, edge_end->intf_name);
printf("Destination Is Impacted Reason\n");
printf("=============================================================\n");
ITERATE_LIST_BEGIN(node->spf_run_result[level_it], list_node){
D_res = list_node->data;
memset(impact_reason , 0 , 256);
MANDATORY_NODE_PROTECTION = TRUE;
is_impacted = is_destination_impacted(node, edge, D_res->node, level_it, impact_reason,
&MANDATORY_NODE_PROTECTION);
printf(" %-20s %-15s %s\n", D_res->node->node_name, is_impacted ? "IMPACTED" : "NOT IMPACTED", impact_reason);
}ITERATE_LIST_END;
}
return 0;
}
void
dump_next_hop(internal_nh_t *nh){
printf("\toif = %-10s", nh->oif->intf_name);
printf("\tprotecting link = %-10s", nh->protected_link->intf_name);
printf("gw_prefix = %-16s", nh->gw_prefix);
if(nh->node)
printf(" Node = %-16s\n", nh->node->node_name);
else
printf(" Node = %s\n", "NULL");
printf("\tnh_type = %-8s", nh->nh_type == IPNH ? "IPNH" : "LSPNH");
printf("lfa_type = %-25s\n", get_str_lfa_type(nh->lfa_type));
if(nh->proxy_nbr)
printf("\tproxy_nbr = %-16s", nh->proxy_nbr->node_name);
else
printf("\tproxy_nbr = %-16s", "NULL");
if(nh->rlfa)
printf("rlfa = %-16s\n", nh->rlfa->node_name);
else
printf("rlfa = %-16s\n", "NULL");
printf("root_metric = %-8u", nh->root_metric);
printf("dest_metric = %-8u", nh->dest_metric);
printf("is_eligible = %-6s\n", nh->is_eligible ? "TRUE" : "FALSE");
}
int
debug_show_node_back_up_spf_results(param_t *param,
ser_buff_t *tlv_buf,
op_mode enable_or_disable){
node_t *node = NULL,
*D = NULL,
*dst_filter = NULL;
tlv_struct_t *tlv = NULL;
LEVEL level_it = MAX_LEVEL;
char *node_name = NULL,
*dst_name = NULL;
nh_type_t nh = NH_MAX;
singly_ll_node_t *list_node = NULL;
spf_result_t *D_res = NULL;
unsigned int i = 0,
nh_count = 0,
j = 0;
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "dst-name", strlen("dst-name")) ==0)
dst_name = tlv->value;
else
assert(0);
} TLV_LOOP_END;
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
if(dst_name)
dst_filter = (node_t *)singly_ll_search_by_key(instance->instance_node_list, dst_name);
internal_nh_t *nxthop = NULL;
if(dst_filter){
D = dst_filter;
for(level_it = LEVEL1; level_it < MAX_LEVEL; level_it++){
printf("\n%s backup spf results\n\n", get_str_level(level_it));
printf("Dest : %s (#IP back-ups = %u, #LSP back-ups = %u)\n",
D->node_name,
get_nh_count(D->backup_next_hop[level_it][IPNH]),
get_nh_count(D->backup_next_hop[level_it][LSPNH]));
D_res = GET_SPF_RESULT((&node->spf_info), D, level_it);
if(!D_res) return 0;
ITERATE_NH_TYPE_BEGIN(nh){
nh_count = get_nh_count(&(D_res->next_hop[nh][0]));
for( i = 0; i < nh_count; i++){
nxthop = &(D_res->next_hop[nh][i]);
PRINT_ONE_LINER_NXT_HOP(nxthop);
}
} ITERATE_NH_TYPE_END;
j = 1;
ITERATE_NH_TYPE_BEGIN(nh){
nh_count = get_nh_count(D->backup_next_hop[level_it][nh]);
for( i = 0; i < nh_count; i++){
printf("Nh# %u. ", j++);
dump_next_hop(&(D->backup_next_hop[level_it][nh][i]));
printf("\n");
}
} ITERATE_NH_TYPE_END;
}
return 0;
}
for(level_it = LEVEL1; level_it < MAX_LEVEL; level_it++){
printf("\n%s backup spf results\n\n", get_str_level(level_it));
ITERATE_LIST_BEGIN(node->spf_run_result[level_it], list_node){
D_res = list_node->data;
D = D_res->node;
printf("Dest : %s (#IP back-ups = %u, #LSP back-ups = %u)\n",
D->node_name,
get_nh_count(D->backup_next_hop[level_it][IPNH]),
get_nh_count(D->backup_next_hop[level_it][LSPNH]));
j = 1;
ITERATE_NH_TYPE_BEGIN(nh){
nh_count = get_nh_count(&(D_res->next_hop[nh][0]));
for( i = 0; i < nh_count; i++){
nxthop = &(D_res->next_hop[nh][i]);
PRINT_ONE_LINER_NXT_HOP(nxthop);
}
} ITERATE_NH_TYPE_END;
ITERATE_NH_TYPE_BEGIN(nh){
nh_count = get_nh_count(D->backup_next_hop[level_it][nh]);
for( i = 0; i < nh_count; i++){
printf("Nh# %u. ", j++);
dump_next_hop(&(D->backup_next_hop[level_it][nh][i]));
printf("\n");
}
} ITERATE_NH_TYPE_END;
} ITERATE_LIST_END;
}
return 0;
}
int
display_logging_status(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
spf_display_trace_options();
return 0;
}
int
instance_node_spring_config_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
node_t *node = NULL;
char *node_name = NULL;
tlv_struct_t *tlv = NULL;
int cmd_code = -1;
char *intf_name = NULL;
unsigned int prefix_sid = 0,
index_range = 0,
first_sid = 0;
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "slot-no", strlen("slot-no")) ==0)
intf_name = tlv->value;
else if(strncmp(tlv->leaf_id, "node-segment", strlen("node-segment")) ==0)
prefix_sid = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "prefix-sid", strlen("prefix-sid")) ==0)
prefix_sid = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "index-range", strlen("index-range")) ==0)
index_range = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "start-label", strlen("start-label")) ==0)
first_sid = atoi(tlv->value);
else
assert(0);
} TLV_LOOP_END;
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
cmd_code = EXTRACT_CMD_CODE(tlv_buf);
switch(cmd_code){
case CMDCODE_CONFIG_NODE_SPRING_BACKUPS:
switch(enable_or_disable){
case CONFIG_ENABLE:
if(!node->spring_enabled){
printf("Error : source-packet-routing not enabled\n");
return 0;
}
node->use_spring_backups = TRUE;
break;
case CONFIG_DISABLE:
node->use_spring_backups = FALSE;
break;
default:
assert(0);
}
break;
case CMDCODE_CONFIG_NODE_SEGMENT_ROUTING_ENABLE:
switch(enable_or_disable){
case CONFIG_ENABLE:
if(node->spring_enabled == TRUE){
printf("Source Packet Routing Already Enabled\n");
return 0;
}
node->spring_enabled = TRUE;
node->srgb = XCALLOC(1, srgb_t);
init_srgb_defaults(node->srgb);
break;
case CONFIG_DISABLE:
node->spring_enabled = FALSE;
spring_disable_cleanup(node);
break;
default:
;
}
break;
case CMDCODE_CONFIG_NODE_SR_PREFIX_SID:
switch(enable_or_disable){
case CONFIG_ENABLE:
set_node_sid(node, prefix_sid);
break;
case CONFIG_DISABLE:
unset_node_sid(node);
break;
default:
;
}
break;
case CMDCODE_CONFIG_NODE_SR_PREFIX_SID_INTF:
switch(enable_or_disable){
case CONFIG_ENABLE:
set_interface_address_prefix_sid(node, intf_name, prefix_sid);
break;
case CONFIG_DISABLE:
unset_interface_address_prefix_sid(node, intf_name);
break;
default:
;
}
break;
#if 0
case CMDCODE_CONFIG_NODE_SR_ADJ_SID:
switch(enable_or_disable){
case CONFIG_ENABLE:
set_interface_adj_sid(node, intf_name, prefix_sid);
break;
case CONFIG_DISABLE:
unset_interface_adj_sid(node, intf_name);
break;
default:
;
}
break;
#endif
case CMDCODE_CONFIG_NODE_SR_SRGB_RANGE:
if(node->spring_enabled == FALSE){
printf("Source Packet Routing Not Enabled\n");
return 0;
}
node->srgb->range = index_range;
printf("SRGB config changed, run - \"run instance sync\"\n");
break;
case CMDCODE_CONFIG_NODE_SR_SRGB_START_LABEL:
if(node->spring_enabled == FALSE){
printf("Source Packet Routing Not Enabled\n");
return 0;
}
node->srgb->first_sid.sid = first_sid;
printf("SRGB config changed, run - \"run instance sync\"\n");
break;
default:
;
}
return 0;
}
void
show_spf_path_predecessors(node_t *spf_root, LEVEL level){
glthread_t *curr = NULL, *curr2 = NULL;
glthread_t *pred_db = NULL;
spf_path_result_t *spf_path_result = NULL;
//compute_spf_paths(spf_root, level, FULL_RUN);
ITERATE_GLTHREAD_BEGIN(
tilfa_get_post_convergence_spf_path_head(spf_root->tilfa_info, level), curr){
spf_path_result = glthread_to_spf_path_result(curr);
printf("Node : %s, %s pred db\n", spf_path_result->node->node_name,
get_str_level(level));