Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgsudharsan committed Sep 13, 2021
1 parent ef9d6e3 commit 084d18e
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 23 deletions.
132 changes: 132 additions & 0 deletions unittest/vslib/TestSwitchBCM56850.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,135 @@ TEST(SwitchBCM56850, warm_update_queues)

EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_BRIDGE, sboid, 1, &attr), SAI_STATUS_SUCCESS);
}

TEST(SwitchBCM56850, test_tunnel_term_capability)
{
auto sc = std::make_shared<SwitchConfig>(0, "");
auto signal = std::make_shared<Signal>();
auto eventQueue = std::make_shared<EventQueue>(signal);

sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU;
sc->m_switchType = SAI_VS_SWITCH_TYPE_BCM56850;
sc->m_bootType = SAI_VS_BOOT_TYPE_COLD;
sc->m_useTapDevice = false;
sc->m_laneMap = LaneMap::getDefaultLaneMap(0);
sc->m_eventQueue = eventQueue;

auto scc = std::make_shared<SwitchConfigContainer>();

scc->insert(sc);

SwitchBCM56850 sw(
0x2100000000,
std::make_shared<RealObjectIdManager>(0, scc),
sc);


sai_s32_list_t enum_val_cap;
int32_t list[2];
enum_val_cap.count = 2;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_TUNNEL,
SAI_TUNNEL_ATTR_PEER_MODE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 2);

int modes_found = 0;
for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_TUNNEL_PEER_MODE_P2MP || enum_val_cap.list[i] == SAI_TUNNEL_PEER_MODE_P2P)
{
modes_found++;
}
}
EXPECT_EQ(modes_found, 2);

}

TEST(SwitchBCM56850, test_vlan_flood_capability)
{
auto sc = std::make_shared<SwitchConfig>(0, "");
auto signal = std::make_shared<Signal>();
auto eventQueue = std::make_shared<EventQueue>(signal);

sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU;
sc->m_switchType = SAI_VS_SWITCH_TYPE_BCM56850;
sc->m_bootType = SAI_VS_BOOT_TYPE_COLD;
sc->m_useTapDevice = false;
sc->m_laneMap = LaneMap::getDefaultLaneMap(0);
sc->m_eventQueue = eventQueue;

auto scc = std::make_shared<SwitchConfigContainer>();

scc->insert(sc);

SwitchBCM56850 sw(
0x2100000000,
std::make_shared<RealObjectIdManager>(0, scc),
sc);

sai_s32_list_t enum_val_cap;
int32_t list[4];
enum_val_cap.count = 4;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_VLAN,
SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 3);

int flood_types_found = 0;
for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_ALL ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_NONE ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP)
{
flood_types_found++;
}
}
EXPECT_EQ(flood_types_found, 3);

memset(list, 0, sizeof(list));
flood_types_found = 0;
enum_val_cap.count = 4;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_VLAN,
SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 3);

for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_ALL ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_NONE ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP)
{
flood_types_found++;
}
}
EXPECT_EQ(flood_types_found, 3);

memset(list, 0, sizeof(list));
flood_types_found = 0;
enum_val_cap.count = 4;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_VLAN,
SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 3);

for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_ALL ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_NONE ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP)
{
flood_types_found++;
}
}
EXPECT_EQ(flood_types_found, 3);
}
125 changes: 125 additions & 0 deletions unittest/vslib/TestSwitchMLNX2700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,128 @@ TEST(SwitchMLNX2700, warm_update_queues)

EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_BRIDGE, sboid, 1, &attr), SAI_STATUS_SUCCESS);
}

