Skip to content

Commit

Permalink
Merge remote-tracking branch 'sonic-net/main' into dp_app_add_flow_in…
Browse files Browse the repository at this point in the history
…_pipeline
  • Loading branch information
jimmyzhai committed Oct 24, 2024
2 parents cb6d2bf + 1b3590a commit 421704e
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 85 deletions.
101 changes: 100 additions & 1 deletion dash-pipeline/SAI/specs/dash_tunnel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sai_apis:
attr_value_field: s32
default: SAI_DASH_ENCAPSULATION_VXLAN
isresourcetype: false
flags: CREATE_AND_SET
flags: CREATE_ONLY
object_name: null
allow_null: false
valid_only: null
Expand All @@ -43,6 +43,32 @@ sai_apis:
attr_value_field: u32
default: '0'
isresourcetype: false
flags: CREATE_ONLY
object_name: null
allow_null: false
valid_only: null
is_vlan: false
deprecated: false
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_DASH_TUNNEL_ATTR_MAX_MEMBER_SIZE
description: Action parameter max member size
type: sai_uint32_t
attr_value_field: u32
default: '1'
isresourcetype: false
flags: CREATE_ONLY
object_name: null
allow_null: false
valid_only: null
is_vlan: false
deprecated: false
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_DASH_TUNNEL_ATTR_SIP
description: Action parameter sip
type: sai_ip_address_t
attr_value_field: ipaddr
default: 0.0.0.0
isresourcetype: false
flags: CREATE_AND_SET
object_name: null
allow_null: false
Expand All @@ -59,3 +85,76 @@ sai_apis:
name: default
id: 27084508
attr_param_id: {}
- !!python/object:utils.sai_spec.sai_api.SaiApi
name: dash_tunnel_member
description: DASH tunnel member
is_object: true
enums: []
structs: []
attributes:
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_DASH_TUNNEL_MEMBER_ATTR_DASH_TUNNEL_ID
description: Action parameter DASH tunnel id
type: sai_object_id_t
attr_value_field: u16
default: null
isresourcetype: false
flags: MANDATORY_ON_CREATE | CREATE_ONLY
object_name: SAI_OBJECT_TYPE_DASH_TUNNEL
allow_null: false
valid_only: null
is_vlan: false
deprecated: false
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_DASH_TUNNEL_MEMBER_ATTR_DASH_TUNNEL_NEXT_HOP_ID
description: Action parameter DASH tunnel next hop id
type: sai_object_id_t
attr_value_field: u16
default: null
isresourcetype: false
flags: MANDATORY_ON_CREATE | CREATE_AND_SET
object_name: SAI_OBJECT_TYPE_DASH_TUNNEL_NEXT_HOP
allow_null: false
valid_only: null
is_vlan: false
deprecated: false
stats: []
p4_meta: !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4Meta
tables:
- !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4MetaTable
id: 40012474
actions:
default: !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4MetaAction
name: default
id: 23738116
attr_param_id: {}
- !!python/object:utils.sai_spec.sai_api.SaiApi
name: dash_tunnel_next_hop
description: DASH tunnel next hop
is_object: true
enums: []
structs: []
attributes:
- !!python/object:utils.sai_spec.sai_attribute.SaiAttribute
name: SAI_DASH_TUNNEL_NEXT_HOP_ATTR_DIP
description: Action parameter dip
type: sai_ip_address_t
attr_value_field: ipaddr
default: 0.0.0.0
isresourcetype: false
flags: CREATE_AND_SET
object_name: null
allow_null: false
valid_only: null
is_vlan: false
deprecated: false
stats: []
p4_meta: !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4Meta
tables:
- !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4MetaTable
id: 34229686
actions:
default: !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4MetaAction
name: default
id: 31749609
attr_param_id: {}
2 changes: 2 additions & 0 deletions dash-pipeline/SAI/specs/sai_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ object_types:
- SAI_OBJECT_TYPE_FLOW_ENTRY_BULK_GET_SESSION
- SAI_OBJECT_TYPE_METER_BUCKET_ENTRY
- SAI_OBJECT_TYPE_DASH_APPLIANCE
- SAI_OBJECT_TYPE_DASH_TUNNEL_MEMBER
- SAI_OBJECT_TYPE_DASH_TUNNEL_NEXT_HOP
object_entries:
- !!python/object:utils.sai_spec.sai_struct_entry.SaiStructEntry
name: direction_lookup_entry
Expand Down
57 changes: 57 additions & 0 deletions dash-pipeline/SAI/src/dashsai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,3 +904,60 @@ std::vector<sai_attribute_t> DashSai::populateDefaultAttributes(

return attrs;
}

sai_status_t DashSai::bulk_create_objects(
_In_ DashSai::sai_create_object_fn create_fn,
_In_ sai_object_id_t switch_id,
_In_ uint32_t object_count,
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_object_id_t *object_id,
_Out_ sai_status_t *object_statuses)
{
sai_status_t agg_status = SAI_STATUS_SUCCESS;

for (uint32_t i = 0; i < object_count; i++)
{
object_statuses[i] = create_fn(&object_id[i], switch_id, attr_count[i], attr_list[i]);

if (object_statuses[i] != SAI_STATUS_SUCCESS)
{
agg_status = SAI_STATUS_FAILURE;
}

if (agg_status == SAI_STATUS_FAILURE && mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR)
{
return agg_status;
}
}

return agg_status;
}

sai_status_t DashSai::bulk_remove_objects(
_In_ DashSai::sai_remove_object_fn remove_fn,
_In_ uint32_t object_count,
_In_ const sai_object_id_t *object_id,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses)
{
sai_status_t agg_status = SAI_STATUS_SUCCESS;

for (uint32_t i = 0; i < object_count; i++)
{
object_statuses[i] = remove_fn(object_id[i]);

if (object_statuses[i] != SAI_STATUS_SUCCESS)
{
agg_status = SAI_STATUS_FAILURE;
}

if (agg_status == SAI_STATUS_FAILURE && mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR)
{
return agg_status;
}
}

return agg_status;
}
26 changes: 26 additions & 0 deletions dash-pipeline/SAI/src/dashsai.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ namespace dash
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

