Skip to content

Commit fc324f2

Browse files
stchenglguohan
authored andcommitted
[neighbor_advertiser]: Adapt to different mirror ACL table names (#703)
ACL table names varies on different platforms. The current assumption is that the name would contain either EVERFLOW or EVERFLOWV6. Thus a function find_mirror_table_name is added to find the exact names for both the v4 and v6 mirror table names. Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
1 parent 342f3a1 commit fc324f2

1 file changed

Lines changed: 46 additions & 19 deletions

File tree

scripts/neighbor_advertiser

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SYSLOG_IDENTIFIER = 'neighbor_advertiser'
3636
#
3737

3838
MIRROR_SESSION_NAME = 'neighbor_advertiser'
39+
MIRROR_ACL_TABLE_PREFIX = 'SONIC_'
3940
MIRROR_ACL_TABLE_NAME = 'EVERFLOW'
4041
MIRROR_ACL_TABLEV6_NAME = 'EVERFLOWV6'
4142
MIRROR_ACL_RULE_NAME = 'rule_arp'
@@ -384,10 +385,30 @@ def save_as_json(obj, file_path):
384385
json.dump(obj, outfile, sort_keys = True)
385386

386387

388+
# This function tries to find the corresponding names of the mirror v4 and v6 table
389+
# Right now, the name could be EVERFLOW/EVERFLOWv6 or SONIC_EVERFLOW/SONIC_EVERFLOWV6
390+
def find_mirror_table_name():
391+
acl_tables = config_db.get_keys("ACL_TABLE")
392+
v4_table, v6_table = "", ""
393+
for table in acl_tables:
394+
if MIRROR_ACL_TABLE_NAME == table or \
395+
MIRROR_ACL_TABLE_PREFIX + MIRROR_ACL_TABLE_NAME == table:
396+
v4_table = table
397+
if MIRROR_ACL_TABLEV6_NAME == table or \
398+
MIRROR_ACL_TABLE_PREFIX + MIRROR_ACL_TABLEV6_NAME == table:
399+
v6_table = table
400+
if not v4_table:
401+
log_error(MIRROR_ACL_TABLE_NAME + " table does not exist")
402+
if not v6_table:
403+
log_error(MIRROR_ACL_TABLEV6_NAME + " table does not exist")
404+
return (v4_table, v6_table)
405+
406+
387407
#
388408
# Set mirror tunnel
389409
#
390410

411+
391412
def add_mirror_session(dst_ipv4_addr):
392413
session_info = {
393414
'src_ip': get_loopback_addr(4),
@@ -397,25 +418,26 @@ def add_mirror_session(dst_ipv4_addr):
397418
config_db.set_entry('MIRROR_SESSION', MIRROR_SESSION_NAME, session_info)
398419

399420

400-
401421
def add_mirror_acl_rule():
402-
acl_rule_info = {
403-
'PRIORITY': '8888',
404-
'ether_type': '2054',
405-
'mirror_action': MIRROR_SESSION_NAME
406-
}
407-
408-
config_db.set_entry('ACL_RULE',
409-
(MIRROR_ACL_TABLE_NAME, MIRROR_ACL_RULE_NAME), acl_rule_info)
422+
(v4_table, v6_table) = find_mirror_table_name()
410423

411-
acl_rule_info = {
412-
'PRIORITY': '8887',
413-
'ICMPV6_TYPE': '135',
414-
'mirror_action': MIRROR_SESSION_NAME
415-
}
416-
417-
config_db.set_entry('ACL_RULE',
418-
(MIRROR_ACL_TABLEV6_NAME, MIRROR_ACL_RULEV6_NAME), acl_rule_info)
424+
if v4_table:
425+
acl_rule_info = {
426+
'PRIORITY': '8888',
427+
'ether_type': '2054',
428+
'mirror_action': MIRROR_SESSION_NAME
429+
}
430+
config_db.set_entry('ACL_RULE',
431+
(v4_table, MIRROR_ACL_RULE_NAME), acl_rule_info)
432+
433+
if v6_table:
434+
acl_rule_info = {
435+
'PRIORITY': '8887',
436+
'ICMPV6_TYPE': '135',
437+
'mirror_action': MIRROR_SESSION_NAME
438+
}
439+
config_db.set_entry('ACL_RULE',
440+
(v6_table, MIRROR_ACL_RULEV6_NAME), acl_rule_info)
419441

420442

421443
def set_mirror_tunnel(ferret_server_ip):
@@ -433,8 +455,13 @@ def remove_mirror_session():
433455

434456

435457
def remove_mirror_acl_rule():
436-
config_db.set_entry('ACL_RULE', (MIRROR_ACL_TABLE_NAME, MIRROR_ACL_RULE_NAME), None)
437-
config_db.set_entry('ACL_RULE', (MIRROR_ACL_TABLEV6_NAME, MIRROR_ACL_RULEV6_NAME), None)
458+
(v4_table, v6_table) = find_mirror_table_name()
459+
460+
if v4_table:
461+
config_db.set_entry('ACL_RULE', (v4_table, MIRROR_ACL_RULE_NAME), None)
462+
463+
if v6_table:
464+
config_db.set_entry('ACL_RULE', (v6_table, MIRROR_ACL_RULEV6_NAME), None)
438465

439466

440467
def reset_mirror_tunnel():

0 commit comments

Comments
 (0)