diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index f3418d2a66..a044bf4938 100755 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -3734,7 +3734,7 @@ void AclOrch::init(vector& connectors, PortsOrch *portOrch, Mirr string platform = getenv("platform") ? getenv("platform") : ""; string sub_platform = getenv("sub_platform") ? getenv("sub_platform") : ""; if (platform == BRCM_PLATFORM_SUBSTRING || - platform == CISCO_8000_PLATFORM_SUBSTRING || + isCiscoPlatform(platform) || platform == MLNX_PLATFORM_SUBSTRING || platform == BFN_PLATFORM_SUBSTRING || platform == MRVL_PRST_PLATFORM_SUBSTRING || @@ -3793,7 +3793,7 @@ void AclOrch::init(vector& connectors, PortsOrch *portOrch, Mirr // In Mellanox platform, V4 and V6 rules are stored in different tables // In Broadcom DNX platform also, V4 and V6 rules are stored in different tables if (platform == MLNX_PLATFORM_SUBSTRING || - platform == CISCO_8000_PLATFORM_SUBSTRING || + isCiscoPlatform(platform) || platform == MRVL_PRST_PLATFORM_SUBSTRING || platform == XS_PLATFORM_SUBSTRING || platform == CLX_PLATFORM_SUBSTRING || diff --git a/orchagent/orch.h b/orchagent/orch.h index c1d8bb7222..00b155e295 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -47,9 +47,16 @@ const char state_db_key_delimiter = '|'; #define VS_PLATFORM_SUBSTRING "vs" #define NPS_PLATFORM_SUBSTRING "nephos" #define CISCO_8000_PLATFORM_SUBSTRING "cisco-8000" +#define CISCO_PLATFORM_SUBSTRING "cisco" #define XS_PLATFORM_SUBSTRING "xsight" #define CLX_PLATFORM_SUBSTRING "clounix" +inline bool isCiscoPlatform(const std::string &platform) +{ + return platform == CISCO_8000_PLATFORM_SUBSTRING || + platform == CISCO_PLATFORM_SUBSTRING; +} + #define CONFIGDB_KEY_SEPARATOR "|" #define DEFAULT_KEY_SEPARATOR ":" #define VLAN_SUB_INTERFACE_SEPARATOR "." diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 9a31f05271..d68a98cd7f 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -844,7 +844,7 @@ bool OrchDaemon::init() queueAttrIds, PFC_WD_POLL_MSECS)); } - } else if (platform == CISCO_8000_PLATFORM_SUBSTRING) + } else if (isCiscoPlatform(platform)) { static const vector portStatIds = { diff --git a/orchagent/pfcactionhandler.cpp b/orchagent/pfcactionhandler.cpp index 32f984cea1..2392828401 100644 --- a/orchagent/pfcactionhandler.cpp +++ b/orchagent/pfcactionhandler.cpp @@ -545,7 +545,7 @@ PfcWdLossyHandler::PfcWdLossyHandler(sai_object_id_t port, sai_object_id_t queue SWSS_LOG_ENTER(); string platform = getenv("platform") ? getenv("platform") : ""; - if (platform == CISCO_8000_PLATFORM_SUBSTRING || ((platform == BRCM_PLATFORM_SUBSTRING) && (gSwitchOrch->checkPfcDlrInitEnable()))) + if (isCiscoPlatform(platform) || ((platform == BRCM_PLATFORM_SUBSTRING) && (gSwitchOrch->checkPfcDlrInitEnable()))) { SWSS_LOG_DEBUG("Skipping in constructor PfcWdLossyHandler for platform %s on port 0x%" PRIx64, platform.c_str(), port); @@ -572,7 +572,7 @@ PfcWdLossyHandler::~PfcWdLossyHandler(void) SWSS_LOG_ENTER(); string platform = getenv("platform") ? getenv("platform") : ""; - if (platform == CISCO_8000_PLATFORM_SUBSTRING || ((platform == BRCM_PLATFORM_SUBSTRING) && (gSwitchOrch->checkPfcDlrInitEnable()))) + if (isCiscoPlatform(platform) || ((platform == BRCM_PLATFORM_SUBSTRING) && (gSwitchOrch->checkPfcDlrInitEnable()))) { SWSS_LOG_DEBUG("Skipping in destructor PfcWdLossyHandler for platform %s on port 0x%" PRIx64, platform.c_str(), getPort()); diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index 8aefd244f3..09ce385ff6 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -230,7 +230,7 @@ task_process_status PfcWdOrch::createEntry(const st SWSS_LOG_ERROR("Invalid PFC Watchdog action %s", value.c_str()); return task_process_status::task_invalid_entry; } - if ((m_platform == CISCO_8000_PLATFORM_SUBSTRING) && (action == PfcWdAction::PFC_WD_ACTION_FORWARD)) { + if (isCiscoPlatform(m_platform) && (action == PfcWdAction::PFC_WD_ACTION_FORWARD)) { SWSS_LOG_ERROR("Unsupported action %s for platform %s", value.c_str(), m_platform.c_str()); return task_process_status::task_invalid_entry; } @@ -711,12 +711,13 @@ PfcWdSwOrch::PfcWdSwOrch( SWSS_LOG_ENTER(); string detectSha, restoreSha; - string detectPluginName = "pfc_detect_" + this->m_platform + ".lua"; + string pluginPlatform = getPfcWdPluginPlatform(this->m_platform); + string detectPluginName = "pfc_detect_" + pluginPlatform + ".lua"; string restorePluginName; string pollIntervalStr = to_string(m_pollInterval); string plugins; - if (this->m_platform == CISCO_8000_PLATFORM_SUBSTRING) { - restorePluginName = "pfc_restore_" + this->m_platform + ".lua"; + if (isCiscoPlatform(this->m_platform)) { + restorePluginName = "pfc_restore_" + pluginPlatform + ".lua"; } else { restorePluginName = "pfc_restore.lua"; } diff --git a/orchagent/pfcwdorch.h b/orchagent/pfcwdorch.h index 69ed9ecfcc..2502f95f47 100644 --- a/orchagent/pfcwdorch.h +++ b/orchagent/pfcwdorch.h @@ -17,6 +17,11 @@ extern "C" { const string pfc_wd_flex_counter_group = PFC_WD_FLEX_COUNTER_GROUP; +inline std::string getPfcWdPluginPlatform(const std::string &platform) +{ + return isCiscoPlatform(platform) ? CISCO_8000_PLATFORM_SUBSTRING : platform; +} + enum class PfcWdAction { PFC_WD_ACTION_UNKNOWN, diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index 157416d96c..d25c3dd10b 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -29,6 +29,7 @@ LDADD_GTEST = -L/usr/src/gtest tests_INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib -I$(top_srcdir)/cfgmgr -I$(top_srcdir)/orchagent -I$(P4_ORCH_DIR)/tests -I$(DASH_ORCH_DIR) -I$(top_srcdir)/warmrestart tests_SOURCES = aclorch_ut.cpp \ + pfcwdorch_ut.cpp \ aclorch_rule_ut.cpp \ portsorch_ut.cpp \ routeorch_ut.cpp \ diff --git a/tests/mock_tests/pfcwdorch_ut.cpp b/tests/mock_tests/pfcwdorch_ut.cpp new file mode 100644 index 0000000000..2985053524 --- /dev/null +++ b/tests/mock_tests/pfcwdorch_ut.cpp @@ -0,0 +1,14 @@ +#include "pfcwdorch.h" + +#include + +TEST(PfcWdPlatformTest, MapsCiscoNamesToExistingPlugin) +{ + EXPECT_EQ(getPfcWdPluginPlatform("cisco-8000"), "cisco-8000"); + EXPECT_EQ(getPfcWdPluginPlatform("cisco"), "cisco-8000"); +} + +TEST(PfcWdPlatformTest, PreservesOtherPlatformNames) +{ + EXPECT_EQ(getPfcWdPluginPlatform("broadcom"), "broadcom"); +}