Skip to content

Commit

Permalink
Adding match_type annotation to generate the right ACL files.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed Dec 14, 2023
1 parent cba06d0 commit 1d67430
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def __init__(self):
self.skipattr = None
self.field = None
self.default = None
self.match_type = ""

def parse_basic_info_if_exists(self, p4rt_object):
'''
Expand Down Expand Up @@ -300,6 +301,8 @@ def _parse_sai_object_annotation(self, p4rt_anno_list):
self.object_name = kv['value']['stringValue']
elif kv['key'] == 'skipattr':
self.skipattr = kv['value']['stringValue']
elif kv['key'] == 'match_type':
self.match_type = kv['value']['stringValue']
else:
raise ValueError("Unknown attr annotation " + kv['key'])

Expand Down Expand Up @@ -381,7 +384,6 @@ class SAIAPITableKey(SAIObject):
'''
def __init__(self):
super().__init__()
self.match_type = ""
self.bitwidth = 0
self.ip_is_v6_field_id = 0

Expand Down
1 change: 1 addition & 0 deletions dash-pipeline/bmv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Available tags are:
- `stage`: Specify which stage this table represents for the matching stage type, e.g. `acl.stage1`.
- `isobject`: When set to "true", a top level objects in SAI that attached to switch will be generated. Otherwise, a new type of entry will be generated, if nothing else helps us to determine this table is an object table.
- `ignored`: When set to "true", we skip this table in SAI API generation.
- `match_type`: Some match kinds used in DASH might not be supported by BMv2, such as `list` and `range_list`. In BMv2, we use `optional` to make the P4 compiler happy. However, we still want to generate the correct SAI API. This tag is used to specify the match type in SAI API generation.

For more details, please check the SAI API generation script: [sai_api_gen.py](../SAI/sai_api_gen.py).

Expand Down
10 changes: 5 additions & 5 deletions dash-pipeline/bmv2/dash_acl.p4
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ match_kind {
key = { \
meta.stage ## stage_index ##_dash_acl_group_id : exact \
@SaiVal[name = "dash_acl_group_id", type="sai_object_id_t", isresourcetype="true", objects="SAI_OBJECT_TYPE_DASH_ACL_GROUP"]; \
meta.dst_ip_addr : LIST_MATCH @SaiVal[name = "dip", type = "sai_ip_prefix_list_t"]; \
meta.src_ip_addr : LIST_MATCH @SaiVal[name = "sip", type = "sai_ip_prefix_list_t"]; \
meta.ip_protocol : LIST_MATCH @SaiVal[name = "protocol", type = "sai_u8_list_t"]; \
meta.src_l4_port : RANGE_LIST_MATCH @SaiVal[name = "src_port", type = "sai_u16_range_list_t"]; \
meta.dst_l4_port : RANGE_LIST_MATCH @SaiVal[name = "dst_port", type = "sai_u16_range_list_t"]; \
meta.dst_ip_addr : LIST_MATCH @SaiVal[name = "dip", type = "sai_ip_prefix_list_t", match_type = "list"]; \
meta.src_ip_addr : LIST_MATCH @SaiVal[name = "sip", type = "sai_ip_prefix_list_t", match_type = "list"]; \
meta.ip_protocol : LIST_MATCH @SaiVal[name = "protocol", type = "sai_u8_list_t", match_type = "list"]; \
meta.src_l4_port : RANGE_LIST_MATCH @SaiVal[name = "src_port", type = "sai_u16_range_list_t", match_type = "range_list"]; \
meta.dst_l4_port : RANGE_LIST_MATCH @SaiVal[name = "dst_port", type = "sai_u16_range_list_t", match_type = "range_list"]; \
} \
actions = { \
permit; \
Expand Down

0 comments on commit 1d67430

Please sign in to comment.