Skip to content

Commit 68a3c0c

Browse files
authored
[vslib] SAI_KEY_VS_OPER_SPEED_IS_CONFIGURED_SPEED, SAI_PORT_ATTR_HOST_TX_READY_STATUS support (#1458)
This PR adds two features to vslib. SAI_KEY_VS_OPER_SPEED_IS_CONFIGURED_SPEED: when true, SAI_PORT_ATTR_SPEED returns the configured speed instead of the value retrieved via /sys/class/net/<name>/speed. fixes Subinterface doesn't inherit the speed of ancestors on kvm testbed. sonic-buildimage#19735 SAI_PORT_ATTR_HOST_TX_READY_STATUS: always returns true. Required to support running xcvrd in the VS env. ref: https://github.com/sonic-net/SONiC/pull/1849/files#diff-6f3e95e6c57a3edc2e30e1f13edb9fd9a32a0db44e1035ac1f0b1b9a191762a5R46
1 parent e212a87 commit 68a3c0c

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

unittest/vslib/TestSwitchConfig.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ TEST(SwitchConfig, parseBootType)
6767
EXPECT_EQ(type, SAI_VS_BOOT_TYPE_FAST);
6868
}
6969

70-
TEST(SwitchConfig, parseUseTapDevice)
70+
TEST(SwitchConfig, parseBool)
7171
{
72-
EXPECT_FALSE(SwitchConfig::parseUseTapDevice(nullptr));
72+
EXPECT_FALSE(SwitchConfig::parseBool(nullptr));
7373

74-
EXPECT_FALSE(SwitchConfig::parseUseTapDevice("foo"));
74+
EXPECT_FALSE(SwitchConfig::parseBool("foo"));
7575

76-
EXPECT_FALSE(SwitchConfig::parseUseTapDevice("false"));
76+
EXPECT_FALSE(SwitchConfig::parseBool("false"));
7777

78-
EXPECT_TRUE(SwitchConfig::parseUseTapDevice("true"));
78+
EXPECT_TRUE(SwitchConfig::parseBool("true"));
7979
}

