Skip to content
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

[WR]: Add reconciliation logic for teamsyncd #725

Merged
merged 20 commits into from
Dec 23, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a5b0a88
Pospone QueueMap initialization until activation of counters
pavel-shirshov Jun 25, 2018
1d54717
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Jun 29, 2018
b767c2e
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Jun 29, 2018
5e96d67
Generate queue maps only for front panel ports
pavel-shirshov Jul 2, 2018
21c072c
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Jul 4, 2018
00192a4
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Aug 22, 2018
1a71c39
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Aug 29, 2018
6bc8091
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Sep 5, 2018
83efbee
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Sep 11, 2018
c2f4fdf
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Sep 15, 2018
c4094b0
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Nov 7, 2018
fc6185a
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Nov 10, 2018
4e5d73d
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Nov 13, 2018
cc57c96
Merge branch 'master' of https://github.com/Azure/sonic-swss
pavel-shirshov Dec 4, 2018
8b7ef4e
Initial commit for teamsyncd reconc logic
pavel-shirshov Dec 5, 2018
b5b7865
Add log messages
pavel-shirshov Dec 6, 2018
72fc2e7
PR refactoring
pavel-shirshov Dec 7, 2018
e1e988d
Make pending timeout configurable
pavel-shirshov Dec 7, 2018
ff0ee2a
if space thing
pavel-shirshov Dec 7, 2018
019c616
Update schema
pavel-shirshov Dec 11, 2018
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
52 changes: 49 additions & 3 deletions teamsyncd/teamsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "netmsg.h"
#include "dbconnector.h"
#include "producerstatetable.h"
#include "warm_restart.h"
#include "teamsync.h"

using namespace std;
Expand All @@ -20,8 +21,15 @@ TeamSync::TeamSync(DBConnector *db, DBConnector *stateDb, Select *select) :
m_select(select),
m_lagTable(db, APP_LAG_TABLE_NAME),
m_lagMemberTable(db, APP_LAG_MEMBER_TABLE_NAME),
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME)
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME),
m_warmstart(WarmStart::isWarmStart())
{
if (m_warmstart)
{
m_lagTable.create_temp_view();
m_lagMemberTable.create_temp_view();
SWSS_LOG_NOTICE("Starting in warmstart mode");
}
}

void TeamSync::doSelectableTask()
Expand All @@ -44,6 +52,29 @@ void TeamSync::doSelectableTask()
m_selectablesToRemove.clear();
}

void TeamSync::applyState()
{
if (!m_warmstart)
{
return;
}

SWSS_LOG_NOTICE("Applying state");

m_lagTable.apply_temp_view();
m_lagMemberTable.apply_temp_view();

for(auto &it: m_stateLagTablePreserved)
{
const auto &lagName = it.first;
const auto &fvVector = it.second;
m_stateLagTable.set(lagName, fvVector);
}
m_stateLagTablePreserved.clear();

m_warmstart = false;
}

void TeamSync::onMsg(int nlmsg_type, struct nl_object *obj)
{
struct rtnl_link *link = (struct rtnl_link *)obj;
Expand Down Expand Up @@ -90,7 +121,14 @@ void TeamSync::addLag(const string &lagName, int ifindex, bool admin_state,
fvVector.clear();
FieldValueTuple s("state", "ok");
fvVector.push_back(s);
m_stateLagTable.set(lagName, fvVector);
if(m_warmstart)
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
{
m_stateLagTablePreserved[lagName] = fvVector;
}
else
{
m_stateLagTable.set(lagName, fvVector);
}

/* Create the team instance */
auto sync = make_shared<TeamPortSync>(lagName, ifindex, &m_lagMemberTable);
Expand All @@ -116,7 +154,15 @@ void TeamSync::removeLag(const string &lagName)
if (m_teamSelectables.find(lagName) == m_teamSelectables.end())
return;

m_stateLagTable.del(lagName);
if(m_warmstart)
{
m_stateLagTablePreserved.erase(lagName);
}
else
{
m_stateLagTable.del(lagName);
}

m_selectablesToRemove.insert(lagName);
}

Expand Down
9 changes: 9 additions & 0 deletions teamsyncd/teamsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
#include "netmsg.h"
#include <team.h>

// seconds
#define WR_PENDING_TIME 70

namespace swss {

class TeamSync : public NetMsg
{
public:
TeamSync(DBConnector *db, DBConnector *stateDb, Select *select);

/* valid only in WR mode */
void applyState();

/* Listen to RTM_NEWLINK, RTM_DELLINK to track team devices */
virtual void onMsg(int nlmsg_type, struct nl_object *obj);

Expand Down Expand Up @@ -60,6 +66,9 @@ class TeamSync : public NetMsg
ProducerStateTable m_lagMemberTable;
Table m_stateLagTable;

bool m_warmstart;
std::unordered_map<std::string, std::vector<FieldValueTuple>> m_stateLagTablePreserved;

/* Store selectables needed to be updated in doSelectableTask function */
std::set<std::string> m_selectablesToAdd;
std::set<std::string> m_selectablesToRemove;
Expand Down
16 changes: 15 additions & 1 deletion teamsyncd/teamsyncd.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#include <iostream>
#include <chrono>
#include <team.h>
#include "logger.h"
#include "select.h"
#include "netdispatcher.h"
#include "netlink.h"
#include "warm_restart.h"
#include "teamsync.h"


pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
using namespace std;
using namespace swss;
using namespace std::chrono;

int main(int argc, char **argv)
{
swss::Logger::linkToDbNative("teamsyncd");
WarmStart::initialize("teamsyncd", "teamd");
WarmStart::checkWarmStart("teamsyncd", "teamd");
DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
Select s;
Expand All @@ -20,6 +26,8 @@ int main(int argc, char **argv)
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync);

steady_clock::time_point start_time = steady_clock::now();

while (1)
{
try
Expand All @@ -34,7 +42,13 @@ int main(int argc, char **argv)
while (true)
{
Selectable *temps;
s.select(&temps);
s.select(&temps, 1000); // check every second

auto diff = duration_cast<seconds>(steady_clock::now() - start_time);
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
if(diff.count() > WR_PENDING_TIME)
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
{
sync.applyState();
pavel-shirshov marked this conversation as resolved.
Show resolved Hide resolved
}

sync.doSelectableTask();
}
Expand Down