OpenSDN source code
vn_uve_entry.h
Go to the documentation of this file.
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  VnStats(std::string vn, uint64_t bytes, uint64_t pkts, bool out) :
23  prev_out_bytes_(0) {
24  dst_vn_ = vn;
25  if (out) {
26  out_bytes_ = bytes;
27  out_pkts_ = pkts;
28  in_bytes_ = 0;
29  in_pkts_ = 0;
30  } else {
31  in_bytes_ = bytes;
32  in_pkts_ = pkts;
33  out_bytes_ = 0;
34  out_pkts_ = 0;
35  }
36  }
37  ~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  bool operator()(const VnStatsPtr &lhs, const VnStatsPtr &rhs) const {
53  if (lhs.get()->dst_vn_.compare(rhs.get()->dst_vn_) < 0)
54  return true;
55  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  VnAceStats(const std::string &ace) : ace_uuid(ace), count(0),
67  prev_count(0) {
68  }
69  bool operator<(const VnAceStats &rhs) const {
70  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();
89  uint64_t in_bytes() const { return in_bytes_; }
90  uint64_t out_bytes() const { return out_bytes_; }
91  bool FrameVnAceStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve);
92 protected:
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;
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_;
127  uint64_t prev_in_bytes_;
128  uint64_t prev_out_bytes_;
131 };
132 
133 #endif // vnsw_agent_vn_uve_entry_h
Definition: agent.h:360
Definition: vn.h:151
const VnEntry * vn() const
bool operator()(const VnStatsPtr &lhs, const VnStatsPtr &rhs) const
Definition: vn_uve_entry.h:52
bool FrameVnAceStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve)
VnUveEntry(Agent *agent, const VnEntry *vn)
Definition: vn_uve_entry.cc:8
void UpdateInterVnStats(const string &dst_vn, uint64_t bytes, uint64_t pkts, bool outgoing)
Definition: vn_uve_entry.cc:33
bool UveVnVrfStatsChanged(const std::vector< UveVrfStats > &vlist) const
std::mutex mutex_
Definition: vn_uve_entry.h:123
bool PopulateInterVnStats(UveVirtualNetworkAgent &s_vn)
uint64_t in_bytes() const
Definition: vn_uve_entry.h:89
bool UpdateVnFlowCount(const VnEntry *vn, UveVirtualNetworkAgent &s_vn)
bool UveVnFipCountChanged(int32_t size) const
bool UveVnInBandChanged(uint64_t out_band) const
bool FrameVnStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve)
bool UveVnOutBandChanged(uint64_t out_band) const
bool UveVnOutFlowCountChanged(uint32_t size)
std::set< VnAceStats > VnAceStatsSet
Definition: vn_uve_entry.h:73
boost::shared_ptr< VnStats > VnStatsPtr
Definition: vn_uve_entry.h:48
VnAceStatsSet ace_stats_
Definition: vn_uve_entry.h:95
uint64_t prev_out_bytes_
Definition: vn_uve_entry.h:128
void ClearInterVnStats()
Definition: vn_uve_entry.cc:64
virtual void Reset()
uint64_t out_bytes() const
Definition: vn_uve_entry.h:90
uint64_t prev_stats_update_time_
Definition: vn_uve_entry.h:126
uint64_t out_bytes_
Definition: vn_uve_entry.h:125
void set_prev_stats_update_time(uint64_t t)
Definition: vn_uve_entry.h:88
void BuildArpStats(const StatsManager::VrfStats *s, UveVrfStats &vrf_stats) const
bool UpdateVnFipCount(int count, UveVirtualNetworkAgent &s_vn)
VnStatsSet inter_vn_stats_
Definition: vn_uve_entry.h:94
std::set< VnStatsPtr, VnStatsCmp > VnStatsSet
Definition: vn_uve_entry.h:60
bool FillVrfStats(int vrf_id, UveVirtualNetworkAgent &s_vn)
bool UpdateVrfStats(const VnEntry *vn, UveVirtualNetworkAgent &s_vn)
void BuildNhStats(const StatsManager::VrfStats *s, UveVrfStats &vrf_stats) const
L4PortBitmap port_bitmap_
Definition: vn_uve_entry.h:93
DISALLOW_COPY_AND_ASSIGN(VnUveEntry)
void UpdatePortBitmap(uint8_t proto, uint16_t sport, uint16_t dport)
Definition: vn_uve_entry.cc:23
virtual ~VnUveEntry()
Definition: vn_uve_entry.cc:20
bool UveVnInFlowCountChanged(uint32_t size)
bool ace_stats_changed_
Definition: vn_uve_entry.h:129
void UpdateVnAceStats(const std::string &ace_uuid)
uint64_t prev_in_bytes_
Definition: vn_uve_entry.h:127
uint64_t in_bytes_
Definition: vn_uve_entry.h:124
bool SetVnPortBitmap(UveVirtualNetworkAgent &uve)
Definition: vn_uve_entry.cc:75
bool UveInterVnOutStatsChanged(const std::vector< UveInterVnStats > &new_list) const
bool UveInterVnInStatsChanged(const std::vector< UveInterVnStats > &new_list) const
const std::string ace_uuid
Definition: vn_uve_entry.h:63
VnAceStats(const std::string &ace)
Definition: vn_uve_entry.h:66
bool operator<(const VnAceStats &rhs) const
Definition: vn_uve_entry.h:69
uint64_t prev_in_bytes_
Definition: vn_uve_entry.h:44
VnStats(std::string vn, uint64_t bytes, uint64_t pkts, bool out)
Definition: vn_uve_entry.h:21
std::string dst_vn_
Definition: vn_uve_entry.h:38
uint64_t prev_out_bytes_
Definition: vn_uve_entry.h:46
uint64_t prev_in_pkts_
Definition: vn_uve_entry.h:43
uint64_t prev_out_pkts_
Definition: vn_uve_entry.h:45