Skip to content

Commit 1215262

Browse files
authored
[DPB portsyncd/portmgrd/portorch] Support dynamic port add/deletion without dependencies (#1112)
Changes were made on portmgrd/portsyncd and orchagent portsorch so it should be able to remove/add ports in case no configuration dependencies or runtime depencies (neighbor, mac etc) on them Also skipped the netlink for port add/delete with master in portsyncd and cleaned up g_init and g_portSet flag and data strcutures usage. Added dynamic portbeakout test cases including the conf_test.py changs Signed-off-by: Zhenggen Xu <zxu@linkedin.com> Signed-off-by: Vasant Patil <vapatil@linkedin.com>
1 parent ddb84fb commit 1215262

9 files changed

Lines changed: 566 additions & 44 deletions

File tree

cfgmgr/portmgr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ void PortMgr::doTask(Consumer &consumer)
151151
SWSS_LOG_NOTICE("Configure %s MAC learn mode to %s", alias.c_str(), learn_mode.c_str());
152152
}
153153
}
154+
else if (op == DEL_COMMAND)
155+
{
156+
SWSS_LOG_NOTICE("Delete Port: %s", alias.c_str());
157+
m_appPortTable.del(alias);
158+
}
154159

155160
it = consumer.m_toSync.erase(it);
156161
}

orchagent/portsorch.cpp

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "crmorch.h"
2525
#include "countercheckorch.h"
2626
#include "notifier.h"
27+
#include "redisclient.h"
2728

2829
extern sai_switch_api_t *sai_switch_api;
2930
extern sai_bridge_api_t *sai_bridge_api;
@@ -1427,6 +1428,7 @@ bool PortsOrch::addPort(const set<int> &lane_set, uint32_t speed, int an, string
14271428
}
14281429

14291430
m_portListLaneMap[lane_set] = port_id;
1431+
m_portCount++;
14301432

14311433
SWSS_LOG_NOTICE("Create port %" PRIx64 " with the speed %u", port_id, speed);
14321434

@@ -1450,7 +1452,10 @@ bool PortsOrch::removePort(sai_object_id_t port_id)
14501452
SWSS_LOG_ERROR("Failed to remove port %" PRIx64 ", rv:%d", port_id, status);
14511453
return false;
14521454
}
1455+
14531456
removeAclTableGroup(p);
1457+
1458+
m_portCount--;
14541459
SWSS_LOG_NOTICE("Remove port %" PRIx64, port_id);
14551460

14561461
return true;
@@ -1528,6 +1533,24 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
15281533
return true;
15291534
}
15301535

1536+
void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
1537+
{
1538+
SWSS_LOG_ENTER();
1539+
1540+
Port p(alias, Port::PHY);
1541+
p.m_port_id = port_id;
1542+
1543+
/* remove port from flex_counter_table for updating counters */
1544+
port_stat_manager.clearCounterIdList(p.m_port_id);
1545+
1546+
/* remove port name map from counter table */
1547+
RedisClient redisClient(m_counter_db.get());
1548+
redisClient.hdel(COUNTERS_PORT_NAME_MAP, alias);
1549+
1550+
SWSS_LOG_NOTICE("De-Initialized port %s", alias.c_str());
1551+
}
1552+
1553+
15311554
bool PortsOrch::bake()
15321555
{
15331556
SWSS_LOG_ENTER();
@@ -1594,6 +1617,35 @@ void PortsOrch::cleanPortTable(const vector<string>& keys)
15941617
}
15951618
}
15961619

1620+
void PortsOrch::removePortFromLanesMap(string alias)
1621+
{
1622+
1623+
for (auto it = m_lanesAliasSpeedMap.begin(); it != m_lanesAliasSpeedMap.end(); it++)
1624+
{
1625+
if (get<0>(it->second) == alias)
1626+
{
1627+
SWSS_LOG_NOTICE("Removing port %s from lanes map", alias.c_str());
1628+
it = m_lanesAliasSpeedMap.erase(it);
1629+
break;
1630+
}
1631+
}
1632+
}
1633+
1634+
void PortsOrch::removePortFromPortListMap(sai_object_id_t port_id)
1635+
{
1636+
1637+
for (auto it = m_portListLaneMap.begin(); it != m_portListLaneMap.end(); it++)
1638+
{
1639+
if (it->second == port_id)
1640+
{
1641+
SWSS_LOG_NOTICE("Removing port-id %lx from port list map", port_id);
1642+
it = m_portListLaneMap.erase(it);
1643+
break;
1644+
}
1645+
}
1646+
}
1647+
1648+
15971649
void PortsOrch::doPortTask(Consumer &consumer)
15981650
{
15991651
SWSS_LOG_ENTER();
@@ -1754,7 +1806,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
17541806
* 2. Create new ports
17551807
* 3. Initialize all ports
17561808
*/
1757-
if (m_portConfigState == PORT_CONFIG_RECEIVED && (m_lanesAliasSpeedMap.size() == m_portCount))
1809+
if (m_portConfigState == PORT_CONFIG_RECEIVED || m_portConfigState == PORT_CONFIG_DONE)
17581810
{
17591811
for (auto it = m_portListLaneMap.begin(); it != m_portListLaneMap.end();)
17601812
{
@@ -1797,7 +1849,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
17971849
}
17981850
}
17991851

1800-
it = m_lanesAliasSpeedMap.erase(it);
1852+
it++;
18011853
}
18021854

