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

Generated by: LCOV version 1.14