Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sai-gen] Move acl table to use SaiTable annotation. #478

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def register_sai_type(name, field_func_prefix, default = None, is_enum = False):

@staticmethod
def get_sai_type(sai_type):
if sai_type not in SAITypeSolver.sai_type_info_registry:
raise ValueError(f'sai_type={sai_type} is not supported')

return SAITypeSolver.sai_type_info_registry[sai_type]

@staticmethod
Expand Down Expand Up @@ -520,13 +523,12 @@ def parse_p4rt(self, p4rt_table_action_param, sai_enums, ip_is_v6_param_ids):
self.id = p4rt_table_action_param['id']
self.name = p4rt_table_action_param[NAME_TAG]
self.bitwidth = p4rt_table_action_param[BITWIDTH_TAG]
#print("Parsing table action param: " + self.name)
print("Parsing table action param: " + self.name)

if STRUCTURED_ANNOTATIONS_TAG in p4rt_table_action_param:
self._parse_sai_object_annotation(p4rt_table_action_param)
else:
sai_type_info = SAITypeSolver.get_object_sai_type(self.bitwidth, self.name, self.name)
print("Parsing table action param: " + self.name + ", type: " + sai_type_info.name, ", is_enum: " + str(sai_type_info.is_enum))
self.type, self.field = sai_type_info.name, sai_type_info.field_func_prefix
if sai_type_info.is_enum:
self.default = sai_type_info.default
Expand Down Expand Up @@ -632,6 +634,12 @@ def __parse_sai_table_annotations(self, p4rt_table_preamble):
self.is_object = kv['value']['stringValue']
if kv['key'] == 'ignoretable':
self.ignored = True
if kv['key'] == 'name':
self.name = kv['value']['stringValue']
if kv['key'] == 'stage':
self.stage = kv['value']['stringValue']
if kv['key'] == 'api':
self.api_name = kv['value']['stringValue']

return

Expand Down
3 changes: 3 additions & 0 deletions dash-pipeline/bmv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Use `@SaiTable["tag"="value", ...]` format for annotating tables.

Available tags are:

- `name`: Specify the preferred table name in SAI API generation, e.g. `dash_acl_rule`.
- `api`: Specify which SAI API should be used in generation, e.g. `dash_acl`.
- `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.
- `ignoretable`: When set to "true", we skip this table in SAI API generation.

Expand Down
42 changes: 21 additions & 21 deletions dash-pipeline/bmv2/dash_acl.p4
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ match_kind {
#define str(name) #name

#ifdef TARGET_BMV2_V1MODEL
#define ACL_STAGE(table_name) \
direct_counter(CounterType.packets_and_bytes) ## table_name ##_counter; \
@name(str(table_name##:dash_acl_rule|dash_acl)) \
table table_name { \
#define ACL_STAGE(stage_index) \
direct_counter(CounterType.packets_and_bytes) ## stage ## stage_index ##_counter; \
@SaiTable[name="dash_acl_rule", stage=str(acl.stage ## stage_index), api="dash_acl"] \
table stage ## stage_index { \
key = { \
meta. ## table_name ##_dash_acl_group_id : exact @name("meta.dash_acl_group_id:dash_acl_group_id") \
meta.stage ## stage_index ##_dash_acl_group_id : exact @name("meta.dash_acl_group_id:dash_acl_group_id") \
@SaiVal[type="sai_object_id_t", isresourcetype="true", objects="SAI_OBJECT_TYPE_DASH_ACL_GROUP"]; \
meta.dst_ip_addr : LIST_MATCH @name("meta.dst_ip_addr:dip"); \
meta.src_ip_addr : LIST_MATCH @name("meta.src_ip_addr:sip"); \
Expand All @@ -51,7 +51,7 @@ match_kind {
deny_and_continue; \
} \
default_action = deny; \
counters = ## table_name ##_counter; \
counters = stage ## stage_index ##_counter; \
}
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
Expand All @@ -63,17 +63,17 @@ match_kind {

// (1) Add the following line as the first line of the definition of
// ACL_STAGE:
// DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) ## table_name ##_counter; \
// DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) stage ## stage_index ##_counter; \

// (2) Add the following line immediately after the line defining the
// default_action of the table:
// pna_direct_counter = ## table_name ##_counter; \
// pna_direct_counter = stage ## stage_index ##_counter; \

#define ACL_STAGE(table_name) \
@name(str(table_name##:dash_acl_rule|dash_acl)) \
table table_name { \
#define ACL_STAGE(stage_index) \
@SaiTable[name="dash_acl_rule", stage=str(acl.stage ## stage_index), api="dash_acl"] \
table stage ##stage_index { \
key = { \
meta. ## table_name ##_dash_acl_group_id : exact @name("meta.dash_acl_group_id:dash_acl_group_id"); \
meta.stage ## stage_index ##_dash_acl_group_id : exact @name("meta.dash_acl_group_id:dash_acl_group_id"); \
meta.dst_ip_addr : LIST_MATCH @name("meta.dst_ip_addr:dip"); \
meta.src_ip_addr : LIST_MATCH @name("meta.src_ip_addr:sip"); \
meta.ip_protocol : LIST_MATCH @name("meta.ip_protocol:protocol"); \
Expand All @@ -90,9 +90,9 @@ match_kind {
}
#endif // TARGET_DPDK_PNA

#define ACL_STAGE_APPLY(table_name) \
if ( meta. ## table_name ##_dash_acl_group_id != 0) { \
switch (table_name.apply().action_run) { \
#define ACL_STAGE_APPLY(stage_index) \
if ( meta.stage ## stage_index ##_dash_acl_group_id != 0) { \
switch (stage ## stage_index.apply().action_run) { \
permit: {return;} \
deny: {return;} \
} \
Expand All @@ -111,14 +111,14 @@ control acl(inout headers_t hdr,
action deny() {meta.dropped = true;}
action deny_and_continue() {meta.dropped = true;}

ACL_STAGE(stage1)
ACL_STAGE(stage2)
ACL_STAGE(stage3)
ACL_STAGE(1)
ACL_STAGE(2)
ACL_STAGE(3)

apply {
ACL_STAGE_APPLY(stage1)
ACL_STAGE_APPLY(stage2)
ACL_STAGE_APPLY(stage3)
ACL_STAGE_APPLY(1)
ACL_STAGE_APPLY(2)
ACL_STAGE_APPLY(3)
}
}
#endif /* _SIRIUS_ACL_P4_ */
6 changes: 3 additions & 3 deletions dash-pipeline/bmv2/dash_outbound.p4
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ control outbound(inout headers_t hdr,
IPv4ORv6Address underlay_dip,
bit<1> underlay_sip_is_v6,
IPv4ORv6Address underlay_sip,
@Sai[type="sai_dash_encapsulation_t", default_value="SAI_DASH_ENCAPSULATION_VXLAN"]
@SaiVal[type="sai_dash_encapsulation_t", default_value="SAI_DASH_ENCAPSULATION_VXLAN"]
dash_encapsulation_t dash_encapsulation,
bit<24> tunnel_key,
bit<1> meter_policy_en,
Expand Down Expand Up @@ -120,7 +120,7 @@ control outbound(inout headers_t hdr,
}

action set_tunnel(IPv4Address underlay_dip,
@Sai[type="sai_dash_encapsulation_t"] dash_encapsulation_t dash_encapsulation,
@SaiVal[type="sai_dash_encapsulation_t"] dash_encapsulation_t dash_encapsulation,
bit<16> meter_class,
bit<1> meter_class_override) {
meta.encap_data.underlay_dip = underlay_dip;
Expand All @@ -147,7 +147,7 @@ control outbound(inout headers_t hdr,
action set_private_link_mapping(IPv4Address underlay_dip,
IPv6Address overlay_sip,
IPv6Address overlay_dip,
@Sai[type="sai_dash_encapsulation_t"] dash_encapsulation_t dash_encapsulation,
@SaiVal[type="sai_dash_encapsulation_t"] dash_encapsulation_t dash_encapsulation,
bit<24> tunnel_key,
bit<16> meter_class,
bit<1> meter_class_override) {
Expand Down