From 93e8ccab476f05ff16162399184725b9d87cfdc1 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 24 Dec 2024 16:23:17 +0000 Subject: [PATCH] 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"); } }