18031855
m_portConfigState = PORT_CONFIG_DONE;
@@ -2086,6 +2138,31 @@ void PortsOrch::doPortTask(Consumer &consumer)
20862138
}
20872139
}
20882140
}
2141+
else if (op == DEL_COMMAND)
2142+
{
2143+
SWSS_LOG_NOTICE("Deleting Port %s", alias.c_str());
2144+
auto port_id = m_portList[alias].m_port_id;
2145+
auto hif_id = m_portList[alias].m_hif_id;
2146+
2147+
deInitPort(alias, port_id);
2148+
2149+
SWSS_LOG_NOTICE("Removing hostif %lx for Port %s", hif_id, alias.c_str());
2150+
sai_status_t status = sai_hostif_api->remove_hostif(hif_id);
2151+
if (status != SAI_STATUS_SUCCESS)
2152+
{
2153+
throw runtime_error("Remove hostif for the port failed");
2154+
}
2155+
2156+
if (!removePort(port_id))
2157+
{
2158+
throw runtime_error("Delete port failed");
2159+
}
2160+
removePortFromLanesMap(alias);
2161+
removePortFromPortListMap(port_id);
2162+
2163+
/* Delete port from port list */
2164+
m_portList.erase(alias);
2165+
}
20892166
else
20902167
{
20912168
SWSS_LOG_ERROR("Unknown operation type %s", op.c_str());

orchagent/portsorch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class PortsOrch : public Orch, public Subject
149149

150150
void doTask(NotificationConsumer &consumer);
151151

152+
void removePortFromLanesMap(string alias);
153+
void removePortFromPortListMap(sai_object_id_t port_id);
152154
void removeDefaultVlanMembers();
153155
void removeDefaultBridgePorts();
154156

@@ -179,6 +181,7 @@ class PortsOrch : public Orch, public Subject
179181
bool addPort(const set<int> &lane_set, uint32_t speed, int an=0, string fec="");
180182
bool removePort(sai_object_id_t port_id);
181183
bool initPort(const string &alias, const set<int> &lane_set);
184+
void deInitPort(string alias, sai_object_id_t port_id);
182185

183186
bool setPortAdminStatus(sai_object_id_t id, bool up);
184187
bool getPortAdminStatus(sai_object_id_t id, bool& up);

portsyncd/linksync.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
155155

156156
void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
157157
{
158+
SWSS_LOG_ENTER();
159+
158160
if ((nlmsg_type != RTM_NEWLINK) && (nlmsg_type != RTM_DELLINK))
159161
{
160162
return;
@@ -209,6 +211,14 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
209211
return;
210212
}
211213

214+
/* If netlink for this port has master, we ignore that for now
215+
* This could be the case where the port was removed from VLAN bridge
216+
*/
217+
if (master)
218+
{
219+
return;
220+
}
221+
212222
/* In the event of swss restart, it is possible to get netlink messages during bridge
213223
* delete, interface delete etc which are part of cleanup. These netlink messages for
214224
* the front-panel interface must not be published or it will update the statedb with
@@ -226,27 +236,24 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
226236
/* Insert or update the ifindex to key map */
227237
m_ifindexNameMap[ifindex] = key;
228238

239+
if (nlmsg_type == RTM_DELLINK)
240+
{
241+
m_statePortTable.del(key);
242+
SWSS_LOG_NOTICE("Delete %s(ok) from state db", key.c_str());
243+
return;
244+
}
245+
229246
/* front panel interfaces: Check if the port is in the PORT_TABLE
230247
* non-front panel interfaces such as eth0, lo which are not in the
231248
* PORT_TABLE are ignored. */
232249
vector<FieldValueTuple> temp;
233250
if (m_portTable.get(key, temp))
234251
{
235-
/* TODO: When port is removed from the kernel */
236-
if (nlmsg_type == RTM_DELLINK)
237-
{
238-
return;
239-
}
240-
241-
/* Host interface is created */
242-
if (!g_init && g_portSet.find(key) != g_portSet.end())
243-
{
244-
g_portSet.erase(key);
245-
FieldValueTuple tuple("state", "ok");
246-
vector<FieldValueTuple> vector;
247-
vector.push_back(tuple);
248-
m_statePortTable.set(key, vector);
249-
SWSS_LOG_INFO("Publish %s(ok) to state db", key.c_str());
250-
}
252+
g_portSet.erase(key);
253+
FieldValueTuple tuple("state", "ok");
254+
vector<FieldValueTuple> vector;
255+
vector.push_back(tuple);
256+
m_statePortTable.set(key, vector);
257+
SWSS_LOG_NOTICE("Publish %s(ok) to state db", key.c_str());
251258
}
252259
}

tests/conftest.py

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def __init__(self, dvs):
7777

7878
class ApplDbValidator(object):
7979
def __init__(self, dvs):
80-
appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
81-
self.neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE")
80+
self.appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
81+
self.neighTbl = swsscommon.Table(self.appl_db, "NEIGH_TABLE")
8282

8383
def __del__(self):
8484
# Make sure no neighbors on physical interfaces
@@ -155,13 +155,14 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
155155
'vrfmgrd',
156156
'portmgrd']
157157
self.syncd = ['syncd']
158-
self.rtd = ['fpmsyncd', 'zebra']
158+
self.rtd = ['fpmsyncd', 'zebra', 'staticd']
159159
self.teamd = ['teamsyncd', 'teammgrd']
160160
# FIXME: We need to verify that NAT processes are running, once the
161161
# appropriate changes are merged into sonic-buildimage
162162
# self.natd = ['natsyncd', 'natmgrd']
163163
self.alld = self.basicd + self.swssd + self.syncd + self.rtd + self.teamd # + self.natd
164164
self.client = docker.from_env()
165+
self.appldb = None
165166

