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