Skip to content

Commit 7ad8ddf

Browse files
oleksandrivantsivShuotian Cheng
authored and
Shuotian Cheng
committed
[portsorch]: Fill COUNTERS_QUEUE_TYPE_MAP table (sonic-net#398)
Create queue to queue type mapping. Fill COUNTERS_QUEUE_TYPE_MAP table.
1 parent 6f0eee3 commit 7ad8ddf

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

orchagent/portsorch.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
7676
m_queueTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_MAP));
7777
m_queuePortTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_PORT_MAP));
7878
m_queueIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP));
79+
m_queueTypeTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP));
7980

8081
m_flex_db = shared_ptr<DBConnector>(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0));
8182
m_flexCounterTable = unique_ptr<ProducerStateTable>(new ProducerStateTable(m_flex_db.get(), PFC_WD_STATE_TABLE));
@@ -645,6 +646,39 @@ bool PortsOrch::getPortSpeed(sai_object_id_t port_id, sai_uint32_t &speed)
645646
return status == SAI_STATUS_SUCCESS;
646647
}
647648

649+
bool PortsOrch::getQueueType(sai_object_id_t queue_id, string &type)
650+
{
651+
SWSS_LOG_ENTER();
652+
653+
sai_attribute_t attr;
654+
attr.id = SAI_QUEUE_ATTR_TYPE;
655+
656+
sai_status_t status = sai_queue_api->get_queue_attribute(queue_id, 1, &attr);
657+
if (status != SAI_STATUS_SUCCESS)
658+
{
659+
SWSS_LOG_ERROR("Failed to get queue type for queue %lu rv:%d", queue_id, status);
660+
return false;
661+
}
662+
663+
switch (attr.value.s32)
664+
{
665+
case SAI_QUEUE_TYPE_ALL:
666+
type = "SAI_QUEUE_TYPE_ALL";
667+
break;
668+
case SAI_QUEUE_TYPE_UNICAST:
669+
type = "SAI_QUEUE_TYPE_UNICAST";
670+
break;
671+
case SAI_QUEUE_TYPE_MULTICAST:
672+
type = "SAI_QUEUE_TYPE_MULTICAST";
673+
break;
674+
default:
675+
SWSS_LOG_ERROR("Got unsupported queue type %d for %lu queue", attr.value.s32, queue_id);
676+
throw runtime_error("Got unsupported queue type");
677+
}
678+
679+
return true;
680+
}
681+
648682
bool PortsOrch::setHostIntfsOperStatus(sai_object_id_t port_id, bool up)
649683
{
650684
SWSS_LOG_ENTER();
@@ -1504,6 +1538,7 @@ void PortsOrch::initializeQueues(Port &port)
15041538
vector<FieldValueTuple> queueVector;
15051539
vector<FieldValueTuple> queuePortVector;
15061540
vector<FieldValueTuple> queueIndexVector;
1541+
vector<FieldValueTuple> queueTypeVector;
15071542

15081543
for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex)
15091544
{
@@ -1522,6 +1557,16 @@ void PortsOrch::initializeQueues(Port &port)
15221557
to_string(queueIndex));
15231558
queueIndexVector.push_back(queueIndexTuple);
15241559

1560+
1561+
string queueType;
1562+
if (getQueueType(port.m_queue_ids[queueIndex], queueType))
1563+
{
1564+
FieldValueTuple queueTypeTuple(
1565+
sai_serialize_object_id(port.m_queue_ids[queueIndex]),
1566+
queueType);
1567+
queueTypeVector.push_back(queueTypeTuple);
1568+
}
1569+
15251570
string key = sai_serialize_object_id(port.m_queue_ids[queueIndex]) + ":" + FLEX_STAT_COUNTER_POLL_MSECS;
15261571

15271572
std::string delimiter = "";
@@ -1541,6 +1586,7 @@ void PortsOrch::initializeQueues(Port &port)
15411586
m_queueTable->set("", queueVector);
15421587
m_queuePortTable->set("", queuePortVector);
15431588
m_queueIndexTable->set("", queueIndexVector);
1589+
m_queueTypeTable->set("", queueTypeVector);
15441590
}
15451591

15461592
void PortsOrch::initializePriorityGroups(Port &port)

orchagent/portsorch.h

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class PortsOrch : public Orch, public Subject
6262
unique_ptr<Table> m_queueTable;
6363
unique_ptr<Table> m_queuePortTable;
6464
unique_ptr<Table> m_queueIndexTable;
65+
unique_ptr<Table> m_queueTypeTable;
6566
unique_ptr<ProducerStateTable> m_flexCounterTable;
6667

6768
shared_ptr<DBConnector> m_counter_db;
@@ -126,6 +127,8 @@ class PortsOrch : public Orch, public Subject
126127
bool validatePortSpeed(sai_object_id_t port_id, sai_uint32_t speed);
127128
bool setPortSpeed(sai_object_id_t port_id, sai_uint32_t speed);
128129
bool getPortSpeed(sai_object_id_t port_id, sai_uint32_t &speed);
130+
131+
bool getQueueType(sai_object_id_t queue_id, string &type);
129132
};
130133
#endif /* SWSS_PORTSORCH_H */
131134

0 commit comments

Comments
 (0)