LCOV - code coverage report
Current view: top level - vnsw/agent/uve - vn_uve_table.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 25 84 29.8 %
Date: 2026-08-03 02:19:58 Functions: 6 12 50.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14