typedef sai_status_t (*sai_create_object_fn)(
_Out_ sai_object_id_t *object_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

typedef sai_status_t (*sai_remove_object_fn)(
_In_ sai_object_id_t object_id);

static sai_status_t bulk_create_objects(
_In_ sai_create_object_fn create_fn,
_In_ sai_object_id_t switch_id,
_In_ uint32_t object_count,
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_object_id_t *object_id,
_Out_ sai_status_t *object_statuses);

static sai_status_t bulk_remove_objects(
_In_ sai_remove_object_fn remove_fn,
_In_ uint32_t object_count,
_In_ const sai_object_id_t *object_id,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

private: // private helper methods

static std::shared_ptr<p4::config::v1::P4Info> parse_p4info(
Expand Down
62 changes: 14 additions & 48 deletions dash-pipeline/SAI/templates/saiapi.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ static sai_status_t dash_sai_create_{{ table.name }}(

matchActionEntry->set_table_id(tableId);

{% if table['keys'] | length== 1 %}
// SAI object table with single P4 key - object ID itself is the P4 table key
// Generate a SAI object ID and fill it as the P4 table key
auto mf = matchActionEntry->add_match();
mf->set_field_id({{table['keys'][0].id}});
auto mf_exact = mf->mutable_exact();
//{{table['keys'][0].field}}SetVal(objId, mf_exact, {{table['keys'][0].bitwidth}});
{{table['keys'][0].field}}SetVal(static_cast<uint{{ table['keys'][0].bitwidth }}_t>(objId), mf_exact, {{ table['keys'][0].bitwidth }});
{% else %}
{% for key in table['keys'] %}
{% if key.is_object_key %}
auto key_mf = matchActionEntry->add_match();
key_mf->set_field_id({{key.id}});
auto key_mf_exact = key_mf->mutable_exact();
// {{key.field}}SetVal(objId, key_mf_exact, {{key.bitwidth}});
{{key.field}}SetVal(static_cast<uint{{ key.bitwidth }}_t>(objId), key_mf_exact, {{ key.bitwidth }});
{% endif %}
{% endfor %}

// SAI object table with multiple P4 table keys
// Copy P4 table keys from appropriate SAI attributes
for (uint32_t i = 0; i < attr_count; i++)
Expand All @@ -79,6 +80,7 @@ static sai_status_t dash_sai_create_{{ table.name }}(
switch(attr_list[i].id)
{
{% for key in table['keys'] %}
{% if not key.is_object_key %}
case SAI_{{ table.name | upper }}_ATTR_{{ key.name | upper }}:
{
auto mf = matchActionEntry->add_match();
Expand Down Expand Up @@ -138,6 +140,7 @@ static sai_status_t dash_sai_create_{{ table.name }}(
{% endif %}
break;
}
{% endif%}
{% endfor %}
{% if table['keys'] | selectattr('match_type', 'ne', 'exact') | list | length > 0 %}
{% if table['keys'] | selectattr('match_type', 'eq', 'lpm') | list | length == 0 %}
Expand All @@ -154,7 +157,6 @@ static sai_status_t dash_sai_create_{{ table.name }}(
break;
}
}
{% endif %}

// If there is only one action, simply set it.
// Else, search in the attrs.
Expand Down Expand Up @@ -255,25 +257,7 @@ static sai_status_t dash_sai_create_{{ table.name }}s(
_Out_ sai_status_t *object_statuses)
{
DASH_LOG_ENTER();

sai_status_t agg_status = SAI_STATUS_SUCCESS;

for (uint32_t i = 0; i < object_count; i++)
{
object_statuses[i] = dash_sai_create_{{ table.name }}(&object_id[i], switch_id, attr_count[i], attr_list[i]);

if (object_statuses[i] != SAI_STATUS_SUCCESS)
{
agg_status = SAI_STATUS_FAILURE;
}

if (agg_status == SAI_STATUS_FAILURE && mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR)
{
return agg_status;
}
}

return agg_status;
return dash::DashSai::bulk_create_objects(dash_sai_create_{{ table.name }}, switch_id, object_count, attr_count, attr_list, mode, object_id, object_statuses);
}

static sai_status_t dash_sai_remove_{{ table.name }}(
Expand All @@ -296,25 +280,7 @@ static sai_status_t dash_sai_remove_{{ table.name }}s(
_Out_ sai_status_t *object_statuses)
{
DASH_LOG_ENTER();

sai_status_t agg_status = SAI_STATUS_SUCCESS;

for (uint32_t i = 0; i < object_count; i++)
{
object_statuses[i] = dash_sai_remove_{{ table.name }}(object_id[i]);

if (object_statuses[i] != SAI_STATUS_SUCCESS)
{
agg_status = SAI_STATUS_FAILURE;
}

if (agg_status == SAI_STATUS_FAILURE && mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR)
{
return agg_status;
}
}

return agg_status;
return dash::DashSai::bulk_remove_objects(dash_sai_remove_{{ table.name }}, object_count, object_id, mode, object_statuses);
}

static sai_status_t dash_sai_set_{{ table.name }}_attribute (
Expand Down
2 changes: 2 additions & 0 deletions dash-pipeline/SAI/templates/saiapi.h.j2
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ typedef enum _sai_{{ table.name }}_attr_t
* @type {{ sai_attr.type }}
{% if sai_attr.isreadonly == 'true' %}
* @flags READ_ONLY
{% else if sai_attr.is_create_only == 'true' %}
* @flags CREATE_ONLY
{% else %}
* @flags CREATE_AND_SET
{% endif %}
Expand Down
12 changes: 8 additions & 4 deletions dash-pipeline/SAI/utils/dash_p4/dash_p4_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __table_with_counters(self, program: Dict[str, Any]) -> None:
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)

if self.is_object != "false":
table_key.is_entry_key = False

Expand Down Expand Up @@ -372,9 +372,13 @@ def create_sai_stats(self, sai_api: SaiApi) -> None:

def create_sai_attributes(self, sai_api: SaiApi) -> None:
# If the table is an object with more one key (table entry id), we need to add all the keys into the attributes.
if self.is_object == "true" and len(self.keys) > 1:
for key in self.keys:
sai_api.attributes.extend(key.to_sai_attribute(self.name, create_only=True))
if self.is_object == "true":
if len(self.keys) == 1:
self.keys[0].is_object_key = True
elif len(self.keys) > 1:
for key in self.keys:
if not key.is_object_key:
sai_api.attributes.extend(key.to_sai_attribute(self.name))

# Add all the action parameters into the attributes.
for attr in self.sai_attributes:
Expand Down
Loading

0 comments on commit 421704e

Please sign in to comment.