diff --git a/orchagent/muxorch.cpp b/orchagent/muxorch.cpp index c9d4158040..6770a4defb 100644 --- a/orchagent/muxorch.cpp +++ b/orchagent/muxorch.cpp @@ -1280,8 +1280,6 @@ bool MuxOrch::handlePeerSwitch(const Request& request) if (op == SET_COMMAND) { - mux_peer_switch_ = peer_ip; - // Create P2P tunnel when peer_ip is available. IpAddresses dst_ips = decap_orch_->getDstIpAddresses(MUX_TUNNEL); if (!dst_ips.getSize()) @@ -1316,6 +1314,7 @@ bool MuxOrch::handlePeerSwitch(const Request& request) } mux_tunnel_id_ = create_tunnel(&peer_ip, &dst_ip, tc_to_dscp_map_id, tc_to_queue_map_id, dscp_mode_name); + mux_peer_switch_ = peer_ip; SWSS_LOG_NOTICE("Mux peer ip '%s' was added, peer name '%s'", peer_ip.to_string().c_str(), peer_name.c_str()); } diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 3440164a0f..1cc3127c31 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -346,7 +346,7 @@ bool OrchDaemon::init() * when iterating ConsumerMap. This is ensured implicitly by the order of keys in ordered map. * For cases when Orch has to process tables in specific order, like PortsOrch during warm start, it has to override Orch::doTask() */ - m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, gFlowCounterRouteOrch, mux_orch, mux_cb_orch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, gQosOrch, wm_orch, gPolicerOrch, tunnel_decap_orch, sflow_orch, gDebugCounterOrch, gMacsecOrch, gBfdOrch, gSrv6Orch}; + m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, gFlowCounterRouteOrch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, gQosOrch, wm_orch, gPolicerOrch, tunnel_decap_orch, sflow_orch, gDebugCounterOrch, gMacsecOrch, gBfdOrch, gSrv6Orch, mux_orch, mux_cb_orch}; bool initialize_dtel = false; if (platform == BFN_PLATFORM_SUBSTRING || platform == VS_PLATFORM_SUBSTRING) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index fd96d6a3c2..e9a3afdc1e 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -77,13 +77,6 @@ static map fec_mode_map = { "fc", SAI_PORT_FEC_MODE_FC } }; -static map fec_mode_reverse_map = -{ - { SAI_PORT_FEC_MODE_NONE, "none" }, - { SAI_PORT_FEC_MODE_RS, "rs" }, - { SAI_PORT_FEC_MODE_FC, "fc" } -}; - static map pfc_asym_map = { { "on", SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE }, @@ -1195,31 +1188,19 @@ bool PortsOrch::setPortTpid(sai_object_id_t id, sai_uint16_t tpid) return true; } -bool PortsOrch::setPortFec(Port &port, string &mode) + +bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t mode) { SWSS_LOG_ENTER(); - auto searchRef = m_portSupportedFecModes.find(port.m_port_id); - if (searchRef != m_portSupportedFecModes.end()) - { - auto &supportedFecModes = searchRef->second; - if (!supportedFecModes.empty() && (supportedFecModes.find(mode) == supportedFecModes.end())) - { - SWSS_LOG_ERROR("Unsupported mode %s on port %s", mode.c_str(), port.m_alias.c_str()); - // We return true becase the caller will keep the item in m_toSync and retry it later if we return false - // As the FEC mode is not supported it doesn't make sense to retry. - return true; - } - } - sai_attribute_t attr; attr.id = SAI_PORT_ATTR_FEC_MODE; - attr.value.s32 = port.m_fec_mode; + attr.value.s32 = mode; sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set FEC mode %s to port %s", mode.c_str(), port.m_alias.c_str()); + SWSS_LOG_ERROR("Failed to set fec mode %d to port pid:%" PRIx64, mode, port.m_port_id); task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status); if (handle_status != task_success) { @@ -1227,7 +1208,7 @@ bool PortsOrch::setPortFec(Port &port, string &mode) } } - SWSS_LOG_NOTICE("Set port %s FEC mode %s", port.m_alias.c_str(), mode.c_str()); + SWSS_LOG_INFO("Set fec mode %d to port pid:%" PRIx64, mode, port.m_port_id); setGearboxPortsAttr(port, SAI_PORT_ATTR_FEC_MODE, &mode); @@ -2004,87 +1985,6 @@ void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_ m_portStateTable.set(alias, v); } -void PortsOrch::getPortSupportedFecModes(const std::string& alias, sai_object_id_t port_id, PortSupportedFecModes &supported_fecmodes) -{ - sai_attribute_t attr; - sai_status_t status; - vector fecModes(fec_mode_reverse_map.size()); - - attr.id = SAI_PORT_ATTR_SUPPORTED_FEC_MODE; - attr.value.s32list.count = static_cast(fecModes.size()); - attr.value.s32list.list = fecModes.data(); - - status = sai_port_api->get_port_attribute(port_id, 1, &attr); - fecModes.resize(attr.value.s32list.count); - if (status == SAI_STATUS_SUCCESS) - { - if (fecModes.empty()) - { - supported_fecmodes.insert("N/A"); - } - else - { - for(auto fecMode : fecModes) - { - supported_fecmodes.insert(fec_mode_reverse_map[static_cast(fecMode)]); - } - } - } - else - { - if (SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) || - SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status) || - status == SAI_STATUS_NOT_IMPLEMENTED) - { - // unable to validate FEC mode if attribute is not supported on platform - SWSS_LOG_NOTICE("Unable to validate FEC mode for port %s id=%" PRIx64 " due to unsupported by platform", - alias.c_str(), port_id); - } - else - { - SWSS_LOG_ERROR("Failed to get a list of supported FEC modes for port %s id=%" PRIx64 ". Error=%d", - alias.c_str(), port_id, status); - } - - supported_fecmodes.clear(); // return empty - } -} - -void PortsOrch::initPortSupportedFecModes(const std::string& alias, sai_object_id_t port_id) -{ - // If port supported speeds map already contains the information, save the SAI call - if (m_portSupportedFecModes.count(port_id)) - { - return; - } - PortSupportedFecModes supported_fec_modes; - getPortSupportedFecModes(alias, port_id, supported_fec_modes); - m_portSupportedFecModes[port_id] = supported_fec_modes; - - if (supported_fec_modes.empty()) - { - // Do not expose "supported_fecs" in case fetching FEC modes is not supported by the vendor - SWSS_LOG_INFO("No supported_fecs exposed to STATE_DB for port %s since fetching supported FEC modes is not supported by the vendor", - alias.c_str()); - return; - } - - vector v; - std::string supported_fec_modes_str; - bool first = true; - for(auto fec : supported_fec_modes) - { - if (first) - first = false; - else - supported_fec_modes_str += ','; - supported_fec_modes_str += fec; - } - - v.emplace_back(std::make_pair("supported_fecs", supported_fec_modes_str)); - m_portStateTable.set(alias, v); -} - /* * If Gearbox is enabled and this is a Gearbox port then set the attributes accordingly. */ @@ -3078,7 +2978,6 @@ void PortsOrch::doPortTask(Consumer &consumer) } initPortSupportedSpeeds(get<0>(it->second), m_portListLaneMap[it->first]); - initPortSupportedFecModes(get<0>(it->second), m_portListLaneMap[it->first]); it++; } @@ -3427,12 +3326,14 @@ void PortsOrch::doPortTask(Consumer &consumer) p.m_fec_mode = fec_mode_map[fec_mode]; p.m_fec_cfg = true; - if (setPortFec(p, fec_mode)) + if (setPortFec(p, p.m_fec_mode)) { m_portList[alias] = p; + SWSS_LOG_NOTICE("Set port %s fec to %s", alias.c_str(), fec_mode.c_str()); } else { + SWSS_LOG_ERROR("Failed to set port %s fec to %s", alias.c_str(), fec_mode.c_str()); it++; continue; } @@ -3442,12 +3343,14 @@ void PortsOrch::doPortTask(Consumer &consumer) /* Port is already down, setting fec mode*/ p.m_fec_mode = fec_mode_map[fec_mode]; p.m_fec_cfg = true; - if (setPortFec(p, fec_mode)) + if (setPortFec(p, p.m_fec_mode)) { m_portList[alias] = p; + SWSS_LOG_NOTICE("Set port %s fec to %s", alias.c_str(), fec_mode.c_str()); } else { + SWSS_LOG_ERROR("Failed to set port %s fec to %s", alias.c_str(), fec_mode.c_str()); it++; continue; } diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index a3413790b1..0fd3552e19 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -27,7 +27,6 @@ #define PG_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP "PG_DROP_STAT_COUNTER" typedef std::vector PortSupportedSpeeds; -typedef std::set PortSupportedFecModes; static const map oper_status_strings = { @@ -210,8 +209,6 @@ class PortsOrch : public Orch, public Subject unique_ptr m_gbcounterTable; std::map m_portSupportedSpeeds; - // Supported FEC modes on the system side. - std::map m_portSupportedFecModes; bool m_initDone = false; Port m_cpuPort; @@ -308,7 +305,7 @@ class PortsOrch : public Orch, public Subject bool setPortTpid(sai_object_id_t id, sai_uint16_t tpid); bool setPortPvid (Port &port, sai_uint32_t pvid); bool getPortPvid(Port &port, sai_uint32_t &pvid); - bool setPortFec(Port &port, std::string &mode); + bool setPortFec(Port &port, sai_port_fec_mode_t mode); bool setPortPfcAsym(Port &port, string pfc_asym); bool getDestPortId(sai_object_id_t src_port_id, dest_port_type_t port_type, sai_object_id_t &des_port_id); @@ -317,9 +314,6 @@ class PortsOrch : public Orch, public Subject bool isSpeedSupported(const std::string& alias, sai_object_id_t port_id, sai_uint32_t speed); void getPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id, PortSupportedSpeeds &supported_speeds); void initPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id); - // Get supported FEC modes on system side - void getPortSupportedFecModes(const std::string& alias, sai_object_id_t port_id, PortSupportedFecModes &supported_fecmodes); - void initPortSupportedFecModes(const std::string& alias, sai_object_id_t port_id); task_process_status setPortSpeed(Port &port, sai_uint32_t speed); bool getPortSpeed(sai_object_id_t id, sai_uint32_t &speed); bool setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value); diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index ee6ce2b802..172b74b559 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -378,11 +378,10 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy) SWSS_LOG_ERROR( "hwinfo string attribute is too long." ); return SAI_STATUS_FAILURE; } - memset(hwinfo, 0, HWINFO_MAX_SIZE + 1); strncpy(hwinfo, phy->hwinfo.c_str(), phy->hwinfo.length()); attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; - attr.value.s8list.count = (uint32_t) phy->hwinfo.length() + 1; + attr.value.s8list.count = (uint32_t) phy->hwinfo.length(); attr.value.s8list.list = (int8_t *) hwinfo; attrs.push_back(attr); diff --git a/tests/mock_tests/portsorch_ut.cpp b/tests/mock_tests/portsorch_ut.cpp index bf0509c1f7..1fb2537529 100644 --- a/tests/mock_tests/portsorch_ut.cpp +++ b/tests/mock_tests/portsorch_ut.cpp @@ -196,169 +196,6 @@ namespace portsorch_test }; - TEST_F(PortsOrchTest, PortSupportedFecModes) - { - _hook_sai_port_api(); - Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME); - std::deque entries; - - not_support_fetching_fec = false; - // Get SAI default ports to populate DB - auto ports = ut_helper::getInitialSaiPorts(); - - for (const auto &it : ports) - { - portTable.set(it.first, it.second); - } - - // Set PortConfigDone - portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } }); - - // refill consumer - gPortsOrch->addExistingData(&portTable); - - // Apply configuration : - // create ports - static_cast(gPortsOrch)->doTask(); - - uint32_t current_sai_api_call_count = _sai_set_port_fec_count; - - entries.push_back({"Ethernet0", "SET", - { - {"fec", "rs"} - }}); - auto consumer = dynamic_cast(gPortsOrch->getExecutor(APP_PORT_TABLE_NAME)); - consumer->addToSync(entries); - static_cast(gPortsOrch)->doTask(); - entries.clear(); - - ASSERT_EQ(_sai_set_port_fec_count, ++current_sai_api_call_count); - ASSERT_EQ(_sai_port_fec_mode, SAI_PORT_FEC_MODE_RS); - - vector ts; - - gPortsOrch->dumpPendingTasks(ts); - ASSERT_TRUE(ts.empty()); - - entries.push_back({"Ethernet0", "SET", - { - {"fec", "none"} - }}); - consumer = dynamic_cast(gPortsOrch->getExecutor(APP_PORT_TABLE_NAME)); - consumer->addToSync(entries); - static_cast(gPortsOrch)->doTask(); - - ASSERT_EQ(_sai_set_port_fec_count, current_sai_api_call_count); - ASSERT_EQ(_sai_port_fec_mode, SAI_PORT_FEC_MODE_RS); - - gPortsOrch->dumpPendingTasks(ts); - ASSERT_EQ(ts.size(), 0); - - _unhook_sai_port_api(); - } - - /* - * Test case: SAI_PORT_ATTR_SUPPORTED_FEC_MODE is not supported by vendor - **/ - TEST_F(PortsOrchTest, PortNotSupportedFecModes) - { - _hook_sai_port_api(); - Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME); - std::deque entries; - - not_support_fetching_fec = true; - // Get SAI default ports to populate DB - auto ports = ut_helper::getInitialSaiPorts(); - - for (const auto &it : ports) - { - portTable.set(it.first, it.second); - } - - // Set PortConfigDone - portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } }); - - // refill consumer - gPortsOrch->addExistingData(&portTable); - - // Apply configuration : - // create ports - static_cast(gPortsOrch)->doTask(); - - uint32_t current_sai_api_call_count = _sai_set_port_fec_count; - - entries.push_back({"Ethernet0", "SET", - { - {"fec", "rs"} - }}); - auto consumer = dynamic_cast(gPortsOrch->getExecutor(APP_PORT_TABLE_NAME)); - consumer->addToSync(entries); - static_cast(gPortsOrch)->doTask(); - entries.clear(); - - ASSERT_EQ(_sai_set_port_fec_count, ++current_sai_api_call_count); - ASSERT_EQ(_sai_port_fec_mode, SAI_PORT_FEC_MODE_RS); - - vector ts; - - gPortsOrch->dumpPendingTasks(ts); - ASSERT_TRUE(ts.empty()); - - _unhook_sai_port_api(); - } - - /* - * Test case: Fetching SAI_PORT_ATTR_SUPPORTED_FEC_MODE is supported but no FEC mode is supported on the port - **/ - TEST_F(PortsOrchTest, PortSupportNoFecModes) - { - _hook_sai_port_api(); - Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME); - std::deque entries; - - not_support_fetching_fec = false; - auto old_mock_port_fec_modes = mock_port_fec_modes; - mock_port_fec_modes.clear(); - // Get SAI default ports to populate DB - auto ports = ut_helper::getInitialSaiPorts(); - - for (const auto &it : ports) - { - portTable.set(it.first, it.second); - } - - // Set PortConfigDone - portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } }); - - // refill consumer - gPortsOrch->addExistingData(&portTable); - - // Apply configuration : - // create ports - static_cast(gPortsOrch)->doTask(); - - uint32_t current_sai_api_call_count = _sai_set_port_fec_count; - - entries.push_back({"Ethernet0", "SET", - { - {"fec", "rs"} - }}); - auto consumer = dynamic_cast(gPortsOrch->getExecutor(APP_PORT_TABLE_NAME)); - consumer->addToSync(entries); - static_cast(gPortsOrch)->doTask(); - entries.clear(); - - ASSERT_EQ(_sai_set_port_fec_count, current_sai_api_call_count); - - vector ts; - - gPortsOrch->dumpPendingTasks(ts); - ASSERT_TRUE(ts.empty()); - - mock_port_fec_modes = old_mock_port_fec_modes; - _unhook_sai_port_api(); - } - TEST_F(PortsOrchTest, PortReadinessColdBoot) { Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME);