From d9f28b64255db54310d3398119f13dfb3203f311 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Date: Sun, 25 Apr 2021 00:43:15 -0400 Subject: [PATCH] [SflowMgr] SamplingRate Update by Speed Change Added (#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 --- cfgmgr/sflowmgr.cpp | 17 +++++++++++++---- tests/test_sflow.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/cfgmgr/sflowmgr.cpp b/cfgmgr/sflowmgr.cpp index b7aeb8bbc18a..0e328122677f 100644 --- a/cfgmgr/sflowmgr.cpp +++ b/cfgmgr/sflowmgr.cpp @@ -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 fvs; sflowGetGlobalInfo(fvs, m_sflowPortConfMap[key].speed); @@ -171,7 +180,7 @@ void SflowMgr::sflowGetGlobalInfo(vector &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]; } diff --git a/tests/test_sflow.py b/tests/test_sflow.py index 761655717761..f70880fce66d 100644 --- a/tests/test_sflow.py +++ b/tests/test_sflow.py @@ -1,3 +1,5 @@ +import time + class TestSflow: speed_rate_table = { "400000": "400000", @@ -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)