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

Add fabric port test to vslib. #737

Merged
merged 2 commits into from
Jan 12, 2021
Merged
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
2 changes: 2 additions & 0 deletions vslib/inc/Sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ namespace saivs

std::shared_ptr<LaneMapContainer> m_laneMapContainer;

std::shared_ptr<LaneMapContainer> m_fabricLaneMapContainer;

std::shared_ptr<ResourceLimiterContainer> m_resourceLimiterContainer;

std::shared_ptr<CorePortIndexMapContainer> m_corePortIndexMapContainer;
Expand Down
2 changes: 2 additions & 0 deletions vslib/inc/SwitchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace saivs

std::shared_ptr<LaneMap> m_laneMap;

std::shared_ptr<LaneMap> m_fabricLaneMap;

std::shared_ptr<EventQueue> m_eventQueue;

std::shared_ptr<ResourceLimiter> m_resourceLimiter;
Expand Down
6 changes: 6 additions & 0 deletions vslib/inc/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ namespace saivs

virtual sai_status_t set_port_list();

virtual sai_status_t create_fabric_ports();

virtual sai_status_t set_fabric_port_list();

virtual sai_status_t create_default_virtual_router();

virtual sai_status_t create_default_stp_instance();
Expand Down Expand Up @@ -565,6 +569,8 @@ namespace saivs
std::vector<sai_object_id_t> m_port_list;
std::vector<sai_object_id_t> m_bridge_port_list_port_based;

std::vector<sai_object_id_t> m_fabric_port_list;

std::vector<sai_acl_action_type_t> m_ingress_acl_action_list;
std::vector<sai_acl_action_type_t> m_egress_acl_action_list;

