OpenSDN source code
vn_uve_table.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <uve/agent_uve_stats.h>
7 #include <uve/vn_uve_table.h>
8 #include <uve/vn_uve_entry.h>
9 
10 VnUveTable::VnUveTable(Agent *agent, uint32_t default_intvl)
11  : VnUveTableBase(agent, default_intvl) {
12 }
13 
15 }
16 
18  VnUveEntryPtr uve(new VnUveEntry(agent_, vn));
19  return uve;
20 }
21 
24  return uve;
25 }
26 
27 bool VnUveTable::SendUnresolvedVnMsg(const string &vn_name,
28  UveVirtualNetworkAgent &uve) {
29  UveVnMap::iterator it = uve_vn_map_.find(vn_name);
30  if (it == uve_vn_map_.end()) {
31  return false;
32  }
33  VnUveEntryPtr entry_ptr(it->second);
34  VnUveEntry *entry = static_cast<VnUveEntry *>(entry_ptr.get());
35 
36  bool changed = false;
37  uve.set_name(vn_name);
38  changed = entry->PopulateInterVnStats(uve);
39 
40 
41  AgentUveStats *u = static_cast<AgentUveStats *>(agent_->uve());
42  StatsManager *stats = u->stats_manager();
43  /* Send Nameless VrfStats as part of Unknown VN */
44  if (vn_name.compare(FlowHandler::UnknownVn()) == 0) {
45  changed = entry->FillVrfStats(stats->GetNamelessVrfId(), uve);
46  }
47 
48  return changed;
49 }
50 
52  UveVnMap::const_iterator it = uve_vn_map_.begin();
53  while (it != uve_vn_map_.end()) {
54  const VnUveEntry *entry = static_cast<VnUveEntry *>(it->second.get());
55  ++it;
56  if (entry->deleted()) {
57  continue;
58  }
59  if (entry->vn()) {
60  SendVnStatsMsg(entry->vn());
61  }
62  }
63  UveVirtualNetworkAgent uve1, uve2;
65  DispatchVnMsg(uve1);
66  }
68  DispatchVnMsg(uve2);
69  }
70 }
71 
73  VnUveEntry* entry = static_cast<VnUveEntry*>(UveEntryFromVn(vn));
74  if (entry == NULL) {
75  return;
76  }
77  if (entry->deleted()) {
78  return;
79  }
80  UveVirtualNetworkAgent uve;
81 
82  bool send = entry->FrameVnStatsMsg(vn, uve);
83  if (send) {
84  DispatchVnMsg(uve);
85  }
86 }
87 
88 void VnUveTable::UpdateBitmap(const string &vn, uint8_t proto, uint16_t sport,
89  uint16_t dport) {
90  std::scoped_lock lock(uve_vn_map_mutex_);
91  UveVnMap::iterator it = uve_vn_map_.find(vn);
92  if (it == uve_vn_map_.end()) {
93  return;
94  }
95 
96  VnUveEntry * entry = static_cast<VnUveEntry *>(it->second.get());
97  entry->UpdatePortBitmap(proto, sport, dport);
98 }
99 
100 void VnUveTable::UpdateInterVnStats(const string &src, const string &dst,
101  uint64_t bytes, uint64_t pkts,
102  bool outgoing) {
103  std::scoped_lock lock(uve_vn_map_mutex_);
104  UveVnMap::iterator it = uve_vn_map_.find(src);
105  if (it == uve_vn_map_.end()) {
106  return;
107  }
108 
109  VnUveEntry * entry = static_cast<VnUveEntry *>(it->second.get());
110  entry->UpdateInterVnStats(dst, bytes, pkts, outgoing);
111 }
112 
114  if (!info.is_valid_) {
115  return;
116  }
117  UveVnMap::iterator it = uve_vn_map_.find(info.vn_);
118  if (it == uve_vn_map_.end()) {
119  return;
120  }
121 
122  VnUveEntry * entry = static_cast<VnUveEntry *>(it->second.get());
123  entry->UpdateVnAceStats(info.nw_ace_uuid_);
124 }
125 
127  UveVirtualNetworkAgent uve;
128  if (vn == NULL) {
129  return;
130  }
131  VnUveEntry *entry = static_cast<VnUveEntry *>(e);
132  if (entry->FrameVnAceStatsMsg(vn, uve)) {
133  DispatchVnMsg(uve);
134  }
135 }
StatsManager * stats_manager() const
Definition: agent.h:361
AgentUveBase * uve() const
Definition: agent.cc:913
static const std::string LinkLocalVn()
Definition: flow_handler.h:33
static const std::string UnknownVn()
Definition: flow_handler.h:27
int GetNamelessVrfId()
Definition: vn.h:152
bool deleted() const
const VnEntry * vn() const
bool FrameVnAceStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve)
void UpdateInterVnStats(const string &dst_vn, uint64_t bytes, uint64_t pkts, bool outgoing)
Definition: vn_uve_entry.cc:34
bool PopulateInterVnStats(UveVirtualNetworkAgent &s_vn)
bool FrameVnStatsMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve)
bool FillVrfStats(int vrf_id, UveVirtualNetworkAgent &s_vn)
void UpdatePortBitmap(uint8_t proto, uint16_t sport, uint16_t dport)
Definition: vn_uve_entry.cc:24
void UpdateVnAceStats(const std::string &ace_uuid)
VnUveEntryBase * UveEntryFromVn(const VnEntry *vn)
boost::shared_ptr< VnUveEntryBase > VnUveEntryPtr
std::mutex uve_vn_map_mutex_
virtual void DispatchVnMsg(const UveVirtualNetworkAgent &uve)
void UpdateInterVnStats(const std::string &src, const std::string &dst, uint64_t bytes, uint64_t pkts, bool outgoing)
void IncrVnAceStats(const FlowUveVnAcePolicyInfo &info)
void UpdateBitmap(const std::string &vn, uint8_t proto, uint16_t sport, uint16_t dport)
Definition: vn_uve_table.cc:88
VnUveTable(Agent *agent, uint32_t default_intvl)
Definition: vn_uve_table.cc:10
bool SendUnresolvedVnMsg(const std::string &vn, UveVirtualNetworkAgent &u)
Definition: vn_uve_table.cc:27
virtual ~VnUveTable()
Definition: vn_uve_table.cc:14
virtual VnUveEntryPtr Allocate()
Definition: vn_uve_table.cc:22
void SendVnAceStats(VnUveEntryBase *entry, const VnEntry *vn)
void SendVnStatsMsg(const VnEntry *vn)
Definition: vn_uve_table.cc:72
void SendVnStats()
Definition: vn_uve_table.cc:51