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