OpenSDN source code
vn_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 
7 #include <uve/agent_uve_base.h>
8 
10  : agent_(agent), vn_(vn), uve_info_(), interface_tree_(), vm_tree_(),
11  add_by_vn_notify_(false), changed_(true), deleted_(false),
12  renewed_(false) {
13 }
14 
16  : agent_(agent), vn_(NULL), uve_info_(), interface_tree_(), vm_tree_(),
17  add_by_vn_notify_(false), changed_(true), deleted_(false),
18  renewed_(false) {
19 }
20 
22 }
23 
24 void VnUveEntryBase::VmAdd(const string &vm) {
25  if (vm != agent_->NullString()) {
26  VmSet::iterator it = vm_tree_.find(vm);
27  if (it == vm_tree_.end()) {
28  vm_tree_.insert(vm);
29  }
30  }
31 }
32 
33 void VnUveEntryBase::VmDelete(const string &vm) {
34  if (vm != agent_->NullString()) {
35  VmSet::iterator vm_it = vm_tree_.find(vm);
36  if (vm_it != vm_tree_.end()) {
37  vm_tree_.erase(vm_it);
38  }
39  }
40 }
41 
43  InterfaceSet::iterator it = interface_tree_.find(intf);
44  if (it == interface_tree_.end()) {
45  interface_tree_.insert(intf);
46  }
47 }
48 
50  InterfaceSet::iterator intf_it = interface_tree_.find(intf);
51  if (intf_it != interface_tree_.end()) {
52  interface_tree_.erase(intf_it);
53  }
54  if (!add_by_vn_notify_ && (interface_tree_.size() == 0)) {
55  renewed_ = false;
56  deleted_ = true;
57  }
58 }
59 
60 bool VnUveEntryBase::BuildInterfaceVmList(UveVirtualNetworkAgent &s_vn) {
61  bool changed = false;
62  assert(!deleted_);
63 
64  s_vn.set_name(vn_->GetName());
65  vector<string> vm_list;
66 
67  VmSet::iterator vm_it = vm_tree_.begin();
68  while (vm_it != vm_tree_.end()) {
69  vm_list.push_back(*vm_it);
70  ++vm_it;
71  }
72  if (UveVnVmListChanged(vm_list)) {
73  s_vn.set_virtualmachine_list(vm_list);
74  uve_info_.set_virtualmachine_list(vm_list);
75  changed = true;
76  }
77 
78  vector<string> intf_list;
79  InterfaceSet::iterator intf_it = interface_tree_.begin();
80  while (intf_it != interface_tree_.end()) {
81  const Interface *intf = *intf_it;
82  const VmInterface *vm_port =
83  static_cast<const VmInterface *>(intf);
84  intf_list.push_back(vm_port->cfg_name());
85  intf_it++;
86  }
87  if (UveVnInterfaceListChanged(intf_list)) {
88  s_vn.set_interface_list(intf_list);
89  uve_info_.set_interface_list(intf_list);
90  changed = true;
91  }
92 
93  return changed;
94 }
95 
96 bool VnUveEntryBase::UveVnAclChanged(const string &name) const {
97  if (!uve_info_.__isset.acl) {
98  return true;
99  }
100  if (name.compare(uve_info_.get_acl()) != 0) {
101  return true;
102  }
103  return false;
104 }
105 
106 bool VnUveEntryBase::UveVnMirrorAclChanged(const string &name) const {
107  if (!uve_info_.__isset.mirror_acl) {
108  return true;
109  }
110  if (name.compare(uve_info_.get_mirror_acl()) != 0) {
111  return true;
112  }
113  return false;
114 }
115 
116 bool VnUveEntryBase::UveVnInterfaceListChanged(const vector<string> &new_list)
117  const {
118  if (!uve_info_.__isset.interface_list) {
119  return true;
120  }
121  if (new_list != uve_info_.get_interface_list()) {
122  return true;
123  }
124  return false;
125 }
126 
127 bool VnUveEntryBase::UveVnVmListChanged(const vector<string> &new_list) const {
128  if (!uve_info_.__isset.virtualmachine_list) {
129  return true;
130  }
131  if (new_list != uve_info_.get_virtualmachine_list()) {
132  return true;
133  }
134  return false;
135 }
136 
138  if (!uve_info_.__isset.total_acl_rules) {
139  return true;
140  }
141  if (size != uve_info_.get_total_acl_rules()) {
142  return true;
143  }
144  return false;
145 }
146 
148  UveVirtualNetworkAgent *uve) {
149  bool changed = false;
150  assert(!deleted_);
151  uve->set_name(vn->GetName());
152 
153  int acl_rule_count;
154  if (vn->GetAcl()) {
155  acl_rule_count = vn->GetAcl()->Size();
156  } else {
157  acl_rule_count = 0;
158  }
159 
160  if (UveVnAclRuleCountChanged(acl_rule_count)) {
161  uve->set_total_acl_rules(acl_rule_count);
162  uve_info_.set_total_acl_rules(acl_rule_count);
163  changed = true;
164  }
165 
166  return changed;
167 }
168 
169 bool VnUveEntryBase::FrameVnMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve) {
170  bool changed = false;
171  assert(!deleted_);
172  uve.set_name(vn->GetName());
173 
174  string acl_name;
175  int acl_rule_count;
176  if (vn->GetAcl()) {
177  acl_name = vn->GetAcl()->GetName();
178  acl_rule_count = vn->GetAcl()->Size();
179  } else {
180  acl_name = agent_->NullString();
181  acl_rule_count = 0;
182  }
183 
184  if (UveVnAclChanged(acl_name)) {
185  uve.set_acl(acl_name);
186  uve_info_.set_acl(acl_name);
187  changed = true;
188  }
189 
190  if (UveVnAclRuleCountChanged(acl_rule_count)) {
191  uve.set_total_acl_rules(acl_rule_count);
192  uve_info_.set_total_acl_rules(acl_rule_count);
193  changed = true;
194  }
195 
196  if (vn->GetMirrorCfgAcl()) {
197  acl_name = vn->GetMirrorCfgAcl()->GetName();
198  } else {
199  acl_name = agent_->NullString();
200  }
201  if (UveVnMirrorAclChanged(acl_name)) {
202  uve.set_mirror_acl(acl_name);
203  uve_info_.set_mirror_acl(acl_name);
204  changed = true;
205  }
206 
207  if (BuildInterfaceVmList(uve)) {
208  changed = true;
209  }
210  return changed;
211 }
212 
214  UveVirtualNetworkAgent uve;
215 
216  interface_tree_.clear();
217  vm_tree_.clear();
218  uve_info_ = uve;
219  vn_ = NULL;
220 
221  deleted_ = true;
222  renewed_ = false;
223  add_by_vn_notify_ = false;
224 }
const std::string & GetName() const
Definition: acl.h:113
uint32_t Size() const
Definition: acl.h:123
Definition: agent.h:361
static const std::string & NullString()
Definition: agent.h:440
const std::string & cfg_name() const
Definition: vn.h:152
const string & GetName() const
Definition: vn.h:163
const AclDBEntry * GetAcl() const
Definition: vn.h:168
const AclDBEntry * GetMirrorCfgAcl() const
Definition: vn.h:170
bool UveVnAclRuleCountChanged(int32_t size) const
bool changed() const
void VmAdd(const std::string &vm)
bool UveVnInterfaceListChanged(const std::vector< string > &new_list) const
bool BuildInterfaceVmList(UveVirtualNetworkAgent &s_vn)
virtual void Reset()
virtual ~VnUveEntryBase()
InterfaceSet interface_tree_
bool UveVnAclChanged(const std::string &name) const
const VnEntry * vn_
void InterfaceAdd(const Interface *intf)
bool FrameVnMsg(const VnEntry *vn, UveVirtualNetworkAgent &uve)
UveVirtualNetworkAgent uve_info_
void InterfaceDelete(const Interface *intf)
bool FrameVnAclRuleCountMsg(const VnEntry *vn, UveVirtualNetworkAgent *uve)
VnUveEntryBase(Agent *agent, const VnEntry *vn)
bool UveVnMirrorAclChanged(const std::string &name) const
const VnEntry * vn() const
bool UveVnVmListChanged(const std::vector< string > &new_list) const
void VmDelete(const std::string &vm)