Skip to content

Commit

Permalink
[SflowMgr] SamplingRate Update by Speed Change Added (sonic-net#1721)
Browse files Browse the repository at this point in the history
Currently, the SflowMgr::sflowUpdatePortInfo method updates the sampling-rate only when adding a new-port. Updated the method to be active for speed change notifications all the time.

Co-authored-by: Vivek Reddy Karri <[email protected]>
  • Loading branch information
vivekrnv and vivekrnv authored Apr 25, 2021
1 parent 6c02acf commit d9f28b6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cfgmgr/sflowmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,26 @@ void SflowMgr::sflowUpdatePortInfo(Consumer &consumer)
port_info.admin = "";
m_sflowPortConfMap[key] = port_info;
}

bool speed_change = false;
string new_speed = SFLOW_ERROR_SPEED_STR;
for (auto i : values)
{
if (fvField(i) == "speed")
{
m_sflowPortConfMap[key].speed = fvValue(i);
new_speed = fvValue(i);
}
}
if (m_sflowPortConfMap[key].speed != new_speed)
{
m_sflowPortConfMap[key].speed = new_speed;
speed_change = true;
}

if (new_port)
if (m_gEnable && m_intfAllConf)
{
if (m_gEnable && m_intfAllConf)
// If the Local Conf is already present, dont't override it even though the speed is changed
if (new_port || (speed_change && !m_sflowPortConfMap[key].local_conf))
{
vector<FieldValueTuple> fvs;
sflowGetGlobalInfo(fvs, m_sflowPortConfMap[key].speed);
Expand Down Expand Up @@ -171,7 +180,7 @@ void SflowMgr::sflowGetGlobalInfo(vector<FieldValueTuple> &fvs, string speed)
FieldValueTuple fv1("admin_state", "up");
fvs.push_back(fv1);

if (speed != SFLOW_ERROR_SPEED_STR)
if (speed != SFLOW_ERROR_SPEED_STR && sflowSpeedRateInitMap.find(speed) != sflowSpeedRateInitMap.end())
{
rate = sflowSpeedRateInitMap[speed];
}
Expand Down
44 changes: 44 additions & 0 deletions tests/test_sflow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

class TestSflow:
speed_rate_table = {
"400000": "400000",
Expand Down Expand Up @@ -131,6 +133,48 @@ def test_ConfigDel(self, dvs, testlog):

expected_fields = {"SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE": rate}
self.adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_SAMPLEPACKET", sample_session, expected_fields)

def test_SamplingRatePortCfgUpdate(self, dvs, testlog):
'''
This test checks if the SflowMgr updates the sampling rate
1) When the Speed is Updated on the port and no local configuration has been given on the port
Eg:
config sflow enable
config interface speed Ethernet0 25000 (Let's suppose Original Speed for Ethernet0 is 100G)
show sflow interface | grep Ethernet0 (Should see a sampling rate of 25000 not 100000)
'''
self.setup_sflow(dvs)
appldb = dvs.get_app_db()
#dvs.runcmd("portconfig -p {} -s {}".format("Ethernet0", "25000"))
self.cdb.update_entry("PORT", "Ethernet0", {'speed' : "25000"})
expected_fields = {"sample_rate": self.speed_rate_table["25000"]}
appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet0", expected_fields)


def test_SamplingRateManualUpdate(self, dvs, testlog):
'''
This test checks if the SflowMgr updates the sampling rate
1) When the Cfg Sflow Table is updated with sampling rate by the user, this rate should not be impacted by Port Speed Changes
Eg:
config sflow enable
config sflow interface sample-rate Ethernet4 256
config interface Ethernet0 speed 25000 (Original Speed for Ethernet0 is 100G)
show sflow interface | grep Ethernet0 (Should see a sampling rate of 256 not 100000 or 25000
'''
self.setup_sflow(dvs)
appldb = dvs.get_app_db()

session_params = {"admin_state": "up", "sample_rate": "256"}
self.cdb.create_entry("SFLOW_SESSION", "Ethernet4", session_params)
self.cdb.wait_for_field_match("SFLOW_SESSION", "Ethernet4", session_params)
appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet4", {"sample_rate": "256"})

self.cdb.update_entry("PORT", "Ethernet4", {'speed' : "25000"})
# The Check here is about the original value not getting changed.
# If some bug was to appear, let's give it some time to get noticed
time.sleep(1)
appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet4", {"sample_rate": "256"})


def test_Teardown(self, dvs, testlog):
self.setup_sflow(dvs)
Expand Down

0 comments on commit d9f28b6

Please sign in to comment.