LCOV - code coverage report
Current view: top level - vnsw/agent/cmn - agent_stats.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 70 123 56.9 %
Date: 2026-06-08 02:02:55 Functions: 24 72 33.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14