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