Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for voq counters in portsorch. #1913

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orchagent/p4orch/tests/fake_portorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void PortsOrch::generateQueueMap(std::map<string, FlexCounterQueueStates> queues
{
}

void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates& queuesState)
void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates& queuesState, bool voq)
{
}

Expand Down
1 change: 1 addition & 0 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct SystemPortInfo
std::string alias = "";
sai_system_port_type_t type = SAI_SYSTEM_PORT_TYPE_LOCAL;
sai_object_id_t local_port_oid = 0;
std::vector<sai_object_id_t> m_voq_ids;
uint32_t port_id = 0;
uint32_t switch_id = 0;
uint32_t core_index = 0;
Expand Down
125 changes: 115 additions & 10 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
/* Initialize counter table */
m_counter_db = shared_ptr<DBConnector>(new DBConnector("COUNTERS_DB", 0));
m_counterTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_PORT_NAME_MAP));
m_counterSysPortTable = unique_ptr<Table>(
new Table(m_counter_db.get(), COUNTERS_SYSTEM_PORT_NAME_MAP));
m_counterLagTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_LAG_NAME_MAP));
FieldValueTuple tuple("", "");
vector<FieldValueTuple> defaultLagFv;
Expand All @@ -383,6 +385,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi

/* Initialize queue tables */
m_queueTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_MAP));
m_voqTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_VOQ_NAME_MAP));
m_queuePortTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_PORT_MAP));
m_queueIndexTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP));
m_queueTypeTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP));
Expand Down Expand Up @@ -2465,6 +2468,9 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin
case SAI_QUEUE_TYPE_MULTICAST:
type = "SAI_QUEUE_TYPE_MULTICAST";
break;
case SAI_QUEUE_TYPE_UNICAST_VOQ:
type = "SAI_QUEUE_TYPE_UNICAST_VOQ";
break;
default:
SWSS_LOG_ERROR("Got unsupported queue type %d for %" PRIu64 " queue", attr[0].value.s32, queue_id);
throw runtime_error("Got unsupported queue type");
Expand Down Expand Up @@ -4488,6 +4494,51 @@ void PortsOrch::doTask(Consumer &consumer)
}
}

void PortsOrch::initializeVoqs(Port &port)
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS;
sai_status_t status = sai_system_port_api->get_system_port_attribute(
port.m_system_port_oid, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get number of voqs for port %s rv:%d", port.m_alias.c_str(), status);
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
if (handle_status != task_process_status::task_success)
{
throw runtime_error("PortsOrch initialization failure.");
}
}
SWSS_LOG_INFO("Get %d voq for port %s", attr.value.u32, port.m_alias.c_str());

port.m_system_port_info.m_voq_ids.resize(attr.value.u32);

if (attr.value.u32 == 0)
{
return;
}

attr.id = SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST;
attr.value.objlist.count = (uint32_t)port.m_system_port_info.m_voq_ids.size();
attr.value.objlist.list = port.m_system_port_info.m_voq_ids.data();

status = sai_system_port_api->get_system_port_attribute(
port.m_system_port_oid, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get voq list for port %s rv:%d", port.m_alias.c_str(), status);
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
if (handle_status != task_process_status::task_success)
{
throw runtime_error("PortsOrch initialization failure.");
}
}

SWSS_LOG_INFO("Get voqs for port %s", port.m_alias.c_str());
}

void PortsOrch::initializeQueues(Port &port)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -5963,34 +6014,63 @@ void PortsOrch::generateQueueMap(map<string, FlexCounterQueueStates> queuesState
FlexCounterQueueStates flexCounterQueueState(maxQueueNumber);
queuesStateVector.insert(make_pair(it.second.m_alias, flexCounterQueueState));
}
generateQueueMapPerPort(it.second, queuesStateVector.at(it.second.m_alias));
generateQueueMapPerPort(it.second, queuesStateVector.at(it.second.m_alias), false);
if (gMySwitchType == "voq")
{
// pass a dummy FlexCounterQueueStates since it is not used for voqs.
FlexCounterQueueStates counterState(0);
generateQueueMapPerPort(it.second, counterState, true);
}
}

if (it.second.m_type == Port::SYSTEM)
{
// pass a dummy FlexCounterQueueStates since it is not used for voqs.
FlexCounterQueueStates counterState(0);
generateQueueMapPerPort(it.second, counterState, true);
}
}

m_isQueueMapGenerated = true;
}

