Skip to content

Commit 15beee4

Browse files
authored
Add support for voq counters in portsorch. (sonic-net#2467)
* swss: Add Voq counter support. * Add m_voq_ids to SystemPortInfo to maintain the list of queue ids. * Add two new tables COUNTERS_SYSTEM_PORT_NAME_MAP and COUNTERS_VOQ_NAME_MAP to enable queuestat to differentiate between Port Tx queues and Voqs. * Add a new function initializeVoqs that retrieves the number of voqs for a system port and stores the voq object ids in m_voq_ids * Add code to handle queue type SAI_QUEUE_TYPE_UNICAST_VOQ. * Initialize voqs and populate COUNTERS_SYSTEM_PORT_NAME_MAP in addSystemPorts function. * Update generateQueueMap to generate queue maps for both Txqs and Voq. For PHY ports in a voq system both Txqs and Voqs are instantiated. For Voqs of remote system port, only Voq counters are initialized.
1 parent c8d4905 commit 15beee4

File tree

4 files changed

+120
-12
lines changed

4 files changed

+120
-12
lines changed

orchagent/p4orch/tests/fake_portorch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin
582582
return true;
583583
}
584584

585-
void PortsOrch::generateQueueMapPerPort(const Port &port)
585+
void PortsOrch::generateQueueMapPerPort(const Port &port, bool voq)
586586
{
587587
}
588588

orchagent/portsorch.cpp

+111-10
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
369369
/* Initialize counter table */
370370
m_counter_db = shared_ptr<DBConnector>(new DBConnector("COUNTERS_DB", 0));
371371
m_counterTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_PORT_NAME_MAP));
372+
m_counterSysPortTable = unique_ptr<Table>(
373+
new Table(m_counter_db.get(), COUNTERS_SYSTEM_PORT_NAME_MAP));
372374
m_counterLagTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_LAG_NAME_MAP));
373375
FieldValueTuple tuple("", "");
374376
vector<FieldValueTuple> defaultLagFv;
@@ -383,6 +385,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
383385

384386
/* Initialize queue tables */
385387
m_queueTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_MAP));
388+
m_voqTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_VOQ_NAME_MAP));
386389
m_queuePortTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_PORT_MAP));
387390
m_queueIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP));
388391
m_queueTypeTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP));
@@ -2465,6 +2468,9 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin
24652468
case SAI_QUEUE_TYPE_MULTICAST:
24662469
type = "SAI_QUEUE_TYPE_MULTICAST";
24672470
break;
2471+
case SAI_QUEUE_TYPE_UNICAST_VOQ:
2472+
type = "SAI_QUEUE_TYPE_UNICAST_VOQ";
2473+
break;
24682474
default:
24692475
SWSS_LOG_ERROR("Got unsupported queue type %d for %" PRIu64 " queue", attr[0].value.s32, queue_id);
24702476
throw runtime_error("Got unsupported queue type");
@@ -2797,7 +2803,7 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
27972803
/* when a port is added and queue map counter is enabled --> we need to add queue map counter for it */
27982804
if (m_isQueueMapGenerated)
27992805
{
2800-
generateQueueMapPerPort(p);
2806+
generateQueueMapPerPort(p, false);
28012807
}
28022808

28032809
PortUpdate update = { p, true };
@@ -4512,6 +4518,51 @@ void PortsOrch::doTask(Consumer &consumer)
45124518
}
45134519
}
45144520

