Skip to content

Commit 8752d35

Browse files
author
Shuotian Cheng
authored
[teamsyncd]: Supporting swss restart to recreate all teams (#182)
- teamsyncd now tracks the admin/oper status of teams - teamsyncd supports swss restart to recreate all teams Signed-off-by: Shuotian Cheng <[email protected]>
1 parent 3e713cc commit 8752d35

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

teamsyncd/teamsync.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,13 @@ void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
3434
if (!type || (strcmp(type, TEAM_DRV_NAME) != 0))
3535
return;
3636

37-
bool tracked = m_teamPorts.find(lagName) != m_teamPorts.end();
38-
39-
if ((nlmsg_type == RTM_DELLINK) && tracked)
37+
if (nlmsg_type == RTM_DELLINK)
4038
{
4139
/* Remove LAG ports and delete LAG */
4240
removeLag(lagName);
4341
return;
4442
}
4543

46-
if ((nlmsg_type == RTM_NEWLINK) && tracked)
47-
return;
48-
49-
/*
50-
* New LAG was dedcated for the first time. Sync admin and oper state since
51-
* portsyncd reflects only changes
52-
*/
5344
addLag(lagName, rtnl_link_get_ifindex(link),
5445
rtnl_link_get_flags(link) & IFF_UP,
5546
rtnl_link_get_flags(link) & IFF_LOWER_UP,
@@ -59,7 +50,7 @@ void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
5950
void TeamSync::addLag(const string &lagName, int ifindex, bool admin_state,
6051
bool oper_state, unsigned int mtu)
6152
{
62-
/* First add the LAG itself */
53+
/* Set the LAG */
6354
std::vector<FieldValueTuple> fvVector;
6455
FieldValueTuple a("admin_status", admin_state ? "up" : "down");
6556
FieldValueTuple o("oper_status", oper_state ? "up" : "down");
@@ -69,17 +60,28 @@ void TeamSync::addLag(const string &lagName, int ifindex, bool admin_state,
6960
fvVector.push_back(m);
7061
m_lagTable.set(lagName, fvVector);
7162

72-
/* Start adding ports to LAG */
63+
/* Return when the team instance has already been tracked */
64+
if (m_teamPorts.find(lagName) != m_teamPorts.end())
65+
return;
66+
67+
/* Start track the team instance */
7368
TeamPortSync *sync = new TeamPortSync(lagName, ifindex, &m_lagTable);
7469
m_select->addSelectable(sync);
7570
m_teamPorts[lagName] = shared_ptr<TeamPortSync>(sync);
7671
}
7772

7873
void TeamSync::removeLag(const string &lagName)
7974
{
75+
/* Delete the LAG */
76+
m_lagTable.del(lagName);
77+
78+
/* Return when the team instance hasn't been tracked before */
79+
if (m_teamPorts.find(lagName) == m_teamPorts.end())
80+
return;
81+
82+
/* No longer track the current team instance */
8083
m_select->removeSelectable(m_teamPorts[lagName].get());
8184
m_teamPorts.erase(lagName);
82-
m_lagTable.del(lagName);
8385
}
8486

8587
const struct team_change_handler TeamSync::TeamPortSync::gPortChangeHandler = {

0 commit comments

Comments
 (0)