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..510c1af0f 100644 --- a/vslib/SwitchConfig.cpp +++ b/vslib/SwitchConfig.cpp @@ -17,7 +17,8 @@ SwitchConfig::SwitchConfig( m_bootType(SAI_VS_BOOT_TYPE_COLD), m_switchIndex(switchIndex), m_hardwareInfo(hwinfo), - m_useTapDevice(false) + m_useTapDevice(false), + m_useConfiguredSpeedAsOperSpeed(false) { SWSS_LOG_ENTER(); @@ -141,14 +142,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..0cf5fcb6d 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -1235,6 +1235,11 @@ sai_status_t SwitchStateBase::create_ports() attr.value.u32 = DEFAULT_VLAN_NUMBER; CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr)); + + attr.id = SAI_PORT_ATTR_HOST_TX_READY_STATUS; + attr.value.u32 = SAI_PORT_HOST_TX_READY_STATUS_READY; + + CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr)); } return SAI_STATUS_SUCCESS; @@ -1699,6 +1704,11 @@ sai_status_t SwitchStateBase::create_port_dependencies( CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr)); + attr.id = SAI_PORT_ATTR_HOST_TX_READY_STATUS; + attr.value.u32 = SAI_PORT_HOST_TX_READY_STATUS_READY; + + CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr)); + // attributes are not required since they will be set outside this function CHECK_STATUS(create_ingress_priority_groups_per_port(port_id)); @@ -2260,7 +2270,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; } @@ -2420,6 +2435,7 @@ sai_status_t SwitchStateBase::refresh_read_only( */ case SAI_PORT_ATTR_OPER_STATUS: + case SAI_PORT_ATTR_HOST_TX_READY_STATUS: return SAI_STATUS_SUCCESS; case SAI_PORT_ATTR_FABRIC_ATTACHED: 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 *