Skip to content

Commit 60a9d61

Browse files
zhenggen-xulguohan
authored andcommitted
Support warm-restart for neighsyncd (#599)
* 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
1 parent 387eac6 commit 60a9d61

File tree

9 files changed

+789
-12
lines changed

9 files changed

+789
-12
lines changed

neighsyncd/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
INCLUDES = -I $(top_srcdir)
1+
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/warmrestart
22

33
bin_PROGRAMS = neighsyncd
44

@@ -8,7 +8,7 @@ else
88
DBGFLAGS = -g
99
endif
1010

11-
neighsyncd_SOURCES = neighsyncd.cpp neighsync.cpp
11+
neighsyncd_SOURCES = neighsyncd.cpp neighsync.cpp $(top_srcdir)/warmrestart/warm_restart.cpp $(top_srcdir)/warmrestart/warmRestartAssist.cpp
1212

1313
neighsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
1414
neighsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)

neighsyncd/neighsync.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
#include "linkcache.h"
1212

1313
#include "neighsync.h"
14+
#include "warm_restart.h"
1415

1516
using namespace std;
1617
using namespace swss;
1718

18-
NeighSync::NeighSync(DBConnector *db) :
19-
m_neighTable(db, APP_NEIGH_TABLE_NAME)
19+
NeighSync::NeighSync(RedisPipeline *pipelineAppDB) :
20+
m_neighTable(pipelineAppDB, APP_NEIGH_TABLE_NAME),
21+
m_AppRestartAssist(pipelineAppDB, "neighsyncd", "swss", &m_neighTable, DEFAULT_NEIGHSYNC_WARMSTART_TIMER)
2022
{
2123
}
2224

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

5456
int state = rtnl_neigh_get_state(neigh);
57+
bool delete_key = false;
5558
if ((nlmsg_type == RTM_DELNEIGH) || (state == NUD_INCOMPLETE) ||
5659
(state == NUD_FAILED))
5760
{
58-
m_neighTable.del(key);
59-
return;
61+
delete_key = true;
6062
}
6163

6264
nl_addr2str(rtnl_neigh_get_lladdr(neigh), macStr, MAX_ADDR_SIZE);
65+
6366
std::vector<FieldValueTuple> fvVector;
6467
FieldValueTuple f("family", family);
6568
FieldValueTuple nh("neigh", macStr);
6669
fvVector.push_back(nh);
6770
fvVector.push_back(f);
68-
m_neighTable.set(key, fvVector);
71+
72+
if (m_AppRestartAssist.isWarmStartInProgress())
73+
{
74+
m_AppRestartAssist.insertToMap(key, fvVector, delete_key);
75+
}
76+
else
77+
{
78+
if (delete_key == true)
79+
{
80+
m_neighTable.del(key);
81+
return;
82+
}
83+
m_neighTable.set(key, fvVector);
84+
}
6985
}

neighsyncd/neighsync.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "dbconnector.h"
55
#include "producerstatetable.h"
66
#include "netmsg.h"
7+
#include "warmRestartAssist.h"
8+
9+
#define DEFAULT_NEIGHSYNC_WARMSTART_TIMER 5
710

811
namespace swss {
912

@@ -12,12 +15,18 @@ class NeighSync : public NetMsg
1215
public:
1316
enum { MAX_ADDR_SIZE = 64 };
1417

15-
NeighSync(DBConnector *db);
18+
NeighSync(RedisPipeline *pipelineAppDB);
1619

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

22+
AppRestartAssist *getRestartAssist()
23+
{
24+
return &m_AppRestartAssist;
25+
}
26+
1927
private:
2028
ProducerStateTable m_neighTable;
29+
AppRestartAssist m_AppRestartAssist;
2130
};
2231

2332
}

neighsyncd/neighsyncd.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ using namespace swss;
1111
int main(int argc, char **argv)
1212
{
1313
Logger::linkToDbNative("neighsyncd");
14-
DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
15-
NeighSync sync(&db);
14+
15+
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
16+
RedisPipeline pipelineAppDB(&appDb);
17+
18+
NeighSync sync(&pipelineAppDB);
1619

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

3134
s.addSelectable(&netlink);
35+
if (sync.getRestartAssist()->isWarmStartInProgress())
36+
{
37+
sync.getRestartAssist()->readTableToMap();
38+
sync.getRestartAssist()->startReconcileTimer(s);
39+
}
3240
while (true)
3341
{
3442
Selectable *temps;
3543
s.select(&temps);
44+
if (sync.getRestartAssist()->isWarmStartInProgress())
45+
{
46+
if (sync.getRestartAssist()->checkReconcileTimer(temps))
47+
{
48+
sync.getRestartAssist()->stopReconcileTimer(s);
49+
sync.getRestartAssist()->reconcile();
50+
}
51+
}
3652
}
3753
}
3854
catch (const std::exception& e)

0 commit comments

Comments
 (0)