166167
if subprocess.check_call(["/sbin/modprobe", "team"]) != 0:
167168
raise NameError("cannot install kernel team module")
@@ -199,7 +200,7 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
199200
self.mount = "/var/run/redis-vs/{}".format(ctn_sw_name)
200201

201202
self.net_cleanup()
202-
self.restart()
203+
self.ctn_restart()
203204
else:
204205
self.ctn_sw = self.client.containers.run('debian:jessie', privileged=True, detach=True,
205206
command="bash", stdin_open=True)
@@ -224,8 +225,20 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
224225
network_mode="container:%s" % self.ctn_sw.name,
225226
volumes={ self.mount: { 'bind': '/var/run/redis', 'mode': 'rw' } })
226227

227-
self.appldb = None
228228
self.redis_sock = self.mount + '/' + "redis.sock"
229+
self.check_ctn_status_and_db_connect()
230+
231+
def destroy(self):
232+
if self.appldb:
233+
del self.appldb
234+
if self.cleanup:
235+
self.ctn.remove(force=True)
236+
self.ctn_sw.remove(force=True)
237+
os.system("rm -rf {}".format(self.mount))
238+
for s in self.servers:
239+
s.destroy()
240+
241+
def check_ctn_status_and_db_connect(self):
229242
try:
230243
# temp fix: remove them once they are moved to vs start.sh
231244
self.ctn.exec_run("sysctl -w net.ipv6.conf.default.disable_ipv6=0")
@@ -239,15 +252,6 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
239252
self.destroy()
240253
raise
241254

242-
def destroy(self):
243-
if self.appldb:
244-
del self.appldb
245-
if self.cleanup:
246-
self.ctn.remove(force=True)
247-
self.ctn_sw.remove(force=True)
248-
os.system("rm -rf {}".format(self.mount))
249-
for s in self.servers:
250-
s.destroy()
251255

252256
def check_ready(self, timeout=30):
253257
'''check if all processes in the dvs is ready'''
@@ -314,15 +318,22 @@ def net_cleanup(self):
314318
print "remove extra link {}".format(pname)
315319
return
316320

317-
def restart(self):
321+
def ctn_restart(self):
318322
self.ctn.restart()
319323

324+
def restart(self):
325+
if self.appldb:
326+
del self.appldb
327+
self.ctn_restart()
328+
self.check_ctn_status_and_db_connect()
329+
320330
# start processes in SWSS
321331
def start_swss(self):
322332
cmd = ""
323333
for pname in self.swssd:
324334
cmd += "supervisorctl start {}; ".format(pname)
325335
self.runcmd(['sh', '-c', cmd])
336+
time.sleep(5)
326337

327338
# stop processes in SWSS
328339
def stop_swss(self):
@@ -839,3 +850,25 @@ def testlog(request, dvs):
839850
dvs.runcmd("logger === start test %s ===" % request.node.name)
840851
yield testlog
841852
dvs.runcmd("logger === finish test %s ===" % request.node.name)
853+
854+
##################### DPB fixtures ###########################################
855+
@pytest.yield_fixture(scope="module")
856+
def create_dpb_config_file(dvs):
857+
cmd = "sonic-cfggen -j /etc/sonic/init_cfg.json -j /tmp/ports.json --print-data > /tmp/dpb_config_db.json"
858+
dvs.runcmd(['sh', '-c', cmd])
859+
cmd = "mv /etc/sonic/config_db.json /etc/sonic/config_db.json.bak"
860+
dvs.runcmd(cmd)
861+
cmd = "cp /tmp/dpb_config_db.json /etc/sonic/config_db.json"
862+
dvs.runcmd(cmd)
863+
864+
@pytest.yield_fixture(scope="module")
865+
def remove_dpb_config_file(dvs):
866+
cmd = "mv /etc/sonic/config_db.json.bak /etc/sonic/config_db.json"
867+
dvs.runcmd(cmd)
868+
869+
@pytest.yield_fixture(scope="module")
870+
def dpb_setup_fixture(dvs):
871+
create_dpb_config_file(dvs)
872+
dvs.restart()
873+
yield
874+
remove_dpb_config_file(dvs)

0 commit comments

Comments
 (0)