Skip to content

Commit 44de75f

Browse files
[portsorch] fix crash when number of PGs returned 0
Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 3ccfa62 commit 44de75f

File tree

3 files changed

+102
-5
lines changed

3 files changed

+102
-5
lines changed

orchagent/portsorch.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6464,10 +6464,16 @@ void PortsOrch::initializePriorityGroupsBulk(std::vector<Port>& ports)
64646464

64656465
bulker.executeGet();
64666466

6467-
for (size_t idx = 0; idx < portCount; idx++)
6467+
size_t idx = 0;
6468+
for (const auto& port: ports)
64686469
{
6469-
const auto& port = ports[idx];
6470+
if (port.m_priority_group_ids.size() == 0)
6471+
{
6472+
continue;
6473+
}
6474+
64706475
const auto status = bulker.statuses[idx];
6476+
idx++;
64716477

64726478
if (status != SAI_STATUS_SUCCESS)
64736479
{
@@ -6542,10 +6548,16 @@ void PortsOrch::initializeQueuesBulk(std::vector<Port>& ports)
65426548

65436549
bulker.executeGet();
65446550

6545-
for (size_t idx = 0; idx < portCount; idx++)
6551+
size_t idx = 0;
6552+
for (const auto& port: ports)
65466553
{
6547-
const auto& port = ports[idx];
6554+
if (port.m_queue_ids.size() == 0)
6555+
{
6556+
continue;
6557+
}
6558+
65486559
const auto status = bulker.statuses[idx];
6560+
idx++;
65496561

65506562
if (status != SAI_STATUS_SUCCESS)
65516563
{
@@ -6622,10 +6634,17 @@ void PortsOrch::initializeSchedulerGroupsBulk(std::vector<Port>& ports)
66226634

66236635
bulker.executeGet();
66246636

6637+
size_t bulkIdx = 0;
66256638
for (size_t idx = 0; idx < portCount; idx++)
66266639
{
66276640
const auto& port = ports[idx];
6628-
const auto status = bulker.statuses[idx];
6641+
if (scheduler_group_ids[idx].size() == 0)
6642+
{
6643+
continue;
6644+
}
6645+
6646+
const auto status = bulker.statuses[bulkIdx];
6647+
bulkIdx++;
66296648

66306649
if (status != SAI_STATUS_SUCCESS)
66316650
{

tests/mock_tests/portsorch_ut.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,74 @@ namespace portsorch_test
29642964
ASSERT_FALSE(port.m_init);
29652965
}
29662966

2967+
TEST_F(PortsOrchTest, PortsWithNoPGsQueuesSchedulerGroups)
2968+
{
2969+
Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME);
2970+
2971+
auto original_api = sai_port_api->get_ports_attribute;
2972+
// Mock SAI port API to return 0 number of PGs, queues and scheduler groups
2973+
auto spy = SpyOn<SAI_API_PORT, SAI_OBJECT_TYPE_PORT>(&sai_port_api->get_ports_attribute);
2974+
spy->callFake([&](
2975+
uint32_t object_count,
2976+
const sai_object_id_t *object_id,
2977+
const uint32_t *attr_count,
2978+
sai_attribute_t **attr_list,
2979+
sai_bulk_op_error_mode_t mode,
2980+
sai_status_t *object_statuses) -> sai_status_t
2981+
{
2982+
assert(object_count > 1);
2983+
assert(attr_count[0] > 1);
2984+
switch (attr_list[0]->id)
2985+
{
2986+
case SAI_PORT_ATTR_NUMBER_OF_INGRESS_PRIORITY_GROUPS:
2987+
case SAI_PORT_ATTR_QOS_NUMBER_OF_QUEUES:
2988+
case SAI_PORT_ATTR_QOS_NUMBER_OF_SCHEDULER_GROUPS:
2989+
for (size_t i = 0; i < object_count; i++)
2990+
{
2991+
attr_list[i]->value.u32 = 0;
2992+
object_statuses[i] = SAI_STATUS_SUCCESS;
2993+
}
2994+
return SAI_STATUS_SUCCESS;
2995+
}
2996+
return original_api(
2997+
object_count,
2998+
object_id,
2999+
attr_count,
3000+
attr_list,
3001+
mode,
3002+
object_statuses);
3003+
}
3004+
);
3005+
3006+
// Get SAI default ports to populate DB
3007+
3008+
auto ports = ut_helper::getInitialSaiPorts();
3009+
3010+
// Populate pot table with SAI ports
3011+
for (const auto &it : ports)
3012+
{
3013+
portTable.set(it.first, it.second);
3014+
}
3015+
3016+
// Set PortConfigDone
3017+
portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } });
3018+
3019+
gPortsOrch->addExistingData(&portTable);
3020+
3021+
// Apply configuration :
3022+
// create ports
3023+
3024+
static_cast<Orch *>(gPortsOrch)->doTask();
3025+
3026+
Port port;
3027+
gPortsOrch->getPort("Ethernet0", port);
3028+
3029+
ASSERT_TRUE(port.m_init);
3030+
ASSERT_EQ(port.m_priority_group_ids.size(), 0);
3031+
ASSERT_EQ(port.m_queue_ids.size(), 0);
3032+
}
3033+
3034+
29673035
TEST_F(PortsOrchTest, PfcDlrHandlerCallingDlrInitAttribute)
29683036
{
29693037
_hook_sai_port_api();

tests/mock_tests/saispy.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,13 @@ std::shared_ptr<SaiSpyFunctor<n, objtype, sai_status_t, sai_object_id_t, uint32_
118118

119119
return std::make_shared<SaiSpyGetAttrFunctor>(fn_ptr);
120120
}
121+
122+
// get bulk entry attribute
123+
template <int n, int objtype>
124+
std::shared_ptr<SaiSpyFunctor<n, objtype, sai_status_t, uint32_t, const sai_object_id_t*, const uint32_t*, sai_attribute_t**, sai_bulk_op_error_mode_t, sai_status_t*>>
125+
SpyOn(sai_status_t (**fn_ptr)(uint32_t, const sai_object_id_t*, const uint32_t*, sai_attribute_t**, sai_bulk_op_error_mode_t, sai_status_t*))
126+
{
127+
using SaiSpyGetAttrFunctor = SaiSpyFunctor<n, objtype, sai_status_t, uint32_t, const sai_object_id_t*, const uint32_t*, sai_attribute_t**, sai_bulk_op_error_mode_t, sai_status_t*>;
128+
129+
return std::make_shared<SaiSpyGetAttrFunctor>(fn_ptr);
130+
}

0 commit comments

Comments
 (0)