Skip to content

Commit

Permalink
Fix tunnel member attribute flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed Oct 3, 2024
1 parent 78b1e3a commit 2ec8597
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
3 changes: 0 additions & 3 deletions dash-pipeline/SAI/utils/dash_p4/dash_p4_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 14 additions & 4 deletions dash-pipeline/SAI/utils/dash_p4/dash_p4_table_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions dash-pipeline/SAI/utils/dash_p4/dash_p4_table_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

#
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 @@ -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 <list>`.
- `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
Expand Down
4 changes: 2 additions & 2 deletions dash-pipeline/bmv2/stages/tunnel_stage.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2ec8597

Please sign in to comment.