Skip to content

Commit

Permalink
Align watermark flow with port configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashinvd committed Oct 25, 2022
1 parent ab29920 commit ae96260
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 97 deletions.
14 changes: 14 additions & 0 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ extern FlowCounterRouteOrch *gFlowCounterRouteOrch;
#define PORT_KEY "PORT"
#define PORT_BUFFER_DROP_KEY "PORT_BUFFER_DROP"
#define QUEUE_KEY "QUEUE"
#define QUEUE_WATERMARK "QUEUE_WATERMARK"
#define PG_WATERMARK_KEY "PG_WATERMARK"
#define PG_DROP_KEY "PG_DROP"
#define RIF_KEY "RIF"
#define ACL_KEY "ACL"
#define TUNNEL_KEY "TUNNEL"
Expand Down Expand Up @@ -158,10 +160,22 @@ void FlexCounterOrch::doTask(Consumer &consumer)
else if(key == QUEUE_KEY)
{
gPortsOrch->generateQueueMap();
gPortsOrch->addQueueFlexCounters();
}
else if(key == QUEUE_WATERMARK)
{
gPortsOrch->generateQueueMap();
gPortsOrch->addQueueWatermarkFlexCounters();
}
else if(key == PG_DROP_KEY)
{
gPortsOrch->generatePriorityGroupMap();
gPortsOrch->addPriorityGroupFlexCounters();
}
else if(key == PG_WATERMARK_KEY)
{
gPortsOrch->generatePriorityGroupMap();
gPortsOrch->addPriorityGroupWatermarkFlexCounters();
}
}
if(gIntfsOrch && (key == RIF_KEY) && (value == "enable"))
Expand Down
234 changes: 181 additions & 53 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,9 @@ void PortsOrch::getCpuPort(Port &port)
port = m_cpuPort;
}

/*
* Create host_tx_ready field in PORT_TABLE of STATE-DB
* and set the field to false by default for the
/*
* Create host_tx_ready field in PORT_TABLE of STATE-DB
* and set the field to false by default for the
* front<Ethernet> port.
*/
void PortsOrch::initHostTxReadyState(Port &port)
Expand All @@ -1096,7 +1096,7 @@ void PortsOrch::initHostTxReadyState(Port &port)
if (hostTxReady.empty())
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
SWSS_LOG_INFO("initalize hostTxReady %s with status %s",
SWSS_LOG_INFO("initalize hostTxReady %s with status %s",
port.m_alias.c_str(), hostTxReady.c_str());
}
}
Expand All @@ -1110,13 +1110,13 @@ bool PortsOrch::setPortAdminStatus(Port &port, bool state)
attr.value.booldata = state;

/* Update the host_tx_ready to false before setting admin_state, when admin state is false */
if (!state)
if (!state)
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
SWSS_LOG_INFO("Set admin status DOWN host_tx_ready to false to port pid:%" PRIx64,
port.m_port_id);
}

sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
Expand All @@ -1135,14 +1135,14 @@ bool PortsOrch::setPortAdminStatus(Port &port, bool state)
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
}

/* Update the state table for host_tx_ready*/
if (state && (gbstatus == true) && (status == SAI_STATUS_SUCCESS) )
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "true");
SWSS_LOG_INFO("Set admin status UP host_tx_ready to true to port pid:%" PRIx64,
port.m_port_id);
}
}

return true;
}
Expand Down Expand Up @@ -1376,9 +1376,9 @@ bool PortsOrch::setPortPfcWatchdogStatus(sai_object_id_t portId, uint8_t pfcwd_b
SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, portId);
return false;
}

p.m_pfcwd_sw_bitmask = pfcwd_bitmask;

m_portList[p.m_alias] = p;

SWSS_LOG_INFO("Set PFC watchdog port id=0x%" PRIx64 ", bitmast=0x%x", portId, pfcwd_bitmask);
Expand All @@ -1396,9 +1396,9 @@ bool PortsOrch::getPortPfcWatchdogStatus(sai_object_id_t portId, uint8_t *pfcwd_
SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, portId);
return false;
}

