Skip to content

Commit

Permalink
Support warm-restart for neighsyncd (#599)
Browse files Browse the repository at this point in the history
* Support warm-restart for neighsyncd
- No function changes if warm-restart is disabled.
In case warm-restart is enabled, below is done in the process to make sure the ARP/NDP is up-to-date:
- ARP/NDP will be restored from App-DB marked with stale.
- new/changed ARP/DNP during the warm-restart marked as new
- deleted ARP/NDP during the warm-restart marked as delete
- same ARP/NDP entries marked as same
- reconciliation is done after timer-out of a timer
- delta (including stale, new, delete) during the warm-restart would be pushed to App-DB and then to HW.

Add vs test cases to cover:
- No changes during the warm-restart
- ADD/DELETE/CHANGE/SAME neighbors during the warm-restart
- verify the timer changes taking effect for neighsyncd

* Add ps-table clear before reading table, address a few comments

* Added a few improvements

* Addressed a few comments

* Moved the class to a common place

* Addressed the review feedback

* Removed some unused code and fixed a typo
  • Loading branch information
zhenggen-xu authored and lguohan committed Sep 9, 2018
1 parent 387eac6 commit 60a9d61
Show file tree
Hide file tree
Showing 9 changed files with 789 additions and 12 deletions.
4 changes: 2 additions & 2 deletions neighsyncd/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INCLUDES = -I $(top_srcdir)
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/warmrestart

bin_PROGRAMS = neighsyncd

Expand All @@ -8,7 +8,7 @@ else
DBGFLAGS = -g
endif

neighsyncd_SOURCES = neighsyncd.cpp neighsync.cpp
neighsyncd_SOURCES = neighsyncd.cpp neighsync.cpp $(top_srcdir)/warmrestart/warm_restart.cpp $(top_srcdir)/warmrestart/warmRestartAssist.cpp

neighsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
neighsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
Expand Down
26 changes: 21 additions & 5 deletions neighsyncd/neighsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include "linkcache.h"

#include "neighsync.h"
#include "warm_restart.h"

using namespace std;
using namespace swss;

NeighSync::NeighSync(DBConnector *db) :
m_neighTable(db, APP_NEIGH_TABLE_NAME)
NeighSync::NeighSync(RedisPipeline *pipelineAppDB) :
m_neighTable(pipelineAppDB, APP_NEIGH_TABLE_NAME),
m_AppRestartAssist(pipelineAppDB, "neighsyncd", "swss", &m_neighTable, DEFAULT_NEIGHSYNC_WARMSTART_TIMER)
{
}

Expand Down Expand Up @@ -52,18 +54,32 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
key+= ipStr;

int state = rtnl_neigh_get_state(neigh);
bool delete_key = false;
if ((nlmsg_type == RTM_DELNEIGH) || (state == NUD_INCOMPLETE) ||
(state == NUD_FAILED))
{
m_neighTable.del(key);
return;
delete_key = true;
}

nl_addr2str(rtnl_neigh_get_lladdr(neigh), macStr, MAX_ADDR_SIZE);

std::vector<FieldValueTuple> fvVector;
FieldValueTuple f("family", family);
FieldValueTuple nh("neigh", macStr);
fvVector.push_back(nh);
fvVector.push_back(f);
m_neighTable.set(key, fvVector);

if (m_AppRestartAssist.isWarmStartInProgress())
{
m_AppRestartAssist.insertToMap(key, fvVector, delete_key);
}
else
{
if (delete_key == true)
{
m_neighTable.del(key);
return;
}
m_neighTable.set(key, fvVector);
}
}
11 changes: 10 additions & 1 deletion neighsyncd/neighsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "dbconnector.h"
#include "producerstatetable.h"
#include "netmsg.h"
#include "warmRestartAssist.h"

#define DEFAULT_NEIGHSYNC_WARMSTART_TIMER 5

namespace swss {

Expand All @@ -12,12 +15,18 @@ class NeighSync : public NetMsg
public:
enum { MAX_ADDR_SIZE = 64 };

NeighSync(DBConnector *db);
NeighSync(RedisPipeline *pipelineAppDB);

virtual void onMsg(int nlmsg_type, struct nl_object *obj);

AppRestartAssist *getRestartAssist()
{
return &m_AppRestartAssist;
}

private:
ProducerStateTable m_neighTable;
AppRestartAssist m_AppRestartAssist;
};

}
Expand Down
20 changes: 18 additions & 2 deletions neighsyncd/neighsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ using namespace swss;
int main(int argc, char **argv)
{
Logger::linkToDbNative("neighsyncd");
DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
NeighSync sync(&db);

DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
RedisPipeline pipelineAppDB(&appDb);

NeighSync sync(&pipelineAppDB);

NetDispatcher::getInstance().registerMessageHandler(RTM_NEWNEIGH, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELNEIGH, &sync);
Expand All @@ -29,10 +32,23 @@ int main(int argc, char **argv)
netlink.dumpRequest(RTM_GETNEIGH);

s.addSelectable(&netlink);
if (sync.getRestartAssist()->isWarmStartInProgress())
{
sync.getRestartAssist()->readTableToMap();
sync.getRestartAssist()->startReconcileTimer(s);
}
while (true)
{
Selectable *temps;
s.select(&temps);
if (sync.getRestartAssist()->isWarmStartInProgress())
{
if (sync.getRestartAssist()->checkReconcileTimer(temps))
{
sync.getRestartAssist()->stopReconcileTimer(s);
sync.getRestartAssist()->reconcile();
}
}
}
}
catch (const std::exception& e)
Expand Down
Loading

0 comments on commit 60a9d61

Please sign in to comment.