Skip to content

Commit db403f4

Browse files
authored
[vslib]: Remove invalid lane when create ports (#938)
* [vslib]: Remove invalid lane when create ports Signed-off-by: Ze Gan <[email protected]> * refactor function Signed-off-by: Ze Gan <[email protected]>
1 parent 6df04d8 commit db403f4

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

vslib/SwitchStateBase.cpp

+52-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "meta/sai_serialize.h"
55

66
#include <net/if.h>
7+
#include <unistd.h>
78

89
#include <algorithm>
910

@@ -1120,7 +1121,14 @@ sai_status_t SwitchStateBase::create_ports()
11201121
return SAI_STATUS_FAILURE;
11211122
}
11221123

1123-
auto& lanesVector = map->getLaneVector();
1124+
auto lanesVector = map->getLaneVector();
1125+
1126+
if (m_switchConfig->m_useTapDevice)
1127+
{
1128+
SWSS_LOG_DEBUG("Check available lane");
1129+
1130+
CHECK_STATUS(filter_available_lanes(lanesVector));
1131+
}
11241132

11251133
uint32_t port_count = (uint32_t)lanesVector.size();
11261134

@@ -2939,6 +2947,49 @@ sai_status_t SwitchStateBase::initialize_voq_switch_objects(
29392947
return SAI_STATUS_SUCCESS;
29402948
}
29412949

2950+
sai_status_t SwitchStateBase::filter_available_lanes(
2951+
_Inout_ std::vector<std::vector<uint32_t>> &lanes_vector)
2952+
{
2953+
SWSS_LOG_ENTER();
2954+
2955+
auto lanes = lanes_vector.begin();
2956+
2957+
while (lanes != lanes_vector.end())
2958+
{
2959+
bool available_lane = false;
2960+
2961+
for (auto lane: *lanes)
2962+
{
2963+
std::string ifname = m_switchConfig->m_laneMap->getInterfaceFromLaneNumber(lane);
2964+
std::string path = std::string("/sys/class/net/") + ifname + "/operstate";
2965+
2966+
if (access(path.c_str(), F_OK) != 0)
2967+
{
2968+
SWSS_LOG_WARN("Port %s isn't available", ifname.c_str());
2969+
2970+
available_lane &= false;
2971+
2972+
break;
2973+
}
2974+
else
2975+
{
2976+
available_lane = true;
2977+
}
2978+
}
2979+
2980+
if (!available_lane)
2981+
{
2982+
lanes = lanes_vector.erase(lanes);
2983+
}
2984+
else
2985+
{
2986+
lanes++;
2987+
}
2988+
}
2989+
2990+
return SAI_STATUS_SUCCESS;
2991+
}
2992+
29422993
sai_status_t SwitchStateBase::create_system_ports(
29432994
_In_ int32_t voq_switch_id,
29442995
_In_ uint32_t sys_port_count,

vslib/SwitchStateBase.h

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ namespace saivs
9898
_In_ sai_switch_attr_t acl_resource,
9999
_In_ int max_count);
100100

101+
sai_status_t filter_available_lanes(
102+
_Inout_ std::vector<std::vector<uint32_t>> &lanes_vector);
103+
101104
sai_status_t create_system_ports(
102105
_In_ int32_t voq_switch_id,
103106
_In_ uint32_t sys_port_count,

0 commit comments

Comments
 (0)