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