OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  sact*/
4 
5 #include "base/os.h"
6 #include <sys/types.h>
7 #include <net/ethernet.h>
8 #include <netinet/ether.h>
9 #include <boost/uuid/uuid_io.hpp>
10 #include <tbb/mutex.h>
11 
12 #include "base/logging.h"
13 #include "base/address.h"
14 #include "db/db.h"
15 #include "db/db_entry.h"
16 #include "db/db_table.h"
17 #include "ifmap/ifmap_node.h"
18 
19 #include <init/agent_param.h>
20 #include <cfg/cfg_init.h>
21 #include <oper/operdb_init.h>
22 #include <oper/route_common.h>
23 #include <oper/vm.h>
24 #include <oper/vn.h>
25 #include <oper/vrf.h>
26 #include <oper/nexthop.h>
27 #include <oper/mpls.h>
28 #include <oper/mirror_table.h>
29 #include <oper/interface_common.h>
30 #include <oper/vrf_assign.h>
31 #include <oper/vxlan.h>
32 #include <oper/qos_config.h>
34 #include <oper/tag.h>
35 #include <oper/config_manager.h>
36 
37 #include <vnc_cfg_types.h>
38 #include <oper/agent_sandesh.h>
39 #include <oper/sg.h>
40 #include <oper/metadata_ip.h>
41 #include <sandesh/sandesh_trace.h>
42 #include <sandesh/common/vns_types.h>
43 #include <sandesh/common/vns_constants.h>
44 #include <filter/acl.h>
45 #include <filter/policy_set.h>
49 using namespace std;
50 using namespace boost::uuids;
51 using boost::assign::map_list_of;
52 using boost::assign::list_of;
53 
55 
57 // Interface Table routines
59 InterfaceTable::InterfaceTable(DB *db, const std::string &name) :
60  AgentOperDBTable(db, name), operdb_(NULL), agent_(NULL),
61  index_table_(), vmi_count_(0), li_count_(0), active_vmi_count_(0),
62  vmi_ifnode_to_req_(0), li_ifnode_to_req_(0), pi_ifnode_to_req_(0) {
65  this, _1, _2),
67  this, _1, _2));
68 }
69 
71  operdb_ = oper;
72  agent_ = oper->agent();
73 }
74 
76 }
77 
79  if (strcmp(node->table()->Typename(), "virtual-machine-interface") == 0) {
80  return VmiIFNodeToUuid(node, u);
81  }
82 
83  if (strcmp(node->table()->Typename(), "logical-interface") == 0) {
84  return LogicalInterfaceIFNodeToUuid(node, u);
85  }
86 
87  return false;
88 }
89 
91  const boost::uuids::uuid &u) {
92  if (strcmp(node->table()->Typename(), "physical-interface") == 0) {
93  return PhysicalInterfaceIFNodeToReq(node, req, u);
94  }
95 
96  if (strcmp(node->table()->Typename(), "logical-interface") == 0) {
97  return LogicalInterfaceIFNodeToReq(node, req, u);
98  }
99 
100  if (strcmp(node->table()->Typename(), "virtual-machine-interface") == 0) {
101  return VmiIFNodeToReq(node, req, u);
102  }
103 
104  return false;
105 }
106 
108  DBRequest &req,
109  const boost::uuids::uuid &u) {
110  if (req.oper == DBRequest::DB_ENTRY_DELETE || node->IsDeleted()) {
111  return true;
112  }
113 
114  InterfaceData *data = static_cast<InterfaceData *>(req.data.get());
115  IFMapNode *adj_node = agent()->config_manager()->
116  FindAdjacentIFMapNode(node, "logical-router");
117  if (adj_node) {
118  autogen::LogicalRouter *lr =
119  static_cast<autogen::LogicalRouter *>(adj_node->GetObject());
120  autogen::IdPermsType id_perms = lr->id_perms();
121  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
122  data->logical_router_uuid_);
123  }
124 
125  return true;
126 }
127 
129  const boost::uuids::uuid &u) {
130  bool config_processed = false;
131  if (strcmp(node->table()->Typename(), "physical-interface") == 0) {
132  if (PhysicalInterfaceProcessConfig(node, req, u)) {
133  config_processed = true;
134  }
135  }
136 
137  if (strcmp(node->table()->Typename(), "logical-interface") == 0) {
138  if (LogicalInterfaceProcessConfig(node, req, u)) {
139  config_processed = true;
140  }
141  }
142 
143  if (strcmp(node->table()->Typename(), "virtual-machine-interface") == 0) {
144  if (VmiProcessConfig(node, req, u)) {
145  config_processed = true;
146  }
147  }
148 
149  //Interface type was identified, if not no need to fill common interface
150  //data.
151  if (config_processed) {
152  InterfaceCommonProcessConfig(node, req, u);
153  }
154  return config_processed;
155 }
156 
157 std::unique_ptr<DBEntry> InterfaceTable::AllocEntry(const DBRequestKey *k) const{
158  const InterfaceKey *key = static_cast<const InterfaceKey *>(k);
159 
160  return std::unique_ptr<DBEntry>(static_cast<DBEntry *>
161  (key->AllocEntry(this)));
162 }
163 
166  index_table_.Remove(index);
167 }
168 
170  InterfaceKey *key = static_cast<InterfaceKey *>(req->key.get());
171  InterfaceData *data = static_cast<InterfaceData *>(req->data.get());
172 
173  Interface *intf = key->AllocEntry(this, data);
174  if (intf == NULL)
175  return NULL;
176  if (intf->type_ == Interface::VM_INTERFACE) {
177  vmi_count_++;
178  } else if (intf->type_ == Interface::LOGICAL) {
179  li_count_++;
180  }
182  (agent()->resource_manager(), key->uuid_,
183  key->name_));
184  intf->id_ = static_cast<IndexResourceData *>(agent()->resource_manager()->
185  Allocate(rkey).get())->index();
186  index_table_.InsertAtIndex(intf->id_, intf);
187 
188  intf->transport_ = data->transport_;
189  // Get the os-ifindex and mac of interface
190  intf->GetOsParams(agent());
191 
192  intf->Add();
193 
194  intf->SendTrace(this, Interface::ADD);
195  return intf;
196 }
197 
199  bool ret = false;
200  InterfaceKey *key = static_cast<InterfaceKey *>(req->key.get());
201 
202  switch (key->type_) {
204  VmInterface *intf = static_cast<VmInterface *>(entry);
205  ret = intf->OnChange(static_cast<VmInterfaceData *>(req->data.get()));
206  break;
207  }
208  case Interface::INET: {
209  InetInterface *intf = static_cast<InetInterface *>(entry);
210  if (intf) {
211  // Get the os-ifindex and mac of interface
212  intf->GetOsParams(agent());
213  intf->OnChange(static_cast<InetInterfaceData *>(req->data.get()));
214  ret = true;
215  }
216  break;
217  }
218 
219  case Interface::PHYSICAL: {
220  PhysicalInterface *intf = static_cast<PhysicalInterface *>(entry);
221  ret = intf->OnChange(this, static_cast<PhysicalInterfaceData *>
222  (req->data.get()));
223  break;
224  }
225 
228  static_cast<RemotePhysicalInterface *>(entry);
229  ret = intf->OnChange(this, static_cast<RemotePhysicalInterfaceData *>
230  (req->data.get()));
231  break;
232  }
233 
234  case Interface::LOGICAL: {
235  LogicalInterface *intf = static_cast<LogicalInterface *>(entry);
236  ret = intf->OnChange(this, static_cast<LogicalInterfaceData *>
237  (req->data.get()));
238  break;
239  }
240 
241  case Interface::PACKET: {
242  PacketInterface *intf = static_cast<PacketInterface *>(entry);
243  PacketInterfaceData *data = static_cast<PacketInterfaceData *>(req->data.get());
244  ret = intf->OnChange(data);
245  break;
246  }
247 
248  default:
249  break;
250  }
251 
252  return ret;
253 }
254 
255 // RESYNC supported only for VM_INTERFACE
257  InterfaceKey *key = static_cast<InterfaceKey *>(req->key.get());
258 
259  //RESYNC for QOS config handling for vhost and fabric interface
260  InterfaceQosConfigData *qos_config_data =
261  dynamic_cast<InterfaceQosConfigData *>(req->data.get());
262  if (qos_config_data) {
263  Interface *intf = static_cast<Interface *>(entry);
264  AgentQosConfigKey key(qos_config_data->qos_config_uuid_);
265 
266  AgentQosConfig *qos_config = static_cast<AgentQosConfig *>
267  (agent()->qos_config_table()->FindActiveEntry(&key));
268 
269  if (intf->qos_config_ != qos_config) {
270  intf->qos_config_ = qos_config;
271  return true;
272  }
273  return false;
274  }
275 
276  if (key->type_ != Interface::VM_INTERFACE)
277  return false;
278 
279  VmInterfaceData *vm_data = static_cast<VmInterfaceData *>(req->data.get());
280  VmInterface *intf = static_cast<VmInterface *>(entry);
281  return intf->Resync(this, vm_data);
282 }
283 
285  Interface *intf = static_cast<Interface *>(entry);
286  bool ret = false;
287 
288  if (intf->Delete(req)) {
289  intf->SendTrace(this, Interface::DEL);
290  ret = true;
291  }
292  return ret;
293 }
294 
295 VrfEntry *InterfaceTable::FindVrfRef(const string &name) const {
296  VrfKey key(name);
297  return static_cast<VrfEntry *>
298  (agent_->vrf_table()->FindActiveEntry(&key));
299 }
300 
302  VmKey key(uuid);
303  return static_cast<VmEntry *>(agent_->vm_table()->FindActiveEntry(&key));
304 }
305 
307  VnKey key(uuid);
308  return static_cast<VnEntry *>(agent_->vn_table()->FindActiveEntry(&key));
309 }
310 
311 MirrorEntry *InterfaceTable::FindMirrorRef(const string &name) const {
312  MirrorEntryKey key(name);
313  return static_cast<MirrorEntry *>
314  (agent_->mirror_table()->FindActiveEntry(&key));
315 }
316 
317 DBTableBase *InterfaceTable::CreateTable(DB *db, const std::string &name) {
318  interface_table_ = new InterfaceTable(db, name);
319  (static_cast<DBTable *>(interface_table_))->Init();
320  return interface_table_;
321 };
322 
323 const Interface *InterfaceTable::FindInterface(size_t index) const {
324  Interface *intf = index_table_.At(index);
325  if (intf && intf->IsDeleted() != true) {
326  return intf;
327  }
328  return NULL;
329 }
330 
332  Interface *intf = index_table_.At(index);
333  if (intf && intf->IsDeleted() != true) {
334  return intf;
335  }
336  return NULL;
337 }
338 
340  std::string *vm_ip,
341  std::string *vm_uuid,
342  std::string *vm_project_uuid) {
343  const Interface *intf = NULL;
344  if (ip.is_v4()) {
345  intf = FindInterfaceFromMetadataIp(ip.to_v4());
346  } else {
347  intf = FindInterfaceFromMetadataIp(ip.to_v6());
348  }
349  if (!intf) {
350  LOG(ERROR, "Interface in table was not found, ip = " <<
351  ip.to_string() << ", in: " <<
352  "InterfaceTable::FindVmUuidFromMetadataIp" <<
353  std::endl);
354  return false;
355  }
356  if (intf && intf->type() == Interface::VM_INTERFACE) {
357  const VmInterface *vintf = static_cast<const VmInterface *>(intf);
358  if (ip.is_v4())
359  *vm_ip = vintf->primary_ip_addr().to_string();
360  else
361  *vm_ip = vintf->primary_ip6_addr().to_string();
362  if (vintf->vm()) {
363  *vm_uuid = UuidToString(vintf->vm()->GetUuid());
364  *vm_project_uuid = UuidToString(vintf->vm_project_uuid());
365  return true;
366  }
367  }
368  return false;
369 }
370 
372  uint32_t idx = MetaDataIp::IpAddressToIndex(ip);
373  const MetaDataIp *mip = agent_->metadata_ip_allocator()->FindIndex(idx);
374  return mip != NULL ? mip->GetInterface() : NULL;
375 }
376 
378  uint32_t idx = MetaDataIp::IpAddressToIndex(ip);
379  const MetaDataIp *mip = agent_->metadata_ip6_allocator()->FindIndex(idx);
380  return mip != NULL ? mip->GetInterface() : NULL;
381 }
382 
384  DBEntryBase *entry) {
385  Interface *intf = static_cast<Interface *>(entry);
386  if ((intf->type() != Interface::VM_INTERFACE) || intf->IsDeleted())
387  return true;
388 
389  VmInterface *vm_intf = static_cast<VmInterface *>(entry);
390  const VnEntry *vn = vm_intf->vn();
391  if (!vm_intf->IsActive())
392  return true;
393 
394  if (!vn) {
395  return true;
396  }
397 
399  vn->layer3_forwarding(),
400  vn->GetVxLanId());
401  vm_intf->Resync(this, &data);
402  return true;
403 }
404 
406  DBTableBase *partition) {
407 }
408 
411 }
412 
417 }
418 
420  VmInterfaceKey key(AgentKey::ADD_DEL_CHANGE, vmi_uuid, "");
421  Interface *intf = static_cast<Interface *>(Find(&key, false));
422  InterfaceConstRef ref(intf);
423  return ref;
424 }
425 
427  if (agent()->tsn_enabled()) {
428  Interface::Transport transport = static_cast<Interface::Transport>
430  AgentParam *params = agent()->params();
431  InetInterface::Create(this, agent()->vhost_interface_name(),
433  agent()->fabric_vrf_name(),
434  params->vhost_addr(),
435  params->vhost_plen(),
436  params->gateway_list()[0],
437  params->eth_port_list()[0],
438  agent()->fabric_vn_name(), transport);
439  } else {
442  nil_uuid(),
443  agent()->vhost_interface_name()));
444 
446  data->CopyVhostData(agent());
447  data->disable_policy_ = true;
448  req.data.reset(data);
449  Process(req);
450  }
451 }
452 
454  if (agent()->tsn_enabled()) {
455  Interface::Transport transport = static_cast<Interface::Transport>
457  InetInterface::CreateReq(this, agent()->vhost_interface_name(),
459  agent()->fabric_vrf_name(),
460  agent()->router_id(),
461  agent()->vhost_prefix_len(),
462  agent()->vhost_default_gateway()[0],
464  transport);
465  } else {
467  req.key.reset(new VmInterfaceKey(AgentKey::ADD_DEL_CHANGE, nil_uuid(),
468  agent()->vhost_interface_name()));
469 
471  data->CopyVhostData(agent());
472 
473  req.data.reset(data);
474  Enqueue(&req);
475  }
476 }
478 // Interface Base Entry routines
480 Interface::Interface(Type type, const uuid &uuid, const string &name,
481  VrfEntry *vrf, bool state,
482  const boost::uuids::uuid &logical_router_uuid) :
483  type_(type), uuid_(uuid),
484  vrf_(vrf, this), label_(MplsTable::kInvalidLabel),
485  l2_label_(MplsTable::kInvalidLabel), ipv4_active_(true),
486  ipv6_active_(false), is_hc_active_(true),
487  metadata_ip_active_(true), metadata_l2_active_(true),
488  l2_active_(true), id_(kInvalidIndex), dhcp_enabled_(true), dhcp_enabled_v6_(true),
489  dns_enabled_(true),
490  admin_state_(true), test_oper_state_(true), transport_(TRANSPORT_INVALID),
491  os_params_(name, kInvalidIndex, state),
492  logical_router_uuid_(logical_router_uuid) {
493 }
494 
496  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
497  if (id_ != kInvalidIndex) {
498  table->FreeInterfaceId(id_);
499  id_ = kInvalidIndex;
500  if (type_ == VM_INTERFACE) {
501  table->decr_vmi_count();
502  } else if (type_ == LOGICAL) {
503  table->decr_li_count();
504  }
505  }
506 }
507 
508 void Interface::SetPciIndex(Agent *agent, size_t index) {
509  std::istringstream pci(agent->params()->physical_interface_pci_addr_list()[index]);
510 
511  uint32_t domain, bus, device, function;
512  char c;
513  if (pci >> std::hex >> domain) {
514  pci >> c;
515  } else {
516  assert(0);
517  }
518 
519  if (pci >> std::hex >> bus) {
520  pci >> c;
521  } else {
522  assert(0);
523  }
524 
525  if (pci >> std::hex >> device) {
526  pci >> c;
527  } else {
528  assert(0);
529  }
530 
531  pci >> std::hex >> function;
532  os_params_.os_index_ = domain << 16 | bus << 8 | device << 3 | function;
533  os_params_.os_oper_state_ = true;
534 }
535 
537  if (agent->test_mode()) {
538  static int dummy_ifindex = 0;
540  os_params_.os_index_ = ++dummy_ifindex;
541  os_params_.mac_.Zero();
543  }
545  return;
546  }
547 
548  std::string lookup_name = name();
549  const PhysicalInterface *phy_intf = dynamic_cast<const PhysicalInterface *>(this);
550  if (phy_intf) {
551  lookup_name = phy_intf->display_name();
552  }
553 
554  size_t index = 0;
555  if (transport_ == TRANSPORT_PMD && type_ == PHYSICAL) {
556  //PCI address is the name of the interface
557  // os index from that
558  std::vector<std::string>::const_iterator ptr;
559  for (ptr = agent->fabric_interface_name_list().begin();
560  ptr != agent->fabric_interface_name_list().end(); ++ptr) {
561  if (*ptr == lookup_name) {
562  break;
563  }
564  index++;
565  }
566  SetPciIndex(agent, index);
567  }
568 
569  //In case of DPDK, set mac-address to the physical
570  //mac address set in configuration file, since
571  //agent cane query for mac address as physical interface
572  //will not be present
573  const VmInterface *vm_intf = dynamic_cast<const VmInterface *>(this);
574  if (transport_ == TRANSPORT_PMD) {
575  struct ether_addr *addr = NULL;
576  if (agent->is_l3mh()) {
577  if (phy_intf) {
578  addr = ether_aton(agent->params()->
579  physical_interface_mac_addr_list()[index].c_str());
580  if(addr==NULL){
581  LOG(ERROR, "Physical interface MAC not set in DPDK vrouter agent");
582  }
583 
584  } else if (vm_intf && vm_intf->vmi_type() == VmInterface::VHOST) {
585  addr = ether_aton(agent->vrrp_mac().ToString().c_str());
586  if(addr==NULL){
587  LOG(ERROR, "Physical interface MAC not set in DPDK vrouter agent");
588  }
589  }
590  } else {
591  if (phy_intf || (vm_intf && vm_intf->vmi_type() == VmInterface::VHOST)) {
592  addr = ether_aton(agent->params()->
593  physical_interface_mac_addr_list()[0].c_str());
594  if(addr==NULL){
595  LOG(ERROR, "Physical interface MAC not set in DPDK vrouter agent");
596  }
597  }
598  }
599  if (addr) {
600  os_params_.mac_ = *addr;
601  }
602  return;
603  }
605  if (!agent->isVmwareMode()) {
606  os_params_.os_oper_state_ = true;
607  }
608  return;
609  }
610 
611  ObtainOsSpecificParams(lookup_name, agent);
612 }
613 
614 void Interface::SetKey(const DBRequestKey *key) {
615  const InterfaceKey *k = static_cast<const InterfaceKey *>(key);
616  type_ = k->type_;
617  uuid_ = k->uuid_;
618  os_params_.name_ = k->name_;
619 }
620 
621 uint32_t Interface::vrf_id() const {
622  VrfEntryRef p = vrf_;
623  if (p == NULL) {
625  }
626 
627  return p->vrf_id();
628 }
629 
632 }
633 
635  const {
636  return update_floatingip_cb_;
637 }
638 
640 // Pkt Interface routines
642 PacketInterface::PacketInterface(const std::string &name) :
643  Interface(Interface::PACKET, nil_uuid(), name, NULL, true, nil_uuid()) {
644 }
645 
647 }
648 
650  InterfaceKey *key = new PacketInterfaceKey(uuid_, name());
651  return DBEntryBase::KeyPtr(key);
652 }
653 
655  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
657 }
658 
660  flow_key_nh_= NULL;
661  return true;
662 }
663 
664 // Enqueue DBRequest to create a Pkt Interface
666  const std::string &ifname,
667  Interface::Transport transport) {
669  req.key.reset(new PacketInterfaceKey(nil_uuid(), ifname));
670  req.data.reset(new PacketInterfaceData(transport));
671  table->Enqueue(&req);
672 }
673 
674 void PacketInterface::Create(InterfaceTable *table, const std::string &ifname,
675  Interface::Transport transport) {
677  req.key.reset(new PacketInterfaceKey(nil_uuid(), ifname));
678  req.data.reset(new PacketInterfaceData(transport));
679  table->Process(req);
680 }
681 
682 // Enqueue DBRequest to delete a Pkt Interface
684  const std::string &ifname) {
686  req.key.reset(new PacketInterfaceKey(nil_uuid(), ifname));
687  req.data.reset(NULL);
688  table->Enqueue(&req);
689 }
690 
691 void PacketInterface::Delete(InterfaceTable *table, const std::string &ifname) {
693  req.key.reset(new PacketInterfaceKey(nil_uuid(), ifname));
694  req.data.reset(NULL);
695  table->Process(req);
696 }
697 
699  return false;
700 }
702 // DHCP Snoop routines
703 // DHCP Snoop entry can be added from 3 different places,
704 // - Interface added from config
705 // - Address learnt from DHCP Snoop on fabric interface
706 // - Address learnt from vrouter when agent restarts
707 //
708 // DHCP Snoop entry is deleted from 2 places
709 // - Interface deleted from config
710 // - Audit of entries read from vrouter on restart and config table
712 
713 // Get DHCP IP address. First try to find entry in DHCP Snoop table.
714 // If no entry in DHCP Snoop table, query the InterfaceKScan table.
715 //
716 // InterfaceKScan table is populated on agent restart
717 const Ip4Address InterfaceTable::GetDhcpSnoopEntry(const std::string &ifname) {
718  tbb::mutex::scoped_lock lock(dhcp_snoop_mutex_);
719  const DhcpSnoopIterator it = dhcp_snoop_map_.find(ifname);
720  if (it != dhcp_snoop_map_.end()) {
721  return it->second.addr_;
722  }
723 
724  return Ip4Address(0);
725 }
726 
727 void InterfaceTable::DeleteDhcpSnoopEntry(const std::string &ifname) {
728  tbb::mutex::scoped_lock lock(dhcp_snoop_mutex_);
729  const DhcpSnoopIterator it = dhcp_snoop_map_.find(ifname);
730  if (it == dhcp_snoop_map_.end()) {
731  return;
732  }
733 
734  dhcp_snoop_map_.erase(it);
735 }
736 
737 // Set config_seen_ flag in DHCP Snoop entry.
738 // Create the DHCP Snoop entry, if not already present
739 void InterfaceTable::DhcpSnoopSetConfigSeen(const std::string &ifname) {
740  tbb::mutex::scoped_lock lock(dhcp_snoop_mutex_);
741  const DhcpSnoopIterator it = dhcp_snoop_map_.find(ifname);
742  Ip4Address addr(0);
743 
744  if (it != dhcp_snoop_map_.end()) {
745  addr = it->second.addr_;
746  }
747  dhcp_snoop_map_[ifname] = DhcpSnoopEntry(addr, true);
748 }
749 
750 void InterfaceTable::AddDhcpSnoopEntry(const std::string &ifname,
751  const Ip4Address &addr) {
752  tbb::mutex::scoped_lock lock(dhcp_snoop_mutex_);
753  DhcpSnoopEntry entry(addr, false);
754  const DhcpSnoopIterator it = dhcp_snoop_map_.find(ifname);
755 
756  if (it != dhcp_snoop_map_.end()) {
757  // Retain config_entry_ flag from old entry
758  if (it->second.config_entry_) {
759  entry.config_entry_ = true;
760  }
761 
762  // If IP address is not specified, retain old IP address
763  if (addr.to_ulong() == 0) {
764  entry.addr_ = it->second.addr_;
765  }
766  }
767 
768  dhcp_snoop_map_[ifname] = entry;
769 }
770 
771 // Audit DHCP Snoop table. Delete the entries which are not seen from config
773  tbb::mutex::scoped_lock lock(dhcp_snoop_mutex_);
774  DhcpSnoopIterator it = dhcp_snoop_map_.begin();
775  while (it != dhcp_snoop_map_.end()){
776  DhcpSnoopIterator del_it = it++;
777  if (del_it->second.config_entry_ == false) {
778  dhcp_snoop_map_.erase(del_it);
779  }
780  }
781 }
782 
784 // Sandesh routines
787  if (type == VmInterface::LOCAL_DEVICE) {
788  return "Gateway";
789  } else if (type == VmInterface::TOR) {
790  return "TOR";
791  } else if (type == VmInterface::VM_ON_TAP) {
792  return "Tap";
793  } else if (type == VmInterface::VM_VLAN_ON_VMI) {
794  return "VMI vlan-sub-if";
795  } else if (type == VmInterface::REMOTE_VM_VLAN_ON_VMI) {
796  return "Remote VM";
797  }
798  return "Invalid";
799 }
800 
802  if (type == VmInterface::INSTANCE) {
803  return "Virtual Machine";
804  } else if (type == VmInterface::SERVICE_CHAIN) {
805  return "Service Chain";
806  } else if (type == VmInterface::SERVICE_INSTANCE) {
807  return "Service Instance";
808  } else if (type == VmInterface::BAREMETAL) {
809  return "Baremetal";
810  } else if (type == VmInterface::GATEWAY) {
811  return "Gateway";
812  } else if (type == VmInterface::REMOTE_VM) {
813  return "Remote VM";
814  } else if (type == VmInterface::SRIOV) {
815  return "Sriov";
816  } else if (type == VmInterface::VHOST) {
817  return "VHOST";
818  }
819  return "Invalid";
820 }
821 
822 void Interface::SetItfSandeshData(ItfSandeshData &data) const {
823  data.set_index(id_);
824  data.set_name(name());
825  data.set_uuid(UuidToString(uuid_));
826 
827  if (vrf_)
828  data.set_vrf_name(vrf_->GetName());
829  else
830  data.set_vrf_name("--ERROR--");
831 
832  if (IsUveActive()) {
833  data.set_active("Active");
834  } else {
835  data.set_active("Inactive");
836  }
837 
838  if (ipv4_active_) {
839  data.set_ipv4_active("Active");
840  } else {
841  data.set_ipv4_active("Inactive");
842  }
843 
844  if (is_hc_active_) {
845  data.set_health_check_active("Active");
846  } else {
847  data.set_health_check_active("Inactive");
848  }
849 
850  if (metadata_ip_active_) {
851  data.set_metadata_ip_active("Active");
852  } else {
853  data.set_metadata_ip_active("Inactive");
854  }
855 
856  if (ipv6_active_) {
857  data.set_ip6_active("Active");
858  } else {
859  data.set_ip6_active("Inactive");
860  }
861 
862  if (l2_active_) {
863  data.set_l2_active("L2 Active");
864  } else {
865  data.set_l2_active("L2 Inactive");
866  }
867 
868  if (dhcp_enabled_) {
869  data.set_dhcp_service("Enable");
870  } else {
871  data.set_dhcp_service("Disable");
872  }
873 
874  if (dhcp_enabled_v6_) {
875  data.set_dhcp_service_v6("Enable");
876  } else {
877  data.set_dhcp_service_v6("Disable");
878  }
879 
880 
881  if (dns_enabled_) {
882  data.set_dns_service("Enable");
883  } else {
884  data.set_dns_service("Disable");
885  }
886  data.set_label(label_);
887  data.set_l2_label(l2_label_);
888  if (flow_key_nh()) {
889  data.set_flow_key_idx(flow_key_nh()->id());
890  }
891  /* For optional fields set the default values here. This will overwritten
892  * (if required) based on interface type */
893  data.set_ip6_addr("--NA--");
894  std::vector<StaticRouteSandesh> aap_list;
895  data.set_allowed_address_pair_list(aap_list);
896  data.set_subnet("--NA--");
897  data.set_sub_type("--NA--");
898  data.set_vrf_assign_acl_uuid("--NA--");
899  data.set_vmi_type("--NA--");
900  data.set_flood_unknown_unicast(false);
901 
902  if (qos_config_.get()) {
903  data.set_qos_config(UuidToString(qos_config_->uuid()));
904  }
905 
906  switch (type_) {
907  case Interface::PHYSICAL:
908  {
909  const PhysicalInterface *pintf =
910  static_cast<const PhysicalInterface *>(this);
912  pintf->getBondChildIntfMap().begin();
913  vector<BondInterface> bond_interface_list;
914  for(; it != pintf->getBondChildIntfMap().end(); it++)
915  {
917  bond_intf = it->second;
918  BondInterface entry;
919  entry.set_intf_name(bond_intf.intf_name);
920  entry.set_intf_drv_name(bond_intf.intf_drv_name);
921  entry.set_intf_status(bond_intf.intf_status ? "UP" : "DOWN");
922  bond_interface_list.push_back(entry);
923  }
924  data.set_bond_interface_list(bond_interface_list);
925 
926  if(pintf->os_params_.os_oper_state_)
927  data.set_active("Active");
928  else
929  data.set_active("Inactive <Oper-state-down>");
930  data.set_type("eth");
931 
932  }
933  break;
934 
936  data.set_type("remote-physical-port");
937  data.set_vrf_name("--NA--");
938  break;
939 
940  case Interface::LOGICAL:
941  {
942  const LogicalInterface *lintf =
943  static_cast<const LogicalInterface*>(this);
944  data.set_type("logical-port");
945  data.set_vrf_name("--NA--");
946  data.set_physical_device(lintf->phy_dev_display_name());
947  data.set_physical_interface(lintf->phy_intf_display_name());
948  }
949  break;
950 
952  data.set_type("vport");
953  const VmInterface *vintf = static_cast<const VmInterface *>(this);
954  if (vintf->vn())
955  data.set_vn_name(vintf->vn()->GetName());
956  if (vintf->vm())
957  data.set_vm_uuid(UuidToString(vintf->vm()->GetUuid()));
958  data.set_ip_addr(vintf->primary_ip_addr().to_string());
959  data.set_ip6_addr(vintf->primary_ip6_addr().to_string());
960  data.set_mac_addr(vintf->vm_mac().ToString());
961  data.set_mdata_ip_addr(vintf->mdata_ip_addr().to_string());
962  data.set_vxlan_id(vintf->vxlan_id());
963  if (vintf->policy_enabled()) {
964  data.set_policy("Enable");
965  } else {
966  data.set_policy("Disable");
967  }
968  data.set_flood_unknown_unicast(vintf->flood_unknown_unicast());
969 
970  string common_reason = "";
971  if (IsUveActive() == false) {
972 
973  if (!vintf->admin_state()) {
974  common_reason += "admin-down ";
975  }
976 
977  if (vintf->vn() == NULL) {
978  common_reason += "vn-null ";
979  } else if (!vintf->vn()->admin_state()) {
980  common_reason += "vn-admin-down ";
981  }
982 
983  if (vintf->vrf() == NULL) {
984  common_reason += "vrf-null ";
985  }
986 
987  if (vintf->NeedDevice()) {
988  if (vintf->os_index() == Interface::kInvalidIndex) {
989  common_reason += "no-dev ";
990  }
991 
992  if (vintf->os_oper_state() == false) {
993  common_reason += "os-state-down ";
994  }
995  } else if (vintf->NeedOsStateWithoutDevice()) {
996  if (vintf->os_oper_state() == false) {
997  common_reason += "os-state-down ";
998  }
999  }
1000 
1001  if (vintf->parent() && vintf->parent()->IsActive() == false) {
1002  common_reason += "parent-inactive ";
1003  }
1004 
1005  string total_reason = common_reason;
1006  if (!ipv4_active_) {
1007  total_reason += "ipv4_inactive ";
1008  }
1009  if (!ipv6_active_) {
1010  total_reason += "ipv6_inactive ";
1011  }
1012  if (!l2_active_) {
1013  total_reason += "l2_inactive ";
1014  }
1015  string reason = "Inactive < " + total_reason + " >";
1016  data.set_active(reason);
1017  }
1018  if (!ipv4_active_ || !ipv6_active_) {
1019  string v4_v6_common_reason = common_reason;
1020  if (vintf->layer3_forwarding() == false) {
1021  v4_v6_common_reason += "l3-disabled ";
1022  }
1023 
1024  if (!ipv4_active_) {
1025  string reason = "Ipv4 Inactive < " + v4_v6_common_reason;
1026  if (vintf->primary_ip_addr().to_ulong() == 0) {
1027  reason += "no-ipv4-addr ";
1028  }
1029  reason += " >";
1030  data.set_ipv4_active(reason);
1031  }
1032  if (!ipv6_active_) {
1033  string reason = "Ipv6 Inactive < " + v4_v6_common_reason;
1034  if (vintf->primary_ip6_addr().is_unspecified()) {
1035  reason += "no-ipv6-addr ";
1036  }
1037  reason += " >";
1038  data.set_ip6_active(reason);
1039  }
1040  }
1041 
1042  if (!l2_active_) {
1043  string l2_reason = common_reason;
1044  if (vintf->bridging() == false) {
1045  l2_reason += "l2-disabled ";
1046  }
1047  string reason = "L2 Inactive < " + l2_reason;
1048  reason += " >";
1049  data.set_l2_active(reason);
1050  }
1051 
1052  std::vector<FloatingIpSandeshList> fip_list;
1053  VmInterface::FloatingIpSet::const_iterator it =
1054  vintf->floating_ip_list().list_.begin();
1055  while (it != vintf->floating_ip_list().list_.end()) {
1056  const VmInterface::FloatingIp &ip = *it;
1057  FloatingIpSandeshList entry;
1058 
1059  entry.set_ip_addr(ip.floating_ip_.to_string());
1060  if (ip.vrf_.get()) {
1061  entry.set_vrf_name(ip.vrf_.get()->GetName());
1062  } else {
1063  entry.set_vrf_name("--ERROR--");
1064  }
1065 
1066  if (ip.Installed()) {
1067  entry.set_installed("Y");
1068  } else {
1069  entry.set_installed("N");
1070  }
1071  entry.set_fixed_ip(ip.fixed_ip_.to_string());
1072 
1073  string dir = "";
1074  switch (it->direction()) {
1076  dir = "both";
1077  break;
1078 
1080  dir = "ingress";
1081  break;
1082 
1084  dir = "egress";
1085  break;
1086 
1087  default:
1088  dir = "INVALID";
1089  break;
1090  }
1091  entry.set_direction(dir);
1092 
1093  entry.set_port_map_enabled(it->port_map_enabled());
1094  std::vector<SandeshPortMapping> pmap_list;
1096  it->src_port_map_.begin();
1097  while (pmap_it != it->src_port_map_.end()) {
1098  SandeshPortMapping pmap;
1099  pmap.set_protocol(pmap_it->first.protocol_);
1100  pmap.set_port(pmap_it->first.port_);
1101  pmap.set_nat_port(pmap_it->second);
1102  pmap_list.push_back(pmap);
1103  pmap_it++;
1104  }
1105  entry.set_port_map(pmap_list);
1106 
1107  fip_list.push_back(entry);
1108  it++;
1109  }
1110  data.set_fip_list(fip_list);
1111 
1112  std::vector<AliasIpSandeshList> aip_list;
1113  VmInterface::AliasIpSet::const_iterator a_it =
1114  vintf->alias_ip_list().list_.begin();
1115  while (a_it != vintf->alias_ip_list().list_.end()) {
1116  const VmInterface::AliasIp &ip = *a_it;
1117  AliasIpSandeshList entry;
1118  entry.set_ip_addr(ip.alias_ip_.to_string());
1119  if (ip.vrf_.get()) {
1120  entry.set_vrf_name(ip.vrf_.get()->GetName());
1121  } else {
1122  entry.set_vrf_name("--ERROR--");
1123  }
1124 
1125  if (ip.Installed()) {
1126  entry.set_installed("Y");
1127  } else {
1128  entry.set_installed("N");
1129  }
1130  aip_list.push_back(entry);
1131  a_it++;
1132  }
1133  data.set_alias_ip_list(aip_list);
1134 
1135  data.set_logical_interface_uuid(to_string(vintf->logical_interface()));
1136 
1137  // Add Service VLAN list
1138  std::vector<ServiceVlanSandeshList> vlan_list;
1139  VmInterface::ServiceVlanSet::const_iterator vlan_it =
1140  vintf->service_vlan_list().list_.begin();
1141  while (vlan_it != vintf->service_vlan_list().list_.end()) {
1142  const VmInterface::ServiceVlan *vlan = vlan_it.operator->();
1143  ServiceVlanSandeshList entry;
1144 
1145  entry.set_tag(vlan->tag_);
1146  if (vlan->vrf_.get()) {
1147  entry.set_vrf_name(vlan->vrf_.get()->GetName());
1148  } else {
1149  entry.set_vrf_name("--ERROR--");
1150  }
1151  entry.set_ip_addr(vlan->addr_.to_string());
1152  entry.set_ip6_addr(vlan->addr6_.to_string());
1153  entry.set_label(vlan->label_);
1154 
1155  if (vlan->v4_rt_installed_ || vlan->v6_rt_installed_) {
1156  entry.set_installed("Y");
1157  } else {
1158  entry.set_installed("N");
1159  }
1160  if (vlan->v4_rt_installed_) {
1161  entry.set_v4_route_installed("Y");
1162  } else {
1163  entry.set_v4_route_installed("N");
1164  }
1165  if (vlan->v6_rt_installed_) {
1166  entry.set_v6_route_installed("Y");
1167  } else {
1168  entry.set_v6_route_installed("N");
1169  }
1170  vlan_list.push_back(entry);
1171  vlan_it++;
1172  }
1173 
1174  std::vector<StaticRouteSandesh> static_route_list;
1175  VmInterface::StaticRouteSet::iterator static_rt_it =
1176  vintf->static_route_list().list_.begin();
1177  while (static_rt_it != vintf->static_route_list().list_.end()) {
1178  const VmInterface::StaticRoute &rt = *static_rt_it;
1179  StaticRouteSandesh entry;
1180  entry.set_vrf_name("");
1181  entry.set_ip_addr(rt.addr_.to_string());
1182  entry.set_prefix(rt.plen_);
1183  entry.set_communities(rt.communities_);
1184  static_rt_it++;
1185  static_route_list.push_back(entry);
1186  }
1187  data.set_static_route_list(static_route_list);
1188 
1189  std::vector<StaticRouteSandesh> aap_list;
1190  VmInterface::AllowedAddressPairSet::iterator aap_it =
1191  vintf->allowed_address_pair_list().list_.begin();
1192  while (aap_it != vintf->allowed_address_pair_list().list_.end()) {
1193  const VmInterface::AllowedAddressPair &rt = *aap_it;
1194  StaticRouteSandesh entry;
1195  entry.set_vrf_name("");
1196  entry.set_ip_addr(rt.addr_.to_string());
1197  entry.set_prefix(rt.plen_);
1198  if (rt.mac_ != MacAddress::ZeroMac()) {
1199  entry.set_mac_addr(rt.mac_.ToString());
1200  entry.set_label(rt.label_);
1201  }
1202  aap_it++;
1203  aap_list.push_back(entry);
1204  }
1205  data.set_allowed_address_pair_list(aap_list);
1206 
1207  std::vector<std::string> fixed_ip4_list;
1208  vintf->BuildIpStringList(Address::INET, &fixed_ip4_list);
1209  data.set_fixed_ip4_list(fixed_ip4_list);
1210 
1211  std::vector<std::string> fixed_ip6_list;
1212  vintf->BuildIpStringList(Address::INET6, &fixed_ip6_list);
1213  data.set_fixed_ip6_list(fixed_ip6_list);
1214 
1215  std::vector<std::string> fat_flow_list;
1216  VmInterface::FatFlowEntrySet::iterator fat_flow_it =
1217  vintf->fat_flow_list().list_.begin();
1218  while (fat_flow_it != vintf->fat_flow_list().list_.end()) {
1219  ostringstream str;
1220  str << (int)fat_flow_it->protocol << ":" << (int)fat_flow_it->port
1221  << ":" << fat_flow_it->ignore_address;
1222  fat_flow_list.push_back(str.str());
1223  fat_flow_it++;
1224  }
1225  data.set_fat_flow_list(fat_flow_list);
1226 
1227  if (vintf->fabric_port()) {
1228  data.set_fabric_port("FabricPort");
1229  } else {
1230  data.set_fabric_port("NotFabricPort");
1231  }
1232  if (vintf->need_linklocal_ip()) {
1233  data.set_alloc_linklocal_ip("LL-Enable");
1234  } else {
1235  data.set_alloc_linklocal_ip("LL-Disable");
1236  }
1237  data.set_service_vlan_list(vlan_list);
1238  data.set_analyzer_name(vintf->GetAnalyzer());
1239  data.set_config_name(vintf->cfg_name());
1240 
1241  VmInterface::TagEntrySet::const_iterator tag_it;
1242  std::vector<VmiTagData> vmi_tag_l;
1243  const VmInterface::TagEntryList &tag_l = vintf->tag_list();
1244  for (tag_it = tag_l.list_.begin(); tag_it != tag_l.list_.end();
1245  ++tag_it) {
1246  VmiTagData vmi_tag_data;
1247  if (tag_it->tag_.get()) {
1248  vmi_tag_data.set_name(tag_it->tag_->name());
1249  vmi_tag_data.set_id(tag_it->tag_->tag_id());
1250  TagEntry::PolicySetList::const_iterator aps_it =
1251  tag_it->tag_->policy_set_list().begin();
1252  std::vector<ApplicationPolicySetLink> aps_uuid_list;
1253  for(; aps_it != tag_it->tag_->policy_set_list().end();
1254  aps_it++) {
1255  std::string aps_id =
1256  UuidToString(aps_it->get()->uuid());
1257  ApplicationPolicySetLink apl;
1258  apl.set_application_policy_set(aps_id);
1259  aps_uuid_list.push_back(apl);
1260  }
1261 
1262  vmi_tag_data.set_application_policy_set_list(aps_uuid_list);
1263  vmi_tag_l.push_back(vmi_tag_data);
1264  }
1265  }
1266  data.set_vmi_tag_list(vmi_tag_l);
1267 
1268  VmInterface::SecurityGroupEntrySet::const_iterator sgit;
1269  std::vector<VmIntfSgUuid> intf_sg_uuid_l;
1270  const VmInterface::SecurityGroupEntryList &sg_uuid_l = vintf->sg_list();
1271  for (sgit = sg_uuid_l.list_.begin(); sgit != sg_uuid_l.list_.end();
1272  ++sgit) {
1273  VmIntfSgUuid sg_id;
1274  sg_id.set_sg_uuid(UuidToString(sgit->uuid_));
1275  intf_sg_uuid_l.push_back(sg_id);
1276  }
1277  data.set_sg_uuid_list(intf_sg_uuid_l);
1278 
1279  data.set_vm_name(vintf->vm_name());
1280  data.set_vm_project_uuid(UuidToString(vintf->vm_project_uuid()));
1281  data.set_local_preference(vintf->local_preference());
1282 
1283  data.set_tx_vlan_id(vintf->tx_vlan_id());
1284  data.set_rx_vlan_id(vintf->rx_vlan_id());
1285  if (vintf->parent()) {
1286  data.set_parent_interface(vintf->parent()->name());
1287  }
1288  if (vintf->subnet().to_ulong() != 0) {
1289  std::ostringstream str;
1290  str << vintf->subnet().to_string() << "/"
1291  << (int)vintf->subnet_plen();
1292  data.set_subnet(str.str());
1293  }
1294 
1295  data.set_sub_type(DeviceTypeToString(vintf->device_type()));
1296  data.set_vmi_type(VmiTypeToString(vintf->vmi_type()));
1297  data.set_vhostuser_mode(vintf->vhostuser_mode());
1298 
1299  if (vintf->vrf_assign_acl()) {
1300  std::string vrf_assign_acl;
1301  vrf_assign_acl.assign(UuidToString(vintf->vrf_assign_acl()->GetUuid()));
1302  data.set_vrf_assign_acl_uuid(vrf_assign_acl);
1303  }
1304 
1305  data.set_service_health_check_ip(
1306  vintf->service_health_check_ip().to_string());
1307  data.set_drop_new_flows(vintf->drop_new_flows());
1308 
1309  VmInterface::BridgeDomainEntrySet::const_iterator bd_it;
1310  std::vector<VmIntfBridgeDomainUuid> intf_bd_uuid_l;
1311  const VmInterface::BridgeDomainList &bd_list =
1312  vintf->bridge_domain_list();
1313  for (bd_it = bd_list.list_.begin(); bd_it != bd_list.list_.end(); ++bd_it) {
1314  VmIntfBridgeDomainUuid bd_id;
1315  bd_id.set_bridge_domain_uuid(UuidToString(bd_it->uuid_));
1316  intf_bd_uuid_l.push_back(bd_id);
1317  }
1318  data.set_bridge_domain_list(intf_bd_uuid_l);
1319 
1320  std::vector<std::string> policy_set_acl_list;
1321  FirewallPolicyList::const_iterator fw_it = vintf->fw_policy_list().begin();
1322  for(; fw_it != vintf->fw_policy_list().end(); fw_it++) {
1323  policy_set_acl_list.push_back(UuidToString(fw_it->get()->GetUuid()));
1324  }
1325  data.set_policy_set_acl_list(policy_set_acl_list);
1326 
1327  std::vector<std::string> policy_set_fwaas_list;
1328  fw_it = vintf->fwaas_fw_policy_list().begin();
1329  for(; fw_it != vintf->fwaas_fw_policy_list().end(); fw_it++) {
1330  policy_set_fwaas_list.push_back(UuidToString(fw_it->get()->GetUuid()));
1331  }
1332  data.set_policy_set_fwaas_list(policy_set_fwaas_list);
1333 
1334  std::vector<SecurityLoggingObjectLink> slo_list;
1335  UuidList::const_iterator sit = vintf->slo_list().begin();
1336  while (sit != vintf->slo_list().end()) {
1337  SecurityLoggingObjectLink slo_entry;
1338  slo_entry.set_slo_uuid(to_string(*sit));
1339  slo_list.push_back(slo_entry);
1340  ++sit;
1341  }
1342  data.set_slo_list(slo_list);
1343  data.set_si_other_end_vmi(UuidToString(vintf->si_other_end_vmi()));
1344  data.set_cfg_igmp_enable(vintf->cfg_igmp_enable());
1345  data.set_igmp_enabled(vintf->igmp_enabled());
1346  data.set_max_flows(vintf->max_flows());
1347  data.set_mac_ip_learning_enable(vintf->mac_ip_learning_enable());
1348  if (vintf->mac_ip_learning_enable()) {
1349  std::vector<LearntMacIpSandeshList> mac_ip_list;
1350  VmInterface::LearntMacIpSet::const_iterator it =
1351  vintf->learnt_mac_ip_list().list_.begin();
1352  while (it != vintf->learnt_mac_ip_list().list_.end()) {
1353  const VmInterface::LearntMacIp &mac_ip = *it;
1354  LearntMacIpSandeshList entry;
1355  entry.set_ip_addr(mac_ip.ip_.to_string());
1356  entry.set_mac_addr(mac_ip.mac_.ToString());
1357  if (mac_ip.l2_installed_) {
1358  entry.set_l2_installed("Y");
1359  } else {
1360  entry.set_l2_installed("N");
1361  }
1362  if (mac_ip.l3_installed_) {
1363  entry.set_l3_installed("Y");
1364  } else {
1365  entry.set_l3_installed("N");
1366  }
1367  mac_ip_list.push_back(entry);
1368  it++;
1369  }
1370  data.set_mac_ip_list(mac_ip_list);
1371  }
1372 
1373  break;
1374  }
1375  case Interface::INET: {
1376  data.set_type("vhost");
1377  const InetInterface *intf = static_cast<const InetInterface*>(this);
1378  if(intf->xconnect()) {
1379  data.set_physical_interface(intf->xconnect()->name());
1380  }
1381  break;
1382  }
1383  case Interface::PACKET:
1384  data.set_type("pkt");
1385  break;
1386  default:
1387  data.set_type("invalid");
1388  break;
1389  }
1390  data.set_os_ifindex(os_index());
1391  if (admin_state_) {
1392  data.set_admin_state("Enabled");
1393  } else {
1394  data.set_admin_state("Disabled");
1395  }
1396 
1397  switch (transport_) {
1398  case TRANSPORT_ETHERNET:{
1399  data.set_transport("Ethernet");
1400  break;
1401  }
1402  case TRANSPORT_SOCKET: {
1403  data.set_transport("Socket");
1404  break;
1405  }
1406  case TRANSPORT_PMD: {
1407  data.set_transport("PMD");
1408  break;
1409  }
1410  default: {
1411  data.set_transport("Unknown");
1412  break;
1413  }
1414  }
1415 }
1416 
1417 bool Interface::DBEntrySandesh(Sandesh *sresp, std::string &name) const {
1418  ItfResp *resp = static_cast<ItfResp *>(sresp);
1419 
1420  ItfSandeshData data;
1421  SetItfSandeshData(data);
1422  std::vector<ItfSandeshData> &list =
1423  const_cast<std::vector<ItfSandeshData>&>(resp->get_itf_list());
1424  list.push_back(data);
1425 
1426  return true;
1427 }
1428 
1429 void ItfReq::HandleRequest() const {
1430  AgentSandeshPtr sand(new AgentIntfSandesh(context(), get_type(),
1431  get_name(), get_uuid(),
1432  get_vn(), get_mac(),
1433  get_ipv4_address(),
1434  get_ipv6_address(),
1435  get_parent_uuid(),
1436  get_ip_active(),
1437  get_ip6_active(),
1438  get_l2_active()));
1439  sand->DoSandesh(sand);
1440 }
1441 
1443  const std::string &context) {
1444  return AgentSandeshPtr
1445  (new AgentIntfSandesh(context, args->GetString("type"),
1446  args->GetString("name"), args->GetString("uuid"),
1447  args->GetString("vn"), args->GetString("mac"),
1448  args->GetString("ipv4"), args->GetString("ipv6"),
1449  args->GetString("parent_uuid"),
1450  args->GetString("ip_active"),
1451  args->GetString("ip6_active"),
1452  args->GetString("l2_active")));
1453 }
1454 
1455 void Interface::SendTrace(const AgentDBTable *table, Trace event) const {
1456  InterfaceInfo intf_info;
1457  intf_info.set_name(name());
1458  intf_info.set_index(id_);
1459 
1460  switch(event) {
1461  case ADD:
1462  intf_info.set_op("Add");
1463  break;
1464  case DEL:
1465  intf_info.set_op("Delete");
1466  break;
1467  default:
1468  intf_info.set_op("Unknown");
1469  break;
1470  }
1472  table,
1473  intf_info);
1474 }
1475 
1477  if (family == Address::INET)
1478  return ipv4_active_;
1479  else if (family == Address::INET6)
1480  return ipv6_active_;
1481  else
1482  assert(0);
1483  return false;
1484 }
1485 
1487  if (ipv4_active() || ipv6_active() || l2_active()) {
1488  return true;
1489  }
1490  return false;
1491 }
1492 
1494  tbb::mutex::scoped_lock lock(Interface::back_ref_mutex_);
1495  std::set<IntrusiveReferrer>::const_iterator it = Interface::back_ref_set_.begin();
1496  for (; it != Interface::back_ref_set_.end(); it++) {
1497  VmInterface *vm_intf = static_cast<VmInterface *>((*it).first);
1498  if (vm_intf && vm_intf->parent()) {
1500  req.key.reset(new VmInterfaceKey(AgentKey::RESYNC, vm_intf->GetUuid(),
1501  vm_intf->name()));
1502  req.data.reset(new VmInterfaceOsOperStateData(vm_intf->
1503  os_oper_state()));
1504  const_cast<InterfaceTable *>(table)->Enqueue(&req);
1505  }
1506  }
1507 }
1508 
1510  if ((transport_ != TRANSPORT_ETHERNET) && agent->isVmwareMode()) {
1511  return true;
1512  }
1513  return false;
1514 }
1515 
1517 // Map of VMI-UUID to VmiType
1521 }
1522 
1524  InterfaceTable::VmiToVmiTypeMap::iterator it = vmi_to_vmitype_map_.find(u);
1525  if (it == vmi_to_vmitype_map_.end())
1526  return -1;
1527  return it->second;
1528 }
1529 
1531  InterfaceTable::VmiToVmiTypeMap::iterator it = vmi_to_vmitype_map_.find(u);
1532  if (it == vmi_to_vmitype_map_.end())
1533  return;
1534  vmi_to_vmitype_map_.erase(it);
1535 }
int GetVxLanId() const
Definition: vn.cc:727
EntryType At(size_t index) const
Definition: index_vector.h:32
bool OperDBDelete(DBEntry *entry, const DBRequest *req)
Definition: interface.cc:284
Interface * xconnect() const
static const MacAddress & ZeroMac()
Definition: mac_address.h:158
boost::uuids::uuid uuid_
Definition: interface.h:162
IndexVector< Interface * > index_table_
Definition: interface.h:480
boost::function< void(VmInterface *, const VnEntry *, const IpAddress &, bool)> UpdateFloatingIpFn
Definition: interface.h:325
bool is_hc_active_
Definition: interface.h:169
BridgeDomainEntrySet list_
int vxlan_id() const
void SetItfSandeshData(ItfSandeshData &data) const
Definition: interface.cc:822
const MacAddress & vm_mac() const
Type type() const
Definition: interface.h:112
std::set< IntrusiveReferrer > back_ref_set_
Definition: agent_db.h:63
void AddVmiToVmiType(const boost::uuids::uuid &u, int type)
Definition: interface.cc:1519
bool isVmwareMode() const
Definition: agent.cc:1033
Agent * agent() const
Definition: operdb_init.h:52
uint32_t l2_label_
Definition: interface.h:165
bool ip_active(Address::Family family) const
Definition: interface.cc:1476
DhcpSnoopMap dhcp_snoop_map_
Definition: interface.h:485
void set_update_floatingip_cb(UpdateFloatingIpFn fn)
Definition: interface.cc:630
void VmInterfaceWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition)
Definition: interface.cc:405
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
Definition: vrf.h:86
const boost::uuids::uuid & vm_project_uuid() const
static void CreateReq(InterfaceTable *table, const std::string &ifname, Interface::Transport transport)
Definition: interface.cc:665
bool test_mode() const
Definition: agent.h:1191
uint16_t rx_vlan_id() const
Definition: vn.h:76
std::string GetString(const std::string &key) const
const boost::uuids::uuid & GetUuid() const
Definition: interface.h:113
boost::uuids::uuid qos_config_uuid_
Definition: interface.h:275
const ServiceVlanList & service_vlan_list() const
MetaDataIp * FindIndex(uint16_t id)
Definition: metadata_ip.cc:167
void UpdateOperStateOfSubIntf(const InterfaceTable *table)
Definition: interface.cc:1493
DBTableBase * get_table() const
Definition: db_entry.cc:119
bool VmiIFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: vm.h:14
static string DeviceTypeToString(VmInterface::DeviceType type)
Definition: interface.cc:786
Ip4Address mdata_ip_addr() const
Transport transport_
Definition: interface.h:186
bool test_oper_state_
Definition: interface.h:180
bool dhcp_enabled_
Definition: interface.h:175
void Release(KeyPtr key)
const LearntMacIpList & learnt_mac_ip_list() const
VmInterface::DeviceType device_type() const
bool is_l3mh() const
Definition: agent.h:725
Family
Definition: address.h:24
bool IsDeleted() const
Definition: db_entry.h:49
uint32_t os_index() const
Definition: interface.h:130
ConfigManager * config_manager() const
Definition: agent.cc:889
std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
Definition: interface.cc:157
const AddressList & gateway_list() const
Definition: agent_param.h:191
boost::asio::ip::address IpAddress
Definition: address.h:13
static const MacAddress & vrrp_mac()
Definition: agent.h:439
Definition: vm.h:32
bool OperDBResync(DBEntry *entry, const DBRequest *req)
Definition: interface.cc:256
bool l2_active() const
Definition: interface.h:122
VmEntry * FindVmRef(const boost::uuids::uuid &uuid) const
Definition: interface.cc:301
void DeleteDhcpSnoopEntry(const std::string &ifname)
Definition: interface.cc:727
virtual void Clear()
Definition: interface.cc:413
void BuildIpStringList(Address::Family family, std::vector< std::string > *vect) const
Interface(Type type, const boost::uuids::uuid &uuid, const std::string &name, VrfEntry *vrf, bool os_oper_state, const boost::uuids::uuid &logical_router_uuid)
Definition: interface.cc:480
const UuidList & slo_list() const
bool l2_active_
Definition: interface.h:173
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
virtual Interface * AllocEntry(const InterfaceTable *table) const =0
boost::shared_ptr< ResourceKey > KeyPtr
static DBTableBase * CreateTable(DB *db, const std::string &name)
Definition: interface.cc:317
DBTableWalkRef AllocWalker(WalkFn walk_fn, WalkCompleteFn walk_complete)
Definition: db_table.cc:613
virtual ~Interface()
Definition: interface.cc:495
virtual const char * Typename() const =0
IpAddress service_health_check_ip() const
InterfaceTable(DB *db, const std::string &name)
Definition: interface.cc:59
const Ip4Address & subnet() const
const boost::uuids::uuid & si_other_end_vmi() const
std::map< const std::string, DhcpSnoopEntry >::iterator DhcpSnoopIterator
Definition: interface.h:313
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:110
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
void DelVmiToVmiType(const boost::uuids::uuid &u)
Definition: interface.cc:1530
boost::uuids::uuid uuid
VnTable * vn_table() const
Definition: agent.h:495
bool VmiIFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
bool dhcp_enabled_v6_
Definition: interface.h:176
bool OnChange(PacketInterfaceData *data)
Definition: interface.cc:698
Interface::Transport transport_
Definition: interface.h:266
void CreateVhostReq()
Definition: interface.cc:453
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:138
const boost::uuids::uuid & GetUuid() const
Definition: acl.h:112
bool metadata_ip_active_
Definition: interface.h:171
IFMapTable * table()
Definition: ifmap_node.h:29
static void CreateReq(InterfaceTable *table, const std::string &ifname, SubType sub_type, const std::string &vrf_name, const Ip4Address &addr, int plen, const Ip4Address &gw, const std::string &xconnect, const std::string &vn_name, Interface::Transport transport)
const Ip4Address & vhost_addr() const
Definition: agent_param.h:184
const int vhost_plen() const
Definition: agent_param.h:189
void FreeInterfaceId(size_t index)
Definition: interface.cc:164
const boost::uuids::uuid & GetUuid() const
Definition: vm.h:46
Agent * agent() const
Definition: interface.h:447
VrfEntry * vrf() const
Definition: interface.h:115
bool admin_state() const
DBTable::DBTableWalkRef global_config_change_walk_ref_
Definition: interface.h:479
bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
Definition: interface.cc:78
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
MirrorEntry * FindMirrorRef(const std::string &name) const
Definition: interface.cc:311
virtual bool OnChange(const InterfaceTable *table, const PhysicalInterfaceData *data)
boost::uuids::uuid logical_router_uuid_
Definition: interface.h:267
void AddDhcpSnoopEntry(const std::string &ifname, const Ip4Address &addr)
Definition: interface.cc:750
Agent * agent_
Definition: interface.h:478
const NextHop * flow_key_nh() const
Definition: interface.h:137
const Interface * GetInterface() const
Definition: metadata_ip.cc:145
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: interface.cc:1442
void ReleaseWalker(DBTableWalkRef &walk)
Definition: db_table.cc:619
uint8_t vhostuser_mode() const
MirrorTable * mirror_table() const
Definition: agent.h:525
std::string ToString() const
Definition: mac_address.cc:53
std::string name_
Definition: interface.h:245
InterfaceConstRef FindVmi(const boost::uuids::uuid &u)
Definition: interface.cc:419
const std::vector< std::string > & physical_interface_pci_addr_list() const
Definition: agent_param.h:404
void Remove(size_t index)
Definition: index_vector.h:78
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
Definition: interface.cc:1417
const std::string & fabric_vrf_name() const
Definition: agent.h:903
Definition: db.h:24
bool PhysicalInterfaceProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
bool ipv6_active_
Definition: interface.h:167
uint16_t tx_vlan_id() const
virtual ~PacketInterface()
Definition: interface.cc:646
bool L2VmInterfaceWalk(DBTablePartBase *partition, DBEntryBase *entry)
Definition: interface.cc:383
void WalkAgain(DBTableWalkRef walk)
Definition: db_table.cc:631
MetaDataIpAllocator * metadata_ip_allocator() const
Definition: agent.cc:949
void Init()
Definition: db_table.cc:387
bool IsActive() const
uint32_t local_preference() const
const SecurityGroupEntryList & sg_list() const
bool OnChange(VmInterfaceData *data)
uint8_t type
Definition: load_balance.h:109
uint8_t GetInterfaceTransport() const
Definition: agent.cc:1179
const UpdateFloatingIpFn & update_floatingip_cb() const
Definition: interface.cc:634
virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent)
void CreateVhost()
Definition: interface.cc:426
Definition: agent.h:358
bool flood_unknown_unicast() const
uint32_t label_
Definition: interface.h:164
static void Create(InterfaceTable *table, const std::string &ifname, SubType sub_type, const std::string &vrf_name, const Ip4Address &addr, int plen, const Ip4Address &gw, const std::string &xconnect, const std::string &vn_name, Interface::Transport transport)
bool LogicalInterfaceProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
uint32_t vrf_id() const
Definition: interface.cc:621
const BondChildIntfMap & getBondChildIntfMap() const
const std::string GetAnalyzer() const
virtual void SendTrace(const AgentDBTable *table, Trace event) const
Definition: interface.cc:1455
Definition: vrf.h:22
void DhcpSnoopSetConfigSeen(const std::string &ifname)
Definition: interface.cc:739
void decr_li_count()
Definition: interface.h:456
bool need_linklocal_ip() const
const FirewallPolicyList & fwaas_fw_policy_list() const
bool ipv4_active() const
Definition: interface.h:116
void AuditDhcpSnoopTable()
Definition: interface.cc:772
bool fabric_port() const
NextHopConstRef flow_key_nh_
Definition: interface.h:185
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
VnEntry * FindVnRef(const boost::uuids::uuid &uuid) const
Definition: interface.cc:306
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
bool NeedOsStateWithoutDevice() const
bool InterfaceCommonProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: interface.cc:107
DBEntry * OperDBAdd(const DBRequest *req)
Definition: interface.cc:169
bool Installed() const
Definition: vm_interface.h:171
const std::vector< std::string > & fabric_interface_name_list() const
Definition: agent.h:1133
virtual bool FindVmUuidFromMetadataIp(const IpAddress &ip, std::string *vm_ip, std::string *vm_uuid, std::string *vm_project_uuid)
Finds information about a virtual machine connected to a given vm interface with a specified link loc...
Definition: interface.cc:339
const TagEntryList & tag_list() const
tbb::mutex back_ref_mutex_
Definition: agent_db.h:60
DBOperation oper
Definition: db_table.h:42
bool layer3_forwarding() const
Definition: trace.h:220
Type type_
Definition: interface.h:161
bool cfg_igmp_enable() const
virtual void SetKey(const DBRequestKey *key)
Definition: interface.cc:614
static const std::string & NullString()
Definition: agent.h:437
bool os_oper_state() const
Definition: interface.h:132
u_int8_t & last_octet()
Definition: mac_address.h:127
const MacAddress mac_
Definition: vm_interface.h:979
bool bridging() const
boost::intrusive_ptr< const Interface > InterfaceConstRef
Definition: agent.h:51
bool PhysicalInterfaceIFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual void Clear()
Definition: agent_db.cc:215
bool NeedDefaultOsOperStateDisabled(Agent *agent) const
Definition: interface.cc:1509
#define OPER_TRACE_ENTRY(obj, table,...)
Definition: agent_db.h:234
VrfEntry * FindVrfRef(const std::string &name) const
Definition: interface.cc:295
bool admin_state_
Definition: interface.h:178
bool OnChange(InetInterfaceData *data)
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
const VnEntry * vn() const
bool policy_enabled() const
Interface::Type type_
Definition: interface.h:243
AgentDBEntry * Find(const DBEntry *key, bool ret_del)
Definition: agent_db.cc:134
virtual void Process(DBRequest &req)
Definition: agent_db.cc:231
AgentParam * params() const
Definition: agent.h:1218
int GetVmiToVmiType(const boost::uuids::uuid &u)
Definition: interface.cc:1523
const AclDBEntry * vrf_assign_acl() const
BondChildIntfMap::const_iterator BondChildIntfMapIterator
void CopyVhostData(const Agent *agent)
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
tbb::mutex dhcp_snoop_mutex_
Definition: interface.h:484
Definition: vn.h:151
bool admin_state() const
Definition: vn.h:197
bool ipv4_active_
Definition: interface.h:166
const BridgeDomainList & bridge_domain_list() const
const FatFlowList & fat_flow_list() const
VrfTable * vrf_table() const
Definition: agent.h:485
void Delete()
Definition: db_entry.cc:131
const Ip4Address & primary_ip_addr() const
const boost::uuids::uuid & logical_interface() const
PacketInterface(const std::string &name)
Definition: interface.cc:642
const StaticRouteList & static_route_list() const
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
UpdateFloatingIpFn update_floatingip_cb_
Definition: interface.h:486
const FloatingIpList & floating_ip_list() const
void SetPciIndex(Agent *agent, size_t index)
Definition: interface.cc:508
PortMap::iterator PortMapIterator
Definition: vm_interface.h:510
Definition: mpls.h:99
bool Resync(const InterfaceTable *table, const VmInterfaceData *data)
const std::string & phy_intf_display_name() const
VmiToVmiTypeMap vmi_to_vmitype_map_
Definition: interface.h:487
const std::string & vm_name() const
virtual bool OnChange(const InterfaceTable *table, const LogicalInterfaceData *data)
static void CreatePacketInterfaceNh(Agent *agent, const string &ifname)
Definition: nexthop.cc:847
AgentQosConfigTable * qos_config_table() const
Definition: agent.h:554
bool IsUveActive() const
Definition: interface.cc:1486
KeyPtr GetDBRequestKey() const
Definition: interface.cc:649
bool layer3_forwarding() const
Definition: vn.h:192
const std::string & phy_dev_display_name() const
VmInterface::VmiType vmi_type() const
static const uint32_t kInvalidIndex
Definition: interface.h:70
const Ip6Address & primary_ip6_addr() const
uint32_t max_flows() const
const uint8_t subnet_plen() const
const std::string & cfg_name() const
AgentQosConfigConstRef qos_config_
Definition: interface.h:187
bool igmp_enabled() const
const Interface * FindInterface(size_t index) const
Definition: interface.cc:323
static const uint32_t kInvalidIndex
Definition: vrf.h:88
#define LOG(_Level, _Msg)
Definition: logging.h:33
VrfEntryRef vrf_
Definition: interface.h:163
static void Create(InterfaceTable *table, const std::string &ifname, Interface::Transport transport)
Definition: interface.cc:674
bool IsActive() const
Definition: agent_db.cc:27
struct InterfaceOsParams os_params_
Definition: interface.h:188
const FirewallPolicyList & fw_policy_list() const
uint32_t vmi_count_
Definition: interface.h:491
const std::string & name() const
Definition: interface.h:114
bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
Definition: interface.cc:198
const string & GetName() const
Definition: vn.h:162
virtual bool Delete(const DBRequest *req)
Definition: interface.h:85
void decr_vmi_count()
Definition: interface.h:452
static InterfaceTable * interface_table_
Definition: interface.h:476
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:169
uint32_t li_count_
Definition: interface.h:492
bool LogicalInterfaceIFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual bool OnChange(const InterfaceTable *table, const RemotePhysicalInterfaceData *data)
const std::string & fabric_vn_name() const
Definition: agent.h:901
bool mac_ip_learning_enable() const
bool bridging() const
Definition: vn.h:191
bool dns_enabled_
Definition: interface.h:177
bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: interface.cc:90
const std::string & display_name() const
const AliasIpList & alias_ip_list() const
MetaDataIpAllocator * metadata_ip6_allocator() const
Definition: agent.cc:957
void Zero()
Definition: mac_address.h:131
virtual void GetOsParams(Agent *agent)
Definition: interface.cc:536
CommunityList communities_
Definition: vm_interface.h:699
void set_vxlan_id(int vxlan_id)
const Ip4Address GetDhcpSnoopEntry(const std::string &ifname)
Definition: interface.cc:717
const std::vector< std::string > & eth_port_list() const
Definition: agent_param.h:205
static uint32_t IpAddressToIndex(const IpT &ip)
Definition: metadata_ip.h:49
boost::uuids::uuid uuid_
Definition: interface.h:244
const Interface * parent() const
const AllowedAddressPairList & allowed_address_pair_list() const
virtual void Add()
Definition: interface.h:86
bool VmiProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: interface.cc:128
bool ipv6_active() const
Definition: interface.h:117
VmTable * vm_table() const
Definition: agent.h:490
OperDB * operdb_
Definition: interface.h:477
static void DeleteReq(InterfaceTable *table, const std::string &ifname)
Definition: interface.cc:683
void RegisterDBClients(IFMapDependencyManager *dep)
Definition: interface.cc:75
const Interface * FindInterfaceFromMetadataIp(const Ip4Address &ip) const
Finds an interface (Interface) to which a given IPv4 address belongs to.
Definition: interface.cc:371
const VmEntry * vm() const
bool NeedDevice() const
bool LogicalInterfaceIFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
ResourceManager * resource_manager() const
Definition: agent.cc:1021
void GlobalVrouterConfigChanged()
Definition: interface.cc:409
size_t id_
Definition: interface.h:174
bool drop_new_flows() const
size_t InsertAtIndex(uint32_t index, EntryType entry)
Definition: index_vector.h:54
static string VmiTypeToString(VmInterface::VmiType type)
Definition: interface.cc:801