summaryrefslogtreecommitdiff
path: root/scripts/bgp/vyatta-bgp.pl
blob: e206fc3f2740ad8909daf7a5b4587a0dec559e44 (plain)
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
#!/usr/bin/perl
# **** License ****
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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.
#
# A copy of the GNU General Public License is available as
# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution
# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'.
# You can also obtain it by writing to the Free Software Foundation,
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2009,2010 Vyatta, Inc.
# All Rights Reserved.
#
# Author: Various
# Date: 2009-2010
# Description: Script to setup Quagga BGP configuration
#
# **** End License ****
#

use strict;
use warnings;

use Getopt::Long;
use NetAddr::IP::Lite;

use lib "/opt/vyatta/share/perl5/";
use Vyatta::Config;
use Vyatta::Quagga::Config;
use Vyatta::Misc;

my %qcom = (
  'protocols' => {
      set => undef,
      del => undef,
  },
  'protocols bgp' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var' => {
      set => 'router bgp #3',
      del => 'no router bgp #3',
  },
  'protocols bgp var address-family' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv6-unicast' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv6-unicast aggregate-address' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv6-unicast aggregate-address var' => {
      set => 'router bgp #3 ; address-family ipv6 ; aggregate-address #7 ?summary-only ?route-map',
      del => 'router bgp #3 ; address-family ipv6 ; no aggregate-address #7 ?summary-only ?route-map',
  },
  'protocols bgp var address-family ipv6-unicast network' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv6-unicast network var' => {
      set => 'router bgp #3 ; address-family ipv6 ; network #7',
      del => 'router bgp #3 ; address-family ipv6 ; no network #7',
  },
  'protocols bgp var address-family ipv6-unicast network var route-map' => {
      set => 'router bgp #3 ; address-family ipv6 ; network #7 route-map #9',
      del => 'router bgp #3 ; address-family ipv6 ; no network #7 route-map #9',
  },
  'protocols bgp var address-family ipv6-unicast network var path-limit' => {
      set => 'router bgp #3 ; address-family ipv6 ; network #7 pathlimit #9',
      del => 'router bgp #3 ; address-family ipv6 ; no network #7 pathlimit #9',
  },
  'protocols bgp var address-family ipv6-unicast maximum-paths' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv6-unicast maximum-paths ebgp' => {
      set => 'router bgp #3 ; address-family ipv6 ; maximum-paths #8',
      del => 'router bgp #3 ; address-family ipv6 ; no maximum-paths #8',
  },
  'protocols bgp var address-family ipv6-unicast maximum-paths ibgp' => {
      set => 'router bgp #3 ; address-family ipv6 ; maximum-paths ibgp #8',
      del => 'router bgp #3 ; address-family ipv6 ; no maximum-paths ibgp #8',
  },
  'protocols bgp var address-family ipv6-unicast redistribute' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv6-unicast redistribute connected' => {
      set => 'router bgp #3 ; address-family ipv6 ; redistribute connected',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute connected',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv6-unicast redistribute connected metric' => {
      set => 'router bgp #3 ; address-family ipv6 ; redistribute connected metric #9',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute connected metric #9',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv6-unicast redistribute connected route-map' => {
      set => 'router bgp #3 ; address-family ipv6 ; redistribute connected route-map #9',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute connected route-map #9',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv6-unicast redistribute kernel' => {
      set => 'router bgp #3 ; address-family ipv6 ; no redistribute kernel ; redistribute kernel ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute kernel',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv6-unicast redistribute ospfv3' => {
      set => 'router bgp #3 ; address-family ipv6 ; no redistribute ospf6 ; redistribute ospf6 ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute ospf6',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv6-unicast redistribute ripng' => {
      set => 'router bgp #3 ; address-family ipv6 ; no redistribute ripng ; redistribute ripng ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute ripng',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv6-unicast redistribute static' => {
      set => 'router bgp #3 ; address-family ipv6 ; no redistribute static ; redistribute static ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv6 ; no redistribute static',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv4-unicast aggregate-address' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv4-unicast aggregate-address var' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; aggregate-address #7 ?as-set ?summary-only ?route-map',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no aggregate-address #7 ?as-set ?summary-only ?route-map',
  },
  'protocols bgp var address-family ipv4-unicast network' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv4-unicast network var' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; network #7 ?backdoor',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no network #7',
  },
  'protocols bgp var address-family ipv4-unicast network var route-map' => {
      set => 'router bgp #3 ; network #7 route-map #9',
      del => 'router bgp #3 ; no network #7 route-map #9 ; network #7',
  },
  'protocols bgp var address-family ipv4-unicast maximum-paths' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv4-unicast maximum-paths ebgp' => {
      set => 'router bgp #3 ; address-family ipv4 ; maximum-paths #8',
      del => 'router bgp #3 ; address-family ipv4 ; no maximum-paths #8',
  },
  'protocols bgp var address-family ipv4-unicast maximum-paths ibgp' => {
      set => 'router bgp #3 ; address-family ipv4 ; maximum-paths ibgp #8',
      del => 'router bgp #3 ; address-family ipv4 ; no maximum-paths ibgp #8',
  },
  'protocols bgp var address-family ipv4-unicast redistribute' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var address-family ipv4-unicast redistribute connected' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; redistribute connected ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute connected',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute connected metric' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; redistribute connected metric #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute connected metric #9',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute connected route-map' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; redistribute connected route-map #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute connected route-map #9',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute isis' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; redistribute isis ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute isis',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute isis metric' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; redistribute isis metric #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute isis metric #9',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute isis route-map' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; redistribute isis route-map #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute isis route-map #9',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute kernel' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute kernel ; redistribute kernel ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute kernel',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute ospf' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute ospf ; redistribute ospf ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute ospf',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute rip' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute rip ; redistribute rip ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute rip',
      noerr => 'set',
  },
  'protocols bgp var address-family ipv4-unicast redistribute static' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute static ; redistribute static ?route-map ?metric',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no redistribute static',
      noerr => 'set',
  },
  'protocols bgp var neighbor' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var' => {
      set => undef,
      del => 'router bgp #3 ; no neighbor #5',
      noerr => 'del',
  },
  'protocols bgp var neighbor var address-family' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast weight' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 weight #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 weight #9',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast weight' => {
      set => 'router bgp #3 ; address-family ipv6 unicast ; neighbor #5 weight #9',
      del => 'router bgp #3 ; address-family ipv6 unicast ; no neighbor #5 weight #9',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 activate',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 activate',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast allowas-in' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 allowas-in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 allowas-in',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast allowas-in number' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 allowas-in #10',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 allowas-in ; neighbor #5 allowas-in',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast attribute-unchanged' => {
      set => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 attribute-unchanged ; neighbor #5 attribute-unchanged ?as-path ?med ?next-hop',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 attribute-unchanged',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast capability' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast capability orf' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast capability orf prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast capability orf prefix-list receive' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 capability orf prefix-list receive',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 capability orf prefix-list receive',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast capability orf prefix-list send' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 capability orf prefix-list send',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 capability orf prefix-list send',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast default-originate' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 default-originate',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 default-originate',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast default-originate route-map' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 default-originate route-map #10',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 default-originate route-map #10',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast disable-send-community' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast disable-send-community extended' => {
      set => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 send-community extended',
      del => 'router bgp #3 ; address-family ipv6 ; neighbor #5 send-community extended',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast disable-send-community standard' => {
      set => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 send-community standard',
      del => 'router bgp #3 ; address-family ipv6 ; neighbor #5 send-community standard',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast distribute-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast distribute-list export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 distribute-list #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 distribute-list #10 out',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast distribute-list import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 distribute-list #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 distribute-list #10 in',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast filter-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast filter-list export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 filter-list #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 filter-list #10 out',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast filter-list import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 filter-list #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 filter-list #10 in',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast maximum-prefix' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 maximum-prefix #9',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 maximum-prefix #9',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast nexthop-local' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 nexthop-local unchanged',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 nexthop-local unchanged',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast nexthop-self' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 next-hop-self',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 next-hop-self',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast nexthop-self force' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 next-hop-self force',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 next-hop-self force',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast peer-group' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 peer-group #9',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 peer-group #9 ; neighbor #5 activate',
      noerr => 'del',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast prefix-list export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 prefix-list #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 prefix-list #10 out',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast prefix-list import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 prefix-list #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 prefix-list #10 in',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast remove-private-as' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 remove-private-AS',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 remove-private-AS',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast remove-private-as all' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 remove-private-AS all',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 remove-private-AS all',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast route-map' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast route-map export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-map #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-map #10 out',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast route-map import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-map #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-map #10 in',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast route-reflector-client' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-reflector-client',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-reflector-client',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast route-server-client' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-server-client',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-server-client',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast soft-reconfiguration' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv6-unicast soft-reconfiguration inbound' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 soft-reconfiguration inbound',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 soft-reconfiguration inbound',
  },
  'protocols bgp var neighbor var address-family ipv6-unicast unsuppress-map' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 unsuppress-map #9',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 unsuppress-map #9',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 activate',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 activate',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast allowas-in' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 allowas-in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 allowas-in',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast allowas-in number' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 allowas-in #10',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 allowas-in ; neighbor #5 allowas-in',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast as-override' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 as-override',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 as-override',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast attribute-unchanged' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 attribute-unchanged ; neighbor #5 attribute-unchanged ?as-path ?med ?next-hop',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 attribute-unchanged ?as-path ?med ?next-hop',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast capability' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast capability orf' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast capability orf prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast capability orf prefix-list receive' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 capability orf prefix-list receive',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 capability orf prefix-list receive',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast capability orf prefix-list send' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 capability orf prefix-list send',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 capability orf prefix-list send',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast default-originate' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 default-originate',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 default-originate',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast default-originate route-map' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 default-originate route-map #10',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 default-originate route-map #10',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast disable-send-community' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast disable-send-community extended' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 send-community extended',
      del => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 send-community extended',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast disable-send-community standard' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 send-community standard',
      del => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 send-community standard',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast distribute-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast distribute-list export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 distribute-list #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 distribute-list #10 out',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast distribute-list import' => {
      set => 'router bgp #3 ; neighbor #5 distribute-list #10 in',
      del => 'router bgp #3 ; no neighbor #5 distribute-list #10 in',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast filter-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast filter-list export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 filter-list #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 filter-list #10 out',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast filter-list import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 filter-list #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 filter-list #10 in',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast maximum-prefix' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 maximum-prefix #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 maximum-prefix',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast nexthop-self' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 next-hop-self',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 next-hop-self',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast nexthop-self force' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 next-hop-self force',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 next-hop-self force',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast prefix-list export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 prefix-list #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 prefix-list #10 out',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast prefix-list import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 prefix-list #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 prefix-list #10 in',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast remove-private-as' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 remove-private-AS',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 remove-private-AS',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast remove-private-as all' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 remove-private-AS all',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 remove-private-AS all',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast route-map' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast route-map export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-map #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-map #10 out',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast route-map import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-map #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-map #10 in',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast route-reflector-client' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-reflector-client',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-reflector-client',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast route-server-client' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-server-client',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-server-client',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast soft-reconfiguration' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var address-family ipv4-unicast soft-reconfiguration inbound' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 soft-reconfiguration inbound',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 soft-reconfiguration inbound',
  },
  'protocols bgp var neighbor var address-family ipv4-unicast unsuppress-map' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 unsuppress-map #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 unsuppress-map #9',
  },
  'protocols bgp var neighbor var remote-as' => {
      set => 'router bgp #3 ; neighbor #5 remote-as #7 ; neighbor #5 activate',
      del => 'router bgp #3 ; no neighbor #5 remote-as #7',
  },
  'protocols bgp var neighbor var interface' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var interface peer-group' => {
      set => 'router bgp #3 ; neighbor #5 interface peer-group #8',
      del => 'router bgp #3 ; no neighbor #5 interface peer-group #8',
  },
  'protocols bgp var neighbor var interface remote-as' => {
      set => 'router bgp #3 ; neighbor #5 interface remote-as #8',
      del => 'router bgp #3 ; no neighbor #5 interface remote-as #8',
  },
  'protocols bgp var neighbor var interface v6only' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var interface v6only peer-group' => {
      set => 'router bgp #3 ; neighbor #5 interface v6only peer-group #9',
      del => 'router bgp #3 ; no neighbor #5 interface v6only peer-group #9',
  },
  'protocols bgp var neighbor var interface v6only remote-as' => {
      set => 'router bgp #3 ; neighbor #5 interface v6only remote-as #9',
      del => 'router bgp #3 ; no neighbor #5 interface v6only remote-as #9',
  },
  'protocols bgp var neighbor var disable-capability-negotiation' => {
      set => 'router bgp #3 ; neighbor #5 dont-capability-negotiate',
      del => 'router bgp #3 ; no neighbor #5 dont-capability-negotiate',
  },
  'protocols bgp var neighbor var disable-connected-check' => {
      set => 'router bgp #3 ; neighbor #5 disable-connected-check',
      del => 'router bgp #3 ; no neighbor #5 disable-connected-check',
  },
  'protocols bgp var neighbor var ebgp-multihop' => {
      set => 'router bgp #3 ; neighbor #5 ebgp-multihop #7',
      del => 'router bgp #3 ; no neighbor #5 ebgp-multihop',
  },
  'protocols bgp var neighbor var advertisement-interval' => {
      set => 'router bgp #3 ; neighbor #5 advertisement-interval #7',
      del => 'router bgp #3 ; no neighbor #5 advertisement-interval',
  },
  'protocols bgp var neighbor var capability' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var capability dynamic' => {
      set => 'router bgp #3 ; neighbor #5 capability dynamic',
      del => 'router bgp #3 ; no neighbor #5 capability dynamic',
  },
  'protocols bgp var neighbor var capability extended-nexthop' => {
      set => 'router bgp #3 ; neighbor #5 capability extended-nexthop',
      del => 'router bgp #3 ; no neighbor #5 capability extended-nexthop',
  },
  'protocols bgp var neighbor var local-as' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var local-as var' => {
      set => 'router bgp #3 ; no neighbor #5 local-as #7 ; neighbor #5 local-as #7',
      del => 'router bgp #3 ; no neighbor #5 local-as',
  },
  'protocols bgp var neighbor var local-as var no-prepend' => {
      set => 'router bgp #3 ; no neighbor #5 local-as #7 ; neighbor #5 local-as #7 no-prepend',
      del => 'router bgp #3 ; no neighbor #5 local-as #7 no-prepend ; neighbor #5 local-as #7',
  },
  'protocols bgp var neighbor var local-as var no-prepend replace-as' => {
      set => 'router bgp #3 ; no neighbor #5 local-as #7 ; neighbor #5 local-as #7 no-prepend replace-as',
      del => 'router bgp #3 ; neighbor #5 local-as #7 no-prepend',
  },
  'protocols bgp var neighbor var override-capability' => {
      set => 'router bgp #3 ; neighbor #5 override-capability',
      del => 'router bgp #3 ; no neighbor #5 override-capability',
  },
  'protocols bgp var neighbor var passive' => {
      set => 'router bgp #3 ; neighbor #5 passive',
      del => 'router bgp #3 ; no neighbor #5 passive',
  },
  'protocols bgp var neighbor var solo' => {
      set => 'router bgp #3 ; neighbor #5 solo',
      del => 'router bgp #3 ; no neighbor #5 solo',
  },
  'protocols bgp var neighbor var bfd' => {
      set => 'router bgp #3 ; neighbor #5 bfd',
      del => 'router bgp #3 ; no neighbor #5 bfd',
  },
  'protocols bgp var neighbor var bfd check-control-plane-failure' => {
      set => 'router bgp #3 ; neighbor #5 bfd check-control-plane-failure',
      del => 'router bgp #3 ; no neighbor #5 bfd check-control-plane-failure',
  },
  'protocols bgp var neighbor var password' => {
      set => 'router bgp #3 ; neighbor #5 password #7',
      del => 'router bgp #3 ; no neighbor #5 password',
  },
  'protocols bgp var neighbor var peer-group' => {
      set => 'router bgp #3 ; neighbor #5 peer-group #7',
      del => 'router bgp #3 ; no neighbor #5 peer-group #7',
      noerr => 'del',
  },
  'protocols bgp var neighbor var port' => {
      set => 'router bgp #3 ; neighbor #5 port #7',
      del => 'router bgp #3 ; no neighbor #5 port',
  },
  'protocols bgp var neighbor var shutdown' => {
      set => 'router bgp #3 ; neighbor #5 shutdown',
      del => 'router bgp #3 ; no neighbor #5 shutdown',
  },
  'protocols bgp var neighbor var strict-capability-match' => {
      set => 'router bgp #3 ; neighbor #5 strict-capability-match',
      del => 'router bgp #3 ; no neighbor #5 strict-capability-match',
  },
  'protocols bgp var neighbor var timers' => {
      set => 'router bgp #3 ; neighbor #5 timers @keepalive @holdtime',
      del => 'router bgp #3 ; no neighbor #5 timers',
  },
  'protocols bgp var neighbor var timers connect' => {
      set => 'router bgp #3 ; neighbor #5 timers connect #8',
      del => 'router bgp #3 ; no neighbor #5 timers connect',
  },
  'protocols bgp var neighbor var ttl-security' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var neighbor var ttl-security hops' => {
      set => 'router bgp #3 ; neighbor #5 ttl-security hops #8',
      del => 'router bgp #3 ; no neighbor #5 ttl-security hops #8',
  },
  'protocols bgp var neighbor var unsuppress-map' => {
      set => 'router bgp #3 ; neighbor #5 unsuppress-map #7',
      del => 'router bgp #3 ; no neighbor #5 unsuppress-map #7',
  },
  'protocols bgp var neighbor var update-source' => {
      set => 'router bgp #3 ; neighbor #5 update-source #7',
      del => 'router bgp #3 ; no neighbor #5 update-source',
  },
  'protocols bgp var neighbor var weight' => {
      set => 'router bgp #3 ; neighbor #5 weight #7',
      del => 'router bgp #3 ; no neighbor #5 weight',
  },
  'protocols bgp var listen' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var listen limit' => {
      set => 'router bgp #3 ; bgp listen limit #6',
      del => 'router bgp #3 ; no bgp listen limit #6',
  },
  'protocols bgp var listen range' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var listen range var' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var listen range var peer-group' => {
      set => 'router bgp #3 ; bgp listen range #6 peer-group #8',
      del => 'router bgp #3 ; no bgp listen range #6 peer-group #8',
  },
  'protocols bgp var parameters' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters always-compare-med' => {
      set => 'router bgp #3 ; bgp always-compare-med',
      del => 'router bgp #3 ; no bgp always-compare-med',
  },
  'protocols bgp var parameters bestpath' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters bestpath as-path' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters bestpath as-path confed' => {
      set => 'router bgp #3 ; bgp bestpath as-path confed',
      del => 'router bgp #3 ; no bgp bestpath as-path confed',
  },
  'protocols bgp var parameters bestpath as-path ignore' => {
      set => 'router bgp #3 ; bgp bestpath as-path ignore',
      del => 'router bgp #3 ; no bgp bestpath as-path ignore',
  },
  'protocols bgp var parameters bestpath as-path multipath-relax' => {
      set => 'router bgp #3 ; bgp bestpath as-path multipath-relax',
      del => 'router bgp #3 ; no bgp bestpath as-path multipath-relax',
  },
  'protocols bgp var parameters bestpath compare-routerid' => {
      set => 'router bgp #3 ; bgp bestpath compare-routerid',
      del => 'router bgp #3 ; no bgp bestpath compare-routerid',
  },
  'protocols bgp var parameters bestpath med' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters bestpath med confed' => {
      set => 'router bgp #3 ; bgp bestpath med confed',
      del => 'router bgp #3 ; no bgp bestpath med confed',
  },
  'protocols bgp var parameters bestpath med missing-as-worst' => {
      set => 'router bgp #3 ; bgp bestpath med missing-as-worst',
      del => 'router bgp #3 ; no bgp bestpath med missing-as-worst',
  },
  'protocols bgp var parameters cluster-id' => {
      set => 'router bgp #3 ; bgp cluster-id #6',
      del => 'router bgp #3 ; no bgp cluster-id #6',
  },
  'protocols bgp var parameters confederation' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters confederation identifier' => {
      set => 'router bgp #3 ; bgp confederation identifier #7',
      del => 'router bgp #3 ; no bgp confederation identifier #7',
  },
  'protocols bgp var parameters confederation peers' => {
      set => 'router bgp #3 ; bgp confederation peers #7',
      del => 'router bgp #3 ; no bgp confederation peers #7',
  },
  'protocols bgp var parameters dampening' => {
      set => 'router bgp #3 ; no bgp dampening ; bgp dampening @half-life @re-use @start-suppress-time @max-suppress-time',
      del => 'router bgp #3 ; no bgp dampening',
  },
  'protocols bgp var parameters default' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters default local-pref' => {
      set => 'router bgp #3 ; bgp default local-preference #7',
      del => 'router bgp #3 ; no bgp default local-preference #7',
  },
  'protocols bgp var parameters default no-ipv4-unicast' => {
      set => 'router bgp #3 ; no bgp default ipv4-unicast',
      del => 'router bgp #3 ; bgp default ipv4-unicast',
  },
  'protocols bgp var parameters deterministic-med' => {
      set => 'router bgp #3 ; bgp deterministic-med',
      del => 'router bgp #3 ; no bgp deterministic-med',
  },
  'protocols bgp var parameters network-import-check' => {
      set => 'router bgp #3 ; bgp network import-check',
      del => 'router bgp #3 ; no bgp network import-check',
  },
  'protocols bgp var parameters distance' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters distance global' => {
      set => 'router bgp #3 ; distance bgp @external @internal @local',
      del => 'router bgp #3 ; no distance bgp',
  },
  'protocols bgp var parameters distance prefix' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters distance prefix var' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters distance prefix var distance' => {
      set => 'router bgp #3 ; distance #9 #7 ',
      del => 'router bgp #3 ; no distance #9 #7',
  },
  'protocols bgp var parameters graceful-restart' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var parameters graceful-restart stalepath-time' => {
      set => 'router bgp #3 ; bgp graceful-restart stalepath-time #7',
      del => 'router bgp #3 ; no bgp graceful-restart stalepath-time #7',
  },
  'protocols bgp var parameters graceful-shutdown' => {
      set => 'router bgp #3 ; bgp graceful-shutdown',
      del => 'router bgp #3 ; no bgp graceful-shutdown',
  },
  'protocols bgp var parameters log-neighbor-changes' => {
      set => 'router bgp #3 ; bgp log-neighbor-changes',
      del => 'router bgp #3 ; no bgp log-neighbor-changes',
  },
  'protocols bgp var parameters no-client-to-client-reflection' => {
      set => 'router bgp #3 ; no bgp client-to-client reflection',
      del => 'router bgp #3 ; bgp client-to-client reflection',
  },
  'protocols bgp var parameters no-fast-external-failover' => {
      set => 'router bgp #3 ; no bgp fast-external-failover',
      del => 'router bgp #3 ; bgp fast-external-failover',
  },
  'protocols bgp var parameters router-id' => {
      set => 'router bgp #3 ; bgp router-id #6',
      del => 'router bgp #3 ; no bgp router-id #6',
  },
  'protocols bgp var peer-group' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var' => {
      set => 'router bgp #3 ; neighbor #5 peer-group',
      del => 'router bgp #3 ; no neighbor #5',
      noerr => 'set',
  },
  'protocols bgp var peer-group var address-family' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 activate',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 activate',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast allowas-in' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 allowas-in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 allowas-in',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast allowas-in number' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 allowas-in #10',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 allowas-in ; neighbor #5 allowas-in',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast attribute-unchanged' => {
      set => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 attribute-unchanged ; neighbor #5 attribute-unchanged ?as-path ?med ?next-hop',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 attribute-unchanged',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast capability' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast capability orf' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast capability orf prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast capability orf prefix-list receive' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 capability orf prefix-list receive',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 capability orf prefix-list receive',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast capability orf prefix-list send' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 capability orf prefix-list send',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 capability orf prefix-list send',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast default-originate' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 default-originate',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 default-originate',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast default-originate route-map' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 default-originate route-map #10',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 default-originate route-map #10',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast disable-send-community' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast disable-send-community extended' => {
      set => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 send-community extended',
      del => 'router bgp #3 ; address-family ipv6 ; neighbor #5 send-community extended',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast disable-send-community standard' => {
      set => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 send-community standard',
      del => 'router bgp #3 ; address-family ipv6 ; neighbor #5 send-community standard',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast distribute-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast distribute-list export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 distribute-list #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 distribute-list #10 out',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast distribute-list import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 distribute-list #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 distribute-list #10 in',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast filter-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast filter-list export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 filter-list #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 filter-list #10 out',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast filter-list import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 filter-list #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 filter-list #10 in',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast maximum-prefix' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 maximum-prefix #9',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 maximum-prefix #9',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast nexthop-local' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 nexthop-local unchanged',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 nexthop-local unchanged',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast nexthop-self' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 next-hop-self',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 next-hop-self',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast nexthop-self force' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 next-hop-self force',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 next-hop-self force',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast prefix-list export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 prefix-list #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 prefix-list #10 out',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast prefix-list import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 prefix-list #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 prefix-list #10 in',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast remove-private-as' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 remove-private-AS',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 remove-private-AS',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast remove-private-as all' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 remove-private-AS all',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 remove-private-AS all',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast route-map' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast route-map export' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-map #10 out',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-map #10 out',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast route-map import' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-map #10 in',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-map #10 in',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast route-reflector-client' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-reflector-client',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-reflector-client',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast route-server-client' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 route-server-client',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 route-server-client',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast soft-reconfiguration' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv6-unicast soft-reconfiguration inbound' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 soft-reconfiguration inbound',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 soft-reconfiguration inbound',
  },
  'protocols bgp var peer-group var address-family ipv6-unicast unsuppress-map' => {
      set => 'router bgp #3 ; address-family ipv6 ; neighbor #5 unsuppress-map #9',
      del => 'router bgp #3 ; address-family ipv6 ; no neighbor #5 unsuppress-map #9',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 activate',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 activate',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast allowas-in' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 allowas-in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 allowas-in',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast allowas-in number' => {
      set => 'router bgp #3 ; neighbor #5 allowas-in #10',
      del => 'router bgp #3 ; no neighbor #5 allowas-in ; neighbor #5 allowas-in',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast attribute-unchanged' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 attribute-unchanged ; neighbor #5 attribute-unchanged ?as-path ?med ?next-hop',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 attribute-unchanged ?as-path ?med ?next-hop',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast capability' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast capability orf' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast capability orf prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast capability orf prefix-list receive' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 capability orf prefix-list receive',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 capability orf prefix-list receive',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast capability orf prefix-list send' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 capability orf prefix-list send',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 capability orf prefix-list send',
  },
  ## Note that the activate will need to be moved when we migrate to
  ## supporting a single IP version in a peering session.
  'protocols bgp var peer-group var address-family ipv4-unicast default-originate' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 activate ; neighbor #5 default-originate',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 default-originate',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast default-originate route-map' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 activate ; neighbor #5 default-originate route-map #10',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 default-originate route-map #10',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast disable-send-community' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast disable-send-community extended' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 send-community extended',
      del => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 send-community extended',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast disable-send-community standard' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 send-community standard',
      del => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 send-community standard',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast distribute-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast distribute-list export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 distribute-list #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 distribute-list #10 out',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast distribute-list import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 distribute-list #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 distribute-list #10 in',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast filter-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast filter-list export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 filter-list #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 filter-list #10 out',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast filter-list import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 filter-list #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 filter-list #10 in',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast maximum-prefix' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 maximum-prefix #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 maximum-prefix #9',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast nexthop-self' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 next-hop-self',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 next-hop-self',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast nexthop-self force' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 next-hop-self force',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 next-hop-self force',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast prefix-list' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast prefix-list export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 prefix-list #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 prefix-list #10 out',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast prefix-list import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 prefix-list #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 prefix-list #10 in',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast remove-private-as' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 remove-private-AS',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 remove-private-AS',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast remove-private-as all' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 remove-private-AS all',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 remove-private-AS all',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast route-map' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast route-map export' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-map #10 out',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-map #10 out',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast route-map import' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-map #10 in',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-map #10 in',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast route-reflector-client' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-reflector-client',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-reflector-client',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast route-server-client' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 route-server-client',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 route-server-client',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast soft-reconfiguration' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var address-family ipv4-unicast soft-reconfiguration inbound' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 soft-reconfiguration inbound',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 soft-reconfiguration inbound',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast unsuppress-map' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 unsuppress-map #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 unsuppress-map #9',
  },
  'protocols bgp var peer-group var address-family ipv4-unicast weight' => {
      set => 'router bgp #3 ; address-family ipv4 unicast ; neighbor #5 weight #9',
      del => 'router bgp #3 ; address-family ipv4 unicast ; no neighbor #5 weight #9',
  },
  'protocols bgp var peer-group var ebgp-multihop' => {
      set => 'router bgp #3 ; neighbor #5 ebgp-multihop #7',
      del => 'router bgp #3 ; no neighbor #5 ebgp-multihop #7',
  },
  'protocols bgp var peer-group var remote-as' => {
      set => 'router bgp #3 ; neighbor #5 peer-group ; neighbor #5 remote-as #7',
      del => 'router bgp #3 ; no neighbor #5 remote-as #7',
      noerr => 'set',
  },
  'protocols bgp var peer-group var capability' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var capability dynamic' => {
      set => 'router bgp #3 ; neighbor #5 capability dynamic',
      del => 'router bgp #3 ; no neighbor #5 capability dynamic',
  },
  'protocols bgp var peer-group var capability extended-nexthop' => {
      set => 'router bgp #3 ; neighbor #5 capability extended-nexthop',
      del => 'router bgp #3 ; no neighbor #5 capability extended-nexthop',
  },
  'protocols bgp var peer-group var disable-capability-negotiation' => {
      set => 'router bgp #3 ; neighbor #5 dont-capability-negotiate',
      del => 'router bgp #3 ; no neighbor #5 dont-capability-negotiate',
  },
  'protocols bgp var peer-group var disable-connected-check' => {
      set => 'router bgp #3 ; neighbor #5 disable-connected-check',
      del => 'router bgp #3 ; no neighbor #5 disable-connected-check',
  },
  'protocols bgp var peer-group var local-as' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var local-as var' => {
      set => 'router bgp #3 ; no neighbor #5 local-as ; neighbor #5 local-as #7',
      del => 'router bgp #3 ; no neighbor #5 local-as #7',
  },
  'protocols bgp var peer-group var local-as var no-prepend' => {
      set => 'router bgp #3 ; no neighbor #5 local-as #7 ; neighbor #5 local-as #7i no-prepend',
      del => 'router bgp #3 ; no neighbor #5 local-as #7 no-prepend ; neighbor #5 local-as #7',
  },
  'protocols bgp var peer-group var override-capability' => {
      set => 'router bgp #3 ; neighbor #5 override-capability',
      del => 'router bgp #3 ; no neighbor #5 override-capability',
  },
  'protocols bgp var peer-group var passive' => {
      set => 'router bgp #3 ; neighbor #5 passive',
      del => 'router bgp #3 ; no neighbor #5 passive',
  },
  'protocols bgp var peer-group var bfd' => {
      set => 'router bgp #3 ; neighbor #5 bfd',
      del => 'router bgp #3 ; no neighbor #5 bfd',
  },
  'protocols bgp var peer-group var password' => {
      set => 'router bgp #3 ; neighbor #5 password #7',
      del => 'router bgp #3 ; no neighbor #5 password',
  },
  'protocols bgp var peer-group var port' => {
      set => 'router bgp #3 ; neighbor #5 port #7',
      del => 'router bgp #3 ; no neighbor #5 port #7',
  },
  'protocols bgp var peer-group var shutdown' => {
      set => 'router bgp #3 ; neighbor #5 shutdown',
      del => 'router bgp #3 ; no neighbor #5 shutdown',
  },
  'protocols bgp var peer-group var timers' => {
      set => 'router bgp #3 ; neighbor #5 timers @keepalive @holdtime',
      del => 'router bgp #3 ; no neighbor #5 timers',
  },
  'protocols bgp var peer-group var timers connect' => {
      set => 'router bgp #3 ; neighbor #5 timers connect #8',
      del => 'router bgp #3 ; no neighbor #5 timers connect #8',
  },
  'protocols bgp var peer-group var ttl-security' => {
      set => undef,
      del => undef,
  },
  'protocols bgp var peer-group var ttl-security hops' => {
      set => 'router bgp #3 ; neighbor #5 ttl-security hops #8',
      del => 'router bgp #3 ; no neighbor #5 ttl-security hops #8',
  },
  'protocols bgp var peer-group var update-source' => {
      set => 'router bgp #3 ; neighbor #5 update-source #7',
      del => 'router bgp #3 ; no neighbor #5 update-source',
  },
  'protocols bgp var timers' => {
      set => 'router bgp #3 ; timers bgp @keepalive @holdtime',
      del => 'router bgp #3 ; no timers bgp',
  },
);

