Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : * 5 : * Global vnswad statistics 6 : */ 7 : 8 : #ifndef vnsw_agent_stats_hpp 9 : #define vnsw_agent_stats_hpp 10 : 11 : #include <stdint.h> 12 : #include <atomic> 13 : 14 : typedef boost::function<uint32_t()> FlowCountFn; 15 : class AgentStats { 16 : public: 17 : static const uint32_t kInvalidFlowCount = 0xFFFFFFFF; 18 : static const int kFlowStatsUpdateInterval = 1000; 19 : struct FlowCounters { 20 : uint64_t prev_flow_count; //previous flow created/aged count 21 : uint32_t max_flows_per_second; //max_flows_added/deleted_per_second 22 : uint32_t min_flows_per_second; //min_flows_added/deleted_per_second 23 : 24 656 : FlowCounters() : prev_flow_count(0), 25 656 : max_flows_per_second(kInvalidFlowCount), 26 656 : min_flows_per_second(kInvalidFlowCount) { 27 656 : } 28 : }; 29 : 30 2 : AgentStats(Agent *agent) 31 14 : : agent_(agent), xmpp_reconnect_(), xmpp_in_msgs_(), xmpp_out_msgs_(), 32 6 : xmpp_config_in_msgs_(), sandesh_reconnects_(0U), 33 2 : sandesh_in_msgs_(0U), sandesh_out_msgs_(0U), 34 2 : sandesh_http_sessions_(0U), nh_count_(0U), pkt_exceptions_(0U), 35 2 : pkt_invalid_agent_hdr_(0U), pkt_invalid_interface_(0U), 36 2 : pkt_no_handler_(0U), pkt_fragments_dropped_(0U), pkt_dropped_(0U), 37 2 : pkt_invalid_mpls_hdr_(0U), pkt_invalid_ip_pkt_(0U), pkt_drop_due_to_disable_tnl_(0U), 38 2 : pkt_invalid_frm_tor_(0U), pkt_drop_due_to_decode_error_(0U), pkt_drop_due_to_invalid_ethertype_(0U), 39 2 : pkt_drop_due_to_flow_trap_(0U), 40 2 : max_flow_count_(0), 41 2 : flow_drop_due_to_max_limit_(0), flow_drop_due_to_linklocal_limit_(0), 42 2 : flow_stats_update_timeout_(kFlowStatsUpdateInterval), 43 2 : ipc_in_msgs_(0U), ipc_out_msgs_(0U), in_tpkts_(0U), in_bytes_(0U), 44 4 : out_tpkts_(0U), out_bytes_(0U) { 45 2 : assert(singleton_ == NULL); 46 2 : singleton_ = this; 47 2 : flow_count_ = 0; 48 2 : flow_created_ = 0; 49 2 : flow_aged_ = 0; 50 2 : hold_flow_count_ = 0; 51 2 : } 52 : 53 4 : virtual ~AgentStats() {singleton_ = NULL;} 54 : 55 60 : static AgentStats *GetInstance() {return singleton_;} 56 2 : void Shutdown() { } 57 : 58 : void Reset(); 59 19 : void incr_xmpp_reconnects(uint8_t idx) {xmpp_reconnect_[idx]++;} 60 103 : uint32_t xmpp_reconnects(uint8_t idx) const { 61 103 : return xmpp_reconnect_[idx]; 62 : } 63 : 64 0 : void incr_xmpp_in_msgs(uint8_t idx) {xmpp_in_msgs_[idx]++;} 65 0 : uint64_t xmpp_in_msgs(uint8_t idx) const {return xmpp_in_msgs_[idx];} 66 : 67 541 : void incr_xmpp_out_msgs(uint8_t idx) {xmpp_out_msgs_[idx]++;} 68 0 : uint64_t xmpp_out_msgs(uint8_t idx) const {return xmpp_out_msgs_[idx];} 69 : 70 0 : void incr_xmpp_config_in_msgs(uint8_t idx) {xmpp_config_in_msgs_[idx]++;} 71 0 : uint64_t xmpp_config_in_msgs(uint8_t idx) const { 72 0 : return xmpp_config_in_msgs_[idx]; 73 : } 74 : 75 : void incr_sandesh_reconnects() {sandesh_reconnects_++;} 76 0 : uint32_t sandesh_reconnects() const {return sandesh_reconnects_;} 77 : 78 : void incr_sandesh_in_msgs() {sandesh_in_msgs_++;} 79 0 : uint64_t sandesh_in_msgs() const {return sandesh_in_msgs_;} 80 : 81 : void incr_sandesh_out_msgs() {sandesh_out_msgs_++;} 82 0 : uint64_t sandesh_out_msgs() const {return sandesh_out_msgs_;} 83 : 84 : void incr_sandesh_http_sessions() {sandesh_http_sessions_++;} 85 0 : uint32_t sandesh_http_sessions() const {return sandesh_http_sessions_;} 86 : 87 144 : void incr_flow_created() { 88 144 : flow_created_++; 89 144 : uint32_t count = flow_count_.fetch_add(1); 90 144 : if (count > max_flow_count_) 91 25 : max_flow_count_ = count + 1; 92 144 : } 93 144 : void decr_flow_count() { 94 144 : flow_count_--; 95 144 : } 96 : 97 0 : void update_hold_flow_count(uint32_t value) { 98 0 : hold_flow_count_ = value; 99 0 : } 100 : 101 0 : uint64_t flow_created() const {return flow_created_;} 102 : 103 0 : uint64_t max_flow_count() const {return max_flow_count_;} 104 : 105 2 : uint32_t hold_flow_count() const {return hold_flow_count_;} 106 : 107 144 : void incr_flow_aged() { flow_aged_++; } 108 0 : uint64_t flow_aged() const {return flow_aged_;} 109 : 110 4 : int flow_stats_update_timeout() const { 111 4 : return flow_stats_update_timeout_; 112 : } 113 : 114 2 : void set_flow_stats_update_timeout(int value) { 115 2 : flow_stats_update_timeout_ = value; 116 2 : } 117 : 118 0 : void incr_flow_drop_due_to_max_limit() {flow_drop_due_to_max_limit_++;} 119 0 : uint64_t flow_drop_due_to_max_limit() const { 120 0 : return flow_drop_due_to_max_limit_; 121 : } 122 : void incr_flow_drop_due_to_linklocal_limit() { 123 : flow_drop_due_to_linklocal_limit_++; 124 : } 125 0 : uint64_t flow_drop_due_to_linklocal_limit() const { 126 0 : return flow_drop_due_to_linklocal_limit_; 127 : } 128 : 129 75 : void incr_pkt_exceptions() {pkt_exceptions_++;} 130 0 : uint64_t pkt_exceptions() const {return pkt_exceptions_;} 131 : 132 1 : void incr_pkt_invalid_agent_hdr() {pkt_invalid_agent_hdr_++;} 133 0 : uint64_t pkt_invalid_agent_hdr() const {return pkt_invalid_agent_hdr_;} 134 : 135 0 : void incr_pkt_invalid_interface() {pkt_invalid_interface_++;} 136 0 : uint64_t pkt_invalid_interface() const {return pkt_invalid_interface_;} 137 : 138 : void incr_pkt_no_handler() {pkt_no_handler_++;} 139 0 : uint64_t pkt_no_handler() const {return pkt_no_handler_;} 140 : 141 0 : void incr_pkt_fragments_dropped() {pkt_fragments_dropped_++;} 142 0 : uint64_t pkt_fragments_dropped() const {return pkt_fragments_dropped_;} 143 : 144 : void incr_pkt_invalid_mpls_hdr() {pkt_invalid_mpls_hdr_++;} 145 0 : uint64_t pkt_invalid_mpls_hdr() const {return pkt_invalid_mpls_hdr_;} 146 : 147 0 : void incr_pkt_invalid_ip_pkt() {pkt_invalid_ip_pkt_++;} 148 0 : uint64_t pkt_invalid_ip_pkt() const {return pkt_invalid_ip_pkt_;} 149 : 150 25 : void incr_pkt_drop_due_to_disable_tnl() {pkt_drop_due_to_disable_tnl_++;} 151 0 : uint64_t pkt_drop_due_to_disable_tnl() const {return pkt_drop_due_to_disable_tnl_;} 152 : 153 0 : void incr_pkt_invalid_frm_tor() {pkt_invalid_frm_tor_++;} 154 0 : uint64_t pkt_invalid_frm_tor() const {return pkt_invalid_frm_tor_;} 155 : 156 0 : void incr_pkt_drop_due_to_decode_error() {pkt_drop_due_to_decode_error_++;} 157 0 : uint64_t pkt_drop_due_to_decode_error() const {return pkt_drop_due_to_decode_error_;} 158 : 159 0 : void incr_pkt_drop_due_to_invalid_ethertype() {pkt_drop_due_to_invalid_ethertype_++;} 160 0 : uint64_t pkt_drop_due_to_invalid_ethertype() const {return pkt_drop_due_to_invalid_ethertype_;} 161 : 162 : void incr_pkt_drop_due_to_flow_trap() {pkt_drop_due_to_flow_trap_++;} 163 0 : uint64_t pkt_drop_due_to_flow_trap() const {return pkt_drop_due_to_flow_trap_;} 164 : 165 0 : void incr_pkt_dropped() {pkt_dropped_++;} 166 0 : uint64_t pkt_dropped() const {return pkt_dropped_;} 167 : 168 : void incr_ipc_in_msgs() {ipc_in_msgs_++;} 169 0 : uint64_t ipc_in_msgs() const {return ipc_out_msgs_;} 170 : 171 : void incr_ipc_out_msgs() {ipc_out_msgs_++;} 172 0 : uint64_t ipc_out_msgs() const {return ipc_out_msgs_;} 173 : 174 0 : void incr_in_pkts(uint64_t count) {in_tpkts_ += count;} 175 0 : uint64_t in_pkts() const {return in_tpkts_;} 176 : 177 0 : void incr_in_bytes(uint64_t count) {in_bytes_ += count;} 178 0 : uint64_t in_bytes() const {return in_bytes_;} 179 : 180 0 : void incr_out_pkts(uint64_t count) {out_tpkts_ += count;} 181 0 : uint64_t out_pkts() const {return out_tpkts_;} 182 : 183 0 : void incr_out_bytes(uint64_t count) {out_bytes_ += count;} 184 0 : uint64_t out_bytes() const {return out_bytes_;} 185 : 186 : uint32_t max_flow_adds_per_second() const { 187 : return added_.max_flows_per_second; 188 : } 189 : uint32_t min_flow_adds_per_second() const { 190 : return added_.min_flows_per_second; 191 : } 192 : uint32_t max_flow_deletes_per_second() const { 193 : return deleted_.max_flows_per_second; 194 : } 195 : uint32_t min_flow_deletes_per_second() const { 196 : return deleted_.min_flows_per_second; 197 : } 198 : 199 1 : void set_prev_flow_created(uint64_t value) { 200 1 : added_.prev_flow_count = value; 201 1 : } 202 : 203 1 : void set_prev_flow_aged(uint64_t value) { 204 1 : deleted_.prev_flow_count = value; 205 1 : } 206 1 : void set_max_flow_adds_per_second(uint32_t value) { 207 1 : added_.max_flows_per_second = value; 208 1 : } 209 1 : void set_min_flow_adds_per_second(uint32_t value) { 210 1 : added_.min_flows_per_second = value; 211 1 : } 212 1 : void set_max_flow_deletes_per_second(uint32_t value) { 213 1 : deleted_.max_flows_per_second = value; 214 1 : } 215 1 : void set_min_flow_deletes_per_second(uint32_t value) { 216 1 : deleted_.min_flows_per_second = value; 217 1 : } 218 : void UpdateFlowMinMaxStats(uint64_t total_flows, FlowCounters &stat) const; 219 : void ResetFlowMinMaxStats(FlowCounters &stat) const; 220 : 221 : void RegisterFlowCountFn(FlowCountFn cb); 222 : uint32_t FlowCount() const; 223 0 : FlowCounters& added() { return added_; } 224 0 : FlowCounters& deleted() { return deleted_; } 225 : private: 226 : 227 : Agent *agent_; 228 : FlowCountFn flow_count_fn_; 229 : uint32_t xmpp_reconnect_[MAX_XMPP_SERVERS]; 230 : uint64_t xmpp_in_msgs_[MAX_XMPP_SERVERS]; 231 : uint64_t xmpp_out_msgs_[MAX_XMPP_SERVERS]; 232 : uint64_t xmpp_config_in_msgs_[MAX_XMPP_SERVERS]; 233 : 234 : uint32_t sandesh_reconnects_; 235 : uint64_t sandesh_in_msgs_; 236 : uint64_t sandesh_out_msgs_; 237 : uint32_t sandesh_http_sessions_; 238 : 239 : // Number of NH created 240 : uint32_t nh_count_; 241 : 242 : // Exception packet stats 243 : uint64_t pkt_exceptions_; 244 : uint64_t pkt_invalid_agent_hdr_; 245 : uint64_t pkt_invalid_interface_; 246 : uint64_t pkt_no_handler_; 247 : uint64_t pkt_fragments_dropped_; 248 : uint64_t pkt_dropped_; 249 : uint64_t pkt_invalid_mpls_hdr_; 250 : uint64_t pkt_invalid_ip_pkt_; 251 : uint64_t pkt_drop_due_to_disable_tnl_; 252 : uint64_t pkt_invalid_frm_tor_; 253 : uint64_t pkt_drop_due_to_decode_error_; 254 : uint64_t pkt_drop_due_to_invalid_ethertype_; 255 : uint64_t pkt_drop_due_to_flow_trap_; 256 : 257 : // Flow stats 258 : std::atomic<uint32_t> flow_count_; 259 : uint32_t max_flow_count_; 260 : std::atomic<uint32_t> hold_flow_count_; 261 : uint64_t flow_drop_due_to_max_limit_; 262 : uint64_t flow_drop_due_to_linklocal_limit_; 263 : std::atomic<uint64_t> flow_created_; 264 : std::atomic<uint64_t> flow_aged_; 265 : FlowCounters added_; 266 : FlowCounters deleted_; 267 : int flow_stats_update_timeout_; 268 : 269 : // Kernel IPC 270 : uint64_t ipc_in_msgs_; 271 : uint64_t ipc_out_msgs_; 272 : uint64_t in_tpkts_; 273 : uint64_t in_bytes_; 274 : uint64_t out_tpkts_; 275 : uint64_t out_bytes_; 276 : 277 : static AgentStats *singleton_; 278 : }; 279 : 280 : #endif // vnsw_agent_stats_hpp