Skip to content

Commit

Permalink
Add meta sibling tables to handle multi-stage tables
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyzhai committed Dec 20, 2024
1 parent 2252758 commit 8b334c3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
55 changes: 51 additions & 4 deletions dash-pipeline/SAI/src/dashsai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ sai_status_t DashSai::create(
}

if (insertInTable(matchActionEntry, objId)) {
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_INSERT, action_id);
*objectId = objId;
return SAI_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -1148,34 +1149,44 @@ sai_status_t DashSai::create(

auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_INSERT);
if (grpc::StatusCode::OK == ret) {
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_INSERT, action_id);
return SAI_STATUS_SUCCESS;
}

return SAI_STATUS_FAILURE;
}

sai_status_t DashSai::remove(
_In_ sai_object_id_t objectId)
_In_ const P4MetaTable &meta_table,
_In_ sai_object_id_t objectId)
{
DASH_LOG_ENTER();
DASH_CHECK_API_INITIALIZED();

std::shared_ptr<p4::v1::TableEntry> matchActionEntry = nullptr;
if (!getFromTable(objectId, matchActionEntry)) {
return SAI_STATUS_FAILURE;
}

if (removeFromTable(objectId)) {
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_DELETE);
return SAI_STATUS_SUCCESS;
}

return SAI_STATUS_FAILURE;
}

sai_status_t DashSai::remove(
_Inout_ std::shared_ptr<p4::v1::TableEntry> matchActionEntry)
_In_ const P4MetaTable &meta_table,
_Inout_ std::shared_ptr<p4::v1::TableEntry> matchActionEntry)
{
DASH_LOG_ENTER();
DASH_CHECK_API_INITIALIZED();

auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_DELETE);

if (grpc::StatusCode::OK == ret) {
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_DELETE);
return SAI_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -1209,6 +1220,9 @@ sai_status_t DashSai::set(
set_attr_value_to_p4(meta_param->field, meta_param->bitwidth, attr->value, pair_param.first);

auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_MODIFY);
if (ret == grpc::StatusCode::OK) {
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_MODIFY, action_id);
}
return ret == grpc::StatusCode::OK ? SAI_STATUS_SUCCESS : SAI_STATUS_FAILURE;
}

Expand All @@ -1233,8 +1247,12 @@ sai_status_t DashSai::set(
}

removeFromTable(objectId);
auto ret = insertInTable(new_entry, objectId);
return ret ? SAI_STATUS_SUCCESS : SAI_STATUS_FAILURE;
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_DELETE);

if (insertInTable(new_entry, objectId)) {
mutateSiblingTablesEntry(meta_table, new_entry, p4::v1::Update_Type_INSERT, action_id);
return SAI_STATUS_SUCCESS;
}
}

return SAI_STATUS_FAILURE;
Expand Down Expand Up @@ -1266,6 +1284,9 @@ sai_status_t DashSai::set(
set_attr_value_to_p4(meta_param->field, meta_param->bitwidth, attr->value, pair_param.first);

auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_MODIFY);
if (ret == grpc::StatusCode::OK) {
mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_MODIFY, action_id);
}
return ret == grpc::StatusCode::OK ? SAI_STATUS_SUCCESS : SAI_STATUS_FAILURE;
}

Expand Down Expand Up @@ -1359,3 +1380,29 @@ sai_status_t DashSai::get(
return SAI_STATUS_SUCCESS;
}

void DashSai::mutateSiblingTablesEntry(
_In_ const P4MetaTable &meta_table,
_In_ std::shared_ptr<p4::v1::TableEntry> matchActionEntry,
_In_ p4::v1::Update_Type updateType,
_In_ uint32_t action_id)
{
if (meta_table.sibling_tables.empty()) {
return;
}

std::shared_ptr<p4::v1::TableEntry> entry = std::make_shared<p4::v1::TableEntry>();
entry->CopyFrom(*matchActionEntry);
auto action = entry->mutable_action()->mutable_action();

for (auto &sibling: meta_table.sibling_tables) {
entry->set_table_id(sibling.id);

if (updateType != p4::v1::Update_Type_DELETE) {
auto enum_id = meta_table.find_action_enum_id(action_id);
auto sibling_action_id = sibling.actions.at(enum_id);
action->set_action_id(sibling_action_id);
}

mutateTableEntry(entry, updateType);
}
}
10 changes: 10 additions & 0 deletions dash-pipeline/SAI/src/dashsai.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ namespace dash
_In_ const sai_attribute_t *attr_list);

