Skip to content

Commit

Permalink
Add Voqs to Virtual Switch (sonic-net#1061)
Browse files Browse the repository at this point in the history
* Add Voqs to Virtual Switch
* Add UnitTest.
  • Loading branch information
skbarista committed Nov 30, 2022
1 parent b7f5f92 commit 9f40994
Show file tree
Hide file tree
Showing 6 changed files with 769 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/BCM56850.pl
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ sub test_neighbor_lag
play "test_neighbor_lag.rec", 3;
}

sub test_voq_switch_create
{
fresh_start("-z", "redis_sync");

play("-z", "redis_sync", "voq_switch_create.rec")
}

# RUN TESTS

test_neighbor_lag;
Expand Down Expand Up @@ -850,5 +857,6 @@ sub test_neighbor_lag
test_brcm_full_to_empty_no_queue_no_ipg_no_buffer_profile;
test_brcm_query_attr_enum_values_capability;
test_brcm_query_object_type_get_availability;
test_voq_switch_create;

kill_syncd;
646 changes: 646 additions & 0 deletions tests/BCM56850/voq_switch_create.rec

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ tests_SOURCES = main.cpp \
TestSwitchBCM56850.cpp \
TestSwitchBCM81724.cpp \
TestSwitchStateBaseMACsec.cpp \
TestMACsecManager.cpp
TestMACsecManager.cpp \
TestSwitchStateBase.cpp

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) -fno-access-control
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \
Expand Down
52 changes: 52 additions & 0 deletions unittest/vslib/TestSwitchStateBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "SwitchStateBase.h"

#include <gtest/gtest.h>

#include <vector>

using namespace saivs;

TEST(SwitchStateBase, initialize_voq_switch)
{
auto sc = std::make_shared<SwitchConfig>(0, "");
auto scc = std::make_shared<SwitchConfigContainer>();

SwitchStateBase ss(
0x2100000000,
std::make_shared<RealObjectIdManager>(0, scc),
sc);

std::vector<sai_attribute_t> attrs;
sai_attribute_t attr;
const u_int32_t numSysPorts = 2;
sai_system_port_config_t sysports[ numSysPorts ] = {
{ .port_id = 0, .attached_switch_id = 2, .attached_core_index = 0,
.attached_core_port_index = 0, .speed=40000, .num_voq = 8 },
{ .port_id = 1, .attached_switch_id = 2, .attached_core_index = 0,
.attached_core_port_index = 1, .speed=40000, .num_voq = 8 }
};

u_int32_t switchId = 2;
u_int32_t maxSystemCores = 16;

attr.id = SAI_SWITCH_ATTR_TYPE;
attr.value.u32 = SAI_SWITCH_TYPE_VOQ;
attrs.push_back(attr);

attr.id = SAI_SWITCH_ATTR_SWITCH_ID;
attr.value.u32 = switchId;
attrs.push_back(attr);

attr.id = SAI_SWITCH_ATTR_MAX_SYSTEM_CORES;
attr.value.u32 = maxSystemCores;
attrs.push_back(attr);

attr.id = SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST;
attr.value.sysportconfiglist.count = numSysPorts;
attr.value.sysportconfiglist.list = sysports;
attrs.push_back(attr);

// Check the result of the initialize_voq_switch_objects
EXPECT_EQ(SAI_STATUS_SUCCESS,
ss.initialize_voq_switch_objects((uint32_t)attrs.size(), attrs.data()));
}
58 changes: 58 additions & 0 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,8 @@ sai_status_t SwitchStateBase::refresh_read_only(
{
case SAI_SYSTEM_PORT_ATTR_TYPE:
case SAI_SYSTEM_PORT_ATTR_PORT:
case SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS:
case SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST:
return SAI_STATUS_SUCCESS;
}
}
Expand Down Expand Up @@ -3033,6 +3035,7 @@ sai_status_t SwitchStateBase::initialize_voq_switch_objects(
}

CHECK_STATUS(create_system_ports(voq_switch_id, sys_port_count, sys_port_cfg_list));
CHECK_STATUS(create_voqs());

CHECK_STATUS(set_system_port_list());

Expand Down Expand Up @@ -3089,6 +3092,61 @@ sai_status_t SwitchStateBase::filter_available_lanes(
return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::create_voq_per_sysport(
_In_ sai_object_id_t sys_port_id)
{
SWSS_LOG_ENTER();

sai_attribute_t attr;

const uint32_t voq_count = 8;

std::vector<sai_object_id_t> voqs;

for (uint32_t i = 0; i < voq_count; ++i)
{
sai_object_id_t voq_id;

CHECK_STATUS(create(SAI_OBJECT_TYPE_QUEUE, &voq_id, m_switch_id, 0, NULL));
voqs.push_back(voq_id);

attr.id = SAI_QUEUE_ATTR_TYPE;
attr.value.s32 = SAI_QUEUE_TYPE_UNICAST_VOQ;

CHECK_STATUS(set(SAI_OBJECT_TYPE_QUEUE, voq_id, &attr));

attr.id = SAI_QUEUE_ATTR_INDEX;
attr.value.u8 = (uint8_t)i;

CHECK_STATUS(set(SAI_OBJECT_TYPE_QUEUE, voq_id, &attr));
}

attr.id = SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS;
attr.value.u32 = voq_count;

CHECK_STATUS(set(SAI_OBJECT_TYPE_SYSTEM_PORT, sys_port_id, &attr));

attr.id = SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST;
attr.value.objlist.count = voq_count;
attr.value.objlist.list = voqs.data();

CHECK_STATUS(set(SAI_OBJECT_TYPE_SYSTEM_PORT, sys_port_id, &attr));

return SAI_STATUS_SUCCESS;
}

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

for (auto &sys_port_id: m_system_port_list)
{
CHECK_STATUS(create_voq_per_sysport(sys_port_id));
}

return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::create_system_ports(
_In_ int32_t voq_switch_id,
_In_ uint32_t sys_port_count,
Expand Down
3 changes: 3 additions & 0 deletions vslib/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ namespace saivs
_In_ uint32_t sys_port_count,
_In_ const sai_system_port_config_t *sys_port_cfg_list);

sai_status_t create_voqs();
sai_status_t create_voq_per_sysport(
_In_ sai_object_id_t sys_port_id);
sai_status_t set_system_port_list();

public:
Expand Down

0 comments on commit 9f40994

Please sign in to comment.