diff --git a/dash-pipeline/SAI/utils/dash_p4/dash_p4_table.py b/dash-pipeline/SAI/utils/dash_p4/dash_p4_table.py index 1d03687fe..f931d57cb 100644 --- a/dash-pipeline/SAI/utils/dash_p4/dash_p4_table.py +++ b/dash-pipeline/SAI/utils/dash_p4/dash_p4_table.py @@ -128,9 +128,6 @@ def __parse_table_keys(self, p4rt_table: Dict[str, Any]) -> None: for p4rt_table_key in p4rt_table[MATCH_FIELDS_TAG]: table_key = DashP4TableKey.from_p4rt(p4rt_table_key) - # For table keys, we currently require the values to be explicitly set. - table_key.default = None - if self.is_object != "false": table_key.is_entry_key = False diff --git a/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_attribute.py b/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_attribute.py index bdde67de3..537c8b30a 100644 --- a/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_attribute.py +++ b/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_attribute.py @@ -16,6 +16,7 @@ def __init__(self): self.isresourcetype: Optional[str] = None self.isreadonly: Optional[str] = None self.iscreateonly: Optional[str] = None + self.ismandatory: Optional[str] = None self.object_name: Optional[str] = None self.skipattr: Optional[str] = None self.match_type: str = "" @@ -62,6 +63,8 @@ def _parse_sai_table_attribute_annotation( self.isreadonly = str(kv["value"]["stringValue"]) elif kv["key"] == "iscreateonly": self.iscreateonly = str(kv["value"]["stringValue"]) + elif kv["key"] == "ismandatory": + self.ismandatory = str(kv["value"]["stringValue"]) elif kv["key"] == "objects": self.object_name = str(kv["value"]["stringValue"]) elif kv["key"] == "skipattr": @@ -140,16 +143,23 @@ def to_sai_attribute(self, table_name: str, add_action_valid_only_check: bool = sai_flags = "READ_ONLY" default_value = None elif self.iscreateonly == "true": - if self.default == None: + if self.default == None or self.ismandatory == "true": sai_flags = "MANDATORY_ON_CREATE | CREATE_ONLY" + default_value = None + allow_null = False else: sai_flags = "CREATE_ONLY" + default_value = self.default - default_value = self.default allow_null = False else: - sai_flags = "CREATE_AND_SET" - default_value = self.default + if self.ismandatory == "true": + sai_flags = "MANDATORY_ON_CREATE | CREATE_AND_SET" + default_value = None + allow_null = False + else: + sai_flags = "CREATE_AND_SET" + default_value = self.default valid_only_checks = [] if add_action_valid_only_check: diff --git a/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_key.py b/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_key.py index 758497dd3..1432c0a61 100644 --- a/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_key.py +++ b/dash-pipeline/SAI/utils/dash_p4/dash_p4_table_key.py @@ -12,6 +12,7 @@ class DashP4TableKey(DashP4TableAttribute): def __init__(self): super().__init__() self.iscreateonly: str = "true" + self.ismandatory: str = "true" self.ip_is_v6_field_id: int = 0 def parse_p4rt(self, p4rt_table_key: Dict[str, Any]) -> None: @@ -56,6 +57,9 @@ def parse_p4rt(self, p4rt_table_key: Dict[str, Any]) -> None: self.set_sai_type(sai_type_info) + # For table keys, we currently require the values to be explicitly set. + self.default = None + return # diff --git a/dash-pipeline/bmv2/README.md b/dash-pipeline/bmv2/README.md index 9b0baac57..1d2927a2e 100644 --- a/dash-pipeline/bmv2/README.md +++ b/dash-pipeline/bmv2/README.md @@ -32,6 +32,7 @@ Available tags are: - `objects`: Space separated list of SAI object type this value accepts. When set, we force this value to be a SAI object id, and generate a corresponding SAI tag in SAI APIs: `@objects `. - `isreadonly`: When set to "true", we generate force this value to be read-only in SAI API using: `@flags READ_ONLY`, otherwise, we generate `@flags CREATE_AND_SET`. It cannot be used with `iscreateonly`. - `iscreateonly`: When set to "true", we generate force this value to be create-only in SAI API using: `@flags CREATE_ONLY`, otherwise, we generate `@flags CREATE_AND_SET`. It cannot be used with `isreadonly`. +- `ismandatory`: When set to "true", we generate force this value to be mandatory in SAI API using: `@flags MANDATORY_ON_CREATE`. It cannot be used with `isreadonly`. - `skipattr`: When set to "true", we skip this attribute in SAI API generation. #### `@SaiCounter`: Counters diff --git a/dash-pipeline/bmv2/stages/tunnel_stage.p4 b/dash-pipeline/bmv2/stages/tunnel_stage.p4 index c9d824d1a..3f218cb2e 100644 --- a/dash-pipeline/bmv2/stages/tunnel_stage.p4 +++ b/dash-pipeline/bmv2/stages/tunnel_stage.p4 @@ -60,8 +60,8 @@ control tunnel_stage( } action set_tunnel_member_attrs( - @SaiVal[type="sai_object_id_t"] bit<16> dash_tunnel_id, - @SaiVal[type="sai_object_id_t"] bit<16> dash_tunnel_next_hop_id) + @SaiVal[type="sai_object_id_t", ismandatory="true", iscreateonly="true"] bit<16> dash_tunnel_id, + @SaiVal[type="sai_object_id_t", ismandatory="true"] bit<16> dash_tunnel_next_hop_id) { // dash_tunnel_id in tunnel member must match the metadata REQUIRES(meta.dash_tunnel_id == dash_tunnel_id);