-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspfdcm.c
2288 lines (2001 loc) · 101 KB
/
spfdcm.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: spfdcm.c
*
* Description: This file initalises the CLI interface for SPFComptation Project
*
* Version: 1.0
* Created: Thursday 24 August 2017 12:55:56 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 SPFComptation 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 "libcli.h"
#include "instance.h"
#include "cmdtlv.h"
#include "spfutil.h"
#include "spfcomputation.h"
#include "spftrace.h"
#include "bitsop.h"
#include "spfcmdcodes.h"
#include "spfclihandler.h"
#include "routes.h"
#include "advert.h"
#include "data_plane.h"
#include "no_warn.h"
#include "spf_candidate_tree.h"
#include "complete_spf_path.h"
#include "LinuxMemoryManager/uapi_mm.h"
extern
instance_t *instance;
/*All Command Handler Functions goes here */
extern void
inet_0_display(rt_un_table_t *rib, char *prefix, char mask);
extern void
inet_3_display(rt_un_table_t *rib, char *prefix, char mask);
extern int
ping_backup(char *node_name, char *dst_prefix);
extern
void config_topology_commands(param_t *config);
extern int
show_tilfa_handler(param_t *param, ser_buff_t *tlv_buf,
op_mode enable_or_disable);
extern void srte_init_dcm(param_t *config_node_node_name);
static void
show_spf_results(node_t *spf_root, LEVEL level){
singly_ll_node_t *list_node = NULL;
spf_result_t *res = NULL;
unsigned int i = 0, j = 0;
edge_end_t *oif = NULL;
nh_type_t nh;
printf("\nSPF run results for LEVEL%u, ROOT = %s\n", level, spf_root->node_name);
ITERATE_LIST_BEGIN(spf_root->spf_run_result[level], list_node){
res = (spf_result_t *)list_node->data;
printf("DEST : %-10s spf_metric : %-6u", res->node->node_name, res->spf_metric);
printf(" Nxt Hop : ");
j = 0;
ITERATE_NH_TYPE_BEGIN(nh){
for( i = 0; i < MAX_NXT_HOPS; i++, j++){
if(is_nh_list_empty2(&res->next_hop[nh][i]))
break;
oif = res->next_hop[nh][i].oif;
if(j == 0){
printf("%s|%-8s OIF : %-7s gateway : %s\n",
res->next_hop[nh][i].node->node_name, nh == LSPNH ? "LSPNH" : "IPNH",
oif->intf_name, res->next_hop[nh][i].gw_prefix);
}
else{
printf(" : %s|%-8s OIF : %-7s gateway : %s\n",
res->next_hop[nh][i].node->node_name, nh == LSPNH ? "LSPNH" : "IPNH",
oif->intf_name, res->next_hop[nh][i].gw_prefix);
}
}
} ITERATE_NH_TYPE_END;
}ITERATE_LIST_END;
}
int
validate_debug_log_enable_disable(char *value_passed){
if(strncmp(value_passed, "enable", strlen(value_passed)) == 0 ||
strncmp(value_passed, "disable", strlen(value_passed)) == 0)
return VALIDATION_SUCCESS;
printf("Error : Incorrect log status specified\n");
return VALIDATION_FAILED;
}
int
validate_node_extistence(char *node_name){
if(singly_ll_search_by_key(instance->instance_node_list, node_name))
return VALIDATION_SUCCESS;
printf("Error : Node %s do not exist\n", node_name);
return VALIDATION_FAILED;
}
int
validate_level_no(char *value_passed){
LEVEL level = atoi(value_passed);
if(level == LEVEL1 || level == LEVEL2)
return VALIDATION_SUCCESS;
printf("Error : Incorrect Level Value.\n");
return VALIDATION_FAILED;
}
boolean
is_global_sid_value_valid(unsigned int sid_value){
if(sid_value >= SRGB_DEF_LOWER_BOUND && sid_value <= SRGB_DEF_UPPER_BOUND)
return TRUE;
return FALSE;
}
int
validate_global_sid_value(char *value_passed){
return VALIDATION_SUCCESS;
boolean rc = is_global_sid_value_valid(atoi(value_passed));
if(rc == TRUE)
return VALIDATION_SUCCESS;
printf("Error : Incorrct SID value. Valid range : [%u,%u]\n",
SRGB_DEF_LOWER_BOUND, SRGB_DEF_UPPER_BOUND);
return VALIDATION_FAILED;
}
int
validate_index_range_value(char *value_passed){
unsigned int range = atoi(value_passed);
if(range >= 1 && range <= 0xFFFFFFFF)
return VALIDATION_SUCCESS;
printf("Error : Incorrect index range specified.\n");
return VALIDATION_FAILED;
}
int
validate_metric_value(char *value_passed){
unsigned int metric = atoi(value_passed);
if(metric >= 0 && metric <= INFINITE_METRIC)
return VALIDATION_SUCCESS;
printf("Error : Incorrect metric Value.\n");
return VALIDATION_FAILED;
}
static int
display_mem_usage(param_t *param, ser_buff_t *tlv_buf,
op_mode enable_or_disable){
tlv_struct_t *tlv = NULL;
char *struct_name = NULL;
int cmdcode = EXTRACT_CMD_CODE(tlv_buf);
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "struct-name", strlen("struct-name")) == 0)
struct_name = tlv->value;
} TLV_LOOP_END;
switch(cmdcode){
case CMDCODE_DEBUG_SHOW_MEMORY_USAGE:
mm_print_block_usage();
break;
case CMDCODE_DEBUG_SHOW_MEMORY_USAGE_DETAIL:
mm_print_memory_usage(struct_name);
break;
default:
;
}
}
static int
node_slot_config_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
tlv_struct_t *tlv = NULL;
char *slot_name = NULL;
char *node_name = NULL;
node_t *node = NULL;
int cmd_code = -1;
LEVEL level = MAX_LEVEL;
unsigned int metric = 0;
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "slot-no", strlen("slot-no")) ==0)
slot_name = tlv->value;
else if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "level-no", strlen("level-no")) ==0)
level = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "metric", strlen("metric")) ==0)
metric = atoi(tlv->value);
} 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_SLOT_ENABLE:
spf_node_slot_enable_disable(node, slot_name, enable_or_disable);
break;
case CMFCODE_CONFIG_NODE_SLOT_METRIC_CHANGE:
if(enable_or_disable == CONFIG_DISABLE)
spf_node_slot_metric_change(node, slot_name, level, LINK_DEFAULT_METRIC);
else
spf_node_slot_metric_change(node, slot_name, level, metric);
break;
default:
printf("%s() : Error : No Handler for command code : %d\n", __FUNCTION__, cmd_code);
break;
}
return 0;
}
static int
show_route_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
char *node_name = NULL;
tlv_struct_t *tlv = NULL;
node_t *node = NULL;
char *prefix = NULL;
char mask = 0;
int 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);
} TLV_LOOP_END;
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
switch(cmd_code){
case CMDCODE_SHOW_NODE_INTERNAL_ROUTES:
show_internal_routing_tree(node, prefix, mask, UNICAST_T);
if(node->spring_enabled)
show_internal_routing_tree(node, prefix, mask, SPRING_T);
break;
case CMDCODE_SHOW_NODE_FORWARDING_TABLE:
inet_0_display(node->spf_info.rib[INET_0], prefix, mask);
break;
case CMDCODE_SHOW_NODE_INET3_FORWARDING_TABLE:
inet_3_display(node->spf_info.rib[INET_3], prefix, mask);
break;
default:
assert(0);
}
return 0;
}
static int
show_traceroute_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
char *node_name = NULL;
char *prefix = NULL;
tlv_struct_t *tlv = NULL;
int cmdcode = 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
assert(0);
} TLV_LOOP_END;
switch(cmdcode){
case CMDCODE_SHOW_NODE_TRACEROUTE_PRIMARY:
ping(node_name, prefix);
break;
default:
assert(0);
}
return 0;
}
extern void
dump_next_hop(internal_nh_t *nh);
static int
show_instance_node_spaces(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
char *node_name = NULL,
*slot_name = NULL;
unsigned int i = 0;
tlv_struct_t *tlv = NULL;
node_t *node = NULL;
edge_end_t *edge_end = NULL;
int cmdcode = -1;
LEVEL level_it ;
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)
slot_name = tlv->value;
else
assert(0);
} TLV_LOOP_END;
cmdcode = EXTRACT_CMD_CODE(tlv_buf);
node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
switch(cmdcode){
case CMDCODE_DEBUG_SHOW_NODE_INTF_EXPSPACE:
{
for(i = 0; i < MAX_NODE_INTF_SLOTS; i++ ) {
edge_end = node->edges[i];
if(edge_end == NULL){
printf("Error : slot-no %s do not exist\n", slot_name);
return 0;
}
if(strncmp(slot_name, edge_end->intf_name, strlen(edge_end->intf_name)))
continue;
if(edge_end->dirn != OUTGOING)
continue;
edge_t *edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
init_back_up_computation(node, edge->level);
Compute_and_Store_Forward_SPF(node, edge->level);
Compute_PHYSICAL_Neighbor_SPFs(node, edge->level);
if(is_broadcast_link(edge, edge->level))
broadcast_compute_link_node_protecting_extended_p_space(node, edge, edge->level);
else
p2p_compute_link_node_protecting_extended_p_space(node, edge, edge->level);
printf("Node %s Extended p-space : \n", node->node_name);
unsigned int j = 0, nh_count = 0;
internal_nh_t *p_node = NULL;
for(level_it = LEVEL1; level_it < MAX_LEVEL; level_it++){
printf("\nextended p-space at %s: \n", get_str_level(level_it));
nh_count = get_nh_count(node->pq_nodes[level_it]);
for(j = 0; j < nh_count; j++){
p_node = &node->pq_nodes[level_it][j];
dump_next_hop(p_node);
printf("\n");
}
}
return 0;
}
}
break;
case CMDCODE_DEBUG_SHOW_NODE_INTF_PQSPACE:
{
/*compute extended p-space first*/
edge_t *edge = NULL;
for(i = 0; i < MAX_NODE_INTF_SLOTS; i++ ) {
edge_end = node->edges[i];
if(edge_end == NULL){
printf("Error : slot-no %s do not exist\n", slot_name);
return 0;
}
if(strncmp(slot_name, edge_end->intf_name, strlen(edge_end->intf_name)))
continue;
if(edge_end->dirn != OUTGOING)
continue;
edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
break;
}
init_back_up_computation(node, edge->level);
Compute_and_Store_Forward_SPF(node, edge->level);
Compute_PHYSICAL_Neighbor_SPFs(node, edge->level);
if(is_broadcast_link(edge, edge->level)){
broadcast_compute_link_node_protecting_extended_p_space(node, edge, edge->level);
broadcast_filter_select_pq_nodes_from_ex_pspace(node, edge, edge->level);
}
else{
p2p_compute_link_node_protecting_extended_p_space(node, edge, edge->level);
p2p_filter_select_pq_nodes_from_ex_pspace(node, edge, edge->level);
}
printf("Node %s pq-space computed.\n", node->node_name);
}
break;
default:
;
}
return 0;
}
static int
instance_node_config_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
int cmd_code = -1;
int mask = 0;
node_t *node = NULL;
tlv_struct_t *tlv = NULL;
unsigned int i = 0,
metric = 0;
char *node_name = NULL,
*intf_name = NULL,
*lsp_name = NULL,
*tail_end_ip = NULL;
LEVEL level = MAX_LEVEL,
from_level_no = MAX_LEVEL,
to_level_no = MAX_LEVEL;
char *prefix = NULL;
dist_info_hdr_t dist_info_hdr;
memset(&dist_info_hdr, 0, sizeof(dist_info_hdr_t));
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 if(strncmp(tlv->leaf_id, "level-no", strlen("level-no")) == 0)
level = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "from-level-no", strlen("from-level-no")) == 0)
from_level_no = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "to-level-no", strlen("to-level-no")) == 0)
to_level_no = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "slot-no", strlen("slot-no")) ==0)
intf_name = tlv->value;
else if(strncmp(tlv->leaf_id, "lsp-name", strlen("lsp-name")) ==0)
lsp_name = tlv->value;
else if(strncmp(tlv->leaf_id, "metric-val", strlen("metric-val")) ==0)
metric = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "tail-end-ip", strlen("tail-end-ip")) ==0)
tail_end_ip = 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_CONFIG_NODE_SPF_BACKUP_OPTIONS:
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_ENABLED);
break;
case CONFIG_DISABLE:
UNSET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_ENABLED);
UNSET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_REMOTE_BACKUP_CALCULATION);
UNSET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_NODE_LINK_DEG);
break;
default:
assert(0);
}
break;
case CMDCODE_CONFIG_NODE_REMOTE_BACKUP_CALCULATION:
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_REMOTE_BACKUP_CALCULATION);
break;
case CONFIG_DISABLE:
UNSET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_REMOTE_BACKUP_CALCULATION);
break;
default:
assert(0);
}
break;
case CMDCODE_CONFIG_NODE_LINK_DEGRADATION:
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_NODE_LINK_DEG);
break;
case CONFIG_DISABLE:
UNSET_BIT(node->backup_spf_options, SPF_BACKUP_OPTIONS_NODE_LINK_DEG);
break;
default:
assert(0);
}
break;
case CMDCODE_CONFIG_NODE_RSVPLSP:
{
boolean rc = FALSE;
switch(enable_or_disable){
case CONFIG_ENABLE:
rc = insert_lsp_as_forward_adjacency(node, lsp_name, metric, tail_end_ip, level);
break;
case CONFIG_DISABLE:
break;
default:
;
}
if(rc == FALSE)
break;
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);
}
break;
case CMDCODE_CONFIG_NODE_OVERLOAD_STUBNW:
{
edge_end_t *edge_end = NULL;
switch(enable_or_disable){
case CONFIG_ENABLE:
if(!IS_OVERLOADED(node, level)){
printf("Error : Router not overloaded\n");
return 0;
}
break;
case CONFIG_DISABLE:
break;
default:
assert(0);
}
for(i = 0; i < MAX_NODE_INTF_SLOTS; i++ ) {
edge_end = node->edges[i];
if(edge_end == NULL){
printf("Error : slot-no %s do not exist\n", intf_name);
return 0;
}
if(strncmp(intf_name, edge_end->intf_name, strlen(edge_end->intf_name)))
continue;
if(edge_end->dirn != OUTGOING)
continue;
edge_t *edge = GET_EGDE_PTR_FROM_EDGE_END(edge_end);
if(!IS_LEVEL_SET(edge->level, level)){
printf("Error : slot-no %s is not operating in level %s\n", intf_name, get_str_level(level));
return 0;
}
prefix_t *prefix = edge_end->prefix[level];
switch(enable_or_disable){
case CONFIG_ENABLE:
prefix->metric = INFINITE_METRIC;
break;
case CONFIG_DISABLE:
prefix->metric = DEFAULT_LOCAL_PREFIX_METRIC;
break;
case MODE_UNKNOWN:
return 0;
default:
;
}
prefix_t *list_prefix = node_local_prefix_search(node, level, prefix->prefix, prefix->mask);
assert(list_prefix);
list_prefix->metric = prefix->metric;
/*Update if the prefix is leaked across levels*/
LEVEL other_level = (level == LEVEL1) ? LEVEL2 : LEVEL1;
prefix_t *leaked_prefix = node_local_prefix_search(node, other_level, prefix->prefix, prefix->mask);
if(leaked_prefix)
leaked_prefix->metric = list_prefix->metric;
tlv128_ip_reach_t ad_msg;
memset(&ad_msg, 0, sizeof(tlv128_ip_reach_t));
ad_msg.prefix = prefix->prefix,
ad_msg.mask = prefix->mask;
ad_msg.metric = prefix->metric;
ad_msg.prefix_flags = prefix->prefix_flags; /*Interface attached prefixes have up_down_bit = 0*/
ad_msg.hosting_node = node;
dist_info_hdr.lsp_generator = node;
dist_info_hdr.info_dist_level = level;
dist_info_hdr.add_or_remove = (enable_or_disable == CONFIG_ENABLE) ? AD_CONFIG_ADDED : AD_CONFIG_REMOVED;
dist_info_hdr.advert_id = TLV128;
dist_info_hdr.info_data = (char *)&ad_msg;
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
/*Generate other level LSP update*/
if(leaked_prefix){
ad_msg.prefix_flags = leaked_prefix->prefix_flags;
dist_info_hdr.info_dist_level = other_level;
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
}
return 0;
}
}
break;
case CMDCODE_CONFIG_NODE_OVERLOAD:
{
lsp_hdr_t lsp_hdr;
switch(enable_or_disable){
case CONFIG_ENABLE:
SET_BIT(node->attributes[level], OVERLOAD_BIT);
lsp_hdr.overload = 1;
break;
case CONFIG_DISABLE:
UNSET_BIT(node->attributes[level], OVERLOAD_BIT);
lsp_hdr.overload = 0;
break;
case MODE_UNKNOWN:
return 0;
default:
;
}
dist_info_hdr.lsp_generator = node;
dist_info_hdr.info_dist_level = level;
dist_info_hdr.add_or_remove = (enable_or_disable == CONFIG_ENABLE) ? AD_CONFIG_ADDED : AD_CONFIG_REMOVED;
dist_info_hdr.advert_id = OVERLOAD;
dist_info_hdr.info_data = (char *)&lsp_hdr;
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
}
break;
case CMDCODE_CONFIG_INSTANCE_IGNOREBIT_ENABLE:
(enable_or_disable == CONFIG_ENABLE) ? SET_BIT(node->instance_flags, IGNOREATTACHED) :
UNSET_BIT(node->instance_flags, IGNOREATTACHED);
break;
case CMDCODE_CONFIG_INSTANCE_ATTACHBIT_ENABLE:
node->attached = (enable_or_disable == CONFIG_ENABLE) ? 1 : 0;
break;
case CMDCODE_CONFIG_NODE_EXPORT_PREFIX:
{
prefix_t *pfx = node_local_prefix_search(node,
level, prefix, mask);
if(pfx){
printf("Error : Attempt to add duplicate prefix %s/%u in %s",
prefix, mask, get_str_level(level));
return 0;
}
tlv128_ip_reach_t ad_msg;
memset(&ad_msg, 0, sizeof(tlv128_ip_reach_t));
ad_msg.prefix = prefix,
ad_msg.mask = mask;
ad_msg.metric = 0;
SET_BIT(ad_msg.prefix_flags, PREFIX_EXTERNABIT_FLAG);
ad_msg.hosting_node = node;
dist_info_hdr.lsp_generator = node;
dist_info_hdr.info_dist_level = level;
dist_info_hdr.add_or_remove = (enable_or_disable == CONFIG_ENABLE) ? AD_CONFIG_ADDED : AD_CONFIG_REMOVED;
dist_info_hdr.advert_id = TLV128;
dist_info_hdr.info_data = (char *)&ad_msg;
/*Adopting to PRC behavior*/
pfx = attach_prefix_on_node (node, prefix, mask, level, 0, ad_msg.prefix_flags);
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
}
break;
case CMDCODE_CONFIG_NODE_LEAK_PREFIX:
{
prefix_t *leaked_prefix = NULL;
if((leaked_prefix = leak_prefix(node_name, prefix, mask, from_level_no, to_level_no)) == NULL)
break;
tlv128_ip_reach_t ad_msg;
memset(&ad_msg, 0, sizeof(tlv128_ip_reach_t));
ad_msg.prefix = prefix,
ad_msg.mask = mask;
ad_msg.metric = leaked_prefix->metric;
ad_msg.prefix_flags = leaked_prefix->prefix_flags;
ad_msg.hosting_node = node;
dist_info_hdr.lsp_generator = node;
dist_info_hdr.info_dist_level = to_level_no;
dist_info_hdr.add_or_remove = (enable_or_disable == CONFIG_ENABLE) ? AD_CONFIG_ADDED : AD_CONFIG_REMOVED;
dist_info_hdr.advert_id = TLV128;
dist_info_hdr.info_data = (char *)&ad_msg;
generate_lsp(instance, node, lsp_distribution_routine, &dist_info_hdr);
}
break;
default:
printf("%s() : Error : No Handler for command code : %d\n", __FUNCTION__, cmd_code);
break;
}
return 0;
}
static int
config_static_route_handler(param_t *param,
ser_buff_t *tlv_buf,
op_mode enable_or_disable){
node_t *host_node = NULL;
tlv_struct_t *tlv = NULL;
char *nh_name = NULL,
*host_node_name = NULL,
*dest_ip = NULL,
*gw_ip = NULL,
*intf_name = NULL;
int mask = 0, k = 0;
rt_un_table_t *inet_0_rib = NULL;
rt_key_t inet_key;
internal_nh_t nexthop;
internal_un_nh_t *un_nxthop = NULL;
edge_end_t *oif = NULL;
boolean rc = FALSE;
LEVEL level = LEVEL1;
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0)
host_node_name = tlv->value;
else if(strncmp(tlv->leaf_id, "nh-name", strlen("nh-name")) ==0)
nh_name = tlv->value;
else if(strncmp(tlv->leaf_id, "destination", strlen("destination")) ==0)
dest_ip = tlv->value;
else if(strncmp(tlv->leaf_id, "mask", strlen("mask")) ==0)
mask = atoi(tlv->value);
else if(strncmp(tlv->leaf_id, "gateway", strlen("gateway")) ==0)
gw_ip = tlv->value;
else if(strncmp(tlv->leaf_id, "oif", strlen("oif")) ==0)
intf_name = tlv->value;
else
assert(0);
} TLV_LOOP_END;
memset(&inet_key, 0, sizeof(rt_key_t));
host_node = singly_ll_search_by_key(instance->instance_node_list, host_node_name);
inet_0_rib = host_node->spf_info.rib[INET_0];
switch(enable_or_disable){
case CONFIG_ENABLE:
oif = get_interface_from_intf_name(host_node, intf_name);
strncpy(RT_ENTRY_PFX(&inet_key), dest_ip, PREFIX_LEN);
RT_ENTRY_MASK(&inet_key) = mask;
/*Test for local route*/
if(strncmp(gw_ip, "-", strlen("-")) == 0 || !oif){
inet_0_rt_un_route_install_nexthop(inet_0_rib, &inet_key, LEVEL1, NULL);
return 0;
}
if(!oif){
printf("Invalid interface name : %s\n", intf_name);
return -1;
}
nexthop.oif = oif;
nexthop.node = get_peer_node(oif, LEVEL1, dest_ip);
level = LEVEL1;
if(!nexthop.node){
nexthop.node = get_peer_node(oif, LEVEL2, dest_ip);
level = LEVEL2;
}
if(!nexthop.node){
printf("Topology incomplete : Could not find Nexthop\n");
return -1;
}
strncpy(nexthop.gw_prefix, gw_ip, PREFIX_LEN);
nexthop.gw_prefix[PREFIX_LEN] = '\0';
un_nxthop = inet_0_unifiy_nexthop(&nexthop, IGP_PROTO);
rc = inet_0_rt_un_route_install_nexthop(inet_0_rib, &inet_key, level, un_nxthop);
if(!rc){
free_un_nexthop(un_nxthop);
printf("Error : Route installation failed\n");
return -1;
}
break;
case CONFIG_DISABLE:
break;
default:
;
}
return 0;
}
static int
set_unset_traceoptions(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
int CMDCODE;
CMDCODE = EXTRACT_CMD_CODE(tlv_buf);
switch(CMDCODE){
case CMDCODE_DEBUG_TRACEOPTIONS_DIJKASTRA:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, DIJKSTRA_BIT):
disable_spf_trace(instance, DIJKSTRA_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_ROUTE_INSTALLATION:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, ROUTE_INSTALLATION_BIT):
disable_spf_trace(instance, ROUTE_INSTALLATION_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_ROUTE_CALCULATION:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, ROUTE_CALCULATION_BIT):
disable_spf_trace(instance, ROUTE_CALCULATION_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_BACKUPS:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, BACKUP_COMPUTATION_BIT):
disable_spf_trace(instance, BACKUP_COMPUTATION_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_PREFIXES:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, SPF_PREFIX_BIT):
disable_spf_trace(instance, SPF_PREFIX_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_ROUTING_TABLE:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, ROUTING_TABLE_BIT):
disable_spf_trace(instance, ROUTING_TABLE_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_CONFLICT_RESOLUTION:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, CONFLICT_RESOLUTION_BIT):
disable_spf_trace(instance, CONFLICT_RESOLUTION_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_SPRING_ROUTE_CAL:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, SPRING_ROUTE_CAL_BIT):
disable_spf_trace(instance, SPRING_ROUTE_CAL_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_TILFA:
enable_or_disable == CONFIG_ENABLE ? enable_spf_trace(instance, TILFA_BIT):
disable_spf_trace(instance, TILFA_BIT);
break;
case CMDCODE_DEBUG_TRACEOPTIONS_ALL:
switch(enable_or_disable){
case CONFIG_ENABLE:
enable_spf_trace(instance, DIJKSTRA_BIT);
enable_spf_trace(instance, ROUTE_CALCULATION_BIT);
enable_spf_trace(instance, ROUTE_INSTALLATION_BIT);
enable_spf_trace(instance, BACKUP_COMPUTATION_BIT);
enable_spf_trace(instance, SPF_PREFIX_BIT);
enable_spf_trace(instance, ROUTING_TABLE_BIT);
enable_spf_trace(instance, CONFLICT_RESOLUTION_BIT);
enable_spf_trace(instance, SPRING_ROUTE_CAL_BIT);
enable_spf_trace(instance, TILFA_BIT);
break;
case CONFIG_DISABLE:
disable_spf_trace(instance, DIJKSTRA_BIT);
disable_spf_trace(instance, ROUTE_INSTALLATION_BIT);
disable_spf_trace(instance, ROUTE_CALCULATION_BIT);
disable_spf_trace(instance, BACKUP_COMPUTATION_BIT);
disable_spf_trace(instance, SPF_PREFIX_BIT);
disable_spf_trace(instance, ROUTING_TABLE_BIT);
disable_spf_trace(instance, CONFLICT_RESOLUTION_BIT);
disable_spf_trace(instance, SPRING_ROUTE_CAL_BIT);
disable_spf_trace(instance, TILFA_BIT);
break;
default:
assert(0);
}
break;
default:
assert(0);
}
return 0;
}
static int
debug_log_enable_disable_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
tlv_struct_t *tlv = NULL;
char *value = NULL;
int CMDCODE = EXTRACT_CMD_CODE(tlv_buf);
TLV_LOOP_BEGIN(tlv_buf, tlv){
value = tlv->value;
} TLV_LOOP_END;
switch(CMDCODE){
case CMDCODE_DEBUG_LOG_ENABLE_DISABLE:
if(strncmp(value, "enable", strlen(value)) ==0){
enable_spf_tracing();
}
else if(strncmp(value, "disable", strlen(value)) ==0){
disable_spf_tracing();
}
break;
case CMDCODE_DEBUG_LOG_FILE_ENABLE_DISABLE:
if(strncmp(value, "enable", strlen(value)) ==0){
trace_set_log_medium(instance->traceopts, LOG_FILE);
}
else if(strncmp(value, "disable", strlen(value)) ==0){
trace_set_log_medium(instance->traceopts, CONSOLE);
}
break;
default:
assert(0);
}
return 0;
}
static void
show_spf_run_stats(node_t *node, LEVEL level){
printf("SPF Statistics - root : %s, LEVEL%u\n", node->node_name, level);
printf("# SPF runs : %u\n", node->spf_info.spf_level_info[level].version);
}
static int
show_spf_run_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
tlv_struct_t *tlv = NULL;
LEVEL level = LEVEL1 | LEVEL2;;
char *node_name = NULL,
*dst_node_name = NULL;
node_t *spf_root = NULL,
*dst_node = NULL;
int CMDCODE = -1;
CMDCODE = EXTRACT_CMD_CODE(tlv_buf);
TLV_LOOP_BEGIN(tlv_buf, tlv){
if(strncmp(tlv->leaf_id, "level-no", strlen("level-no")) ==0){
level = atoi(tlv->value);
}
else if(strncmp(tlv->leaf_id, "node-name", strlen("node-name")) ==0){
node_name = tlv->value;
}
else if(strncmp(tlv->leaf_id, "dst-node-name", strlen("dst-node-name")) ==0){
dst_node_name = tlv->value;
}
} TLV_LOOP_END;
if(node_name == NULL)
spf_root = instance->instance_root;
else
spf_root = (node_t *)singly_ll_search_by_key(instance->instance_node_list, node_name);
if(dst_node_name)
dst_node = (node_t *)singly_ll_search_by_key(instance->instance_node_list, dst_node_name);
switch(CMDCODE){
case CMDCODE_SHOW_SPF_RUN:
spf_computation(spf_root, &spf_root->spf_info, level, FULL_RUN, 0);
show_spf_results(spf_root, level);
break;
case CMDCODE_DEBUG_SHOW_SPF_PATH_TRACE:
show_spf_path_predecessors(spf_root, level);
break;
case CMDCODE_SHOW_SPF_PATH_LIST:
trace_spf_path_to_destination_node(spf_root, dst_node, level, print_spf_paths, NULL, TRUE);
break;
case CMDCODE_SHOW_SPF_RUN_PRC:
partial_spf_run(spf_root, level);
break;
case CMDCODE_SHOW_SPF_STATS:
show_spf_run_stats(spf_root, level);
break;
case CMDCODE_SHOW_SPF_RUN_INVERSE:
inverse_topology(instance, level);
spf_computation(spf_root, &spf_root->spf_info, level, FORWARD_RUN, 0);
inverse_topology(instance, level);
show_spf_results(spf_root, level);
break;
case CMDCODE_SHOW_SPF_RUN_INIT:
spf_only_intitialization(spf_root, level);
show_spf_initialization(spf_root, level);
SPF_RE_INIT_CANDIDATE_TREE(&instance->ctree);
spf_root->traversing_bit = 0;
spf_root->is_node_on_heap = FALSE;
break;