1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
|
/*
* 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 "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_memory.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);
return CMD_SUCCESS;
}
static int path_pcep_cli_pcc_pcc_peer(struct vty *vty, const char *peer_name,
const char *precedence_str,
long precedence)
{
/* Check if the pcc-peer exists */
struct pce_opts_cli *pce_opts_cli = pcep_cli_find_pce(peer_name);
if (pce_opts_cli == NULL) {
vty_out(vty, "%% PCE [%s] does not exist.\n", peer_name);
return CMD_WARNING;
}
struct pce_opts *pce_opts = &pce_opts_cli->pce_opts;
/* Check if the pcc-peer is duplicated */
if (pcep_cli_pcc_has_pce(peer_name)) {
vty_out(vty, "%% The peer [%s] has already been configured.\n",
peer_name);
return CMD_WARNING;
}
/* Get the optional precedence argument */
pce_opts->precedence = DEFAULT_PCE_PRECEDENCE;
PCEP_VTYSH_INT_ARG_CHECK(precedence_str, precedence,
pce_opts->precedence, 0, 256);
/* Finalize the pce_opts config values */
pcep_cli_merge_pcep_pce_config_options(pce_opts_cli);
pcep_cli_add_pce_connection(&pce_opts_cli->pce_opts);
/* Verify the PCE has the IP set */
struct in6_addr zero_v6_addr;
memset(&zero_v6_addr, 0, sizeof(struct in6_addr));
if (memcmp(&pce_opts->addr.ip, &zero_v6_addr, IPADDRSZ(&pce_opts->addr))
== 0) {
vty_out(vty,
"%% The peer [%s] does not have an IP set and cannot be used until it does.\n",
peer_name);
return CMD_WARNING;
}
/* Update the pcc_opts with the source ip, port, and msd */
struct pcc_opts *pcc_opts_copy =
XMALLOC(MTYPE_PCEP, sizeof(struct pcc_opts));
memcpy(&pcc_opts_copy->addr,
&pce_opts_cli->pce_opts.config_opts.source_ip,
sizeof(struct pcc_opts));
pcc_opts_copy->msd = pcc_msd_g;
pcc_opts_copy->port = pce_opts_cli->pce_opts.config_opts.source_port;
if (pcep_ctrl_update_pcc_options(pcep_g->fpt, pcc_opts_copy)) {
return CMD_WARNING;
}
/* Send a copy of the pce_opts, this one is only used for the CLI */
struct pce_opts *pce_opts_copy =
XMALLOC(MTYPE_PCEP, sizeof(struct pce_opts));
memcpy(pce_opts_copy, pce_opts, sizeof(struct pce_opts));
if (pcep_ctrl_update_pce_options(pcep_g->fpt, pce_opts_copy)) {
return CMD_WARNING;
}
return CMD_SUCCESS;
}
static int path_pcep_cli_pcc_pcc_peer_delete(struct vty *vty,
const char *peer_name,
const char *precedence_str,
long precedence)
{
/* Check if the pcc-peer is connected to the PCC */
if (!pcep_cli_pcc_has_pce(peer_name)) {
vty_out(vty,
"%% WARN: The peer [%s] is not connected to the PCC.\n",
peer_name);
return CMD_WARNING;
}
struct pce_opts_cli *pce_opts_cli = pcep_cli_find_pce(peer_name);
pcep_cli_remove_pce_connection(&pce_opts_cli->pce_opts);
/* Send a copy of the pce_opts, this one is used for CLI only */
struct pce_opts *pce_opts_copy =
XMALLOC(MTYPE_PCEP, sizeof(struct pce_opts));
memcpy(pce_opts_copy, &pce_opts_cli->pce_opts, sizeof(struct pce_opts));
pcep_ctrl_remove_pcc(pcep_g->fpt, pce_opts_copy);
return CMD_SUCCESS;
}
static int path_pcep_cli_show_srte_pcep_pcc(struct vty *vty)
{
vty_out(vty, "pcc msd %d\n", pcc_msd_g);
return CMD_SUCCESS;
}
/* Internal util function to print pcep capabilities to a buffer */
static void print_pcep_capabilities(char *buf, size_t buf_len,
pcep_configuration *config)
{
if (config->support_stateful_pce_lsp_update) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_STATEFUL);
}
if (config->support_include_db_version) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_INCL_DB_VER);
}
if (config->support_lsp_triggered_resync) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_LSP_TRIGGERED);
}
if (config->support_lsp_delta_sync) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_LSP_DELTA);
}
if (config->support_pce_triggered_initial_sync) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_PCE_TRIGGERED);
}
if (config->support_sr_te_pst) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_SR_TE_PST);
}
if (config->pcc_can_resolve_nai_to_sid) {
csnprintfrr(buf, buf_len, "%s", PCEP_CLI_CAP_PCC_RESOLVE_NAI);
}
}
/* Internal util function to print a pcep session */
static void print_pcep_session(struct vty *vty, struct pce_opts *pce_opts,
struct pcep_pcc_info *pcc_info)
{
char buf[1024];
buf[0] = '\0';
vty_out(vty, "\nPCE %s\n", pce_opts->pce_name);
/* PCE IP */
if (IS_IPADDR_V4(&pce_opts->addr)) {
vty_out(vty, " PCE IP %pI4 port %d\n",
&pce_opts->addr.ipaddr_v4, pce_opts->port);
} else if (IS_IPADDR_V6(&pce_opts->addr)) {
vty_out(vty, " PCE IPv6 %pI6 port %d\n",
&pce_opts->addr.ipaddr_v6, pce_opts->port);
}
/* PCC IP */
if (IS_IPADDR_V4(&pcc_info->pcc_addr)) {
vty_out(vty, " PCC IP %pI4 port %d\n",
&pcc_info->pcc_addr.ipaddr_v4, pcc_info->pcc_port);
} else if (IS_IPADDR_V6(&pcc_info->pcc_addr)) {
vty_out(vty, " PCC IPv6 %pI6 port %d\n",
&pcc_info->pcc_addr.ipaddr_v6, pcc_info->pcc_port);
}
vty_out(vty, " PCC MSD %d\n", pcc_info->msd);
if (pcc_info->status == PCEP_PCC_OPERATING) {
vty_out(vty, " Session Status UP\n");
} else {
vty_out(vty, " Session Status %s\n",
pcc_status_name(pcc_info->status));
}
if (pcc_info->is_best_multi_pce) {
vty_out(vty, " Precedence %d, best candidate\n",
((pcc_info->precedence > 0) ? pcc_info->precedence
: DEFAULT_PCE_PRECEDENCE));
} else {
vty_out(vty, " Precedence %d\n",
((pcc_info->precedence > 0) ? pcc_info->precedence
: DEFAULT_PCE_PRECEDENCE));
}
vty_out(vty, " Confidence %s\n",
((pcc_info->previous_best) ? "low"
: "normal"));
/* PCEPlib pcep session values, get a thread safe copy of the counters
*/
pcep_session *session =
pcep_ctrl_get_pcep_session(pcep_g->fpt, pcc_info->pcc_id);
/* Config Options values */
struct pcep_config_group_opts *config_opts = &pce_opts->config_opts;
if (session != NULL) {
vty_out(vty, " Timer: KeepAlive config %d, pce-negotiated %d\n",
config_opts->keep_alive_seconds,
session->pcc_config
.keep_alive_pce_negotiated_timer_seconds);
vty_out(vty, " Timer: DeadTimer config %d, pce-negotiated %d\n",
config_opts->dead_timer_seconds,
session->pcc_config.dead_timer_pce_negotiated_seconds);
} else {
vty_out(vty, " Timer: KeepAlive %d\n",
config_opts->keep_alive_seconds);
vty_out(vty, " Timer: DeadTimer %d\n",
config_opts->dead_timer_seconds);
}
vty_out(vty, " Timer: PcRequest %d\n",
config_opts->pcep_request_time_seconds);
vty_out(vty, " Timer: SessionTimeout Interval %d\n",
config_opts->session_timeout_inteval_seconds);
vty_out(vty, " Timer: Delegation Timeout %d\n",
config_opts->delegation_timeout_seconds);
if (strlen(config_opts->tcp_md5_auth) > 0) {
vty_out(vty, " TCP MD5 Auth Str: %s\n",
config_opts->tcp_md5_auth);
} else {
vty_out(vty, " No TCP MD5 Auth\n");
}
if (config_opts->draft07) {
vty_out(vty, " PCE SR Version draft07\n");
} else {
vty_out(vty, " PCE SR Version draft16 and RFC8408\n");
}
vty_out(vty, " Next PcReq ID %d\n", pcc_info->next_reqid);
vty_out(vty, " Next PLSP ID %d\n", pcc_info->next_plspid);
if (session != NULL) {
if (pcc_info->status == PCEP_PCC_SYNCHRONIZING
|| pcc_info->status == PCEP_PCC_OPERATING) {
time_t current_time = time(NULL);
struct tm lt = {0};
/* Just for the timezone */
localtime_r(¤t_time, <);
gmtime_r(&session->time_connected, <);
vty_out(vty,
" Connected for %u seconds, since %d-%02d-%02d %02d:%02d:%02d UTC\n",
(uint32_t)(current_time
- session->time_connected),
lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday,
lt.tm_hour, lt.tm_min, lt.tm_sec);
}
/* PCC capabilities */
buf[0] = '\0';
int index = 0;
if (config_opts->pce_initiated) {
index += csnprintfrr(buf, sizeof(buf), "%s",
PCEP_CLI_CAP_PCC_PCE_INITIATED);
} else {
index += csnprintfrr(buf, sizeof(buf), "%s",
PCEP_CLI_CAP_PCC_INITIATED);
}
print_pcep_capabilities(buf, sizeof(buf) - index,
&session->pcc_config);
vty_out(vty, " PCC Capabilities:%s\n", buf);
/* PCE capabilities */
buf[0] = '\0';
print_pcep_capabilities(buf, sizeof(buf), &session->pce_config);
if (buf[0] != '\0') {
vty_out(vty, " PCE Capabilities:%s\n", buf);
}
XFREE(MTYPE_PCEP, session);
} else {
vty_out(vty, " Detailed session information not available\n");
}
/* Message Counters, get a thread safe copy of the counters */
struct counters_group *group =
pcep_ctrl_get_counters(pcep_g->fpt, pcc_info->pcc_id);
if (group != NULL) {
struct counters_subgroup *rx_msgs =
find_subgroup(group, COUNTER_SUBGROUP_ID_RX_MSG);
struct counters_subgroup *tx_msgs =
find_subgroup(group, COUNTER_SUBGROUP_ID_TX_MSG);
if (rx_msgs != NULL && tx_msgs != NULL) {
vty_out(vty, " PCEP Message Statistics\n");
vty_out(vty, " %27s %6s\n", "Sent", "Rcvd");
for (int i = 0; i < rx_msgs->max_counters; i++) {
struct counter *rx_counter =
rx_msgs->counters[i];
struct counter *tx_counter =
tx_msgs->counters[i];
if (rx_counter != NULL && tx_counter != NULL) {
vty_out(vty, " %20s: %5d %5d\n",
tx_counter->counter_name,
tx_counter->counter_value,
rx_counter->counter_value);
}
}
vty_out(vty, " %20s: %5d %5d\n", "Total",
subgroup_counters_total(tx_msgs),
subgroup_counters_total(rx_msgs));
}
pcep_lib_free_counters(group);
} else {
vty_out(vty, " Counters not available\n");
}
XFREE(MTYPE_PCEP, pcc_info);
}
static int path_pcep_cli_show_srte_pcep_session(struct vty *vty,
const char *pcc_peer)
{
struct pce_opts_cli *pce_opts_cli;
struct pcep_pcc_info *pcc_info;
/* Only show 1 PCEP session */
if (pcc_peer != NULL) {
pce_opts_cli = pcep_cli_find_pce(pcc_peer);
if (pce_opts_cli == NULL) {
vty_out(vty, "%% PCE [%s] does not exist.\n", pcc_peer);
return CMD_WARNING;
}
if (!pcep_cli_pcc_has_pce(pcc_peer)) {
vty_out(vty, "%% PCC is not connected to PCE [%s].\n",
pcc_peer);
return CMD_WARNING;
}
pcc_info = pcep_ctrl_get_pcc_info(pcep_g->fpt, pcc_peer);
if (pcc_info == NULL) {
vty_out(vty,
"%% Cannot retrieve PCEP session info for PCE [%s]\n",
pcc_peer);
return CMD_WARNING;
}
print_pcep_session(vty, &pce_opts_cli->pce_opts, pcc_info);
return CMD_SUCCESS;
}
/* Show all PCEP sessions */
struct pce_opts *pce_opts;
int num_pcep_sessions_conf = 0;
int num_pcep_sessions_conn = 0;
for (int i = 0; i < MAX_PCC; i++) {
pce_opts = pce_connections_g.connections[i];
if (pce_opts == NULL) {
continue;
}
pcc_info =
pcep_ctrl_get_pcc_info(pcep_g->fpt, pce_opts->pce_name);
if (pcc_info == NULL) {
vty_out(vty,
"%% Cannot retrieve PCEP session info for PCE [%s]\n",
pce_opts->pce_name);
continue;
}
num_pcep_sessions_conn +=
pcc_info->status == PCEP_PCC_OPERATING ? 1 : 0;
num_pcep_sessions_conf++;
print_pcep_session(vty, pce_opts, pcc_info);
}
vty_out(vty, "PCEP Sessions => Configured %d ; Connected %d\n",
num_pcep_sessions_conf, num_pcep_sessions_conn);
return CMD_SUCCESS;
}
static int path_pcep_cli_clear_srte_pcep_session(struct vty *vty,
const char *pcc_peer)
{
struct pce_opts_cli *pce_opts_cli;
/* Only clear 1 PCEP session */
if (pcc_peer != NULL) {
pce_opts_cli = pcep_cli_find_pce(pcc_peer);
if (pce_opts_cli == NULL) {
vty_out(vty, "%% PCE [%s] does not exist.\n", pcc_peer);
return CMD_WARNING;
}
if (!pcep_cli_pcc_has_pce(pcc_peer)) {
vty_out(vty, "%% PCC is not connected to PCE [%s].\n",
pcc_peer);
return CMD_WARNING;
}
pcep_ctrl_reset_pcc_session(pcep_g->fpt,
pce_opts_cli->pce_opts.pce_name);
vty_out(vty, "PCEP session cleared for peer %s\n", pcc_peer);
return CMD_SUCCESS;
}
/* Clear all PCEP sessions */
struct pce_opts *pce_opts;
int num_pcep_sessions = 0;
for (int i = 0; i < MAX_PCC; i++) {
pce_opts = pce_connections_g.connections[i];
if (pce_opts == NULL) {
continue;
}
num_pcep_sessions++;
pcep_ctrl_reset_pcc_session(pcep_g->fpt, pce_opts->pce_name);
vty_out(vty, "PCEP session cleared for peer %s\n",
pce_opts->pce_name);
}
vty_out(vty, "Cleared [%d] PCEP sessions\n", num_pcep_sessions);
return CMD_SUCCESS;
}
/*
* Config Write functions
*/
int pcep_cli_debug_config_write(struct vty *vty)
{
char buff[128] = "";
if (DEBUG_MODE_CHECK(&pcep_g->dbg, DEBUG_MODE_CONF)) {
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC))
csnprintfrr(buff, sizeof(buff), " %s",
PCEP_VTYSH_ARG_BASIC);
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH))
csnprintfrr(buff, sizeof(buff), " %s",
PCEP_VTYSH_ARG_PATH);
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP))
csnprintfrr(buff, sizeof(buff), " %s",
PCEP_VTYSH_ARG_MESSAGE);
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB))
csnprintfrr(buff, sizeof(buff), " %s",
PCEP_VTYSH_ARG_PCEPLIB);
vty_out(vty, "debug pathd pcep%s\n", buff);
buff[0] = 0;
return 1;
}
return 0;
}
int pcep_cli_debug_set_all(uint32_t flags, bool set)
{
DEBUG_FLAGS_SET(&pcep_g->dbg, flags, set);
/* If all modes have been turned off, don't preserve options. */
if (!DEBUG_MODE_CHECK(&pcep_g->dbg, DEBUG_MODE_ALL))
DEBUG_CLEAR(&pcep_g->dbg);
return 0;
}
int pcep_cli_pcep_config_write(struct vty *vty)
{
vty_out(vty, " pcep\n");
return 1;
}
int pcep_cli_pcc_config_write(struct vty *vty)
{
struct pce_opts *pce_opts;
char buf[128] = "";
int lines = 0;
/* The MSD, nor any PCE peers have been configured on the PCC */
if (!pcc_msd_configured_g && pce_connections_g.num_connections == 0) {
return lines;
}
vty_out(vty, " pcc\n");
lines++;
/* Prepare the MSD, if present */
if (pcc_msd_configured_g) {
vty_out(vty, " %s %d\n", PCEP_VTYSH_ARG_MSD, pcc_msd_g);
lines++;
}
if (pce_connections_g.num_connections == 0) {
return lines;
}
buf[0] = 0;
for (int i = 0; i < MAX_PCC; i++) {
pce_opts = pce_connections_g.connections[i];
if (pce_opts == NULL) {
continue;
}
/* Only show the PCEs configured in the pcc sub-command */
if (!pcep_cli_pcc_has_pce(pce_opts->pce_name)) {
continue;
}
csnprintfrr(buf, sizeof(buf), " peer %s",
pce_opts->pce_name);
if (pce_opts->precedence > 0
&& pce_opts->precedence != DEFAULT_PCE_PRECEDENCE) {
csnprintfrr(buf, sizeof(buf), " %s %d",
PCEP_VTYSH_ARG_PRECEDENCE,
pce_opts->precedence);
}
vty_out(vty, "%s\n", buf);
lines++;
buf[0] = 0;
}
return lines;
}
/* Internal function used by pcep_cli_pce_config_write()
* and pcep_cli_pcep_pce_config_write() */
static int pcep_cli_print_pce_config(struct pcep_config_group_opts *group_opts,
char *buf, size_t buf_len)
{
int lines = 0;
if (group_opts->source_ip.ipa_type != IPADDR_NONE
|| group_opts->source_port != 0) {
csnprintfrr(buf, buf_len, " ");
if (IS_IPADDR_V4(&group_opts->source_ip)) {
csnprintfrr(buf, buf_len, " %s %s %pI4",
PCEP_VTYSH_ARG_SOURCE_ADDRESS,
PCEP_VTYSH_ARG_IP,
&group_opts->source_ip.ipaddr_v4);
} else if (IS_IPADDR_V6(&group_opts->source_ip)) {
csnprintfrr(buf, buf_len, " %s %s %pI6",
PCEP_VTYSH_ARG_SOURCE_ADDRESS,
PCEP_VTYSH_ARG_IPV6,
&group_opts->source_ip.ipaddr_v6);
}
if (group_opts->source_port > 0) {
csnprintfrr(buf, buf_len, " %s %d", PCEP_VTYSH_ARG_PORT,
group_opts->source_port);
}
csnprintfrr(buf, buf_len, "\n");
lines++;
}
/* Group the keep-alive together for devman */
if ((group_opts->keep_alive_seconds > 0)
|| (group_opts->min_keep_alive_seconds > 0)
|| (group_opts->max_keep_alive_seconds > 0)) {
csnprintfrr(buf, buf_len, " %s", PCEP_VTYSH_ARG_TIMER);
if (group_opts->keep_alive_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %d",
PCEP_VTYSH_ARG_KEEP_ALIVE,
group_opts->keep_alive_seconds);
}
if (group_opts->min_keep_alive_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %d",
PCEP_VTYSH_ARG_KEEP_ALIVE_MIN,
group_opts->min_keep_alive_seconds);
}
if (group_opts->max_keep_alive_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %d",
PCEP_VTYSH_ARG_KEEP_ALIVE_MAX,
group_opts->max_keep_alive_seconds);
}
csnprintfrr(buf, buf_len, "\n");
lines++;
}
/* Group the dead-timer together for devman */
if ((group_opts->dead_timer_seconds > 0)
|| (group_opts->min_dead_timer_seconds > 0)
|| (group_opts->max_dead_timer_seconds > 0)) {
csnprintfrr(buf, buf_len, " %s", PCEP_VTYSH_ARG_TIMER);
if (group_opts->dead_timer_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %d",
PCEP_VTYSH_ARG_DEAD_TIMER,
group_opts->dead_timer_seconds);
}
if (group_opts->min_dead_timer_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %d",
PCEP_VTYSH_ARG_DEAD_TIMER_MIN,
group_opts->min_dead_timer_seconds);
}
if (group_opts->max_dead_timer_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %d",
PCEP_VTYSH_ARG_DEAD_TIMER_MAX,
group_opts->max_dead_timer_seconds);
}
csnprintfrr(buf, buf_len, "\n");
lines++;
}
if (group_opts->pcep_request_time_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %s %d\n",
PCEP_VTYSH_ARG_TIMER, PCEP_VTYSH_ARG_PCEP_REQUEST,
group_opts->pcep_request_time_seconds);
lines++;
}
if (group_opts->delegation_timeout_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %s %d\n",
PCEP_VTYSH_ARG_TIMER,
PCEP_VTYSH_ARG_DELEGATION_TIMEOUT,
group_opts->delegation_timeout_seconds);
lines++;
}
if (group_opts->session_timeout_inteval_seconds > 0) {
csnprintfrr(buf, buf_len, " %s %s %d\n",
PCEP_VTYSH_ARG_TIMER,
PCEP_VTYSH_ARG_SESSION_TIMEOUT,
group_opts->session_timeout_inteval_seconds);
lines++;
}
if (group_opts->tcp_md5_auth[0] != '\0') {
csnprintfrr(buf, buf_len, " %s %s\n", PCEP_VTYSH_ARG_TCP_MD5,
group_opts->tcp_md5_auth);
lines++;
}
if (group_opts->draft07) {
csnprintfrr(buf, buf_len, " %s\n",
PCEP_VTYSH_ARG_SR_DRAFT07);
lines++;
}
if (group_opts->pce_initiated) {
csnprintfrr(buf, buf_len, " %s\n", PCEP_VTYSH_ARG_PCE_INIT);
lines++;
}
return lines;
}
int pcep_cli_pce_config_write(struct vty *vty)
{
int lines = 0;
char buf[1024] = "";
for (int i = 0; i < MAX_PCE; i++) {
struct pce_opts_cli *pce_opts_cli = pcep_g->pce_opts_cli[i];
if (pce_opts_cli == NULL) {
continue;
}
struct pce_opts *pce_opts = &pce_opts_cli->pce_opts;
vty_out(vty, " pce %s\n", pce_opts->pce_name);
if (IS_IPADDR_V6(&pce_opts->addr)) {
vty_out(vty, " %s %s %pI6", PCEP_VTYSH_ARG_ADDRESS,
PCEP_VTYSH_ARG_IPV6, &pce_opts->addr.ipaddr_v6);
} else if (IS_IPADDR_V4(&pce_opts->addr)) {
vty_out(vty, " address %s %pI4", PCEP_VTYSH_ARG_IP,
&pce_opts->addr.ipaddr_v4);
}
if (pce_opts->port != PCEP_DEFAULT_PORT) {
vty_out(vty, " %s %d", PCEP_VTYSH_ARG_PORT,
pce_opts->port);
}
vty_out(vty, "%s\n", buf);
lines += 2;
if (pce_opts_cli->config_group_name[0] != '\0') {
vty_out(vty, " config %s\n",
pce_opts_cli->config_group_name);
lines++;
}
/* Only display the values configured on the PCE, not the values
* from its optional pce-config-group, nor the default values */
lines += pcep_cli_print_pce_config(
&pce_opts_cli->pce_config_group_opts, buf, sizeof(buf));
vty_out(vty, "%s", buf);
buf[0] = '\0';
}
return lines;
}
int pcep_cli_pcep_pce_config_write(struct vty *vty)
{
int lines = 0;
char buf[1024] = "";
for (int i = 0; i < MAX_PCE; i++) {
struct pcep_config_group_opts *group_opts =
pcep_g->config_group_opts[i];
if (group_opts == NULL) {
continue;
}
vty_out(vty, " pce-config %s\n", group_opts->name);
lines += 1;
lines +=
pcep_cli_print_pce_config(group_opts, buf, sizeof(buf));
vty_out(vty, "%s", buf);
buf[0] = 0;
}
return lines;
}
/*
* VTYSH command syntax definitions
* The param names are taken from the path_pcep_cli_clippy.c generated file.
*/
DEFPY(show_debugging_pathd_pcep,
show_debugging_pathd_pcep_cmd,
"show debugging pathd-pcep",
SHOW_STR
"State of each debugging option\n"
"pathd pcep module debugging\n")
{
vty_out(vty, "Pathd pcep debugging status:\n");
if (DEBUG_MODE_CHECK(&pcep_g->dbg, DEBUG_MODE_CONF)) {
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC))
vty_out(vty, " Pathd pcep %s debugging is on\n",
PCEP_VTYSH_ARG_BASIC);
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH))
vty_out(vty, " Pathd pcep %s debugging is on\n",
PCEP_VTYSH_ARG_PATH);
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP))
vty_out(vty, " Pathd pcep %s debugging is on\n",
PCEP_VTYSH_ARG_MESSAGE);
if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB))
vty_out(vty, " Pathd pcep %s debugging is on\n",
PCEP_VTYSH_ARG_PCEPLIB);
}
return CMD_SUCCESS;
}
DEFPY(pcep_cli_debug,
pcep_cli_debug_cmd,
"[no] debug pathd pcep [basic]$basic_str [path]$path_str [message]$message_str [pceplib]$pceplib_str",
NO_STR DEBUG_STR
"pathd debugging\n"
"pcep module debugging\n"
"module basic debugging\n"
"path structures debugging\n"
"pcep message debugging\n"
"pceplib debugging\n")
{
return path_pcep_cli_debug(vty, no, basic_str, path_str, message_str,
pceplib_str);
}
DEFPY(pcep_cli_show_srte_pcep_counters,
pcep_cli_show_srte_pcep_counters_cmd,
"show sr-te pcep counters",
SHOW_STR
"SR-TE info\n"
"PCEP info\n"
"PCEP counters\n")
{
return path_pcep_cli_show_srte_pcep_counters(vty);
}
DEFPY_NOSH(
pcep_cli_pcep,
pcep_cli_pcep_cmd,
"pcep",
"PCEP configuration\n")
{
vty->node = PCEP_NODE;
return CMD_SUCCESS;
}
DEFPY_NOSH(
pcep_cli_pcep_pce_config,
pcep_cli_pcep_pce_config_cmd,
"[no] pce-config WORD$name",
NO_STR
"Shared configuration\n"
"Shared configuration name\n")
{
if (no == NULL)
return path_pcep_cli_pcep_pce_config(vty, name);
return path_pcep_cli_pcep_pce_config_delete(vty, name);
}
DEFPY(pcep_cli_show_srte_pcep_pce_config,
pcep_cli_show_srte_pcep_pce_config_cmd,
"show sr-te pcep pce-config [<default|WORD>$name]",
SHOW_STR
"SR-TE info\n"
"PCEP info\n"
"Show shared PCE configuration\n"
"Show default hard-coded values\n"
"Shared configuration name\n")
{
return path_pcep_cli_show_srte_pcep_pce_config(vty, name);
}
DEFPY_NOSH(
pcep_cli_pce,
pcep_cli_pce_cmd,
"[no] pce WORD$name",
NO_STR
"PCE configuration, address sub-config is mandatory\n"
"PCE name\n")
{
if (no == NULL)
return path_pcep_cli_pce(vty, name);
return path_pcep_cli_pce_delete(vty, name);
}
DEFPY(pcep_cli_show_srte_pcep_pce,
pcep_cli_show_srte_pcep_pce_cmd,
"show sr-te pcep pce [WORD$name]",
SHOW_STR
"SR-TE info\n"
"PCEP info\n"
"Show detailed pce values\n"
"pce name\n")
{
return path_pcep_cli_show_srte_pcep_pce(vty, name);
}
DEFPY(pcep_cli_peer_sr_draft07,
pcep_cli_peer_sr_draft07_cmd,
"sr-draft07",
"Configure PCC to send PCEP Open with SR draft07\n")
{
return path_pcep_cli_peer_sr_draft07(vty);
}
DEFPY(pcep_cli_peer_pce_initiated,
pcep_cli_peer_pce_initiated_cmd,
"pce-initiated",
"Configure PCC to accept PCE initiated LSPs\n")
{
return path_pcep_cli_peer_pce_initiated(vty);
}
DEFPY(pcep_cli_peer_tcp_md5_auth,
pcep_cli_peer_tcp_md5_auth_cmd,
"tcp-md5-auth WORD",
"Configure PCC TCP-MD5 RFC2385 Authentication\n"
"TCP-MD5 Authentication string\n")
{
return path_pcep_cli_peer_tcp_md5_auth(vty, tcp_md5_auth);
}
DEFPY(pcep_cli_peer_address,
pcep_cli_peer_address_cmd,
"address <ip A.B.C.D | ipv6 X:X::X:X> [port (1024-65535)]",
"PCE IP Address configuration, mandatory configuration\n"
"PCE IPv4 address\n"
"Remote PCE server IPv4 address\n"
"PCE IPv6 address\n"
"Remote PCE server IPv6 address\n"
"Remote PCE server port\n"
"Remote PCE server port value\n")
{
return path_pcep_cli_peer_address(vty, ip_str, &ip, ipv6_str, &ipv6,
port_str, port);
}
DEFPY(pcep_cli_peer_source_address,
pcep_cli_peer_source_address_cmd,
"source-address [ip A.B.C.D | ipv6 X:X::X:X] [port (1024-65535)]",
"PCE source IP Address configuration\n"
"PCE source IPv4 address\n"
"PCE source IPv4 address value\n"
"PCE source IPv6 address\n"
"PCE source IPv6 address value\n"
"Source PCE server port\n"
"Source PCE server port value\n")
{
return path_pcep_cli_peer_source_address(vty, ip_str, &ip, ipv6_str,
&ipv6, port_str, port);
}
DEFPY(pcep_cli_peer_pcep_pce_config_ref,
pcep_cli_peer_pcep_pce_config_ref_cmd,
"config WORD$name",
"PCE shared configuration to use\n"
"Shared configuration name\n")
{
return path_pcep_cli_peer_pcep_pce_config_ref(vty, name);
}
DEFPY(pcep_cli_peer_timers,
pcep_cli_peer_timers_cmd,
"timer [keep-alive (1-63)] [min-peer-keep-alive (1-255)] [max-peer-keep-alive (1-255)] "
"[dead-timer (4-255)] [min-peer-dead-timer (4-255)] [max-peer-dead-timer (4-255)] "
"[pcep-request (1-120)] [session-timeout-interval (1-120)] [delegation-timeout (1-60)]",
"PCE PCEP Session Timers configuration\n"
"PCC Keep Alive Timer\n"
"PCC Keep Alive Timer value in seconds\n"
"Min Acceptable PCE Keep Alive Timer\n"
"Min Acceptable PCE Keep Alive Timer value in seconds\n"
"Max Acceptable PCE Keep Alive Timer\n"
"Max Acceptable PCE Keep Alive Timer value in seconds\n"
"PCC Dead Timer\n"
"PCC Dead Timer value in seconds\n"
"Min Acceptable PCE Dead Timer\n"
"Min Acceptable PCE Dead Timer value in seconds\n"
"Max Acceptable PCE Dead Timer\n"
"Max Acceptable PCE Dead Timer value in seconds\n"
"PCC PCEP Request Timer\n"
"PCC PCEP Request Timer value in seconds\n"
"PCC Session Timeout Interval\n"
"PCC Session Timeout Interval value in seconds\n"
"Multi-PCE delegation timeout\n"
"Multi-PCE delegation timeout value in seconds\n")
{
return path_pcep_cli_peer_timers(
vty, keep_alive_str, keep_alive, min_peer_keep_alive_str,
min_peer_keep_alive, max_peer_keep_alive_str,
max_peer_keep_alive, dead_timer_str, dead_timer,
min_peer_dead_timer_str, min_peer_dead_timer,
max_peer_dead_timer_str, max_peer_dead_timer, pcep_request_str,
pcep_request, session_timeout_interval_str,
session_timeout_interval, delegation_timeout_str,
delegation_timeout);
}
DEFPY_NOSH(
pcep_cli_pcc,
pcep_cli_pcc_cmd,
"[no] pcc",
NO_STR
"PCC configuration\n")
{
if (no != NULL) {
return path_pcep_cli_pcc_delete(vty);
} else {
return path_pcep_cli_pcc(vty);
}
}
DEFPY(pcep_cli_pcc_pcc_msd,
pcep_cli_pcc_pcc_msd_cmd,
"msd (1-32)",
"PCC maximum SID depth \n"
"PCC maximum SID depth value\n")
{
return path_pcep_cli_pcc_pcc_msd(vty, msd_str, msd);
}
DEFPY(pcep_cli_pcc_pcc_peer,
pcep_cli_pcc_pcc_peer_cmd,
"[no] peer WORD [precedence (1-255)]",
NO_STR
"PCC PCE peer\n"
"PCC PCE name\n"
"PCC Multi-PCE precedence\n"
"PCE precedence\n")
{
if (no != NULL) {
return path_pcep_cli_pcc_pcc_peer_delete(
vty, peer, precedence_str, precedence);
} else {
return path_pcep_cli_pcc_pcc_peer(vty, peer, precedence_str,
precedence);
}
}
DEFPY(pcep_cli_show_srte_pcc,
pcep_cli_show_srte_pcc_cmd,
"show sr-te pcep pcc",
SHOW_STR
"SR-TE info\n"
"PCEP info\n"
"Show current PCC configuration\n")
{
return path_pcep_cli_show_srte_pcep_pcc(vty);
}
DEFPY(pcep_cli_show_srte_pcep_session,
pcep_cli_show_srte_pcep_session_cmd,
"show sr-te pcep session [WORD]$pce",
SHOW_STR
"SR-TE info\n"
"PCEP info\n"
"Show PCEP Session information\n"
"PCE name\n")
{
return path_pcep_cli_show_srte_pcep_session(vty, pce);
}
DEFPY(pcep_cli_clear_srte_pcep_session,
pcep_cli_clear_srte_pcep_session_cmd,
"clear sr-te pcep session [WORD]$pce",
CLEAR_STR
"SR-TE\n"
"PCEP\n"
"Reset PCEP connection\n"
"PCE name\n")
{
return path_pcep_cli_clear_srte_pcep_session(vty, pce);
}
void pcep_cli_init(void)
{
hook_register(nb_client_debug_config_write,
pcep_cli_debug_config_write);
hook_register(nb_client_debug_set_all, pcep_cli_debug_set_all);
memset(&pce_connections_g, 0, sizeof(pce_connections_g));
install_node(&pcep_node);
install_node(&pcep_pcc_node);
install_node(&pcep_pce_node);
install_node(&pcep_pce_config_node);
install_default(PCEP_PCE_CONFIG_NODE);
install_default(PCEP_PCE_NODE);
install_default(PCEP_PCC_NODE);
install_default(PCEP_NODE);
install_element(SR_TRAFFIC_ENG_NODE, &pcep_cli_pcep_cmd);
/* PCEP configuration group related configuration commands */
install_element(PCEP_NODE, &pcep_cli_pcep_pce_config_cmd);
install_element(PCEP_PCE_CONFIG_NODE,
&pcep_cli_peer_source_address_cmd);
install_element(PCEP_PCE_CONFIG_NODE, &pcep_cli_peer_timers_cmd);
install_element(PCEP_PCE_CONFIG_NODE, &pcep_cli_peer_sr_draft07_cmd);
install_element(PCEP_PCE_CONFIG_NODE, &pcep_cli_peer_pce_initiated_cmd);
install_element(PCEP_PCE_CONFIG_NODE, &pcep_cli_peer_tcp_md5_auth_cmd);
/* PCE peer related configuration commands */
install_element(PCEP_NODE, &pcep_cli_pce_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_address_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_source_address_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_pcep_pce_config_ref_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_timers_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_sr_draft07_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_pce_initiated_cmd);
install_element(PCEP_PCE_NODE, &pcep_cli_peer_tcp_md5_auth_cmd);
/* PCC related configuration commands */
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcc_cmd);
install_element(PCEP_NODE, &pcep_cli_pcc_cmd);
install_element(PCEP_PCC_NODE, &pcep_cli_pcc_pcc_peer_cmd);
install_element(PCEP_PCC_NODE, &pcep_cli_pcc_pcc_msd_cmd);
/* Top commands */
install_element(CONFIG_NODE, &pcep_cli_debug_cmd);
install_element(ENABLE_NODE, &pcep_cli_debug_cmd);
install_element(ENABLE_NODE, &show_debugging_pathd_pcep_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_counters_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_pce_config_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_pce_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_session_cmd);
install_element(ENABLE_NODE, &pcep_cli_clear_srte_pcep_session_cmd);
}
|