Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vslib] SAI_KEY_VS_OPER_SPEED_IS_CONFIGURED_SPEED, SAI_PORT_ATTR_HOST_TX_READY_STATUS support #1458

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 6 additions & 5 deletions vslib/SwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
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
18 changes: 17 additions & 1 deletion vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
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
Loading