OpenSDN source code
flow_stats_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_flow_stats_maanger_h
6 #define vnsw_agent_flow_stats_maanger_h
7 
8 #include <atomic>
9 
10 
11 #include <cmn/agent_cmn.h>
12 #include <cmn/index_vector.h>
13 #include <uve/stats_collector.h>
15 #include <pkt/flow_table.h>
17 #include <sandesh/common/flow_types.h>
18 
20 
21 #define FLOW_EXPORT_STATS_TRACE(...)\
22 do {\
23  FlowExportStatsTrace::TraceMsg(FlowExportStatsTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
24 } while (false)
25 
26 class FlowStatsCollector;
30 
32  FlowAgingTableKey(const uint8_t &protocol, const uint16_t &dst_port):
33  proto(protocol), port(dst_port) {}
34 
35  bool operator==(const FlowAgingTableKey &rhs) const {
36  return (proto == rhs.proto && port == rhs.port);
37  }
38 
39  bool operator<(const FlowAgingTableKey &rhs) const {
40  if (proto != rhs.proto) {
41  return proto < rhs.proto;
42  }
43 
44  return port < rhs.port;
45  }
46 
47  uint8_t proto;
48  uint16_t port;
49 };
50 
52  enum Event {
57  };
58 
60  uint64_t interval, uint64_t timeout) :
61  event(ev), key(k), flow_stats_interval(interval),
62  flow_cache_timeout(timeout) {}
63 
65  event(ev), key(k) {}
66 
71 };
72 
74 public:
75  static const uint8_t kCatchAllProto = 0x0;
76  static const uint64_t FlowThresoldUpdateTime = 1000 * 2;
77  static const uint32_t kDefaultFlowSamplingThreshold = 500;
78  static const uint32_t kMinFlowSamplingThreshold = 20;
79 
80  typedef boost::shared_ptr<FlowStatsCollectorObject> FlowAgingTablePtr;
81  typedef boost::shared_ptr<SessionStatsCollectorObject> SessionStatsCollectorPtr;
82 
83  typedef std::map<const FlowAgingTableKey, FlowAgingTablePtr>
85  typedef std::pair<const FlowAgingTableKey, FlowAgingTablePtr>
87 
90 
91  Agent* agent() { return agent_; }
94  }
96  return session_stats_collector_obj_.get();
97  }
98 
99  //Add protocol + port based flow aging table
100  void Add(const FlowAgingTableKey &key,
101  uint64_t flow_stats_interval,
102  uint64_t flow_cache_timeout);
103  void Delete(const FlowAgingTableKey &key);
104  void Free(const FlowAgingTableKey &key);
105 
106  //Add flow entry to particular aging table
107  void AddEvent(FlowEntryPtr &flow);
108  void DeleteEvent(const FlowEntryPtr &flow, const RevFlowDepParams &params);
109  void UpdateStatsEvent(const FlowEntryPtr &flow, uint32_t bytes,
110  uint32_t packets, uint32_t oflow_bytes,
111  const boost::uuids::uuid &u);
112 
113  void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout);
114  void InitDone();
115  void Shutdown();
116 
117  FlowAgingTableMap::iterator begin() {
118  return flow_aging_table_map_.begin();
119  }
120 
121  FlowAgingTableMap::iterator end() {
122  return flow_aging_table_map_.end();
123  }
124 
126  const FlowStatsCollectorObject* Find(uint32_t proto, uint32_t port) const;
127 
128  bool RequestHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
129  void AddReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
130  void DeleteReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
131  void FreeReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
132 
134  return protocol_list_[protocol];
135  }
136  uint32_t session_export_rate() const {
137  return session_export_rate_;
138  }
139 
140  uint32_t session_export_count() const {
141  return session_export_count_;
142  }
143 
144  void set_session_export_count(uint32_t count) {
145  session_export_count_ = count;
146  }
147 
149  return session_export_count_.exchange(0);
150  }
151 
153  return session_export_without_sampling_.exchange(0);
154  }
155 
156  uint32_t session_export_drops() const { return session_export_drops_; }
157 
158  uint64_t session_sample_exports() const { return session_sample_exports_; }
159  uint64_t session_msg_exports() const { return session_msg_exports_; }
160  uint64_t session_exports() const { return session_exports_; }
161 
162  uint64_t session_export_disable_drops() const {
164  }
165  uint32_t session_export_sampling_drops() const {
167  }
170  }
171  uint64_t session_slo_logging_drops() const {
173  }
176  }
177 
178  uint64_t threshold() const { return threshold_;}
179  bool delete_short_flow() const {
180  return delete_short_flow_;
181  }
182 
183  void set_delete_short_flow(bool val) {
184  delete_short_flow_ = val;
185  }
186  static void FlowStatsReqHandler(Agent *agent, uint32_t proto,
187  uint32_t port,
188  uint64_t protocol);
189  void FreeIndex(uint32_t idx);
190  uint32_t AllocateIndex();
191  void UpdateSessionSampleExportStats(uint32_t count);
192  void UpdateSessionMsgExportStats(uint32_t count);
193  void UpdateSessionExportStats(uint32_t count, bool first_export,
194  bool sampled);
195 
196  void SetProfileData(ProfileData *data);
197  void RegisterDBClients();
200 private:
201  friend struct FlowStatsCollectorReq;
202  friend class FlowStatsRecordsReq;
203  friend class FlowStatsCollector;
204  friend class SessionStatsCollector;
205  bool UpdateSessionThreshold(void);
206  void UpdateThreshold(uint64_t new_value, bool check_oflow);
208  const;
215  uint64_t threshold_;
218  std::atomic<uint32_t> session_export_count_;
219  std::atomic<uint64_t> session_sample_exports_;
220  std::atomic<uint64_t> session_msg_exports_;
221  std::atomic<uint64_t> session_exports_;
222  std::atomic<uint64_t> session_export_disable_drops_;
223  std::atomic<uint64_t> session_export_sampling_drops_;
224  std::atomic<uint32_t> session_export_without_sampling_;
225  std::atomic<uint64_t> session_export_drops_;
227  std::atomic<uint64_t> session_global_slo_logging_drops_;
228  std::atomic<uint64_t> session_slo_logging_drops_;
231  //Protocol based array for minimal tree comparision
234 };
235 #endif //vnsw_agent_flow_stats_manager_h
Definition: agent.h:360
void UpdateStatsEvent(const FlowEntryPtr &flow, uint32_t bytes, uint32_t packets, uint32_t oflow_bytes, const boost::uuids::uuid &u)
std::atomic< uint64_t > session_export_disable_drops_
void FreeIndex(uint32_t idx)
void UpdateSessionSampleExportStats(uint32_t count)
uint32_t prev_cfg_flow_export_rate_
uint64_t session_sample_exports() const
bool delete_short_flow() const
std::atomic< uint64_t > session_global_slo_logging_drops_
IndexVector< FlowStatsCollector * > instance_table_
void DeleteReqHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
uint64_t threshold() const
void AddEvent(FlowEntryPtr &flow)
boost::shared_ptr< SessionStatsCollectorObject > SessionStatsCollectorPtr
std::atomic< bool > sessions_sampled_atleast_once_
FlowAgingTableMap::iterator begin()
void set_delete_short_flow(bool val)
friend class FlowStatsRecordsReq
static const uint32_t kDefaultFlowSamplingThreshold
uint32_t session_export_drops() const
uint32_t session_export_count_reset()
std::atomic< uint64_t > session_slo_logging_drops_
std::atomic< uint64_t > session_msg_exports_
void set_sessions_sampled_atleast_once()
static void FlowStatsReqHandler(Agent *agent, uint32_t proto, uint32_t port, uint64_t protocol)
SessionStatsCollectorPtr session_stats_collector_obj_
static const uint8_t kCatchAllProto
std::atomic< uint32_t > session_export_count_
friend class AgentUtXmlFlowThresholdValidate
std::atomic< uint64_t > session_export_drops_
void UpdateSessionExportStats(uint32_t count, bool first_export, bool sampled)
boost::shared_ptr< FlowStatsCollectorObject > FlowAgingTablePtr
const FlowStatsCollectorObject * Find(uint32_t proto, uint32_t port) const
void Delete(const FlowAgingTableKey &key)
uint32_t session_export_sampling_drops() const
FlowStatsManager(Agent *agent)
static const uint64_t FlowThresoldUpdateTime
std::map< const FlowAgingTableKey, FlowAgingTablePtr > FlowAgingTableMap
std::atomic< uint64_t > session_export_sampling_drops_
FlowStatsCollectorObject * GetFlowStatsCollectorObject(const FlowEntry *flow) const
uint32_t session_export_count() const
void AddReqHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
FlowStatsCollectorObject * protocol_list_[256]
void Free(const FlowAgingTableKey &key)
uint64_t session_slo_logging_drops() const
uint64_t prev_flow_export_rate_compute_time_
WorkQueue< boost::shared_ptr< FlowStatsCollectorReq > > request_queue_
void set_session_export_count(uint32_t count)
void DeleteEvent(const FlowEntryPtr &flow, const RevFlowDepParams &params)
std::atomic< uint64_t > session_sample_exports_
friend class AgentUtXmlFlowThreshold
void FreeReqHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
bool RequestHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
std::atomic< uint64_t > session_exports_
std::atomic< uint32_t > session_export_without_sampling_
uint64_t session_exports() const
std::pair< const FlowAgingTableKey, FlowAgingTablePtr > FlowAgingTableEntry
FlowStatsCollector * GetFlowStatsCollector(const FlowEntry *p) const
void UpdateThreshold(uint64_t new_value, bool check_oflow)
void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout)
uint64_t session_global_slo_logging_drops() const
FlowStatsCollectorObject * default_flow_stats_collector_obj()
SessionStatsCollectorObject * session_stats_collector_obj()
void Add(const FlowAgingTableKey &key, uint64_t flow_stats_interval, uint64_t flow_cache_timeout)
uint64_t session_export_disable_drops() const
uint64_t session_msg_exports() const
FlowAgingTableMap flow_aging_table_map_
static const uint32_t kMinFlowSamplingThreshold
uint32_t session_export_rate() const
FlowAgingTablePtr default_flow_stats_collector_obj_
uint32_t session_export_without_sampling_reset()
void SetProfileData(ProfileData *data)
void UpdateSessionMsgExportStats(uint32_t count)
FlowStatsCollectorObject * proto(int protocol)
FlowAgingTableMap::iterator end()
Definition: timer.h:57
boost::intrusive_ptr< FlowEntry > FlowEntryPtr
Definition: flow_entry.h:125
SandeshTraceBufferPtr FlowExportStatsTraceBuf
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
FlowAgingTableKey(const uint8_t &protocol, const uint16_t &dst_port)
bool operator==(const FlowAgingTableKey &rhs) const
bool operator<(const FlowAgingTableKey &rhs) const
FlowStatsCollectorReq(Event ev, const FlowAgingTableKey &k, uint64_t interval, uint64_t timeout)
FlowAgingTableKey key
FlowStatsCollectorReq(Event ev, const FlowAgingTableKey &k)
boost::uuids::uuid uuid