forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsflowmgrd.cpp
82 lines (68 loc) · 2.09 KB
/
sflowmgrd.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
#include <fstream>
#include <iostream>
#include <mutex>
#include <unistd.h>
#include <vector>
#include "exec.h"
#include "sflowmgr.h"
#include "schema.h"
#include "select.h"
using namespace std;
using namespace swss;
/* select() function timeout retry time, in millisecond */
#define SELECT_TIMEOUT 1000
int main(int argc, char **argv)
{
Logger::linkToDbNative("sflowmgrd");
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("--- Starting sflowmgrd ---");
try
{
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);
TableConnector conf_port_table(&cfgDb, CFG_PORT_TABLE_NAME);
TableConnector state_port_table(&stateDb, STATE_PORT_TABLE_NAME);
TableConnector conf_sflow_table(&cfgDb, CFG_SFLOW_TABLE_NAME);
TableConnector conf_sflow_session_table(&cfgDb, CFG_SFLOW_SESSION_TABLE_NAME);
vector<TableConnector> sflow_tables = {
conf_port_table,
state_port_table,
conf_sflow_table,
conf_sflow_session_table
};
SflowMgr sflowmgr(&appDb, sflow_tables);
/* During process startup, the ordering of config_db followed by state_db notifications cannot be guaranteed
and so handle the config events manually */
sflowmgr.readPortConfig();
vector<Orch *> orchList = {&sflowmgr};
swss::Select s;
for (Orch *o : orchList)
{
s.addSelectables(o->getSelectables());
}
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)
{
sflowmgr.doTask();
continue;
}
auto *c = (Executor *)sel;
c->execute();
}
}
catch (const exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
return -1;
}