Skip to content

Commit

Permalink
[ppi]: Enable bulk API.
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <nazariig@nvidia.com>
  • Loading branch information
nazariig committed Jan 3, 2023
1 parent 86bb828 commit 7710607
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 8 deletions.
4 changes: 2 additions & 2 deletions syncd/scripts/syncd_init_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ config_syncd_bcm()

config_syncd_mlnx()
{
CMD_ARGS+=" -p /tmp/sai.profile"
CMD_ARGS+=" -l -p /tmp/sai.profile"

[ -e /dev/sxdevs/sxcdev ] || ( mkdir -p /dev/sxdevs && mknod /dev/sxdevs/sxcdev c 231 193 )

Expand Down Expand Up @@ -285,7 +285,7 @@ config_syncd_nephos()

config_syncd_vs()
{
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
CMD_ARGS+=" -l -p $HWSKU_DIR/sai.profile"
}

config_syncd_soda()
Expand Down
3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ tests_SOURCES = main.cpp \
TestSwitchBCM81724.cpp \
TestSwitchStateBaseMACsec.cpp \
TestMACsecManager.cpp \
TestSwitchStateBase.cpp
TestSwitchStateBase.cpp \
TestVirtualSwitchSaiInterface.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
137 changes: 134 additions & 3 deletions unittest/vslib/TestSwitchMLNX2700.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,143 @@
#include "SwitchMLNX2700.h"
#include <cstdint>

#include "meta/sai_serialize.h"
#include <memory>
#include <string>
#include <vector>
#include <array>

#include <gtest/gtest.h>

#include <memory>
#include "ContextConfigContainer.h"
#include "SwitchMLNX2700.h"

#include "meta/Globals.h"
#include "meta/sai_serialize.h"

using namespace saivs;
using namespace saimeta;

class SwitchMLNX2700Test : public ::testing::Test
{
public:
SwitchMLNX2700Test() = default;
virtual ~SwitchMLNX2700Test() = default;

public:
virtual void SetUp() override
{
m_ccc = ContextConfigContainer::getDefault();
m_cc = m_ccc->get(m_guid);
m_scc = m_cc->m_scc;
m_sc = m_scc->getConfig(m_scid);

m_sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU;
m_sc->m_switchType = SAI_VS_SWITCH_TYPE_MLNX2700;
m_sc->m_bootType = SAI_VS_BOOT_TYPE_COLD;
m_sc->m_useTapDevice = false;
m_sc->m_laneMap = LaneMap::getDefaultLaneMap();
m_sc->m_eventQueue = std::make_shared<EventQueue>(std::make_shared<Signal>());

m_ridmgr = std::make_shared<RealObjectIdManager>(m_cc->m_guid, m_cc->m_scc);
m_swid = m_ridmgr->allocateNewSwitchObjectId(Globals::getHardwareInfo(0, nullptr));
m_ss = std::make_shared<SwitchMLNX2700>(m_swid, m_ridmgr, m_sc);
}

virtual void TearDown() override
{
// Empty
}

protected:
std::shared_ptr<ContextConfigContainer> m_ccc;
std::shared_ptr<ContextConfig> m_cc;
std::shared_ptr<SwitchConfigContainer> m_scc;
std::shared_ptr<SwitchConfig> m_sc;
std::shared_ptr<RealObjectIdManager> m_ridmgr;
std::shared_ptr<SwitchStateBase> m_ss;

sai_object_id_t m_swid = SAI_NULL_OBJECT_ID;

const std::uint32_t m_guid = 0; // default context config id
const std::uint32_t m_scid = 0; // default switch config id
};

TEST_F(SwitchMLNX2700Test, portBulkAddRemove)
{
const std::uint32_t portCount = 32;
const std::uint32_t laneCount = 4;

// Generate port object ids
std::vector<sai_object_id_t> oidList(portCount, SAI_NULL_OBJECT_ID);

for (std::uint32_t idx = 0; idx < portCount; idx++)
{
oidList[idx] = m_ridmgr->allocateNewObjectId(SAI_OBJECT_TYPE_PORT, m_swid);
}

// Serialize port object ids
std::vector<std::string> serializedOidList;

for (std::uint32_t idx = 0; idx < portCount; idx++)
{
serializedOidList.emplace_back(sai_serialize_object_id(oidList[idx]));
}

// Generate port config
std::vector<std::array<std::uint32_t, laneCount>> laneDataList;
std::vector<std::vector<sai_attribute_t>> attrDataList;
std::vector<std::uint32_t> attrCountList;
std::vector<const sai_attribute_t*> attrPtrList;

std::vector<sai_status_t> statusList(portCount, SAI_STATUS_SUCCESS);

for (std::uint32_t idx = 0; idx < portCount * 4; idx += 4)
{
sai_attribute_t attr;
std::vector<sai_attribute_t> attrList;

std::array<std::uint32_t, laneCount> laneList = { idx, idx + 1, idx + 2, idx + 3 };
laneDataList.push_back(laneList);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = static_cast<std::uint32_t>(laneDataList.back().size());
attr.value.u32list.list = laneDataList.back().data();
attrList.push_back(attr);

attr.id = SAI_PORT_ATTR_SPEED;
attr.value.u32 = 1000;
attrList.push_back(attr);

attrDataList.push_back(attrList);
attrCountList.push_back(static_cast<std::uint32_t>(attrDataList.back().size()));
attrPtrList.push_back(attrDataList.back().data());
}

// Verify port bulk add
auto status = m_ss->bulkCreate(
m_swid, SAI_OBJECT_TYPE_PORT, serializedOidList, attrCountList.data(), attrPtrList.data(),
SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,
statusList.data()
);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);

for (std::uint32_t i = 0; i < portCount; i++)
{
ASSERT_EQ(statusList.at(i), SAI_STATUS_SUCCESS);
}

// Verify port bulk remove
status = m_ss->bulkRemove(
SAI_OBJECT_TYPE_PORT, serializedOidList,
SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,
statusList.data()
);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);

