Skip to content

Commit a0bff26

Browse files
[acl-loader] modify acl-loader with change in STATE DB ACL capability table (sonic-net#1896)
* [acl-loader] modify acl-loader with change in STATE DB ACL capability table Signed-off-by: Stepan Blyshchak <[email protected]>
1 parent a395e28 commit a0bff26

File tree

7 files changed

+60
-27
lines changed

7 files changed

+60
-27
lines changed

acl_loader/main.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class AclLoader(object):
7878
POLICER = "POLICER"
7979
SESSION_PREFIX = "everflow"
8080
SWITCH_CAPABILITY_TABLE = "SWITCH_CAPABILITY"
81-
ACL_ACTIONS_CAPABILITY_FIELD = "ACL_ACTIONS"
81+
ACL_STAGE_CAPABILITY_TABLE = "ACL_STAGE_CAPABILITY_TABLE"
82+
ACL_ACTIONS_CAPABILITY_FIELD = "action_list"
8283
ACL_ACTION_CAPABILITY_FIELD = "ACL_ACTION"
8384

8485
min_priority = 1
@@ -402,16 +403,18 @@ def validate_actions(self, table_name, action_props):
402403
# Same information should be there in all state DB's
403404
# as it is static information about switch capability
404405
namespace_statedb = list(self.per_npu_statedb.values())[0]
405-
capability = namespace_statedb.get_all(self.statedb.STATE_DB, "{}|switch".format(self.SWITCH_CAPABILITY_TABLE))
406+
aclcapability = namespace_statedb.get_all(self.statedb.STATE_DB, "{}|{}".format(self.ACL_STAGE_CAPABILITY_TABLE, stage.upper()))
407+
switchcapability = namespace_statedb.get_all(self.statedb.STATE_DB, "{}|switch".format(self.SWITCH_CAPABILITY_TABLE))
406408
else:
407-
capability = self.statedb.get_all(self.statedb.STATE_DB, "{}|switch".format(self.SWITCH_CAPABILITY_TABLE))
409+
aclcapability = self.statedb.get_all(self.statedb.STATE_DB, "{}|{}".format(self.ACL_STAGE_CAPABILITY_TABLE, stage.upper()))
410+
switchcapability = self.statedb.get_all(self.statedb.STATE_DB, "{}|switch".format(self.SWITCH_CAPABILITY_TABLE))
408411
for action_key in dict(action_props):
409-
key = "{}|{}".format(self.ACL_ACTIONS_CAPABILITY_FIELD, stage.upper())
410-
if key not in capability:
412+
action_list_key = self.ACL_ACTIONS_CAPABILITY_FIELD
413+
if action_list_key not in aclcapability:
411414
del action_props[action_key]
412415
continue
413416

414-
values = capability[key].split(",")
417+
values = aclcapability[action_list_key].split(",")
415418
if action_key.upper() not in values:
416419
del action_props[action_key]
417420
continue
@@ -420,11 +423,11 @@ def validate_actions(self, table_name, action_props):
420423
# Check if action_value is supported
421424
action_value = action_props[action_key]
422425
key = "{}|{}".format(self.ACL_ACTION_CAPABILITY_FIELD, action_key.upper())
423-
if key not in capability:
426+
if key not in switchcapability:
424427
del action_props[action_key]
425428
continue
426429

427-
if action_value not in capability[key]:
430+
if action_value not in switchcapability[key]:
428431
del action_props[action_key]
429432
continue
430433

tests/acl_loader_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_validate_mirror_action(self, acl_loader):
3535
"mirror_egress_action": "everflow0"
3636
}
3737

38-
# switch capability taken from mock_tables/state_db.json SWITCH_CAPABILITY table
38+
# switch capability taken from mock_tables/state_db.json ACL_STAGE_CAPABILITY_TABLE table
3939
assert acl_loader.validate_actions("EVERFLOW", ingress_mirror_rule_props)
4040
assert not acl_loader.validate_actions("EVERFLOW", egress_mirror_rule_props)
4141

@@ -50,7 +50,7 @@ def test_validate_mirror_action(self, acl_loader):
5050
"PACKET_ACTION": "DROP"
5151
}
5252

53-
# switch capability taken from mock_tables/state_db.json SWITCH_CAPABILITY table
53+
# switch capability taken from mock_tables/state_db.json ACL_STAGE_CAPABILITY_TABLE table
5454
assert acl_loader.validate_actions("DATAACL", forward_packet_action)
5555
assert not acl_loader.validate_actions("DATAACL", drop_packet_action)
5656

