Skip to content

Commit d9f28b6

Browse files
authored
[SflowMgr] SamplingRate Update by Speed Change Added (sonic-net#1721)
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]>
1 parent 6c02acf commit d9f28b6

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

cfgmgr/sflowmgr.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,26 @@ void SflowMgr::sflowUpdatePortInfo(Consumer &consumer)
8989
port_info.admin = "";
9090
m_sflowPortConfMap[key] = port_info;
9191
}
92+
93+
bool speed_change = false;
94+
string new_speed = SFLOW_ERROR_SPEED_STR;
9295
for (auto i : values)
9396
{
9497
if (fvField(i) == "speed")
9598
{
96-
m_sflowPortConfMap[key].speed = fvValue(i);
99+
new_speed = fvValue(i);
97100
}
98101
}
102+
if (m_sflowPortConfMap[key].speed != new_speed)
103+
{
104+
m_sflowPortConfMap[key].speed = new_speed;
105+
speed_change = true;
106+
}
99107

100-
if (new_port)
108+
if (m_gEnable && m_intfAllConf)
101109
{
102-
if (m_gEnable && m_intfAllConf)
110+
// If the Local Conf is already present, dont't override it even though the speed is changed
111+
if (new_port || (speed_change && !m_sflowPortConfMap[key].local_conf))
103112
{
104113
vector<FieldValueTuple> fvs;
105114
sflowGetGlobalInfo(fvs, m_sflowPortConfMap[key].speed);
@@ -171,7 +180,7 @@ void SflowMgr::sflowGetGlobalInfo(vector<FieldValueTuple> &fvs, string speed)
171180
FieldValueTuple fv1("admin_state", "up");
172181
fvs.push_back(fv1);
173182

174-
if (speed != SFLOW_ERROR_SPEED_STR)
183+
if (speed != SFLOW_ERROR_SPEED_STR && sflowSpeedRateInitMap.find(speed) != sflowSpeedRateInitMap.end())
175184
{
176185
rate = sflowSpeedRateInitMap[speed];
177186
}

tests/test_sflow.py

+44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
class TestSflow:
24
speed_rate_table = {
35
"400000": "400000",
@@ -131,6 +133,48 @@ def test_ConfigDel(self, dvs, testlog):
131133

132134
expected_fields = {"SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE": rate}
133135
self.adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_SAMPLEPACKET", sample_session, expected_fields)
136+
137+
def test_SamplingRatePortCfgUpdate(self, dvs, testlog):
138+
'''
139+
This test checks if the SflowMgr updates the sampling rate
140+
1) When the Speed is Updated on the port and no local configuration has been given on the port
141+
Eg:
142+
config sflow enable
143+
config interface speed Ethernet0 25000 (Let's suppose Original Speed for Ethernet0 is 100G)
144+
show sflow interface | grep Ethernet0 (Should see a sampling rate of 25000 not 100000)
145+
'''
146+
self.setup_sflow(dvs)
147+
appldb = dvs.get_app_db()
148+
#dvs.runcmd("portconfig -p {} -s {}".format("Ethernet0", "25000"))
149+
self.cdb.update_entry("PORT", "Ethernet0", {'speed' : "25000"})
150+
expected_fields = {"sample_rate": self.speed_rate_table["25000"]}
151+
appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet0", expected_fields)
152+
153+
154+
def test_SamplingRateManualUpdate(self, dvs, testlog):
155+
'''
156+
This test checks if the SflowMgr updates the sampling rate
157+
1) When the Cfg Sflow Table is updated with sampling rate by the user, this rate should not be impacted by Port Speed Changes
158+
Eg:
159+
config sflow enable
160+
config sflow interface sample-rate Ethernet4 256
161+
config interface Ethernet0 speed 25000 (Original Speed for Ethernet0 is 100G)
162+
show sflow interface | grep Ethernet0 (Should see a sampling rate of 256 not 100000 or 25000
163+
'''
164+
self.setup_sflow(dvs)
165+
appldb = dvs.get_app_db()
166+
167+
session_params = {"admin_state": "up", "sample_rate": "256"}
168+
self.cdb.create_entry("SFLOW_SESSION", "Ethernet4", session_params)
169+
self.cdb.wait_for_field_match("SFLOW_SESSION", "Ethernet4", session_params)
170+
appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet4", {"sample_rate": "256"})
171+
172+
self.cdb.update_entry("PORT", "Ethernet4", {'speed' : "25000"})
173+
# The Check here is about the original value not getting changed.
174+
# If some bug was to appear, let's give it some time to get noticed
175+
time.sleep(1)
176+
appldb.wait_for_field_match("SFLOW_SESSION_TABLE", "Ethernet4", {"sample_rate": "256"})
177+
134178

135179
def test_Teardown(self, dvs, testlog):
136180
self.setup_sflow(dvs)

0 commit comments

Comments
 (0)