for (std::uint32_t i = 0; i < portCount; i++)
{
ASSERT_EQ(statusList.at(i), SAI_STATUS_SUCCESS);
}
}

TEST(SwitchMLNX2700, ctr)
{
Expand Down
115 changes: 115 additions & 0 deletions unittest/vslib/TestVirtualSwitchSaiInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include <cstdint>

#include <memory>
#include <vector>
#include <array>

#include <gtest/gtest.h>

#include "ContextConfigContainer.h"
#include "VirtualSwitchSaiInterface.h"

using namespace saivs;

class VirtualSwitchSaiInterfaceTest : public ::testing::Test
{
public:
VirtualSwitchSaiInterfaceTest() = default;
virtual ~VirtualSwitchSaiInterfaceTest() = default;

public:
virtual void SetUp() override
{
m_ccc = ContextConfigContainer::getDefault();
m_cc = m_ccc->get(m_guid);
m_scc = m_cc->m_scc;
m_sc = m_scc->getConfig(m_scid);

m_sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU;
m_sc->m_switchType = SAI_VS_SWITCH_TYPE_MLNX2700;
m_sc->m_bootType = SAI_VS_BOOT_TYPE_COLD;
m_sc->m_useTapDevice = false;
m_sc->m_laneMap = LaneMap::getDefaultLaneMap();
m_sc->m_eventQueue = std::make_shared<EventQueue>(std::make_shared<Signal>());

m_vssai = std::make_shared<VirtualSwitchSaiInterface>(m_cc);

sai_attribute_t attr;
attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

auto status = m_vssai->create(SAI_OBJECT_TYPE_SWITCH, &m_swid, SAI_NULL_OBJECT_ID, 1, &attr);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);
}

virtual void TearDown() override
{
auto status = m_vssai->remove(SAI_OBJECT_TYPE_SWITCH, m_swid);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);
}

protected:
std::shared_ptr<ContextConfigContainer> m_ccc;
std::shared_ptr<ContextConfig> m_cc;
std::shared_ptr<SwitchConfigContainer> m_scc;
std::shared_ptr<SwitchConfig> m_sc;
std::shared_ptr<VirtualSwitchSaiInterface> m_vssai;

