Skip to content

[teamsyncd]: Add LAG members to syncd when created. #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion teamsyncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ teamsyncd_SOURCES = teamsyncd.cpp teamsync.cpp

teamsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
teamsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
teamsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon -lteam
teamsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon -lteam -lteamdctl
56 changes: 53 additions & 3 deletions teamsyncd/teamsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <sys/socket.h>
#include <linux/if.h>
#include <netlink/route/link.h>
#include <teamdctl.h>
#include "logger.h"
#include "netmsg.h"
#include "dbconnector.h"
Expand All @@ -28,20 +29,29 @@ void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
if ((nlmsg_type != RTM_NEWLINK) && (nlmsg_type != RTM_DELLINK))
return;

string lagName = rtnl_link_get_name(link);
string intfName = rtnl_link_get_name(link);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or change to teamName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can have either a LAG or its member, so I picked a more general name

Copy link
Contributor

@nikos-github nikos-github Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a comment to that effect. That this can be the LAG or a member.

/* Listens to LAG messages */
char *type = rtnl_link_get_type(link);
if (!type || (strcmp(type, TEAM_DRV_NAME) != 0))
{
if (nlmsg_type == RTM_NEWLINK)
{
for (const auto& i : m_teamPorts)
{
i.second->syncMember(intfName);
}
}
return;
}

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

addLag(lagName, rtnl_link_get_ifindex(link),
addLag(intfName, rtnl_link_get_ifindex(link),
rtnl_link_get_flags(link) & IFF_UP,
rtnl_link_get_flags(link) & IFF_LOWER_UP,
rtnl_link_get_mtu(link));
Expand Down Expand Up @@ -121,6 +131,19 @@ TeamSync::TeamPortSync::TeamPortSync(const string &lagName, int ifindex,
"Unable to register port change event");
}

m_tdc = teamdctl_alloc();

if (m_tdc == NULL)
{
SWSS_LOG_THROW("Failed to allocate teamdctl context.");
}

err = teamdctl_connect(m_tdc, m_lagName.c_str(), NULL, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this defined? I'm sorry but I couldn't find the function. Can you please tell me which file has it?

if (err)
{
SWSS_LOG_THROW("Failed to connect to %s teamdctl.", m_lagName.c_str());
}

/* Sync LAG at first */
onChange();
}
Expand All @@ -132,6 +155,12 @@ TeamSync::TeamPortSync::~TeamPortSync()
team_change_handler_unregister(m_team, &gPortChangeHandler, this);
team_free(m_team);
}

if (m_tdc)
{
teamdctl_disconnect(m_tdc);
teamdctl_free(m_tdc);
}
}

int TeamSync::TeamPortSync::onChange()
Expand Down Expand Up @@ -209,3 +238,24 @@ void TeamSync::TeamPortSync::readMe()
{
team_handle_events(m_team);
}

void TeamSync::TeamPortSync::syncMember(const std::string& intfName)
{
const std::string config(teamdctl_config_get_raw(m_tdc));
const std::string intfNameStr("\"" + intfName + "\"");

if (config.find(intfNameStr) == std::string::npos)
{
return;
}

if (m_lagMembers.find(intfName) != m_lagMembers.end())
{
return;
}

if (teamdctl_port_add(m_tdc, intfName.c_str()))
{
SWSS_LOG_ERROR("Failed to add port %s to %s", intfName.c_str(), m_lagName.c_str());
}
}
2 changes: 2 additions & 0 deletions teamsyncd/teamsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TeamSync : public NetMsg
virtual bool isMe(fd_set *fd);
virtual int readCache();
virtual void readMe();
void syncMember(const std::string& intfName);

protected:
int onChange();
Expand All @@ -45,6 +46,7 @@ class TeamSync : public NetMsg
private:
ProducerStateTable *m_lagTable;
struct team_handle *m_team;
struct teamdctl *m_tdc;
std::string m_lagName;
int m_ifindex;
std::map<std::string, bool> m_lagMembers; /* map[ifname] = status (enabled|disabled) */
Expand Down