4521+
void PortsOrch::initializeVoqs(Port &port)
4522+
{
4523+
SWSS_LOG_ENTER();
4524+
4525+
sai_attribute_t attr;
4526+
attr.id = SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS;
4527+
sai_status_t status = sai_system_port_api->get_system_port_attribute(
4528+
port.m_system_port_oid, 1, &attr);
4529+
if (status != SAI_STATUS_SUCCESS)
4530+
{
4531+
SWSS_LOG_ERROR("Failed to get number of voqs for port %s rv:%d", port.m_alias.c_str(), status);
4532+
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
4533+
if (handle_status != task_process_status::task_success)
4534+
{
4535+
throw runtime_error("PortsOrch initialization failure.");
4536+
}
4537+
}
4538+
SWSS_LOG_INFO("Get %d voq for port %s", attr.value.u32, port.m_alias.c_str());
4539+
4540+
m_port_voq_ids[port.m_alias] = std::vector<sai_object_id_t>( attr.value.u32 );
4541+
4542+
if (attr.value.u32 == 0)
4543+
{
4544+
return;
4545+
}
4546+
4547+
attr.id = SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST;
4548+
attr.value.objlist.count = (uint32_t) m_port_voq_ids[port.m_alias].size();
4549+
attr.value.objlist.list = m_port_voq_ids[port.m_alias].data();
4550+
4551+
status = sai_system_port_api->get_system_port_attribute(
4552+
port.m_system_port_oid, 1, &attr);
4553+
if (status != SAI_STATUS_SUCCESS)
4554+
{
4555+
SWSS_LOG_ERROR("Failed to get voq list for port %s rv:%d", port.m_alias.c_str(), status);
4556+
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
4557+
if (handle_status != task_process_status::task_success)
4558+
{
4559+
throw runtime_error("PortsOrch initialization failure.");
4560+
}
4561+
}
4562+
4563+
SWSS_LOG_INFO("Get voqs for port %s", port.m_alias.c_str());
4564+
}
4565+
45154566
void PortsOrch::initializeQueues(Port &port)
45164567
{
45174568
SWSS_LOG_ENTER();
@@ -5981,7 +6032,16 @@ void PortsOrch::generateQueueMap()
59816032
{
59826033
if (it.second.m_type == Port::PHY)
59836034
{
5984-
generateQueueMapPerPort(it.second);
6035+
generateQueueMapPerPort(it.second, false);
6036+
if (gMySwitchType == "voq")
6037+
{
6038+
generateQueueMapPerPort(it.second, true);
6039+
}
6040+
}
6041+
6042+
if (it.second.m_type == Port::SYSTEM)
6043+
{
6044+
generateQueueMapPerPort(it.second, true);
59856045
}
59866046
}
59876047

@@ -6026,28 +6086,51 @@ void PortsOrch::removeQueueMapPerPort(const Port& port)
60266086
CounterCheckOrch::getInstance().removePort(port);
60276087
}
60286088

6029-
void PortsOrch::generateQueueMapPerPort(const Port& port)
6089+
void PortsOrch::generateQueueMapPerPort(const Port& port, bool voq)
60306090
{
60316091
/* Create the Queue map in the Counter DB */
60326092
/* Add stat counters to flex_counter */
60336093
vector<FieldValueTuple> queueVector;
60346094
vector<FieldValueTuple> queuePortVector;
60356095
vector<FieldValueTuple> queueIndexVector;
60366096
vector<FieldValueTuple> queueTypeVector;
6097+
std::vector<sai_object_id_t> queue_ids;
6098+
if (voq)
6099+
{
6100+
queue_ids = m_port_voq_ids[port.m_alias];
6101+
}
6102+
else
6103+
{
6104+
queue_ids = port.m_queue_ids;
6105+
}
60376106

6038-
for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex)
6107+
for (size_t queueIndex = 0; queueIndex < queue_ids.size(); ++queueIndex)
60396108
{
60406109
std::ostringstream name;
6041-
name << port.m_alias << ":" << queueIndex;
6110+
if (voq)
6111+
{
6112+
name << port.m_system_port_info.alias << ":" << queueIndex;
6113+
}
6114+
else
6115+
{
6116+
name << port.m_alias << ":" << queueIndex;
6117+
}
60426118

6043-
const auto id = sai_serialize_object_id(port.m_queue_ids[queueIndex]);
6119+
const auto id = sai_serialize_object_id(queue_ids[queueIndex]);
60446120

60456121
queueVector.emplace_back(name.str(), id);
6046-
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
6122+
if (voq)
6123+
{
6124+
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_system_port_oid));
6125+
}
6126+
else
6127+
{
6128+
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
6129+
}
60476130

60486131
string queueType;
60496132
uint8_t queueRealIndex = 0;
6050-
if (getQueueTypeAndIndex(port.m_queue_ids[queueIndex], queueType, queueRealIndex))
6133+
if (getQueueTypeAndIndex(queue_ids[queueIndex], queueType, queueRealIndex))
60516134
{
60526135
queueTypeVector.emplace_back(id, queueType);
60536136
queueIndexVector.emplace_back(id, to_string(queueRealIndex));
@@ -6059,7 +6142,11 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
60596142
{
60606143
counter_stats.emplace(sai_serialize_queue_stat(it));
60616144
}
6062-
queue_stat_manager.setCounterIdList(port.m_queue_ids[queueIndex], CounterType::QUEUE, counter_stats);
6145+
queue_stat_manager.setCounterIdList(queue_ids[queueIndex], CounterType::QUEUE, counter_stats);
6146+
6147+
if (voq) {
6148+
continue;
6149+
}
60636150

60646151
/* add watermark queue counters */
60656152
string key = getQueueWatermarkFlexCounterTableKey(id);
@@ -6078,7 +6165,14 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
60786165
m_flexCounterTable->set(key, fieldValues);
60796166
}
60806167

