Skip to content

Commit

Permalink
vslib: add SAI_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED option
Browse files Browse the repository at this point in the history
Signed-off-by: Wataru Ishida <[email protected]>
  • Loading branch information
ishidawataru committed Nov 14, 2024
1 parent 866985f commit 9c1e265
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
10 changes: 5 additions & 5 deletions unittest/vslib/TestSwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
9 changes: 8 additions & 1 deletion vslib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions vslib/SwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions vslib/SwitchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -81,6 +81,8 @@ namespace saivs

bool m_useTapDevice;

bool m_useConfiguredSpeedAsOperSpeed;

std::shared_ptr<LaneMap> m_laneMap;

std::shared_ptr<LaneMap> m_fabricLaneMap;
Expand Down
7 changes: 6 additions & 1 deletion vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions vslib/saivs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 9c1e265

Please sign in to comment.