Skip to content

Commit a0f955d

Browse files
globaltroubleAntonMyron Sosyak
authored andcommitted
[swss/cfgmgr] teammgr configure lacp rate (sonic-net#2121)
* add lacp_rate config * add lacp_rate to teammgr addLag params * docs for portchannel db config * add test Co-authored-by: Anton <[email protected]> Co-authored-by: Myron Sosyak <[email protected]>
1 parent 1862612 commit a0f955d

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

cfgmgr/teammgr.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void TeamMgr::doLagTask(Consumer &consumer)
252252
{
253253
int min_links = 0;
254254
bool fallback = false;
255+
bool fast_rate = false;
255256
string admin_status = DEFAULT_ADMIN_STATUS_STR;
256257
string mtu = DEFAULT_MTU_STR;
257258
string learn_mode;
@@ -293,12 +294,18 @@ void TeamMgr::doLagTask(Consumer &consumer)
293294
{
294295
tpid = fvValue(i);
295296
SWSS_LOG_INFO("Get TPID %s", tpid.c_str());
296-
}
297+
}
298+
else if (fvField(i) == "fast_rate")
299+
{
300+
fast_rate = fvValue(i) == "true";
301+
SWSS_LOG_INFO("Get fast_rate `%s`",
302+
fast_rate ? "true" : "false");
303+
}
297304
}
298305

299306
if (m_lagList.find(alias) == m_lagList.end())
300307
{
301-
if (addLag(alias, min_links, fallback) == task_need_retry)
308+
if (addLag(alias, min_links, fallback, fast_rate) == task_need_retry)
302309
{
303310
it++;
304311
continue;
@@ -553,7 +560,7 @@ bool TeamMgr::setLagLearnMode(const string &alias, const string &learn_mode)
553560
return true;
554561
}
555562

556-
task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fallback)
563+
task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fallback, bool fast_rate)
557564
{
558565
SWSS_LOG_ENTER();
559566

@@ -610,6 +617,11 @@ task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fal
610617
conf << ",\"fallback\":true";
611618
}
612619

620+
if (fast_rate)
621+
{
622+
conf << ",\"fast_rate\":true";
623+
}
624+
613625
conf << "}}'";
614626

615627
SWSS_LOG_INFO("Port channel %s teamd configuration: %s",
@@ -652,7 +664,7 @@ bool TeamMgr::removeLag(const string &alias)
652664
}
653665

654666
// Port-channel names are in the pattern of "PortChannel####"
655-
//
667+
//
656668
// The LACP key could be generated in 3 ways based on the value in config DB:
657669
// 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
658670
// We are adding 1 at the beginning to avoid LACP key collisions between similar LACP keys e.g. PortChannel10 and PortChannel010.

cfgmgr/teammgr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TeamMgr : public Orch
4141
void doLagMemberTask(Consumer &consumer);
4242
void doPortUpdateTask(Consumer &consumer);
4343

44-
task_process_status addLag(const std::string &alias, int min_links, bool fall_back);
44+
task_process_status addLag(const std::string &alias, int min_links, bool fall_back, bool fast_rate);
4545
bool removeLag(const std::string &alias);
4646
task_process_status addLagMember(const std::string &lag, const std::string &member);
4747
bool removeLagMember(const std::string &lag, const std::string &member);

tests/conftest.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def create_servers(self):
412412
for i in range(NUM_PORTS):
413413
server = VirtualServer(self.ctn_sw.name, self.ctn_sw_pid, i)
414414
self.servers.append(server)
415-
415+
416416
def reset_dbs(self):
417417
# DB wrappers are declared here, lazy-loaded in the tests
418418
self.app_db = None
@@ -1853,7 +1853,8 @@ def dvs_route(request, dvs) -> DVSRoute:
18531853
@pytest.yield_fixture(scope="class")
18541854
def dvs_lag_manager(request, dvs):
18551855
request.cls.dvs_lag = dvs_lag.DVSLag(dvs.get_asic_db(),
1856-
dvs.get_config_db())
1856+
dvs.get_config_db(),
1857+
dvs)
18571858

18581859

