OpenSDN source code
port_subscribe_table.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 #include <string>
6 #include <sandesh/sandesh_trace.h>
7 #include <port_ipc/port_ipc_types.h>
8 #include <cmn/agent_cmn.h>
9 #include <init/agent_param.h>
10 #include <oper/interface_common.h>
12 #include "port_subscribe_table.h"
13 #include "port_ipc_handler.h"
14 
15 using namespace autogen;
16 using boost::uuids::nil_uuid;
17 
19 // Init/Shutdown routines
22  // Register with config DB table for vm-port UUID to IFNode mapping
23  vmi_config_table_ = (static_cast<IFMapAgentTable *>
24  (IFMapTable::FindTable(agent_->db(),
25  "virtual-machine-interface")));
26  vmi_config_listener_id_ = vmi_config_table_->Register
27  (boost::bind(&PortSubscribeTable::Notify, this, _1, _2));
28 }
29 
31  DBTable::DBStateClear(vmi_config_table_, vmi_config_listener_id_);
32  vmi_config_table_->Unregister(vmi_config_listener_id_);
33 }
34 
36 // PortSubscribeEntry routines
39  int32_t version) :
40  type_(type), ifname_(ifname), version_(version) {
41 }
42 
44 }
45 
46 // Only version number is modifiable
48  version_ = rhs->version_;
49 }
50 
52  switch (type) {
53  case VMPORT:
54  return "VM Port";
55  break;
56 
57  case NAMESPACE:
58  return "Namespace Port";
59  break;
60 
61  case REMOTE_PORT:
62  return "Remote Port";
63  break;
64 
65  default:
66  break;
67  }
68 
69  return "Invalid";
70 }
71 
73 // VmiSubscribeEntry routines
76  const std::string &ifname,
77  uint32_t version,
78  const boost::uuids::uuid &vmi_uuid,
79  const boost::uuids::uuid vm_uuid,
80  const std::string &vm_name,
81  const boost::uuids::uuid &vn_uuid,
82  const boost::uuids::uuid &project_uuid,
83  const Ip4Address &ip4_addr,
84  const Ip6Address &ip6_addr,
85  const std::string &mac_addr,
86  uint16_t tx_vlan_id, uint16_t rx_vlan_id,
87  uint8_t vhostuser_mode, uint8_t link_state) :
88  PortSubscribeEntry(type, ifname, version), vmi_uuid_(vmi_uuid),
89  vm_uuid_(vm_uuid), vm_name_(vm_name), vn_uuid_(vn_uuid),
90  project_uuid_(project_uuid), ip4_addr_(ip4_addr), ip6_addr_(ip6_addr),
91  mac_addr_(mac_addr), tx_vlan_id_(tx_vlan_id), rx_vlan_id_(rx_vlan_id),
92  vhostuser_mode_(vhostuser_mode), link_state_(link_state) {
93 }
94 
96 }
97 
100 }
101 
103  uint16_t tx_vlan_id_p = VmInterface::kInvalidVlanId;
104  uint16_t rx_vlan_id_p = VmInterface::kInvalidVlanId;
105  string port = Agent::NullString();
107  if (agent->params()->isVmwareMode()) {
108  tx_vlan_id_p = tx_vlan_id_;
109  rx_vlan_id_p = rx_vlan_id_;
110  if (tx_vlan_id_p != VmInterface::kInvalidVlanId ||
111  rx_vlan_id_p != VmInterface::kInvalidVlanId) {
112  // In case of netns instance transport mode and
113  // parent interface shouldnt be set
114  port = agent->params()->vmware_physical_port();
115  transport = Interface::TRANSPORT_VIRTUAL;
116  }
117  }
118 
119  if ((agent->vrouter_on_nic_mode() == true ||
120  agent->vrouter_on_host_dpdk() == true) &&
122  transport = Interface::TRANSPORT_PMD;
123  }
124 
125  // Add the interface
128  tx_vlan_id_p, rx_vlan_id_p, port, ip6_addr_,
129  vhostuser_mode_, transport, link_state_);
130 
131  // Notify controller module about new port
133  return;
134 
136  data(new ControllerVmiSubscribeData(false, vmi_uuid_, vm_uuid_));
137  agent->controller()->Enqueue(data);
138 }
139 
141  const {
145  return;
146 
149  agent->controller()->Enqueue(data);
150 }
151 
153  return vn_uuid_ == u;
154 }
155 
157  return vm_uuid_ == u;
158 }
159 
161 // VmVnPortSubscribeEntry routines
164 (PortSubscribeEntry::Type type, const std::string &ifname, uint32_t version,
165  const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid,
166  const boost::uuids::uuid &vmi_uuid, const std::string &vm_name,
167  const std::string &vm_identifier, const std::string &vm_ifname,
168  const std::string &vm_namespace) :
169  PortSubscribeEntry(type, ifname, version), vm_uuid_(vm_uuid),
170  vn_uuid_(vn_uuid), vm_name_(vm_name), vm_identifier_(vm_identifier),
171  vm_ifname_(vm_ifname), vm_namespace_(vm_namespace), vmi_uuid_(vmi_uuid) {
172 }
173 
175 }
176 
179 }
180 
182  const {
184 
185 }
186 
188  const {
190 }
191 
193  if (vn_uuid_ == nil_uuid())
194  return true;
195 
196  return vn_uuid_ == u;
197 }
198 
200  return vm_uuid_ == u;
201 }
202 
204 // PortSubscribeTable routines
207  agent_(agent), interface_table_(agent->interface_table()),
208  controller_(agent->controller()),
209  vmi_config_table_(NULL), vmi_config_listener_id_(DBTableBase::kInvalidId) {
210 }
211 
213  assert(vmi_tree_.size() == 0);
214 }
215 
217  PortSubscribeEntryPtr entry) {
218  std::scoped_lock lock(mutex_);
219  std::pair<VmiTree::iterator, bool> ret =
220  vmi_tree_.insert(std::make_pair(u, entry));
221  if (ret.second == false) {
222  // Could be a port add for an exisiting VMI with a different VM.
223  // If so need to handle as a del and add.
224  VmiSubscribeEntry *new_entry =
225  dynamic_cast<VmiSubscribeEntry *>(entry.get());
226  VmiSubscribeEntry *old_entry =
227  dynamic_cast<VmiSubscribeEntry *>(ret.first->second.get());
228  if (old_entry->vm_uuid() != new_entry->vm_uuid()) {
229  ret.first->second->OnDelete(agent_, this);
230  vmi_tree_.erase(ret.first);
231  ret = vmi_tree_.insert(std::make_pair(u, entry));
232  } else {
233  ret.first->second->Update(entry.get());
234  }
235  }
236 
237  ret.first->second->OnAdd(agent_, this);
238 }
239 
241  std::scoped_lock lock(mutex_);
242  VmiTree::iterator it = vmi_tree_.find(u);
243  if (it == vmi_tree_.end())
244  return;
245 
246  it->second->OnDelete(agent_, this);
247  vmi_tree_.erase(it);
248 }
249 
251  const {
252  std::scoped_lock lock(mutex_);
253  VmiTree::const_iterator it = vmi_tree_.find(u);
254  if (it == vmi_tree_.end())
255  return PortSubscribeEntryPtr();
256 
257  return it->second;
258 }
259 
260 /*
261  * Process add of vm-vn subscribe entry.
262  * Add an entry to vmvn_subscribe_tree_
263  * If VMI config was already received for port then
264  * - find vmi-uuid from * vmvn_to_vmi_tree_
265  * - ifmap config resync will be done once vmi is added
266  */
268  const boost::uuids::uuid &vn_uuid,
269  const boost::uuids::uuid &vmi_uuid,
270  PortSubscribeEntryPtr entry) {
271  std::scoped_lock lock(mutex_);
272  std::pair<VmVnTree::iterator, bool> ret = vmvn_subscribe_tree_.insert
273  (make_pair(VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid),entry));
274  if (ret.second == false) {
275  ret.first->second->Update(entry.get());
276  }
277 
278  // Find VMI for the vm-vn
279  //boost::uuids::uuid vmi_uuid = VmVnToVmiNoLock(vm_uuid);
280  if (vmi_uuid.is_nil())
281  return;
282 
283  // If entry is found, it means IFNode for VMI already present
284  // Enqueue vm-add request
285  VmVnPortSubscribeEntry *vmvn_entry =
286  static_cast<VmVnPortSubscribeEntry *>(entry.get());
287  vmvn_entry->set_vmi_uuid(vmi_uuid);
288  vmvn_entry->OnAdd(agent_, this);
289 }
290 
292 (const boost::uuids::uuid &vm_uuid,
293 const boost::uuids::uuid &vn_uuid,
294 const boost::uuids::uuid &vmi_uuid) {
295  std::scoped_lock lock(mutex_);
296  VmVnTree::iterator it =
297  vmvn_subscribe_tree_.find(VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid));
298  if (it == vmvn_subscribe_tree_.end())
299  return;
300 
301  it->second->OnDelete(agent_, this);
302  vmvn_subscribe_tree_.erase(it);
303 }
304 
306 (const boost::uuids::uuid &vm_uuid,
307  const boost::uuids::uuid &vn_uuid,
308  const boost::uuids::uuid &vmi_uuid) {
309  VmVnTree::iterator it =
310  vmvn_subscribe_tree_.find(VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid));
311  if (it == vmvn_subscribe_tree_.end())
312  return PortSubscribeEntryPtr();
313 
314  return it->second;
315 }
316 
318 (const boost::uuids::uuid &vm_uuid,
319  const boost::uuids::uuid &vn_uuid,
320  const boost::uuids::uuid &vmi_uuid) {
321  std::scoped_lock lock(mutex_);
322  return GetVmVnPortNoLock(vm_uuid, vn_uuid, vmi_uuid);
323 }
324 
326 // virtual-machine-interface table handler
329  IFMapNode *node = static_cast<IFMapNode *>(e);
330  State *state = static_cast<State *>(e->GetState(partition->parent(),
332  if (node->IsDeleted()) {
333  if (state == NULL)
334  return;
335  if (state->uuid_ != nil_uuid())
336  uuid_ifnode_tree_.erase(state->uuid_);
337  node->ClearState(partition->parent(), vmi_config_listener_id_);
338  delete state;
339  return;
340  }
341 
342  // Allocate DBState
343  if (state == NULL) {
344  state = new State();
345  node->SetState(partition->parent(), vmi_config_listener_id_, state);
346  }
347 
349  VirtualMachineInterface *cfg =
350  static_cast <VirtualMachineInterface *> (node->GetObject());
351  if (cfg != NULL) {
352  autogen::IdPermsType id_perms = cfg->id_perms();
353  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
354  }
355 
356  // Update UUID tree
357  if (state->uuid_ != u) {
358  // Remove old-uuid
359  if (state->uuid_ != nil_uuid()) {
360  uuid_ifnode_tree_.erase(state->uuid_);
361  state->uuid_ = nil_uuid();
362  }
363 
364  // Set new-uuid
365  if (u != nil_uuid()) {
366  state->uuid_ = u;
367  uuid_ifnode_tree_.insert(std::make_pair(u, node));
368  }
369  }
370 }
371 
373  UuidToIFNodeTree::const_iterator it;
374  it = uuid_ifnode_tree_.find(u);
375  if (it == uuid_ifnode_tree_.end()) {
376  return NULL;
377  }
378  return it->second;
379 }
380 
382 (const boost::uuids::uuid &vmi_uuid) const {
383  VmiToVmVnTree::const_iterator it = vmi_to_vmvn_tree_.find(vmi_uuid);
384  if (it == vmi_to_vmvn_tree_.end())
385  return NULL;
386 
387  return &it->second;
388 }
389 
391  const VmInterfaceConfigData *data) {
392  entry->vm_uuid_ = data->vm_uuid_;
393  entry->vn_uuid_ = data->vn_uuid_;
394  entry->sub_interface_ = (entry->parent_vmi_.is_nil() == false);
395  entry->parent_vmi_ = data->parent_vmi_;
396  entry->vlan_tag_ = data->rx_vlan_id_;
397  entry->vhostuser_mode_ = data->vhostuser_mode_;
398  entry->mac_ = data->vm_mac_;
399  entry->vmi_cfg = data->GetVmiCfg();
400 }
401 
402 /*
403  * Update config tables built from VMI IFnode
404  * - Adds entry into vmi_to_vmvn_tree_
405  * - Adds entry to vmvn_to_vmi_tree_
406  */
408 (const boost::uuids::uuid &vmi_uuid, const VmInterfaceConfigData *data) {
409  // Find entry from vmi to vm-vn tree first
410  VmiToVmVnTree::iterator it;
411  it = vmi_to_vmvn_tree_.find(vmi_uuid);
412 
413  if (it != vmi_to_vmvn_tree_.end()) {
414  // Nothing to do if entry already present and vm/vn match
415  if (it->second.vm_uuid_ != data->vm_uuid_ ||
416  it->second.vn_uuid_ != data->vn_uuid_) {
417  // If an entry already present and VM/VN are different, remove the
418  // reverse entry first and then update with new entry
419  vmvn_to_vmi_tree_.erase(VmVnUuidEntry(it->second.vm_uuid_,
420  it->second.vn_uuid_,
421  vmi_uuid));
422  VmVnUuidEntry entry(data->vm_uuid_, data->vn_uuid_, vmi_uuid);
423  vmvn_to_vmi_tree_.insert(std::make_pair(entry, vmi_uuid));
424  }
425 
426  // Update data fields
427  CopyVmiConfigToInfo(&it->second, data);
428  } else {
429  // Entry not present add to vmi_to_vmvn_tree_ and vmvn_to_vmi_tree_
430  VmVnUuidEntry entry(data->vm_uuid_, data->vn_uuid_, vmi_uuid);
431  vmvn_to_vmi_tree_.insert(std::make_pair(entry, vmi_uuid));
432  VmiEntry vmi_entry;
433  CopyVmiConfigToInfo(&vmi_entry, data);
434  vmi_to_vmvn_tree_.insert(std::make_pair(vmi_uuid, vmi_entry));
435  }
436 }
437 
438 /*
439  * VMI IFNode config added. Build vmi_to_vmvn_tree_ and vmvn_to_vmi_tree from
440  * interface configuration. It will be used for vm-vn based subscriptions
441  *
442  * If the vm-vn port subscription is already received, the message would have
443  * been ignored since vmi-uuid was not known. Process the vm-vn port
444  * subscription now
445  */
447  const VmInterfaceConfigData *data) {
448  std::scoped_lock lock(mutex_);
449  UpdateVmiIfnodeInfo(vmi_uuid, data);
450  // Add vm-interface if possible
451  PortSubscribeEntryPtr entry_ref =
452  GetVmVnPortNoLock(data->vm_uuid_, data->vn_uuid_, vmi_uuid);
453  if (entry_ref.get() == NULL)
454  return;
455 
456  VmVnPortSubscribeEntry *entry =
457  dynamic_cast<VmVnPortSubscribeEntry *>(entry_ref.get());
458  // Nothing to do if vmi-uuid doesnt change
459  if (entry->vmi_uuid() == vmi_uuid) {
460  return;
461  }
462 
463  // vmi-uuid for vmvn-port entry changed. Delete old VMI and add new VMI
464  if (entry->vmi_uuid().is_nil() == false) {
465  entry->OnDelete(agent_, this);
466  }
467  entry->set_vmi_uuid(vmi_uuid);
468  if (entry->vmi_uuid().is_nil() == false) {
469  entry->OnAdd(agent_, this);
470  }
471 }
472 
473 /*
474  * Update config tables built from VMI IFnode
475  * - Deletes entry from vmi_to_vmvn_tree_
476  * - Deletes entry from vmvn_to_vmi_tree_
477  */
479 (const boost::uuids::uuid &vmi_uuid) {
480  VmiToVmVnTree::iterator it;
481  it = vmi_to_vmvn_tree_.find(vmi_uuid);
482  if (it == vmi_to_vmvn_tree_.end()) {
483  return;
484  }
485 
486  // If an entry already present in vm-vn entry, delete entries from
487  // vmi_to_vmvn_tree_ and vmvn_to_vmi_tree_
488  vmvn_to_vmi_tree_.erase(VmVnUuidEntry(it->second.vm_uuid_,
489  it->second.vn_uuid_,
490  vmi_uuid));
491  vmi_to_vmvn_tree_.erase(it);
492 }
493 
494 /*
495  * VMI IFNode config deleted. Remove entries from vmi_to_vmvn_tree_ and
496  * vmvn_to_vmi_tree from interface configuration.
497  *
498  * VMI deletion happens only on deletion of vm-vn port subscription. So, dont
499  * enqueue any VMI delete from here
500  */
502 (const boost::uuids::uuid &vmi_uuid) {
503  std::scoped_lock lock(mutex_);
504  DeleteVmiIfnodeInfo(vmi_uuid);
505 }
506 
508  // TODO : The tree can be modified in parallel. Must ensure synchronization
510  if (!pih) {
511  return;
512  }
513  VmiTree::iterator it = vmi_tree_.begin();
514  while (it != vmi_tree_.end()) {
515  VmiSubscribeEntry *entry =
516  dynamic_cast<VmiSubscribeEntry *>(it->second.get());
517  it++;
518  if (entry->type() == PortSubscribeEntry::NAMESPACE)
519  continue;
520 
521  if (entry->version() >= version) {
522  continue;
523  }
524 
525  std::string msg;
526  pih->DeleteVmiUuidEntry(entry->vmi_uuid(), msg);
527  }
528 
529  // Audit vm-vn port subscription entries
530  VmVnTree::iterator vmvn_it = vmvn_subscribe_tree_.begin();
531  while (vmvn_it != vmvn_subscribe_tree_.end()) {
532  VmVnPortSubscribeEntry *entry =
533  dynamic_cast<VmVnPortSubscribeEntry *>(vmvn_it->second.get());
534  vmvn_it++;
535  if (entry->type() == PortSubscribeEntry::NAMESPACE)
536  continue;
537 
538  if (entry->version() >= version) {
539  continue;
540  }
541 
542  std::string msg;
543  pih->DeleteVmVnPort(entry->vm_uuid(), msg);
544  }
545 }
546 
547 // Get port-subscribe-entry for a VMI
548 // First looks at VMI subscription table. If not found, looks into
549 // vmvn-port-subscribe table
551 (const boost::uuids::uuid &vmi_uuid,
552  const boost::uuids::uuid &vm_uuid,
553  const boost::uuids::uuid &vn_uuid) const {
554  std::scoped_lock lock(mutex_);
555  VmiTree::const_iterator it = vmi_tree_.find(vmi_uuid);
556  if (it != vmi_tree_.end())
557  return it->second;
558 
559  VmVnTree::const_iterator it1 =
560  vmvn_subscribe_tree_.find(VmVnUuidEntry(vm_uuid, vn_uuid, vmi_uuid));
561  if (it1 != vmvn_subscribe_tree_.end())
562  return it1->second;
563 
564  return PortSubscribeEntryPtr();
565 }
566 
568 (const boost::uuids::uuid &vm_uuid,
569  std::set<boost::uuids::uuid> &vmi_uuid_set) const {
570  VmVnToVmiTree::const_iterator it =
571  vmvn_to_vmi_tree_.lower_bound(
572  VmVnUuidEntry(vm_uuid, nil_uuid(), nil_uuid()));
573 
574  while (it != vmvn_to_vmi_tree_.end()) {
575  if (it->first.vm_uuid_ == vm_uuid)
576  vmi_uuid_set.insert(it->second);
577  it++;
578  }
579 
580  if (vmi_uuid_set.empty())
581  return false;
582 
583  return true;
584 }
585 
587 (const boost::uuids::uuid &vm_uuid,
588  std::set<boost::uuids::uuid> &vmi_uuid_set) const {
589  std::scoped_lock lock(mutex_);
590  return VmVnToVmiSetNoLock(vm_uuid, vmi_uuid_set);
591 }
592 
594 // Introspect routines
597 public:
598  SandeshPortSubscribeTask(Agent *agent, const std::string &context) :
599  Task(agent->task_scheduler()->GetTaskId(kTaskHttpRequstHandler), 0),
600  agent_(agent),
601  table_(agent->port_ipc_handler()->port_subscribe_table()),
602  context_(context) {
603  }
605 
606 protected:
609  std::string context_;
611 };
612 
613 // vmi_tree_ routes
615 public:
616  SandeshVmiPortSubscribeTask(Agent *agent, const std::string &context,
617  const std::string &ifname,
618  const boost::uuids::uuid &vmi_uuid) :
619  SandeshPortSubscribeTask(agent, context),
620  ifname_(ifname), vmi_uuid_(vmi_uuid) {
621  }
623 
624  virtual bool Run();
625  std::string Description() const { return "SandeshVmiPortSubscribeTask"; }
626 private:
627  std::string ifname_;
630 };
631 
633  SandeshVmiPortSubscriptionResp *resp = new SandeshVmiPortSubscriptionResp();
634 
635  PortSubscribeTable::VmiTree::const_iterator it = table_->vmi_tree_.begin();
636  std::vector<SandeshVmiPortSubscriptionInfo> port_list;
637  while (it != table_->vmi_tree_.end()) {
638  const VmiSubscribeEntry *entry =
639  dynamic_cast<const VmiSubscribeEntry *> (it->second.get());
640  it++;
641 
642  if ((ifname_.empty() == false) &&
643  (entry->ifname().find(ifname_) == string::npos) ) {
644  continue;
645  }
646 
647  if (vmi_uuid_.is_nil() == false && entry->vmi_uuid() != vmi_uuid_) {
648  continue;
649  }
650 
651  SandeshVmiPortSubscriptionInfo info;
652  info.set_ifname(entry->ifname());
653  info.set_version(entry->version());
654  info.set_vmi_uuid(UuidToString(entry->vmi_uuid()));
655  info.set_vm_uuid(UuidToString(entry->vm_uuid()));
656  info.set_vn_uuid(UuidToString(entry->vn_uuid()));
657  info.set_vm_name(entry->vm_name());
658  info.set_ip4_addr(entry->ip4_addr().to_string());
659  info.set_ip6_addr(entry->ip6_addr().to_string());
660  info.set_mac(entry->mac_addr());
661  info.set_tx_vlan(entry->tx_vlan_id());
662  info.set_rx_vlan(entry->rx_vlan_id());
663  info.set_vhostuser_mode(entry->vhostuser_mode());
664 
665  port_list.push_back(info);
666  }
667  resp->set_port_list(port_list);
668 
669  resp->set_context(context_);
670  resp->set_more(false);
671  resp->Response();
672  return true;
673 }
674 
675 void FetchVmiPortSubscriptionReq::HandleRequest() const {
676  Agent *agent = Agent::GetInstance();
677  boost::uuids::uuid u = StringToUuid(get_vmi_uuid());
679  new SandeshVmiPortSubscribeTask(agent, context(), get_ifname(), u);
680  agent->task_scheduler()->Enqueue(t);
681 }
682 
683 // vmvn_subscribe_tree_ routes
685 public:
686  SandeshVmVnPortSubscribeTask(Agent *agent, const std::string &context,
687  const std::string &ifname,
688  const boost::uuids::uuid &vm_uuid) :
689  SandeshPortSubscribeTask(agent, context),
690  ifname_(ifname), vm_uuid_(vm_uuid) {
691  }
693 
694  virtual bool Run();
695  std::string Description() const { return "SandeshVmVnPortSubscribeTask"; }
696 private:
697  std::string ifname_;
700 };
701 
703  SandeshVmVnPortSubscriptionResp *resp =
704  new SandeshVmVnPortSubscriptionResp();
705 
706  PortSubscribeTable::VmVnTree::const_iterator it =
707  table_->vmvn_subscribe_tree_.begin();
708  std::vector<SandeshVmVnPortSubscriptionInfo> port_list;
709  while (it != table_->vmvn_subscribe_tree_.end()) {
710  const VmVnPortSubscribeEntry *entry =
711  dynamic_cast<const VmVnPortSubscribeEntry *> (it->second.get());
712  it++;
713 
714  if ((ifname_.empty() == false) &&
715  (entry->ifname().find(ifname_) == string::npos) ) {
716  continue;
717  }
718 
719  if (vm_uuid_.is_nil() == false && entry->vm_uuid() != vm_uuid_) {
720  continue;
721  }
722 
723  SandeshVmVnPortSubscriptionInfo info;
724  info.set_ifname(entry->ifname());
725  info.set_version(entry->version());
726  info.set_vm_uuid(UuidToString(entry->vm_uuid()));
727  info.set_vn_uuid(UuidToString(nil_uuid()));
728  info.set_vm_name(entry->vm_name());
729  info.set_vm_identifier(entry->vm_identifier());
730  info.set_vm_ifname(entry->vm_ifname());
731  info.set_vm_namespace(entry->vm_namespace());
732  info.set_vmi_uuid(UuidToString(entry->vmi_uuid()));
733  port_list.push_back(info);
734  }
735  resp->set_port_list(port_list);
736 
737  resp->set_context(context_);
738  resp->set_more(false);
739  resp->Response();
740  return true;
741 }
742 
743 void FetchVmVnPortSubscriptionReq::HandleRequest() const {
744  Agent *agent = Agent::GetInstance();
745  boost::uuids::uuid u = StringToUuid(get_vm_uuid());
747  new SandeshVmVnPortSubscribeTask(agent, context(), get_ifname(), u);
748  agent->task_scheduler()->Enqueue(t);
749 }
750 
751 // vmi_to_vmvn_tree_ routes
753 public:
754  SandeshVmiToVmVnTask(Agent *agent, const std::string &context,
755  const boost::uuids::uuid &vmi_uuid) :
756  SandeshPortSubscribeTask(agent, context),
757  vmi_uuid_(vmi_uuid) {
758  }
759  virtual ~SandeshVmiToVmVnTask() { }
760 
761  virtual bool Run();
762  std::string Description() const { return "SandeshVmiToVmVnTask"; }
763 private:
766 };
767 
769  SandeshVmiToVmVnResp *resp = new SandeshVmiToVmVnResp();
770 
771  PortSubscribeTable::VmiToVmVnTree::const_iterator it =
772  table_->vmi_to_vmvn_tree_.begin();
773  std::vector<SandeshVmiToVmVnInfo> port_list;
774  while (it != table_->vmi_to_vmvn_tree_.end()) {
775  boost::uuids::uuid vmi_uuid = it->first;
776  const PortSubscribeTable::VmiEntry *vmi_entry = &it->second;
777  boost::uuids::uuid vm_uuid = vmi_entry->vm_uuid_;
778  boost::uuids::uuid vn_uuid = vmi_entry->vn_uuid_;
779  it++;
780 
781  if (vmi_uuid_.is_nil() == false && vmi_uuid != vmi_uuid_) {
782  continue;
783  }
784 
785  SandeshVmiToVmVnInfo info;
786  info.set_vmi_uuid(UuidToString(vmi_uuid));
787  info.set_vm_uuid(UuidToString(vm_uuid));
788  info.set_vn_uuid(UuidToString(vn_uuid));
789  if (vmi_entry->sub_interface_)
790  info.set_sub_interface("True");
791  else
792  info.set_sub_interface("False");
793  info.set_vlan_tag(vmi_entry->vlan_tag_);
794  info.set_parent_uuid(UuidToString(vmi_entry->parent_vmi_));
795  info.set_mac(vmi_entry->mac_);
796  port_list.push_back(info);
797  }
798  resp->set_port_list(port_list);
799 
800  resp->set_context(context_);
801  resp->set_more(false);
802  resp->Response();
803  return true;
804 }
805 
806 void FetchVmiToVmVnUuidReq::HandleRequest() const {
807  Agent *agent = Agent::GetInstance();
808  boost::uuids::uuid u = StringToUuid(get_vmi_uuid());
809  agent->task_scheduler()->Enqueue(new SandeshVmiToVmVnTask(agent, context(),
810  u));
811 }
812 
813 // vmvn_to_vmi_tree_ routes
815 public:
816  SandeshVmVnToVmiTask(Agent *agent, const std::string &context,
817  const boost::uuids::uuid &vm_uuid,
818  const boost::uuids::uuid &vn_uuid) :
819  SandeshPortSubscribeTask(agent, context),
820  vm_uuid_(vm_uuid), vn_uuid_(vn_uuid) {
821  }
822  virtual ~SandeshVmVnToVmiTask() { }
823 
824  virtual bool Run();
825  std::string Description() const { return "SandeshVmVnToVmiTask"; }
826 private:
830 };
831 
833  SandeshVmVnToVmiResp *resp = new SandeshVmVnToVmiResp();
834 
835  PortSubscribeTable::VmVnToVmiTree::const_iterator it =
836  table_->vmvn_to_vmi_tree_.begin();
837  std::vector<SandeshVmVnToVmiInfo> port_list;
838  while (it != table_->vmvn_to_vmi_tree_.end()) {
839  boost::uuids::uuid vm_uuid = it->first.vm_uuid_;
840  boost::uuids::uuid vn_uuid = it->first.vn_uuid_;
841  boost::uuids::uuid vmi_uuid = it->second;
842  it++;
843 
844  if (vm_uuid_.is_nil() == false && vm_uuid != vm_uuid_) {
845  continue;
846  }
847 
848  if (vn_uuid_.is_nil() == false && vn_uuid != vn_uuid_) {
849  continue;
850  }
851 
852  SandeshVmVnToVmiInfo info;
853  info.set_vmi_uuid(UuidToString(vmi_uuid));
854  info.set_vm_uuid(UuidToString(vm_uuid));
855  info.set_vn_uuid(UuidToString(vn_uuid));
856  port_list.push_back(info);
857  }
858  resp->set_port_list(port_list);
859 
860  resp->set_context(context_);
861  resp->set_more(false);
862  resp->Response();
863  return true;
864 }
865 
866 void FetchVmVnToVmiUuidReq::HandleRequest() const {
867  Agent *agent = Agent::GetInstance();
868  boost::uuids::uuid u1 = StringToUuid(get_vm_uuid());
869  boost::uuids::uuid u2 = StringToUuid(get_vn_uuid());
870  agent->task_scheduler()->Enqueue(new SandeshVmVnToVmiTask(agent, context(),
871  u1, u2));
872 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
#define kTaskHttpRequstHandler
Definition: agent.h:341
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
const std::string & vmware_physical_port() const
Definition: agent_param.h:331
bool isVmwareMode() const
Definition: agent_param.h:339
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
bool vrouter_on_nic_mode() const
Definition: agent.cc:1057
VNController * controller() const
Definition: agent.cc:985
PortIpcHandler * port_ipc_handler() const
Definition: agent.cc:1009
AgentParam * params() const
Definition: agent.h:1227
bool vrouter_on_host_dpdk() const
Definition: agent.cc:1061
static const std::string & NullString()
Definition: agent.h:440
TaskScheduler * task_scheduler() const
Definition: agent.h:1123
static Agent * GetInstance()
Definition: agent.h:439
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:38
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:74
bool IsDeleted() const
Definition: db_entry.h:49
void Delete()
Definition: db_entry.cc:132
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
Definition: db_entry.cc:23
DBTableBase * parent()
static void DBStateClear(DBTable *table, ListenerId id)
Definition: db_table.cc:577
IFMapObject * GetObject()
Definition: ifmap_node.cc:64
static IFMapTable * FindTable(DB *db, const std::string &element_type)
Definition: ifmap_table.cc:40
@ TRANSPORT_VIRTUAL
Definition: interface.h:67
@ TRANSPORT_PMD
Definition: interface.h:70
@ TRANSPORT_ETHERNET
Definition: interface.h:68
bool DeleteVmVnPort(const boost::uuids::uuid &vmi_uuid, string &err_msg)
void DeleteVmiUuidEntry(const boost::uuids::uuid &u, std::string &err_str)
uint32_t version() const
const std::string & ifname() const
static const char * TypeToString(Type type)
virtual void Update(const PortSubscribeEntry *rhs)
PortSubscribeEntry(Type type, const std::string &ifname, int32_t version)
PortSubscribeEntryPtr Get(const boost::uuids::uuid &vmi_uuid, const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid) const
void AddVmi(const boost::uuids::uuid &u, PortSubscribeEntryPtr entry)
PortSubscribeEntryPtr GetVmVnPort(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid)
void DeleteVmVnPort(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid)
VmiToVmVnTree vmi_to_vmvn_tree_
const VmiEntry * VmiToEntry(const boost::uuids::uuid &vmi_uuid) const
bool VmVnToVmiSet(const boost::uuids::uuid &vm_uuid, std::set< boost::uuids::uuid > &vmi_uuid_set) const
PortSubscribeEntryPtr GetVmi(const boost::uuids::uuid &u) const
void HandleVmiIfnodeDelete(const boost::uuids::uuid &vmi_uuid)
void DeleteVmiIfnodeInfo(const boost::uuids::uuid &vmi_uuid)
void AddVmVnPort(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid, PortSubscribeEntryPtr entry)
PortSubscribeEntryPtr GetVmVnPortNoLock(const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid)
void DeleteVmi(const boost::uuids::uuid &u)
void HandleVmiIfnodeAdd(const boost::uuids::uuid &vmi_uuid, const VmInterfaceConfigData *data)
PortSubscribeTable(Agent *agent)
void UpdateVmiIfnodeInfo(const boost::uuids::uuid &vmi_uuid, const VmInterfaceConfigData *data)
bool VmVnToVmiSetNoLock(const boost::uuids::uuid &vm_uuid, std::set< boost::uuids::uuid > &vmi_uuid_set) const
void Notify(DBTablePartBase *partition, DBEntryBase *e)
VmVnToVmiTree vmvn_to_vmi_tree_
DBTableBase::ListenerId vmi_config_listener_id_
UuidToIFNodeTree uuid_ifnode_tree_
void StaleWalk(uint64_t version)
IFMapNode * UuidToIFNode(const boost::uuids::uuid &u) const
const PortSubscribeTable * table_
SandeshPortSubscribeTask(Agent *agent, const std::string &context)
DISALLOW_COPY_AND_ASSIGN(SandeshPortSubscribeTask)
std::string Description() const
Gives a description of the task.
DISALLOW_COPY_AND_ASSIGN(SandeshVmVnPortSubscribeTask)
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
SandeshVmVnPortSubscribeTask(Agent *agent, const std::string &context, const std::string &ifname, const boost::uuids::uuid &vm_uuid)
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
boost::uuids::uuid vm_uuid_
SandeshVmVnToVmiTask(Agent *agent, const std::string &context, const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid)
boost::uuids::uuid vn_uuid_
std::string Description() const
Gives a description of the task.
DISALLOW_COPY_AND_ASSIGN(SandeshVmVnToVmiTask)
SandeshVmiPortSubscribeTask(Agent *agent, const std::string &context, const std::string &ifname, const boost::uuids::uuid &vmi_uuid)
std::string Description() const
Gives a description of the task.
DISALLOW_COPY_AND_ASSIGN(SandeshVmiPortSubscribeTask)
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
boost::uuids::uuid vmi_uuid_
DISALLOW_COPY_AND_ASSIGN(SandeshVmiToVmVnTask)
SandeshVmiToVmVnTask(Agent *agent, const std::string &context, const boost::uuids::uuid &vmi_uuid)
std::string Description() const
Gives a description of the task.
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq....
Definition: task.cc:662
Task is a class to describe a computational task within OpenSDN control plane applications....
Definition: task.h:82
boost::shared_ptr< ControllerWorkQueueData > ControllerWorkQueueDataType
void Enqueue(ControllerWorkQueueDataType data)
static void DeleteIfNameReq(InterfaceTable *table, const boost::uuids::uuid &uuid)
static void NovaAdd(InterfaceTable *table, const boost::uuids::uuid &intf_uuid, const std::string &os_name, const Ip4Address &addr, const std::string &mac, const std::string &vn_name, const boost::uuids::uuid &vm_project_uuid, uint16_t tx_vlan_id, uint16_t rx_vlan_id, const std::string &parent, const Ip6Address &ipv6, uint8_t vhostuser_mode, Interface::Transport transport, uint8_t link_state)
static const uint32_t kInvalidVlanId
Definition: vm_interface.h:363
static void SetIfNameReq(InterfaceTable *table, const boost::uuids::uuid &uuid, const std::string &ifname)
virtual void Update(const PortSubscribeEntry *rhs)
const std::string & vm_name() const
void OnAdd(Agent *agent, PortSubscribeTable *table) const
virtual const boost::uuids::uuid & vm_uuid() const
boost::uuids::uuid vn_uuid_
boost::uuids::uuid vmi_uuid_
virtual bool MatchVn(const boost::uuids::uuid &u) const
void set_vmi_uuid(const boost::uuids::uuid &u)
const std::string & vm_identifier() const
const std::string & vm_ifname() const
virtual bool MatchVm(const boost::uuids::uuid &u) const
boost::uuids::uuid vm_uuid_
void OnDelete(Agent *agent, PortSubscribeTable *table) const
const std::string & vm_namespace() const
VmVnPortSubscribeEntry(PortSubscribeEntry::Type type, const std::string &ifname, uint32_t version, const boost::uuids::uuid &vm_uuid, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &vmi_uuid, const std::string &vm_name, const std::string &vm_identifier, const std::string &vm_ifname, const std::string &vm_namespace)
const boost::uuids::uuid & vmi_uuid() const
uint16_t rx_vlan_id() const
boost::uuids::uuid vn_uuid_
const Ip4Address & ip4_addr() const
virtual bool MatchVn(const boost::uuids::uuid &u) const
const Ip6Address & ip6_addr() const
virtual bool MatchVm(const boost::uuids::uuid &u) const
const std::string & vm_name() const
uint16_t tx_vlan_id() const
const boost::uuids::uuid & vn_uuid() const
boost::uuids::uuid vm_uuid_
uint8_t vhostuser_mode() const
virtual void Update(const PortSubscribeEntry *rhs)
const boost::uuids::uuid & vmi_uuid() const
boost::uuids::uuid project_uuid_
void OnAdd(Agent *agent, PortSubscribeTable *table) const
const std::string & mac_addr() const
void OnDelete(Agent *agent, PortSubscribeTable *table) const
VmiSubscribeEntry(PortSubscribeEntry::Type type, const std::string &ifname, uint32_t version, const boost::uuids::uuid &vmi_uuid, const boost::uuids::uuid vm_uuid, const std::string &vm_name, const boost::uuids::uuid &vn_uuid, const boost::uuids::uuid &project_uuid, const Ip4Address &ip4_addr, const Ip6Address &ip6_addr, const std::string &mac_addr, uint16_t tx_vlan_id, uint16_t rx_vlan_id, uint8_t vhostuser_mode, uint8_t link_state)
const boost::uuids::uuid & vm_uuid() const
boost::uuids::uuid vmi_uuid_
uint8_t type
Definition: load_balance.h:2
boost::shared_ptr< PortSubscribeEntry > PortSubscribeEntryPtr
static void CopyVmiConfigToInfo(PortSubscribeTable::VmiEntry *entry, const VmInterfaceConfigData *data)
static boost::uuids::uuid StringToUuid(const std::string &str)
Definition: string_util.h:146
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:139
autogen::VirtualMachineInterface * vmi_cfg
boost::uuids::uuid vm_uuid_
boost::uuids::uuid vn_uuid_
autogen::VirtualMachineInterface * GetVmiCfg() const
boost::uuids::uuid parent_vmi_
boost::uuids::uuid uuid