From a302e5d55ce2f41b72593d1a775dc33da2b7d505 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Sat, 4 Sep 2021 00:15:12 +0000 Subject: [PATCH 1/6] Enhancing vs tests to mock platform specific flows --- vslib/SwitchMLNX2700.cpp | 13 +++++++++++++ vslib/SwitchMLNX2700.h | 5 +++++ vslib/SwitchStateBase.cpp | 27 +++++++++++++++++++++++++++ vslib/SwitchStateBase.h | 11 +++++++++++ vslib/VirtualSwitchSaiInterface.cpp | 21 ++++++++++++++++++++- 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/vslib/SwitchMLNX2700.cpp b/vslib/SwitchMLNX2700.cpp index b3ab808aa..ff8e34467 100644 --- a/vslib/SwitchMLNX2700.cpp +++ b/vslib/SwitchMLNX2700.cpp @@ -424,3 +424,16 @@ sai_status_t SwitchMLNX2700::warm_update_queues() return SAI_STATUS_SUCCESS; } + +sai_status_t SwitchMLNX2700::queryVxlanTunnelPeerModeCapability( + _Inout_ sai_s32_list_t *enum_values_capability) +{ + if (enum_values_capability->count < 1) + { + return SAI_STATUS_BUFFER_OVERFLOW; + } + + enum_values_capability->count = 1; + enum_values_capability->list[0] = SAI_TUNNEL_PEER_MODE_P2MP; + return SAI_STATUS_SUCCESS; +} diff --git a/vslib/SwitchMLNX2700.h b/vslib/SwitchMLNX2700.h index 52f18bc9a..4f91a1fc4 100644 --- a/vslib/SwitchMLNX2700.h +++ b/vslib/SwitchMLNX2700.h @@ -43,5 +43,10 @@ namespace saivs _In_ sai_object_id_t bridge_id) override; virtual sai_status_t warm_update_queues() override; + + protected: + virtual sai_status_t queryVxlanTunnelPeerModeCapability( + _Inout_ sai_s32_list_t *enum_values_capability) override; + }; } diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 7ca4bff25..282749470 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -3296,3 +3296,30 @@ bool SwitchStateBase::dumpObject( return true; } + +sai_status_t SwitchStateBase::queryVxlanTunnelPeerModeCapability( + _Inout_ sai_s32_list_t *enum_values_capability) +{ + if (enum_values_capability->count < 2) + { + return SAI_STATUS_BUFFER_OVERFLOW; + } + + enum_values_capability->count = 2; + enum_values_capability->list[0] = SAI_TUNNEL_PEER_MODE_P2MP; + enum_values_capability->list[1] = SAI_TUNNEL_PEER_MODE_P2P; + return SAI_STATUS_SUCCESS; +} + +sai_status_t SwitchStateBase::queryAttrEnumValuesCapability( + _In_ sai_object_id_t switch_id, + _In_ sai_object_type_t object_type, + _In_ sai_attr_id_t attr_id, + _Inout_ sai_s32_list_t *enum_values_capability) +{ + if (object_type == SAI_OBJECT_TYPE_TUNNEL && attr_id == SAI_TUNNEL_ATTR_PEER_MODE) + { + return queryVxlanTunnelPeerModeCapability(enum_values_capability); + } + return SAI_STATUS_NOT_SUPPORTED; +} diff --git a/vslib/SwitchStateBase.h b/vslib/SwitchStateBase.h index d870deaab..11cd71106 100644 --- a/vslib/SwitchStateBase.h +++ b/vslib/SwitchStateBase.h @@ -268,6 +268,12 @@ namespace saivs _In_ sai_bulk_op_error_mode_t mode, _Out_ sai_status_t *object_statuses); + virtual sai_status_t queryAttrEnumValuesCapability( + _In_ sai_object_id_t switch_id, + _In_ sai_object_type_t object_type, + _In_ sai_attr_id_t attr_id, + _Inout_ sai_s32_list_t *enum_values_capability); + protected: virtual sai_status_t remove_internal( @@ -633,6 +639,11 @@ namespace saivs constexpr static const int m_maxAclTables = 3; constexpr static const int m_maxAclTableGroups = 200; + protected: + + virtual sai_status_t queryVxlanTunnelPeerModeCapability( + _Inout_ sai_s32_list_t *enum_values_capability); + public: // TODO private std::set m_fdb_info_set; diff --git a/vslib/VirtualSwitchSaiInterface.cpp b/vslib/VirtualSwitchSaiInterface.cpp index 14bd9dce1..3969fca12 100644 --- a/vslib/VirtualSwitchSaiInterface.cpp +++ b/vslib/VirtualSwitchSaiInterface.cpp @@ -831,8 +831,27 @@ 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); - return SAI_STATUS_NOT_SUPPORTED; } sai_status_t VirtualSwitchSaiInterface::getStats( From 47a3e9a3ae5f9c5f01f5a9c8ce6e875c2b9dbf98 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Sat, 4 Sep 2021 18:21:55 +0000 Subject: [PATCH 2/6] Fixing build issues --- vslib/SwitchMLNX2700.cpp | 2 ++ vslib/SwitchStateBase.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/vslib/SwitchMLNX2700.cpp b/vslib/SwitchMLNX2700.cpp index ff8e34467..32fcef0fd 100644 --- a/vslib/SwitchMLNX2700.cpp +++ b/vslib/SwitchMLNX2700.cpp @@ -428,6 +428,8 @@ sai_status_t SwitchMLNX2700::warm_update_queues() sai_status_t SwitchMLNX2700::queryVxlanTunnelPeerModeCapability( _Inout_ sai_s32_list_t *enum_values_capability) { + SWSS_LOG_ENTER(); + if (enum_values_capability->count < 1) { return SAI_STATUS_BUFFER_OVERFLOW; diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 282749470..7f10d8900 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -3300,6 +3300,8 @@ bool SwitchStateBase::dumpObject( sai_status_t SwitchStateBase::queryVxlanTunnelPeerModeCapability( _Inout_ sai_s32_list_t *enum_values_capability) { + SWSS_LOG_ENTER(); + if (enum_values_capability->count < 2) { return SAI_STATUS_BUFFER_OVERFLOW; @@ -3317,6 +3319,8 @@ sai_status_t SwitchStateBase::queryAttrEnumValuesCapability( _In_ sai_attr_id_t attr_id, _Inout_ sai_s32_list_t *enum_values_capability) { + SWSS_LOG_ENTER(); + if (object_type == SAI_OBJECT_TYPE_TUNNEL && attr_id == SAI_TUNNEL_ATTR_PEER_MODE) { return queryVxlanTunnelPeerModeCapability(enum_values_capability); From 084d18eff2aedd4512b3315ae9bb35662b819199 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Mon, 13 Sep 2021 23:43:35 +0000 Subject: [PATCH 3/6] Added unit tests --- unittest/vslib/TestSwitchBCM56850.cpp | 132 ++++++++++++++++++++++++++ unittest/vslib/TestSwitchMLNX2700.cpp | 125 ++++++++++++++++++++++++ vslib/SwitchMLNX2700.cpp | 21 +++- vslib/SwitchMLNX2700.h | 4 +- vslib/SwitchStateBase.cpp | 28 +++++- vslib/SwitchStateBase.h | 5 +- vslib/VirtualSwitchSaiInterface.cpp | 18 ---- 7 files changed, 310 insertions(+), 23 deletions(-) diff --git a/unittest/vslib/TestSwitchBCM56850.cpp b/unittest/vslib/TestSwitchBCM56850.cpp index 6c049259f..e1c015552 100644 --- a/unittest/vslib/TestSwitchBCM56850.cpp +++ b/unittest/vslib/TestSwitchBCM56850.cpp @@ -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(0, ""); + auto signal = std::make_shared(); + auto eventQueue = std::make_shared(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(); + + scc->insert(sc); + + SwitchBCM56850 sw( + 0x2100000000, + std::make_shared(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(0, ""); + auto signal = std::make_shared(); + auto eventQueue = std::make_shared(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(); + + scc->insert(sc); + + SwitchBCM56850 sw( + 0x2100000000, + std::make_shared(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); +} diff --git a/unittest/vslib/TestSwitchMLNX2700.cpp b/unittest/vslib/TestSwitchMLNX2700.cpp index 8086ea692..2a88469cb 100644 --- a/unittest/vslib/TestSwitchMLNX2700.cpp +++ b/unittest/vslib/TestSwitchMLNX2700.cpp @@ -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(0, ""); + auto signal = std::make_shared(); + auto eventQueue = std::make_shared(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(); + + scc->insert(sc); + + SwitchMLNX2700 sw( + 0x2100000000, + std::make_shared(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(0, ""); + auto signal = std::make_shared(); + auto eventQueue = std::make_shared(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(); + + scc->insert(sc); + + SwitchMLNX2700 sw( + 0x2100000000, + std::make_shared(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); +} diff --git a/vslib/SwitchMLNX2700.cpp b/vslib/SwitchMLNX2700.cpp index 32fcef0fd..de709e6f9 100644 --- a/vslib/SwitchMLNX2700.cpp +++ b/vslib/SwitchMLNX2700.cpp @@ -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(); diff --git a/vslib/SwitchMLNX2700.h b/vslib/SwitchMLNX2700.h index 4f91a1fc4..9ef0f9f07 100644 --- a/vslib/SwitchMLNX2700.h +++ b/vslib/SwitchMLNX2700.h @@ -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; }; diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 7f10d8900..02aa7c3ed 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -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(); @@ -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, @@ -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; } diff --git a/vslib/SwitchStateBase.h b/vslib/SwitchStateBase.h index 11cd71106..666c106f0 100644 --- a/vslib/SwitchStateBase.h +++ b/vslib/SwitchStateBase.h @@ -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 diff --git a/vslib/VirtualSwitchSaiInterface.cpp b/vslib/VirtualSwitchSaiInterface.cpp index 3969fca12..58df841e1 100644 --- a/vslib/VirtualSwitchSaiInterface.cpp +++ b/vslib/VirtualSwitchSaiInterface.cpp @@ -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); From b3f6173448e1f0fab910f7ce0f2ab62c63093061 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Tue, 14 Sep 2021 23:26:39 +0000 Subject: [PATCH 4/6] Addressing review comments --- unittest/vslib/TestSwitchBCM56850.cpp | 27 ++++++++++++++++--------- unittest/vslib/TestSwitchMLNX2700.cpp | 29 +++++++++++++++++++-------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/unittest/vslib/TestSwitchBCM56850.cpp b/unittest/vslib/TestSwitchBCM56850.cpp index e1c015552..e14673815 100644 --- a/unittest/vslib/TestSwitchBCM56850.cpp +++ b/unittest/vslib/TestSwitchBCM56850.cpp @@ -296,13 +296,16 @@ TEST(SwitchBCM56850, test_tunnel_term_capability) 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), + 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) @@ -310,8 +313,8 @@ TEST(SwitchBCM56850, test_tunnel_term_capability) modes_found++; } } - EXPECT_EQ(modes_found, 2); + EXPECT_EQ(modes_found, 2); } TEST(SwitchBCM56850, test_vlan_flood_capability) @@ -340,8 +343,10 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) 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), + 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); @@ -362,8 +367,10 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) 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), + 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); @@ -383,8 +390,10 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) 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), + 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); diff --git a/unittest/vslib/TestSwitchMLNX2700.cpp b/unittest/vslib/TestSwitchMLNX2700.cpp index 2a88469cb..5451ec054 100644 --- a/unittest/vslib/TestSwitchMLNX2700.cpp +++ b/unittest/vslib/TestSwitchMLNX2700.cpp @@ -292,10 +292,13 @@ TEST(SwitchMLNX2700, test_tunnel_term_capability) 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), + 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); @@ -329,13 +332,16 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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), + 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 || @@ -346,14 +352,17 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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), + 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); @@ -368,14 +377,17 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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), + 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); @@ -390,5 +402,6 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) flood_types_found++; } } + EXPECT_EQ(flood_types_found, 4); } From f337322917005951e98a7ef39bd586db6aa54239 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Tue, 14 Sep 2021 23:29:16 +0000 Subject: [PATCH 5/6] Newline changes --- unittest/vslib/TestSwitchBCM56850.cpp | 3 +++ unittest/vslib/TestSwitchMLNX2700.cpp | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unittest/vslib/TestSwitchBCM56850.cpp b/unittest/vslib/TestSwitchBCM56850.cpp index e14673815..facfcbc39 100644 --- a/unittest/vslib/TestSwitchBCM56850.cpp +++ b/unittest/vslib/TestSwitchBCM56850.cpp @@ -361,6 +361,7 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) flood_types_found++; } } + EXPECT_EQ(flood_types_found, 3); memset(list, 0, sizeof(list)); @@ -384,6 +385,7 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) flood_types_found++; } } + EXPECT_EQ(flood_types_found, 3); memset(list, 0, sizeof(list)); @@ -407,5 +409,6 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) flood_types_found++; } } + EXPECT_EQ(flood_types_found, 3); } diff --git a/unittest/vslib/TestSwitchMLNX2700.cpp b/unittest/vslib/TestSwitchMLNX2700.cpp index 5451ec054..2f0619fd4 100644 --- a/unittest/vslib/TestSwitchMLNX2700.cpp +++ b/unittest/vslib/TestSwitchMLNX2700.cpp @@ -300,7 +300,6 @@ TEST(SwitchMLNX2700, test_tunnel_term_capability) 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); @@ -330,6 +329,7 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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, @@ -337,7 +337,6 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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; From c43103d43eaf13d660828d06a653938d14c74864 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Tue, 14 Sep 2021 23:38:23 +0000 Subject: [PATCH 6/6] Added more new lines --- unittest/vslib/TestSwitchBCM56850.cpp | 6 ++++++ unittest/vslib/TestSwitchMLNX2700.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/unittest/vslib/TestSwitchBCM56850.cpp b/unittest/vslib/TestSwitchBCM56850.cpp index facfcbc39..df4e3d17f 100644 --- a/unittest/vslib/TestSwitchBCM56850.cpp +++ b/unittest/vslib/TestSwitchBCM56850.cpp @@ -294,8 +294,10 @@ TEST(SwitchBCM56850, test_tunnel_term_capability) 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, @@ -341,8 +343,10 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) 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, @@ -368,6 +372,7 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) 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, @@ -392,6 +397,7 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) 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, diff --git a/unittest/vslib/TestSwitchMLNX2700.cpp b/unittest/vslib/TestSwitchMLNX2700.cpp index 2f0619fd4..d271b4c62 100644 --- a/unittest/vslib/TestSwitchMLNX2700.cpp +++ b/unittest/vslib/TestSwitchMLNX2700.cpp @@ -295,12 +295,15 @@ TEST(SwitchMLNX2700, test_tunnel_term_capability) 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); } @@ -332,11 +335,13 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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; @@ -358,6 +363,7 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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, @@ -383,6 +389,7 @@ TEST(SwitchMLNX2700, test_vlan_flood_capability) 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,