From 3e3810491e73b1d804e8d8c2ca1a4d132f4667be Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 20 Jan 2022 04:16:28 -0800 Subject: [PATCH] Add lacp_rate config Signed-off-by: Myron Sosyak --- cfgmgr/teammgr.cpp | 20 ++++++++++++---- cfgmgr/teammgr.h | 2 +- tests/test_portchannel.py | 49 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/cfgmgr/teammgr.cpp b/cfgmgr/teammgr.cpp index ad8572e07b1..98f5df0f37d 100644 --- a/cfgmgr/teammgr.cpp +++ b/cfgmgr/teammgr.cpp @@ -206,6 +206,7 @@ void TeamMgr::doLagTask(Consumer &consumer) { int min_links = 0; bool fallback = false; + bool fast_rate = false; string admin_status = DEFAULT_ADMIN_STATUS_STR; string mtu = DEFAULT_MTU_STR; string learn_mode; @@ -247,12 +248,18 @@ void TeamMgr::doLagTask(Consumer &consumer) { tpid = fvValue(i); SWSS_LOG_INFO("Get TPID %s", tpid.c_str()); - } + } + else if (fvField(i) == "fast_rate") + { + fast_rate = fvValue(i) == "true"; + SWSS_LOG_INFO("Get fast_rate `%s`", + fast_rate ? "true" : "false"); + } } if (m_lagList.find(alias) == m_lagList.end()) { - if (addLag(alias, min_links, fallback) == task_need_retry) + if (addLag(alias, min_links, fallback, fast_rate) == task_need_retry) { it++; continue; @@ -496,7 +503,7 @@ bool TeamMgr::setLagLearnMode(const string &alias, const string &learn_mode) return true; } -task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fallback) +task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fallback, bool fast_rate) { SWSS_LOG_ENTER(); @@ -553,6 +560,11 @@ task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fal conf << ",\"fallback\":true"; } + if (fast_rate) + { + conf << ",\"fast_rate\":true"; + } + conf << "}}'"; SWSS_LOG_INFO("Port channel %s teamd configuration: %s", @@ -595,7 +607,7 @@ bool TeamMgr::removeLag(const string &alias) } // Port-channel names are in the pattern of "PortChannel####" -// +// // The LACP key could be generated in 3 ways based on the value in config DB: // 1. "auto" - LACP key is extracted from the port-channel name and is set to be the number at the end of the port-channel name // We are adding 1 at the beginning to avoid LACP key collisions between similar LACP keys e.g. PortChannel10 and PortChannel010. diff --git a/cfgmgr/teammgr.h b/cfgmgr/teammgr.h index c1b5d525c02..8118995c523 100644 --- a/cfgmgr/teammgr.h +++ b/cfgmgr/teammgr.h @@ -40,7 +40,7 @@ class TeamMgr : public Orch void doLagMemberTask(Consumer &consumer); void doPortUpdateTask(Consumer &consumer); - task_process_status addLag(const std::string &alias, int min_links, bool fall_back); + task_process_status addLag(const std::string &alias, int min_links, bool fall_back, bool fast_rate); bool removeLag(const std::string &alias); task_process_status addLagMember(const std::string &lag, const std::string &member); bool removeLagMember(const std::string &lag, const std::string &member); diff --git a/tests/test_portchannel.py b/tests/test_portchannel.py index ee612ec46d1..32ac70ab529 100644 --- a/tests/test_portchannel.py +++ b/tests/test_portchannel.py @@ -89,6 +89,53 @@ def test_Portchannel(self, dvs, testlog): lagms = lagmtbl.getKeys() assert len(lagms) == 0 + def test_Portchannel_fast_rate(self, dvs, testlog): + portchannel_slow = ("PortChannel0003", "Ethernet16", 0) + portchannel_fast = ("PortChannel0004", "Ethernet20", 0) + + self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + + # Create PortChannels + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL") + fvs_base = [("admin_status", "up"), ("mtu", "9100"), ("oper_status", "up"), ("lacp_key", "auto")] + + fvs_slow = swsscommon.FieldValuePairs(fvs_base + [("fast_rate", "false")]) + tbl.set(portchannel_slow[0], fvs_slow) + + fvs_fast = swsscommon.FieldValuePairs(fvs_base + [("fast_rate", "true")]) + tbl.set(portchannel_fast[0], fvs_fast) + time.sleep(1) + + # Add members to PortChannels + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER") + fvs = swsscommon.FieldValuePairs([("NULL", "NULL")]) + + for portchannel in portchannel_slow, portchannel_fast: + tbl.set(portchannel[0] + "|" + portchannel[1], fvs) + time.sleep(1) + + # test fast rate was not set on portchannel_slow + output = dvs.runcmd("teamdctl {} state dump".format(portchannel_slow[0]))[1] + port_state_dump = json.loads(output) + assert not port_state_dump["runner"]["fast_rate"] + + # test fast rate was set on portchannel_fast + output = dvs.runcmd("teamdctl {} state dump".format(portchannel_fast[0]))[1] + port_state_dump = json.loads(output) + assert port_state_dump["runner"]["fast_rate"] + + # remove PortChannel members + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER") + for portchannel in portchannel_slow, portchannel_fast: + tbl._del(portchannel[0] + "|" + portchannel[1]) + time.sleep(1) + + # remove PortChannel + tbl = swsscommon.Table(self.cdb, "PORTCHANNEL") + for portchannel in portchannel_slow, portchannel_fast: + tbl._del(portchannel[0]) + time.sleep(1) + def test_Portchannel_lacpkey(self, dvs, testlog): portchannelNamesAuto = [("PortChannel001", "Ethernet0", 1001), ("PortChannel002", "Ethernet4", 1002), @@ -108,7 +155,7 @@ def test_Portchannel_lacpkey(self, dvs, testlog): for portchannel in portchannelNamesAuto: tbl.set(portchannel[0], fvs) - + fvs_no_lacp_key = swsscommon.FieldValuePairs( [("admin_status", "up"), ("mtu", "9100"), ("oper_status", "up")]) tbl.set(portchannelNames[0][0], fvs_no_lacp_key)