LCOV - code coverage report
Current view: top level - vnsw/agent/uve - vn_uve_entry.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 27 27 100.0 %
Date: 2026-08-03 02:19:58 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef vnsw_agent_vn_uve_entry_h
       6             : #define vnsw_agent_vn_uve_entry_h
       7             : 
       8             : #include <mutex>
       9             : 
      10             : #include <uve/l4_port_bitmap.h>
      11             : #include "pkt/flow_proto.h"
      12             : #include "pkt/flow_table.h"
      13             : #include <uve/vn_uve_entry_base.h>
      14             : #include <uve/stats_manager.h>
      15             : 
      16             : //The class that defines data-structures to store VirtualNetwork information
      17             : //required for sending VirtualNetwork UVE.
      18             : class VnUveEntry : public VnUveEntryBase {
      19             : public:
      20             :     struct VnStats {
      21         133 :         VnStats(std::string vn, uint64_t bytes, uint64_t pkts, bool out) :
      22         133 :             prev_in_pkts_(0), prev_in_bytes_(0), prev_out_pkts_(0),
      23         133 :             prev_out_bytes_(0) {
      24         133 :                 dst_vn_ = vn;
      25         133 :                 if (out) {
      26           2 :                     out_bytes_ = bytes;
      27           2 :                     out_pkts_ = pkts;
      28           2 :                     in_bytes_ = 0;
      29           2 :                     in_pkts_ = 0;
      30             :                 } else {
      31         131 :                     in_bytes_ = bytes;
      32         131 :                     in_pkts_ = pkts;
      33         131 :                     out_bytes_ = 0;
      34         131 :                     out_pkts_ = 0;
      35             :                 }
      36         133 :             }
      37         133 :         ~VnStats() {}
      38             :         std::string dst_vn_;
      39             :         uint64_t in_pkts_;
      40             :         uint64_t in_bytes_;
      41             :         uint64_t out_pkts_;
      42             :         uint64_t out_bytes_;
      43             :         uint64_t prev_in_pkts_;
      44             :         uint64_t prev_in_bytes_;
      45             :         uint64_t prev_out_pkts_;
      46             :         uint64_t prev_out_bytes_;
      47             :     };
      48             :     typedef boost::shared_ptr<VnStats> VnStatsPtr;
      49             : 
      50             :     class VnStatsCmp {
      51             :         public:
      52         261 :             bool operator()(const VnStatsPtr &lhs, const VnStatsPtr &rhs) const {
      53         261 :                 if (lhs.get()->dst_vn_.compare(rhs.get()->dst_vn_) < 0)
      54          19 :                     return true;
      55         242 :                 return false;
      56             :             }
      57             : 
      58             :     };
      59             : 
      60             :     typedef std::set<VnStatsPtr, VnStatsCmp> VnStatsSet;
      61             : 
      62             :     struct VnAceStats {
      63             :         const std::string ace_uuid;
      64             :         mutable uint64_t count;
      65             :         mutable uint64_t prev_count;
      66          54 :         VnAceStats(const std::string &ace) : ace_uuid(ace), count(0),
      67          54 :             prev_count(0) {
      68          54 :         }
      69         135 :         bool operator<(const VnAceStats &rhs) const {
      70         135 :             return ace_uuid < rhs.ace_uuid;
      71             :         }
      72             :     };
      73             :     typedef std::set<VnAceStats> VnAceStatsSet;
      74             : 
      75             :     VnUveEntry(Agent *agent, const VnEntry *vn);
      76             :     VnUveEntry(Agent *agent);
      77             :     virtual ~VnUveEntry();
      78             : 
      79             :     void UpdatePortBitmap(uint8_t proto, uint16_t sport, uint16_t dport);
      80             :     bool FillVrfStats(int vrf_id, UveVirtualNetworkAgent &s_vn);
      81             :     bool PopulateInterVnStats(UveVirtualNetworkAgent &s_vn);
      82             :     bool FrameVnStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve);
      83             :     void UpdateInterVnStats(const string &dst_vn, uint64_t bytes,
      84             :                             uint64_t pkts, bool outgoing);
      85             :     void UpdateVnAceStats(const std::string &ace_uuid);
      86             :     void ClearInterVnStats();
      87             :     virtual void Reset();
      88           1 :     void set_prev_stats_update_time(uint64_t t) { prev_stats_update_time_ = t; }
      89           2 :     uint64_t in_bytes() const { return in_bytes_; }
      90           2 :     uint64_t out_bytes() const { return out_bytes_; }
      91             :     bool FrameVnAceStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve);
      92             : protected:
      93             :     L4PortBitmap port_bitmap_;
      94             :     VnStatsSet inter_vn_stats_;
      95             :     VnAceStatsSet ace_stats_;
      96             : 
      97             : private:
      98             :     bool SetVnPortBitmap(UveVirtualNetworkAgent &uve);
      99             :     bool UveVnInBandChanged(uint64_t out_band) const;
     100             :     bool UveVnOutBandChanged(uint64_t out_band) const;
     101             :     bool UpdateVnFlowCount(const VnEntry *vn, UveVirtualNetworkAgent &s_vn);
     102             :     bool UpdateVnFipCount(int count, UveVirtualNetworkAgent &s_vn);
     103             :     bool UveVnFipCountChanged(int32_t size) const;
     104             :     bool UveInterVnInStatsChanged(const std::vector<UveInterVnStats>
     105             :                                   &new_list) const;
     106             :     bool UveInterVnOutStatsChanged(const std::vector<UveInterVnStats>
     107             :                                    &new_list) const;
     108             :     bool UveVnVrfStatsChanged(const std::vector<UveVrfStats> &vlist) const;
     109             :     bool UpdateVrfStats(const VnEntry *vn, UveVirtualNetworkAgent &s_vn);
     110             :     bool UveVnInFlowCountChanged(uint32_t size);
     111             :     bool UveVnOutFlowCountChanged(uint32_t size);
     112             :     void BuildNhStats(const StatsManager::VrfStats *s,
     113             :                       UveVrfStats &vrf_stats) const;
     114             :     void BuildArpStats(const StatsManager::VrfStats *s,
     115             :                        UveVrfStats &vrf_stats) const;
     116             : 
     117             :     /* For exclusion between kTaskFlowStatsCollector and
     118             :      * Agent::Uve/kTaskDBExclude. This is used to protect port_bitmap_ and
     119             :      * inter_vn_stats_ from parallel access between
     120             :      * 1. kTaskFlowStatsCollector and Agent::Uve
     121             :      * 2. kTaskFlowStatsCollector and kTaskDBExclude
     122             :      */
     123             :     std::mutex mutex_;
     124             :     uint64_t in_bytes_;
     125             :     uint64_t out_bytes_;
     126             :     uint64_t prev_stats_update_time_;
     127             :     uint64_t prev_in_bytes_;
     128             :     uint64_t prev_out_bytes_;
     129             :     bool ace_stats_changed_;
     130             :     DISALLOW_COPY_AND_ASSIGN(VnUveEntry);
     131             : };
     132             : 
     133             : #endif // vnsw_agent_vn_uve_entry_h

Generated by: LCOV version 1.14