Skip to content

Commit

Permalink
fix template generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed Dec 22, 2023
1 parent 1bd4cee commit 44150df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def __init__(self):
self.bitwidth: int = 64
self.isreadonly: str = "true"
self.counter_type: str = "bytes"
self.action_name: str = ""
self.as_attr: bool = False
self.param_actions: List[str] = []

def parse_p4rt(self, p4rt_counter: Dict[str, Any]) -> None:
'''
Expand Down Expand Up @@ -454,8 +454,8 @@ def __parse_sai_counter_annotation(self, p4rt_counter: Dict[str, Any]) -> None:
for kv in anno[KV_PAIR_LIST_TAG][KV_PAIRS_TAG]:
if self._parse_sai_common_annotation(kv):
continue
elif kv['key'] == 'action_name':
self.action_name = kv['value']['stringValue']
elif kv['key'] == 'action_names':
self.param_actions = kv['value']['stringValue'].split(",")
elif kv['key'] == 'as_attr':
self.as_attr = True if kv['value']['stringValue'] == "true" else False
else:
Expand Down Expand Up @@ -797,7 +797,8 @@ def __build_sai_attributes_after_parsing(self):
# We need to build a mechanism to ensure the order of the attributes, because the attributes can come from
# multiple actions as well as counters. Adding a new parameter to one action may cause the new parameter
# being inserted in the middle of the list and break the ABI compatibility.
self.sai_attributes = self.action_params + [counter for counter in self.counters if counter.as_attr]
self.sai_attributes = [action_param for action_param in self.action_params if action_param.skipattr != "true"] \
+ [counter for counter in self.counters if counter.as_attr]


class DASHAPISet(SAIObject):
Expand Down Expand Up @@ -860,7 +861,8 @@ def __parse_sai_apis_from_p4rt(self, program: Dict[str, Any], ignore_tables: Lis
# Group all counters by action name.
counters_by_action_name = {}
for counter in self.sai_counters:
counters_by_action_name.setdefault(counter.action_name, []).append(counter)
for action_name in counter.param_actions:
counters_by_action_name.setdefault(action_name, []).append(counter)

# Parse all actions.
actions = self.__parse_sai_table_action(program[ACTIONS_TAG], self.sai_enums, counters_by_action_name)
Expand Down
4 changes: 2 additions & 2 deletions dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ control dash_ingress(
// MAX_METER_BUCKET = MAX_ENI(64) * NUM_BUCKETS_PER_ENI(4096)
#define MAX_METER_BUCKETS 262144
#ifdef TARGET_BMV2_V1MODEL
@SaiCounter[name="outbound_bytes_counter", action_name="meter_bucket_action", as_attr="true"]
@SaiCounter[name="outbound_bytes_counter", action_names="meter_bucket_action", as_attr="true"]
counter(MAX_METER_BUCKETS, CounterType.bytes) meter_bucket_outbound;
@SaiCounter[name="inbound_bytes_counter", action_name="meter_bucket_action", as_attr="true"]
@SaiCounter[name="inbound_bytes_counter", action_names="meter_bucket_action", as_attr="true"]
counter(MAX_METER_BUCKETS, CounterType.bytes) meter_bucket_inbound;
#endif // TARGET_BMV2_V1MODEL
action meter_bucket_action(
Expand Down

0 comments on commit 44150df

Please sign in to comment.