void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates& queuesState)
void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates& queuesState, bool voq)
{
/* Create the Queue map in the Counter DB */
/* Add stat counters to flex_counter */
vector<FieldValueTuple> queueVector;
vector<FieldValueTuple> queuePortVector;
vector<FieldValueTuple> queueIndexVector;
vector<FieldValueTuple> queueTypeVector;
std::vector<sai_object_id_t> queue_ids;
if (voq)
{
queue_ids = port.m_system_port_info.m_voq_ids;
}
else
{
queue_ids = port.m_queue_ids;
}

for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex)
for (size_t queueIndex = 0; queueIndex < queue_ids.size(); ++queueIndex)
{
std::ostringstream name;
name << port.m_alias << ":" << queueIndex;
if (voq)
{
name << port.m_system_port_info.alias << ":" << queueIndex;
}
else
{
name << port.m_alias << ":" << queueIndex;
}

const auto id = sai_serialize_object_id(port.m_queue_ids[queueIndex]);
const auto id = sai_serialize_object_id(queue_ids[queueIndex]);

string queueType;
uint8_t queueRealIndex = 0;
if (getQueueTypeAndIndex(port.m_queue_ids[queueIndex], queueType, queueRealIndex))
if (getQueueTypeAndIndex(queue_ids[queueIndex], queueType, queueRealIndex))
{
if (!queuesState.isQueueCounterEnabled(queueRealIndex))
if (!voq && !queuesState.isQueueCounterEnabled(queueRealIndex))
{
continue;
}
Expand All @@ -5999,15 +6079,26 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates
}

queueVector.emplace_back(name.str(), id);
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
if (voq)
{
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_system_port_oid));
}
else
{
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
}

// Install a flex counter for this queue to track stats
std::unordered_set<string> counter_stats;
for (const auto& it: queue_stat_ids)
{
counter_stats.emplace(sai_serialize_queue_stat(it));
}
queue_stat_manager.setCounterIdList(port.m_queue_ids[queueIndex], CounterType::QUEUE, counter_stats);
queue_stat_manager.setCounterIdList(queue_ids[queueIndex], CounterType::QUEUE, counter_stats);

if (voq) {
continue;
}

/* add watermark queue counters */
string key = getQueueWatermarkFlexCounterTableKey(id);
Expand All @@ -6026,7 +6117,14 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates
m_flexCounterTable->set(key, fieldValues);
}

m_queueTable->set("", queueVector);
if (voq)
{
m_voqTable->set("", queueVector);
}
else
{
m_queueTable->set("", queueVector);
}
m_queuePortTable->set("", queuePortVector);
m_queueIndexTable->set("", queueIndexVector);
m_queueTypeTable->set("", queueTypeVector);
Expand Down Expand Up @@ -7521,7 +7619,14 @@ bool PortsOrch::addSystemPorts()
port.m_system_port_info.speed = attrs[1].value.sysportconfig.speed;
port.m_system_port_info.num_voq = attrs[1].value.sysportconfig.num_voq;

initializeVoqs( port );
setPort(port.m_alias, port);
/* Add system port name map to counter table */
FieldValueTuple tuple(port.m_system_port_info.alias,
sai_serialize_object_id(system_port_oid));
vector<FieldValueTuple> fields;
fields.push_back(tuple);
m_counterSysPortTable->set("", fields);
if(m_port_ref_count.find(port.m_alias) == m_port_ref_count.end())
{
m_port_ref_count[port.m_alias] = 0;
Expand Down
6 changes: 5 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ class PortsOrch : public Orch, public Subject

private:
unique_ptr<Table> m_counterTable;
unique_ptr<Table> m_counterSysPortTable;
unique_ptr<Table> m_counterLagTable;
unique_ptr<Table> m_portTable;
unique_ptr<Table> m_gearboxTable;
unique_ptr<Table> m_queueTable;
unique_ptr<Table> m_voqTable;
unique_ptr<Table> m_queuePortTable;
unique_ptr<Table> m_queueIndexTable;
unique_ptr<Table> m_queueTypeTable;
Expand Down Expand Up @@ -296,6 +298,7 @@ class PortsOrch : public Orch, public Subject
void initializePriorityGroups(Port &port);
void initializePortBufferMaximumParameters(Port &port);
void initializeQueues(Port &port);
void initializeVoqs(Port &port);

bool addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id);
bool setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip);
Expand Down Expand Up @@ -352,7 +355,8 @@ class PortsOrch : public Orch, public Subject
bool getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uint8_t &index);

bool m_isQueueMapGenerated = false;
void generateQueueMapPerPort(const Port& port, FlexCounterQueueStates& queuesState);
void generateQueueMapPerPort(const Port& port, FlexCounterQueueStates& queuesState,
bool voq);
bool m_isPriorityGroupMapGenerated = false;
void generatePriorityGroupMapPerPort(const Port& port, FlexCounterPgStates& pgsState);
bool m_isPortCounterMapGenerated = false;
Expand Down