OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vm_uve_entry_base.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <uve/vm_uve_entry.h>
6 #include <uve/agent_uve_base.h>
7 
8 using namespace std;
9 
10 VmUveEntryBase::VmUveEntryBase(Agent *agent, const string &vm_name)
11  : agent_(agent), interface_tree_(), uve_info_(), changed_(true),
12  deleted_(false), renewed_(false), mutex_(), add_by_vm_notify_(false),
13  vm_config_name_(vm_name), vm_name_() {
14 }
15 
17 }
18 
20  if (vm_config_name_ != vm->GetCfgName()) {
22  return true;
23  }
24  return false;
25 }
26 
27 void VmUveEntryBase::InterfaceAdd(const std::string &intf_cfg_name) {
28  InterfaceSet::iterator it = interface_tree_.find(intf_cfg_name);
29  if (it == interface_tree_.end()) {
30  interface_tree_.insert(intf_cfg_name);
31  }
32 }
33 
34 void VmUveEntryBase::InterfaceDelete(const std::string &intf_cfg_name) {
35  InterfaceSet::iterator intf_it = interface_tree_.find(intf_cfg_name);
36  if (intf_it != interface_tree_.end()) {
37  interface_tree_.erase(intf_it);
38  }
39  if (!add_by_vm_notify_ && (interface_tree_.size() == 0)) {
40  renewed_ = false;
41  deleted_ = true;
42  }
43  if (interface_tree_.size() == 0) {
44  vm_name_ = "";
45  }
46 }
47 
49  UveVirtualMachineAgent *uve) {
50  bool changed = false;
51  assert(!deleted_);
52  uve->set_name(vm_config_name_);
53  vector<string> s_intf_list;
54 
55  if (!uve_info_.__isset.uuid) {
56  uve->set_uuid(to_string(u));
57  uve_info_.set_uuid(to_string(u));
58  changed = true;
59  }
60  if (!uve_info_.__isset.vm_name ||
61  (uve_info_.get_vm_name() != vm_name_)) {
62  uve->set_vm_name(vm_name_);
63  uve_info_.set_vm_name(vm_name_);
64  }
65 
66  InterfaceSet::iterator it = interface_tree_.begin();
67  while(it != interface_tree_.end()) {
68  s_intf_list.push_back(*it);
69  ++it;
70  }
71 
72  if (UveVmInterfaceListChanged(s_intf_list)) {
73  uve->set_interface_list(s_intf_list);
74  uve_info_.set_interface_list(s_intf_list);
75  changed = true;
76  }
77 
78  string hostname = agent_->host_name();
79  if (UveVmVRouterChanged(hostname)) {
80  uve->set_vrouter(hostname);
81  uve_info_.set_vrouter(hostname);
82  changed = true;
83  }
84 
85  return changed;
86 }
87 
88 bool VmUveEntryBase::UveVmVRouterChanged(const string &new_value) const {
89  if (!uve_info_.__isset.vrouter) {
90  return true;
91  }
92  if (new_value.compare(uve_info_.get_vrouter()) == 0) {
93  return false;
94  }
95  return true;
96 }
97 
99  (const vector<string> &new_list)
100  const {
101  if (new_list != uve_info_.get_interface_list()) {
102  return true;
103  }
104  return false;
105 }
106 
108  UveVirtualMachineAgent uve;
109 
110  interface_tree_.clear();
111  uve_info_ = uve;
112 
113  deleted_ = true;
114  renewed_ = false;
115  add_by_vm_notify_ = false;
116 }
const string & GetCfgName() const
Definition: vm.h:43
InterfaceSet interface_tree_
Definition: vm.h:32
boost::uuids::uuid uuid
bool Update(const VmEntry *vm)
bool changed() const
UveVirtualMachineAgent uve_info_
void InterfaceDelete(const std::string &intf_cfg_name)
virtual ~VmUveEntryBase()
bool UveVmVRouterChanged(const std::string &new_value) const
Definition: agent.h:358
std::string vm_name_
virtual void Reset()
VmUveEntryBase(Agent *agent, const std::string &vm_name)
std::string vm_config_name_
bool FrameVmMsg(const boost::uuids::uuid &u, UveVirtualMachineAgent *uve)
void InterfaceAdd(const std::string &intf_cfg_name)
const std::string & host_name() const
Definition: agent.h:875
bool UveVmInterfaceListChanged(const std::vector< std::string > &new_l) const