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