Skip to content

Commit c0ae0f3

Browse files
authored
Fix: Junos quirks have to check RP set.community and delete.community (#2846)
The Junos 'delete community' RP functionality was broken by #2842 when the 'delete community' functionality was moved from 'set.community.delete' to 'delete.community'.
1 parent 533f9da commit c0ae0f3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

netsim/devices/junos.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,18 @@ def community_set_quirk(node: Box, topology: Box) -> None:
203203
node.routing['community'] = {}
204204
for pl_name, pl_list in node.routing.get('policy', {}).items():
205205
for pl_item in pl_list:
206-
comm_struct = pl_item.get('set.community', {})
207-
if comm_struct:
208-
for ct in ['standard','extended','large']:
206+
for cmod_kw in ('set.community','delete.community'): # Have to create policies for set/delete community
207+
comm_struct = pl_item.get(cmod_kw, None)
208+
if not comm_struct: # Keyword not used in the RP entry, move on
209+
continue
210+
211+
for ct in ['standard','extended','large']: # Do the same fixup for all three community types
209212
for comm in comm_struct.get(ct, []):
210-
comm_action = 'set'
211-
if comm_struct.get('append', False):
212-
comm_action = 'add'
213-
if comm_struct.get('delete', False):
213+
comm_action = 'set' # Figure out the operation (set/add/del)
214+
if 'delete' in cmod_kw:
214215
comm_action = 'del'
216+
elif comm_struct.get('append', False):
217+
comm_action = 'add'
215218
# add this "fake" community to the community list
216219
comm_list_name = f"{comm_name_prefix}_{comm_action}_{comm}"
217220
comm_list_name = comm_list_name.replace(':', '_')
@@ -225,6 +228,10 @@ def community_set_quirk(node: Box, topology: Box) -> None:
225228
comm_list.append({ "action": "permit", "_value": "65535:0:65536" })
226229
else:
227230
comm_list.append({ "action": "permit", "_value": "large:65535:0:65536" })
231+
232+
# Note that the Junos implementation incorrectly used 'type' attribute to save the
233+
# community type that should be matched (standard/extended/large), not the type of
234+
# match (standard/expanded). This mismatch will disappear once we implement #2243
228235
node.routing.community[comm_list_name] = {
229236
'type': ct,
230237
'value': comm_list,

0 commit comments

Comments
 (0)