LCOV - code coverage report
Current view: top level - vnsw/agent/uve - vm_uve_entry_base.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 28 73 38.4 %
Date: 2026-11-09 02:10:49 Functions: 5 10 50.0 %
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 <uve/vm_uve_entry.h>
       7             : #include <uve/agent_uve_base.h>
       8             : 
       9             : using namespace std;
      10             : 
      11         332 : VmUveEntryBase::VmUveEntryBase(Agent *agent, const string &vm_name)
      12         332 :     : agent_(agent), interface_tree_(), uve_info_(), changed_(true),
      13         332 :     deleted_(false), renewed_(false), mutex_(), add_by_vm_notify_(false),
      14         664 :     vm_config_name_(vm_name), vm_name_() {
      15         332 : }
      16             : 
      17         332 : VmUveEntryBase::~VmUveEntryBase() {
      18         332 : }
      19             : 
      20           0 : bool VmUveEntryBase::Update(const VmEntry *vm) {
      21           0 :     if (vm_config_name_ != vm->GetCfgName()) {
      22           0 :         vm_config_name_ = vm->GetCfgName();
      23           0 :         return true;
      24             :     }
      25           0 :     return false;
      26             : }
      27             : 
      28         167 : void VmUveEntryBase::InterfaceAdd(const std::string &intf_cfg_name) {
      29         167 :     InterfaceSet::iterator it = interface_tree_.find(intf_cfg_name);
      30         167 :     if (it == interface_tree_.end()) {
      31         167 :         interface_tree_.insert(intf_cfg_name);
      32             :     }
      33         167 : }
      34             : 
      35         167 : void VmUveEntryBase::InterfaceDelete(const std::string &intf_cfg_name) {
      36         167 :     InterfaceSet::iterator intf_it = interface_tree_.find(intf_cfg_name);
      37         167 :     if (intf_it != interface_tree_.end()) {
      38         167 :         interface_tree_.erase(intf_it);
      39             :     }
      40         167 :     if (!add_by_vm_notify_ && (interface_tree_.size() == 0)) {
      41           0 :         renewed_ = false;
      42           0 :         deleted_ = true;
      43             :     }
      44         167 :     if (interface_tree_.size() == 0) {
      45         165 :         vm_name_ = "";
      46             :     }
      47         167 : }
      48             : 
      49           0 : bool VmUveEntryBase::FrameVmMsg(const boost::uuids::uuid &u,
      50             :                                 UveVirtualMachineAgent *uve) {
      51           0 :     bool changed = false;
      52           0 :     assert(!deleted_);
      53           0 :     uve->set_name(vm_config_name_);
      54           0 :     vector<string> s_intf_list;
      55             : 
      56           0 :     if (!uve_info_.__isset.uuid) {
      57           0 :         uve->set_uuid(to_string(u));
      58           0 :         uve_info_.set_uuid(to_string(u));
      59           0 :         changed = true;
      60             :     }
      61           0 :     if (!uve_info_.__isset.vm_name ||
      62           0 :         (uve_info_.get_vm_name() != vm_name_)) {
      63           0 :         uve->set_vm_name(vm_name_);
      64           0 :         uve_info_.set_vm_name(vm_name_);
      65             :     }
      66             : 
      67           0 :     InterfaceSet::iterator it = interface_tree_.begin();
      68           0 :     while(it != interface_tree_.end()) {
      69           0 :         s_intf_list.push_back(*it);
      70           0 :         ++it;
      71             :     }
      72             : 
      73           0 :     if (UveVmInterfaceListChanged(s_intf_list)) {
      74           0 :         uve->set_interface_list(s_intf_list);
      75           0 :         uve_info_.set_interface_list(s_intf_list);
      76           0 :         changed = true;
      77             :     }
      78             : 
      79           0 :     string hostname = agent_->host_name();
      80           0 :     if (UveVmVRouterChanged(hostname)) {
      81           0 :         uve->set_vrouter(hostname);
      82           0 :         uve_info_.set_vrouter(hostname);
      83           0 :         changed = true;
      84             :     }
      85             : 
      86           0 :     return changed;
      87           0 : }
      88             : 
      89           0 : bool VmUveEntryBase::UveVmVRouterChanged(const string &new_value) const {
      90           0 :     if (!uve_info_.__isset.vrouter) {
      91           0 :         return true;
      92             :     }
      93           0 :     if (new_value.compare(uve_info_.get_vrouter()) == 0) {
      94           0 :         return false;
      95             :     }
      96           0 :     return true;
      97             : }
      98             : 
      99           0 : bool VmUveEntryBase::UveVmInterfaceListChanged
     100             :     (const vector<string> &new_list)
     101             :     const {
     102           0 :     if (new_list != uve_info_.get_interface_list()) {
     103           0 :         return true;
     104             :     }
     105           0 :     return false;
     106             : }
     107             : 
     108         165 : void VmUveEntryBase::Reset() {
     109         330 :     UveVirtualMachineAgent uve;
     110             : 
     111         165 :     interface_tree_.clear();
     112         165 :     uve_info_ = uve;
     113             : 
     114         165 :     deleted_ = true;
     115         165 :     renewed_ = false;
     116         165 :     add_by_vm_notify_ = false;
     117         165 : }

Generated by: LCOV version 1.14