Skip to content

Commit

Permalink
Move tables to use SaiTable annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed Dec 12, 2023
1 parent e6a8e98 commit 4d15328
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
12 changes: 9 additions & 3 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import json
import argparse
import shutil
import copy
from jinja2 import Template, Environment, FileSystemLoader
except ImportError as ie:
Expand Down Expand Up @@ -35,6 +34,7 @@
KV_PAIR_LIST_TAG = 'kvPairList'
SAI_VAL_TAG = 'SaiVal'
SAI_TABLE_TAG = 'SaiTable'
SAI_API_ORDER_TAG = 'api_order'

#
# SAI parser decorators:
Expand Down Expand Up @@ -559,6 +559,7 @@ def __init__(self):
# Extra properties from annotations
self.stage = None
self.is_object = None
self.api_order = 0

def parse_p4rt(self, p4rt_table, program, all_actions, ignore_tables):
'''
Expand Down Expand Up @@ -640,6 +641,8 @@ def __parse_sai_table_annotations(self, p4rt_table_preamble):
self.stage = kv['value']['stringValue']
if kv['key'] == 'api':
self.api_name = kv['value']['stringValue']
if kv['key'] == 'api_order':
self.api_order = kv['value']['int64Value']

return

Expand Down Expand Up @@ -747,8 +750,7 @@ def __parse_sai_apis_from_p4rt(self, program, ignore_tables):
actions = self.__parse_sai_table_action(program[ACTIONS_TAG], self.sai_enums)

# Parse all tables into SAI API sets.
tables = sorted(program[TABLES_TAG], key=lambda k: k[PREAMBLE_TAG][NAME_TAG])
for table in tables:
for table in program[TABLES_TAG]:
sai_api_table_data = SAIAPITableData.from_p4rt(table, program, actions, ignore_tables)
if sai_api_table_data.ignored:
continue
Expand All @@ -762,6 +764,10 @@ def __parse_sai_apis_from_p4rt(self, program, ignore_tables):
new_api.add_table(sai_api_table_data)
self.sai_apis.append(new_api)

# Sort all parsed tables by API order, so we can always generate the APIs in the same order for keeping ABI compatibility.
for sai_api in self.sai_apis:
sai_api.tables.sort(key=lambda x: x.api_order)

def __update_table_param_object_name_reference(self):
all_table_names = [table.name for api in self.sai_apis for table in api.tables]

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 @@ -44,6 +44,7 @@ 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`.
- `api_order`: Specify the order of the generated API in the SAI API header file. When multiple tables generates API entries in the same API set, e.g., acl group and acl rules. This explicit attribute helps us keep the order of the generated APIs to keep ABI compatibility.
- `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
2 changes: 1 addition & 1 deletion dash-pipeline/bmv2/dash_acl.p4
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ match_kind {
#ifdef TARGET_BMV2_V1MODEL
#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"] \
@SaiTable[name="dash_acl_rule", stage=str(acl.stage ## stage_index), api="dash_acl", api_order=1] \
table stage ## stage_index { \
key = { \
meta.stage ## stage_index ##_dash_acl_group_id : exact @name("meta.dash_acl_group_id:dash_acl_group_id") \
Expand Down
6 changes: 3 additions & 3 deletions dash-pipeline/bmv2/dash_outbound.p4
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ control outbound(inout headers_t hdr,
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA

@name("outbound_routing|dash_outbound_routing")
@SaiTable[name = "outbound_routing", api = "dash_outbound_routing"]
table routing {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
Expand Down Expand Up @@ -175,7 +175,7 @@ control outbound(inout headers_t hdr,
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA

@name("outbound_ca_to_pa|dash_outbound_ca_to_pa")
@SaiTable[name = "outbound_ca_to_pa", api = "dash_outbound_ca_to_pa"]
table ca_to_pa {
key = {
/* Flow for express route */
Expand Down Expand Up @@ -205,7 +205,7 @@ control outbound(inout headers_t hdr,
meta.encap_data.vni = vni;
}

@name("vnet|dash_vnet")
@SaiTable[name = "vnet", api = "dash_vnet"]
table vnet {
key = {
meta.vnet_id : exact @name("meta.vnet_id:vnet_id");
Expand Down
23 changes: 10 additions & 13 deletions dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ control dash_ingress(
action accept() {
}

@name("vip|dash_vip")
@SaiTable[name = "vip", api = "dash_vip"]
table vip {
key = {
hdr.ipv4.dst_addr : exact @name("hdr.ipv4.dst_addr:VIP");
Expand All @@ -61,7 +61,7 @@ control dash_ingress(
meta.direction = dash_direction_t.INBOUND;
}

@name("direction_lookup|dash_direction_lookup")
@SaiTable[name = "direction_lookup", api = "dash_direction_lookup"]
table direction_lookup {
key = {
hdr.vxlan.vni : exact @name("hdr.vxlan.vni:VNI");
Expand Down Expand Up @@ -153,7 +153,7 @@ control dash_ingress(
}
}

@name("eni|dash_eni")
@SaiTable[name = "eni", api = "dash_eni", api_order=1]
table eni {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
Expand Down Expand Up @@ -211,7 +211,7 @@ control dash_ingress(
meta.vnet_id = src_vnet_id;
}

@name("pa_validation|dash_pa_validation")
@SaiTable[name = "pa_validation", api = "dash_pa_validation"]
table pa_validation {
key = {
meta.vnet_id: exact @name("meta.vnet_id:vnet_id");
Expand All @@ -226,7 +226,7 @@ control dash_ingress(
const default_action = deny;
}

@name("inbound_routing|dash_inbound_routing")
@SaiTable[name = "inbound_routing", api = "dash_inbound_routing"]
table inbound_routing {
key = {
meta.eni_id: exact @name("meta.eni_id:eni_id");
Expand Down Expand Up @@ -254,8 +254,7 @@ control dash_ingress(
}
}

@name("meter_policy|dash_meter")
@SaiTable[isobject="true"]
@SaiTable[name = "meter_policy", api = "dash_meter", api_order = 1, isobject="true"]
table meter_policy {
key = {
meta.meter_policy_id : exact @name("meta.meter_policy_id:meter_policy_id");
Expand All @@ -269,8 +268,7 @@ control dash_ingress(
meta.policy_meter_class = meter_class;
}

@name("meter_rule|dash_meter")
@SaiTable[isobject="true"]
@SaiTable[name = "meter_rule", api = "dash_meter", api_order = 2, isobject="true"]
table meter_rule {
key = {
meta.meter_policy_id: exact @name("meta.meter_policy_id:meter_policy_id") @SaiVal[type="sai_object_id_t", isresourcetype="true", objects="METER_POLICY"];
Expand Down Expand Up @@ -298,8 +296,7 @@ control dash_ingress(
meta.meter_bucket_index = meter_bucket_index;
}

@name("meter_bucket|dash_meter")
@SaiTable[isobject="true"]
@SaiTable[name = "meter_bucket", api = "dash_meter", api_order = 0, isobject="true"]
table meter_bucket {
key = {
meta.eni_id: exact @name("meta.eni_id:eni_id");
Expand All @@ -316,7 +313,7 @@ control dash_ingress(
meta.eni_id = eni_id;
}

@name("eni_ether_address_map|dash_eni")
@SaiTable[name = "eni_ether_address_map", api = "dash_eni", api_order=0]
table eni_ether_address_map {
key = {
meta.eni_addr : exact @name("meta.eni_addr:address");
Expand All @@ -341,7 +338,7 @@ control dash_ingress(
}
}

@name("dash_acl_group|dash_acl")
@SaiTable[name = "dash_acl_group", api = "dash_acl", api_order = 0]
table acl_group {
key = {
meta.stage1_dash_acl_group_id : exact @name("meta.stage1_dash_acl_group_id:dash_acl_group_id");
Expand Down
4 changes: 2 additions & 2 deletions dash-pipeline/bmv2/underlay.p4
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ control underlay(
#endif // TARGET_DPDK_PNA
}

@name("route|route")
// TODO: To add structural annotations (example: @SaiTable[skipHeaderGen=true])
@SaiTable[name = "route", api = "route"]
// TODO: To add structural annotations (example: @SaiTable[skipHeaderGen=true]]
table underlay_routing {
key = {
meta.dst_ip_addr : lpm @name("meta.dst_ip_addr:destination");
Expand Down

0 comments on commit 4d15328

Please sign in to comment.