diff --git a/unittest/vslib/TestSwitchConfig.cpp b/unittest/vslib/TestSwitchConfig.cpp index e4382c235..36cd9c624 100644 --- a/unittest/vslib/TestSwitchConfig.cpp +++ b/unittest/vslib/TestSwitchConfig.cpp @@ -67,13 +67,13 @@ TEST(SwitchConfig, parseBootType) EXPECT_EQ(type, SAI_VS_BOOT_TYPE_FAST); } -TEST(SwitchConfig, parseUseTapDevice) +TEST(SwitchConfig, parseBool) { - EXPECT_FALSE(SwitchConfig::parseUseTapDevice(nullptr)); + EXPECT_FALSE(SwitchConfig::parseBool(nullptr)); - EXPECT_FALSE(SwitchConfig::parseUseTapDevice("foo")); + EXPECT_FALSE(SwitchConfig::parseBool("foo")); - EXPECT_FALSE(SwitchConfig::parseUseTapDevice("false")); + EXPECT_FALSE(SwitchConfig::parseBool("false")); - EXPECT_TRUE(SwitchConfig::parseUseTapDevice("true")); + EXPECT_TRUE(SwitchConfig::parseBool("true")); } diff --git a/vslib/Sai.cpp b/vslib/Sai.cpp index 97238f9de..e04c8597e 100644 --- a/vslib/Sai.cpp +++ b/vslib/Sai.cpp @@ -150,10 +150,16 @@ sai_status_t Sai::apiInitialize( const char *use_tap_dev = service_method_table->profile_get_value(0, SAI_KEY_VS_HOSTIF_USE_TAP_DEVICE); - auto useTapDevice = SwitchConfig::parseUseTapDevice(use_tap_dev); + auto useTapDevice = SwitchConfig::parseBool(use_tap_dev); SWSS_LOG_NOTICE("hostif use TAP device: %s", (useTapDevice ? "true" : "false")); + const char *use_configured_speed_as_oper_speed = service_method_table->profile_get_value(0, SAI_KEY_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED); + + auto useConfiguredSpeedAsOperSpeed = SwitchConfig::parseBool(use_configured_speed_as_oper_speed); + + SWSS_LOG_NOTICE("use configured speed as oper speed: %s", (useConfiguredSpeedAsOperSpeed ? "true" : "false")); + auto cstrGlobalContext = service_method_table->profile_get_value(0, SAI_KEY_VS_GLOBAL_CONTEXT); m_globalContext = 0; @@ -218,6 +224,7 @@ sai_status_t Sai::apiInitialize( sc->m_switchType = switchType; sc->m_bootType = bootType; sc->m_useTapDevice = useTapDevice; + sc->m_useConfiguredSpeedAsOperSpeed = useConfiguredSpeedAsOperSpeed; sc->m_laneMap = m_laneMapContainer->getLaneMap(sc->m_switchIndex); if (sc->m_laneMap == nullptr) diff --git a/vslib/SwitchConfig.cpp b/vslib/SwitchConfig.cpp index 88eeebd52..bbb446b54 100644 --- a/vslib/SwitchConfig.cpp +++ b/vslib/SwitchConfig.cpp @@ -141,14 +141,14 @@ bool SwitchConfig::parseBootType( return true; } -bool SwitchConfig::parseUseTapDevice( - _In_ const char* useTapDeviceStr) +bool SwitchConfig::parseBool( + _In_ const char* str) { SWSS_LOG_ENTER(); - if (useTapDeviceStr) + if (str) { - return strcmp(useTapDeviceStr, "true") == 0; + return strcmp(str, "true") == 0; } return false; diff --git a/vslib/SwitchConfig.h b/vslib/SwitchConfig.h index 8509eabf3..b22a0963d 100644 --- a/vslib/SwitchConfig.h +++ b/vslib/SwitchConfig.h @@ -64,8 +64,8 @@ namespace saivs _In_ const char* bootTypeStr, _Out_ sai_vs_boot_type_t& bootType); - static bool parseUseTapDevice( - _In_ const char* useTapDeviceStr); + static bool parseBool( + _In_ const char* boolStr); public: @@ -81,6 +81,8 @@ namespace saivs bool m_useTapDevice; + bool m_useConfiguredSpeedAsOperSpeed; + std::shared_ptr m_laneMap; std::shared_ptr m_fabricLaneMap; diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 8fa4d7761..fc1f46e59 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -2260,7 +2260,12 @@ sai_status_t SwitchStateBase::refresh_port_oper_speed( } else { - if (!vs_get_oper_speed(port_id, attr.value.u32)) + if (m_switchConfig->m_useConfiguredSpeedAsOperSpeed) + { + attr.id = SAI_PORT_ATTR_SPEED; + CHECK_STATUS(get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr)); + } + else if (!vs_get_oper_speed(port_id, attr.value.u32)) { return SAI_STATUS_FAILURE; } diff --git a/vslib/saivs.h b/vslib/saivs.h index a68da6e84..62c3d59dd 100644 --- a/vslib/saivs.h +++ b/vslib/saivs.h @@ -56,6 +56,16 @@ extern "C" { */ #define SAI_KEY_VS_HOSTIF_USE_TAP_DEVICE "SAI_VS_HOSTIF_USE_TAP_DEVICE" +/** + * @def SAI_KEY_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED + * + * Bool flag, (true/false). If set to true, SAI_PORT_ATTR_OPER_SPEED returns + * the SAI_PORT_ATTR_SPEED instead of querying the speed of veth + * + * By default this flag is set to false. + */ +#define SAI_KEY_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED "SAI_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED" + /** * @def SAI_KEY_VS_CORE_PORT_INDEX_MAP_FILE *