|
4 | 4 | #include "meta/sai_serialize.h" |
5 | 5 |
|
6 | 6 | #include <net/if.h> |
| 7 | +#include <unistd.h> |
7 | 8 |
|
8 | 9 | #include <algorithm> |
9 | 10 |
|
@@ -1120,7 +1121,14 @@ sai_status_t SwitchStateBase::create_ports() |
1120 | 1121 | return SAI_STATUS_FAILURE; |
1121 | 1122 | } |
1122 | 1123 |
|
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 | + } |
1124 | 1132 |
|
1125 | 1133 | uint32_t port_count = (uint32_t)lanesVector.size(); |
1126 | 1134 |
|
@@ -2939,6 +2947,49 @@ sai_status_t SwitchStateBase::initialize_voq_switch_objects( |
2939 | 2947 | return SAI_STATUS_SUCCESS; |
2940 | 2948 | } |
2941 | 2949 |
|
| 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 | + |
2942 | 2993 | sai_status_t SwitchStateBase::create_system_ports( |
2943 | 2994 | _In_ int32_t voq_switch_id, |
2944 | 2995 | _In_ uint32_t sys_port_count, |
|
0 commit comments