sai_object_id_t m_swid = SAI_NULL_OBJECT_ID;

const std::uint32_t m_guid = 0; // default context config id
const std::uint32_t m_scid = 0; // default switch config id
};

TEST_F(VirtualSwitchSaiInterfaceTest, portBulkAddRemove)
{
const std::uint32_t portCount = 1;
const std::uint32_t laneCount = 4;

// Generate port config
std::array<std::uint32_t, laneCount> laneList = { 0, 1, 2, 3 };

sai_attribute_t attr;
std::vector<sai_attribute_t> attrList;

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
attr.value.u32list.count = static_cast<std::uint32_t>(laneList.size());
attr.value.u32list.list = laneList.data();
attrList.push_back(attr);

attr.id = SAI_PORT_ATTR_SPEED;
attr.value.u32 = 1000;
attrList.push_back(attr);

std::array<std::uint32_t, portCount> attrCountList = { static_cast<std::uint32_t>(attrList.size()) };
std::array<const sai_attribute_t*, portCount> attrPtrList = { attrList.data() };

std::array<sai_object_id_t, portCount> oidList = { SAI_NULL_OBJECT_ID };
std::array<sai_status_t, portCount> statusList = { SAI_STATUS_SUCCESS };

// Validate port bulk add
auto status = m_vssai->bulkCreate(
SAI_OBJECT_TYPE_PORT, m_swid, portCount, attrCountList.data(), attrPtrList.data(),
SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,
oidList.data(), statusList.data()
);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);

for (std::uint32_t i = 0; i < portCount; i++)
{
ASSERT_EQ(statusList.at(i), SAI_STATUS_SUCCESS);
}

// Validate port bulk remove
status = m_vssai->bulkRemove(
SAI_OBJECT_TYPE_PORT, portCount, oidList.data(),
SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,
statusList.data()
);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);

for (std::uint32_t i = 0; i < portCount; i++)
{
ASSERT_EQ(statusList.at(i), SAI_STATUS_SUCCESS);
}
}
5 changes: 5 additions & 0 deletions unittest/vslib/test_sai_vs_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ TEST(libsaivs, port)
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_port_attribute(0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_port_attribute(0,0,0));

EXPECT_NE(SAI_STATUS_SUCCESS, api->create_ports(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_ports(0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_ports_attribute(0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_ports_attribute(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));

EXPECT_NE(SAI_STATUS_SUCCESS, api->get_port_stats(0,0,0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_port_stats_ext(0,0,0,SAI_STATS_MODE_READ,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->clear_port_stats(0,0,0));
Expand Down
4 changes: 2 additions & 2 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ sai_status_t SwitchStateBase::bulkCreate(

for (it = 0; it < object_count; it++)
{
object_statuses[it] = create_internal(object_type, serialized_object_ids[it], switch_id, attr_count[it], attr_list[it]);
object_statuses[it] = create(object_type, serialized_object_ids[it], switch_id, attr_count[it], attr_list[it]);

if (object_statuses[it] != SAI_STATUS_SUCCESS)
{
Expand Down Expand Up @@ -779,7 +779,7 @@ sai_status_t SwitchStateBase::bulkRemove(

for (it = 0; it < object_count; it++)
{
object_statuses[it] = remove_internal(object_type, serialized_object_ids[it]);
object_statuses[it] = remove(object_type, serialized_object_ids[it]);

if (object_statuses[it] != SAI_STATUS_SUCCESS)
{
Expand Down
6 changes: 6 additions & 0 deletions vslib/VirtualSwitchSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,12 @@ sai_status_t VirtualSwitchSaiInterface::bulkCreate(
{
SWSS_LOG_ENTER();

// create new real object IDs
for (uint32_t idx = 0; idx < object_count; idx++)
{
object_id[idx] = m_realObjectIdManager->allocateNewObjectId(object_type, switch_id);
}

std::vector<std::string> serialized_object_ids;

// on create vid is put in db by syncd
Expand Down

0 comments on commit 7710607

Please sign in to comment.