Skip to content

Commit

Permalink
Add structured annotations to params
Browse files Browse the repository at this point in the history
  • Loading branch information
saad-mzhr committed Sep 4, 2023
1 parent 0ba774c commit b057cee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dash-pipeline/python_model/dash_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def deny_and_continue():
default_action = deny,
api_hints = {
API_NAME : "dash_acl",
"meta.dash_acl_group_id" : {TYPE : "sai_object_id_t", ISRESOURCETYPE : True, OBJECTS : "SAI_OBJECT_TYPE_DASH_ACL_GROUP"}
"meta.dash_acl_group_id" : {TYPE : "sai_object_id_t", ISRESOURCETYPE : "true", OBJECTS : "SAI_OBJECT_TYPE_DASH_ACL_GROUP"}
}
)

Expand Down
1 change: 0 additions & 1 deletion dash-pipeline/python_model/dash_api_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
API_NAME = "api_name"
SAI_KEY_NAME = "sai_key_name"
DEFAULT_ONLY = "default_only"
SAI = "sai"
ISOBJECT = "isobject"
TYPE = "type"
ISRESOURCETYPE = "isresourcetype"
Expand Down
18 changes: 9 additions & 9 deletions dash-pipeline/python_model/dash_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def vxlan_decap_pa_validate(src_vnet_id: Annotated[int, 16]):
}
)

def check_ip_addr_family(ip_addr_family: Annotated[int, 32, {TYPE : "sai_ip_addr_family_t", ISRESOURCETYPE : True}]):
def check_ip_addr_family(ip_addr_family: Annotated[int, 32, {TYPE : "sai_ip_addr_family_t", ISRESOURCETYPE : "true"}]):
if ip_addr_family == 0:
if meta.is_overlay_ip_v6 == 1:
meta.dropped = True
Expand All @@ -216,7 +216,7 @@ def check_ip_addr_family(ip_addr_family: Annotated[int, 32, {TYPE : "sai_ip_addr
],
api_hints = {
API_NAME : "dash_meter",
ISOBJECT : True
ISOBJECT : "true"
}
)

Expand All @@ -236,8 +236,8 @@ def set_policy_meter_class(meter_class: Annotated[int, 16]):

api_hints = {
API_NAME : "dash_meter",
ISOBJECT : True,
"meta.meter_policy_id" : {TYPE : "sai_object_id_t", ISRESOURCETYPE : True, OBJECTS : "METER_POLICY"},
ISOBJECT : "true",
"meta.meter_policy_id" : {TYPE : "sai_object_id_t", ISRESOURCETYPE : "true", OBJECTS : "METER_POLICY"},
NoAction : {DEFAULT_ONLY : True}
}
)
Expand All @@ -248,9 +248,9 @@ def set_policy_meter_class(meter_class: Annotated[int, 16]):
meter_bucket_inbound = byte_counter(MAX_METER_BUCKETS)
meter_bucket_outbound = byte_counter(MAX_METER_BUCKETS)

def meter_bucket_action(outbound_bytes_counter : Annotated[int, 64, {TYPE : "sai_uint64_t", ISREADONLY : True}],
inbound_bytes_counter : Annotated[int, 64, {TYPE : "sai_uint64_t", ISREADONLY : True}],
meter_bucket_index : Annotated[int, 32, {TYPE : "sai_uint32_t", SKIPATTR : True}]):
def meter_bucket_action(outbound_bytes_counter : Annotated[int, 64, {TYPE : "sai_uint64_t", ISREADONLY : "true"}],
inbound_bytes_counter : Annotated[int, 64, {TYPE : "sai_uint64_t", ISREADONLY : "true"}],
meter_bucket_index : Annotated[int, 32, {TYPE : "sai_uint32_t", SKIPATTR : "true"}]):
# read only counters for SAI api generation only
meta.meter_bucket_index = meter_bucket_index

Expand All @@ -267,7 +267,7 @@ def meter_bucket_action(outbound_bytes_counter : Annotated[int, 64, {TYPE : "sai

api_hints = {
API_NAME : "dash_meter",
ISOBJECT : True,
ISOBJECT : "true",
NoAction : {DEFAULT_ONLY : True}
}
)
Expand All @@ -292,7 +292,7 @@ def set_eni(eni_id: Annotated[int, 16]):
}
)

def set_acl_group_attrs(ip_addr_family: Annotated[int, 32, {TYPE : "sai_ip_addr_family_t", ISRESOURCETYPE : True}]):
def set_acl_group_attrs(ip_addr_family: Annotated[int, 32, {TYPE : "sai_ip_addr_family_t", ISRESOURCETYPE : "true"}]):
if ip_addr_family == 0:
if meta.is_overlay_ip_v6 == 1:
meta.dropped = True
Expand Down
13 changes: 13 additions & 0 deletions dash-pipeline/python_model/p4info_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ def make_action_node(action, id):
param_id += 1
param_node["name"] = k
param_node["bitwidth"] = annotations[k].__metadata__[0]
if len(annotations[k].__metadata__) > 1:
structured_annotations = annotations[k].__metadata__[1]
kvPairs_node = []
for s_a in structured_annotations:
s_a_node = {}
s_a_node["key"] = s_a
s_a_node["value"] = {"stringValue" : structured_annotations[s_a]}
kvPairs_node.append(s_a_node)
structuredAnnotations_node = [{
"name" : "Sai",
"kvPairList" : {"kvPairs" : kvPairs_node}
}]
param_node["structuredAnnotations"] = structuredAnnotations_node
params_node.append(param_node)
action_node["params"] = params_node
return action_node
Expand Down

0 comments on commit b057cee

Please sign in to comment.