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  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_flow_stats_maanger_h
7 #define vnsw_agent_flow_stats_maanger_h
8 
9 #include <atomic>
10 
11 
12 #include <cmn/agent_cmn.h>
13 #include <cmn/index_vector.h>
14 #include <uve/stats_collector.h>
16 #include <pkt/flow_table.h>
18 #include <sandesh/common/flow_types.h>
19 
21 
22 #define FLOW_EXPORT_STATS_TRACE(...)\
23 do {\
24  FlowExportStatsTrace::TraceMsg(FlowExportStatsTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
25 } while (false)
26 
27 class FlowStatsCollector;
31 
33  FlowAgingTableKey(const uint8_t &protocol, const uint16_t &dst_port):
34  proto(protocol), port(dst_port) {}
35 
36  bool operator==(const FlowAgingTableKey &rhs) const {
37  return (proto == rhs.proto && port == rhs.port);
38  }
39 
40  bool operator<(const FlowAgingTableKey &rhs) const {
41  if (proto != rhs.proto) {
42  return proto < rhs.proto;
43  }
44 
45  return port < rhs.port;
46  }
47 
48  uint8_t proto;
49  uint16_t port;
50 };
51 
53  enum Event {
58  };
59 
61  uint64_t interval, uint64_t timeout) :
62  event(ev), key(k), flow_stats_interval(interval),
63  flow_cache_timeout(timeout) {}
64 
66  event(ev), key(k) {}
67 
72 };
73 
75 public:
76  static const uint8_t kCatchAllProto = 0x0;
77  static const uint64_t FlowThresoldUpdateTime = 1000 * 2;
78  static const uint32_t kDefaultFlowSamplingThreshold = 500;
79  static const uint32_t kMinFlowSamplingThreshold = 20;
80 
81  typedef boost::shared_ptr<FlowStatsCollectorObject> FlowAgingTablePtr;
82  typedef boost::shared_ptr<SessionStatsCollectorObject> SessionStatsCollectorPtr;
83 
84  typedef std::map<const FlowAgingTableKey, FlowAgingTablePtr>
86  typedef std::pair<const FlowAgingTableKey, FlowAgingTablePtr>
88 
91 
92  Agent* agent() { return agent_; }
95  }
97  return session_stats_collector_obj_.get();
98  }
99 
100  //Add protocol + port based flow aging table
101  void Add(const FlowAgingTableKey &key,
102  uint64_t flow_stats_interval,
103  uint64_t flow_cache_timeout);
104  void Delete(const FlowAgingTableKey &key);
105  void Free(const FlowAgingTableKey &key);
106 
107  //Add flow entry to particular aging table
108  void AddEvent(FlowEntryPtr &flow);
109  void DeleteEvent(const FlowEntryPtr &flow, const RevFlowDepParams &params);
110  void UpdateStatsEvent(const FlowEntryPtr &flow, uint32_t bytes,
111  uint32_t packets, uint32_t oflow_bytes,
112  const boost::uuids::uuid &u);
113 
114  void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout);
115  void InitDone();
116  void Shutdown();
117 
118  FlowAgingTableMap::iterator begin() {
119  return flow_aging_table_map_.begin();
120  }
121 
122  FlowAgingTableMap::iterator end() {
123  return flow_aging_table_map_.end();
124  }
125 
127  const FlowStatsCollectorObject* Find(uint32_t proto, uint32_t port) const;
128 
129  bool RequestHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
130  void AddReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
131  void DeleteReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
132  void FreeReqHandler(boost::shared_ptr<FlowStatsCollectorReq> req);
133 
135  return protocol_list_[protocol];
136  }
137  uint32_t session_export_rate() const {
138  return session_export_rate_;
139  }
140 
141  uint32_t session_export_count() const {
142  return session_export_count_;
143  }
144 
145  void set_session_export_count(uint32_t count) {
146  session_export_count_ = count;
147  }
148 
150  return session_export_count_.exchange(0);
151  }
152 
154  return session_export_without_sampling_.exchange(0);
155  }
156 
157  uint32_t session_export_drops() const { return session_export_drops_; }
158 
159  uint64_t session_sample_exports() const { return session_sample_exports_; }
160  uint64_t session_msg_exports() const { return session_msg_exports_; }
161  uint64_t session_exports() const { return session_exports_; }
162 
163  uint64_t session_export_disable_drops() const {
165  }
166  uint32_t session_export_sampling_drops() const {
168  }
171  }
172  uint64_t session_slo_logging_drops() const {
174  }
177  }
178 
179  uint64_t threshold() const { return threshold_;}
180  bool delete_short_flow() const {
181  return delete_short_flow_;
182  }
183 
184  void set_delete_short_flow(bool val) {
185  delete_short_flow_ = val;
186  }
187  static void FlowStatsReqHandler(Agent *agent, uint32_t proto,
188  uint32_t port,
189  uint64_t protocol);
190  void FreeIndex(uint32_t idx);
191  uint32_t AllocateIndex();
192  void UpdateSessionSampleExportStats(uint32_t count);
193  void UpdateSessionMsgExportStats(uint32_t count);
194  void UpdateSessionExportStats(uint32_t count, bool first_export,
195  bool sampled);
196 
197  void SetProfileData(ProfileData *data);
198  void RegisterDBClients();
201 private:
202  friend struct FlowStatsCollectorReq;
203  friend class FlowStatsRecordsReq;
204  friend class FlowStatsCollector;
205  friend class SessionStatsCollector;
206  bool UpdateSessionThreshold(void);
207  void UpdateThreshold(uint64_t new_value, bool check_oflow);
209  const;
216  uint64_t threshold_;
219  std::atomic<uint32_t> session_export_count_;
220  std::atomic<uint64_t> session_sample_exports_;
221  std::atomic<uint64_t> session_msg_exports_;
222  std::atomic<uint64_t> session_exports_;
223  std::atomic<uint64_t> session_export_disable_drops_;
224  std::atomic<uint64_t> session_export_sampling_drops_;
225  std::atomic<uint32_t> session_export_without_sampling_;
226  std::atomic<uint64_t> session_export_drops_;
228  std::atomic<uint64_t> session_global_slo_logging_drops_;
229  std::atomic<uint64_t> session_slo_logging_drops_;
232  //Protocol based array for minimal tree comparision
235 };
236 #endif //vnsw_agent_flow_stats_manager_h
Definition: agent.h:361
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:58
boost::intrusive_ptr< FlowEntry > FlowEntryPtr
Definition: flow_entry.h:126
SandeshTraceBufferPtr FlowExportStatsTraceBuf
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:19
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