Skip to content

Commit

Permalink
[teamsyncd]: Supporting swss restart to recreate all teams (sonic-net…
Browse files Browse the repository at this point in the history
…#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]>
  • Loading branch information
Shuotian Cheng authored Mar 27, 2017
1 parent 3e713cc commit 8752d35
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions teamsyncd/teamsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,13 @@ void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
if (!type || (strcmp(type, TEAM_DRV_NAME) != 0))
return;

bool tracked = m_teamPorts.find(lagName) != m_teamPorts.end();

if ((nlmsg_type == RTM_DELLINK) && tracked)
if (nlmsg_type == RTM_DELLINK)
{
/* Remove LAG ports and delete LAG */
removeLag(lagName);
return;
}

if ((nlmsg_type == RTM_NEWLINK) && tracked)
return;

/*
* New LAG was dedcated for the first time. Sync admin and oper state since
* portsyncd reflects only changes
*/
addLag(lagName, rtnl_link_get_ifindex(link),
rtnl_link_get_flags(link) & IFF_UP,
rtnl_link_get_flags(link) & IFF_LOWER_UP,
Expand All @@ -59,7 +50,7 @@ void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
void TeamSync::addLag(const string &lagName, int ifindex, bool admin_state,
bool oper_state, unsigned int mtu)
{
/* First add the LAG itself */
/* Set the LAG */
std::vector<FieldValueTuple> fvVector;
FieldValueTuple a("admin_status", admin_state ? "up" : "down");
FieldValueTuple o("oper_status", oper_state ? "up" : "down");
Expand All @@ -69,17 +60,28 @@ void TeamSync::addLag(const string &lagName, int ifindex, bool admin_state,
fvVector.push_back(m);
m_lagTable.set(lagName, fvVector);

/* Start adding ports to LAG */
/* Return when the team instance has already been tracked */
if (m_teamPorts.find(lagName) != m_teamPorts.end())
return;

/* Start track the team instance */
TeamPortSync *sync = new TeamPortSync(lagName, ifindex, &m_lagTable);
m_select->addSelectable(sync);
m_teamPorts[lagName] = shared_ptr<TeamPortSync>(sync);
}

void TeamSync::removeLag(const string &lagName)
{
/* Delete the LAG */
m_lagTable.del(lagName);

/* Return when the team instance hasn't been tracked before */
if (m_teamPorts.find(lagName) == m_teamPorts.end())
return;

/* No longer track the current team instance */
m_select->removeSelectable(m_teamPorts[lagName].get());
m_teamPorts.erase(lagName);
m_lagTable.del(lagName);
}

const struct team_change_handler TeamSync::TeamPortSync::gPortChangeHandler = {
Expand Down

0 comments on commit 8752d35

Please sign in to comment.