OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <cmn/agent_cmn.h>
9 #include <cmn/index_vector.h>
10 #include <uve/stats_collector.h>
12 #include <pkt/flow_table.h>
14 #include <sandesh/common/flow_types.h>
15 
17 
18 #define FLOW_EXPORT_STATS_TRACE(...)\
19 do {\
20  FlowExportStatsTrace::TraceMsg(FlowExportStatsTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
21 } while (false)
22 
23 class FlowStatsCollector;
27 
29  FlowAgingTableKey(const uint8_t &protocol, const uint16_t &dst_port):
30  proto(protocol), port(dst_port) {}
31 
32  bool operator==(const FlowAgingTableKey &rhs) const {
33  return (proto == rhs.proto && port == rhs.port);
34  }
35 
36  bool operator<(const FlowAgingTableKey &rhs) const {
37  if (proto != rhs.proto) {
38  return proto < rhs.proto;
39  }
40 
41  return port < rhs.port;
42  }
43 
44  uint8_t proto;
45  uint16_t port;
46 };
47 
49  enum Event {
54  };
55 
57  uint64_t interval, uint64_t timeout) :
58  event(ev), key(k), flow_stats_interval(interval),
59  flow_cache_timeout(timeout) {}
60 
62  event(ev), key(k) {}
63 
68 };
69 
71 public:
72  static const uint8_t kCatchAllProto = 0x0;
73  static const uint64_t FlowThresoldUpdateTime = 1000 * 2;
74  static const uint32_t kDefaultFlowSamplingThreshold = 500;
75  static const uint32_t kMinFlowSamplingThreshold = 20;
76 
77  typedef boost::shared_ptr<FlowStatsCollectorObject> FlowAgingTablePtr;
78  typedef boost::shared_ptr<SessionStatsCollectorObject> SessionStatsCollectorPtr;
79 
80  typedef std::map<const FlowAgingTableKey, FlowAgingTablePtr>
82  typedef std::pair<const FlowAgingTableKey, FlowAgingTablePtr>
84 
87 
88  Agent* agent() { return agent_; }
91  }
93  return session_stats_collector_obj_.get();
94  }
95 
96  //Add protocol + port based flow aging table
97  void Add(const FlowAgingTableKey &key,
98  uint64_t flow_stats_interval,
99  uint64_t flow_cache_timeout);
100  void Delete(const FlowAgingTableKey &key);
101  void Free(const FlowAgingTableKey &key);
102 
103  //Add flow entry to particular aging table
104  void AddEvent(FlowEntryPtr &flow);
105  void DeleteEvent(const FlowEntryPtr &flow, const RevFlowDepParams &params);
106  void UpdateStatsEvent(const FlowEntryPtr &flow, uint32_t bytes,
107  uint32_t packets, uint32_t oflow_bytes,
108  const boost::uuids::uuid &u);
109 
110  void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout);
111  void InitDone();
112  void Shutdown();
113 
114  FlowAgingTableMap::iterator begin() {
115  return flow_aging_table_map_.begin();
116  }
117 
118  FlowAgingTableMap::iterator end() {
119  return flow_aging_table_map_.end();
120  }
121 
123  const FlowStatsCollectorObject* Find(uint32_t proto, uint32_t port) const;
124 
125  bool RequestHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
126  void AddReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
127  void DeleteReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
128  void FreeReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
129 
131  return protocol_list_[protocol];
132  }
133  uint32_t session_export_rate() const {
134  return session_export_rate_;
135  }
136 
137  uint32_t session_export_count() const {
138  return session_export_count_;
139  }
140 
141  void set_session_export_count(uint32_t count) {
142  session_export_count_ = count;
143  }
144 
146  return session_export_count_.fetch_and_store(0);
147  }
148 
150  return session_export_without_sampling_.fetch_and_store(0);
151  }
152 
153  uint32_t session_export_drops() const { return session_export_drops_; }
154 
155  uint64_t session_sample_exports() const { return session_sample_exports_; }
156  uint64_t session_msg_exports() const { return session_msg_exports_; }
157  uint64_t session_exports() const { return session_exports_; }
158 
159  uint64_t session_export_disable_drops() const {
161  }
162  uint32_t session_export_sampling_drops() const {
164  }
167  }
168  uint64_t session_slo_logging_drops() const {
170  }
173  }
174 
175  uint64_t threshold() const { return threshold_;}
176  bool delete_short_flow() const {
177  return delete_short_flow_;
178  }
179 
180  void set_delete_short_flow(bool val) {
181  delete_short_flow_ = val;
182  }
183  static void FlowStatsReqHandler(Agent *agent, uint32_t proto,
184  uint32_t port,
185  uint64_t protocol);
186  void FreeIndex(uint32_t idx);
187  uint32_t AllocateIndex();
188  void UpdateSessionSampleExportStats(uint32_t count);
189  void UpdateSessionMsgExportStats(uint32_t count);
190  void UpdateSessionExportStats(uint32_t count, bool first_export,
191  bool sampled);
192 
193  void SetProfileData(ProfileData *data);
194  void RegisterDBClients();
197 private:
198  friend struct FlowStatsCollectorReq;
199  friend class FlowStatsCollector;
200  friend class SessionStatsCollector;
201  bool UpdateSessionThreshold(void);
202  void UpdateThreshold(uint64_t new_value, bool check_oflow);
204  const;
211  uint64_t threshold_;
214  tbb::atomic<uint32_t> session_export_count_;
215  tbb::atomic<uint64_t> session_sample_exports_;
216  tbb::atomic<uint64_t> session_msg_exports_;
217  tbb::atomic<uint64_t> session_exports_;
218  tbb::atomic<uint64_t> session_export_disable_drops_;
219  tbb::atomic<uint64_t> session_export_sampling_drops_;
220  tbb::atomic<uint32_t> session_export_without_sampling_;
221  tbb::atomic<uint64_t> session_export_drops_;
223  tbb::atomic<uint64_t> session_global_slo_logging_drops_;
224  tbb::atomic<uint64_t> session_slo_logging_drops_;
227  //Protocol based array for minimal tree comparision
230 };
231 #endif //vnsw_agent_flow_stats_manager_h
uint32_t session_export_count() const
uint64_t session_export_disable_drops() const
boost::shared_ptr< SessionStatsCollectorObject > SessionStatsCollectorPtr
tbb::atomic< uint64_t > session_exports_
uint64_t session_slo_logging_drops() const
tbb::atomic< bool > sessions_sampled_atleast_once_
tbb::atomic< uint64_t > session_slo_logging_drops_
FlowAgingTableMap flow_aging_table_map_
void Free(const FlowAgingTableKey &key)
void set_delete_short_flow(bool val)
FlowStatsCollectorReq(Event ev, const FlowAgingTableKey &k, uint64_t interval, uint64_t timeout)
boost::shared_ptr< FlowStatsCollectorObject > FlowAgingTablePtr
uint32_t session_export_without_sampling_reset()
FlowAgingTableMap::iterator begin()
boost::uuids::uuid uuid
std::pair< const FlowAgingTableKey, FlowAgingTablePtr > FlowAgingTableEntry
tbb::atomic< uint64_t > session_export_disable_drops_
bool operator<(const FlowAgingTableKey &rhs) const
void set_sessions_sampled_atleast_once()
tbb::atomic< uint64_t > session_global_slo_logging_drops_
void Add(const FlowAgingTableKey &key, uint64_t flow_stats_interval, uint64_t flow_cache_timeout)
tbb::atomic< uint64_t > session_export_drops_
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
uint64_t threshold() const
void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout)
SessionStatsCollectorPtr session_stats_collector_obj_
uint32_t session_export_count_reset()
FlowAgingTableMap::iterator end()
void AddReqHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
FlowAgingTablePtr default_flow_stats_collector_obj_
static const uint32_t kDefaultFlowSamplingThreshold
uint32_t prev_cfg_flow_export_rate_
SessionStatsCollectorObject * session_stats_collector_obj()
Definition: agent.h:358
static const uint32_t kMinFlowSamplingThreshold
void FreeReqHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
bool RequestHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
static void FlowStatsReqHandler(Agent *agent, uint32_t proto, uint32_t port, uint64_t protocol)
void UpdateSessionMsgExportStats(uint32_t count)
void UpdateSessionExportStats(uint32_t count, bool first_export, bool sampled)
friend class AgentUtXmlFlowThresholdValidate
static const uint8_t kCatchAllProto
WorkQueue< boost::shared_ptr< FlowStatsCollectorReq > > request_queue_
void Delete(const FlowAgingTableKey &key)
std::map< const FlowAgingTableKey, FlowAgingTablePtr > FlowAgingTableMap
void AddEvent(FlowEntryPtr &flow)
FlowAgingTableKey(const uint8_t &protocol, const uint16_t &dst_port)
void SetProfileData(ProfileData *data)
SandeshTraceBufferPtr FlowExportStatsTraceBuf
FlowStatsCollectorObject * proto(int protocol)
void UpdateStatsEvent(const FlowEntryPtr &flow, uint32_t bytes, uint32_t packets, uint32_t oflow_bytes, const boost::uuids::uuid &u)
FlowStatsCollector * GetFlowStatsCollector(const FlowEntry *p) const
uint64_t prev_flow_export_rate_compute_time_
void DeleteEvent(const FlowEntryPtr &flow, const RevFlowDepParams &params)
tbb::atomic< uint64_t > session_msg_exports_
uint32_t session_export_drops() const
IndexVector< FlowStatsCollector * > instance_table_
FlowStatsManager(Agent *agent)
friend class AgentUtXmlFlowThreshold
uint64_t session_exports() const
void UpdateThreshold(uint64_t new_value, bool check_oflow)
tbb::atomic< uint64_t > session_export_sampling_drops_
uint32_t session_export_sampling_drops() const
bool delete_short_flow() const
FlowStatsCollectorObject * protocol_list_[256]
bool operator==(const FlowAgingTableKey &rhs) const
tbb::atomic< uint64_t > session_sample_exports_
FlowAgingTableKey key
tbb::atomic< uint32_t > session_export_count_
tbb::atomic< uint32_t > session_export_without_sampling_
FlowStatsCollectorObject * GetFlowStatsCollectorObject(const FlowEntry *flow) const
Definition: timer.h:54
uint64_t session_sample_exports() const
uint32_t session_export_rate() const
static const uint64_t FlowThresoldUpdateTime
void DeleteReqHandler(boost::shared_ptr< FlowStatsCollectorReq > req)
void UpdateSessionSampleExportStats(uint32_t count)
const FlowStatsCollectorObject * Find(uint32_t proto, uint32_t port) const
void FreeIndex(uint32_t idx)
FlowStatsCollectorObject * default_flow_stats_collector_obj()
uint64_t session_global_slo_logging_drops() const
void set_session_export_count(uint32_t count)
uint64_t session_msg_exports() const
boost::intrusive_ptr< FlowEntry > FlowEntryPtr
Definition: flow_entry.h:125
FlowStatsCollectorReq(Event ev, const FlowAgingTableKey &k)