Skip to content

Commit

Permalink
Add lacp_rate config
Browse files Browse the repository at this point in the history
Signed-off-by: Myron Sosyak <myronx.sosyak@intel.com>
  • Loading branch information
Anton authored and Myron Sosyak committed Mar 21, 2022
1 parent bea0b70 commit 3e38104
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
20 changes: 16 additions & 4 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/teammgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
49 changes: 48 additions & 1 deletion tests/test_portchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down

0 comments on commit 3e38104

Please sign in to comment.