TEST(SwitchMLNX2700, test_tunnel_term_capability)
{
auto sc = std::make_shared<SwitchConfig>(0, "");
auto signal = std::make_shared<Signal>();
auto eventQueue = std::make_shared<EventQueue>(signal);

sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU;
sc->m_switchType = SAI_VS_SWITCH_TYPE_MLNX2700;
sc->m_bootType = SAI_VS_BOOT_TYPE_COLD;
sc->m_useTapDevice = false;
sc->m_laneMap = LaneMap::getDefaultLaneMap(0);
sc->m_eventQueue = eventQueue;

auto scc = std::make_shared<SwitchConfigContainer>();

scc->insert(sc);

SwitchMLNX2700 sw(
0x2100000000,
std::make_shared<RealObjectIdManager>(0, scc),
sc);

sai_s32_list_t enum_val_cap;
int32_t list[2];
enum_val_cap.count = 2;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_TUNNEL,
SAI_TUNNEL_ATTR_PEER_MODE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 1);
EXPECT_EQ(enum_val_cap.list[0], SAI_TUNNEL_PEER_MODE_P2MP);

}

TEST(SwitchMLNX2700, test_vlan_flood_capability)
{
auto sc = std::make_shared<SwitchConfig>(0, "");
auto signal = std::make_shared<Signal>();
auto eventQueue = std::make_shared<EventQueue>(signal);

sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU;
sc->m_switchType = SAI_VS_SWITCH_TYPE_MLNX2700;
sc->m_bootType = SAI_VS_BOOT_TYPE_COLD;
sc->m_useTapDevice = false;
sc->m_laneMap = LaneMap::getDefaultLaneMap(0);
sc->m_eventQueue = eventQueue;

auto scc = std::make_shared<SwitchConfigContainer>();

scc->insert(sc);

SwitchMLNX2700 sw(
0x2100000000,
std::make_shared<RealObjectIdManager>(0, scc),
sc);

sai_s32_list_t enum_val_cap;
int32_t list[4];
enum_val_cap.count = 4;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_VLAN,
SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 4);

int flood_types_found = 0;
for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_ALL ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_NONE ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_COMBINED)
{
flood_types_found++;
}
}
EXPECT_EQ(flood_types_found, 4);

memset(list, 0, sizeof(list));
flood_types_found = 0;
enum_val_cap.count = 4;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_VLAN,
SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 4);

for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_ALL ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_NONE ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_COMBINED)
{
flood_types_found++;
}
}
EXPECT_EQ(flood_types_found, 4);

memset(list, 0, sizeof(list));
flood_types_found = 0;
enum_val_cap.count = 4;
enum_val_cap.list = list;
EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, SAI_OBJECT_TYPE_VLAN,
SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE, &enum_val_cap),
SAI_STATUS_SUCCESS);

EXPECT_EQ(enum_val_cap.count, 4);