tests/mock_tables/asic0/state_db.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@
6565
"SWITCH_CAPABILITY|switch": {
6666
"MIRROR": "true",
6767
"MIRRORV6": "true",
68-
"ACL_ACTIONS|INGRESS": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION",
69-
"ACL_ACTIONS|EGRESS": "PACKET_ACTION,MIRROR_EGRESS_ACTION",
7068
"ACL_ACTION|PACKET_ACTION": "FORWARD"
7169
},
70+
"ACL_STAGE_CAPABILITY_TABLE|INGRESS": {
71+
"action_list": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION"
72+
},
73+
"ACL_STAGE_CAPABILITY_TABLE|EGRESS": {
74+
"action_list": "PACKET_ACTION,MIRROR_EGRESS_ACTION"
75+
},
7276
"DEBUG_COUNTER_CAPABILITIES|PORT_INGRESS_DROPS": {
7377
"reasons": "[IP_HEADER_ERROR,NO_L3_HEADER]",
7478
"count": "4"

tests/mock_tables/asic1/state_db.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@
6565
"SWITCH_CAPABILITY|switch": {
6666
"MIRROR": "true",
6767
"MIRRORV6": "true",
68-
"ACL_ACTIONS|INGRESS": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION",
69-
"ACL_ACTIONS|EGRESS": "PACKET_ACTION,MIRROR_EGRESS_ACTION",
7068
"ACL_ACTION|PACKET_ACTION": "FORWARD"
7169
},
70+
"ACL_STAGE_CAPABILITY_TABLE|INGRESS": {
71+
"action_list": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION"
72+
},
73+
"ACL_STAGE_CAPABILITY_TABLE|EGRESS": {
74+
"action_list": "PACKET_ACTION,MIRROR_EGRESS_ACTION"
75+
},
7276
"DEBUG_COUNTER_CAPABILITIES|PORT_INGRESS_DROPS": {
7377
"reasons": "[IP_HEADER_ERROR,NO_L3_HEADER]",
7478
"count": "4"

tests/mock_tables/asic2/state_db.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@
6565
"SWITCH_CAPABILITY|switch": {
6666
"MIRROR": "true",
6767
"MIRRORV6": "true",
68-
"ACL_ACTIONS|INGRESS": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION",
69-
"ACL_ACTIONS|EGRESS": "PACKET_ACTION,MIRROR_EGRESS_ACTION",
7068
"ACL_ACTION|PACKET_ACTION": "FORWARD"
7169
},
70+
"ACL_STAGE_CAPABILITY_TABLE|INGRESS": {
71+
"action_list": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION"
72+
},
73+
"ACL_STAGE_CAPABILITY_TABLE|EGRESS": {
74+
"action_list": "PACKET_ACTION,MIRROR_EGRESS_ACTION"
75+
},
7276
"DEBUG_COUNTER_CAPABILITIES|PORT_INGRESS_DROPS": {
7377
"reasons": "[IP_HEADER_ERROR,NO_L3_HEADER]",
7478
"count": "4"

tests/mock_tables/state_db.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,14 @@
286286
"MIRRORV6": "true",
287287
"PORT_TPID_CAPABLE": "true",
288288
"LAG_TPID_CAPABLE": "true",
289-
"ACL_ACTIONS|INGRESS": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION",
290-
"ACL_ACTIONS|EGRESS": "PACKET_ACTION,MIRROR_EGRESS_ACTION",
291289
"ACL_ACTION|PACKET_ACTION": "FORWARD"
292290
},
291+
"ACL_STAGE_CAPABILITY_TABLE|INGRESS": {
292+
"action_list": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION"
293+
},
294+
"ACL_STAGE_CAPABILITY_TABLE|EGRESS": {
295+
"action_list": "PACKET_ACTION,MIRROR_EGRESS_ACTION"
296+
},
293297
"DEBUG_COUNTER_CAPABILITIES|PORT_INGRESS_DROPS": {
294298
"reasons": "[IP_HEADER_ERROR,NO_L3_HEADER]",
295299
"count": "4"

tests/mock_tables/t1/state_db.json

+23-9
Original file line numberDiff line numberDiff line change
@@ -6114,17 +6114,31 @@
61146114
},
61156115
"SWITCH_CAPABILITY|switch": {
61166116
"expireat": 1602454497.423883,
6117-
"ttl": -0.001,
6118-
"type": "hash",
6117+
"ttl": -0.001,
6118+
"type": "hash",
61196119
"value": {
6120-
"ACL_ACTIONS|EGRESS": "PACKET_ACTION",
6121-
"ACL_ACTIONS|INGRESS": "PACKET_ACTION,MIRROR_INGRESS_ACTION",
6122-
"ACL_ACTION|PACKET_ACTION": "DROP,FORWARD",
6123-
"MAX_NEXTHOP_GROUP_COUNT": "512",
6124-
"MIRROR": "true",
6125-
"MIRRORV6": "true"
6120+
"MAX_NEXTHOP_GROUP_COUNT": "512",
6121+
"MIRROR": "true",
6122+
"MIRRORV6": "true",
6123+
"PACKET_ACTION": "DROP,FORWARD"
61266124
}
61276125
},
6126+
"ACL_STAGE_CAPABILITY_TABLE|EGRESS": {
6127+
"expireat": 1602454497.423883,
6128+
"ttl": -0.001,
6129+
"type": "hash",
6130+
"value": {
6131+
"action_list": "PACKET_ACTION,MIRROR_INGRESS_ACTION"
6132+
}
6133+
},
6134+
"ACL_STAGE_CAPABILITY_TABLE|INGRESS": {
6135+
"expireat": 1602454497.423883,
6136+
"ttl": -0.001,
6137+
"type": "hash",
6138+
"value": {
6139+
"action_list": "PACKET_ACTION"
6140+
}
6141+
},
61286142
"TRANSCEIVER_DOM_SENSOR|Ethernet0": {
61296143
"expireat": 1602454497.4302251,
61306144
"ttl": -0.001,
@@ -7909,4 +7923,4 @@
79097923
"restore_count": "0"
79107924
}
79117925
}
7912-
}
7926+
}

0 commit comments

Comments
 (0)