-
Notifications
You must be signed in to change notification settings - Fork 390
/
agent_cmn.h
120 lines (99 loc) · 3.18 KB
/
agent_cmn.h
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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_cmn_hpp
#define vnsw_agent_cmn_hpp
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/address.h>
#include <unistd.h>
#include <boost/intrusive_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/nil_generator.hpp>
#include <boost/uuid/string_generator.hpp>
#include <tbb/atomic.h>
#include <tbb/mutex.h>
#include <io/event_manager.h>
#include <db/db.h>
#include <db/db_entry.h>
#include <db/db_table.h>
#include <db/db_table_partition.h>
#include <db/db_table_walker.h>
#include <base/logging.h>
#include <base/task.h>
#include <base/task_trigger.h>
#include <base/task_annotations.h>
#include <base/dependency.h>
#include <base/lifetime.h>
#include <ifmap/ifmap_agent_parser.h>
#include <ifmap/ifmap_agent_table.h>
#include <sandesh/sandesh.h>
#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh_trace.h>
#include <sandesh/common/vns_constants.h>
#include <cmn/agent.h>
#include <cmn/agent_db.h>
static inline bool UnregisterDBTable(DBTable *table,
DBTableBase::ListenerId id) {
table->Unregister(id);
return true;
}
static inline TaskTrigger *SafeDBUnregister(DBTable *table,
DBTableBase::ListenerId id) {
TaskTrigger *trigger =
new TaskTrigger(boost::bind(&UnregisterDBTable, table, id),
TaskScheduler::GetInstance()->GetTaskId("db::DBTable"), 0);
trigger->Set();
return trigger;
}
static inline void CfgUuidSet(uint64_t ms_long, uint64_t ls_long,
boost::uuids::uuid &u) {
for (int i = 0; i < 8; i++) {
u.data[7 - i] = ms_long & 0xFF;
ms_long = ms_long >> 8;
}
for (int i = 0; i < 8; i++) {
u.data[15 - i] = ls_long & 0xFF;
ls_long = ls_long >> 8;
}
}
static inline void CloseTaskFds(void) {
int max_open_fds = sysconf(_SC_OPEN_MAX);
int fd;
for(fd = 3; fd < max_open_fds; fd++)
close(fd);
}
extern SandeshTraceBufferPtr OperDBTraceBuf;
extern bool GetBuildInfo(std::string &build_info_str);
#define OPER_TRACE(obj, ...)\
do {\
Oper##obj::TraceMsg(OperDBTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
} while (false);\
#define IFMAP_ERROR(obj, ...)\
do {\
if (LoggingDisabled()) break;\
obj::Send(g_vns_constants.CategoryNames.find(Category::IFMAP_AGENT)->second,\
SandeshLevel::SYS_ERR, __FILE__, __LINE__, ##__VA_ARGS__);\
} while (false);\
#define AGENT_ERROR(obj, ...)\
do {\
if (LoggingDisabled()) break;\
obj::Send(g_vns_constants.CategoryNames.find(Category::VROUTER)->second,\
SandeshLevel::SYS_ERR, __FILE__, __LINE__, ##__VA_ARGS__);\
} while (false);
#define AGENT_LOG(obj, ...)\
do {\
if (LoggingDisabled()) break;\
obj::Send(g_vns_constants.CategoryNames.find(Category::VROUTER)->second,\
SandeshLevel::SYS_INFO, __FILE__, __LINE__, ##__VA_ARGS__);\
} while (false);
#define AGENT_ASSERT(cond)\
do {\
if (Agent::GetInstance()->debug() == true) {\
assert(cond);\
}\
} while (false);
#endif // vnsw_agent_cmn_hpp