if ( ! -e "/usr/sbin/zebra" ) {
  $qcom{'protocols bgp var neighbor var remote-as'}{'set'} = 'router bgp #3 ; neighbor #5 remote-as #7';
}

my ( $pg, $as, $neighbor );
my ( $main, $peername, $isneighbor, $checkpeergroups, $checkpeergroups6, $checksource,
     $isiBGPpeer, $wasiBGPpeer, $confedibgpasn, $listpeergroups, $checkremoteas, $checkbfdpeer, $checkbfdgroup,
     $checkbgplisten);

GetOptions(
    "peergroup=s"             => \$pg,
    "as=s"                    => \$as,
    "neighbor=s"              => \$neighbor,
    "check-peergroup-name=s"  => \$peername,
    "check-neighbor-ip"       => \$isneighbor,
    "check-peer-groups"       => \$checkpeergroups,
    "check-peer-groups-6"     => \$checkpeergroups6,
    "check-source=s"	      => \$checksource,
    "is-iBGP"		      => \$isiBGPpeer,
    "was-iBGP"                => \$wasiBGPpeer,
    "confed-iBGP-ASN-check=s" => \$confedibgpasn,
    "list-peer-groups"        => \$listpeergroups,
    "check-remote-as=s"       => \$checkremoteas,
    "check-bfd-peer=s"        => \$checkbfdpeer,
    "check-peer-group-bfd=s"  => \$checkbfdgroup,
    "check-bgp-listen"        => \$checkbgplisten,
    "main"                    => \$main,
);

