forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvxlanmgrd.cpp
123 lines (105 loc) · 3.37 KB
/
vxlanmgrd.cpp
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
#include <unistd.h>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include <mutex>
#include <algorithm>
#include "dbconnector.h"
#include "select.h"
#include "exec.h"
#include "schema.h"
#include "macaddress.h"
#include "producerstatetable.h"
#include "vxlanmgr.h"
#include "shellcmd.h"
#include "warm_restart.h"
using namespace std;
using namespace swss;
/* select() function timeout retry time, in millisecond */
#define SELECT_TIMEOUT 1000
MacAddress gMacAddress;
int main(int argc, char **argv)
{
Logger::linkToDbNative("vxlanmgrd");
SWSS_LOG_NOTICE("--- Starting vxlanmgrd ---");
try
{
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);
WarmStart::initialize("vxlanmgrd", "swss");
WarmStart::checkWarmStart("vxlanmgrd", "swss");
if (WarmStart::isWarmStart())
{
WarmStart::setWarmStartState("vxlanmgrd", WarmStart::INITIALIZED);
}
vector<std::string> cfg_vnet_tables = {
CFG_VNET_TABLE_NAME,
CFG_VXLAN_TUNNEL_TABLE_NAME,
CFG_VXLAN_TUNNEL_MAP_TABLE_NAME,
CFG_VXLAN_EVPN_NVO_TABLE_NAME,
};
VxlanMgr vxlanmgr(&cfgDb, &appDb, &stateDb, cfg_vnet_tables);
std::vector<Orch *> cfgOrchList = {&vxlanmgr};
swss::Select s;
for (Orch *o : cfgOrchList)
{
s.addSelectables(o->getSelectables());
}
/*
* swss service starts after interfaces-config.service which will have
* switch_mac set.
* Dynamic switch_mac update is not supported for now.
*/
Table table(&cfgDb, "DEVICE_METADATA");
std::vector<FieldValueTuple> ovalues;
table.get("localhost", ovalues);
auto it = std::find_if( ovalues.begin(), ovalues.end(), [](const FieldValueTuple& t){ return t.first == "mac";} );
if ( it == ovalues.end() ) {
throw runtime_error("couldn't find MAC address of the device from config DB");
}
gMacAddress = MacAddress(it->second);
auto in_recon = true;
vxlanmgr.beginReconcile(true);
if (WarmStart::isWarmStart())
{
vxlanmgr.waitTillReadyToReconcile();
vxlanmgr.restoreVxlanNetDevices();
WarmStart::setWarmStartState("vxlanmgrd", WarmStart::REPLAYED);
}
SWSS_LOG_NOTICE("starting main loop");
while (true)
{
Selectable *sel;
int ret;
ret = s.select(&sel, SELECT_TIMEOUT);
if (ret == Select::ERROR)
{
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
continue;
}
if (ret == Select::TIMEOUT)
{
if (true == in_recon)
{
in_recon = false;
vxlanmgr.endReconcile(false);
if (WarmStart::isWarmStart())
{
WarmStart::setWarmStartState("vxlanmgrd", WarmStart::RECONCILED);
}
}
vxlanmgr.doTask();
continue;
}
auto *c = (Executor *)sel;
c->execute();
}
}
catch(const std::exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
return -1;
}