Skip to content

Commit

Permalink
Add support for any number of ports in virtual switch using lane map (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Jan 9, 2019
1 parent 60f97c3 commit b1b739b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 112 deletions.
4 changes: 4 additions & 0 deletions vslib/inc/sai_vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ extern const char *g_interface_lane_map_file;
extern std::map<uint32_t,std::string> g_lane_to_ifname;
extern std::map<std::string,std::vector<uint32_t>> g_ifname_to_lanes;
extern std::vector<uint32_t> g_lane_order;
extern std::vector<std::vector<uint32_t>> g_laneMap;

extern void getPortLaneMap(
_Inout_ std::vector<std::vector<uint32_t>> &laneMap);

extern const sai_acl_api_t vs_acl_api;
extern const sai_bfd_api_t vs_bfd_api;
Expand Down
79 changes: 79 additions & 0 deletions vslib/src/sai_vs_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int g_vs_boot_type = SAI_VS_COLD_BOOT;
std::map<uint32_t,std::string> g_lane_to_ifname;
std::map<std::string,std::vector<uint32_t>> g_ifname_to_lanes;
std::vector<uint32_t> g_lane_order;
std::vector<std::vector<uint32_t>> g_laneMap;

const char *g_boot_type = NULL;
const char *g_warm_boot_read_file = NULL;
Expand Down Expand Up @@ -604,11 +605,89 @@ void load_interface_lane_map()
}

g_ifname_to_lanes[ifname] = lanevec;
g_laneMap.push_back(lanevec);
}

SWSS_LOG_NOTICE("loaded %zu lanes and %zu interfaces", g_lane_to_ifname.size(), g_ifname_to_lanes.size());
}

void getPortLaneMap(
_Inout_ std::vector<std::vector<uint32_t>> &laneMap)
{
SWSS_LOG_ENTER();

laneMap.clear();

for (auto v: g_laneMap)
{
size_t s = v.size();

if (s != 1 && s != 2 && s != 4)
{
SWSS_LOG_THROW("invald number of lanes for interface: %zu", s);
}

laneMap.push_back(v);
}

if (g_laneMap.size())
{
SWSS_LOG_NOTICE("got port lane map with %zu interfaces", laneMap.size());
return;
}

const uint32_t default_port_count = 32;

sai_uint32_t default_lanes[] = {
29,30,31,32,
25,26,27,28,
37,38,39,40,
33,34,35,36,
41,42,43,44,
45,46,47,48,
5,6,7,8,
1,2,3,4,
9,10,11,12,
13,14,15,16,
21,22,23,24,
17,18,19,20,
49,50,51,52,
53,54,55,56,
61,62,63,64,
57,58,59,60,
65,66,67,68,
69,70,71,72,
77,78,79,80,
73,74,75,76,
105,106,107,108,
109,110,111,112,
117,118,119,120,
113,114,115,116,
121,122,123,124,
125,126,127,128,
85,86,87,88,
81,82,83,84,
89,90,91,92,
93,94,95,96,
97,98,99,100,
101,102,103,104
};

// populate default lane map

for (size_t i = 0; i < default_port_count; i++)
{
std::vector<uint32_t> portLanes;

for(int j = 0; j < 4; j++)
portLanes.push_back(default_lanes[4*i + j]);

laneMap.push_back(portLanes);
}

SWSS_LOG_NOTICE("populated default port lane map with %zu interfaces", laneMap.size());
}

