/
flow_stats_collector.h
221 lines (205 loc) · 9.43 KB
/
flow_stats_collector.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_flow_stats_collector_h
#define vnsw_agent_flow_stats_collector_h
#include <pkt/flow_table.h>
#include <pkt/flow_mgmt_request.h>
#include <cmn/agent_cmn.h>
#include <cmn/index_vector.h>
#include <uve/stats_collector.h>
#include <uve/interface_uve_stats_table.h>
#include <vrouter/ksync/flowtable_ksync.h>
#include <sandesh/common/flow_types.h>
#include <vrouter/flow_stats/flow_export_request.h>
#include <vrouter/flow_stats/flow_export_info.h>
#include <vrouter/flow_stats/flow_stats_manager.h>
// Forward declaration
class AgentUtXmlFlowThreshold;
class AgentUtXmlFlowThresholdValidate;
class FlowStatsRecordsReq;
class FetchFlowStatsRecord;
class FlowStatsManager;
//Defines the functionality to periodically read flow stats from
//shared memory (between agent and Kernel) and export this stats info to
//collector. Also responsible for aging of flow entries. Runs in the context
//of kTaskFlowStatsCollector which has exclusion with "db::DBTable",
class FlowStatsCollector : public StatsCollector {
public:
static const uint64_t FlowAgeTime = 1000000 * 180;
static const uint32_t kFlowStatsTimerInterval = 50; // time in milliseconds
// Min time in milliseconds
static const uint32_t kFlowStatsTimerIntervalMin = 5;
static const uint64_t FlowTcpSynAgeTime = 1000000 * 180;
// Retry flow-delete after 2 second
static const uint64_t kFlowDeleteRetryTime = (5 * 1000 * 1000);
// Time within which complete table must be scanned
// Specified in terms of percentage of aging-time
static const uint8_t kFlowScanTime = 25;
// Flow timer interval
static const uint32_t kFlowStatsInterval = 50;
// Minimum flows to visit per interval
static const uint32_t kMinFlowsPerTimer = 500;
static const uint32_t kDefaultFlowSamplingThreshold = 500;
static const uint8_t kMaxFlowMsgsPerSend = 16;
typedef std::map<const FlowEntry*, FlowExportInfo> FlowEntryTree;
FlowStatsCollector(boost::asio::io_service &io, int intvl,
uint32_t flow_cache_timeout,
AgentUveBase *uve, uint32_t instance_id,
FlowAgingTableKey *key,
FlowStatsManager *aging_module);
virtual ~FlowStatsCollector();
uint64_t flow_age_time_intvl() { return flow_age_time_intvl_; }
void set_flow_age_time_intvl(uint64_t interval) {
flow_age_time_intvl_ = interval;
}
uint32_t flow_age_time_intvl_in_secs() const {
return flow_age_time_intvl_/(1000 * 1000);
}
uint64_t flow_tcp_syn_age_time() const {
return flow_tcp_syn_age_time_;
}
void set_flow_tcp_syn_age_time(uint64_t interval) {
flow_tcp_syn_age_time_ = interval;
}
uint32_t flow_export_count() const { return flow_export_count_; }
void set_flow_export_count(uint32_t val) { flow_export_count_ = val; }
uint32_t flow_export_rate() const { return flow_export_rate_; }
uint32_t threshold() const;
uint64_t flow_export_msg_drops() const { return flow_export_msg_drops_; }
boost::uuids::uuid rand_gen();
bool Run();
void UpdateFlowAgeTime(uint64_t usecs) {
flow_age_time_intvl_ = usecs;
}
void UpdateFlowAgeTimeInSecs(uint32_t secs) {
UpdateFlowAgeTime(secs * 1000 * 1000);
}
void UpdateFloatingIpStats(const FlowEntry *flow, uint64_t bytes,
uint64_t pkts);
void Shutdown();
void set_delete_short_flow(bool val) { delete_short_flow_ = val; }
void AddEvent(const FlowEntryPtr &flow);
void DeleteEvent(const FlowEntryPtr &flow, const RevFlowDepParams ¶ms);
void SourceIpOverride(FlowExportInfo *info, FlowLogData &s_flow,
const RevFlowDepParams *params);
FlowExportInfo *FindFlowExportInfo(const FlowEntry *fe);
const FlowExportInfo *FindFlowExportInfo(const FlowEntry *fe) const;
void ExportFlow(FlowExportInfo *info, uint64_t diff_bytes,
uint64_t diff_pkts, const RevFlowDepParams *params);
void UpdateFloatingIpStats(const FlowExportInfo *flow,
uint64_t bytes, uint64_t pkts);
void UpdateStatsEvent(const FlowEntryPtr &flow, uint32_t bytes,
uint32_t packets, uint32_t oflow_bytes);
size_t Size() const { return flow_tree_.size(); }
void NewFlow(const FlowExportInfo &info);
void set_deleted(bool val) {
deleted_ = val;
}
bool deleted() const {
return deleted_;
}
bool user_configured() const { return user_configured_; }
void set_user_configured(bool value) { user_configured_ = value; }
const FlowAgingTableKey& flow_aging_key() const {
return flow_aging_key_;
}
friend class AgentUtXmlFlowThreshold;
friend class AgentUtXmlFlowThresholdValidate;
friend class FlowStatsRecordsReq;
friend class FetchFlowStatsRecord;
friend class FlowStatsManager;
protected:
virtual void DispatchFlowMsg(const std::vector<FlowLogData> &lst);
private:
void ExportFlowLocked(FlowExportInfo *info, uint64_t diff_bytes,
uint64_t diff_pkts, const RevFlowDepParams *params);
uint64_t GetScanTime();
void UpdateAgingParameters();
void UpdateStatsAndExportFlow(FlowExportInfo *info, uint64_t teardown_time,
const RevFlowDepParams *params);
void EvictedFlowStatsUpdate(const FlowEntryPtr &flow,
uint32_t bytes,
uint32_t packets,
uint32_t oflow_bytes);
void UpdateAndExportInternal(FlowExportInfo *info,
uint32_t bytes,
uint16_t oflow_bytes,
uint32_t pkts,
uint16_t oflow_pkts,
uint64_t time,
bool teardown_time,
const RevFlowDepParams *params);
void UpdateAndExportInternalLocked(FlowExportInfo *info,
uint32_t bytes,
uint16_t oflow_bytes,
uint32_t pkts,
uint16_t oflow_pkts,
uint64_t time,
bool teardown_time,
const RevFlowDepParams *params);
void UpdateFlowStatsInternal(FlowExportInfo *info,
uint32_t bytes,
uint16_t oflow_bytes,
uint32_t pkts,
uint16_t oflow_pkts,
uint64_t time,
bool teardown_time,
uint64_t *diff_bytes,
uint64_t *diff_pkts);
void FlowDeleteEnqueue(FlowExportInfo *info, uint64_t t);
void EnqueueFlowMsg();
void DispatchPendingFlowMsg();
void GetFlowSandeshActionParams(const FlowAction &action_info,
std::string &action_str);
void SetUnderlayInfo(FlowExportInfo *info, FlowLogData &s_flow);
void UpdateThreshold(uint32_t new_value);
void UpdateInterVnStats(FlowExportInfo *info,
uint64_t bytes, uint64_t pkts);
uint64_t GetFlowStats(const uint16_t &oflow_data, const uint32_t &data);
bool ShouldBeAged(FlowExportInfo *info, const vr_flow_entry *k_flow,
uint64_t curr_time);
uint64_t GetUpdatedFlowPackets(const FlowExportInfo *stats,
uint64_t k_flow_pkts);
uint64_t GetUpdatedFlowBytes(const FlowExportInfo *stats,
uint64_t k_flow_bytes);
InterfaceUveTable::FloatingIp *ReverseFlowFipEntry
(const FlowExportInfo *flow);
uint32_t ReverseFlowFip(const FlowExportInfo *info);
VmInterfaceKey ReverseFlowFipVmi(const FlowExportInfo *info);
bool RequestHandler(boost::shared_ptr<FlowExportReq> req);
void AddFlow(FlowExportInfo info);
void DeleteFlow(const FlowEntryPtr &flow);
void HandleFlowStatsUpdate(const FlowKey &key, uint32_t bytes,
uint32_t packets, uint32_t oflow_bytes);
void UpdateFlowStats(FlowExportInfo *flow, uint64_t &diff_bytes,
uint64_t &diff_pkts);
uint8_t GetFlowMsgIdx();
AgentUveBase *agent_uve_;
boost::uuids::random_generator rand_gen_;
const FlowEntry* flow_iteration_key_;
uint64_t flow_age_time_intvl_;
uint32_t flow_count_per_pass_;
uint32_t flow_multiplier_;
uint32_t flow_default_interval_;
// Should short-flow be deleted immediately?
// Value will be set to false for test cases
bool delete_short_flow_;
uint64_t flow_tcp_syn_age_time_;
FlowEntryTree flow_tree_;
WorkQueue<boost::shared_ptr<FlowExportReq> > request_queue_;
uint32_t flow_export_count_;
uint64_t prev_flow_export_rate_compute_time_;
uint32_t flow_export_rate_;
uint64_t flow_export_msg_drops_;
uint32_t prev_cfg_flow_export_rate_;
std::vector<FlowLogData> msg_list_;
uint8_t msg_index_;
tbb::atomic<bool> deleted_;
FlowAgingTableKey flow_aging_key_;
uint32_t instance_id_;
FlowStatsManager *flow_stats_manager_;
bool user_configured_;
DISALLOW_COPY_AND_ASSIGN(FlowStatsCollector);
};
#endif //vnsw_agent_flow_stats_collector_h