Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libsai] Make helper function for bulk object create and removal to simplify libsai generation. #632

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
40 changes: 2 additions & 38 deletions dash-pipeline/SAI/templates/saiapi.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,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 +278,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
Loading