diff --git a/dash-pipeline/SAI/sai_api_gen.py b/dash-pipeline/SAI/sai_api_gen.py index 3b94645eb..20e5c4ec7 100755 --- a/dash-pipeline/SAI/sai_api_gen.py +++ b/dash-pipeline/SAI/sai_api_gen.py @@ -516,6 +516,7 @@ def __init__(self): self.isreadonly: str = "true" self.counter_type: str = "bytes" self.attr_type: str = "stats" + self.no_suffix: bool = "" self.param_actions: List[str] = [] def parse_p4rt(self, p4rt_counter: Dict[str, Any], var_ref_graph: P4VarRefGraph) -> None: @@ -597,6 +598,8 @@ def __parse_sai_counter_annotation(self, p4rt_counter: Dict[str, Any]) -> None: self.attr_type = str(kv['value']['stringValue']) if self.attr_type not in ["counter_attr", "counter_id", "stats"]: raise ValueError(f'Unknown counter attribute type: attr_type={self.attr_type}') + elif kv['key'] == 'no_suffix': + self.no_suffix = str(kv['value']['stringValue']) == "true" else: raise ValueError("Unknown attr annotation " + kv['key']) @@ -613,10 +616,11 @@ def generate_counter_sai_attributes(self) -> 'Iterator[SAICounter]': counter = copy.deepcopy(self) counter.counter_type = counter_type + if counter.attr_type == "counter_attr": - counter.name = f"{counter.name}_{counter.counter_type}_counter" + counter.name = f"{counter.name}_{counter.counter_type}_counter" if not self.no_suffix else f"{counter.name}_counter" else: - counter.name = f"{counter.name}_{counter.counter_type}" + counter.name = f"{counter.name}_{counter.counter_type}" if not self.no_suffix else counter.name yield counter diff --git a/dash-pipeline/bmv2/dash_arch_specific.p4 b/dash-pipeline/bmv2/dash_arch_specific.p4 index ca7bb75e1..17b8c60e8 100644 --- a/dash-pipeline/bmv2/dash_arch_specific.p4 +++ b/dash-pipeline/bmv2/dash_arch_specific.p4 @@ -28,6 +28,10 @@ @SaiCounter[__VA_ARGS__] \ counter(count, CounterType.bytes) name; + #define DEFINE_HIT_COUNTER(name, count, ...) \ + @SaiCounter[__VA_ARGS__, no_suffix="true"] \ + counter(count, CounterType.packets) name; + #define UPDATE_COUNTER(name, index) \ name.count((bit<32>)index) @@ -40,6 +44,7 @@ #define DEFINE_COUNTER(name, count, ...) #define DEFINE_PACKET_COUNTER(name, count, ...) #define DEFINE_BYTE_COUNTER(name, count, ...) + #define DEFINE_HIT_COUNTER(name, count, ...) #define UPDATE_COUNTER(name, index) #ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE