Skip to content
Merged
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
72 changes: 48 additions & 24 deletions teamsyncd/teamsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "warm_restart.h"
#include "teamsync.h"

#include <unistd.h>

using namespace std;
using namespace std::chrono;
using namespace swss;
Expand Down Expand Up @@ -194,32 +196,54 @@ TeamSync::TeamPortSync::TeamPortSync(const string &lagName, int ifindex,
m_lagName(lagName),
m_ifindex(ifindex)
{
m_team = team_alloc();
if (!m_team)
{
SWSS_LOG_ERROR("Unable to allocated team socket");
throw system_error(make_error_code(errc::address_not_available),
"Unable to allocated team socket");
}

int err = team_init(m_team, ifindex);
if (err)
{
team_free(m_team);
m_team = NULL;
SWSS_LOG_ERROR("Unable to init team socket");
throw system_error(make_error_code(errc::address_not_available),
"Unable to init team socket");
}
int count = 0;
int max_retries = 3;

err = team_change_handler_register(m_team, &gPortChangeHandler, this);
if (err)
while (true)
{
team_free(m_team);
m_team = NULL;
SWSS_LOG_ERROR("Unable to register port change event");
throw system_error(make_error_code(errc::address_not_available),
"Unable to register port change event");
try
{
m_team = team_alloc();
if (!m_team)
{
throw system_error(make_error_code(errc::address_not_available),
"Unable to allocate team socket");
}

int err = team_init(m_team, ifindex);
if (err)
{
team_free(m_team);
m_team = NULL;
throw system_error(make_error_code(errc::address_not_available),
"Unable to initialize team socket");
}

err = team_change_handler_register(m_team, &gPortChangeHandler, this);
if (err)
{
team_free(m_team);
m_team = NULL;
throw system_error(make_error_code(errc::address_not_available),
"Unable to register port change event");
}

break;
}
catch (const system_error& e)
{
if (++count == max_retries)
{
throw;
}
else
{
SWSS_LOG_WARN("Failed to initialize team handler. LAG=%s error=%d:%s, attempt=%d",
lagName.c_str(), e.code().value(), e.what(), count);
}

sleep(1);
}
}

/* Sync LAG at first */
Expand Down