*pfcwd_bitmask = p.m_pfcwd_sw_bitmask;

return true;
}

Expand Down Expand Up @@ -2798,12 +2798,28 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
if (m_isPriorityGroupMapGenerated)
{
generatePriorityGroupMapPerPort(p);
if (m_isPriorityGroupFlexCountersAdded)
{
addPriorityGroupFlexCountersPerPort(p);
}
if (m_isPriorityGroupWatermarkFlexCountersAdded)
{
addPriorityGroupWatermarkFlexCountersPerPort(p);
}
}

/* when a port is added and queue map counter is enabled --> we need to add queue map counter for it */
if (m_isQueueMapGenerated)
{
generateQueueMapPerPort(p, false);
if (m_isQueueFlexCountersAdded)
{
addQueueFlexCountersPerPort(p);
}
if (m_isQueueWatermarkFlexCountersAdded)
{
addQueueWatermarkFlexCountersPerPort(p);
}
}

PortUpdate update = { p, true };
Expand Down Expand Up @@ -3778,10 +3794,10 @@ void PortsOrch::doPortTask(Consumer &consumer)
continue;
}
}

/* create host_tx_ready field in state-db */
initHostTxReadyState(p);

/* Last step set port admin status */
if (!admin_status.empty() && (p.m_admin_state_up != (admin_status == "up")))
{
Expand Down Expand Up @@ -6135,18 +6151,90 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, bool voq)
queueTypeVector.emplace_back(id, queueType);
queueIndexVector.emplace_back(id, to_string(queueRealIndex));
}
}

// Install a flex counter for this queue to track stats
std::unordered_set<string> counter_stats;
for (const auto& it: queue_stat_ids)
if (voq)
{
m_voqTable->set("", queueVector);
}
else
{
m_queueTable->set("", queueVector);
}
m_queuePortTable->set("", queuePortVector);
m_queueIndexTable->set("", queueIndexVector);
m_queueTypeTable->set("", queueTypeVector);

CounterCheckOrch::getInstance().addPort(port);
}

void PortsOrch::addQueueFlexCounters()
{
if (m_isQueueFlexCountersAdded)
{
return;
}

for (const auto& it: m_portList)
{
if (it.second.m_type == Port::PHY)
{
counter_stats.emplace(sai_serialize_queue_stat(it));
addQueueFlexCountersPerPort(it.second);
}
queue_stat_manager.setCounterIdList(queue_ids[queueIndex], CounterType::QUEUE, counter_stats);
}

if (voq) {
continue;
}
m_isQueueFlexCountersAdded = true;
}


void PortsOrch::addQueueFlexCountersPerPort(const Port& port)
{
std::vector<sai_object_id_t> queue_ids;
if (voq)
{
queue_ids = m_port_voq_ids[port.m_alias];
}
else
{
queue_ids = port.m_queue_ids;
}
for (size_t queueIndex = 0; queueIndex < queue_ids.size(); ++queueIndex)
{
// 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(queue_ids[queueIndex], CounterType::QUEUE, counter_stats);
}
}

void PortsOrch::addQueueWatermarkFlexCounters()
{
if (m_isQueueWatermarkFlexCountersAdded)
{
return;
}

for (const auto& it: m_portList)
{
if (it.second.m_type == Port::PHY)
{
addQueueWatermarkFlexCountersPerPort(it.second);
}
}

m_isQueueWatermarkFlexCountersAdded = true;
}

void PortsOrch::addQueueWatermarkFlexCountersPerPort(const Port& port)
{
/* Add stat counters to flex_counter */

for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex)
{
const auto id = sai_serialize_object_id(port.m_queue_ids[queueIndex]);

/* add watermark queue counters */
string key = getQueueWatermarkFlexCounterTableKey(id);
Expand All @@ -6164,20 +6252,6 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, bool voq)

m_flexCounterTable->set(key, fieldValues);
}

if (voq)
{
m_voqTable->set("", queueVector);
}
else
{
m_queueTable->set("", queueVector);
}
m_queuePortTable->set("", queuePortVector);
m_queueIndexTable->set("", queueIndexVector);
m_queueTypeTable->set("", queueTypeVector);