main()					    if ($main);
check_peergroup_name($peername)	  	    if ($peername);
check_neighbor_ip($neighbor)                if ($isneighbor);
check_for_peer_groups( $pg, $as )	    if ($checkpeergroups);
check_for_peer_groups6( $pg, $as )	    if ($checkpeergroups6);
check_source($checksource)	            if ($checksource);
confed_iBGP_ASN($as, $confedibgpasn)        if ($confedibgpasn);
is_iBGP_peer($neighbor, $as)          	    if ($isiBGPpeer);
was_iBGP_peer($neighbor, $as)               if ($wasiBGPpeer);
list_peer_groups($as)                       if ($listpeergroups);
check_remote_as($checkremoteas)             if ($checkremoteas);
check_bfd_peer($checkbfdpeer)               if ($checkbfdpeer);
check_bfd_group($checkbfdgroup, $as)        if ($checkbfdgroup);
check_bgp_listen($as)                       if ($checkbgplisten);

exit 0;

sub list_peer_groups {
   my $as = shift;
   my $config = new Vyatta::Config;

   $config->setLevel("protocols bgp $as peer-group");
   my @nodes = $config->listNodes();
   foreach my $node (@nodes) { print "$node "; }
   return;
}

# Make sure the peer IP isn't a local system IP
sub check_neighbor_ip {
    my $neighbor = shift;

    my $found = grep { $_ eq $neighbor } Vyatta::Misc::getInterfaces();
    if ($found != 0) {
            exit 0;
    }

    die "Can't set neighbor address to local system IP.\n"
	if (is_local_address($neighbor));

    exit 0;
}

