From c0f76852114b4aa16eead8c1460ef326ec47efd9 Mon Sep 17 00:00:00 2001 From: Derek Foster Date: Sun, 12 Jan 2025 11:57:25 -0800 Subject: [PATCH] [ovsp4rt] Implement GetTxiAccVsiHostSrcPort() - Extracted the GetTxiAccVsiHostSrcPort() function from ConfigFdbEntry() and ConfigSrcPortEntry(). This change is ES2K-specific. Signed-off-by: Derek Foster --- ovs-p4rt/sidecar/newovsp4rt.cc | 124 +++++++++++++-------------------- 1 file changed, 50 insertions(+), 74 deletions(-) diff --git a/ovs-p4rt/sidecar/newovsp4rt.cc b/ovs-p4rt/sidecar/newovsp4rt.cc index 3e46f4f3..d0cc476d 100644 --- a/ovs-p4rt/sidecar/newovsp4rt.cc +++ b/ovs-p4rt/sidecar/newovsp4rt.cc @@ -2110,6 +2110,46 @@ absl::StatusOr<::p4::v1::ReadResponse> GetTxAccVsiTableEntry( return client.sendReadRequest(read_request); } +absl::StatusOr GetTxAccVsiHostSrcPort( + ClientInterface& client, const ::p4::config::v1::P4Info& p4info, + uint32 src_port) { + auto response_or_status = GetTxAccVsiTableEntry(client, src_port, p4info); + auto status = response_or_status.status(); + if (!status.ok()) return status; + + ::p4::v1::ReadResponse read_response = std::move(response_or_status).value(); + + // TODO(derek): remove dead code + std::vector<::p4::v1::TableEntry> table_entries; + table_entries.reserve(read_response.entities().size()); + + int param_id = + GetParamId(p4info, TX_ACC_VSI_TABLE_ACTION_L2_FWD_AND_BYPASS_BRIDGE, + ACTION_L2_FWD_AND_BYPASS_BRIDGE_PARAM_PORT); + + uint32_t host_sp = 0; + for (const auto& entity : read_response.entities()) { + ::p4::v1::TableEntry table_entry = entity.table_entry(); + // TODO(derek): why mutable? + auto* table_action = table_entry.mutable_action(); + // TODO(derek): why mutable? + auto* action = table_action->mutable_action(); + for (const auto& param : action->params()) { + if (param_id == param.param_id()) { + const std::string& s1 = param.value(); + // TODO(derek): why make a mutable copy? + std::string s2 = s1; + for (int param_bytes = 0; param_bytes < 4; param_bytes++) { + host_sp = host_sp << 8 | int(s2[param_bytes]); + } + break; + } + } + } + + return host_sp; +} + absl::Status ConfigureVsiSrcPortTableEntry( ClientInterface& client, const struct src_port_info& sp, const ::p4::config::v1::P4Info& p4info, bool insert_entry) { @@ -2269,7 +2309,7 @@ absl::Status DoConfigFdbEntry(ClientInterface& client, GetFdbTunnelTableEntry(client, learn_info, p4info, true); if (status_or_read_response.ok()) { // Return if entry already exists. - return status_or_read_response.status(); + return util::OkStatus(); } } @@ -2293,45 +2333,12 @@ absl::Status DoConfigFdbEntry(ClientInterface& client, // Ignore errors (why?) (void)ConfigFdbRxVlanTableEntry(client, learn_info, p4info, insert_entry); - // TODO(derek): refactor (extract method) - // - // GetVsiSrcPort(ClientInterface& client, const P4Info& p4info, - // uint32_t src_port, uint32_t& vsi_port); - auto response_or_status = - GetTxAccVsiTableEntry(client, learn_info.src_port, p4info); - if (!response_or_status.ok()) { - return response_or_status.status(); + auto host_sp = + GetTxAccVsiHostSrcPort(client, p4info, learn_info.src_port); + if (!host_sp.ok()) { + return host_sp.status(); } - - ::p4::v1::ReadResponse read_response = - std::move(response_or_status).value(); - std::vector<::p4::v1::TableEntry> table_entries; - - table_entries.reserve(read_response.entities().size()); - - int param_id = - GetParamId(p4info, TX_ACC_VSI_TABLE_ACTION_L2_FWD_AND_BYPASS_BRIDGE, - ACTION_L2_FWD_AND_BYPASS_BRIDGE_PARAM_PORT); - - uint32_t host_sp = 0; - for (const auto& entity : read_response.entities()) { - p4::v1::TableEntry table_entry_1 = entity.table_entry(); - auto* table_action = table_entry_1.mutable_action(); - auto* action = table_action->mutable_action(); - for (const auto& param : action->params()) { - if (param_id == param.param_id()) { - const std::string& s1 = param.value(); - std::string s2 = s1; - for (int param_bytes = 0; param_bytes < 4; param_bytes++) { - host_sp = host_sp << 8 | int(s2[param_bytes]); - } - break; - } - } - } - - learn_info.src_port = host_sp; - // end of refactoring + learn_info.src_port = host_sp.value(); } // Ignore errors (why?) @@ -2414,42 +2421,11 @@ absl::Status DoConfigSrcPortEntry(ClientInterface& client, status = client.getPipelineConfig(&p4info); if (!status.ok()) return status; - // TODO(derek): refactor (extract method) - // - // GetVsiSrcPort(ClientInterface& client, const P4Info& p4info, - // uint32_t src_port, uint32_t& vsi_port); - auto response_or_status = - GetTxAccVsiTableEntry(client, vsi_sp.src_port, p4info); - if (!response_or_status.ok()) return response_or_status.status(); - - ::p4::v1::ReadResponse read_response = std::move(response_or_status).value(); - std::vector<::p4::v1::TableEntry> table_entries; - - table_entries.reserve(read_response.entities().size()); - - int param_id = - GetParamId(p4info, TX_ACC_VSI_TABLE_ACTION_L2_FWD_AND_BYPASS_BRIDGE, - ACTION_L2_FWD_AND_BYPASS_BRIDGE_PARAM_PORT); - - uint32_t host_sp = 0; - for (const auto& entity : read_response.entities()) { - p4::v1::TableEntry table_entry_1 = entity.table_entry(); - auto* table_action = table_entry_1.mutable_action(); - auto* action = table_action->mutable_action(); - for (const auto& param : action->params()) { - if (param_id == param.param_id()) { - const std::string& s1 = param.value(); - std::string s2 = s1; - for (int param_bytes = 0; param_bytes < 4; param_bytes++) { - host_sp = host_sp << 8 | int(s2[param_bytes]); - } - break; - } - } + auto host_sp = GetTxAccVsiHostSrcPort(client, p4info, vsi_sp.src_port); + if (!host_sp.ok()) { + return host_sp.status(); } - - vsi_sp.src_port = host_sp; - // end of refactoring + vsi_sp.src_port = host_sp.value(); return ConfigureVsiSrcPortTableEntry(client, vsi_sp, p4info, insert_entry); }