Skip to content

Commit e9a27e4

Browse files
Fix: make "bgp._session_clear" VRF-aware (#2630)
Fixes #2619 --------- Co-authored-by: Ivan Pepelnjak <ip@ipspace.net>
1 parent e1fd3a6 commit e9a27e4

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

netsim/extra/bgp.policy/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ def apply_config(node: Box, ngb: Box) -> None:
160160
global _config_name
161161
api.node_config(node,_config_name) # Remember that we have to do extra configuration
162162
for af in ('ipv4','ipv6'): # ... and add sessions that have to be cleared
163-
if af in ngb:
163+
if af in ngb and '_src_vrf' not in ngb:
164164
data.append_to_list(node.bgp,'_session_clear',ngb[af])
165+
elif af in ngb and '_src_vrf' in ngb:
166+
for vname,vdata in node.vrfs.items():
167+
if vname == ngb['_src_vrf']:
168+
data.append_to_list(node.vrfs[vname].bgp,'_session_clear',ngb[af])
165169

166170
'''
167171
Apply attributes supported by bgp.policy plugin to a single neighbor

netsim/extra/bgp.session/arubacx.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ router bgp {{ bgp.as }}
7171
{% endfor %}
7272
{% endif %}
7373
!
74-
{% for ngb in bgp._session_clear|default([]) %}
75-
do clear bgp {{ ngb }}
74+
do clear bgp *
75+
{% for vname,vdata in (vrfs|default({})).items() if vdata.bgp is defined %}
76+
do clear bgp vrf {{vname}} *
7677
{% endfor %}

netsim/extra/bgp.session/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ def mark_plugin_config(node: Box, ngb: Box) -> None:
3535

3636
api.node_config(node,_config_name) # Remember that we have to do extra configuration
3737
for af in ('ipv4','ipv6'): # ... and add sessions that have to be cleared
38-
if af in ngb:
38+
if af in ngb and '_src_vrf' not in ngb:
3939
data.append_to_list(node.bgp,'_session_clear',ngb[af])
40+
elif af in ngb and '_src_vrf' in ngb:
41+
for vname,vdata in node.vrfs.items():
42+
if vname == ngb['_src_vrf']:
43+
data.append_to_list(node.vrfs[vname].bgp,'_session_clear',ngb[af])
4044

4145
'''
4246
Apply attributes supported by bgp.session plugin to a single neighbor

netsim/extra/bgp.session/srlinux.j2

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
updates:
7979
{% for addr in bgp._session_clear|default([]) %}
8080
{{ bgp_admin_state(addr,'default','disable') }}
81+
82+
{% if vrfs is defined %}
83+
{% for vname,vdata in vrfs.items() if vdata.bgp is defined %}
84+
{% for addr in vdata.bgp._session_clear|default([]) %}
85+
{{ bgp_admin_state(addr,vname,'disable') }}
86+
{% endfor %}
87+
{% endfor %}
88+
{% endif %}
89+
8190
{% endfor %}
8291
{% for af in ['ipv4','ipv6'] %}
8392
{% for n in bgp.neighbors if n[af] is defined and (n[af] is string or (af=='ipv6' and n.ipv6)) %}
@@ -98,3 +107,11 @@ updates:
98107
{% for addr in bgp._session_clear|default([]) %}
99108
{{ bgp_admin_state(addr,'default','enable') }}
100109
{% endfor %}
110+
111+
{% if vrfs is defined %}
112+
{% for vname,vdata in vrfs.items() if vdata.bgp is defined %}
113+
{% for addr in vdata.bgp._session_clear|default([]) %}
114+
{{ bgp_admin_state(addr,vname,'enable') }}
115+
{% endfor %}
116+
{% endfor %}
117+
{% endif %}

tests/topology/expected/ebgp.utils.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ nodes:
143143
- 10.0.0.4
144144
- 10.1.0.2
145145
- 10.1.0.6
146-
- 10.1.0.14
147146
advertise_loopback: true
148147
as: 65001
149148
community:
@@ -297,6 +296,8 @@ nodes:
297296
af:
298297
ipv4: true
299298
bgp:
299+
_session_clear:
300+
- 10.1.0.14
300301
import:
301302
connected:
302303
auto: true
@@ -333,7 +334,6 @@ nodes:
333334
- link-bandwidth
334335
_session_clear:
335336
- 10.1.0.1
336-
- 10.1.0.13
337337
- 10.0.0.3
338338
advertise_loopback: true
339339
as: 65002
@@ -448,6 +448,8 @@ nodes:
448448
af:
449449
ipv4: true
450450
bgp:
451+
_session_clear:
452+
- 10.1.0.13
451453
import:
452454
connected:
453455
auto: true

0 commit comments

Comments
 (0)