Expand Down
12 changes: 12 additions & 0 deletions vslib/inc/saivs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ extern "C" {
*/
#define SAI_KEY_VS_RESOURCE_LIMITER_FILE "SAI_VS_RESOURCE_LIMITER_FILE"

/**
* @def SAI_KEY_VS_INTERFACE_FABRIC_LANE_MAP_FILE
*
* If specified in profile.ini it should point to fabric port to lane map.
*
* Example:
* fabric0:1
* fabric1:2
*
*/
#define SAI_KEY_VS_INTERFACE_FABRIC_LANE_MAP_FILE "SAI_VS_INTERFACE_FABRIC_LANE_MAP_FILE"

/**
* @def SAI_KEY_VS_HOSTIF_USE_TAP_DEVICE
*
Expand Down
10 changes: 10 additions & 0 deletions vslib/src/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ sai_status_t Sai::initialize(

m_laneMapContainer = LaneMapFileParser::parseLaneMapFile(laneMapFile);

auto *fabricLaneMapFile = service_method_table->profile_get_value(0, SAI_KEY_VS_INTERFACE_FABRIC_LANE_MAP_FILE);
if (fabricLaneMapFile)
{
m_fabricLaneMapContainer = LaneMapFileParser::parseLaneMapFile(fabricLaneMapFile);
}

auto *corePortIndexMapFile = service_method_table->profile_get_value(0, SAI_KEY_VS_CORE_PORT_INDEX_MAP_FILE);

m_corePortIndexMapContainer = CorePortIndexMapFileParser::parseCorePortIndexMapFile(corePortIndexMapFile);
Expand Down Expand Up @@ -157,6 +163,10 @@ sai_status_t Sai::initialize(
sc->m_switchIndex = 0;
sc->m_useTapDevice = useTapDevice;
sc->m_laneMap = m_laneMapContainer->getLaneMap(sc->m_switchIndex);
if (m_fabricLaneMapContainer)
{
sc->m_fabricLaneMap = m_fabricLaneMapContainer->getLaneMap(sc->m_switchIndex);
}
sc->m_eventQueue = m_eventQueue;
sc->m_resourceLimiter = m_resourceLimiterContainer->getResourceLimiter(sc->m_switchIndex);
sc->m_corePortIndexMap = m_corePortIndexMapContainer->getCorePortIndexMap(sc->m_switchIndex);
Expand Down
95 changes: 95 additions & 0 deletions vslib/src/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,9 @@ sai_status_t SwitchStateBase::refresh_port_list(

const sai_object_id_t cpu_port_id = attr.value.oid;

std::unordered_set<sai_object_id_t> fabric_port_set(m_fabric_port_list.begin(),
m_fabric_port_list.end());

m_port_list.clear();

// iterate via ASIC state to find all the ports
Expand All @@ -1781,6 +1784,10 @@ sai_status_t SwitchStateBase::refresh_port_list(
if (port_id == cpu_port_id)
continue;

// don't put fabric ports on the list
if (fabric_port_set.find(port_id) != fabric_port_set.end())
kcudnik marked this conversation as resolved.
Show resolved Hide resolved
continue;

m_port_list.push_back(port_id);
}

Expand Down Expand Up @@ -1905,6 +1912,10 @@ sai_status_t SwitchStateBase::refresh_read_only(
case SAI_SWITCH_ATTR_SYSTEM_PORT_LIST:
return refresh_system_port_list(meta);

case SAI_SWITCH_ATTR_NUMBER_OF_FABRIC_PORTS:
case SAI_SWITCH_ATTR_FABRIC_PORT_LIST:
return SAI_STATUS_SUCCESS;
ngoc-do marked this conversation as resolved.
Show resolved Hide resolved

case SAI_SWITCH_ATTR_SUPPORTED_OBJECT_TYPE_LIST:
return SAI_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -1932,6 +1943,9 @@ sai_status_t SwitchStateBase::refresh_read_only(

case SAI_PORT_ATTR_OPER_STATUS:
return SAI_STATUS_SUCCESS;

case SAI_PORT_ATTR_FABRIC_ATTACHED:
return SAI_STATUS_SUCCESS;
}
}

Expand Down Expand Up @@ -2650,6 +2664,10 @@ sai_status_t SwitchStateBase::initialize_voq_switch_objects(

CHECK_STATUS(set_system_port_list());

CHECK_STATUS(create_fabric_ports());

CHECK_STATUS(set_fabric_port_list());

return SAI_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -2781,6 +2799,83 @@ sai_status_t SwitchStateBase::refresh_system_port_list(
return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::create_fabric_ports()
{
SWSS_LOG_ENTER();

SWSS_LOG_INFO("create fabric ports");

auto map = m_switchConfig->m_fabricLaneMap;

if (!map)
{
SWSS_LOG_ERROR("fabric lane map for switch %s is NULL",
sai_serialize_object_id(m_switch_id).c_str());

return SAI_STATUS_FAILURE;
}

auto& lanesVector = map->getLaneVector();

uint32_t fabric_port_count = (uint32_t)lanesVector.size();

m_fabric_port_list.clear();

for (uint32_t i = 0; i < fabric_port_count; i++)
{
SWSS_LOG_DEBUG("create fabric port index %u", i);

sai_object_id_t fabric_port_id;

CHECK_STATUS(create(SAI_OBJECT_TYPE_PORT, &fabric_port_id, m_switch_id, 0, NULL));
m_fabric_port_list.push_back(fabric_port_id);

sai_attribute_t attr;

attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED;
attr.value.booldata = false;

CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr));

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

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = (uint32_t)lanes.size();
attr.value.u32list.list = lanes.data();

CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr));

attr.id = SAI_PORT_ATTR_TYPE;
attr.value.s32 = SAI_PORT_TYPE_FABRIC;

CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr));
}

return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::set_fabric_port_list()
{
SWSS_LOG_ENTER();

SWSS_LOG_INFO("set fabric port list");

sai_attribute_t attr;

uint32_t fabric_port_count = (uint32_t)m_fabric_port_list.size();

attr.id = SAI_SWITCH_ATTR_FABRIC_PORT_LIST;
attr.value.objlist.count = fabric_port_count;
attr.value.objlist.list = m_fabric_port_list.data();

CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr));

attr.id = SAI_SWITCH_ATTR_NUMBER_OF_FABRIC_PORTS;
attr.value.u32 = fabric_port_count;

return set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr);
}

sai_status_t SwitchStateBase::createVoqSystemNeighborEntry(
_In_ const std::string &serializedObjectId,
_In_ sai_object_id_t switch_id,
Expand Down