Skip to content

Commit

Permalink
[201911] Add SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS counter,…
Browse files Browse the repository at this point in the history
… create new FlexCounter group (#2263)

Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com>

Appropriate PR in master #1600

What I did
Added possibility to calculate Priority Group drop packet counters

Why I did it
Need to merge feature from master to 201911

How I verified it
Setup a testbed like this: hostA - DUT – hostB, layer 2 or 3 forwarding between A/B. better to use layer 3 because by using layer 3 we can easily designate DSCP of the packet.
Make sure all entries for forwarding have been correctly established, ARP, routing, neighbor, …
Assume you will send traffic from A to B, start PFC storm on host B. if you are using SONiC testbed, you can start PFC storm on the fanout switch. (you can consult Volodymyr regarding how to start PFC storm)
Check and update the buffer profile on the DUT’s ports connected to host A:

Let’s say it’s Ethernet8, using the following command:
admin@arc-mtbc-1001:~$ redis-cli -n 4 hgetall "BUFFER_PG|Ethernet8|3-4"
1) "profile"
2) "[BUFFER_PROFILE|pg_lossless_25000_5m_profile]"
admin@arc-mtbc-1001:~$ redis-cli -n 4 hset "BUFFER_PROFILE|pg_lossless_25000_5m_profile" dynamic_th -8
and then save config and reload config.
Send packets from host A to host B, make sure the DSCP is 3.
You should be able to observe discard on PG 3 soon.
  • Loading branch information
ayurkiv-nvda authored Jun 22, 2022
1 parent 923db73 commit 805f4bb
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ unordered_map<string, string> flexCounterGroupMap =
{"PFCWD", PFC_WD_FLEX_COUNTER_GROUP},
{"QUEUE_WATERMARK", QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"PG_WATERMARK", PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"PG_DROP", PG_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP},
{BUFFER_POOL_WATERMARK_KEY, BUFFER_POOL_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"RIF", RIF_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"DEBUG_COUNTER", DEBUG_COUNTER_FLEX_COUNTER_GROUP},
Expand Down
32 changes: 32 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern FdbOrch *gFdbOrch;
#define QUEUE_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define PG_DROP_FLEX_STAT_COUNTER_POLL_MSECS "10000"


static map<string, sai_port_fec_mode_t> fec_mode_map =
Expand Down Expand Up @@ -141,6 +142,11 @@ static const vector<sai_ingress_priority_group_stat_t> ingressPriorityGroupWater
SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES,
};

static const vector<sai_ingress_priority_group_stat_t> ingressPriorityGroupDropStatIds =
{
SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS
};

static char* hostif_vlan_tag[] = {
[SAI_HOSTIF_VLAN_TAG_STRIP] = "SAI_HOSTIF_VLAN_TAG_STRIP",
[SAI_HOSTIF_VLAN_TAG_KEEP] = "SAI_HOSTIF_VLAN_TAG_KEEP",
Expand Down Expand Up @@ -230,6 +236,11 @@ PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames)
fieldValues.emplace_back(POLL_INTERVAL_FIELD, PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS);
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR);
m_flexCounterGroupTable->set(PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);

fieldValues.clear();
fieldValues.emplace_back(POLL_INTERVAL_FIELD, PG_DROP_FLEX_STAT_COUNTER_POLL_MSECS);
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(PG_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
}
catch (const runtime_error &e)
{
Expand Down Expand Up @@ -1568,6 +1579,11 @@ string PortsOrch::getPriorityGroupWatermarkFlexCounterTableKey(string key)
return string(PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}

string PortsOrch::getPriorityGroupDropPacketsFlexCounterTableKey(string key)
{
return string(PG_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
}

bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -3725,6 +3741,22 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
fieldValues.emplace_back(PG_COUNTER_ID_LIST, counters_stream.str());

m_flexCounterTable->set(key, fieldValues);

delimiter = "";
std::ostringstream ingress_pg_drop_packets_counters_stream;
key = getPriorityGroupDropPacketsFlexCounterTableKey(id);
/* Add dropped packets counters to flex_counter */
for (const auto& it: ingressPriorityGroupDropStatIds)
{
ingress_pg_drop_packets_counters_stream << delimiter << sai_serialize_ingress_priority_group_stat(it);
if (delimiter.empty())
{
delimiter = comma;
}
}
fieldValues.clear();
fieldValues.emplace_back(PG_COUNTER_ID_LIST, ingress_pg_drop_packets_counters_stream.str());
m_flexCounterTable->set(key, fieldValues);
}

m_pgTable->set("", pgVector);
Expand Down
2 changes: 2 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_STAT_COUNTER"
#define QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_WATERMARK_STAT_COUNTER"
#define PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP "PG_WATERMARK_STAT_COUNTER"
#define PG_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP "PG_DROP_STAT_COUNTER"


typedef std::vector<sai_uint32_t> PortSupportedSpeeds;
Expand Down Expand Up @@ -114,6 +115,7 @@ class PortsOrch : public Orch, public Subject
std::string getPortFlexCounterTableKey(std::string s);
std::string getPortBuffDropFlexCounterTableKey(std::string s);
std::string getPriorityGroupWatermarkFlexCounterTableKey(std::string s);
std::string getPriorityGroupDropPacketsFlexCounterTableKey(std::string s);

shared_ptr<DBConnector> m_counter_db;
shared_ptr<DBConnector> m_flex_db;
Expand Down
88 changes: 88 additions & 0 deletions tests/test_pg_drop_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from swsscommon import swsscommon
import os
import re
import time
import json
import pytest
import redis


pg_drop_attr = "SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS"

class TestPGDropCounter(object):
DEFAULT_POLL_INTERVAL = 10

def enable_unittests(self, dvs, status):
db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL")
fvp = swsscommon.FieldValuePairs()
ntf.send("enable_unittests", status, fvp)

def set_counter(self, dvs, obj_id, attr, val):

db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL")

r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB)
rid = r.hget("VIDTORID", obj_id)

assert rid is not None
fvp = swsscommon.FieldValuePairs([(attr, val)])
key = rid

ntf.send("set_stats", key, fvp)

def populate_asic(self, dvs, val):
for obj_id in self.pgs:
self.set_counter(dvs, obj_id, pg_drop_attr, val)

def verify_value(self, dvs, obj_ids, entry_name, expected_value):
counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0)
table = swsscommon.Table(counters_db, "COUNTERS")

for obj_id in obj_ids:
ret = table.get(obj_id)
status = ret[0]
assert status
keyvalues = ret[1]
found = False
for key, value in keyvalues:
if key == entry_name:
assert value == expected_value, "Saved value not the same as expected"
found = True
assert found, "no such entry found"

def get_oids(self, dvs, obj_type):
db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
tbl = swsscommon.Table(db, "ASIC_STATE:{0}".format(obj_type))
keys = tbl.getKeys()
return keys

def set_up_flex_counter(self, dvs):
for pg in self.pgs:
dvs.runcmd("redis-cli -n 5 hset 'FLEX_COUNTER_TABLE:PG_DROP_STAT_COUNTER:{}' ".format(pg) + "PG_COUNTER_ID_LIST '{}'".format(pg_drop_attr))

dvs.runcmd("redis-cli -n 4 hset 'FLEX_COUNTER_TABLE|PG_DROP' 'FLEX_COUNTER_STATUS' 'enable'")

self.populate_asic(dvs, "0")


def test_pg_drop(self, dvs):
try:
self.pgs = self.get_oids(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP")
self.set_up_flex_counter(dvs)

self.populate_asic(dvs, "100")
time.sleep(self.DEFAULT_POLL_INTERVAL + 1)
self.verify_value(dvs, self.pgs, pg_drop_attr , "100")

self.populate_asic(dvs, "123")
time.sleep(self.DEFAULT_POLL_INTERVAL + 1)
self.verify_value(dvs, self.pgs, pg_drop_attr, "123")
finally:
dvs.runcmd("redis-cli -n 4 DEL 'FLEX_COUNTER_TABLE|PG_DROP'")

for pg in self.pgs:
dvs.runcmd("redis-cli -n 5 DEL 'FLEX_COUNTER_TABLE:PG_DROP_STAT_COUNTER:{}' ".format(pg))


0 comments on commit 805f4bb

Please sign in to comment.