# Make sure the peer-group name is properly formatted
sub check_peergroup_name {
    my $neighbor = shift;

    $_ = $neighbor;
    my $version = is_ip_v4_or_v6($neighbor);
    if ( ( defined($version) ) || (/[\s\W]/g) ) {
        die "malformed peer-group name $neighbor\n";
    }

    # Quagga treats the first byte as a potential IPv6 address
    # so we can't use it as a peer group name.  So let's check for it.
    if (/^[A-Fa-f]{1,4}$/) {
		die "malformed peer-group name $neighbor\n";
    }
}

sub check_remote_as {
    my $remote_as = shift;

    if ($remote_as =~ /^(\d+)$/) {
        if ( $remote_as >= 1 && $remote_as <= 4294967294) {
	    exit 0;
	}
    die "remote-as must be between 1 and 4294967294 or external or internal";
    }

    if ( $remote_as eq "external" || $remote_as eq "internal") {
        exit 0;
    }
    die "remote-as must be between 1 and 4294967294 or external or internal";
}


# Make sure we aren't deleteing a peer-group that has
# neighbors configured to it
sub check_for_peer_groups6 {
    my $config = new Vyatta::Config;
    my $pg     = shift;
    die "Peer group not defined\n" unless $pg;
    my $as = shift;
    die "AS not defined\n" unless $as;
    my @peers;

    # get the list of neighbors and see if they have a peer-group set
    $config->setLevel("protocols bgp $as neighbor");
    my @neighbors = $config->listNodes();

    foreach my $node (@neighbors) {
        my $peergroup6 = $config->returnValue("$node address-family ipv6-unicast peer-group");
        if (defined($peergroup6) && ($peergroup6 eq $pg))
        {
             push @peers, $node;
        }
    }

    # if we found peers in the previous statements
    # notify an return errors
    if (@peers) {
        foreach my $node (@peers) {
            print "neighbor $node uses ipv6 peer-group $pg\n";
        }

	die "please delete these peers before removing the peer-group\n";
    }
}

