Skip to content

Commit

Permalink
More spec updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed May 30, 2024
1 parent 96686c0 commit 8999784
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 149 deletions.
568 changes: 429 additions & 139 deletions dash-pipeline/SAI/dash_sai_spec.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash-pipeline/SAI/templates/saiapi.h.j2
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ typedef enum _sai_{{ table.name }}_attr_t

{% endif %}
{% endif %}
{% if sai_attr.validonly | length > 0 %}
{% if sai_attr.validonly != None %}
* @validonly {{ sai_attr.validonly }}
{% endif %}
{% if sai_attr.isresourcetype == 'true' %}
Expand Down
6 changes: 3 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 @@ -311,7 +311,7 @@ def create_sai_structs(self, sai_api: SaiApi) -> None:
if self.is_object != "false":
return

sai_struct_members = [attr.to_sai(self.name) for attr in self.keys if attr.skipattr != "true"]
sai_struct_members = [attr.to_sai_struct_entry(self.name) for attr in self.keys if attr.skipattr != "true"]

sai_struct = SaiStruct(
name=f"sai_{self.name.lower()}_entry_t",
Expand All @@ -323,13 +323,13 @@ def create_sai_structs(self, sai_api: SaiApi) -> None:

def create_sai_stats(self, sai_api: SaiApi) -> None:
sai_api.stats = [
sai_stat.to_sai(self.name)
sai_stat.to_sai_attribute(self.name)
for sai_stat in self.sai_stats
]

def create_sai_attributes(self, sai_api: SaiApi) -> None:
sai_api.attributes.extend(
[attr.to_sai(self.name) for attr in self.sai_attributes if attr.skipattr != "true"]
[attr.to_sai_attribute(self.name) for attr in self.sai_attributes if attr.skipattr != "true"]
)

# If the table has an counter attached, we need to create a counter attribute for it.
Expand Down
19 changes: 17 additions & 2 deletions dash-pipeline/SAI/utils/dash_p4/dash_p4_table_attribute.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional
from .common import *
from .sai_type_solver import SAITypeInfo
from ..sai_spec import SaiAttribute
from ..sai_spec import SaiAttribute, SaiStructEntry


class DashP4TableAttribute(DashP4Object):
Expand All @@ -18,6 +18,7 @@ def __init__(self):
self.object_name: Optional[str] = None
self.skipattr: Optional[str] = None
self.match_type: str = ""
self.validonly: Optional[str] = None

def _parse_sai_table_attribute_annotation(
self, p4rt_anno_list: Dict[str, Any]
Expand Down Expand Up @@ -93,7 +94,20 @@ def set_sai_type(self, sai_type_info: SAITypeInfo) -> None:
#
# Functions for generating SAI specs.
#
def to_sai(self, table_name: str) -> SaiAttribute:
def to_sai_struct_entry(self, table_name: str) -> SaiStructEntry:
name = self._get_sai_name(table_name)
description = self._get_sai_description(table_name)
object_name = f"SAI_OBJECT_TYPE_{self.object_name.upper()}" if self.object_name else None

return SaiStructEntry(
name = name,
description = description,
type = self.type,
objects = object_name,
valid_only = self.validonly,
)

def to_sai_attribute(self, table_name: str) -> SaiAttribute:
name = self._get_sai_name(table_name)
description = self._get_sai_description(table_name)

Expand All @@ -112,6 +126,7 @@ def to_sai(self, table_name: str) -> SaiAttribute:
flags = sai_flags,
object_name = object_name,
allow_null = allow_null,
valid_only = self.validonly,
)

def _get_sai_name(self, table_name: str) -> str:
Expand Down
29 changes: 28 additions & 1 deletion dash-pipeline/SAI/utils/dash_p4/dash_sai_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,38 @@ def post_parsing_process(self) -> None:
#
def to_sai(self) -> SaiSpec:
sai_spec = SaiSpec()
self.create_sai_api_types(sai_spec)
self.create_sai_object_types(sai_spec)
self.create_sai_object_entries(sai_spec)
self.create_sai_enums(sai_spec)
self.create_sai_port_counters(sai_spec.port_extenstion)
sai_spec.api_groups = [api_group.to_sai() for api_group in self.table_groups]
return sai_spec

def create_sai_api_types(self, sai_spec: SaiSpec):
for table_group in self.table_groups:
sai_spec.api_types.append(f"SAI_API_{table_group.app_name.upper()}")

def create_sai_object_types(self, sai_spec: SaiSpec):
for table_group in self.table_groups:
for table in table_group.tables:
sai_spec.object_types.append(f"SAI_OBJECT_TYPE_{table.name.upper()}")

def create_sai_object_entries(self, sai_spec: SaiSpec):
for table_group in self.table_groups:
for table in table_group.tables:
if table.is_object != "false":
continue

object_entry = SaiStructEntry(
name=table.name,
description=f"Object entry for DASH API {table.name}",
type=f"sai_{table.name}_t",
valid_only=f"object_type == SAI_OBJECT_TYPE_{table.name.upper()},"
)

sai_spec.object_entries.append(object_entry)

def create_sai_enums(self, sai_spec: SaiSpec):
for enum in self.enums:
sai_spec.enums.append(enum.to_sai())
Expand All @@ -135,7 +162,7 @@ def create_sai_port_counters(self, api_ext: SaiApiExtension) -> None:
if len(counter.param_actions) > 0:
continue

sai_counter = counter.to_sai("port")
sai_counter = counter.to_sai_attribute("port")

if counter.attr_type != "stats":
api_ext.attributes.append(sai_counter)
Expand Down
1 change: 1 addition & 0 deletions dash-pipeline/SAI/utils/sai_spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
from .sai_enum import SaiEnum
from .sai_enum_member import SaiEnumMember
from .sai_struct import SaiStruct
from .sai_struct_entry import SaiStructEntry
from .sai_attribute import SaiAttribute
2 changes: 2 additions & 0 deletions dash-pipeline/SAI/utils/sai_spec/sai_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(
flags: str = "CREATE_AND_SET",
object_name: Optional[str] = None,
allow_null: bool = False,
valid_only: Optional[str] = None,
):
super().__init__(name, description)
self.type = type
Expand All @@ -27,3 +28,4 @@ def __init__(
self.flags = flags
self.object_name = object_name
self.allow_null = allow_null
self.valid_only = valid_only
2 changes: 2 additions & 0 deletions dash-pipeline/SAI/utils/sai_spec/sai_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .sai_enum import SaiEnum
from .sai_api_group import SaiApiGroup
from .sai_api_extension import SaiApiExtension
from .sai_struct_entry import SaiStructEntry


class SaiSpec:
Expand All @@ -12,6 +13,7 @@ class SaiSpec:
def __init__(self):
self.api_types: List[str] = []
self.object_types: List[str] = []
self.object_entries: List[SaiStructEntry] = []
self.enums: List[SaiEnum] = []
self.port_extenstion: SaiApiExtension = SaiApiExtension()
self.api_groups: List[SaiApiGroup] = []
6 changes: 3 additions & 3 deletions dash-pipeline/SAI/utils/sai_spec/sai_struct.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import List
from .sai_common import SaiCommon
from .sai_attribute import SaiAttribute
from .sai_struct_entry import SaiStructEntry


class SaiStruct(SaiCommon):
"""
This class represents a single SAI struct.
"""

def __init__(self, name: str, description: str, members: List[SaiAttribute] = []):
def __init__(self, name: str, description: str, members: List[SaiStructEntry] = []):
super().__init__(name, description)
self.members: List[SaiAttribute] = members
self.members: List[SaiStructEntry] = members
21 changes: 21 additions & 0 deletions dash-pipeline/SAI/utils/sai_spec/sai_struct_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Optional
from .sai_common import SaiCommon


class SaiStructEntry(SaiCommon):
"""
This class represents a single SAI struct entry.
"""

def __init__(
self,
name: str,
description: str,
type: str,
objects: Optional[str] = None,
valid_only: Optional[str] = None,
):
super().__init__(name, description)
self.type = type
self.objects = objects
self.valid_only = valid_only

0 comments on commit 8999784

Please sign in to comment.