vslib/Sai.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,16 @@ sai_status_t Sai::apiInitialize(
150150

151151
const char *use_tap_dev = service_method_table->profile_get_value(0, SAI_KEY_VS_HOSTIF_USE_TAP_DEVICE);
152152

153-
auto useTapDevice = SwitchConfig::parseUseTapDevice(use_tap_dev);
153+
auto useTapDevice = SwitchConfig::parseBool(use_tap_dev);
154154

155155
SWSS_LOG_NOTICE("hostif use TAP device: %s", (useTapDevice ? "true" : "false"));
156156

157+
const char *use_configured_speed_as_oper_speed = service_method_table->profile_get_value(0, SAI_KEY_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED);
158+
159+
auto useConfiguredSpeedAsOperSpeed = SwitchConfig::parseBool(use_configured_speed_as_oper_speed);
160+
161+
SWSS_LOG_NOTICE("use configured speed as oper speed: %s", (useConfiguredSpeedAsOperSpeed ? "true" : "false"));
162+
157163
auto cstrGlobalContext = service_method_table->profile_get_value(0, SAI_KEY_VS_GLOBAL_CONTEXT);
158164

159165
m_globalContext = 0;
@@ -218,6 +224,7 @@ sai_status_t Sai::apiInitialize(
218224
sc->m_switchType = switchType;
219225
sc->m_bootType = bootType;
220226
sc->m_useTapDevice = useTapDevice;
227+
sc->m_useConfiguredSpeedAsOperSpeed = useConfiguredSpeedAsOperSpeed;
221228
sc->m_laneMap = m_laneMapContainer->getLaneMap(sc->m_switchIndex);
222229

223230
if (sc->m_laneMap == nullptr)

vslib/SwitchConfig.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ SwitchConfig::SwitchConfig(
1717
m_bootType(SAI_VS_BOOT_TYPE_COLD),
1818
m_switchIndex(switchIndex),
1919
m_hardwareInfo(hwinfo),
20-
m_useTapDevice(false)
20+
m_useTapDevice(false),
21+
m_useConfiguredSpeedAsOperSpeed(false)
2122
{
2223
SWSS_LOG_ENTER();
2324

@@ -141,14 +142,14 @@ bool SwitchConfig::parseBootType(
141142
return true;
142143
}
143144

144-
bool SwitchConfig::parseUseTapDevice(
145-
_In_ const char* useTapDeviceStr)
145+
bool SwitchConfig::parseBool(
146+
_In_ const char* str)
146147
{
147148
SWSS_LOG_ENTER();
148149

149-
if (useTapDeviceStr)
150+
if (str)
150151
{
151-
return strcmp(useTapDeviceStr, "true") == 0;
152+
return strcmp(str, "true") == 0;
152153
}
153154

154155
return false;

vslib/SwitchConfig.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ namespace saivs
6464
_In_ const char* bootTypeStr,
6565
_Out_ sai_vs_boot_type_t& bootType);
6666

67-
static bool parseUseTapDevice(
68-
_In_ const char* useTapDeviceStr);
67+
static bool parseBool(
68+
_In_ const char* boolStr);
6969

7070
public:
7171

@@ -81,6 +81,8 @@ namespace saivs
8181

8282
bool m_useTapDevice;
8383

84+
bool m_useConfiguredSpeedAsOperSpeed;
85+
8486
std::shared_ptr<LaneMap> m_laneMap;
8587

8688
std::shared_ptr<LaneMap> m_fabricLaneMap;

vslib/SwitchStateBase.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,11 @@ sai_status_t SwitchStateBase::create_ports()
13131313
attr.value.u32 = DEFAULT_VLAN_NUMBER;
13141314

13151315
CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
1316+
1317+
attr.id = SAI_PORT_ATTR_HOST_TX_READY_STATUS;
1318+
attr.value.u32 = SAI_PORT_HOST_TX_READY_STATUS_READY;
1319+
1320+
CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
13161321
}
13171322

13181323
return SAI_STATUS_SUCCESS;
@@ -1778,6 +1783,11 @@ sai_status_t SwitchStateBase::create_port_dependencies(
17781783

17791784
CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
17801785

1786+
attr.id = SAI_PORT_ATTR_HOST_TX_READY_STATUS;
1787+
attr.value.u32 = SAI_PORT_HOST_TX_READY_STATUS_READY;
1788+
1789+
CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr));
1790+
17811791
// attributes are not required since they will be set outside this function
17821792

17831793
CHECK_STATUS(create_ingress_priority_groups_per_port(port_id));
@@ -2339,7 +2349,12 @@ sai_status_t SwitchStateBase::refresh_port_oper_speed(
23392349
}
23402350
else
23412351
{
2342-
if (!vs_get_oper_speed(port_id, attr.value.u32))
2352+
if (m_switchConfig->m_useConfiguredSpeedAsOperSpeed)
2353+
{
2354+
attr.id = SAI_PORT_ATTR_SPEED;
2355+
CHECK_STATUS(get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr));
2356+
}
2357+
else if (!vs_get_oper_speed(port_id, attr.value.u32))
23432358
{
23442359
return SAI_STATUS_FAILURE;
23452360
}
@@ -2499,6 +2514,7 @@ sai_status_t SwitchStateBase::refresh_read_only(
24992514
*/
25002515

25012516
case SAI_PORT_ATTR_OPER_STATUS:
2517+
case SAI_PORT_ATTR_HOST_TX_READY_STATUS:
25022518
return SAI_STATUS_SUCCESS;
25032519

25042520
case SAI_PORT_ATTR_FABRIC_ATTACHED:

vslib/saivs.h

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ extern "C" {
5656
*/
5757
#define SAI_KEY_VS_HOSTIF_USE_TAP_DEVICE "SAI_VS_HOSTIF_USE_TAP_DEVICE"
5858

59+
/**
60+
* @def SAI_KEY_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED
61+
*
62+
* Bool flag, (true/false). If set to true, SAI_PORT_ATTR_OPER_SPEED returns
63+
* the SAI_PORT_ATTR_SPEED instead of querying the speed of veth
64+
*
65+
* By default this flag is set to false.
66+
*/
67+
#define SAI_KEY_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED "SAI_VS_USE_CONFIGURED_SPEED_AS_OPER_SPEED"
68+
5969
/**
6070
* @def SAI_KEY_VS_CORE_PORT_INDEX_MAP_FILE
6171
*

0 commit comments

Comments
 (0)