# Make sure we aren't deleteing a peer-group that has
# neighbors configured to it
sub check_for_peer_groups {
    my $config = new Vyatta::Config;
    my $pg     = shift;
    die "Peer group not defined\n" unless $pg;
    my $as = shift;
    die "AS not defined\n" unless $as;
    my @peers;

    # get the list of neighbors and see if they have a peer-group set
    $config->setLevel("protocols bgp $as");
    my @neighbors = $config->listNodes("neighbor");

    foreach my $node (@neighbors) {
        my $peergroup = $config->returnValue("neighbor $node peer-group");
        if ((defined $peergroup) && ($peergroup eq $pg)) { push @peers, $node; }
        $peergroup = $config->returnValue("neighbor $node interface peer-group");
        if ((defined $peergroup) && ($peergroup eq $pg)) { push @peers, $node; }
        $peergroup = $config->returnValue("neighbor $node interface v6only peer-group");
        if ((defined $peergroup) && ($peergroup eq $pg)) { push @peers, $node; }
    }

    # if we found peers in the previous statements
    # notify an return errors
    if (@peers) {
        foreach my $node (@peers) {
            print "neighbor $node uses peer-group $pg\n";
        }

	die "please delete these peers before removing the peer-group\n";
    }

    # check BGP listen ranges
    if ($config->exists("listen range")) {
        my @listen_ranges = $config->listNodes("listen range");
        foreach my $range (@listen_ranges) {
            my $peer_group = $config->returnValue("listen range $range peer-group");
            if ($pg eq $peer_group) {
                die "BGP peer-group $peer_group is used for BGP listen range $range and cannot be deleted\n";
            }
        }
    }
}

