forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfdbsyncd.cpp
More file actions
165 lines (149 loc) · 6.12 KB
/
Copy pathfdbsyncd.cpp
File metadata and controls
165 lines (149 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <chrono>
#include "logger.h"
#include "select.h"
#include "netdispatcher.h"
#include "netlink.h"
#include "fdbsyncd/fdbsync.h"
using namespace std;
using namespace swss;
int main(int argc, char **argv)
{
Logger::linkToDbNative("fdbsyncd");
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
RedisPipeline pipelineAppDB(&appDb);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector log_db(LOGLEVEL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector config_db(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
FdbSync sync(&pipelineAppDB, &stateDb, &config_db);
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWNEIGH, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELNEIGH, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
while (1)
{
try
{
NetLink netlink;
Selectable *temps;
int ret;
Select s;
SelectableTimer replayCheckTimer(timespec{0, 0});
SelectableTimer reconCheckTimer(timespec{0, 0});
using namespace std::chrono;
/*
* If WarmStart is enabled, restore the VXLAN-FDB and VNI
* tables and start a reconcillation timer
*/
if (sync.getRestartAssist()->isWarmStartInProgress())
{
int pasttime = 0;
sync.getRestartAssist()->readTablesToMap();
while (!sync.isIntfRestoreDone())
{
if (pasttime++ > WARM_RESTORE_WAIT_TIME_OUT_MAX)
{
SWSS_LOG_INFO("timed-out before all interface data was replayed to kernel!!!");
break;
}
sleep(1);
}
SWSS_LOG_NOTICE("Starting ReconcileTimer");
sync.getRestartAssist()->startReconcileTimer(s);
replayCheckTimer.setInterval(timespec{1, 0});
replayCheckTimer.start();
s.addSelectable(&replayCheckTimer);
}
else
{
sync.getRestartAssist()->warmStartDisabled();
sync.m_reconcileDone = true;
}
netlink.registerGroup(RTNLGRP_LINK);
netlink.registerGroup(RTNLGRP_NEIGH);
SWSS_LOG_NOTICE("Listens to link and neigh messages...");
netlink.dumpRequest(RTM_GETLINK);
s.addSelectable(&netlink);
ret = s.select(&temps, 1);
if (ret == Select::ERROR)
{
SWSS_LOG_ERROR("Error in RTM_GETLINK dump");
}
netlink.dumpRequest(RTM_GETNEIGH);
s.addSelectable(sync.getFdbStateTable());
s.addSelectable(sync.getCfgEvpnNvoTable());
while (true)
{
s.select(&temps);
if (temps == (Selectable *)sync.getFdbStateTable())
{
sync.processStateFdb();
}
else if (temps == (Selectable *)sync.getCfgEvpnNvoTable())
{
sync.processCfgEvpnNvo();
}
else if (temps == &replayCheckTimer)
{
if (sync.getFdbStateTable()->empty() && sync.getCfgEvpnNvoTable()->empty())
{
sync.getRestartAssist()->appDataReplayed();
SWSS_LOG_NOTICE("FDB Replay Complete, Start Reconcile Check");
reconCheckTimer.setInterval(timespec{FDBSYNC_RECON_TIMER, 0});
reconCheckTimer.start();
s.addSelectable(&reconCheckTimer);
}
else
{
replayCheckTimer.setInterval(timespec{1, 0});
// re-start replay check timer
replayCheckTimer.start();
}
}
else if (temps == &reconCheckTimer)
{
if (sync.isReadyToReconcile())
{
if (sync.getRestartAssist()->isWarmStartInProgress())
{
sync.m_reconcileDone = true;
sync.getRestartAssist()->stopReconcileTimer(s);
sync.getRestartAssist()->reconcile();
SWSS_LOG_NOTICE("VXLAN FDB VNI Reconcillation Complete (Event)");
}
}
else
{
reconCheckTimer.setInterval(timespec{1, 0});
// Restart and check again in 1 sec
reconCheckTimer.start();
}
}
else
{
/*
* If warmstart is in progress, we check the reconcile timer,
* if timer expired, we stop the timer and start the reconcile process
*/
if (sync.getRestartAssist()->isWarmStartInProgress())
{
if (sync.getRestartAssist()->checkReconcileTimer(temps))
{
sync.m_reconcileDone = true;
sync.getRestartAssist()->stopReconcileTimer(s);
sync.getRestartAssist()->reconcile();
SWSS_LOG_NOTICE("VXLAN FDB VNI Reconcillation Complete (Timer)");
}
}
}
}
}
catch (const std::exception& e)
{
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
return 0;
}
}
return 1;
}