LCOV - code coverage report
Current view: top level - vnsw/agent/uve - stats_manager.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 1 36 2.8 %
Date: 2026-06-22 02:21:21 Functions: 1 8 12.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef _ROOT_STATS_MANAGER_H_
       6             : #define _ROOT_STATS_MANAGER_H_
       7             : 
       8             : #include <cmn/agent_cmn.h>
       9             : #include <cmn/agent_stats.h>
      10             : #include <oper/vrf.h>
      11             : #include <oper/interface.h>
      12             : #include <vrouter_types.h>
      13             : #include <string>
      14             : #include <map>
      15             : #include <utility>
      16             : #include <uve/flow_uve_stats_request.h>
      17             : #include <vr_types.h>
      18             : #include <uve/agent_uve.h>
      19             : 
      20             : struct FlowRateComputeInfo {
      21             :     uint64_t prev_time_;
      22             :     uint64_t prev_flow_created_;
      23             :     uint64_t prev_flow_aged_;
      24             : 
      25           0 :     FlowRateComputeInfo() : prev_time_(UTCTimestampUsec()),
      26           0 :         prev_flow_created_(0), prev_flow_aged_(0) {
      27           0 :     }
      28             : };
      29             : 
      30             : #define DEFAULT_FUVE_REQUEST_QUEUE_SIZE (4*1024*1024)
      31             : 
      32             : // The container class for storing stats queried from vrouter
      33             : // Defines routines for storing and managing (add, delete and query)
      34             : // interface, vrf and drop statistics
      35             : class StatsManager {
      36             :  public:
      37             :     struct InterfaceStats {
      38             :         InterfaceStats();
      39             :         void UpdateStats(uint64_t in_b, uint64_t in_p, uint64_t out_b,
      40             :                          uint64_t out_p);
      41             :         void UpdatePrevStats();
      42             :         void GetDiffStats(uint64_t *in_b, uint64_t *out_b) const;
      43             : 
      44             :         std::string name;
      45             :         int32_t  speed;
      46             :         int32_t  duplexity;
      47             :         uint64_t in_pkts;
      48             :         uint64_t in_bytes;
      49             :         uint64_t out_pkts;
      50             :         uint64_t out_bytes;
      51             :         uint64_t prev_in_bytes;
      52             :         uint64_t prev_out_bytes;
      53             :         uint64_t prev_5min_in_bytes;
      54             :         uint64_t prev_5min_out_bytes;
      55             :         uint64_t stats_time;
      56             :         FlowRateComputeInfo flow_info;
      57             :         AgentStats::FlowCounters added;
      58             :         AgentStats::FlowCounters deleted;
      59             :         bool drop_stats_received;
      60             :         vr_drop_stats_req drop_stats;
      61             :     };
      62             :     struct VrfStats {
      63             :         VrfStats();
      64             :         std::string name;
      65             :         uint64_t discards;
      66             :         uint64_t resolves;
      67             :         uint64_t receives;
      68             :         uint64_t udp_tunnels;
      69             :         uint64_t udp_mpls_tunnels;
      70             :         uint64_t gre_mpls_tunnels;
      71             :         uint64_t ecmp_composites;
      72             :         uint64_t l2_mcast_composites;
      73             :         uint64_t fabric_composites;
      74             :         uint64_t encaps;
      75             :         uint64_t l2_encaps;
      76             :         uint64_t gros;
      77             :         uint64_t diags;
      78             :         uint64_t encap_composites;
      79             :         uint64_t evpn_composites;
      80             :         uint64_t vrf_translates;
      81             :         uint64_t vxlan_tunnels;
      82             :         uint64_t arp_virtual_proxy;
      83             :         uint64_t arp_virtual_stitch;
      84             :         uint64_t arp_virtual_flood;
      85             :         uint64_t arp_physical_stitch;
      86             :         uint64_t arp_tor_proxy;
      87             :         uint64_t arp_physical_flood;
      88             :         uint64_t l2_receives;
      89             :         uint64_t uuc_floods;
      90             : 
      91             :         uint64_t prev_discards;
      92             :         uint64_t prev_resolves;
      93             :         uint64_t prev_receives;
      94             :         uint64_t prev_udp_tunnels;
      95             :         uint64_t prev_udp_mpls_tunnels;
      96             :         uint64_t prev_gre_mpls_tunnels;
      97             :         uint64_t prev_ecmp_composites;
      98             :         uint64_t prev_l2_mcast_composites;
      99             :         uint64_t prev_fabric_composites;
     100             :         uint64_t prev_encaps;
     101             :         uint64_t prev_l2_encaps;
     102             :         uint64_t prev_gros;
     103             :         uint64_t prev_diags;
     104             :         uint64_t prev_encap_composites;
     105             :         uint64_t prev_evpn_composites;
     106             :         uint64_t prev_vrf_translates;
     107             :         uint64_t prev_vxlan_tunnels;
     108             :         uint64_t prev_arp_virtual_proxy;
     109             :         uint64_t prev_arp_virtual_stitch;
     110             :         uint64_t prev_arp_virtual_flood;
     111             :         uint64_t prev_arp_physical_stitch;
     112             :         uint64_t prev_arp_tor_proxy;
     113             :         uint64_t prev_arp_physical_flood;
     114             :         uint64_t prev_l2_receives;
     115             :         uint64_t prev_uuc_floods;
     116             : 
     117             :         uint64_t k_discards;
     118             :         uint64_t k_resolves;
     119             :         uint64_t k_receives;
     120             :         uint64_t k_udp_tunnels;
     121             :         uint64_t k_udp_mpls_tunnels;
     122             :         uint64_t k_gre_mpls_tunnels;
     123             :         uint64_t k_ecmp_composites;
     124             :         uint64_t k_l2_mcast_composites;
     125             :         uint64_t k_fabric_composites;
     126             :         uint64_t k_encaps;
     127             :         uint64_t k_l2_encaps;
     128             :         uint64_t k_gros;
     129             :         uint64_t k_diags;
     130             :         uint64_t k_encap_composites;
     131             :         uint64_t k_evpn_composites;
     132             :         uint64_t k_vrf_translates;
     133             :         uint64_t k_vxlan_tunnels;
     134             :         uint64_t k_arp_virtual_proxy;
     135             :         uint64_t k_arp_virtual_stitch;
     136             :         uint64_t k_arp_virtual_flood;
     137             :         uint64_t k_arp_physical_stitch;
     138             :         uint64_t k_arp_tor_proxy;
     139             :         uint64_t k_arp_physical_flood;
     140             :         uint64_t k_l2_receives;
     141             :         uint64_t k_uuc_floods;
     142             :     };
     143             : 
     144             :     typedef std::map<const Interface *, InterfaceStats> InterfaceStatsTree;
     145             :     typedef std::pair<const Interface *, InterfaceStats> InterfaceStatsPair;
     146             :     typedef std::map<int, VrfStats> VrfIdToVrfStatsTree;
     147             :     typedef std::pair<int, VrfStats> VrfStatsPair;
     148             : 
     149             :     struct FlowRuleMatchInfo {
     150             :         std::string interface;
     151             :         std::string sg_rule_uuid;
     152             :         FlowUveFwPolicyInfo fw_policy_info;
     153             :         FlowUveVnAcePolicyInfo vn_ace_info;
     154           0 :         FlowRuleMatchInfo(const std::string &itf, const std::string &sg_rule,
     155             :                           const FlowUveFwPolicyInfo &fw_info,
     156           0 :                           const FlowUveVnAcePolicyInfo &nw_ace_info) :
     157           0 :             interface(itf), sg_rule_uuid(sg_rule), fw_policy_info(fw_info),
     158           0 :             vn_ace_info(nw_ace_info) {
     159           0 :         }
     160           0 :         bool IsFwPolicyInfoEqual(const FlowUveFwPolicyInfo &info) const {
     161           0 :             if (fw_policy_info.is_valid_ != info.is_valid_) {
     162           0 :                 return false;
     163             :             }
     164           0 :             if (fw_policy_info.local_tagset_ != info.local_tagset_) {
     165           0 :                 return false;
     166             :             }
     167           0 :             if (fw_policy_info.fw_policy_ != info.fw_policy_) {
     168           0 :                 return false;
     169             :             }
     170           0 :             if (fw_policy_info.remote_tagset_ != info.remote_tagset_) {
     171           0 :                 return false;
     172             :             }
     173           0 :             if (fw_policy_info.remote_prefix_ != info.remote_prefix_) {
     174           0 :                 return false;
     175             :             }
     176           0 :             if (fw_policy_info.local_vn_ != info.local_vn_) {
     177           0 :                 return false;
     178             :             }
     179           0 :             if (fw_policy_info.remote_vn_ != info.remote_vn_) {
     180           0 :                 return false;
     181             :             }
     182           0 :             if (fw_policy_info.initiator_ != info.initiator_) {
     183           0 :                 return false;
     184             :             }
     185           0 :             return true;
     186             :         }
     187           0 :         bool IsVnAceInfoEqual(const FlowUveVnAcePolicyInfo &info) const {
     188           0 :             if (vn_ace_info.vn_ != info.vn_) {
     189           0 :                 return false;
     190             :             }
     191           0 :             if (vn_ace_info.nw_ace_uuid_ != info.nw_ace_uuid_) {
     192           0 :                 return false;
     193             :             }
     194           0 :             return true;
     195             :         }
     196             :     };
     197             : 
     198             :     typedef std::map<const boost::uuids::uuid, FlowRuleMatchInfo> FlowAceTree;
     199             :     typedef std::pair<const boost::uuids::uuid, FlowRuleMatchInfo> FlowAcePair;
     200             : 
     201             :     explicit StatsManager(Agent *agent);
     202             :     virtual ~StatsManager();
     203             : 
     204          40 :     vr_drop_stats_req drop_stats() const { return drop_stats_; }
     205           0 :     void set_drop_stats(const vr_drop_stats_req &req) { drop_stats_ = req; }
     206             : 
     207             :     InterfaceStats* GetInterfaceStats(const Interface *intf);
     208             : 
     209             :     VrfStats* GetVrfStats(int vrf_id);
     210           0 :     std::string GetNamelessVrf() { return "__untitled__"; }
     211           0 :     int GetNamelessVrfId() { return -1; }
     212             :     void Shutdown(void);
     213             :     void RegisterDBClients();
     214             :     void InitDone();
     215             :     bool RequestHandler(boost::shared_ptr<FlowUveStatsRequest> req);
     216             :     void EnqueueEvent(const boost::shared_ptr<FlowUveStatsRequest> &req);
     217             :     bool BuildFlowRate(AgentStats::FlowCounters &created,
     218             :                        AgentStats::FlowCounters &aged,
     219             :                        FlowRateComputeInfo &flow_info,
     220             :                        VrouterFlowRate &flow_rate) const;
     221             :     void BuildDropStats(const vr_drop_stats_req &r,
     222             :                         AgentDropStats &ds) const;
     223             :     friend class AgentStatsCollectorTest;
     224             : 
     225             :  private:
     226             :     void VrfNotify(DBTablePartBase *partition, DBEntryBase *e);
     227             :     void InterfaceNotify(DBTablePartBase *part, DBEntryBase *e);
     228             :     void AddNamelessVrfStatsEntry();
     229             :     void AddInterfaceStatsEntry(const Interface *intf);
     230             :     void DelInterfaceStatsEntry(const Interface *intf);
     231             :     void AddUpdateVrfStatsEntry(const VrfEntry *intf);
     232             :     void DelVrfStatsEntry(const VrfEntry *intf);
     233             :     void AddFlow(const FlowUveStatsRequest *req);
     234             :     void DeleteFlow(const FlowUveStatsRequest *req);
     235             :     bool FlowStatsUpdate();
     236             : 
     237             :     VrfIdToVrfStatsTree vrf_stats_tree_;
     238             :     InterfaceStatsTree if_stats_tree_;
     239             :     FlowAceTree flow_ace_tree_;
     240             :     vr_drop_stats_req drop_stats_;
     241             :     DBTableBase::ListenerId vrf_listener_id_;
     242             :     DBTableBase::ListenerId intf_listener_id_;
     243             :     Agent *agent_;
     244             :     WorkQueue<boost::shared_ptr<FlowUveStatsRequest> > request_queue_;
     245             :     Timer *timer_;
     246             :     DISALLOW_COPY_AND_ASSIGN(StatsManager);
     247             : };
     248             : #endif  // _ROOT_STATS_MANAGER_H_

Generated by: LCOV version 1.14