Skip to content

Commit

Permalink
Handle the clear request for 'Q_SHARED_ALL' (sonic-net#1653)
Browse files Browse the repository at this point in the history
What I did
Add handling the clear request for 'Q_SHARED_ALL'

Why I did it
In  sonic-net/sonic-utilities#1149 added the following new commands

sonic-clear queue persistent-watermark all
sonic-clear queue watermark all

Without these changes, commands will result in
https://github.com/Azure/sonic-swss/blob/master/orchagent/watermarkorch.cpp#L221

Signed-off-by: Petro Bratash <petrox.bratash@intel.com>
  • Loading branch information
bratashX authored and raphaelt-nvidia committed Oct 5, 2021
1 parent 94da401 commit 61a7f4e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
22 changes: 18 additions & 4 deletions orchagent/watermarkorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define CLEAR_PG_SHARED_REQUEST "PG_SHARED"
#define CLEAR_QUEUE_SHARED_UNI_REQUEST "Q_SHARED_UNI"
#define CLEAR_QUEUE_SHARED_MULTI_REQUEST "Q_SHARED_MULTI"
#define CLEAR_QUEUE_SHARED_ALL_REQUEST "Q_SHARED_ALL"
#define CLEAR_BUFFER_POOL_REQUEST "BUFFER_POOL"
#define CLEAR_HEADROOM_POOL_REQUEST "HEADROOM_POOL"

Expand Down Expand Up @@ -92,7 +93,7 @@ void WatermarkOrch::doTask(Consumer &consumer)

void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vector<FieldValueTuple> &fvt)
{
SWSS_LOG_ENTER();
SWSS_LOG_ENTER();
if (key == "TELEMETRY_INTERVAL")
{
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
Expand Down Expand Up @@ -153,7 +154,7 @@ void WatermarkOrch::doTask(NotificationConsumer &consumer)
init_pg_ids();
}

if (m_multicast_queue_ids.empty() and m_unicast_queue_ids.empty())
if (m_multicast_queue_ids.empty() and m_unicast_queue_ids.empty() and m_all_queue_ids.empty())
{
init_queue_ids();
}
Expand Down Expand Up @@ -204,6 +205,12 @@ void WatermarkOrch::doTask(NotificationConsumer &consumer)
"SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES",
m_multicast_queue_ids);
}
else if (data == CLEAR_QUEUE_SHARED_ALL_REQUEST)
{
clearSingleWm(table,
"SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES",
m_all_queue_ids);
}
else if (data == CLEAR_BUFFER_POOL_REQUEST)
{
clearSingleWm(table,
Expand Down Expand Up @@ -232,7 +239,7 @@ void WatermarkOrch::doTask(SelectableTimer &timer)
init_pg_ids();
}

if (m_multicast_queue_ids.empty() and m_unicast_queue_ids.empty())
if (m_multicast_queue_ids.empty() and m_unicast_queue_ids.empty() and m_all_queue_ids.empty())
{
init_queue_ids();
}
Expand Down Expand Up @@ -261,6 +268,9 @@ void WatermarkOrch::doTask(SelectableTimer &timer)
clearSingleWm(m_periodicWatermarkTable.get(),
"SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES",
m_multicast_queue_ids);
clearSingleWm(m_periodicWatermarkTable.get(),
"SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES",
m_all_queue_ids);
clearSingleWm(m_periodicWatermarkTable.get(),
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES",
gBufferOrch->getBufferPoolNameOidMap());
Expand Down Expand Up @@ -299,10 +309,14 @@ void WatermarkOrch::init_queue_ids()
{
m_unicast_queue_ids.push_back(id);
}
else
else if (fv.second == "SAI_QUEUE_TYPE_MULTICAST")
{
m_multicast_queue_ids.push_back(id);
}
else if (fv.second == "SAI_QUEUE_TYPE_ALL")
{
m_all_queue_ids.push_back(id);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions orchagent/watermarkorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class WatermarkOrch : public Orch

std::vector<sai_object_id_t> m_unicast_queue_ids;
std::vector<sai_object_id_t> m_multicast_queue_ids;
std::vector<sai_object_id_t> m_all_queue_ids;
std::vector<sai_object_id_t> m_pg_ids;
};

Expand Down
32 changes: 30 additions & 2 deletions tests/test_watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ def set_up(self, dvs):

self.uc_q = []
self.mc_q = []
self.all_q = []

for q in self.qs:
if self.qs.index(q) % 16 < 8:
if self.qs.index(q) % 16 < 5:
tbl.set('', [(q, "SAI_QUEUE_TYPE_UNICAST")])
self.uc_q.append(q)
else:
elif self.qs.index(q) % 16 < 10:
tbl.set('', [(q, "SAI_QUEUE_TYPE_MULTICAST")])
self.mc_q.append(q)
else:
tbl.set('', [(q, "SAI_QUEUE_TYPE_ALL")])
self.all_q.append(q)

def test_telemetry_period(self, dvs):
self.setup_dbs(dvs)
Expand Down Expand Up @@ -279,6 +283,30 @@ def test_clear(self, dvs):
self.verify_value(dvs, self.mc_q, WmTables.persistent, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.uc_q, WmTables.user, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.mc_q, WmTables.user, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.all_q, WmTables.user, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.all_q, WmTables.persistent, SaiWmStats.queue_shared, "288")

# clear queue all watermark, and verify that multicast and unicast watermarks are not affected

# clear persistent all watermark
exitcode, output = dvs.runcmd("sonic-clear queue persistent-watermark all")
time.sleep(1)
assert exitcode == 0, "CLI failure: %s" % output
# make sure it cleared
self.verify_value(dvs, self.all_q, WmTables.persistent, SaiWmStats.queue_shared, "0")

# clear user all watermark
exitcode, output = dvs.runcmd("sonic-clear queue watermark all")
time.sleep(1)
assert exitcode == 0, "CLI failure: %s" % output
# make sure it cleared
self.verify_value(dvs, self.all_q, WmTables.user, SaiWmStats.queue_shared, "0")

# make sure the rest is untouched
self.verify_value(dvs, self.mc_q, WmTables.user, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.mc_q, WmTables.persistent, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.uc_q, WmTables.user, SaiWmStats.queue_shared, "288")
self.verify_value(dvs, self.uc_q, WmTables.persistent, SaiWmStats.queue_shared, "0")

self.enable_unittests(dvs, "false")

Expand Down

0 comments on commit 61a7f4e

Please sign in to comment.