From f3cbd1c45d3042f528f73c269884db78ede40a2b Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Thu, 19 Dec 2024 10:28:51 +0000 Subject: [PATCH 1/7] Refactor APIs create/remove --- dash-pipeline/SAI/src/dashsai.cpp | 139 +++++++++++++++++- dash-pipeline/SAI/src/dashsai.h | 21 +++ dash-pipeline/SAI/src/p4meta.h | 6 + .../templates/impls/p4_table_action.cpp.j2 | 73 --------- .../impls/p4_table_object_match.cpp.j2 | 66 --------- .../templates/impls/sai_api_func_quad.cpp.j2 | 123 ++-------------- 6 files changed, 174 insertions(+), 254 deletions(-) delete mode 100644 dash-pipeline/SAI/templates/impls/p4_table_action.cpp.j2 delete mode 100644 dash-pipeline/SAI/templates/impls/p4_table_object_match.cpp.j2 diff --git a/dash-pipeline/SAI/src/dashsai.cpp b/dash-pipeline/SAI/src/dashsai.cpp index e61a1914d..374d55099 100644 --- a/dash-pipeline/SAI/src/dashsai.cpp +++ b/dash-pipeline/SAI/src/dashsai.cpp @@ -640,10 +640,12 @@ grpc::StatusCode DashSai::readTableEntry( entity = rep.mutable_entities(0); entry->CopyFrom(entity->table_entry()); } + else { + entity->release_table_entry(); + } auto status = client_reader->Finish(); -exit: if (status.ok()) { DASH_LOG_NOTICE("GRPC call Read OK %s", entry->ShortDebugString().c_str()); } @@ -1043,6 +1045,141 @@ sai_status_t DashSai::bulk_remove_objects( return agg_status; } +sai_status_t DashSai::create( + _In_ const P4MetaTable &meta_table, + _In_ sai_object_type_t objectType, + _Out_ sai_object_id_t* objectId, + _In_ sai_object_id_t switchId, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list) +{ + DASH_LOG_ENTER(); + DASH_CHECK_API_INITIALIZED(); + + auto attrs = DashSai::populateDefaultAttributes(objectType, attr_count, attr_list); + attr_count = (uint32_t)attrs.size(); + attr_list = attrs.data(); + + std::shared_ptr matchActionEntry; + matchActionEntry = std::make_shared(); + matchActionEntry->set_table_id(meta_table.id); + + sai_object_id_t objId = getNextObjectId(objectType); + if (objId == SAI_NULL_OBJECT_ID) + { + DASH_LOG_ERROR("getNextObjectId failed for OBJECT_TYPE %u", objectType); + return SAI_STATUS_FAILURE; + } + + if (auto meta_object_key = meta_table.get_meta_object_key()) { + auto key_mf = matchActionEntry->add_match(); + auto key_mf_exact = key_mf->mutable_exact(); + + key_mf->set_field_id(meta_object_key->id); + u16SetVal((uint16_t)objId, key_mf_exact, 16); + } + + pi_p4_id_t action_id = meta_table.find_action_id(attr_count, attr_list); + if (!action_id) { + DASH_LOG_ERROR("Not find p4 table action"); + return SAI_STATUS_FAILURE; + } + + auto action = matchActionEntry->mutable_action()->mutable_action(); + action->set_action_id(action_id); + + for (uint32_t i = 0; i < attr_count; i++) { + if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { + // attr in table action params + set_attr_to_p4_action(meta_param, &attr_list[i], action); + } + else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) { + // attr in table keys + set_attr_to_p4_match(meta_key, &attr_list[i], matchActionEntry); + } + else { + // FIXME: check extra fields + } + } + + if (insertInTable(matchActionEntry, objId)) { + *objectId = objId; + return SAI_STATUS_SUCCESS; + } + + return SAI_STATUS_FAILURE; +} + +sai_status_t DashSai::create( + _In_ const P4MetaTable &meta_table, + _In_ sai_object_type_t objectType, + _Inout_ std::shared_ptr matchActionEntry, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list) +{ + DASH_LOG_ENTER(); + DASH_CHECK_API_INITIALIZED(); + + auto attrs = DashSai::populateDefaultAttributes(objectType, attr_count, attr_list); + attr_count = (uint32_t)attrs.size(); + attr_list = attrs.data(); + + matchActionEntry->set_table_id(meta_table.id); + + pi_p4_id_t action_id = meta_table.find_action_id(attr_count, attr_list); + if (!action_id) { + DASH_LOG_ERROR("Not find p4 table action"); + return SAI_STATUS_FAILURE; + } + auto action = matchActionEntry->mutable_action()->mutable_action(); + action->set_action_id(action_id); + + for (uint32_t i = 0; i < attr_count; i++) { + if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { + // attr in table action params + set_attr_to_p4_action(meta_param, &attr_list[i], action); + } + else { + // FIXME: check extra fields + } + } + + auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_INSERT); + if (grpc::StatusCode::OK == ret) { + return SAI_STATUS_SUCCESS; + } + + return SAI_STATUS_FAILURE; +} + +sai_status_t DashSai::remove( + _In_ sai_object_id_t objectId) +{ + DASH_LOG_ENTER(); + DASH_CHECK_API_INITIALIZED(); + + if (removeFromTable(objectId)) { + return SAI_STATUS_SUCCESS; + } + + return SAI_STATUS_FAILURE; +} + +sai_status_t DashSai::remove( + _Inout_ std::shared_ptr matchActionEntry) +{ + DASH_LOG_ENTER(); + DASH_CHECK_API_INITIALIZED(); + + auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_DELETE); + + if (grpc::StatusCode::OK == ret) { + return SAI_STATUS_SUCCESS; + } + + return SAI_STATUS_FAILURE; +} + sai_status_t DashSai::set( _In_ const P4MetaTable &meta_table, _In_ sai_object_id_t objectId, diff --git a/dash-pipeline/SAI/src/dashsai.h b/dash-pipeline/SAI/src/dashsai.h index 1d1517872..6b4a22743 100644 --- a/dash-pipeline/SAI/src/dashsai.h +++ b/dash-pipeline/SAI/src/dashsai.h @@ -53,6 +53,27 @@ namespace dash _Inout_ sai_attribute_t *attr_list); // QUAD api implementation, using p4 meta table + sai_status_t create( + _In_ const P4MetaTable &meta_table, + _In_ sai_object_type_t objectType, + _Out_ sai_object_id_t* objectId, + _In_ sai_object_id_t switchId, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list); + + sai_status_t create( + _In_ const P4MetaTable &meta_table, + _In_ sai_object_type_t objectType, + _Inout_ std::shared_ptr matchActionEntry, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list); + + sai_status_t remove( + _In_ sai_object_id_t objectId); + + sai_status_t remove( + _Inout_ std::shared_ptr matchActionEntry); + sai_status_t set( _In_ const P4MetaTable &meta_table, _In_ sai_object_id_t objectId, diff --git a/dash-pipeline/SAI/src/p4meta.h b/dash-pipeline/SAI/src/p4meta.h index 219aab202..0617aaf44 100644 --- a/dash-pipeline/SAI/src/p4meta.h +++ b/dash-pipeline/SAI/src/p4meta.h @@ -81,6 +81,8 @@ namespace dash return u8SetVal(value, p4_key_or_param, bitwidth); if (field == "u16") return u16SetVal(value, p4_key_or_param, bitwidth); + if (field == "s32") + return s32SetVal(value, p4_key_or_param, bitwidth); if (field == "u32") return u32SetVal(value, p4_key_or_param, bitwidth); if (field == "u64") @@ -121,6 +123,10 @@ namespace dash uint16_t val = *(const uint16_t*)v; value.u16 = ntohs(val); } + else if (field == "s32") { + int32_t val = *(const int32_t*)v; + value.s32 = ntohl(val) >> (32 - bitwidth); + } else if (field == "u32") { uint32_t val = *(const uint32_t*)v; value.u32 = ntohl(val) >> (32 - bitwidth); diff --git a/dash-pipeline/SAI/templates/impls/p4_table_action.cpp.j2 b/dash-pipeline/SAI/templates/impls/p4_table_action.cpp.j2 deleted file mode 100644 index d0cbfec47..000000000 --- a/dash-pipeline/SAI/templates/impls/p4_table_action.cpp.j2 +++ /dev/null @@ -1,73 +0,0 @@ - {% if table.actions|length == 1 %} - {% for name, action in table.actions.items() %} - actionId = {{action.id}}; // {{name}} - //expectedParams = {{ action.attr_params|length }}; - {% endfor %} - {% else %} - // Search the action - for (uint32_t i = 0; i < attr_count; i++) - { - if (SAI_{{ api.name | upper }}_ATTR_ACTION == attr_list[i].id) - { - switch(attr_list[i].value.s32) - { - {% for name, action in table.actions.items() %} - case {{ name }}: - { - actionId = {{action.id}}; - //expectedParams = {{ action.attr_params|length }}; - break; - } - {% endfor %} - default: - DASH_LOG_ERROR("attribute value [%d] %d not supported yet", i, attr_list[i].value.s32); - break; - } - // only one action - break; - } - } - {% endif %} - action->set_action_id(actionId); - - for (uint32_t i = 0; i < attr_count; i++) - { - auto *md = sai_metadata_get_attr_metadata((sai_object_type_t)SAI_OBJECT_TYPE_{{ api.name | upper }}, attr_list[i].id); - - const char* attrName = md ? md->attridname : "unknown"; - - switch(attr_list[i].id) - { - {% set attr_id_list = [] %} - {% for name, action in table.actions.items() %} - {% for param_name, param in action.attr_params.items() %} - {% if param_name in attr_id_list %}{% continue %}{% endif %} - {% do attr_id_list.append( param_name ) %} - {% if param.skipattr == 'true' %} - {% else %} - case {{ param_name }}: - { - auto param = action->add_params(); - param->set_param_id({{param.id}}); - {{param.field}}SetVal(attr_list[i].value, param, {{param.bitwidth}}); - //matchedParams++; - {% if param.ip_is_v6_field_id != 0 %} - { - // set ip_is_v6_field_id field - auto param2 = action->add_params(); - param2->set_param_id({{param.ip_is_v6_field_id}}); - booldataSetVal((attr_list[i].value.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, param2, 1); - //matchedParams++; - } - {% endif %} - break; - } - {% endif %} - {% endfor %} - {% endfor %} - default: - DASH_LOG_ERROR("attribute [%d] %d %s not supported yet", i, attr_list[i].id, attrName); - break; - } - } - diff --git a/dash-pipeline/SAI/templates/impls/p4_table_object_match.cpp.j2 b/dash-pipeline/SAI/templates/impls/p4_table_object_match.cpp.j2 deleted file mode 100644 index d6419e5f3..000000000 --- a/dash-pipeline/SAI/templates/impls/p4_table_object_match.cpp.j2 +++ /dev/null @@ -1,66 +0,0 @@ - {% import 'templates/impls/p4_table_util.cpp.j2' as util %} - {% 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(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++) - { - auto *md = sai_metadata_get_attr_metadata((sai_object_type_t)SAI_OBJECT_TYPE_{{ api.name | upper }}, attr_list[i].id); - - const char* attrName = md ? md->attridname : "unknown"; - - switch(attr_list[i].id) - { - {% for key in table['keys'] %} - {% if not key.is_object_key %} - {% set value = 'attr_list[i].value' %} - case SAI_{{ api.name | upper }}_ATTR_{{ key.name | upper }}: - { - auto mf = matchActionEntry->add_match(); - mf->set_field_id({{key.id}}); - {% filter indent(8, True) %} - {% if key.match_type == 'exact' %}{{ util.set_key_in_attr_exact(key, value) }} - {% elif key.match_type == 'lpm' %}{{ util.set_key_lpm(key, value) }} - {% elif key.match_type == 'ternary' %}{{ util.set_key_in_attr_ternary(api, key, value) }} - {% elif key.match_type == 'optional' %}{{ util.set_key_optional(key, value) }} - {% elif key.match_type == 'list' %}{{ util.set_key_list(key, value) }} - {% elif key.match_type == 'range_list' %}{{ util.set_key_range_list(key, value) }} - {% endif %} - {% endfilter %} - {% if key.ip_is_v6_field_id != 0 %} - { - // set ip_is_v6_field_id field - auto mf = matchActionEntry->add_match(); - mf->set_field_id({{key.ip_is_v6_field_id}}); - auto mf_exact = mf->mutable_exact(); - booldataSetVal(({{value}}.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, mf_exact, 1); - } - {% 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 %} - // Table has non lpm ternary keys - add priority field - case SAI_{{ api.name | upper }}_ATTR_PRIORITY: - { - matchActionEntry->set_priority(attr_list[i].value.u32); - break; - } - {% endif %} - {% endif %} - default: - DASH_LOG_ERROR("attribute [%d] %d %s not supported yet", i, attr_list[i].id, attrName); - break; - } - } - diff --git a/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 b/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 index 6903f5b68..26469f0d6 100644 --- a/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 +++ b/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 @@ -20,99 +20,16 @@ static sai_status_t dash_sai_create_{{ api.name }}( _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list) { - DASH_LOG_ENTER(); - - auto attrs = dash::DashSai::populateDefaultAttributes((sai_object_type_t)SAI_OBJECT_TYPE_{{ api.name | upper }}, attr_count, attr_list); - attr_count = (uint32_t)attrs.size(); - attr_list = attrs.data(); + auto obj_type = (sai_object_type_t)SAI_OBJECT_TYPE_{{ api.name | upper }}; {% if api.is_object %} - std::shared_ptr matchActionEntry; - pi_p4_id_t tableId = 0; - // There shall be one and only one action_type - p4::v1::TableAction* entry = nullptr; - p4::v1::Action* action = nullptr; - //auto expectedParams = 0; - //auto matchedParams = 0; - sai_object_id_t objId = 0; - // Search the action - pi_p4_id_t actionId = 0; - - {% for table in api.p4_meta.tables %} - {% if table.stage != None %} - // For stage {{ table.stage }} - {% endif %} - matchActionEntry = std::make_shared(); - tableId = {{table.id}}; - entry = matchActionEntry->mutable_action(); - action = entry->mutable_action(); - //expectedParams = 0; - //matchedParams = 0; - objId = dashSai->getNextObjectId((sai_object_type_t)SAI_OBJECT_TYPE_{{ api.name | upper }}); - - if (objId == SAI_NULL_OBJECT_ID) - { - DASH_LOG_ERROR("getNextObjectId failed for SAI_OBJECT_TYPE_{{ api.name | upper }}"); - // TODO clean resources - return SAI_STATUS_FAILURE; - } - - matchActionEntry->set_table_id(tableId); - - {% include 'templates/impls/p4_table_object_match.cpp.j2' %} - - // If there is only one action, simply set it. - // Else, search in the attrs. - {% include 'templates/impls/p4_table_action.cpp.j2' %} - - //assert((matchedParams == expectedParams)); - - //if (matchedParams != expectedParams) { - // goto ErrRet; - //} - if (false == dashSai->insertInTable(matchActionEntry, objId)) { - goto ErrRet; - } - - {% endfor %} - - *{{ api.name }}_id = objId; - return SAI_STATUS_SUCCESS; -ErrRet: - dashSai->removeFromTable(*{{ api.name }}_id); - return SAI_STATUS_FAILURE; + return dashSai->create({{meta_table}}, obj_type, {{ api.name }}_id, switch_id, attr_count, attr_list); {% else %} std::shared_ptr matchActionEntry = std::make_shared(); - pi_p4_id_t tableId = {{table.id}}; - matchActionEntry->set_table_id(tableId); - auto tableEntry = {{ api.name }}; - // There shall be one and only one action_type - auto entry = matchActionEntry->mutable_action(); - auto action = entry->mutable_action(); - //auto expectedParams = 0; - //auto matchedParams = 0; - pi_p4_id_t actionId; - grpc::StatusCode retCode; - - {% include 'templates/impls/p4_table_entry_match.cpp.j2' %} - - - {% include 'templates/impls/p4_table_action.cpp.j2' %} - - //assert((matchedParams == expectedParams)); - - //if (matchedParams != expectedParams) { - // goto ErrRet; - //} - // TODO: ternaly needs to set priority - retCode = dashSai->mutateTableEntry(matchActionEntry, p4::v1::Update_Type_INSERT); + matchActionEntry->set_table_id({{meta_table}}.id); - if (grpc::StatusCode::OK == retCode) - { - return SAI_STATUS_SUCCESS; - } -ErrRet: - return SAI_STATUS_FAILURE; + table_{{api.name}}_add_keys({{ api.name }}, matchActionEntry); + return dashSai->create({{meta_table}}, obj_type, matchActionEntry, attr_count, attr_list); {% endif %} } @@ -120,35 +37,13 @@ static sai_status_t dash_sai_remove_{{ api.name }}( {% include 'templates/headers/sai_api_param_object_id.j2' %}) { {% if api.is_object %} - DASH_LOG_ENTER(); - - if (dashSai->removeFromTable({{ api.name }}_id)) - { - return SAI_STATUS_SUCCESS; - } - - return SAI_STATUS_FAILURE; + return dashSai->remove({{ api.name }}_id); {% else %} - DASH_LOG_ENTER(); - std::shared_ptr matchActionEntry = std::make_shared(); - pi_p4_id_t tableId = {{table.id}}; - matchActionEntry->set_table_id(tableId); - auto tableEntry = {{ api.name }}; - grpc::StatusCode retCode; - - {% include 'templates/impls/p4_table_entry_match.cpp.j2' %} - - retCode = dashSai->mutateTableEntry(matchActionEntry, p4::v1::Update_Type_DELETE); - - if (grpc::StatusCode::OK == retCode) - { - return SAI_STATUS_SUCCESS; - } - -ErrRet: + matchActionEntry->set_table_id({{meta_table}}.id); - return SAI_STATUS_FAILURE; + table_{{api.name}}_add_keys({{ api.name }}, matchActionEntry); + return dashSai->remove(matchActionEntry); {% endif %} } From 35328694f406b030842ecb999bacc49424f1f49c Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Thu, 19 Dec 2024 16:04:07 +0000 Subject: [PATCH 2/7] Set attr PRIORITY to p4 table, if existing --- dash-pipeline/SAI/src/dashsai.cpp | 10 ++++--- dash-pipeline/SAI/src/p4meta.cpp | 46 +++++++++++++++++++++++++++++++ dash-pipeline/SAI/src/p4meta.h | 27 +++++++++++++----- 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/dash-pipeline/SAI/src/dashsai.cpp b/dash-pipeline/SAI/src/dashsai.cpp index 374d55099..7829a859a 100644 --- a/dash-pipeline/SAI/src/dashsai.cpp +++ b/dash-pipeline/SAI/src/dashsai.cpp @@ -1098,7 +1098,8 @@ sai_status_t DashSai::create( set_attr_to_p4_match(meta_key, &attr_list[i], matchActionEntry); } else { - // FIXME: check extra fields + // attr in extra fields + set_attr_to_p4_misc(meta_table, &attr_list[i], matchActionEntry); } } @@ -1140,7 +1141,8 @@ sai_status_t DashSai::create( set_attr_to_p4_action(meta_param, &attr_list[i], action); } else { - // FIXME: check extra fields + // attr in extra fields + set_attr_to_p4_misc(meta_table, &attr_list[i], matchActionEntry); } } @@ -1315,7 +1317,7 @@ sai_status_t DashSai::get( } } else { - DASH_LOG_ERROR("failed to get value for attr %d", attr_list[i].id); + get_attr_from_p4_misc(meta_table, matchActionEntry, &attr_list[i]); } } @@ -1350,7 +1352,7 @@ sai_status_t DashSai::get( get_attr_value_from_p4(meta_param->field, meta_param->bitwidth, pair_param.first, attr_list[i].value); } else { - DASH_LOG_ERROR("failed to get value for attr %d", attr_list[i].id); + get_attr_from_p4_misc(meta_table, matchActionEntry, &attr_list[i]); } } diff --git a/dash-pipeline/SAI/src/p4meta.cpp b/dash-pipeline/SAI/src/p4meta.cpp index 7c9b068e3..2cf8478d6 100644 --- a/dash-pipeline/SAI/src/p4meta.cpp +++ b/dash-pipeline/SAI/src/p4meta.cpp @@ -88,6 +88,17 @@ namespace dash return 0; // invalid p4 action id } + uint32_t P4MetaTable::find_action_enum_id( + _In_ uint32_t action_id) const + { + auto itr = actions.find(action_id); + if (itr != actions.end()) { + return itr->second.enum_id; + } + + return ~0u; + } + // // helper functions, set/get attr to/from p4 match|action // @@ -311,6 +322,41 @@ namespace dash set_attr_value_to_p4(meta_param->field, meta_param->bitwidth, attr->value, param); } + void set_attr_to_p4_misc( + _In_ const P4MetaTable &meta_table, + _In_ const sai_attribute_t *attr, + _Inout_ std::shared_ptr matchActionEntry) + { + for (auto &extra_attr: meta_table.extra_fields) { + if (extra_attr.second == attr->id) { + if (extra_attr.first == "PRIORITY") { + matchActionEntry->set_priority(attr->value.u32); + break; + } + } + } + } + + void get_attr_from_p4_misc( + _In_ const P4MetaTable &meta_table, + _In_ const std::shared_ptr matchActionEntry, + _Inout_ sai_attribute_t *attr) + { + for (auto &extra_attr: meta_table.extra_fields) { + if (extra_attr.second == attr->id) { + if (extra_attr.first == "ACTION") { + auto action = matchActionEntry->mutable_action()->mutable_action(); + auto action_id = action->action_id(); + attr->value.u32 = meta_table.find_action_enum_id(action_id); + } + else if (extra_attr.first == "PRIORITY") { + attr->value.u32 = matchActionEntry->priority(); + break; + } + } + } + } + std::pair get_match_pair_from_p4_table_entry( _In_ const P4MetaKey *meta_key, _In_ std::shared_ptr matchActionEntry) diff --git a/dash-pipeline/SAI/src/p4meta.h b/dash-pipeline/SAI/src/p4meta.h index 0617aaf44..9fba28bef 100644 --- a/dash-pipeline/SAI/src/p4meta.h +++ b/dash-pipeline/SAI/src/p4meta.h @@ -55,15 +55,18 @@ namespace dash const P4MetaKey* get_meta_key( _In_ const std::string &key_name) const; - const P4MetaKey* get_meta_object_key() const; + const P4MetaKey* get_meta_object_key() const; - const P4MetaActionParam* get_meta_action_param( - _In_ uint32_t action_id, - _In_ sai_attr_id_t attr_id) const; + const P4MetaActionParam* get_meta_action_param( + _In_ uint32_t action_id, + _In_ sai_attr_id_t attr_id) const; + + pi_p4_id_t find_action_id( + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list) const; - pi_p4_id_t find_action_id( - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) const; + uint32_t find_action_enum_id( + _In_ uint32_t action_id) const; }; @@ -222,6 +225,16 @@ namespace dash _In_ const sai_attribute_t *attr, _Out_ p4::v1::Action *action); + void set_attr_to_p4_misc( + _In_ const P4MetaTable &meta_table, + _In_ const sai_attribute_t *attr, + _Inout_ std::shared_ptr matchActionEntry); + + void get_attr_from_p4_misc( + _In_ const P4MetaTable &meta_table, + _In_ const std::shared_ptr matchActionEntry, + _Inout_ sai_attribute_t *attr); + std::pair get_match_pair_from_p4_table_entry( _In_ const P4MetaKey *meta_key, _In_ std::shared_ptr matchActionEntry); From d28f67d42d124318566331d04886499b1c3f7bba Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Fri, 20 Dec 2024 13:48:20 +0000 Subject: [PATCH 3/7] Add meta sibling tables to handle multi-stage tables --- dash-pipeline/SAI/src/dashsai.cpp | 55 +++++++++++++++++-- dash-pipeline/SAI/src/dashsai.h | 10 ++++ dash-pipeline/SAI/src/p4meta.h | 13 ++++- .../templates/impls/sai_api_func_quad.cpp.j2 | 4 +- .../SAI/templates/impls/sai_api_group.cpp.j2 | 14 +++++ 5 files changed, 88 insertions(+), 8 deletions(-) diff --git a/dash-pipeline/SAI/src/dashsai.cpp b/dash-pipeline/SAI/src/dashsai.cpp index 7829a859a..12195f0d6 100644 --- a/dash-pipeline/SAI/src/dashsai.cpp +++ b/dash-pipeline/SAI/src/dashsai.cpp @@ -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; } @@ -1148,6 +1149,7 @@ 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; } @@ -1155,12 +1157,19 @@ sai_status_t DashSai::create( } 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 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; } @@ -1168,7 +1177,8 @@ sai_status_t DashSai::remove( } sai_status_t DashSai::remove( - _Inout_ std::shared_ptr matchActionEntry) + _In_ const P4MetaTable &meta_table, + _Inout_ std::shared_ptr matchActionEntry) { DASH_LOG_ENTER(); DASH_CHECK_API_INITIALIZED(); @@ -1176,6 +1186,7 @@ sai_status_t DashSai::remove( 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; } @@ -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; } @@ -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; @@ -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; } @@ -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 matchActionEntry, + _In_ p4::v1::Update_Type updateType, + _In_ uint32_t action_id) +{ + if (meta_table.sibling_tables.empty()) { + return; + } + + std::shared_ptr entry = std::make_shared(); + 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); + } +} diff --git a/dash-pipeline/SAI/src/dashsai.h b/dash-pipeline/SAI/src/dashsai.h index 6b4a22743..ccda64c12 100644 --- a/dash-pipeline/SAI/src/dashsai.h +++ b/dash-pipeline/SAI/src/dashsai.h @@ -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 matchActionEntry); sai_status_t set( @@ -147,6 +149,14 @@ namespace dash _In_ sai_object_id_t id, _Out_ std::shared_ptr &entry); + private: // private helper methods + + void mutateSiblingTablesEntry( + _In_ const P4MetaTable &meta_table, + _In_ std::shared_ptr, + _In_ p4::v1::Update_Type updateType, + _In_ uint32_t action_id = 0); + public: // default attributes helper static std::vector populateDefaultAttributes( diff --git a/dash-pipeline/SAI/src/p4meta.h b/dash-pipeline/SAI/src/p4meta.h index 9fba28bef..6c815fdd1 100644 --- a/dash-pipeline/SAI/src/p4meta.h +++ b/dash-pipeline/SAI/src/p4meta.h @@ -34,18 +34,27 @@ namespace dash std::vector params; }; + struct P4MetaSiblingTable { + uint32_t id; + // action enum id -> p4 action id + std::map actions; + }; + struct P4MetaTable { uint32_t id; std::vector keys; std::map actions; std::map extra_fields; + std::vector sibling_tables; P4MetaTable( uint32_t table_id, std::initializer_list init_keys, std::initializer_list::value_type> init_actions, - std::initializer_list::value_type> extras - ) : id(table_id), keys(init_keys), actions(init_actions), extra_fields(extras) + std::initializer_list::value_type> extras, + std::initializer_list sibling_list = {} + ) : id(table_id), keys(init_keys), actions(init_actions), + extra_fields(extras), sibling_tables(sibling_list) {} diff --git a/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 b/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 index 26469f0d6..41be79ab2 100644 --- a/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 +++ b/dash-pipeline/SAI/templates/impls/sai_api_func_quad.cpp.j2 @@ -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 matchActionEntry = std::make_shared(); 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 %} } diff --git a/dash-pipeline/SAI/templates/impls/sai_api_group.cpp.j2 b/dash-pipeline/SAI/templates/impls/sai_api_group.cpp.j2 index 8308ecc49..1e2b7095f 100644 --- a/dash-pipeline/SAI/templates/impls/sai_api_group.cpp.j2 +++ b/dash-pipeline/SAI/templates/impls/sai_api_group.cpp.j2 @@ -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' %} From 862866baee977f3e516a82643e9c75c0ea3a6ac7 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 24 Dec 2024 14:51:08 +0000 Subject: [PATCH 4/7] Fix the minor comments of @r12f in PR 651 --- dash-pipeline/SAI/src/dashsai.cpp | 12 ++++++------ dash-pipeline/SAI/src/p4meta.cpp | 8 ++++---- dash-pipeline/SAI/src/p4meta.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dash-pipeline/SAI/src/dashsai.cpp b/dash-pipeline/SAI/src/dashsai.cpp index 12195f0d6..2960377f9 100644 --- a/dash-pipeline/SAI/src/dashsai.cpp +++ b/dash-pipeline/SAI/src/dashsai.cpp @@ -1211,7 +1211,7 @@ sai_status_t DashSai::set( pi_p4_id_t action_id = action->action_id(); auto meta_param = meta_table.get_meta_action_param(action_id, attr->id); if (meta_param) { - auto pair_param = get_action_param_pair_from_p4_table_entry(meta_param, matchActionEntry); + auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); if (pair_param.second) { set_attr_ipaddr_family_to_p4(attr->value, pair_param.second); } @@ -1238,7 +1238,7 @@ sai_status_t DashSai::set( } assert(pair_key.first); - if (meta_key->match_type == "ternary" && string_has_suffix(meta_key->name, "_MASK")) { + if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) { set_attr_value_mask_to_p4_ternary(meta_key->field, meta_key->bitwidth, attr->value, pair_key.first->mutable_ternary()); } @@ -1275,7 +1275,7 @@ sai_status_t DashSai::set( pi_p4_id_t action_id = action->action_id(); auto meta_param = meta_table.get_meta_action_param(action_id, attr->id); if (meta_param) { - auto pair_param = get_action_param_pair_from_p4_table_entry(meta_param, matchActionEntry); + auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); if (pair_param.second) { set_attr_ipaddr_family_to_p4(attr->value, pair_param.second); } @@ -1313,7 +1313,7 @@ sai_status_t DashSai::get( for (uint32_t i = 0; i < attr_count; i++) { if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { // attr in table action params - auto pair_param = get_action_param_pair_from_p4_table_entry(meta_param, matchActionEntry); + auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); if (pair_param.second) { get_attr_ipaddr_family_from_p4(pair_param.second, attr_list[i].value); } @@ -1329,7 +1329,7 @@ sai_status_t DashSai::get( } assert(pair_key.first); - if (meta_key->match_type == "ternary" && string_has_suffix(meta_key->name, "_MASK")) { + if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) { get_attr_value_mask_from_p4_ternary(meta_key->field, meta_key->bitwidth, pair_key.first->mutable_ternary(), attr_list[i].value); } @@ -1364,7 +1364,7 @@ sai_status_t DashSai::get( for (uint32_t i = 0; i < attr_count; i++) { if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { // attr in table action params - auto pair_param = get_action_param_pair_from_p4_table_entry(meta_param, matchActionEntry); + auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); if (pair_param.second) { get_attr_ipaddr_family_from_p4(pair_param.second, attr_list[i].value); } diff --git a/dash-pipeline/SAI/src/p4meta.cpp b/dash-pipeline/SAI/src/p4meta.cpp index 2cf8478d6..b75d7bb2d 100644 --- a/dash-pipeline/SAI/src/p4meta.cpp +++ b/dash-pipeline/SAI/src/p4meta.cpp @@ -37,7 +37,7 @@ namespace dash const P4MetaKey* P4MetaTable::get_meta_object_key() const { for (auto i=0u; iadd_match(); mf->set_field_id(meta_key->id); - if (meta_key->match_type == "ternary" && string_has_suffix(meta_key->name, "_MASK")) { + if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) { set_attr_value_mask_to_p4_ternary(meta_key->field, meta_key->bitwidth, attr->value, mf->mutable_ternary()); } @@ -376,7 +376,7 @@ namespace dash return pair_key; } - std::pair get_action_param_pair_from_p4_table_entry( + std::pair get_action_param_with_is_v6_flag_from_p4_table_entry( _In_ const P4MetaActionParam *meta_param, _In_ std::shared_ptr matchActionEntry) { @@ -396,7 +396,7 @@ namespace dash return pair_param; } - bool string_has_suffix(const std::string &str, const std::string &suffix) + bool string_ends_with(const std::string &str, const std::string &suffix) { if (str.length() < suffix.length()) return false; diff --git a/dash-pipeline/SAI/src/p4meta.h b/dash-pipeline/SAI/src/p4meta.h index 6c815fdd1..c4a35756a 100644 --- a/dash-pipeline/SAI/src/p4meta.h +++ b/dash-pipeline/SAI/src/p4meta.h @@ -248,9 +248,9 @@ namespace dash _In_ const P4MetaKey *meta_key, _In_ std::shared_ptr matchActionEntry); - std::pair get_action_param_pair_from_p4_table_entry( + std::pair get_action_param_with_is_v6_flag_from_p4_table_entry( _In_ const P4MetaActionParam *meta_param, _In_ std::shared_ptr matchActionEntry); - bool string_has_suffix(const std::string &str, const std::string &suffix); + bool string_ends_with(const std::string &str, const std::string &suffix); } From 93e8ccab476f05ff16162399184725b9d87cfdc1 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 24 Dec 2024 16:23:17 +0000 Subject: [PATCH 5/7] make '{' in new line --- dash-pipeline/SAI/src/dashsai.cpp | 147 ++++++++++++++++-------- dash-pipeline/SAI/src/p4meta.cpp | 182 ++++++++++++++++++++---------- dash-pipeline/SAI/src/p4meta.h | 61 ++++++---- 3 files changed, 258 insertions(+), 132 deletions(-) diff --git a/dash-pipeline/SAI/src/dashsai.cpp b/dash-pipeline/SAI/src/dashsai.cpp index 2960377f9..bbef72fde 100644 --- a/dash-pipeline/SAI/src/dashsai.cpp +++ b/dash-pipeline/SAI/src/dashsai.cpp @@ -634,22 +634,26 @@ grpc::StatusCode DashSai::readTableEntry( assert(client_reader); p4::v1::ReadResponse rep; - if (client_reader->Read(&rep)) { + if (client_reader->Read(&rep)) + { assert(rep.entities_size() == 1); entity->release_table_entry(); entity = rep.mutable_entities(0); entry->CopyFrom(entity->table_entry()); } - else { + else + { entity->release_table_entry(); } auto status = client_reader->Finish(); - if (status.ok()) { + if (status.ok()) + { DASH_LOG_NOTICE("GRPC call Read OK %s", entry->ShortDebugString().c_str()); } - else { + else + { DASH_LOG_ERROR("GRPC ERROR[%d]: %s, %s", status.error_code(), status.error_message().c_str(), status.error_details().c_str()); } @@ -1071,7 +1075,8 @@ sai_status_t DashSai::create( return SAI_STATUS_FAILURE; } - if (auto meta_object_key = meta_table.get_meta_object_key()) { + if (auto meta_object_key = meta_table.get_meta_object_key()) + { auto key_mf = matchActionEntry->add_match(); auto key_mf_exact = key_mf->mutable_exact(); @@ -1080,7 +1085,8 @@ sai_status_t DashSai::create( } pi_p4_id_t action_id = meta_table.find_action_id(attr_count, attr_list); - if (!action_id) { + if (!action_id) + { DASH_LOG_ERROR("Not find p4 table action"); return SAI_STATUS_FAILURE; } @@ -1088,22 +1094,27 @@ sai_status_t DashSai::create( auto action = matchActionEntry->mutable_action()->mutable_action(); action->set_action_id(action_id); - for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { + for (uint32_t i = 0; i < attr_count; i++) + { + if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + { // attr in table action params set_attr_to_p4_action(meta_param, &attr_list[i], action); } - else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) { + else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) + { // attr in table keys set_attr_to_p4_match(meta_key, &attr_list[i], matchActionEntry); } - else { + else + { // attr in extra fields set_attr_to_p4_misc(meta_table, &attr_list[i], matchActionEntry); } } - if (insertInTable(matchActionEntry, objId)) { + if (insertInTable(matchActionEntry, objId)) + { mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_INSERT, action_id); *objectId = objId; return SAI_STATUS_SUCCESS; @@ -1129,26 +1140,31 @@ sai_status_t DashSai::create( matchActionEntry->set_table_id(meta_table.id); pi_p4_id_t action_id = meta_table.find_action_id(attr_count, attr_list); - if (!action_id) { + if (!action_id) + { DASH_LOG_ERROR("Not find p4 table action"); return SAI_STATUS_FAILURE; } auto action = matchActionEntry->mutable_action()->mutable_action(); action->set_action_id(action_id); - for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { + for (uint32_t i = 0; i < attr_count; i++) + { + if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + { // attr in table action params set_attr_to_p4_action(meta_param, &attr_list[i], action); } - else { + else + { // attr in extra fields set_attr_to_p4_misc(meta_table, &attr_list[i], matchActionEntry); } } auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_INSERT); - if (grpc::StatusCode::OK == ret) { + if (grpc::StatusCode::OK == ret) + { mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_INSERT, action_id); return SAI_STATUS_SUCCESS; } @@ -1164,11 +1180,13 @@ sai_status_t DashSai::remove( DASH_CHECK_API_INITIALIZED(); std::shared_ptr matchActionEntry = nullptr; - if (!getFromTable(objectId, matchActionEntry)) { + if (!getFromTable(objectId, matchActionEntry)) + { return SAI_STATUS_FAILURE; } - if (removeFromTable(objectId)) { + if (removeFromTable(objectId)) + { mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_DELETE); return SAI_STATUS_SUCCESS; } @@ -1185,7 +1203,8 @@ sai_status_t DashSai::remove( auto ret = mutateTableEntry(matchActionEntry, p4::v1::Update_Type_DELETE); - if (grpc::StatusCode::OK == ret) { + if (grpc::StatusCode::OK == ret) + { mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_DELETE); return SAI_STATUS_SUCCESS; } @@ -1202,7 +1221,8 @@ sai_status_t DashSai::set( DASH_CHECK_API_INITIALIZED(); std::shared_ptr matchActionEntry = nullptr; - if (!getFromTable(objectId, matchActionEntry)) { + if (!getFromTable(objectId, matchActionEntry)) + { return SAI_STATUS_FAILURE; } @@ -1210,9 +1230,11 @@ sai_status_t DashSai::set( auto action = matchActionEntry->mutable_action()->mutable_action(); pi_p4_id_t action_id = action->action_id(); auto meta_param = meta_table.get_meta_action_param(action_id, attr->id); - if (meta_param) { + if (meta_param) + { auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); - if (pair_param.second) { + if (pair_param.second) + { set_attr_ipaddr_family_to_p4(attr->value, pair_param.second); } @@ -1220,7 +1242,8 @@ 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) { + 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; @@ -1228,28 +1251,33 @@ sai_status_t DashSai::set( // Search attr in table match fields auto meta_key = meta_table.get_meta_key(attr->id); - if (meta_key) { + if (meta_key) + { std::shared_ptr new_entry = std::make_shared(); new_entry->CopyFrom(*matchActionEntry); auto pair_key = get_match_pair_from_p4_table_entry(meta_key, new_entry); - if (pair_key.second) { + if (pair_key.second) + { set_attr_ipaddr_family_to_p4(attr->value, pair_key.second->mutable_exact()); } assert(pair_key.first); - if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) { + if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) + { set_attr_value_mask_to_p4_ternary(meta_key->field, meta_key->bitwidth, attr->value, pair_key.first->mutable_ternary()); } - else { + else + { set_attr_value_to_p4_match(*meta_key, attr->value, pair_key.first); } removeFromTable(objectId); mutateSiblingTablesEntry(meta_table, matchActionEntry, p4::v1::Update_Type_DELETE); - if (insertInTable(new_entry, objectId)) { + if (insertInTable(new_entry, objectId)) + { mutateSiblingTablesEntry(meta_table, new_entry, p4::v1::Update_Type_INSERT, action_id); return SAI_STATUS_SUCCESS; } @@ -1266,7 +1294,8 @@ sai_status_t DashSai::set( DASH_LOG_ENTER(); DASH_CHECK_API_INITIALIZED(); - if (grpc::StatusCode::OK != readTableEntry(matchActionEntry)) { + if (grpc::StatusCode::OK != readTableEntry(matchActionEntry)) + { return SAI_STATUS_FAILURE; } @@ -1274,9 +1303,11 @@ sai_status_t DashSai::set( auto action = matchActionEntry->mutable_action()->mutable_action(); pi_p4_id_t action_id = action->action_id(); auto meta_param = meta_table.get_meta_action_param(action_id, attr->id); - if (meta_param) { + if (meta_param) + { auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); - if (pair_param.second) { + if (pair_param.second) + { set_attr_ipaddr_family_to_p4(attr->value, pair_param.second); } @@ -1284,7 +1315,8 @@ 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) { + 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; @@ -1303,41 +1335,50 @@ sai_status_t DashSai::get( DASH_CHECK_API_INITIALIZED(); std::shared_ptr matchActionEntry = nullptr; - if (!getFromTable(objectId, matchActionEntry)) { + if (!getFromTable(objectId, matchActionEntry)) + { return SAI_STATUS_FAILURE; } auto action = matchActionEntry->mutable_action()->mutable_action(); pi_p4_id_t action_id = action->action_id(); - for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { + for (uint32_t i = 0; i < attr_count; i++) + { + if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + { // attr in table action params auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); - if (pair_param.second) { + if (pair_param.second) + { get_attr_ipaddr_family_from_p4(pair_param.second, attr_list[i].value); } assert(pair_param.first); get_attr_value_from_p4(meta_param->field, meta_param->bitwidth, pair_param.first, attr_list[i].value); } - else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) { + else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) + { // attr in table keys auto pair_key = get_match_pair_from_p4_table_entry(meta_key, matchActionEntry); - if (pair_key.second) { + if (pair_key.second) + { get_attr_ipaddr_family_from_p4(pair_key.second->mutable_exact(), attr_list[i].value); } assert(pair_key.first); - if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) { + if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) + { get_attr_value_mask_from_p4_ternary(meta_key->field, meta_key->bitwidth, pair_key.first->mutable_ternary(), attr_list[i].value); } - else { + else + { get_attr_value_from_p4_match(*meta_key, pair_key.first, attr_list[i].value); } } - else { + else + { get_attr_from_p4_misc(meta_table, matchActionEntry, &attr_list[i]); } } @@ -1354,25 +1395,30 @@ sai_status_t DashSai::get( DASH_LOG_ENTER(); DASH_CHECK_API_INITIALIZED(); - if (grpc::StatusCode::OK != readTableEntry(matchActionEntry)) { + if (grpc::StatusCode::OK != readTableEntry(matchActionEntry)) + { return SAI_STATUS_FAILURE; } auto action = matchActionEntry->mutable_action()->mutable_action(); pi_p4_id_t action_id = action->action_id(); - for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) { + for (uint32_t i = 0; i < attr_count; i++) + { + if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + { // attr in table action params auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); - if (pair_param.second) { + if (pair_param.second) + { get_attr_ipaddr_family_from_p4(pair_param.second, attr_list[i].value); } assert(pair_param.first); get_attr_value_from_p4(meta_param->field, meta_param->bitwidth, pair_param.first, attr_list[i].value); } - else { + else + { get_attr_from_p4_misc(meta_table, matchActionEntry, &attr_list[i]); } } @@ -1386,7 +1432,8 @@ void DashSai::mutateSiblingTablesEntry( _In_ p4::v1::Update_Type updateType, _In_ uint32_t action_id) { - if (meta_table.sibling_tables.empty()) { + if (meta_table.sibling_tables.empty()) + { return; } @@ -1394,10 +1441,12 @@ void DashSai::mutateSiblingTablesEntry( entry->CopyFrom(*matchActionEntry); auto action = entry->mutable_action()->mutable_action(); - for (auto &sibling: meta_table.sibling_tables) { + for (auto &sibling: meta_table.sibling_tables) + { entry->set_table_id(sibling.id); - if (updateType != p4::v1::Update_Type_DELETE) { + 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); diff --git a/dash-pipeline/SAI/src/p4meta.cpp b/dash-pipeline/SAI/src/p4meta.cpp index b75d7bb2d..f71ad42dd 100644 --- a/dash-pipeline/SAI/src/p4meta.cpp +++ b/dash-pipeline/SAI/src/p4meta.cpp @@ -13,8 +13,10 @@ namespace dash const P4MetaKey* P4MetaTable::get_meta_key( _In_ sai_attr_id_t attr_id) const { - for (auto i=0u; isecond.params; - for (auto i=0u; ifirst; } auto itr = extra_fields.find("ACTION"); assert(itr != extra_fields.end()); - for (uint32_t i = 0; i < attr_count; i++) { - if (attr_list[i].id == itr->second) { + for (uint32_t i = 0; i < attr_count; i++) + { + if (attr_list[i].id == itr->second) + { uint32_t action_enum_id = attr_list[i].value.u32; - for (auto &action: actions) { - if (action.second.enum_id == action_enum_id) { + for (auto &action: actions) + { + if (action.second.enum_id == action_enum_id) + { return action.first; } } @@ -92,7 +106,8 @@ namespace dash _In_ uint32_t action_id) const { auto itr = actions.find(action_id); - if (itr != actions.end()) { + if (itr != actions.end()) + { return itr->second.enum_id; } @@ -123,14 +138,16 @@ namespace dash const char *v = mf_lpm->value().c_str(); auto prefix_len = mf_lpm->prefix_len(); - if (value.ipprefix.addr_family == SAI_IP_ADDR_FAMILY_IPV4) { + if (value.ipprefix.addr_family == SAI_IP_ADDR_FAMILY_IPV4) + { uint32_t val = *(const uint32_t*)v; prefix_len -= 96; assert (prefix_len <= 32); value.ipprefix.addr.ip4 = val; value.ipprefix.mask.ip4 = 0xffffffff << (32 - prefix_len); } - else { + else + { assert (prefix_len <= 128); uint8_t netmask[16] = { 0 }; int i; @@ -157,7 +174,7 @@ namespace dash if (field == "u64") return u64SetMask(value, mf_ternary, bitwidth); - assert(0); + assert(0 && "unsupported field"); } void get_attr_value_mask_from_p4_ternary( @@ -169,30 +186,38 @@ namespace dash { const char *v = mf_ternary->mask().c_str(); - if (field == "ipaddr") { - if (value.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) { + if (field == "ipaddr") + { + if (value.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) + { uint32_t val = *(const uint32_t*)v; value.ipaddr.addr.ip4 = val; } - else { + else + { memcpy(value.ipaddr.addr.ip6, v, 16); } } - else if (field == "u32") { + else if (field == "u32") + { uint32_t val = *(const uint32_t*)v; value.u32 = ntohl(val) >> (32 - bitwidth); } - else if (field == "u64") { + else if (field == "u64") + { uint64_t val = *(const uint64_t*)v; - if (*reinterpret_cast("\0\x01") == 0) { // Little Endian + if (*reinterpret_cast("\0\x01") == 0) + { // Little Endian value.u64 = be64toh(val) >> (64 - bitwidth); } - else { + else + { value.u64 = val & ((1ul<mutable_exact(); set_attr_value_to_p4(key.field, key.bitwidth, value, mf_exact); } - else if (key.match_type == "lpm") { + else if (key.match_type == "lpm") + { auto mf_lpm = mf->mutable_lpm(); if (getPrefixLength(value) == 0) { @@ -216,37 +243,44 @@ namespace dash } set_attr_value_to_p4(key.field, key.bitwidth, value, mf_lpm); } - else if (key.match_type == "ternary") { + else if (key.match_type == "ternary") + { auto mf_ternary = mf->mutable_ternary(); set_attr_value_to_p4(key.field, key.bitwidth, value, mf_ternary); } - else if (key.match_type == "optional") { + else if (key.match_type == "optional") + { auto mf_optional = mf->mutable_optional(); set_attr_value_to_p4(key.field, key.bitwidth, value, mf_optional); } - else if (key.match_type == "list") { + else if (key.match_type == "list") + { // BMv2 doesn't support "list" match type, and we are using "optional" match in v1model as our implementation. // Hence, here we only take the first item from the list and program it as optional match. auto mf_optional = mf->mutable_optional(); - if (key.field == "ipprefixlist") { + if (key.field == "ipprefixlist") + { sai_attribute_value_t val; val.ipaddr.addr_family = value.ipprefixlist.list[0].addr_family; val.ipaddr.addr = value.ipprefixlist.list[0].addr; set_attr_value_to_p4("ipaddr", key.bitwidth, val, mf_optional); } - else { + else + { set_attr_value_to_p4(key.field, key.bitwidth, value, mf_optional); } } - else if (key.match_type == "range_list") { + else if (key.match_type == "range_list") + { // BMv2 doesn't support "range_list" match type, and we are using "optional" match in v1model as our implementation. // Hence, here we only take the first item from the list and program the range start as optional match. auto mf_optional = mf->mutable_optional(); // FIXME only u16rangelist in sai_attribute_value_t u16SetVal(value.u16rangelist.list[0].min, mf_optional, key.bitwidth); } - else { - assert(0); + else + { + assert(0 && "unsupported match type"); } } @@ -255,32 +289,39 @@ namespace dash _In_ p4::v1::FieldMatch *mf, _Out_ sai_attribute_value_t &value) { - if (key.match_type == "exact") { + if (key.match_type == "exact") + { auto mf_exact = mf->mutable_exact(); get_attr_value_from_p4(key.field, key.bitwidth, mf_exact, value); } - else if (key.match_type == "lpm") { + else if (key.match_type == "lpm") + { auto mf_lpm = mf->mutable_lpm(); get_attr_value_from_p4(key.field, key.bitwidth, mf_lpm, value); } - else if (key.match_type == "ternary") { + else if (key.match_type == "ternary") + { auto mf_ternary = mf->mutable_ternary(); get_attr_value_from_p4(key.field, key.bitwidth, mf_ternary, value); } - else if (key.match_type == "optional") { + else if (key.match_type == "optional") + { auto mf_optional = mf->mutable_optional(); get_attr_value_from_p4(key.field, key.bitwidth, mf_optional, value); } - else if (key.match_type == "list") { + else if (key.match_type == "list") + { auto mf_optional = mf->mutable_optional(); get_attr_value_from_p4(key.field, key.bitwidth, mf_optional, value); } - else if (key.match_type == "range_list") { + else if (key.match_type == "range_list") + { auto mf_optional = mf->mutable_optional(); get_attr_value_from_p4(key.field, key.bitwidth, mf_optional, value); } - else { - assert(0); + else + { + assert(0 && "unsupported match type"); } } @@ -289,7 +330,8 @@ namespace dash _In_ const sai_attribute_t *attr, _Inout_ std::shared_ptr matchActionEntry) { - if (meta_key->ip_is_v6_field_id) { + if (meta_key->ip_is_v6_field_id) + { auto mf = matchActionEntry->add_match(); mf->set_field_id(meta_key->ip_is_v6_field_id); set_attr_ipaddr_family_to_p4(attr->value, mf->mutable_exact()); @@ -297,11 +339,13 @@ namespace dash auto mf = matchActionEntry->add_match(); mf->set_field_id(meta_key->id); - if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) { + if (meta_key->match_type == "ternary" && string_ends_with(meta_key->name, "_MASK")) + { set_attr_value_mask_to_p4_ternary(meta_key->field, meta_key->bitwidth, attr->value, mf->mutable_ternary()); } - else { + else + { set_attr_value_to_p4_match(*meta_key, attr->value, mf); } } @@ -311,7 +355,8 @@ namespace dash _In_ const sai_attribute_t *attr, _Out_ p4::v1::Action *action) { - if (meta_param->ip_is_v6_field_id) { + if (meta_param->ip_is_v6_field_id) + { auto param = action->add_params(); param->set_param_id(meta_param->ip_is_v6_field_id); set_attr_ipaddr_family_to_p4(attr->value, param); @@ -327,9 +372,12 @@ namespace dash _In_ const sai_attribute_t *attr, _Inout_ std::shared_ptr matchActionEntry) { - for (auto &extra_attr: meta_table.extra_fields) { - if (extra_attr.second == attr->id) { - if (extra_attr.first == "PRIORITY") { + for (auto &extra_attr: meta_table.extra_fields) + { + if (extra_attr.second == attr->id) + { + if (extra_attr.first == "PRIORITY") + { matchActionEntry->set_priority(attr->value.u32); break; } @@ -342,14 +390,18 @@ namespace dash _In_ const std::shared_ptr matchActionEntry, _Inout_ sai_attribute_t *attr) { - for (auto &extra_attr: meta_table.extra_fields) { - if (extra_attr.second == attr->id) { - if (extra_attr.first == "ACTION") { + for (auto &extra_attr: meta_table.extra_fields) + { + if (extra_attr.second == attr->id) + { + if (extra_attr.first == "ACTION") + { auto action = matchActionEntry->mutable_action()->mutable_action(); auto action_id = action->action_id(); attr->value.u32 = meta_table.find_action_enum_id(action_id); } - else if (extra_attr.first == "PRIORITY") { + else if (extra_attr.first == "PRIORITY") + { attr->value.u32 = matchActionEntry->priority(); break; } @@ -363,12 +415,15 @@ namespace dash { std::pair pair_key = {nullptr, nullptr}; - for (int i = 0; i < matchActionEntry->match_size(); i++) { + for (int i = 0; i < matchActionEntry->match_size(); i++) + { auto mf = matchActionEntry->mutable_match(i); - if (mf->field_id() == meta_key->id) { + if (mf->field_id() == meta_key->id) + { pair_key.first = mf; } - else if (mf->field_id() == meta_key->ip_is_v6_field_id) { + else if (mf->field_id() == meta_key->ip_is_v6_field_id) + { pair_key.second = mf; } } @@ -383,12 +438,15 @@ namespace dash auto action = matchActionEntry->mutable_action()->mutable_action(); std::pair pair_param = {nullptr, nullptr}; - for (int i = 0; i < action->params_size(); i++) { + for (int i = 0; i < action->params_size(); i++) + { auto param = action->mutable_params(i); - if (param->param_id() == meta_param->id) { + if (param->param_id() == meta_param->id) + { pair_param.first = param; } - else if (param->param_id() == meta_param->ip_is_v6_field_id) { + else if (param->param_id() == meta_param->ip_is_v6_field_id) + { pair_param.second = param; } } diff --git a/dash-pipeline/SAI/src/p4meta.h b/dash-pipeline/SAI/src/p4meta.h index c4a35756a..097f8c7b9 100644 --- a/dash-pipeline/SAI/src/p4meta.h +++ b/dash-pipeline/SAI/src/p4meta.h @@ -11,7 +11,8 @@ using namespace dash::utils; namespace dash { - struct P4MetaKey { + struct P4MetaKey + { sai_attr_id_t attr_id; std::string name; uint32_t id; @@ -21,7 +22,8 @@ namespace dash uint32_t ip_is_v6_field_id; }; - struct P4MetaActionParam { + struct P4MetaActionParam + { sai_attr_id_t attr_id; uint32_t id; std::string field; @@ -29,18 +31,21 @@ namespace dash uint32_t ip_is_v6_field_id; }; - struct P4MetaAction { + struct P4MetaAction + { uint32_t enum_id; std::vector params; }; - struct P4MetaSiblingTable { + struct P4MetaSiblingTable + { uint32_t id; // action enum id -> p4 action id std::map actions; }; - struct P4MetaTable { + struct P4MetaTable + { uint32_t id; std::vector keys; std::map actions; @@ -106,7 +111,7 @@ namespace dash if (field == "u8list") return u8listSetVal(value, p4_key_or_param, bitwidth); - assert(0); + assert(0 && "unsupported field"); } void set_attr_value_to_p4( @@ -125,50 +130,64 @@ namespace dash { const char *v = p4_key_or_param->value().c_str(); - if (field == "booldata") { + if (field == "booldata") + { value.booldata = *(const bool*)v; } - else if (field == "u8") { + else if (field == "u8") + { value.u8 = *(const uint8_t*)v; } - else if (field == "u16") { + else if (field == "u16") + { uint16_t val = *(const uint16_t*)v; value.u16 = ntohs(val); } - else if (field == "s32") { + else if (field == "s32") + { int32_t val = *(const int32_t*)v; value.s32 = ntohl(val) >> (32 - bitwidth); } - else if (field == "u32") { + else if (field == "u32") + { uint32_t val = *(const uint32_t*)v; value.u32 = ntohl(val) >> (32 - bitwidth); } - else if (field == "u64") { + else if (field == "u64") + { uint64_t val = *(const uint64_t*)v; - if (*reinterpret_cast("\0\x01") == 0) { // Little Endian + if (*reinterpret_cast("\0\x01") == 0) + { // Little Endian value.u64 = be64toh(val) >> (64 - bitwidth); } - else { + else + { value.u64 = val & ((1ul<value().size()); } - else { - assert(0); + else + { + assert(0 && "unsupported field"); } } From f972b8371f4d94a75cb48920c19beff714f48f25 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 24 Dec 2024 16:36:48 +0000 Subject: [PATCH 6/7] Replace TAB with four blank spaces in dashsai.h --- dash-pipeline/SAI/src/dashsai.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dash-pipeline/SAI/src/dashsai.h b/dash-pipeline/SAI/src/dashsai.h index ccda64c12..2c83810e6 100644 --- a/dash-pipeline/SAI/src/dashsai.h +++ b/dash-pipeline/SAI/src/dashsai.h @@ -151,11 +151,11 @@ namespace dash private: // private helper methods - void mutateSiblingTablesEntry( - _In_ const P4MetaTable &meta_table, - _In_ std::shared_ptr, - _In_ p4::v1::Update_Type updateType, - _In_ uint32_t action_id = 0); + void mutateSiblingTablesEntry( + _In_ const P4MetaTable &meta_table, + _In_ std::shared_ptr, + _In_ p4::v1::Update_Type updateType, + _In_ uint32_t action_id = 0); public: // default attributes helper From 2810824beb103e111160738871f7c87c72d95261 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Wed, 8 Jan 2025 10:02:43 +0000 Subject: [PATCH 7/7] Address review comments --- dash-pipeline/SAI/src/dashsai.cpp | 27 ++++++++++++++++++++------- dash-pipeline/SAI/src/p4meta.cpp | 15 +++++++-------- dash-pipeline/SAI/src/p4meta.h | 15 +++++++-------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/dash-pipeline/SAI/src/dashsai.cpp b/dash-pipeline/SAI/src/dashsai.cpp index bbef72fde..4c281fd00 100644 --- a/dash-pipeline/SAI/src/dashsai.cpp +++ b/dash-pipeline/SAI/src/dashsai.cpp @@ -1075,7 +1075,8 @@ sai_status_t DashSai::create( return SAI_STATUS_FAILURE; } - if (auto meta_object_key = meta_table.get_meta_object_key()) + auto meta_object_key = meta_table.get_meta_object_key(); + if (meta_object_key) { auto key_mf = matchActionEntry->add_match(); auto key_mf_exact = key_mf->mutable_exact(); @@ -1096,12 +1097,16 @@ sai_status_t DashSai::create( for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id); + if (meta_param) { // attr in table action params set_attr_to_p4_action(meta_param, &attr_list[i], action); + continue; } - else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) + + auto meta_key = meta_table.get_meta_key(attr_list[i].id); + if (meta_key) { // attr in table keys set_attr_to_p4_match(meta_key, &attr_list[i], matchActionEntry); @@ -1150,7 +1155,8 @@ sai_status_t DashSai::create( for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id); + if (meta_param) { // attr in table action params set_attr_to_p4_action(meta_param, &attr_list[i], action); @@ -1345,7 +1351,8 @@ sai_status_t DashSai::get( for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id); + if (meta_param) { // attr in table action params auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); @@ -1356,8 +1363,11 @@ sai_status_t DashSai::get( assert(pair_param.first); get_attr_value_from_p4(meta_param->field, meta_param->bitwidth, pair_param.first, attr_list[i].value); + continue; } - else if (auto meta_key = meta_table.get_meta_key(attr_list[i].id)) + + auto meta_key = meta_table.get_meta_key(attr_list[i].id); + if (meta_key) { // attr in table keys auto pair_key = get_match_pair_from_p4_table_entry(meta_key, matchActionEntry); @@ -1405,7 +1415,8 @@ sai_status_t DashSai::get( for (uint32_t i = 0; i < attr_count; i++) { - if (auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id)) + auto meta_param = meta_table.get_meta_action_param(action_id, attr_list[i].id); + if (meta_param) { // attr in table action params auto pair_param = get_action_param_with_is_v6_flag_from_p4_table_entry(meta_param, matchActionEntry); @@ -1437,6 +1448,8 @@ void DashSai::mutateSiblingTablesEntry( return; } + // Entry in sibling table is almost same as the original table entry, + // only table id and table action id are different. std::shared_ptr entry = std::make_shared(); entry->CopyFrom(*matchActionEntry); auto action = entry->mutable_action()->mutable_action(); diff --git a/dash-pipeline/SAI/src/p4meta.cpp b/dash-pipeline/SAI/src/p4meta.cpp index f71ad42dd..57b6c787e 100644 --- a/dash-pipeline/SAI/src/p4meta.cpp +++ b/dash-pipeline/SAI/src/p4meta.cpp @@ -206,14 +206,13 @@ namespace dash else if (field == "u64") { uint64_t val = *(const uint64_t*)v; - if (*reinterpret_cast("\0\x01") == 0) - { // Little Endian - value.u64 = be64toh(val) >> (64 - bitwidth); - } - else - { - value.u64 = val & ((1ul<> (64 - bitwidth); +#elif __BYTE_ORDER == __BIG_ENDIAN + value.u64 = val & ((1ul<" +#endif } else { diff --git a/dash-pipeline/SAI/src/p4meta.h b/dash-pipeline/SAI/src/p4meta.h index 097f8c7b9..71d9a23ec 100644 --- a/dash-pipeline/SAI/src/p4meta.h +++ b/dash-pipeline/SAI/src/p4meta.h @@ -156,14 +156,13 @@ namespace dash else if (field == "u64") { uint64_t val = *(const uint64_t*)v; - if (*reinterpret_cast("\0\x01") == 0) - { // Little Endian - value.u64 = be64toh(val) >> (64 - bitwidth); - } - else - { - value.u64 = val & ((1ul<> (64 - bitwidth); +#elif __BYTE_ORDER == __BIG_ENDIAN + value.u64 = val & ((1ul<" +#endif } else if (field == "ipaddr") {