sai_status_t remove(
_In_ const P4MetaTable &meta_table,
_In_ sai_object_id_t objectId);

sai_status_t remove(
_In_ const P4MetaTable &meta_table,
_Inout_ std::shared_ptr<p4::v1::TableEntry> matchActionEntry);

sai_status_t set(
Expand Down Expand Up @@ -147,6 +149,14 @@ namespace dash
_In_ sai_object_id_t id,
_Out_ std::shared_ptr<p4::v1::TableEntry> &entry);

private: // private helper methods

void mutateSiblingTablesEntry(
_In_ const P4MetaTable &meta_table,
_In_ std::shared_ptr<p4::v1::TableEntry>,
_In_ p4::v1::Update_Type updateType,
_In_ uint32_t action_id = 0);

public: // default attributes helper

static std::vector<sai_attribute_t> populateDefaultAttributes(
Expand Down
13 changes: 11 additions & 2 deletions dash-pipeline/SAI/src/p4meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,27 @@ namespace dash
std::vector<P4MetaActionParam> params;
};

struct P4MetaSiblingTable {
uint32_t id;
// action enum id -> p4 action id
std::map<uint32_t, uint32_t> actions;
};

struct P4MetaTable {
uint32_t id;
std::vector<P4MetaKey> keys;
std::map<uint32_t, P4MetaAction> actions;
std::map<std::string, sai_attr_id_t> extra_fields;
std::vector<P4MetaSiblingTable> sibling_tables;

P4MetaTable(
uint32_t table_id,
std::initializer_list<P4MetaKey> init_keys,
std::initializer_list<std::map<uint32_t, P4MetaAction>::value_type> init_actions,
std::initializer_list<std::map<std::string, sai_attr_id_t>::value_type> extras
) : id(table_id), keys(init_keys), actions(init_actions), extra_fields(extras)
std::initializer_list<std::map<std::string, sai_attr_id_t>::value_type> extras,
std::initializer_list<P4MetaSiblingTable> sibling_list = {}
) : id(table_id), keys(init_keys), actions(init_actions),
extra_fields(extras), sibling_tables(sibling_list)

{}

Expand Down
4 changes: 2 additions & 2 deletions dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ static sai_status_t dash_sai_remove_{{ api.name }}(
{% include 'templates/headers/sai_api_param_object_id.j2' %})
{
{% if api.is_object %}
return dashSai->remove({{ api.name }}_id);
return dashSai->remove({{meta_table}}, {{ api.name }}_id);
{% else %}
std::shared_ptr<p4::v1::TableEntry> matchActionEntry = std::make_shared<p4::v1::TableEntry>();
matchActionEntry->set_table_id({{meta_table}}.id);

table_{{api.name}}_add_keys({{ api.name }}, matchActionEntry);
return dashSai->remove(matchActionEntry);
return dashSai->remove({{meta_table}}, matchActionEntry);
{% endif %}
}

Expand Down
14 changes: 14 additions & 0 deletions dash-pipeline/SAI/templates/impls/sai_api_group.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ static dash::P4MetaTable {{meta_table}} (
{% endfor %}
{% endif%}
}
{% if api.p4_meta.tables|length > 1 %}
,{ // sibling table list for multiple stages
{% for sibling_table in api.p4_meta.tables[1:] %}
{
{{sibling_table.id}}, // {{ sibling_table.stage }}
{ // map of action enum id -> action id
{% for name, action in sibling_table.actions.items() %}
{ {{name}}, {{action.id}} },
{% endfor %}
}
},
{% endfor %}
}
{% endif %}
);

{% include 'templates/impls/sai_api_func_quad.cpp.j2' %}
Expand Down

0 comments on commit 8b334c3

Please sign in to comment.