for (uint32_t i = 0; i < enum_val_cap.count; i++)
{
if (enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_ALL ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_NONE ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP ||
enum_val_cap.list[i] == SAI_VLAN_FLOOD_CONTROL_TYPE_COMBINED)
{
flood_types_found++;
}
}
EXPECT_EQ(flood_types_found, 4);
}
21 changes: 20 additions & 1 deletion vslib/SwitchMLNX2700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,26 @@ sai_status_t SwitchMLNX2700::warm_update_queues()
return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchMLNX2700::queryVxlanTunnelPeerModeCapability(
sai_status_t SwitchMLNX2700::queryVlanfloodTypeCapability(
_Inout_ sai_s32_list_t *enum_values_capability)
{
SWSS_LOG_ENTER();

if (enum_values_capability->count < 4)
{
return SAI_STATUS_BUFFER_OVERFLOW;
}

enum_values_capability->count = 4;
enum_values_capability->list[0] = SAI_VLAN_FLOOD_CONTROL_TYPE_ALL;
enum_values_capability->list[1] = SAI_VLAN_FLOOD_CONTROL_TYPE_NONE;
enum_values_capability->list[2] = SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP;
enum_values_capability->list[3] = SAI_VLAN_FLOOD_CONTROL_TYPE_COMBINED;

return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchMLNX2700::queryTunnelPeerModeCapability(
_Inout_ sai_s32_list_t *enum_values_capability)
{
SWSS_LOG_ENTER();
Expand Down
4 changes: 3 additions & 1 deletion vslib/SwitchMLNX2700.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ namespace saivs
virtual sai_status_t warm_update_queues() override;

protected:
virtual sai_status_t queryVxlanTunnelPeerModeCapability(
virtual sai_status_t queryTunnelPeerModeCapability(
_Inout_ sai_s32_list_t *enum_values_capability) override;
virtual sai_status_t queryVlanfloodTypeCapability(
_Inout_ sai_s32_list_t *enum_values_capability) override;

};
Expand Down
28 changes: 26 additions & 2 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3297,7 +3297,7 @@ bool SwitchStateBase::dumpObject(
return true;
}

sai_status_t SwitchStateBase::queryVxlanTunnelPeerModeCapability(
sai_status_t SwitchStateBase::queryTunnelPeerModeCapability(
_Inout_ sai_s32_list_t *enum_values_capability)
{
SWSS_LOG_ENTER();
Expand All @@ -3313,6 +3313,24 @@ sai_status_t SwitchStateBase::queryVxlanTunnelPeerModeCapability(
return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::queryVlanfloodTypeCapability(
_Inout_ sai_s32_list_t *enum_values_capability)
{
SWSS_LOG_ENTER();

if (enum_values_capability->count < 3)
{
return SAI_STATUS_BUFFER_OVERFLOW;
}

enum_values_capability->count = 3;
enum_values_capability->list[0] = SAI_VLAN_FLOOD_CONTROL_TYPE_ALL;
enum_values_capability->list[1] = SAI_VLAN_FLOOD_CONTROL_TYPE_NONE;
enum_values_capability->list[2] = SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP;

return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::queryAttrEnumValuesCapability(
_In_ sai_object_id_t switch_id,
_In_ sai_object_type_t object_type,
Expand All @@ -3323,7 +3341,13 @@ sai_status_t SwitchStateBase::queryAttrEnumValuesCapability(

if (object_type == SAI_OBJECT_TYPE_TUNNEL && attr_id == SAI_TUNNEL_ATTR_PEER_MODE)
{
return queryVxlanTunnelPeerModeCapability(enum_values_capability);
return queryTunnelPeerModeCapability(enum_values_capability);
}
else if (object_type == SAI_OBJECT_TYPE_VLAN && (attr_id == SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE ||
attr_id == SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE ||
attr_id == SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE))
{
return queryVlanfloodTypeCapability(enum_values_capability);
}
return SAI_STATUS_NOT_SUPPORTED;
}
5 changes: 4 additions & 1 deletion vslib/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,10 @@ namespace saivs

protected:

virtual sai_status_t queryVxlanTunnelPeerModeCapability(
virtual sai_status_t queryTunnelPeerModeCapability(
_Inout_ sai_s32_list_t *enum_values_capability);

virtual sai_status_t queryVlanfloodTypeCapability(
_Inout_ sai_s32_list_t *enum_values_capability);

public: // TODO private
Expand Down
18 changes: 0 additions & 18 deletions vslib/VirtualSwitchSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,24 +831,6 @@ sai_status_t VirtualSwitchSaiInterface::queryAattributeEnumValuesCapability(

return SAI_STATUS_SUCCESS;
}
else if (object_type == SAI_OBJECT_TYPE_VLAN && (attr_id == SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE ||
attr_id == SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE ||
attr_id == SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE))
{

if (enum_values_capability->count < 4)
{
return SAI_STATUS_BUFFER_OVERFLOW;
}

enum_values_capability->count = 4;
enum_values_capability->list[0] = SAI_VLAN_FLOOD_CONTROL_TYPE_ALL;
enum_values_capability->list[1] = SAI_VLAN_FLOOD_CONTROL_TYPE_NONE;
enum_values_capability->list[2] = SAI_VLAN_FLOOD_CONTROL_TYPE_L2MC_GROUP;
enum_values_capability->list[3] = SAI_VLAN_FLOOD_CONTROL_TYPE_COMBINED;

return SAI_STATUS_SUCCESS;
}
auto ss = m_switchStateMap.at(switch_id);
return ss->queryAttrEnumValuesCapability(switch_id, object_type, attr_id, enum_values_capability);

Expand Down

0 comments on commit 084d18e

Please sign in to comment.