# function to verify changing remote-as from/to i/eBGP
# there are two types of parameter checks we need to do.  The first should happen
# when the affected parameter is created/changed. Those checks should happen in
# the syntax and commit statements in the node.defs for those specific params since
# they can be updated individually. The params should be checked again if the remote-as
# changes.
# This funtion handles changes in the remote-as and/or peer-group
sub bgp_type_change {
    my ($neighbor, $as, $ntype) =@_;
    my $config = new Vyatta::Config;
    $config->setLevel('protocols bgp');

    if ( ("$ntype" ne "neighbor") && ("$ntype" ne "peer-group") ) {
      return -1;
    }

    # check if changing from iBGP to eBGP
    if ( (iBGP_peer(1, $neighbor, $as, $ntype)) && (! iBGP_peer(0, $neighbor, $as, $ntype)) ) {
      if ( $config->exists("$as $ntype $neighbor route-reflector-client") ||
           $config->exists("$as $ntype $neighbor address-family ipv6-unicast route-reflector-client") ) {
        return "can not set route-reflector-client and an eBGP remote-as at the same time\n";
      }
    }

    # check if changing from eBGP to iBGP
    if ( (! iBGP_peer(1, $neighbor, $as, $ntype)) && (iBGP_peer(0, $neighbor, $as, $ntype)) ) {
      if ($config->exists("$as $ntype $neighbor ebgp-multihop")) {
        return "can not set ebgp-multihop and an iBGP remote-as at the same time\n";
      }
      if ($config->exists("$as $ntype $neighbor ttl-security")) {
        return "can not set ttl-security and an iBGP remote-as at the same time\n";
      }
      if ($config->exists("$as $ntype $neighbor local-as")) {
        return "can not set local-as and an iBGP remote-as at the same time\n";
      }
    }
}

sub checkBannedPeerGroupParameters
{
	my ($level, $protocol) = @_;
	unless ($protocol == 4 || $protocol == 6) {
		return -1;
	}

	my @bannedlist = ('advertisement-interval', 'attribute-unchanged', 'capability orf',
						'default-originate', 'distribute-list export', 'filter-list export',
						'nexthop-self', 'prefix-list export', 'remove-private-as',
						'route-map export', 'route-reflector-client', 'route-server-client',
						'disable-send-community', 'timers', 'ttl-security', 'unsuppress-map');

	my @globalbannedlist = ('local-as');

	my $config = new Vyatta::Config;
	$config->setLevel("protocols bgp $level");

	foreach my $node (@globalbannedlist) {
		if ($config->exists($node)) {
			die "[ protocols bgp $level ]\n  parameter $node is incompatible with a neighbor in a peer-group\n";
		}
	}
	if ($protocol == 6) {
		$config->setLevel("protocols bgp $level address-family ipv6-unicast");
	}
	foreach my $node (@bannedlist) {
		if ($config->exists($node)) {
			die "[ protocols bgp $level ]\n  parameter $node is incompatible with a neighbor in a peer-group\n";
		}
	}
	return 1;
}

sub checkOverwritePeerGroupParameters
{
	my ($qconfig_ref, $level, $protocol) = @_;
	my $ret = 0;

	unless ($protocol == 4 || $protocol == 6) {
		return -1;
	}

	my @overwritelist = ('allowas-in', 'allowas-in number', 'capability dynamic', 'capability extended-nexthop',
							'distribute-list import', 'filter-list import', 'maximum-prefix',
							'port', 'prefix-list import', 'route-map import',
							'soft-reconfiguration inbound', 'strict-capability-match');

	my @globaloverwritelist = ('disable-capability-negotiation', 'disable-connected-check',
								'ebgp-multihop', 'override-capability', 'passive', 'password',
								'shutdown', 'update-source', 'weight');

	my $config = new Vyatta::Config;
	$config->setLevel("protocols bgp $level");

	foreach my $node (@globaloverwritelist) {
		if ($config->exists($node)) {
			$$qconfig_ref->reInsertNode("protocols bgp $level $node");
			$ret++;
		}
	}
	if ($protocol == 6) {
		$level .= " address-family ipv6-unicast";
		$config->setLevel("protocols bgp $level");
	}
	foreach my $node (@overwritelist) {
		if ($config->exists($node)) {
			$$qconfig_ref->reInsertNode("protocols bgp $level $node");
			$ret++;
		}
	}
	return $ret;
}

