OpenSDN source code
vm_uve_entry_base.cc
Go to the documentation of this file.
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 VmUveEntryBase::VmUveEntryBase(Agent *agent, const string &vm_name)
12  : agent_(agent), interface_tree_(), uve_info_(), changed_(true),
13  deleted_(false), renewed_(false), mutex_(), add_by_vm_notify_(false),
14  vm_config_name_(vm_name), vm_name_() {
15 }
16 
18 }
19 
21  if (vm_config_name_ != vm->GetCfgName()) {
23  return true;
24  }
25  return false;
26 }
27 
28 void VmUveEntryBase::InterfaceAdd(const std::string &intf_cfg_name) {
29  InterfaceSet::iterator it = interface_tree_.find(intf_cfg_name);
30  if (it == interface_tree_.end()) {
31  interface_tree_.insert(intf_cfg_name);
32  }
33 }
34 
35 void VmUveEntryBase::InterfaceDelete(const std::string &intf_cfg_name) {
36  InterfaceSet::iterator intf_it = interface_tree_.find(intf_cfg_name);
37  if (intf_it != interface_tree_.end()) {
38  interface_tree_.erase(intf_it);
39  }
40  if (!add_by_vm_notify_ && (interface_tree_.size() == 0)) {
41  renewed_ = false;
42  deleted_ = true;
43  }
44  if (interface_tree_.size() == 0) {
45  vm_name_ = "";
46  }
47 }
48 
50  UveVirtualMachineAgent *uve) {
51  bool changed = false;
52  assert(!deleted_);
53  uve->set_name(vm_config_name_);
54  vector<string> s_intf_list;
55 
56  if (!uve_info_.__isset.uuid) {
57  uve->set_uuid(to_string(u));
58  uve_info_.set_uuid(to_string(u));
59  changed = true;
60  }
61  if (!uve_info_.__isset.vm_name ||
62  (uve_info_.get_vm_name() != vm_name_)) {
63  uve->set_vm_name(vm_name_);
64  uve_info_.set_vm_name(vm_name_);
65  }
66 
67  InterfaceSet::iterator it = interface_tree_.begin();
68  while(it != interface_tree_.end()) {
69  s_intf_list.push_back(*it);
70  ++it;
71  }
72 
73  if (UveVmInterfaceListChanged(s_intf_list)) {
74  uve->set_interface_list(s_intf_list);
75  uve_info_.set_interface_list(s_intf_list);
76  changed = true;
77  }
78 
79  string hostname = agent_->host_name();
80  if (UveVmVRouterChanged(hostname)) {
81  uve->set_vrouter(hostname);
82  uve_info_.set_vrouter(hostname);
83  changed = true;
84  }
85 
86  return changed;
87 }
88 
89 bool VmUveEntryBase::UveVmVRouterChanged(const string &new_value) const {
90  if (!uve_info_.__isset.vrouter) {
91  return true;
92  }
93  if (new_value.compare(uve_info_.get_vrouter()) == 0) {
94  return false;
95  }
96  return true;
97 }
98 
100  (const vector<string> &new_list)
101  const {
102  if (new_list != uve_info_.get_interface_list()) {
103  return true;
104  }
105  return false;
106 }
107 
109  UveVirtualMachineAgent uve;
110 
111  interface_tree_.clear();
112  uve_info_ = uve;
113 
114  deleted_ = true;
115  renewed_ = false;
116  add_by_vm_notify_ = false;
117 }
Definition: agent.h:361
const std::string & host_name() const
Definition: agent.h:878
Definition: vm.h:35
const string & GetCfgName() const
Definition: vm.h:46
VmUveEntryBase(Agent *agent, const std::string &vm_name)
UveVirtualMachineAgent uve_info_
InterfaceSet interface_tree_
bool changed() const
void InterfaceAdd(const std::string &intf_cfg_name)
std::string vm_config_name_
bool UveVmVRouterChanged(const std::string &new_value) const
bool Update(const VmEntry *vm)
std::string vm_name_
bool UveVmInterfaceListChanged(const std::vector< std::string > &new_l) const
virtual ~VmUveEntryBase()
virtual void Reset()
bool FrameVmMsg(const boost::uuids::uuid &u, UveVirtualMachineAgent *uve)
void InterfaceDelete(const std::string &intf_cfg_name)
boost::uuids::uuid uuid