Skip to content

Commit 24d5fa0

Browse files
authored
Fix: ensure bgp.neighbors is defined for BGP-enabled routing instances (#2492)
Numerous implementations of ebgp.multihop configuration template assume bgp.neighbors is defined if bgp is defined (in node data or in a VRF). We could either meet that assumption or fix all those templates (and meeting that assumption could result in simpler templates overall). Fixes #2486
1 parent bcb73bf commit 24d5fa0

File tree

11 files changed

+37
-0
lines changed

11 files changed

+37
-0
lines changed

netsim/modules/bgp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,14 @@ def vlan_ebgp_role_set(topology: Box, EBGP_ROLE: str) -> None:
728728
vdata.pop('_as_set',None) # ... and clean up
729729
vdata.pop('_bgp_attr',None)
730730

731+
"""
732+
Make sure BGP data always has the expected attributes (currently: neighbors, might be others in the future)
733+
"""
734+
def sanitize_bgp_data(node: Box) -> None:
735+
for (b_data,_,_) in _rp_utils.rp_data(node,'bgp'):
736+
if 'neighbors' not in b_data:
737+
b_data.neighbors = []
738+
731739
class BGP(_Module):
732740
"""
733741
Node pre-transform: set bgp.rr node attribute to _true_ if the node name is in the
@@ -787,3 +795,4 @@ def node_post_transform(self, node: Box, topology: Box) -> None:
787795
bgp_transform_community_list(node,topology)
788796
_routing.check_vrf_protocol_support(node,'bgp',None,'bgp',topology)
789797
_routing.process_imports(node,'bgp',topology,global_vars.get_const('vrf_igp_protocols',['connected']))
798+
sanitize_bgp_data(node)

tests/topology/expected/evpn-asymmetric-irb-ospf.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ nodes:
596596
auto: true
597597
ospf:
598598
auto: true
599+
neighbors: []
599600
evpn:
600601
bundle: vlan_aware
601602
evi: 1
@@ -922,6 +923,7 @@ nodes:
922923
auto: true
923924
ospf:
924925
auto: true
926+
neighbors: []
925927
evpn:
926928
bundle: vlan_aware
927929
evi: 1

tests/topology/expected/evpn-hub-spoke.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ nodes:
129129
import:
130130
connected:
131131
auto: true
132+
neighbors: []
132133
evpn:
133134
evi: 1
134135
rd: 10.0.0.1:1
@@ -223,6 +224,7 @@ nodes:
223224
import:
224225
connected:
225226
auto: true
227+
neighbors: []
226228
evpn:
227229
evi: 2
228230
rd: 10.0.0.2:2

tests/topology/expected/evpn-l3vni-only.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ nodes:
181181
import:
182182
connected:
183183
auto: true
184+
neighbors: []
184185
evpn:
185186
evi: 1
186187
rd: 10.0.0.1:1
@@ -306,6 +307,7 @@ nodes:
306307
import:
307308
connected:
308309
auto: true
310+
neighbors: []
309311
evpn:
310312
evi: 1
311313
rd: 10.0.0.2:1

tests/topology/expected/evpn-node-vrf.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ nodes:
143143
import:
144144
connected:
145145
auto: true
146+
neighbors: []
146147
evpn:
147148
evi: 1
148149
rd: 10.0.0.1:1

tests/topology/expected/mpls-vpn-simple.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ nodes:
196196
import:
197197
connected:
198198
auto: true
199+
neighbors: []
199200
export:
200201
- '65001:1'
201202
id: 1
@@ -329,6 +330,7 @@ nodes:
329330
import:
330331
connected:
331332
auto: true
333+
neighbors: []
332334
export:
333335
- '65001:1'
334336
id: 1

tests/topology/expected/null-vrfs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ nodes:
121121
import:
122122
connected:
123123
auto: true
124+
neighbors: []
124125
export:
125126
- '65000:1'
126127
id: 1

tests/topology/expected/vrf-igp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ nodes:
258258
auto: true
259259
ospf:
260260
auto: true
261+
neighbors: []
261262
export:
262263
- '65000:3'
263264
id: 3
@@ -514,6 +515,7 @@ nodes:
514515
auto: true
515516
ospf:
516517
auto: true
518+
neighbors: []
517519
export:
518520
- '65000:3'
519521
id: 3

tests/topology/expected/vrf-links.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ nodes:
231231
auto: true
232232
ospf:
233233
auto: true
234+
neighbors: []
234235
export:
235236
- '65000:2'
236237
id: 2
@@ -277,6 +278,7 @@ nodes:
277278
auto: true
278279
ospf:
279280
auto: true
281+
neighbors: []
280282
export:
281283
- '65000:1'
282284
id: 1
@@ -452,6 +454,7 @@ nodes:
452454
auto: true
453455
ospf:
454456
auto: true
457+
neighbors: []
455458
export:
456459
- '65000:1'
457460
id: 1
@@ -642,6 +645,7 @@ nodes:
642645
auto: true
643646
ospf:
644647
auto: true
648+
neighbors: []
645649
export:
646650
- '65000:2'
647651
id: 2
@@ -702,6 +706,7 @@ nodes:
702706
auto: true
703707
ospf:
704708
auto: true
709+
neighbors: []
705710
export:
706711
- '65000:1'
707712
id: 1

tests/topology/expected/vrf-routing-blocks.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ nodes:
426426
import:
427427
connected:
428428
auto: true
429+
neighbors: []
429430
export:
430431
- '65000:5'
431432
id: 5
@@ -444,6 +445,7 @@ nodes:
444445
auto: true
445446
ospf:
446447
auto: true
448+
neighbors: []
447449
export:
448450
- '65000:1'
449451
id: 1
@@ -563,6 +565,7 @@ nodes:
563565
auto: true
564566
isis:
565567
auto: true
568+
neighbors: []
566569
export:
567570
- '65000:2'
568571
id: 2
@@ -609,6 +612,7 @@ nodes:
609612
auto: true
610613
ospf:
611614
auto: true
615+
neighbors: []
612616
export:
613617
- '65000:3'
614618
id: 3
@@ -815,6 +819,7 @@ nodes:
815819
auto: true
816820
ospf:
817821
auto: true
822+
neighbors: []
818823
export:
819824
- '65000:1'
820825
id: 1
@@ -934,6 +939,7 @@ nodes:
934939
auto: true
935940
isis:
936941
auto: true
942+
neighbors: []
937943
export:
938944
- '65000:2'
939945
id: 2
@@ -1093,6 +1099,7 @@ nodes:
10931099
import:
10941100
connected:
10951101
auto: true
1102+
neighbors: []
10961103
export:
10971104
- '65000:5'
10981105
id: 5

0 commit comments

Comments
 (0)