# check that changed neighbors have a remote-as or peer-group defined
# and that all permutations of parameters and BGP type are correct
sub check_neighbor_parameters
{
    my $qconfig_ref = shift;
    my $config = new Vyatta::Config;
    $config->setLevel('protocols bgp');

    my @asns = $config->listNodes();
    foreach my $as (@asns) {
      # check peer-groups if they have changed
      my @peergroups = $config->listNodes("$as peer-group");
      foreach my $peergroup (@peergroups) {
          next unless ($config->isChanged("$as peer-group $peergroup"));

          # if we delete the remote-as in the pg, make sure all neighbors have a remote-as defined
          if ($config->isDeleted("$as peer-group $peergroup remote-as")) {
            my @neighbors = $config->listNodes("$as neighbor");
            foreach my $neighbor (@neighbors) {
              my $pgmembership = $config->returnValue("$as neighbor $neighbor peer-group");
              if ( ! defined $pgmembership ) {
                my $pgmembership = $config->returnValue("$as neighbor $neighbor іnterface peer-group");
              }
              if ( ! defined $pgmembership ) {
                my $pgmembership = $config->returnValue("$as neighbor $neighbor іnterface v6only peer-group");
              }
              if ( (defined $pgmembership) && ("$pgmembership" eq "$peergroup") ) {
                my $remoteas = $config->returnValue("$as neighbor $neighbor remote-as");
                if ( ! defined $remoteas) {
                  my $remoteas = $config->returnValue("$as neighbor $neighbor іnterface remote-as");
                }
                if ( ! defined $remoteas ) {
                  my $remoteas = $config->returnValue("$as neighbor $neighbor іnterface v6only remote-as");
                }
                if (! defined $remoteas) {
                  die "[ protocols bgp $as peer-group $neighbor ]\n  can't delete the remote-as in peer-group without setting remote-as in member neighbors\n"
                }
              }
            }
          }

          # check asn type change
          my $error = bgp_type_change($peergroup, $as, "peer-group");
          if ($error) { die "[ protocols bgp $as peer-group $peergroup ]\n  $error\n"; }

          # remote-as can't be defined in both pg and neighbor at the same time
          my $pgremoteas = $config->returnValue("$as peer-group $peergroup remote-as");
          if ($pgremoteas) {
            my @neighbors = $config->listNodes("$as neighbor");
            foreach my $neighbor (@neighbors) {
              my $pgmembership = $config->returnValue("$as neighbor $neighbor peer-group");
              if ( ! defined $pgmembership ) {
                my $pgmembership = $config->returnValue("$as neighbor $neighbor іnterface peer-group");
              }
              if ( ! defined $pgmembership ) {
                my $pgmembership = $config->returnValue("$as neighbor $neighbor іnterface v6only peer-group");
              }
              if ((defined $pgmembership) && ("$pgmembership" eq "$peergroup")) {
                my $remoteas = $config->returnValue("$as neighbor $neighbor remote-as");
                if ( ! defined $remoteas) {
                  my $remoteas = $config->returnValue("$as neighbor $neighbor іnterface remote-as");
                }
                if ( ! defined $remoteas ) {
                  my $remoteas = $config->returnValue("$as neighbor $neighbor іnterface v6only remote-as");
                }
                if (defined $remoteas && defined $pgremoteas) {
                  die "[ protocols bgp $as peer-group $neighbor ]\n  must not define remote-as in both neighbor and peer-group\n"
                }
              }
            }
          }

          # check if a peer-group overwrite parameter was changed and resubmit
          my @neighbors = $config->listNodes("$as neighbor");
          foreach my $neighbor (@neighbors) {
            my $pg = $config->returnValue("$as neighbor $neighbor peer-group");
            if (defined $pg && ($pg eq "$peergroup")) {
              checkOverwritePeerGroupParameters($qconfig_ref, "$as neighbor $neighbor", 4);
            }
          }
      } ## end foreach my $peergroup (@peergroups)

      # check neighbor if remote-as or peer-group has been changed
      my @neighbors = $config->listNodes("$as neighbor");

      foreach my $neighbor (@neighbors) {
      	# check that remote-as exists
      	if ($config->isChanged("$as neighbor $neighbor remote-as") ||
	    ! $config->exists("$as neighbor $neighbor remote-as")) {
	    # remote-as checks: Make sure the neighbor has a remote-as defined locally or in the peer-group
	    my ($remoteas, $peergroup, $peergroupas, $peergroup6, $peergroup6as);
	    $remoteas = $config->returnValue("$as neighbor $neighbor remote-as");
        if (! defined($remoteas)) {
                $remoteas = $config->returnValue("$as neighbor $neighbor interface remote-as");
        }
        if (! defined($remoteas)) {
                $remoteas = $config->returnValue("$as neighbor $neighbor interface v6only remote-as");
        }
	    if ($config->exists("$as neighbor $neighbor peer-group") ||
            $config->exists("$as neighbor $neighbor interface peer-group") ||
            $config->exists("$as neighbor $neighbor interface v6only peer-group")) {
		$peergroup = $config->returnValue("$as neighbor $neighbor peer-group");
                if (! defined($peergroup)) {
                    $peergroup = $config->returnValue("$as neighbor $neighbor interface peer-group");
                }
                if (! defined($peergroup)) {
                    $peergroup = $config->returnValue("$as neighbor $neighbor interface v6only  peer-group");
                }
            	if ($config->exists("$as peer-group $peergroup remote-as")) {
		            $peergroupas = $config->returnValue("$as peer-group $peergroup remote-as");
            	}
	    }
            if ($config->exists("$as neighbor $neighbor address-family ipv6-unicast peer-group")) {
		        $peergroup6 = $config->returnValue("$as neighbor $neighbor address-family ipv6-unicast peer-group");
            	if ($config->exists("$as peer-group $peergroup6 remote-as")
                    && $config->exists("$as peer-group $peergroup6 address-family ipv6-unicast")) {
		            $peergroup6as = $config->returnValue("$as peer-group $peergroup6 remote-as");
            	}
	        }
	    die "[ protocols bgp $as neighbor $neighbor ]\n  must set remote-as or peer-group with remote-as defined\n"
		if ((!defined($remoteas) && !defined($peergroupas)) && !$config->exists("$as parameters default no-ipv4-unicast"));

	    die "[ protocols bgp $as neighbor $neighbor ]\n  must set remote-as or address-family ipv6-unicast peer-group"
               ." with remote-as defined\n"
		if ($config->exists("$as neighbor $neighbor address-family ipv6-unicast") &&
                   (!defined($peergroup6as) && !defined($remoteas)));

	    die "[ protocols bgp $as neighbor $neighbor ]\n  remote-as should not be defined in both neighbor and peer-group\n"
            	if ($remoteas && $peergroupas);

        } ## end remote-as checks

        # Check if changing BGP peer type from/to i/eBGP
        my $error = bgp_type_change($neighbor, $as, "neighbor");
        if ($error) { die "[ protocols bgp $as neighbor $neighbor ]\n  $error\n"; }

	# If the peer-group has changed since the last commit, update overwritable nodes
	# We do this because Quagga removes nodes silently while vyatta-cfg does not.
	# check IPv4 peer-group
	if ($config->exists("$as neighbor $neighbor peer-group")) {
	    checkBannedPeerGroupParameters("$as neighbor $neighbor", 4);
	}
	if ($config->isChanged("$as neighbor $neighbor peer-group")) {
	    checkOverwritePeerGroupParameters($qconfig_ref, "$as neighbor $neighbor", 4);
	}

	# check IPv6 peer-group
	if ($config->exists("$as neighbor $neighbor address-family ipv6-unicast peer-group")) {
	    checkBannedPeerGroupParameters("$as neighbor $neighbor", 6);
	}
	if ($config->isChanged("$as neighbor $neighbor address-family ipv6-unicast peer-group")) {
	    checkOverwritePeerGroupParameters($qconfig_ref, "$as neighbor $neighbor", 6);
        }
      } ## end foreach my $neighbor (@neighbors)
    } ## end foreach my $as (@asns)
}

# check to see if adding this ASN to confederations
# will make a peer an iBGP peer
sub confed_iBGP_ASN {
    my ($as, $testas) = @_;
    if ("$as" eq "$testas") { exit 1 ; }

    my $config = new Vyatta::Config;
    $config->setLevel("protocols bgp $as");

    #my @neighbors = $config->listNodes('neighbor');
    my @neighbors = $config->listOrigNodes('neighbor');
    foreach my $neighbor (@neighbors) {
      my $remoteas = $config->returnValue("neighbor $neighbor remote-as");
      if (defined $remoteas) {
        if (("$testas" eq "$remoteas") || ("$testas" eq "internal")) {
          exit 1;
        }
      }
      $remoteas = $config->returnValue("neighbor $neighbor interface remote-as");
      if (defined $remoteas) {
        if (("$testas" eq "$remoteas") || ("$testas" eq "internal")) {
          exit 1;
        }
      }
      $remoteas = $config->returnValue("neighbor $neighbor interface v6only remote-as");
      if (defined $remoteas) {
        if (("$testas" eq "$remoteas") || ("$testas" eq "internal")) {
            exit 1;
        }
      }
    }

    return;
}

sub is_iBGP_peer {
    my ($neighbor, $as) = @_;

    my $return = iBGP_peer(0, $neighbor, $as, "neighbor");
    if ($return > 0) { exit 1; }
    elsif ($return < 0) { print "Unable to determine original ASN for neighbhor $neighbor\n"; }
    exit 0;
}

sub was_iBGP_peer {
    my ($neighbor, $as) = @_;

    if (iBGP_peer(1, $neighbor, $as, "neighbor") >= 1) { exit 1; }
    exit 0;
}

