forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpath_pcep_cli.c
2036 lines (1784 loc) · 60.6 KB
/
path_pcep_cli.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
/*
* Copyright (C) 2020 Volta Networks, Inc
* Brady Johnson
*
* 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; 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 "pceplib/pcep_utils_counters.h"
#include "pceplib/pcep_session_logic.h"
#include "log.h"
#include "command.h"
#include "libfrr.h"
#include "printfrr.h"
#include "lib/version.h"
#include "northbound.h"
#include "frr_pthread.h"
#include "jhash.h"
#include "termtable.h"
#include "pathd/pathd.h"
#include "pathd/path_errors.h"
#include "pathd/path_pcep.h"
#include "pathd/path_pcep_cli.h"
#include "pathd/path_pcep_controller.h"
#include "pathd/path_pcep_debug.h"
#include "pathd/path_pcep_lib.h"
#include "pathd/path_pcep_pcc.h"
#ifndef VTYSH_EXTRACT_PL
#include "pathd/path_pcep_cli_clippy.c"
#endif
#define DEFAULT_PCE_PRECEDENCE 255
#define DEFAULT_PCC_MSD 4
#define DEFAULT_SR_DRAFT07 false
#define DEFAULT_PCE_INITIATED false
#define DEFAULT_TIMER_KEEP_ALIVE 30
#define DEFAULT_TIMER_KEEP_ALIVE_MIN 1
#define DEFAULT_TIMER_KEEP_ALIVE_MAX 255
#define DEFAULT_TIMER_DEADTIMER 120
#define DEFAULT_TIMER_DEADTIMER_MIN 4
#define DEFAULT_TIMER_DEADTIMER_MAX 255
#define DEFAULT_TIMER_PCEP_REQUEST 30
#define DEFAULT_TIMER_SESSION_TIMEOUT_INTERVAL 30
#define DEFAULT_DELEGATION_TIMEOUT_INTERVAL 10
/* CLI Function declarations */
static int pcep_cli_debug_config_write(struct vty *vty);
static int pcep_cli_debug_set_all(uint32_t flags, bool set);
static int pcep_cli_pcep_config_write(struct vty *vty);
static int pcep_cli_pcc_config_write(struct vty *vty);
static int pcep_cli_pce_config_write(struct vty *vty);
static int pcep_cli_pcep_pce_config_write(struct vty *vty);
/* Internal Util Function declarations */
static struct pce_opts_cli *pcep_cli_find_pce(const char *pce_name);
static bool pcep_cli_add_pce(struct pce_opts_cli *pce_opts_cli);
static struct pce_opts_cli *pcep_cli_create_pce_opts();
static void pcep_cli_delete_pce(const char *pce_name);
static void
pcep_cli_merge_pcep_pce_config_options(struct pce_opts_cli *pce_opts_cli);
static struct pcep_config_group_opts *
pcep_cli_find_pcep_pce_config(const char *group_name);
static bool
pcep_cli_add_pcep_pce_config(struct pcep_config_group_opts *config_group_opts);
static struct pcep_config_group_opts *
pcep_cli_create_pcep_pce_config(const char *group_name);
static bool pcep_cli_is_pcep_pce_config_used(const char *group_name);
static void pcep_cli_delete_pcep_pce_config(const char *group_name);
static int pcep_cli_print_pce_config(struct pcep_config_group_opts *group_opts,
char *buf, size_t buf_len);
static void print_pcep_capabilities(char *buf, size_t buf_len,
pcep_configuration *config);
static void print_pcep_session(struct vty *vty, struct pce_opts *pce_opts,
struct pcep_pcc_info *pcc_info);
static bool pcep_cli_pcc_has_pce(const char *pce_name);
static void pcep_cli_add_pce_connection(struct pce_opts *pce_opts);
static void pcep_cli_remove_pce_connection(struct pce_opts *pce_opts);
static int path_pcep_cli_pcc_pcc_peer_delete(struct vty *vty,
const char *peer_name,
const char *precedence_str,
long precedence);
/*
* Globals.
*/
static const char PCEP_VTYSH_ARG_ADDRESS[] = "address";
static const char PCEP_VTYSH_ARG_SOURCE_ADDRESS[] = "source-address";
static const char PCEP_VTYSH_ARG_IP[] = "ip";
static const char PCEP_VTYSH_ARG_IPV6[] = "ipv6";
static const char PCEP_VTYSH_ARG_PORT[] = "port";
static const char PCEP_VTYSH_ARG_PRECEDENCE[] = "precedence";
static const char PCEP_VTYSH_ARG_MSD[] = "msd";
static const char PCEP_VTYSH_ARG_KEEP_ALIVE[] = "keep-alive";
static const char PCEP_VTYSH_ARG_TIMER[] = "timer";
static const char PCEP_VTYSH_ARG_KEEP_ALIVE_MIN[] = "min-peer-keep-alive";
static const char PCEP_VTYSH_ARG_KEEP_ALIVE_MAX[] = "max-peer-keep-alive";
static const char PCEP_VTYSH_ARG_DEAD_TIMER[] = "dead-timer";
static const char PCEP_VTYSH_ARG_DEAD_TIMER_MIN[] = "min-peer-dead-timer";
static const char PCEP_VTYSH_ARG_DEAD_TIMER_MAX[] = "max-peer-dead-timer";
static const char PCEP_VTYSH_ARG_PCEP_REQUEST[] = "pcep-request";
static const char PCEP_VTYSH_ARG_SESSION_TIMEOUT[] = "session-timeout-interval";
static const char PCEP_VTYSH_ARG_DELEGATION_TIMEOUT[] = "delegation-timeout";
static const char PCEP_VTYSH_ARG_SR_DRAFT07[] = "sr-draft07";
static const char PCEP_VTYSH_ARG_PCE_INIT[] = "pce-initiated";
static const char PCEP_VTYSH_ARG_TCP_MD5[] = "tcp-md5-auth";
static const char PCEP_VTYSH_ARG_BASIC[] = "basic";
static const char PCEP_VTYSH_ARG_PATH[] = "path";
static const char PCEP_VTYSH_ARG_MESSAGE[] = "message";
static const char PCEP_VTYSH_ARG_PCEPLIB[] = "pceplib";
static const char PCEP_CLI_CAP_STATEFUL[] = " [Stateful PCE]";
static const char PCEP_CLI_CAP_INCL_DB_VER[] = " [Include DB version]";
static const char PCEP_CLI_CAP_LSP_TRIGGERED[] = " [LSP Triggered Resync]";
static const char PCEP_CLI_CAP_LSP_DELTA[] = " [LSP Delta Sync]";
static const char PCEP_CLI_CAP_PCE_TRIGGERED[] =
" [PCE triggered Initial Sync]";
static const char PCEP_CLI_CAP_SR_TE_PST[] = " [SR TE PST]";
static const char PCEP_CLI_CAP_PCC_RESOLVE_NAI[] =
" [PCC can resolve NAI to SID]";
static const char PCEP_CLI_CAP_PCC_INITIATED[] = " [PCC Initiated LSPs]";
static const char PCEP_CLI_CAP_PCC_PCE_INITIATED[] =
" [PCC and PCE Initiated LSPs]";
struct pce_connections {
int num_connections;
struct pce_opts *connections[MAX_PCC];
};
struct pce_connections pce_connections_g = {.num_connections = 0};
/* Default PCE group that all PCE-Groups and PCEs will inherit from */
struct pcep_config_group_opts default_pcep_config_group_opts_g = {
.name = "default",
.tcp_md5_auth = "\0",
.draft07 = DEFAULT_SR_DRAFT07,
.pce_initiated = DEFAULT_PCE_INITIATED,
.keep_alive_seconds = DEFAULT_TIMER_KEEP_ALIVE,
.min_keep_alive_seconds = DEFAULT_TIMER_KEEP_ALIVE_MIN,
.max_keep_alive_seconds = DEFAULT_TIMER_KEEP_ALIVE_MAX,
.dead_timer_seconds = DEFAULT_TIMER_DEADTIMER,
.min_dead_timer_seconds = DEFAULT_TIMER_DEADTIMER_MIN,
.max_dead_timer_seconds = DEFAULT_TIMER_DEADTIMER_MAX,
.pcep_request_time_seconds = DEFAULT_TIMER_PCEP_REQUEST,
.session_timeout_inteval_seconds =
DEFAULT_TIMER_SESSION_TIMEOUT_INTERVAL,
.delegation_timeout_seconds = DEFAULT_DELEGATION_TIMEOUT_INTERVAL,
.source_port = DEFAULT_PCEP_TCP_PORT,
.source_ip.ipa_type = IPADDR_NONE,
};
/* Used by PCEP_PCE_CONFIG_NODE sub-commands to operate on the current pce group
*/
struct pcep_config_group_opts *current_pcep_config_group_opts_g = NULL;
/* Used by PCEP_PCE_NODE sub-commands to operate on the current pce opts */
struct pce_opts_cli *current_pce_opts_g = NULL;
short pcc_msd_g = DEFAULT_PCC_MSD;
bool pcc_msd_configured_g = false;
static struct cmd_node pcep_node = {
.name = "srte pcep",
.node = PCEP_NODE,
.parent_node = SR_TRAFFIC_ENG_NODE,
.config_write = pcep_cli_pcep_config_write,
.prompt = "%s(config-sr-te-pcep)# "
};
static struct cmd_node pcep_pcc_node = {
.name = "srte pcep pcc",
.node = PCEP_PCC_NODE,
.parent_node = PCEP_NODE,
.config_write = pcep_cli_pcc_config_write,
.prompt = "%s(config-sr-te-pcep-pcc)# "
};
static struct cmd_node pcep_pce_node = {
.name = "srte pcep pce",
.node = PCEP_PCE_NODE,
.parent_node = PCEP_NODE,
.config_write = pcep_cli_pce_config_write,
.prompt = "%s(config-sr-te-pcep-pce)# "
};
static struct cmd_node pcep_pce_config_node = {
.name = "srte pcep pce-config",
.node = PCEP_PCE_CONFIG_NODE,
.parent_node = PCEP_NODE,
.config_write = pcep_cli_pcep_pce_config_write,
.prompt = "%s(pce-sr-te-pcep-pce-config)# "
};
/* Common code used in VTYSH processing for int values */
#define PCEP_VTYSH_INT_ARG_CHECK(arg_str, arg_val, arg_store, min_value, \
max_value) \
if (arg_str != NULL) { \
if (arg_val <= min_value || arg_val >= max_value) { \
vty_out(vty, \
"%% Invalid value %ld in range [%d - %d]", \
arg_val, min_value, max_value); \
return CMD_WARNING; \
} \
arg_store = arg_val; \
}
#define MERGE_COMPARE_CONFIG_GROUP_VALUE(config_param, not_set_value) \
pce_opts_cli->pce_opts.config_opts.config_param = \
pce_opts_cli->pce_config_group_opts.config_param; \
if (pce_opts_cli->pce_config_group_opts.config_param \
== not_set_value) { \
pce_opts_cli->pce_opts.config_opts.config_param = \
((pce_config != NULL \
&& pce_config->config_param != not_set_value) \
? pce_config->config_param \
: default_pcep_config_group_opts_g \
.config_param); \
}
/*
* Internal Util functions
*/
/* Check if a pce_opts_cli already exists based on its name and return it,
* return NULL otherwise */
static struct pce_opts_cli *pcep_cli_find_pce(const char *pce_name)
{
for (int i = 0; i < MAX_PCE; i++) {
struct pce_opts_cli *pce_rhs_cli = pcep_g->pce_opts_cli[i];
if (pce_rhs_cli != NULL) {
if (strcmp(pce_name, pce_rhs_cli->pce_opts.pce_name)
== 0) {
return pce_rhs_cli;
}
}
}
return NULL;
}
/* Add a new pce_opts_cli to pcep_g, return false if MAX_PCES, true otherwise */
static bool pcep_cli_add_pce(struct pce_opts_cli *pce_opts_cli)
{
for (int i = 0; i < MAX_PCE; i++) {
if (pcep_g->pce_opts_cli[i] == NULL) {
pcep_g->pce_opts_cli[i] = pce_opts_cli;
pcep_g->num_pce_opts_cli++;
return true;
}
}
return false;
}
/* Create a new pce opts_cli */
static struct pce_opts_cli *pcep_cli_create_pce_opts(const char *name)
{
struct pce_opts_cli *pce_opts_cli =
XCALLOC(MTYPE_PCEP, sizeof(struct pce_opts_cli));
strlcpy(pce_opts_cli->pce_opts.pce_name, name,
sizeof(pce_opts_cli->pce_opts.pce_name));
pce_opts_cli->pce_opts.port = PCEP_DEFAULT_PORT;
return pce_opts_cli;
}
static void pcep_cli_delete_pce(const char *pce_name)
{
for (int i = 0; i < MAX_PCE; i++) {
if (pcep_g->pce_opts_cli[i] != NULL) {
if (strcmp(pcep_g->pce_opts_cli[i]->pce_opts.pce_name,
pce_name)
== 0) {
XFREE(MTYPE_PCEP, pcep_g->pce_opts_cli[i]);
pcep_g->pce_opts_cli[i] = NULL;
pcep_g->num_pce_opts_cli--;
return;
}
}
}
}
static void
pcep_cli_merge_pcep_pce_config_options(struct pce_opts_cli *pce_opts_cli)
{
if (pce_opts_cli->merged == true) {
return;
}
struct pcep_config_group_opts *pce_config =
pcep_cli_find_pcep_pce_config(pce_opts_cli->config_group_name);
/* Configuration priorities:
* 1) pce_opts->config_opts, if present, overwrite pce_config
* config_opts 2) pce_config config_opts, if present, overwrite
* default config_opts 3) If neither pce_opts->config_opts nor
* pce_config config_opts are set, then the default config_opts value
* will be used.
*/
const char *tcp_md5_auth_str =
pce_opts_cli->pce_config_group_opts.tcp_md5_auth;
if (pce_opts_cli->pce_config_group_opts.tcp_md5_auth[0] == '\0') {
if (pce_config != NULL && pce_config->tcp_md5_auth[0] != '\0') {
tcp_md5_auth_str = pce_config->tcp_md5_auth;
} else {
tcp_md5_auth_str =
default_pcep_config_group_opts_g.tcp_md5_auth;
}
}
strlcpy(pce_opts_cli->pce_opts.config_opts.tcp_md5_auth,
tcp_md5_auth_str,
sizeof(pce_opts_cli->pce_opts.config_opts.tcp_md5_auth));
struct ipaddr *source_ip =
&pce_opts_cli->pce_config_group_opts.source_ip;
if (pce_opts_cli->pce_config_group_opts.source_ip.ipa_type
== IPADDR_NONE) {
if (pce_config != NULL
&& pce_config->source_ip.ipa_type != IPADDR_NONE) {
source_ip = &pce_config->source_ip;
} else {
source_ip = &default_pcep_config_group_opts_g.source_ip;
}
}
memcpy(&pce_opts_cli->pce_opts.config_opts.source_ip, source_ip,
sizeof(struct ipaddr));
MERGE_COMPARE_CONFIG_GROUP_VALUE(draft07, false);
MERGE_COMPARE_CONFIG_GROUP_VALUE(pce_initiated, false);
MERGE_COMPARE_CONFIG_GROUP_VALUE(keep_alive_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(min_keep_alive_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(max_keep_alive_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(dead_timer_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(min_dead_timer_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(max_dead_timer_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(pcep_request_time_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(session_timeout_inteval_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(delegation_timeout_seconds, 0);
MERGE_COMPARE_CONFIG_GROUP_VALUE(source_port, 0);
pce_opts_cli->merged = true;
}
/* Check if a pcep_config_group_opts already exists based on its name and return
* it, return NULL otherwise */
static struct pcep_config_group_opts *
pcep_cli_find_pcep_pce_config(const char *group_name)
{
for (int i = 0; i < MAX_PCE; i++) {
struct pcep_config_group_opts *pcep_pce_config_rhs =
pcep_g->config_group_opts[i];
if (pcep_pce_config_rhs != NULL) {
if (strcmp(group_name, pcep_pce_config_rhs->name)
== 0) {
return pcep_pce_config_rhs;
}
}
}
return NULL;
}
/* Add a new pcep_config_group_opts to pcep_g, return false if MAX_PCE,
* true otherwise */
static bool pcep_cli_add_pcep_pce_config(
struct pcep_config_group_opts *pcep_config_group_opts)
{
for (int i = 0; i < MAX_PCE; i++) {
if (pcep_g->config_group_opts[i] == NULL) {
pcep_g->config_group_opts[i] = pcep_config_group_opts;
pcep_g->num_config_group_opts++;
return true;
}
}
return false;
}
/* Create a new pce group, inheriting its values from the default pce group */
static struct pcep_config_group_opts *
pcep_cli_create_pcep_pce_config(const char *group_name)
{
struct pcep_config_group_opts *pcep_config_group_opts =
XCALLOC(MTYPE_PCEP, sizeof(struct pcep_config_group_opts));
strlcpy(pcep_config_group_opts->name, group_name,
sizeof(pcep_config_group_opts->name));
return pcep_config_group_opts;
}
/* Iterate the pce_opts and return true if the pce-group-name is referenced,
* false otherwise. */
static bool pcep_cli_is_pcep_pce_config_used(const char *group_name)
{
for (int i = 0; i < MAX_PCE; i++) {
if (pcep_g->pce_opts_cli[i] != NULL) {
if (strcmp(pcep_g->pce_opts_cli[i]->config_group_name,
group_name)
== 0) {
return true;
}
}
}
return false;
}
static void pcep_cli_delete_pcep_pce_config(const char *group_name)
{
for (int i = 0; i < MAX_PCE; i++) {
if (pcep_g->config_group_opts[i] != NULL) {
if (strcmp(pcep_g->config_group_opts[i]->name,
group_name)
== 0) {
XFREE(MTYPE_PCEP, pcep_g->config_group_opts[i]);
pcep_g->config_group_opts[i] = NULL;
pcep_g->num_config_group_opts--;
return;
}
}
}
}
static bool pcep_cli_pcc_has_pce(const char *pce_name)
{
for (int i = 0; i < MAX_PCC; i++) {
struct pce_opts *pce_opts = pce_connections_g.connections[i];
if (pce_opts == NULL) {
continue;
}
if (strcmp(pce_opts->pce_name, pce_name) == 0) {
return true;
}
}
return false;
}
static void pcep_cli_add_pce_connection(struct pce_opts *pce_opts)
{
for (int i = 0; i < MAX_PCC; i++) {
if (pce_connections_g.connections[i] == NULL) {
pce_connections_g.num_connections++;
pce_connections_g.connections[i] = pce_opts;
return;
}
}
}
static void pcep_cli_remove_pce_connection(struct pce_opts *pce_opts)
{
for (int i = 0; i < MAX_PCC; i++) {
if (pce_connections_g.connections[i] == pce_opts) {
pce_connections_g.num_connections--;
pce_connections_g.connections[i] = NULL;
return;
}
}
}
/*
* VTY command implementations
*/
static int path_pcep_cli_debug(struct vty *vty, const char *no_str,
const char *basic_str, const char *path_str,
const char *message_str, const char *pceplib_str)
{
uint32_t mode = DEBUG_NODE2MODE(vty->node);
bool no = (no_str != NULL);
DEBUG_MODE_SET(&pcep_g->dbg, mode, !no);
if (basic_str != NULL) {
DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC, !no);
}
if (path_str != NULL) {
DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH, !no);
}
if (message_str != NULL) {
DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP, !no);
}
if (pceplib_str != NULL) {
DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB, !no);
}
return CMD_SUCCESS;
}
static int path_pcep_cli_show_srte_pcep_counters(struct vty *vty)
{
int i, j, row;
time_t diff_time;
struct tm *tm_info;
char tm_buffer[26];
struct counters_group *group;
struct counters_subgroup *subgroup;
struct counter *counter;
const char *group_name, *empty_string = "";
struct ttable *tt;
char *table;
group = pcep_ctrl_get_counters(pcep_g->fpt, 1);
if (group == NULL) {
vty_out(vty, "No counters to display.\n\n");
return CMD_SUCCESS;
}
diff_time = time(NULL) - group->start_time;
tm_info = localtime(&group->start_time);
strftime(tm_buffer, sizeof(tm_buffer), "%Y-%m-%d %H:%M:%S", tm_info);
vty_out(vty, "PCEP counters since %s (%uh %um %us):\n", tm_buffer,
(uint32_t)(diff_time / 3600), (uint32_t)((diff_time / 60) % 60),
(uint32_t)(diff_time % 60));
/* Prepare table. */
tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
ttable_add_row(tt, "Group|Name|Value");
tt->style.cell.rpad = 2;
tt->style.corner = '+';
ttable_restyle(tt);
ttable_rowseps(tt, 0, BOTTOM, true, '-');
for (row = 0, i = 0; i <= group->num_subgroups; i++) {
subgroup = group->subgroups[i];
if (subgroup != NULL) {
group_name = subgroup->counters_subgroup_name;
for (j = 0; j <= subgroup->num_counters; j++) {
counter = subgroup->counters[j];
if (counter != NULL) {
ttable_add_row(tt, "%s|%s|%u",
group_name,
counter->counter_name,
counter->counter_value);
row++;
group_name = empty_string;
}
}
ttable_rowseps(tt, row, BOTTOM, true, '-');
}
}
/* Dump the generated table. */
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
XFREE(MTYPE_TMP, table);
ttable_del(tt);
pcep_lib_free_counters(group);
return CMD_SUCCESS;
}
static int path_pcep_cli_pcep_pce_config(struct vty *vty,
const char *pcep_pce_config)
{
struct pcep_config_group_opts *pce_config =
pcep_cli_find_pcep_pce_config(pcep_pce_config);
if (pce_config == NULL) {
pce_config = pcep_cli_create_pcep_pce_config(pcep_pce_config);
if (pcep_cli_add_pcep_pce_config(pce_config) == false) {
vty_out(vty,
"%% Cannot create pce-config, as the Maximum limit of %d pce-config has been reached.\n",
MAX_PCE);
XFREE(MTYPE_PCEP, pce_config);
return CMD_WARNING;
}
} else {
vty_out(vty,
"Notice: changes to this pce-config will not affect PCEs already configured with this group\n");
}
current_pcep_config_group_opts_g = pce_config;
vty->node = PCEP_PCE_CONFIG_NODE;
return CMD_SUCCESS;
}
static int path_pcep_cli_pcep_pce_config_delete(struct vty *vty,
const char *pcep_pce_config)
{
struct pcep_config_group_opts *pce_config =
pcep_cli_find_pcep_pce_config(pcep_pce_config);
if (pce_config == NULL) {
vty_out(vty,
"%% Cannot delete pce-config, since it does not exist.\n");
return CMD_WARNING;
}
if (pcep_cli_is_pcep_pce_config_used(pce_config->name)) {
vty_out(vty,
"%% Cannot delete pce-config, since it is in use by a peer.\n");
return CMD_WARNING;
}
pcep_cli_delete_pcep_pce_config(pce_config->name);
return CMD_SUCCESS;
}
static int path_pcep_cli_show_srte_pcep_pce_config(struct vty *vty,
const char *pcep_pce_config)
{
char buf[1024] = "";
/* Only show 1 Peer config group */
struct pcep_config_group_opts *group_opts;
if (pcep_pce_config != NULL) {
if (strcmp(pcep_pce_config, "default") == 0) {
group_opts = &default_pcep_config_group_opts_g;
} else {
group_opts =
pcep_cli_find_pcep_pce_config(pcep_pce_config);
}
if (group_opts == NULL) {
vty_out(vty, "%% pce-config [%s] does not exist.\n",
pcep_pce_config);
return CMD_WARNING;
}
vty_out(vty, "pce-config: %s\n", group_opts->name);
pcep_cli_print_pce_config(group_opts, buf, sizeof(buf));
vty_out(vty, "%s", buf);
return CMD_SUCCESS;
}
/* Show all Peer config groups */
for (int i = 0; i < MAX_PCE; i++) {
group_opts = pcep_g->config_group_opts[i];
if (group_opts == NULL) {
continue;
}
vty_out(vty, "pce-config: %s\n", group_opts->name);
pcep_cli_print_pce_config(group_opts, buf, sizeof(buf));
vty_out(vty, "%s", buf);
buf[0] = 0;
}
return CMD_SUCCESS;
}
static int path_pcep_cli_pce(struct vty *vty, const char *pce_peer_name)
{
/* If it already exists, it will be updated in the sub-commands */
struct pce_opts_cli *pce_opts_cli = pcep_cli_find_pce(pce_peer_name);
if (pce_opts_cli == NULL) {
pce_opts_cli = pcep_cli_create_pce_opts(pce_peer_name);
if (!pcep_cli_add_pce(pce_opts_cli)) {
vty_out(vty,
"%% Cannot create PCE, as the Maximum limit of %d PCEs has been reached.\n",
MAX_PCE);
XFREE(MTYPE_PCEP, pce_opts_cli);
return CMD_WARNING;
}
}
current_pce_opts_g = pce_opts_cli;
vty->node = PCEP_PCE_NODE;
return CMD_SUCCESS;
}
static int path_pcep_cli_pce_delete(struct vty *vty, const char *pce_peer_name)
{
struct pce_opts_cli *pce_opts_cli = pcep_cli_find_pce(pce_peer_name);
if (pce_opts_cli == NULL) {
vty_out(vty, "%% PCC peer does not exist.\n");
return CMD_WARNING;
}
/* To better work with frr-reload, go ahead and delete it if its in use
*/
if (pcep_cli_pcc_has_pce(pce_peer_name)) {
vty_out(vty,
"%% Notice: the pce is in use by a PCC, also disconnecting.\n");
path_pcep_cli_pcc_pcc_peer_delete(vty, pce_peer_name, NULL, 0);
}
pcep_cli_delete_pce(pce_peer_name);
return CMD_SUCCESS;
}
/* Internal Util func to show an individual PCE,
* only used by path_pcep_cli_show_srte_pcep_pce() */
static void show_pce_peer(struct vty *vty, struct pce_opts_cli *pce_opts_cli)
{
struct pce_opts *pce_opts = &pce_opts_cli->pce_opts;
vty_out(vty, "PCE: %s\n", pce_opts->pce_name);
/* Remote PCE IP address */
if (IS_IPADDR_V6(&pce_opts->addr)) {
vty_out(vty, " %s %s %pI6 %s %d\n", PCEP_VTYSH_ARG_ADDRESS,
PCEP_VTYSH_ARG_IPV6, &pce_opts->addr.ipaddr_v6,
PCEP_VTYSH_ARG_PORT, pce_opts->port);
} else {
vty_out(vty, " %s %s %pI4 %s %d\n", PCEP_VTYSH_ARG_ADDRESS,
PCEP_VTYSH_ARG_IP, &pce_opts->addr.ipaddr_v4,
PCEP_VTYSH_ARG_PORT, pce_opts->port);
}
if (pce_opts_cli->config_group_name[0] != '\0') {
vty_out(vty, " pce-config: %s\n",
pce_opts_cli->config_group_name);
}
char buf[1024] = "";
pcep_cli_print_pce_config(&pce_opts->config_opts, buf, sizeof(buf));
vty_out(vty, "%s", buf);
}
static int path_pcep_cli_show_srte_pcep_pce(struct vty *vty,
const char *pce_peer)
{
/* Only show 1 PCE */
struct pce_opts_cli *pce_opts_cli;
if (pce_peer != NULL) {
pce_opts_cli = pcep_cli_find_pce(pce_peer);
if (pce_opts_cli == NULL) {
vty_out(vty, "%% PCE [%s] does not exist.\n", pce_peer);
return CMD_WARNING;
}
pcep_cli_merge_pcep_pce_config_options(pce_opts_cli);
show_pce_peer(vty, pce_opts_cli);
return CMD_SUCCESS;
}
/* Show all PCEs */
for (int i = 0; i < MAX_PCE; i++) {
pce_opts_cli = pcep_g->pce_opts_cli[i];
if (pce_opts_cli == NULL) {
continue;
}
pcep_cli_merge_pcep_pce_config_options(pce_opts_cli);
show_pce_peer(vty, pce_opts_cli);
}
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_sr_draft07(struct vty *vty)
{
struct pcep_config_group_opts *pce_config = NULL;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = ¤t_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
pce_config->draft07 = true;
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_pce_initiated(struct vty *vty)
{
struct pcep_config_group_opts *pce_config = NULL;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = ¤t_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
pce_config->pce_initiated = true;
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_tcp_md5_auth(struct vty *vty,
const char *tcp_md5_auth)
{
struct pcep_config_group_opts *pce_config = NULL;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = ¤t_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
strlcpy(pce_config->tcp_md5_auth, tcp_md5_auth,
sizeof(pce_config->tcp_md5_auth));
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_address(struct vty *vty, const char *ip_str,
struct in_addr *ip, const char *ipv6_str,
struct in6_addr *ipv6,
const char *port_str, long port)
{
struct pce_opts *pce_opts = NULL;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_opts = ¤t_pce_opts_g->pce_opts;
current_pce_opts_g->merged = false;
} else {
return CMD_ERR_NO_MATCH;
}
if (ipv6_str != NULL) {
pce_opts->addr.ipa_type = IPADDR_V6;
memcpy(&pce_opts->addr.ipaddr_v6, ipv6,
sizeof(struct in6_addr));
} else if (ip_str != NULL) {
pce_opts->addr.ipa_type = IPADDR_V4;
memcpy(&pce_opts->addr.ipaddr_v4, ip, sizeof(struct in_addr));
} else {
return CMD_ERR_NO_MATCH;
}
/* Handle the optional port */
pce_opts->port = PCEP_DEFAULT_PORT;
PCEP_VTYSH_INT_ARG_CHECK(port_str, port, pce_opts->port, 0, 65535);
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_source_address(struct vty *vty,
const char *ip_str,
struct in_addr *ip,
const char *ipv6_str,
struct in6_addr *ipv6,
const char *port_str, long port)
{
struct pcep_config_group_opts *pce_config = NULL;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = ¤t_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
/* Handle the optional source IP */
if (ipv6_str != NULL) {
pce_config->source_ip.ipa_type = IPADDR_V6;
memcpy(&pce_config->source_ip.ipaddr_v6, ipv6,
sizeof(struct in6_addr));
} else if (ip_str != NULL) {
pce_config->source_ip.ipa_type = IPADDR_V4;
memcpy(&pce_config->source_ip.ipaddr_v4, ip,
sizeof(struct in_addr));
}
/* Handle the optional port */
PCEP_VTYSH_INT_ARG_CHECK(port_str, port, pce_config->source_port, 0,
65535);
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_pcep_pce_config_ref(struct vty *vty,
const char *config_group_name)
{
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
current_pce_opts_g->merged = false;
} else {
return CMD_ERR_NO_MATCH;
}
struct pcep_config_group_opts *pce_config =
pcep_cli_find_pcep_pce_config(config_group_name);
if (pce_config == NULL) {
vty_out(vty, "%% pce-config [%s] does not exist.\n",
config_group_name);
return CMD_WARNING;
}
strlcpy(current_pce_opts_g->config_group_name, config_group_name,
sizeof(current_pce_opts_g->config_group_name));
return CMD_SUCCESS;
}
static int path_pcep_cli_peer_timers(
struct vty *vty, const char *keep_alive_str, long keep_alive,
const char *min_peer_keep_alive_str, long min_peer_keep_alive,
const char *max_peer_keep_alive_str, long max_peer_keep_alive,
const char *dead_timer_str, long dead_timer,
const char *min_peer_dead_timer_str, long min_peer_dead_timer,
const char *max_peer_dead_timer_str, long max_peer_dead_timer,
const char *pcep_request_str, long pcep_request,
const char *session_timeout_interval_str, long session_timeout_interval,
const char *delegation_timeout_str, long delegation_timeout)
{
struct pcep_config_group_opts *pce_config = NULL;
if (vty->node == PCEP_PCE_NODE) {
/* TODO need to see if the pce is in use, and reset the
* connection */
pce_config = ¤t_pce_opts_g->pce_config_group_opts;
current_pce_opts_g->merged = false;
} else if (vty->node == PCEP_PCE_CONFIG_NODE) {
pce_config = current_pcep_config_group_opts_g;
} else {
return CMD_ERR_NO_MATCH;
}
if (min_peer_keep_alive && max_peer_keep_alive)
if (min_peer_keep_alive >= max_peer_keep_alive) {
return CMD_ERR_NO_MATCH;
}
if (min_peer_dead_timer && max_peer_dead_timer)
if (min_peer_dead_timer >= max_peer_dead_timer) {
return CMD_ERR_NO_MATCH;
}
/* Handle the arguments */
PCEP_VTYSH_INT_ARG_CHECK(keep_alive_str, keep_alive,
pce_config->keep_alive_seconds, 0, 64);
PCEP_VTYSH_INT_ARG_CHECK(min_peer_keep_alive_str, min_peer_keep_alive,
pce_config->min_keep_alive_seconds, 0, 256);
PCEP_VTYSH_INT_ARG_CHECK(max_peer_keep_alive_str, max_peer_keep_alive,
pce_config->max_keep_alive_seconds, 0, 256);
PCEP_VTYSH_INT_ARG_CHECK(dead_timer_str, dead_timer,
pce_config->dead_timer_seconds, 3, 256);
PCEP_VTYSH_INT_ARG_CHECK(min_peer_dead_timer_str, min_peer_dead_timer,
pce_config->min_dead_timer_seconds, 3, 256);
PCEP_VTYSH_INT_ARG_CHECK(max_peer_dead_timer_str, max_peer_dead_timer,
pce_config->max_dead_timer_seconds, 3, 256);
PCEP_VTYSH_INT_ARG_CHECK(pcep_request_str, pcep_request,
pce_config->pcep_request_time_seconds, 0, 121);
PCEP_VTYSH_INT_ARG_CHECK(
session_timeout_interval_str, session_timeout_interval,
pce_config->session_timeout_inteval_seconds, 0, 121);
PCEP_VTYSH_INT_ARG_CHECK(delegation_timeout_str, delegation_timeout,
pce_config->delegation_timeout_seconds, 0, 61);
return CMD_SUCCESS;
}
static int path_pcep_cli_pcc(struct vty *vty)
{
VTY_PUSH_CONTEXT_NULL(PCEP_PCC_NODE);
return CMD_SUCCESS;
}
static int path_pcep_cli_pcc_delete(struct vty *vty)
{
/* Clear the pce_connections */
memset(&pce_connections_g, 0, sizeof(pce_connections_g));
pcc_msd_configured_g = false;
pcep_ctrl_remove_pcc(pcep_g->fpt, NULL);
return CMD_SUCCESS;
}
static int path_pcep_cli_pcc_pcc_msd(struct vty *vty, const char *msd_str,
long msd)
{
pcc_msd_configured_g = true;
PCEP_VTYSH_INT_ARG_CHECK(msd_str, msd, pcc_msd_g, 0, 33);