Skip to content

Commit

Permalink
Pospone QueueMap initialization until activation of counters (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-shirshov authored Jun 26, 2018
1 parent 72a7f3a commit 258ffe6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 55 deletions.
4 changes: 4 additions & 0 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ void FlexCounterOrch::doTask(Consumer &consumer)
}
else if(field == FLEX_COUNTER_STATUS_FIELD)
{
// Currently the counters are disabled by default
// The queue maps will be generated as soon as counters are enabled
gPortsOrch->generateQueueMap();

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value);
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
Expand Down
118 changes: 63 additions & 55 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,61 +1817,6 @@ void PortsOrch::initializeQueues(Port &port)
}

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

/* 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;

for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex)
{
std::ostringstream name;
name << port.m_alias << ":" << queueIndex;
FieldValueTuple tuple(name.str(), sai_serialize_object_id(port.m_queue_ids[queueIndex]));
queueVector.push_back(tuple);

FieldValueTuple queuePortTuple(
sai_serialize_object_id(port.m_queue_ids[queueIndex]),
sai_serialize_object_id(port.m_port_id));
queuePortVector.push_back(queuePortTuple);

FieldValueTuple queueIndexTuple(
sai_serialize_object_id(port.m_queue_ids[queueIndex]),
to_string(queueIndex));
queueIndexVector.push_back(queueIndexTuple);


string queueType;
if (getQueueType(port.m_queue_ids[queueIndex], queueType))
{
FieldValueTuple queueTypeTuple(
sai_serialize_object_id(port.m_queue_ids[queueIndex]),
queueType);
queueTypeVector.push_back(queueTypeTuple);
}

string key = getQueueFlexCounterTableKey(sai_serialize_object_id(port.m_queue_ids[queueIndex]));

std::string delimiter = "";
std::ostringstream counters_stream;
for (auto it = queueStatIds.begin(); it != queueStatIds.end(); it++)
{
counters_stream << delimiter << sai_serialize_queue_stat(*it);
delimiter = ",";
}

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fieldValues);
}

m_queueTable->set("", queueVector);
m_queuePortTable->set("", queuePortVector);
m_queueIndexTable->set("", queueIndexVector);
m_queueTypeTable->set("", queueTypeVector);
}

void PortsOrch::initializePriorityGroups(Port &port)
Expand Down Expand Up @@ -2420,6 +2365,69 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
return true;
}

void PortsOrch::generateQueueMap()
{
if (m_isQueueMapGenerated)
{
return;
}

for (const auto& it: m_portList)
{
generateQueueMapPerPort(it.second);
}

m_isQueueMapGenerated = true;
}

void PortsOrch::generateQueueMapPerPort(const Port& port)
{
/* 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;

for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex)
{
std::ostringstream name;
name << port.m_alias << ":" << queueIndex;

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

queueVector.emplace_back(name.str(), id);
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
queueIndexVector.emplace_back(id, to_string(queueIndex));

string queueType;
if (getQueueType(port.m_queue_ids[queueIndex], queueType))
{
queueTypeVector.emplace_back(id, queueType);
}

string key = getQueueFlexCounterTableKey(id);

std::string delimiter = "";
std::ostringstream counters_stream;
for (const auto& it: queueStatIds)
{
counters_stream << delimiter << sai_serialize_queue_stat(it);
delimiter = ",";
}

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fieldValues);
}

m_queueTable->set("", queueVector);
m_queuePortTable->set("", queuePortVector);
m_queueIndexTable->set("", queueIndexVector);
m_queueTypeTable->set("", queueTypeVector);
}

void PortsOrch::doTask(NotificationConsumer &consumer)
{
SWSS_LOG_ENTER();
Expand Down
5 changes: 5 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class PortsOrch : public Orch, public Subject
bool setHostIntfsOperStatus(sai_object_id_t id, bool up);
void updateDbPortOperStatus(sai_object_id_t id, sai_port_oper_status_t status);
bool bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_object_id_t &group_member_oid, acl_stage_type_t acl_stage = ACL_STAGE_INGRESS);

void generateQueueMap();
private:
unique_ptr<Table> m_counterTable;
unique_ptr<Table> m_portTable;
Expand Down Expand Up @@ -143,6 +145,9 @@ class PortsOrch : public Orch, public Subject
bool getPortSpeed(sai_object_id_t port_id, sai_uint32_t &speed);

bool getQueueType(sai_object_id_t queue_id, string &type);

bool m_isQueueMapGenerated = false;
void generateQueueMapPerPort(const Port& port);
};
#endif /* SWSS_PORTSORCH_H */

0 comments on commit 258ffe6

Please sign in to comment.