CounterCheckOrch::getInstance().addPort(port);
}

void PortsOrch::generatePriorityGroupMap()
Expand Down Expand Up @@ -6242,25 +6316,42 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
pgVector.emplace_back(name.str(), id);
pgPortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id));
pgIndexVector.emplace_back(id, to_string(pgIndex));
}

string key = getPriorityGroupWatermarkFlexCounterTableKey(id);
m_pgTable->set("", pgVector);
m_pgPortTable->set("", pgPortVector);
m_pgIndexTable->set("", pgIndexVector);

std::string delimiter = "";
std::ostringstream counters_stream;
/* Add watermark counters to flex_counter */
for (const auto& it: ingressPriorityGroupWatermarkStatIds)
CounterCheckOrch::getInstance().addPort(port);
}

void PortsOrch::addPriorityGroupFlexCounters()
{
if (m_isPriorityGroupFlexCountersAdded)
{
return;
}

for (const auto& it: m_portList)
{
if (it.second.m_type == Port::PHY)
{
counters_stream << delimiter << sai_serialize_ingress_priority_group_stat(it);
delimiter = comma;
addPriorityGroupFlexCountersPerPort(it.second);
}
}

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(PG_COUNTER_ID_LIST, counters_stream.str());
m_flexCounterTable->set(key, fieldValues);
m_isPriorityGroupFlexCountersAdded = true;
}

void PortsOrch::addPriorityGroupFlexCountersPerPort(const Port& port)
{
for (size_t pgIndex = 0; pgIndex < port.m_priority_group_ids.size(); ++pgIndex)
{
const auto id = sai_serialize_object_id(port.m_priority_group_ids[pgIndex]);

delimiter = "";
string delimiter = "";
std::ostringstream ingress_pg_drop_packets_counters_stream;
key = getPriorityGroupDropPacketsFlexCounterTableKey(id);
string key = getPriorityGroupDropPacketsFlexCounterTableKey(id);
/* Add dropped packets counters to flex_counter */
for (const auto& it: ingressPriorityGroupDropStatIds)
{
Expand All @@ -6270,16 +6361,53 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
delimiter = comma;
}
}
fieldValues.clear();
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(PG_COUNTER_ID_LIST, ingress_pg_drop_packets_counters_stream.str());
m_flexCounterTable->set(key, fieldValues);
}
}

m_pgTable->set("", pgVector);
m_pgPortTable->set("", pgPortVector);
m_pgIndexTable->set("", pgIndexVector);
void PortsOrch::addPriorityGroupWatermarkFlexCounters()
{
if (m_isPriorityGroupWatermarkFlexCountersAdded)
{
return;
}

CounterCheckOrch::getInstance().addPort(port);
for (const auto& it: m_portList)
{
if (it.second.m_type == Port::PHY)
{
addPriorityGroupWatermarkFlexCountersPerPort(it.second);
}
}

m_isPriorityGroupWatermarkFlexCountersAdded = true;
}

void PortsOrch::addPriorityGroupWatermarkFlexCountersPerPort(const Port& port)
{
/* Add stat counters to flex_counter */

for (size_t pgIndex = 0; pgIndex < port.m_priority_group_ids.size(); ++pgIndex)
{
const auto id = sai_serialize_object_id(port.m_priority_group_ids[pgIndex]);

string key = getPriorityGroupWatermarkFlexCounterTableKey(id);

std::string delimiter = "";
std::ostringstream counters_stream;
/* Add watermark counters to flex_counter */
for (const auto& it: ingressPriorityGroupWatermarkStatIds)
{
counters_stream << delimiter << sai_serialize_ingress_priority_group_stat(it);
delimiter = comma;
}

vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(PG_COUNTER_ID_LIST, counters_stream.str());
m_flexCounterTable->set(key, fieldValues);
}
}

void PortsOrch::generatePortCounterMap()
Expand Down
Loading

0 comments on commit ae96260

Please sign in to comment.