6081-
m_queueTable->set("", queueVector);
6168+
if (voq)
6169+
{
6170+
m_voqTable->set("", queueVector);
6171+
}
6172+
else
6173+
{
6174+
m_queueTable->set("", queueVector);
6175+
}
60826176
m_queuePortTable->set("", queuePortVector);
60836177
m_queueIndexTable->set("", queueIndexVector);
60846178
m_queueTypeTable->set("", queueTypeVector);
@@ -7361,7 +7455,14 @@ bool PortsOrch::addSystemPorts()
73617455
port.m_system_port_info.speed = attrs[1].value.sysportconfig.speed;
73627456
port.m_system_port_info.num_voq = attrs[1].value.sysportconfig.num_voq;
73637457

7458+
initializeVoqs( port );
73647459
setPort(port.m_alias, port);
7460+
/* Add system port name map to counter table */
7461+
FieldValueTuple tuple(port.m_system_port_info.alias,
7462+
sai_serialize_object_id(system_port_oid));
7463+
vector<FieldValueTuple> fields;
7464+
fields.push_back(tuple);
7465+
m_counterSysPortTable->set("", fields);
73657466
if(m_port_ref_count.find(port.m_alias) == m_port_ref_count.end())
73667467
{
73677468
m_port_ref_count[port.m_alias] = 0;

orchagent/portsorch.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ class PortsOrch : public Orch, public Subject
182182

183183
private:
184184
unique_ptr<Table> m_counterTable;
185+
unique_ptr<Table> m_counterSysPortTable;
185186
unique_ptr<Table> m_counterLagTable;
186187
unique_ptr<Table> m_portTable;
187188
unique_ptr<Table> m_gearboxTable;
188189
unique_ptr<Table> m_queueTable;
190+
unique_ptr<Table> m_voqTable;
189191
unique_ptr<Table> m_queuePortTable;
190192
unique_ptr<Table> m_queueIndexTable;
191193
unique_ptr<Table> m_queueTypeTable;
@@ -251,6 +253,7 @@ class PortsOrch : public Orch, public Subject
251253
map<set<int>, tuple<string, uint32_t, int, string, int, string>> m_lanesAliasSpeedMap;
252254
map<string, Port> m_portList;
253255
map<string, vlan_members_t> m_portVlanMember;
256+
map<string, std::vector<sai_object_id_t>> m_port_voq_ids;
254257
/* mapping from SAI object ID to Name for faster
255258
* retrieval of Port/VLAN from object ID for events
256259
* coming from SAI
@@ -288,6 +291,8 @@ class PortsOrch : public Orch, public Subject
288291
void initializePriorityGroups(Port &port);
289292
void initializePortBufferMaximumParameters(Port &port);
290293
void initializeQueues(Port &port);
294+
void initializeVoqs(Port &port);
295+
291296

292297
bool addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id);
293298
bool setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip);
@@ -344,7 +349,7 @@ class PortsOrch : public Orch, public Subject
344349
bool getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uint8_t &index);
345350

346351
bool m_isQueueMapGenerated = false;
347-
void generateQueueMapPerPort(const Port& port);
352+
void generateQueueMapPerPort(const Port& port, bool voq);
348353
void removeQueueMapPerPort(const Port& port);
349354

350355
bool m_isPriorityGroupMapGenerated = false;

tests/test_vlan.py

+2
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def arp_accept_disabled():
460460
wait_for_result(arp_accept_disabled, PollingConfig(), "IPv4 arp_accept not disabled")
461461

462462
self.dvs_vlan.remove_vlan(vlan)
463+
self.dvs_vlan.get_and_verify_vlan_ids(0)
463464

464465
def test_VlanProxyArp(self, dvs):
465466

@@ -487,6 +488,7 @@ def proxy_arp_disabled():
487488
wait_for_result(proxy_arp_disabled, PollingConfig(), 'IPv4 proxy_arp or proxy_arp_pvlan not disabled')
488489

489490
self.dvs_vlan.remove_vlan(vlan)
491+
self.dvs_vlan.get_and_verify_vlan_ids(0)
490492

491493
def test_VlanMemberLinkDown(self, dvs):
492494

0 commit comments

Comments
 (0)