18591860
@pytest.yield_fixture(scope="class")
@@ -1868,7 +1869,7 @@ def dvs_vlan_manager(request, dvs):
18681869
def dvs_port_manager(request, dvs):
18691870
request.cls.dvs_port = dvs_port.DVSPort(dvs.get_asic_db(),
18701871
dvs.get_config_db())
1871-
1872+
18721873
@pytest.yield_fixture(scope="class")
18731874
def dvs_mirror_manager(request, dvs):
18741875
request.cls.dvs_mirror = dvs_mirror.DVSMirror(dvs.get_asic_db(),

tests/dvslib/dvs_lag.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import json
2+
13
class DVSLag(object):
2-
def __init__(self, adb, cdb):
4+
def __init__(self, adb, cdb, dvs):
35
self.asic_db = adb
46
self.config_db = cdb
7+
self.dvs = dvs
58

6-
def create_port_channel(self, lag_id, admin_status="up", mtu="1500"):
9+
def create_port_channel(self, lag_id, admin_status="up", mtu="1500", fast_rate=False):
710
lag = "PortChannel{}".format(lag_id)
8-
lag_entry = {"admin_status": admin_status, "mtu": mtu}
11+
lag_entry = {"admin_status": admin_status, "mtu": mtu, "fast_rate": str(fast_rate).lower()}
912
self.config_db.create_entry("PORTCHANNEL", lag, lag_entry)
1013

1114
def remove_port_channel(self, lag_id):
@@ -27,3 +30,12 @@ def get_and_verify_port_channel_members(self, expected_num):
2730
def get_and_verify_port_channel(self, expected_num):
2831
return self.asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_LAG", expected_num)
2932

33+
def dump_portchannel(self, lag_id):
34+
lag = "PortChannel{}".format(lag_id)
35+
output = self.dvs.runcmd("teamdctl {} state dump".format(lag))[1]
36+
port_state_dump = json.loads(output)
37+
return port_state_dump
38+
39+
def get_and_verify_port_channel_fast_rate(self, lag_id, fast_rate):
40+
assert self.dump_portchannel(lag_id)["runner"]["fast_rate"] == fast_rate
41+

tests/test_portchannel.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import time
23
import re
34
import json
@@ -6,6 +7,7 @@
67
from swsscommon import swsscommon
78

89

10+
@pytest.mark.usefixtures('dvs_lag_manager')
911
class TestPortchannel(object):
1012
def test_Portchannel(self, dvs, testlog):
1113

@@ -89,6 +91,28 @@ def test_Portchannel(self, dvs, testlog):
8991
lagms = lagmtbl.getKeys()
9092
assert len(lagms) == 0
9193

94+
@pytest.mark.parametrize("fast_rate", [False, True])
95+
def test_Portchannel_fast_rate(self, dvs, testlog, fast_rate):
96+
po_id = "0003"
97+
po_member = "Ethernet16"
98+
99+
# Create PortChannel
100+
self.dvs_lag.create_port_channel(po_id, fast_rate=fast_rate)
101+
self.dvs_lag.get_and_verify_port_channel(1)
102+
103+
# Add member to PortChannel
104+
self.dvs_lag.create_port_channel_member(po_id, po_member)
105+
self.dvs_lag.get_and_verify_port_channel_members(1)
106+
107+
# test fast rate configuration
108+
self.dvs_lag.get_and_verify_port_channel_fast_rate(po_id, fast_rate)
109+
110+
# remove PortChannel
111+
self.dvs_lag.create_port_channel_member(po_id, po_member)
112+
self.dvs_lag.remove_port_channel(po_id)
113+
self.dvs_lag.get_and_verify_port_channel(0)
114+
115+
92116
def test_Portchannel_lacpkey(self, dvs, testlog):
93117
portchannelNamesAuto = [("PortChannel001", "Ethernet0", 1001),
94118
("PortChannel002", "Ethernet4", 1002),
@@ -108,7 +132,7 @@ def test_Portchannel_lacpkey(self, dvs, testlog):
108132

109133
for portchannel in portchannelNamesAuto:
110134
tbl.set(portchannel[0], fvs)
111-
135+
112136
fvs_no_lacp_key = swsscommon.FieldValuePairs(
113137
[("admin_status", "up"), ("mtu", "9100"), ("oper_status", "up")])
114138
tbl.set(portchannelNames[0][0], fvs_no_lacp_key)

0 commit comments

Comments
 (0)