sai_status_t sai_api_initialize(
_In_ uint64_t flags,
_In_ const sai_service_method_table_t *service_method_table)
Expand Down
63 changes: 8 additions & 55 deletions vslib/src/sai_vs_switch_BCM56850.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,62 +145,13 @@ static sai_status_t create_ports()
{
SWSS_LOG_ENTER();

// TODO currently port information is hardcoded
// but later on we can read this from config file

const uint32_t port_count = 32;

SWSS_LOG_INFO("create ports");

sai_uint32_t lanes[] = {
29,30,31,32,
25,26,27,28,
37,38,39,40,
33,34,35,36,
41,42,43,44,
45,46,47,48,
5,6,7,8,
1,2,3,4,
9,10,11,12,
13,14,15,16,
21,22,23,24,
17,18,19,20,
49,50,51,52,
53,54,55,56,
61,62,63,64,
57,58,59,60,
65,66,67,68,
69,70,71,72,
77,78,79,80,
73,74,75,76,
105,106,107,108,
109,110,111,112,
117,118,119,120,
113,114,115,116,
121,122,123,124,
125,126,127,128,
85,86,87,88,
81,82,83,84,
89,90,91,92,
93,94,95,96,
97,98,99,100,
101,102,103,104
};

if (g_lane_order.size() != port_count * 4)
{
SWSS_LOG_ERROR("only supported lane count is %d, using default", port_count * 4);
}
else if (g_ifname_to_lanes.size() != port_count)
{
SWSS_LOG_ERROR("only supported interface count is %d, using default", port_count);
}
else
{
SWSS_LOG_NOTICE("replacing lane numbers from %s", g_interface_lane_map_file);
std::vector<std::vector<uint32_t>> laneMap;

memcpy(lanes, g_lane_order.data(), port_count * 4);
}
getPortLaneMap(laneMap);

uint32_t port_count = (uint32_t)laneMap.size();

port_list.clear();

Expand All @@ -223,9 +174,11 @@ static sai_status_t create_ports()

CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));

std::vector<uint32_t> lanes = laneMap.at(i);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = 4;
attr.value.u32list.list = &lanes[4 * i];
attr.value.u32list.count = (uint32_t)lanes.size();
attr.value.u32list.list = lanes.data();

CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));

Expand Down
65 changes: 8 additions & 57 deletions vslib/src/sai_vs_switch_MLNX2700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,64 +142,13 @@ static sai_status_t create_ports()
{
SWSS_LOG_ENTER();

/*
* TODO currently port information is hardcoded but later on we can read
* this from profile.ini and use correct lane mapping.
*/

const uint32_t port_count = 32;

SWSS_LOG_INFO("create ports");

sai_uint32_t lanes[] = {
64,65,66,67,
68,69,70,71,
72,73,74,75,
76,77,78,79,
80,81,82,83,
84,85,86,87,
88,89,90,91,
92,93,94,95,
96,97,98,99,
100,101,102,103,
104,105,106,107,
108,109,110,111,
112,113,114,115,
116,117,118,119,
120,121,122,123,
124,125,126,127,
56,57,58,59,
60,61,62,63,
48,49,50,51,
52,53,54,55,
40,41,42,43,
44,45,46,47,
32,33,34,35,
36,37,38,39,
24,25,26,27,
28,29,30,31,
16,17,18,19,
20,21,22,23,
8,9,10,11,
12,13,14,15,
0,1,2,3,
4,5,6,7,
};

if (g_lane_order.size() != port_count * 4)
{
SWSS_LOG_ERROR("only supported lane count is %d, using default", port_count * 4);
}
else if (g_ifname_to_lanes.size() != port_count)
{
SWSS_LOG_ERROR("only supported interface count is %d, using default", port_count);
}
else
{
SWSS_LOG_NOTICE("replacing lane numbers from %s", g_interface_lane_map_file);
std::vector<std::vector<uint32_t>> laneMap;

memcpy(lanes, g_lane_order.data(), port_count * 4);
}
getPortLaneMap(laneMap);

uint32_t port_count = (uint32_t)laneMap.size();

port_list.clear();

Expand All @@ -222,9 +171,11 @@ static sai_status_t create_ports()

CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));

std::vector<uint32_t> lanes = laneMap.at(i);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = 4;
attr.value.u32list.list = &lanes[4 * i];
attr.value.u32list.count = (uint32_t)lanes.size();
attr.value.u32list.list = lanes.data();

CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_PORT, port_id, &attr));

Expand Down

0 comments on commit b1b739b

Please sign in to comment.