LCOV - code coverage report
Current view: top level - vnsw/agent/uve - vm_uve_table.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 16 70 22.9 %
Date: 2026-08-03 02:19:58 Functions: 4 13 30.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <oper/interface_common.h>
       6             : #include <uve/vm_uve_table.h>
       7             : #include <uve/vm_uve_entry.h>
       8             : #include <uve/agent_uve.h>
       9             : #include <uve/vm_stat_kvm.h>
      10             : #include <uve/vm_stat_docker.h>
      11             : 
      12           6 : VmUveTable::VmUveTable(Agent *agent, uint32_t default_intvl)
      13           6 :     : VmUveTableBase(agent, default_intvl) {
      14          12 :     event_queue_.reset(new WorkQueue<VmStatData *>
      15          12 :             (TaskScheduler::GetInstance()->GetTaskId("Agent::VmUve"), 0,
      16           6 :              boost::bind(&VmUveTable::Process, this, _1)));
      17           6 :     event_queue_->set_name("Virtual-Machine UVE");
      18           6 : }
      19             : 
      20           9 : VmUveTable::~VmUveTable() {
      21           9 : }
      22             : 
      23          44 : void VmUveTable::UpdateBitmap(const VmEntry* vm, uint8_t proto,
      24             :                               uint16_t sport, uint16_t dport) {
      25          44 :     std::scoped_lock lock(uve_vm_map_mutex_);
      26          44 :     UveVmMap::iterator it = uve_vm_map_.find(vm->GetUuid());
      27          44 :     if (it != uve_vm_map_.end()) {
      28          44 :         VmUveEntry *entry = static_cast<VmUveEntry *>(it->second.get());
      29          44 :         entry->UpdatePortBitmap(proto, sport, dport);
      30             :     }
      31          44 : }
      32             : 
      33           0 : VmUveTableBase::VmUveEntryPtr VmUveTable::Allocate(const VmEntry *vm) {
      34           0 :     VmUveEntryPtr uve(new VmUveEntry(agent_, vm->GetCfgName()));
      35           0 :     return uve;
      36             : }
      37             : 
      38           0 : void VmUveTable::SendVmStatsMsg(const boost::uuids::uuid &u) {
      39           0 :     VmUveEntry* entry = static_cast<VmUveEntry*>(UveEntryFromVm(u));
      40           0 :     if (entry == NULL) {
      41           0 :         return;
      42             :     }
      43           0 :     if (entry->deleted()) {
      44             :         /* Skip entry marked for delete because the 'vm' pointer could be
      45             :          * invalid */
      46           0 :         return;
      47             :     }
      48           0 :     UveVirtualMachineAgent uve;
      49             : 
      50           0 :     bool send = entry->FrameVmStatsMsg(&uve);
      51           0 :     if (send) {
      52           0 :         DispatchVmMsg(uve);
      53             :     }
      54           0 : }
      55             : 
      56           0 : void VmUveTable::VmStatCollectionStart(VmUveVmState *state, const VmEntry *vm) {
      57             :     //Create object to poll for VM stats
      58           0 :     VmStat *stat = NULL;
      59           0 :     if (agent_->isKvmMode()) {
      60           0 :         stat = new VmStatKvm(agent_, vm->GetUuid());
      61           0 :     } else if (agent_->isDockerMode()) {
      62           0 :         stat = new VmStatDocker(agent_, vm->GetUuid());
      63             :     }
      64             : 
      65           0 :     if (stat) {
      66           0 :         stat->Start();
      67           0 :         state->stat_ = stat;
      68             :     }
      69           0 : }
      70             : 
      71           0 : void VmUveTable::VmStatCollectionStop(VmUveVmState *state) {
      72           0 :     if (state->stat_) {
      73           0 :         state->stat_->Stop();
      74           0 :         state->stat_ = NULL;
      75             :     }
      76           0 : }
      77             : 
      78           0 : void VmUveTable::EnqueueVmStatData(VmStatData *data) {
      79           0 :     event_queue_->Enqueue(data);
      80           0 : }
      81             : 
      82           0 : bool VmUveTable::Process(VmStatData* vm_stat_data) {
      83           0 :     if (vm_stat_data->vm_stat()->marked_delete()) {
      84           0 :         delete vm_stat_data->vm_stat();
      85             :     } else {
      86           0 :         vm_stat_data->vm_stat()->ProcessData();
      87             :     }
      88           0 :     delete vm_stat_data;
      89           0 :     return true;
      90             : }
      91             : 
      92           0 : void VmUveTable::DispatchVmStatsMsg(const VirtualMachineStats &uve) {
      93           0 :     VirtualMachineStatsTrace::Send(uve);
      94           0 : }
      95             : 
      96           0 : void VmUveTable::SendVmStats(void) {
      97           0 :     UveVmMap::iterator it = uve_vm_map_.begin();
      98           0 :     while (it != uve_vm_map_.end()) {
      99           0 :         SendVmStatsMsg(it->first);
     100           0 :         it++;
     101             :     }
     102           0 : }
     103             : 
     104           0 : void VmUveTable::SendVmDeleteMsg(const string &vm_config_name) {
     105           0 :     VmUveTableBase::SendVmDeleteMsg(vm_config_name);
     106             : 
     107           0 :     VirtualMachineStats stats_uve;
     108           0 :     stats_uve.set_name(vm_config_name);
     109           0 :     stats_uve.set_deleted(true);
     110           0 :     DispatchVmStatsMsg(stats_uve);
     111           0 : }

Generated by: LCOV version 1.14