# is this peer an iBGP peer?
sub iBGP_peer {
    my ($orig, $neighbor, $as, $ntype) = @_;
    my $config = new Vyatta::Config;
    my @ibgp_as;
    my $neighbor_as;

    $config->setLevel("protocols bgp $as");

    my $exists = sub { $config->exists(@_) };
    my $returnValue = sub { $config->returnValue(@_) };
    my $returnValues = sub { $config->returnValues(@_) };

    if ($orig) {
      $exists = sub { $config->existsOrig(@_) };
      $returnValue = sub { $config->returnOrigValue(@_) };
      $returnValues = sub { $config->returnOrigValues(@_) };
    }

    # find my local ASN for this neighbor
    # it's either explicitly defined or in the peer-group
    if ($exists->("$ntype $neighbor remote-as")) {
      $neighbor_as = $returnValue->("$ntype $neighbor remote-as");
    }
    elsif ( ("$ntype" eq "neighbor") && ($exists->("neighbor $neighbor peer-group")) ) {
      my $peergroup = $returnValue->("neighbor $neighbor peer-group");
      if ($exists->("peer-group $peergroup remote-as")) {
        my $peergroup = $returnValue->("neighbor $neighbor peer-group");
        $neighbor_as = $returnValue->("peer-group $peergroup remote-as");
      }
      else {
	return -1;
      }
    }
    else {
      return -1;
    }

    # now find my possible local ASNs.  Confederation ASNs are first.
    if ($exists->('parameters confederation peers')) {
      @ibgp_as = $returnValues->('parameters confederation peers');
    }

    # push router local ASN on the stack
    push @ibgp_as, $as;

    # and compare neighbor local as to possible local ASNs
    foreach my $localas (@ibgp_as) {
      if ("$localas" eq "$neighbor_as") {
        return 1;
      }
    }

    return 0;
}

# check that value is either an IPV4 address on system or an interface
sub check_source {
    my $src = shift;
    my $ip = new NetAddr::IP::Lite($src);

    if ($ip) {
	my $found = grep { my $a = new NetAddr::IP::Lite($_);
			   $a->addr() eq $ip->addr() } Vyatta::Misc::getIP();
	print("Warning: IP address $ip does not exist on this system\n") if ($found == 0);
    } else {
	my $found = grep { $_ eq $src } Vyatta::Misc::getInterfaces();
	print("Warning: Interface $src does not exist on the system\n") if ($found == 0);
    }
}

# check if BFD peer exists for configured BGP peer
sub check_bfd_peer {
  my $peer = shift;
  my $config = new Vyatta::Config;

  # check for BFD peer configuration
  my $bfd_exists = $config->exists("protocols bfd peer $peer");
  if (!$bfd_exists) { die "BFD peer need to be configured for using BFD protocol\n"; }
}

# check if BFD peer exists for configured BGP peer-group
sub check_bfd_group {
  my $group = shift;
  my $as = shift;
  my @group_neighbors = ();
  my $config = new Vyatta::Config;

  # check if BFD enabled for peer-group and stop check if not
  if (!$config->exists("protocols bgp $as peer-group $group bfd")) {
    return 0;
  }

  # get a list of all BGP neighbors in the defined group
  my @all_neighbors = $config->listNodes("protocols bgp $as neighbor");
  foreach my $neighbor (@all_neighbors) {
    if ($config->exists("protocols bgp $as neighbor $neighbor peer-group")) {
      if ($config->returnValue("protocols bgp $as neighbor $neighbor peer-group") eq $group) {
        push @group_neighbors, $neighbor;
      }
    }
  }

  # check if BFD peer exist and raise error if not
  foreach my $neighbor (@group_neighbors) {
    if (!$config->exists("protocols bfd peer $neighbor")) { die "BFD peers need to be configured for all neighbors in peer-group $group before enabling for BGP\n"; }
  }
}

# check if ranges are overlapped
sub ranges_overlapped {
    my @ranges = @_;

    foreach my $range (@ranges) {
        foreach my $range_other (@ranges) {
            if ($range_other != $range) {
                my $first_address = $range->network();
                my $last_address = $range->broadcast();
                my $first_address_other = $range_other->network();
                my $last_address_other = $range_other->broadcast();

                if (($first_address >= $first_address_other and $first_address <= $last_address_other) or
                    ($last_address >= $first_address_other and $last_address <= $last_address_other)) {
                        # ranges are overlapped
                        print "Listen ranges cannot overlap: $range and $range_other\n";
                        return 1;
                }
            }
        }
    }
    # return undef if ranges are not overlapped
    return undef;
}

# check BGP listen options
sub check_bgp_listen {
    my $as = shift;
    die "AS not defined\n" unless $as;
    my @listen_ranges;
    my @ranges_v4;
    my @ranges_v6;

    # get a list of ranges
    my $config = new Vyatta::Config;
    $config->setLevel("protocols bgp $as");
    if ($config->exists("listen range")) {
        @listen_ranges = $config->listNodes("listen range");
    }

    foreach my $range (@listen_ranges) {
        # check if a peer-group is changed - this is not supported by FRR,
        # a listen range must be removed and added with a new peer-group in two commits
        if ($config->isChanged("listen range $range peer-group") and not $config->isAdded("listen range $range") ) {
            die "A peer-group cannot be changed. A listen range $range needs to be removed and added again with the new peer-group\n";
        }

        # check if a peer-group is defined
        if (not $config->exists("listen range $range peer-group")) {
            die "A peer-group must be configured for range $range\n";
        }

        # sort IPv4 and IPv6 ranges
        my $range_netaddr = new NetAddr::IP::Lite($range);
        if ($range_netaddr->version() == 4) {
            push(@ranges_v4, $range_netaddr);
        }
        if ($range_netaddr->version() == 6) {
            push(@ranges_v6, $range_netaddr);
        }
    }

    # check if listen ranges are not overlapped
    if (ranges_overlapped(@ranges_v4) or ranges_overlapped(@ranges_v6)) {
        die "Configuration error\n";
    }
}

sub main
{
   # initialize the Quagga Config object with data from Vyatta config tree
   my $qconfig = new Vyatta::Quagga::Config('protocols', \%qcom);

   # debug routines
   #$qconfig->setDebugLevel('3');
   #$qconfig->_reInitialize();

   # check that all changed neighbors have a proper remote-as or peer-group defined
   # and that migrations to/from iBGP eBGP are valid
   check_neighbor_parameters(\$qconfig);

   ## deletes with priority
   # delete everything in neighbor, ordered nodes last
   my @ordered = ('remote-as', 'peer-group', 'shutdown',
                  'address-family ipv4-unicast route-map',
                  'address-family ipv4-unicast prefix-list',
                  'address-family ipv4-unicast filter-list',
                  'address-family ipv4-unicast distribute-list',
                  'address-family ipv4-unicast unsuppress-map',
                  'address-family ipv6-unicast route-map',
                  'address-family ipv6-unicast prefix-list',
                  'address-family ipv6-unicast filter-list',
                  'address-family ipv6-unicast distribute-list',
                  'address-family ipv6-unicast unsuppress-map');

   # notice the extra space in the level string.  keeps the parent from being deleted.
   $qconfig->deleteConfigTreeRecursive('protocols bgp var neighbor var', undef, \@ordered) || die "exiting $?\n";
   $qconfig->deleteConfigTreeRecursive('protocols bgp var listen') || die "exiting $?\n";
   $qconfig->deleteConfigTreeRecursive('protocols bgp var peer-group var', undef, \@ordered) || die "exiting $?\n";
   $qconfig->deleteConfigTreeRecursive('protocols bgp') || die "exiting $?\n";

   ## sets with priority
   $qconfig->setConfigTreeRecursive('protocols bgp var parameters') || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var peer-group', undef, \@ordered) || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var neighbor var remote-as', undef, \@ordered) || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var neighbor var interface', undef, \@ordered)
                                    || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var neighbor var address-family ipv6-unicast peer-group'
                                    , undef, \@ordered) || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var neighbor var address-family ipv6-unicast'
                                    , undef, \@ordered) || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var neighbor var ', undef, \@ordered) || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp var listen') || die "exiting $?\n";
   $qconfig->setConfigTreeRecursive('protocols bgp') || die "exiting $?\n";
}