OpenSDN source code
vm_interface_utils.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <cmn/agent_cmn.h>
7 #include <init/agent_param.h>
8 #include <base/address_util.h>
9 #include <oper/operdb_init.h>
10 #include <oper/route_common.h>
11 #include <oper/vm.h>
12 #include <oper/vn.h>
13 #include <oper/vrf.h>
14 #include <oper/nexthop.h>
15 #include <oper/mpls.h>
16 #include <oper/mirror_table.h>
17 #include <oper/metadata_ip.h>
18 #include <oper/interface_common.h>
19 #include <oper/health_check.h>
20 #include <oper/vrf_assign.h>
21 #include <oper/vxlan.h>
22 #include <oper/oper_dhcp_options.h>
24 #include <oper/global_vrouter.h>
25 #include <oper/qos_config.h>
26 #include <oper/bridge_domain.h>
27 #include <oper/sg.h>
28 #include <oper/bgp_as_service.h>
29 
30 #include <filter/acl.h>
36 
39 
40 using namespace std;
41 using namespace boost::uuids;
42 using namespace autogen;
43 
44 static IpAddress ipv4_empty_addr = IpAddress::from_string("0.0.0.0");
45 static IpAddress ipv6_empty_addr = IpAddress::from_string("0::0");
46 static IpAddress ipv4_max_addr = IpAddress::from_string("255.255.255.255");
48  IpAddress::from_string("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
49 
51 // Routines to manage VmiToPhysicalDeviceVnTree
54 (const boost::uuids::uuid &dev, const boost::uuids::uuid &vn) :
55  dev_(dev), vn_(vn) {
56 }
57 
59 }
60 
62  boost::uuids::uuid &dev,
64  IFMapNode *vn_node) {
65  VmiToPhysicalDeviceVnTree::iterator iter =
67  if (iter == vmi_to_physical_device_vn_tree_.end()) {
69  (make_pair(vmi,VmiToPhysicalDeviceVnData(nil_uuid(), nil_uuid())));
70  iter = vmi_to_physical_device_vn_tree_.find(vmi);
71  }
72 
73  if (iter->second.dev_ != dev || iter->second.vn_ != vn) {
75  (vmi, iter->second.dev_, iter->second.vn_);
76  }
77 
78  iter->second.dev_ = dev;
79  iter->second.vn_ = vn;
80  agent()->physical_device_vn_table()->AddConfigEntry(vmi, dev, vn);
81 }
82 
84  VmiToPhysicalDeviceVnTree::iterator iter =
86  if (iter == vmi_to_physical_device_vn_tree_.end())
87  return;
88 
90  (vmi, iter->second.dev_, iter->second.vn_);
92 }
93 
95 // VM Port active status related methods
97 // Does the VMInterface need a physical device to be present
99  bool ret = true;
100 
101  if (device_type_ == TOR)
102  ret = false;
103 
105  ret = false;
106 
107  if (vmi_type_ != VHOST && subnet_.is_unspecified() == false) {
108  ret = false;
109  }
110 
112  ret = false;
113  }
114 
116  ret = false;
117  } else {
118  // Sanity check. rx_vlan_id is set, make sure tx_vlan_id is also set
120  }
121 
122  return ret;
123 }
124 
126  /* For TRANSPORT_PMD (in dpdk mode) interfaces, the link state is updated
127  * as part of netlink message sent by vrouter to agent. This state is
128  * updated in os_oper_state_ field */
129  if (transport_ == TRANSPORT_PMD) {
130  return true;
131  }
132  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
133  if (table) {
134  return NeedDefaultOsOperStateDisabled(table->agent());
135  }
136  return false;
137 }
138 
142  return;
143  }
144 
147  /* In VmWare mode, the default os_oper_state of VMI is false. It needs to be
148  * explicitly enabled via REST request to agent. This needs to be done
149  * only for interfaces which are not of transport_ TRANSPORT_ETHERNET */
151  os_params_.os_oper_state_ = true;
152  }
153 }
154 
155 // A VM Interface is L3 active under following conditions,
156 // - If interface is deleted, it is inactive
157 // - VN, VRF are set
158 // - If sub_interface VMIs, parent_ should be set
159 // (We dont track parent_ and activate sub-interfaces. So, we only check
160 // parent_ is present and not necessarily active)
161 // - For non-VMWARE hypervisors,
162 // The tap interface must be created. This is verified by os_index_
163 // - MAC address set for the interface
164 bool VmInterface::IsActive() const {
165  if (IsDeleted()) {
166  return false;
167  }
168 
169  if (!admin_state_) {
170  return false;
171  }
172 
173  // If sub_interface VMIs, parent_vmi_ should be set
174  // (We dont track parent_ and activate sub-interfaces. So, we only check
175  // paremt_vmi is present and not necessarily active)
176  // Check if parent is not active set the SubInterface also not active
177  const VmInterface *parentIntf = static_cast<const VmInterface *>(parent());
178  if (device_type_ == VM_VLAN_ON_VMI) {
179  if (parentIntf == NULL)
180  return false;
181  else if (parentIntf->IsActive() == false) {
182  return false;
183  }
184  }
185 
189  parent_.get() == NULL)
190  return false;
191  }
192 
193  if (vmi_type_ == VHOST) {
194  //In case of vhost interface, upon interface
195  //addition we dont have corresponding VN, hence
196  //ignore VN name check for ip active
197  if (vrf_.get() == NULL) {
198  return false;
199  }
200  } else if ((vn_.get() == NULL) || (vrf_.get() == NULL)) {
201  return false;
202  }
203 
204  if (vn_.get() && !vn_.get()->admin_state()) {
205  return false;
206  }
207 
208  if (NeedOsStateWithoutDevice() && os_oper_state() == false) {
209  VnswInterfaceListener *vnswif =
211  bool link_status = vnswif->IsHostLinkStateUp(name());
212  if ((transport_ == TRANSPORT_PMD) && link_status &&
213  (os_index() != Interface::kInvalidIndex) && (!agent()->test_mode())) {
215  req.key.reset(new VmInterfaceKey(AgentKey::RESYNC, GetUuid(),
216  name()));
217  req.data.reset(new VmInterfaceOsOperStateData(link_status));
218  agent()->interface_table()->Enqueue(&req);
219  return true;
220  }
221  return false;
222  }
223 
224  if (NeedDevice() == false) {
225  return true;
226  }
227 
228  if (os_index() == kInvalidIndex)
229  return false;
230 
231  if (os_oper_state() == false)
232  return false;
233 
234  return mac_set_;
235 }
236 
238  if (vmi_type_ == VHOST) {
239  return IsActive();
240  }
241 
242  if (!layer3_forwarding()) {
243  return false;
244  }
245 
246  if (primary_ip6_addr_.is_unspecified()) {
247  if (subnet_.is_unspecified() && primary_ip_addr_.to_ulong() == 0) {
248  return false;
249  }
250 
251  if (subnet_.is_unspecified() == false && parent_ == NULL) {
252  return false;
253  }
254  }
255 
256  return IsActive();
257 }
258 
260  if (!bridging()) {
261  return false;
262  }
263 
264  return IsActive();
265 }
266 
268  if (vmi_type_ == VHOST) {
269  return IsActive();
270  }
271 
272  if (!layer3_forwarding()) {
273  return false;
274  }
275 
276  if (subnet_.is_unspecified() && primary_ip_addr_.to_ulong() == 0) {
277  return false;
278  }
279 
280  if (subnet_.is_unspecified() == false && parent_ == NULL) {
281  return false;
282  }
283 
284  if (!is_hc_active_) {
285  return false;
286  }
287 
288  return IsActive();
289 }
290 
292  if (vmi_type_ == VHOST) {
293  return IsActive();
294  }
295 
296  if (!layer3_forwarding() || (primary_ip6_addr_.is_unspecified())) {
297  return false;
298  }
299 
300  if (!is_hc_active_) {
301  return false;
302  }
303 
304  return IsActive();
305 }
306 
308  if (vmi_type_ == VHOST) {
309  return IsActive();
310  }
311 
312  if (!bridging()) {
313  return false;
314  }
315 
316  if (!is_hc_active_) {
317  return false;
318  }
319 
320  return IsActive();
321 }
322 
324 // Path preference utility methods
326 // Set path-preference information for the route
328  const IpAddress &dependent_ip) const {
329  pref->set_ecmp(ecmp);
330  if (local_preference_ != 0) {
331  pref->set_static_preference(true);
333  } else if (ecmp == true) {
335  }
336  pref->set_dependent_ip(dependent_ip);
337  pref->set_vrf(vrf()->GetName());
338 }
339 
341  const IpAddress &service_ip) const {
342 
343  bool ecmp_mode = false;
344  IpAddress dependent_ip;
345 
346  //Logic for setting ecmp and tracking IP on Service chain route
347  //Service vlan route can be active when interface is either
348  //IPV4 active or IPV6 active, hence we have to consider both
349  //IPV6 and IPV4 IP
350  //If Service vlan is for Ipv4 route, then priority is as below
351  //1> Service IP for v4
352  //3> Primary IP for v4
353  if (service_ip.is_v4()) {
354  if (service_ip_ != Ip4Address(0)) {
355  dependent_ip = service_ip_;
356  ecmp_mode = service_ip_ecmp_;
357  } else {
358  dependent_ip = primary_ip_addr_;
359  ecmp_mode = ecmp_;
360  }
361  }
362 
363  //If Service vlan is for Ipv6 route, then priority is as below
364  //1> Service IP for v6
365  //3> Primary IP for v6
366  if (service_ip.is_v6()) {
367  if (service_ip6_ != Ip6Address()) {
368  dependent_ip = service_ip6_;
369  ecmp_mode = service_ip_ecmp6_;
370  } else {
371  dependent_ip = primary_ip6_addr_;
372  ecmp_mode = ecmp6_;
373  }
374  }
375 
376  pref->set_ecmp(ecmp_mode);
377  if (local_preference_ != 0) {
378  pref->set_static_preference(true);
380  } else if (ecmp_mode == true) {
382  }
383 
384  pref->set_dependent_ip(dependent_ip);
385  pref->set_vrf(vrf()->GetName());
386 }
387 
389  if (ecmp_load_balance_.use_global_vrouter() == false)
391  return ecmp_load_balance.Copy(agent()->oper_db()->global_vrouter()->
393 }
394 
396 // Route utility methods
398 
399 // Add EVPN route of type <ip, mac>
401  const MacAddress &mac,
402  const IpAddress &dependent_ip) const {
403  assert(peer_.get());
404  EvpnAgentRouteTable *table =
405  static_cast<EvpnAgentRouteTable *>(vrf_->GetEvpnRouteTable());
406 
407  SecurityGroupList sg_id_list;
408  CopySgIdList(&sg_id_list);
409 
412 
413  PathPreference path_preference;
414  SetPathPreference(&path_preference, false, dependent_ip);
415 
416  uint32_t label = l2_label_;
417  if (pbb_interface()) {
418  label = GetPbbLabel();
419  }
420 
421  std::string vn_name = Agent::NullString();
422  if (vn() != NULL) {
423  vn_name = vn()->GetName();
424  }
425 
426  table->AddLocalVmRoute(peer_.get(), vrf_->GetName(), mac, this, ip,
427  label, vn_name, sg_id_list,
428  tag_list, path_preference,
430 }
431 
432 // Delete EVPN route
434  uint32_t ethernet_tag,
435  const IpAddress &ip,
436  const MacAddress &mac) const {
437  EvpnAgentRouteTable *table =
438  static_cast<EvpnAgentRouteTable *>(vrf->GetEvpnRouteTable());
439  if (table == NULL)
440  return;
441 
442  table->DelLocalVmRoute(peer_.get(), vrf->GetName(), mac, this,
443  ip, ethernet_tag);
444 }
445 
446 //Add a route for VM port
447 //If ECMP route, add new composite NH and mpls label for same
448 void VmInterface::AddRoute(const std::string &vrf_name, const IpAddress &addr,
449  uint32_t plen, const std::string &dest_vn,
450  bool force_policy, bool ecmp, bool is_local,
451  bool is_health_check_service,
452  const IpAddress &service_ip,
453  const IpAddress &dependent_rt,
454  const CommunityList &communities, uint32_t label,
455  const std::string &intf_route_type,
456  bool is_learnt_route) {
457 
458  SecurityGroupList sg_id_list;
459  CopySgIdList(&sg_id_list);
460 
463 
464  PathPreference path_preference;
465  SetPathPreference(&path_preference, ecmp, dependent_rt);
466 
467  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
468  bool native_encap = false;
469  VrfEntry *vrf = table->FindVrfRef(vrf_name);
470  if (addr.is_v4() &&
471  vrf && vrf->forwarding_vrf() == table->agent()->fabric_vrf()) {
472  native_encap = true;
473  }
474 
475  VnListType vn_list;
476  vn_list.insert(dest_vn);
480  (peer_.get(), vrf_name, addr, plen, GetUuid(), vn_list, label,
481  sg_id_list, tag_list, communities, force_policy, path_preference,
482  service_ip, ecmp_load_balance, is_local, is_health_check_service,
483  name(), native_encap, intf_route_type, is_learnt_route);
484  return;
485 }
486 
487 void VmInterface::DeleteRoute(const std::string &vrf_name,
488  const IpAddress &addr, uint32_t plen) {
490  return;
491 }
492 
494 // Utility methods
496 // DHCP options applicable to the Interface
498 (std::vector<autogen::DhcpOptionType> *options) const {
499  if (oper_dhcp_options().are_dhcp_options_set()) {
501  return true;
502  }
503 
504  return false;
505 }
506 
507 // DHCP options applicable to the Subnet to which the interface belongs
509 (std::vector<autogen::DhcpOptionType> *options, bool ipv6) const {
510  if (vn()) {
511  const std::vector<VnIpam> &vn_ipam = vn()->GetVnIpam();
512  uint32_t index;
513  for (index = 0; index < vn_ipam.size(); ++index) {
514  if (!ipv6 && vn_ipam[index].IsSubnetMember(primary_ip_addr())) {
515  break;
516  }
517  if (ipv6 && vn_ipam[index].IsSubnetMember(primary_ip6_addr())) {
518  break;
519  }
520  }
521  if (index < vn_ipam.size() &&
522  vn_ipam[index].oper_dhcp_options.are_dhcp_options_set()) {
523  *options = vn_ipam[index].oper_dhcp_options.dhcp_options();
524  return true;
525  }
526  }
527 
528  return false;
529 }
530 
531 // DHCP options applicable to the Ipam to which the interface belongs
533 (std::vector<autogen::DhcpOptionType> *options, bool ipv6) const {
534  if (vn()) {
535  std::string ipam_name;
536  autogen::IpamType ipam_type;
537  if (!ipv6 &&
538  vn()->GetIpamData(primary_ip_addr(), &ipam_name, &ipam_type)) {
539  *options = ipam_type.dhcp_option_list.dhcp_option;
540  return true;
541  }
542  if (ipv6 &&
543  vn()->GetIpamData(primary_ip6_addr(), &ipam_name, &ipam_type)) {
544  *options = ipam_type.dhcp_option_list.dhcp_option;
545  return true;
546  }
547  }
548 
549  return false;
550 }
551 
552 const MacAddress&
553 VmInterface::GetIpMac(const IpAddress &ip, uint8_t plen) const {
554  AllowedAddressPairSet::const_iterator it =
556  while (it != allowed_address_pair_list_.list_.end()) {
557  if (it->addr_ == ip && it->plen_ == plen &&
558  it->mac_ != MacAddress::kZeroMac) {
559  return it->mac_;
560  }
561  it++;
562  }
563  LearntMacIpSet::const_iterator mac_ip_it =
564  learnt_mac_ip_list_.list_.begin();
565  while (mac_ip_it != learnt_mac_ip_list_.list_.end()) {
566  if (mac_ip_it->ip_ == ip &&
567  mac_ip_it->mac_ != MacAddress::kZeroMac) {
568  return mac_ip_it->mac_;
569  }
570  mac_ip_it++;
571  }
572  return vm_mac_;
573 }
574 
575 /*
576  * Check if the passed IP is in the AAP IP list on this interface;
577  * If so, return true, else return false
578  */
579 bool
580 VmInterface::MatchAapIp(const IpAddress &ip, uint8_t plen) const {
581  AllowedAddressPairSet::const_iterator it =
583  while (it != allowed_address_pair_list_.list_.end()) {
584  if (it->addr_ == ip && it->plen_ == plen) {
585  return true;
586  }
587  it++;
588  }
589  return false;
590 }
591 
593  // do not continue if the interface is inactive or if the VRF is deleted
594  if (IsActive() == false || vrf_->IsDeleted()) {
595  return false;
596  }
597 
598  //Get the instance ip route and its corresponding traffic seen status
599  InetUnicastRouteKey rt_key(peer_.get(), vrf_->GetName(),
600  primary_ip_addr_, 32);
601  const InetUnicastRouteEntry *rt = static_cast<const InetUnicastRouteEntry *>
602  (vrf_->GetInet4UnicastRouteTable()->FindActiveEntry(&rt_key));
603  if (!rt) {
604  return false;
605  }
606 
607  if (rt->FindPath(peer_.get()) == NULL) {
608  return false;
609  }
610 
611  return rt->FindPath(peer_.get())->path_preference().wait_for_traffic();
612 }
613 
615  IpAddress ip;
616  if (vm_ip.is_v4()) {
617  ip = Ip4Address(0);
618  } else if (vm_ip.is_v6()) {
619  ip = Ip6Address();
620  }
621  if (vn_.get() == NULL) {
622  return ip;
623  }
624 
625  const VnIpam *ipam = NULL;
626  if (subnet_.is_unspecified()) {
627  ipam = vn_->GetIpam(vm_ip);
628  } else {
629  ipam = vn_->GetIpam(subnet_);
630  }
631 
632  if (ipam) {
633  if ((vm_ip.is_v4() && ipam->dns_server.is_v4()) ||
634  (vm_ip.is_v6() && ipam->dns_server.is_v6())) {
635  return ipam->dns_server;
636  }
637  }
638  return ip;
639 }
640 
642  IpAddress ip;
643  if (vn_.get() == NULL) {
644  return ip;
645  }
646 
647  const VnIpam *ipam = NULL;
648  if (subnet_.is_unspecified()) {
649  ipam = vn_->GetIpam(vm_ip);
650  } else {
651  ipam = vn_->GetIpam(subnet_);
652  }
653 
654  if (ipam) {
655  if ((vm_ip.is_v4() && ipam->default_gw.is_v4()) ||
656  (vm_ip.is_v6() && ipam->default_gw.is_v6())) {
657  return ipam->default_gw;
658  }
659  }
660  return ip;
661 }
662 
663 // Copy the SG List for VM Interface. Used to add route for interface
665  SecurityGroupEntrySet::const_iterator it;
666  for (it = sg_list_.list_.begin(); it != sg_list_.list_.end(); ++it) {
667  if (it->del_pending_)
668  continue;
669  if (it->sg_.get() == NULL)
670  continue;
671  sg_id_list->push_back(it->sg_->GetSgId());
672  }
673 }
674 
675 uint32_t VmInterface::GetServiceVlanLabel(const VrfEntry *vrf) const {
676  ServiceVlanSet::const_iterator it = service_vlan_list_.list_.begin();
677  while (it != service_vlan_list_.list_.end()) {
678  if (it->vrf_.get() == vrf) {
679  return it->label_;
680  }
681  it++;
682  }
683  return 0;
684 }
685 
686 const VrfEntry* VmInterface::GetServiceVlanVrf(uint16_t vlan_tag) const {
687  ServiceVlanSet::const_iterator it = service_vlan_list_.list_.begin();
688  while (it != service_vlan_list_.list_.end()) {
689  if (it->tag_ == vlan_tag) {
690  return it->vrf_.get();
691  }
692  it++;
693  }
694  return NULL;
695 }
696 
698  if (family == Address::INET) {
699  return floating_ip_list_.v4_count_ > 0;
700  } else {
701  return floating_ip_list_.v6_count_ > 0;
702  }
703 }
704 
706  return floating_ip_list_.list_.size() != 0;
707 }
708 
709 bool VmInterface::IsFloatingIp(const IpAddress &ip) const {
710  VmInterface::FloatingIpSet::const_iterator it =
711  floating_ip_list_.list_.begin();
712  while(it != floating_ip_list_.list_.end()) {
713  if ((*it).floating_ip_ == ip) {
714  return true;
715  }
716  it++;
717  }
718  return false;
719 }
720 
722  // Look for matching Alias IP
723  VmInterface::AliasIpSet::const_iterator it =
724  alias_ip_list_.list_.begin();
725  for (; it != alias_ip_list_.list_.end(); ++it) {
726  if (it->vrf_.get() == NULL) {
727  continue;
728  }
729 
730  if (ip == it->alias_ip_) {
731  return it->vrf_.get();
732  }
733  }
734  return NULL;
735 }
736 
738  std::pair<HealthCheckInstanceSet::iterator, bool> ret;
739  ret = hc_instance_set_.insert(hc_inst);
740  assert(ret.second);
741 }
742 
744  //[CEM-29104 for reference]If service_type of HealthCheck instance is "vn-ip-list"
745  //while creating the BFD HealthCheck and if it is modified before deleting
746  //the HealthCheck object, then object hc_inst will not present in hc_instance_set
747  //and assert will fail while erasing hc_inst from hc_instance_set. So,
748  //added a check to see if hc_inst is present in the set.
749  if(hc_instance_set_.find(hc_inst) != hc_instance_set_.end()) {
750  std::size_t ret = hc_instance_set_.erase(hc_inst);
751  assert(ret != 0);
752  }
753 }
754 
757  return hc_instance_set_;
758 }
759 
761  return hc_instance_set_.size() != 0;
762 }
763 
764 // Check if the interface requires to resync the health check service instance
765 // Resync will be applied for healthcheck types BFD or Segment.
767 {
768  if (!IsHealthCheckEnabled() || !is_hc_active()) {
769  return;
770  }
771 
772  HealthCheckInstanceSet::const_iterator it = hc_instance_set_.begin();
773  while (it != hc_instance_set_.end()) {
774  const HealthCheckInstanceBase *hc_instance = *it;
775  it++;
776  HealthCheckService *hc_service = hc_instance->service();
777  if (hc_service == NULL)
778  continue;
779 
780  // resync will be applied healthcheck type is either BFD or Segment.
782  hc_service->health_check_type();
783  if (type != HealthCheckService::BFD &&
785  continue;
786  }
787 
788  // if either source_ip or destination_ip unspecified,
789  // resync the healtcheckservice
790  if ((hc_instance->destination_ip().is_unspecified() == false) &&
791  (hc_instance->get_source_ip().is_unspecified() == false)) {
792  continue;
793  }
794  hc_service->ResyncHealthCheckInterface(hc_service, this);
795  }
796 }
797 
798 const string VmInterface::GetAnalyzer() const {
799  if (mirror_entry()) {
800  return mirror_entry()->GetAnalyzerName();
801  } else {
802  return std::string();
803  }
804 }
805 
806 const Peer *VmInterface::peer() const {
807  return peer_.get();
808 }
809 
810 bool VmInterface::IsFatFlowPortBased(uint8_t protocol, uint16_t port,
811  FatFlowIgnoreAddressType *ignore_addr) const {
812 
813  FatFlowEntrySet::iterator start = fat_flow_list_.list_.lower_bound(
814  FatFlowEntry(protocol, port,
817  FatFlowEntrySet::iterator end = fat_flow_list_.list_.upper_bound(
818  FatFlowEntry(protocol, port,
821 
822  if (start != fat_flow_list_.list_.end()) {
823  while (start != end) {
824  if ((start->protocol == protocol) && (start->port == port) &&
825  (start->prefix_aggregate == AGGREGATE_NONE)) {
826  *ignore_addr = start->ignore_address;
827  return true;
828  }
829  start++;
830  }
831  }
832  return false;
833 }
834 
835 bool VmInterface::MatchSrcPrefixPort(uint8_t protocol, uint16_t port,
836  IpAddress *src_ip,
837  FatFlowIgnoreAddressType *ignore_addr) const
838 {
839  FatFlowPrefixAggregateType prefix_type, max_prefix_type;
840  Ip4Address Ipv4_subnet, Ipv4_ret_subnet;
841  Ip6Address Ipv6_subnet, Ipv6_ret_subnet;
842  uint8_t max_mask, max_plen;
843  const FatFlowEntry *match_ffe = NULL;
844 
845  *ignore_addr = VmInterface::IGNORE_NONE;
846 
847  if (src_ip->is_v4()) {
848  prefix_type = AGGREGATE_SRC_IPV4;
849  // set max_prefixtype to src_dst_ipv4 so that we can do LPM on src prefix
850  max_prefix_type = AGGREGATE_SRC_DST_IPV4;
851  Ipv4_subnet = Address::GetIp4SubnetAddress(src_ip->to_v4(),
853  max_mask = 32;
854  max_plen = 32;
855  } else {
856  prefix_type = AGGREGATE_SRC_IPV6;
857  max_prefix_type = AGGREGATE_SRC_DST_IPV6;
858  Ipv6_subnet = Address::GetIp6SubnetAddress(src_ip->to_v6(),
860  max_mask = 128;
861  max_plen = 128;
862  }
863 
864  const FatFlowEntry lbffe = FatFlowEntry(protocol, port, "destination",
865  prefix_type,
866  (src_ip->is_v4()?
867  IpAddress(Ipv4_subnet):
868  IpAddress(Ipv6_subnet)),
871  (src_ip->is_v4()?
873  ),
874  0, 0);
875 
876  FatFlowEntrySet::iterator start = fat_flow_list_.list_.lower_bound(lbffe);
877 
878  const FatFlowEntry ubffe =
879  FatFlowEntry(protocol, port, "none",
880  max_prefix_type,
881  *src_ip, max_mask, max_plen,
882  (src_ip->is_v4()?
884  ),
885  max_mask, max_plen);
886 
887  FatFlowEntrySet::iterator end = fat_flow_list_.list_.upper_bound(ubffe);
888 
889  if ((start != fat_flow_list_.list_.end()) &&
890  (start->protocol == protocol) && (start->port == port)) {
891  while (start != end) {
892  if (src_ip->is_v4() && start->src_prefix.is_v4() &&
893  IsIp4SubnetMember(src_ip->to_v4(), start->src_prefix.to_v4(),
894  start->src_prefix_mask) &&
895  (start->protocol == protocol) && (start->port == port)) {
896  if ((!match_ffe) ||
897  (start->src_prefix_mask > match_ffe->src_prefix_mask)) {
898  match_ffe = &(*start);
899  }
900  } else if (src_ip->is_v6() && start->src_prefix.is_v6() &&
901  IsIp6SubnetMember(src_ip->to_v6(), start->src_prefix.to_v6(),
902  start->src_prefix_mask) &&
903  (start->protocol == protocol) && (start->port == port)) {
904  if ((!match_ffe) ||
905  (start->src_prefix_mask > match_ffe->src_prefix_mask)) {
906  match_ffe = &(*start);
907  }
908  }
909  start++;
910  }
911  }
912  if (match_ffe && (match_ffe->prefix_aggregate == prefix_type)) {
913  if (src_ip->is_v4()) {
914  Ipv4_ret_subnet = Address::GetIp4SubnetAddress(src_ip->to_v4(),
915  match_ffe->src_aggregate_plen);
916  *src_ip = IpAddress(Ipv4_ret_subnet);
917  *ignore_addr = match_ffe->ignore_address;
918  } else {
919  Ipv6_ret_subnet = Address::GetIp6SubnetAddress(src_ip->to_v6(),
920  match_ffe->src_aggregate_plen);
921  *src_ip = IpAddress(Ipv6_ret_subnet);
922  *ignore_addr = match_ffe->ignore_address;
923  }
924  return true;
925  }
926  return false;
927 }
928 
929 bool VmInterface::MatchSrcPrefixRule(uint8_t protocol, uint16_t *sport,
930  uint16_t *dport, bool *same_port_num,
931  IpAddress *SrcIP,
932  FatFlowIgnoreAddressType *ignore_addr) const
933 {
934  if ((*sport) < (*dport)) {
935  if (MatchSrcPrefixPort(protocol, *sport, SrcIP, ignore_addr)) {
936  *dport = 0;
937  return true;
938  }
939  if (MatchSrcPrefixPort(protocol, *dport, SrcIP, ignore_addr)) {
940  *sport = 0;
941  return true;
942  }
943  } else {
944  if (MatchSrcPrefixPort(protocol, *dport, SrcIP, ignore_addr)) {
945  if ((*sport) == (*dport)) {
946  *same_port_num = true;
947  }
948  *sport = 0;
949  return true;
950  }
951  if (MatchSrcPrefixPort(protocol, *sport, SrcIP, ignore_addr)) {
952  *dport = 0;
953  return true;
954  }
955  }
956  if (MatchSrcPrefixPort(protocol, 0, SrcIP, ignore_addr)) {
957  *sport = *dport = 0;
958  return true;
959  }
960  return false;
961 }
962 
963 bool VmInterface::MatchDstPrefixPort(uint8_t protocol, uint16_t port,
964  IpAddress *dst_ip,
965  FatFlowIgnoreAddressType *ignore_addr) const
966 {
967  FatFlowPrefixAggregateType prefix_type;
968  Ip4Address Ipv4_subnet, Ipv4_ret_subnet;
969  Ip6Address Ipv6_subnet, Ipv6_ret_subnet;
970  uint8_t max_mask, max_plen;
971  const FatFlowEntry *match_ffe = NULL;
972 
973  *ignore_addr = VmInterface::IGNORE_NONE;
974 
975  if (dst_ip->is_v4()) {
976  prefix_type = AGGREGATE_DST_IPV4;
977  Ipv4_subnet = Address::GetIp4SubnetAddress(dst_ip->to_v4(),
979  max_mask = 32;
980  max_plen = 32;
981  } else {
982  prefix_type = AGGREGATE_DST_IPV6;
983  Ipv6_subnet = Address::GetIp6SubnetAddress(dst_ip->to_v6(),
985  max_mask = 128;
986  max_plen = 128;
987  }
988 
989  const FatFlowEntry lbffe =
990  FatFlowEntry(protocol, port, "source", prefix_type,
991  (dst_ip->is_v4()?
994  ), 0, 0,
995  (dst_ip->is_v4()?
996  IpAddress(Ipv4_subnet):
997  IpAddress(Ipv6_subnet)),
1000 
1001  FatFlowEntrySet::iterator start = fat_flow_list_.list_.lower_bound(lbffe);
1002 
1003  const FatFlowEntry ubffe = FatFlowEntry(protocol, port, "none",
1004  prefix_type,
1005  (dst_ip->is_v4()?
1008  ), 0, 0,
1009  *dst_ip, max_mask, max_plen);
1010 
1011  FatFlowEntrySet::iterator end = fat_flow_list_.list_.upper_bound(ubffe);
1012 
1013  if ((start != fat_flow_list_.list_.end()) &&
1014  (start->protocol == protocol) && (start->port == port)) {
1015  while (start != end) {
1016  if (dst_ip->is_v4() && start->dst_prefix.is_v4() &&
1017  IsIp4SubnetMember(dst_ip->to_v4(), start->dst_prefix.to_v4(),
1018  start->dst_prefix_mask) &&
1019  (start->protocol == protocol) && (start->port == port)) {
1020  if ((!match_ffe) ||
1021  (start->dst_prefix_mask > match_ffe->dst_prefix_mask)) {
1022  match_ffe = &(*start);
1023  }
1024  } else if (dst_ip->is_v6() && start->dst_prefix.is_v6() &&
1025  IsIp6SubnetMember(dst_ip->to_v6(), start->dst_prefix.to_v6(),
1026  start->dst_prefix_mask) &&
1027  (start->protocol == protocol) && (start->port == port)) {
1028  if ((!match_ffe) ||
1029  (start->dst_prefix_mask > match_ffe->dst_prefix_mask)) {
1030  match_ffe = &(*start);
1031  }
1032  }
1033  start++;
1034  }
1035  }
1036  if (match_ffe && (match_ffe->prefix_aggregate == prefix_type)) {
1037  if (dst_ip->is_v4()) {
1038  Ipv4_ret_subnet = Address::GetIp4SubnetAddress(dst_ip->to_v4(),
1039  match_ffe->dst_aggregate_plen);
1040  *dst_ip = IpAddress(Ipv4_ret_subnet);
1041  *ignore_addr = match_ffe->ignore_address;
1042  } else {
1043  Ipv6_ret_subnet = Address::GetIp6SubnetAddress(dst_ip->to_v6(),
1044  match_ffe->dst_aggregate_plen);
1045  *dst_ip = IpAddress(Ipv6_ret_subnet);
1046  *ignore_addr = match_ffe->ignore_address;
1047  }
1048  return true;
1049  }
1050  return false;
1051 }
1052 
1053 
1054 bool VmInterface::MatchDstPrefixRule(uint8_t protocol, uint16_t *sport,
1055  uint16_t *dport, bool *same_port_num,
1056  IpAddress *DstIP,
1057  FatFlowIgnoreAddressType *ignore_addr) const
1058 {
1059  if ((*sport) < (*dport)) {
1060  if (MatchDstPrefixPort(protocol, *sport, DstIP, ignore_addr)) {
1061  *dport = 0;
1062  return true;
1063  }
1064  if (MatchDstPrefixPort(protocol, *dport, DstIP, ignore_addr)) {
1065  *sport = 0;
1066  return true;
1067  }
1068  } else {
1069  if (MatchDstPrefixPort(protocol, *dport, DstIP, ignore_addr)) {
1070  if ((*sport) == (*dport)) {
1071  *same_port_num = true;
1072  }
1073  *sport = 0;
1074  return true;
1075  }
1076  if (MatchDstPrefixPort(protocol, *sport, DstIP, ignore_addr)) {
1077  *dport = 0;
1078  return true;
1079  }
1080  }
1081  if (MatchDstPrefixPort(protocol, 0, DstIP, ignore_addr)) {
1082  *sport = *dport = 0;
1083  return true;
1084  }
1085  return false;
1086 }
1087 
1088 
1089 bool VmInterface::MatchSrcDstPrefixPort(uint8_t protocol, uint16_t port,
1090  IpAddress *src_ip,
1091  IpAddress *dst_ip) const
1092 {
1093  FatFlowPrefixAggregateType prefix_type;
1094  Ip4Address Ipv4_src_subnet, Ipv4_src_ret_subnet;
1095  Ip4Address Ipv4_dst_subnet, Ipv4_dst_ret_subnet;
1096  Ip6Address Ipv6_src_subnet, Ipv6_src_ret_subnet;
1097  Ip6Address Ipv6_dst_subnet, Ipv6_dst_ret_subnet;
1098  uint8_t max_mask, max_plen;
1099  const FatFlowEntry *match_ffe = NULL;
1100 
1101  if (src_ip->is_v4()) {
1102  prefix_type = AGGREGATE_SRC_DST_IPV4;
1103  Ipv4_src_subnet = Address::GetIp4SubnetAddress(src_ip->to_v4(),
1105  Ipv4_dst_subnet = Address::GetIp4SubnetAddress(dst_ip->to_v4(),
1107  max_mask = 32;
1108  max_plen = 32;
1109  } else {
1110  prefix_type = AGGREGATE_SRC_DST_IPV6;
1111  Ipv6_src_subnet = Address::GetIp6SubnetAddress(src_ip->to_v6(),
1113  Ipv6_dst_subnet = Address::GetIp6SubnetAddress(dst_ip->to_v6(),
1115  max_mask = 128;
1116  max_plen = 128;
1117  }
1118 
1119  const FatFlowEntry lbffe =
1120  FatFlowEntry(protocol, port, "none",
1121  prefix_type,
1122  (src_ip->is_v4()?
1123  IpAddress(Ipv4_src_subnet):
1124  IpAddress(Ipv6_src_subnet)),
1127  (dst_ip->is_v4()?
1128  IpAddress(Ipv4_dst_subnet):
1129  IpAddress(Ipv6_dst_subnet)),
1132 
1133  FatFlowEntrySet::iterator start = fat_flow_list_.list_.lower_bound(lbffe);
1134 
1135  const FatFlowEntry ubffe = FatFlowEntry(protocol, port, "none", prefix_type,
1136  *src_ip, max_mask, max_plen,
1137  *dst_ip, max_mask, max_plen);
1138 
1139  FatFlowEntrySet::iterator end = fat_flow_list_.list_.upper_bound(ubffe);
1140 
1141  if ((start != fat_flow_list_.list_.end()) &&
1142  (start->protocol == protocol) && (start->port == port)) {
1143  while (start != end) {
1144  if (src_ip->is_v4() && start->src_prefix.is_v4() &&
1145  start->dst_prefix.is_v4() &&
1146  IsIp4SubnetMember(src_ip->to_v4(), start->src_prefix.to_v4(),
1147  start->src_prefix_mask) &&
1148  IsIp4SubnetMember(dst_ip->to_v4(), start->dst_prefix.to_v4(),
1149  start->dst_prefix_mask) &&
1150  (start->protocol == protocol) && (start->port == port)) {
1151  match_ffe = &(*start);
1152  } else if (src_ip->is_v6() && start->src_prefix.is_v6() &&
1153  start->dst_prefix.is_v6() &&
1154  IsIp6SubnetMember(src_ip->to_v6(), start->src_prefix.to_v6(),
1155  start->src_prefix_mask) &&
1156  IsIp6SubnetMember(dst_ip->to_v6(), start->dst_prefix.to_v6(),
1157  start->dst_prefix_mask) &&
1158  (start->protocol == protocol) && (start->port == port)) {
1159  match_ffe = &(*start);
1160  }
1161  start++;
1162  }
1163  }
1164  if (match_ffe && (match_ffe->prefix_aggregate == prefix_type)) {
1165  if (src_ip->is_v4()) {
1166  Ipv4_src_ret_subnet =
1167  Address::GetIp4SubnetAddress(src_ip->to_v4(),
1168  match_ffe->src_aggregate_plen);
1169  Ipv4_dst_ret_subnet =
1170  Address::GetIp4SubnetAddress(dst_ip->to_v4(),
1171  match_ffe->dst_aggregate_plen);
1172  *src_ip = IpAddress(Ipv4_src_ret_subnet);
1173  *dst_ip = IpAddress(Ipv4_dst_ret_subnet);
1174  } else {
1175  Ipv6_src_ret_subnet =
1176  Address::GetIp6SubnetAddress(src_ip->to_v6(),
1177  match_ffe->src_aggregate_plen);
1178  Ipv6_dst_ret_subnet =
1179  Address::GetIp6SubnetAddress(dst_ip->to_v6(),
1180  match_ffe->dst_aggregate_plen);
1181  *src_ip = IpAddress(Ipv6_src_ret_subnet);
1182  *dst_ip = IpAddress(Ipv6_dst_ret_subnet);
1183  }
1184  return true;
1185  }
1186  return false;
1187 }
1188 
1189 
1190 bool VmInterface::MatchSrcDstPrefixRule(uint8_t protocol, uint16_t *sport,
1191  uint16_t *dport, bool *same_port_num,
1192  IpAddress *SrcIP, IpAddress *DstIP) const
1193 {
1194  if ((*sport) < (*dport)) {
1195  if (MatchSrcDstPrefixPort(protocol, *sport, SrcIP, DstIP)) {
1196  *dport = 0;
1197  return true;
1198  }
1199  if (MatchSrcDstPrefixPort(protocol, *dport, SrcIP, DstIP)) {
1200  *sport = 0;
1201  return true;
1202  }
1203  } else {
1204  if (MatchSrcDstPrefixPort(protocol, *dport, SrcIP, DstIP)) {
1205  if ((*sport) == (*dport)) {
1206  *same_port_num = true;
1207  }
1208  *sport = 0;
1209  return true;
1210  }
1211  if (MatchSrcDstPrefixPort(protocol, *sport, SrcIP, DstIP)) {
1212  *dport = 0;
1213  return true;
1214  }
1215  }
1216  if (MatchSrcDstPrefixPort(protocol, 0, SrcIP, DstIP)) {
1217  *sport = *dport = 0;
1218  return true;
1219  }
1220  return false;
1221 }
1222 
1223 
1224 bool VmInterface::IsFatFlowPrefixAggregation(bool ingress, uint8_t protocol,
1225  uint16_t *sport, uint16_t *dport,
1226  bool *same_port_num,
1227  IpAddress *SrcIP, IpAddress *DstIP,
1228  bool *is_fat_flow_src_prefix,
1229  bool *is_fat_flow_dst_prefix,
1231  *ignore_addr) const
1232 {
1233  uint16_t *src_port = sport,
1234  *dst_port = dport;
1235  IpAddress *src_ip = (ingress? SrcIP: DstIP),
1236  *dst_ip = (ingress? DstIP: SrcIP);
1237  bool *is_src_prefix = (ingress? is_fat_flow_src_prefix : is_fat_flow_dst_prefix);
1238  bool *is_dst_prefix = (ingress? is_fat_flow_dst_prefix : is_fat_flow_src_prefix);
1239  bool ret;
1240  FatFlowIgnoreAddressType ign_addr;
1241 
1242  *is_src_prefix = false;
1243  *is_dst_prefix = false;
1244 
1245  /* Match Src prefix rule first */
1246  if (MatchSrcPrefixRule(protocol, src_port, dst_port, same_port_num,
1247  src_ip, &ign_addr)) {
1248  *is_src_prefix = true;
1249  *ignore_addr = ign_addr;
1250  return true;
1251  }
1252  /* Match Dst prefix rule */
1253  if (MatchDstPrefixRule(protocol, src_port, dst_port, same_port_num,
1254  dst_ip, &ign_addr)) {
1255  *is_dst_prefix = true;
1256  *ignore_addr = ign_addr;
1257  return true;
1258  }
1259  /* Match Src+Dst prefix rule */
1260  ret = MatchSrcDstPrefixRule(protocol, src_port, dst_port, same_port_num,
1261  src_ip, dst_ip);
1262  if (ret) {
1263  *is_src_prefix = true;
1264  *is_dst_prefix = true;
1265  }
1266 
1267  return ret;
1268 }
1269 
1270 
1272  const IpAddress &sip,
1273  const IpAddress &dip) const {
1274  if (family == Address::INET) {
1276  if ((sip == gw_ip) || (dip == gw_ip)) {
1277  return true;
1278  }
1280  if ((sip == service_ip) || (dip == service_ip)) {
1281  return true;
1282  }
1283  boost::system::error_code ec;
1284  Ip4Address ll_subnet = Ip4Address::from_string
1285  (agent()->v4_link_local_subnet(), ec);
1286  if (IsIp4SubnetMember(sip.to_v4(), ll_subnet,
1287  agent()->v4_link_local_plen())) {
1288  return true;
1289  }
1290  if (IsIp4SubnetMember(dip.to_v4(), ll_subnet,
1291  agent()->v4_link_local_plen())) {
1292  return true;
1293  }
1294  } else if (family == Address::INET6){
1296  if ((sip == gw_ip) || (dip == gw_ip)) {
1297  return true;
1298  }
1300  if ((sip == service_ip) || (dip == service_ip)) {
1301  return true;
1302  }
1303  boost::system::error_code ec;
1304  Ip6Address ll6_subnet = Ip6Address::from_string
1305  (agent()->v6_link_local_subnet(), ec);
1306  if (IsIp6SubnetMember(sip.to_v6(), ll6_subnet,
1307  agent()->v6_link_local_plen())) {
1308  return true;
1309  }
1310  if (IsIp6SubnetMember(dip.to_v6(), ll6_subnet,
1311  agent()->v6_link_local_plen())) {
1312  return true;
1313  }
1314  }
1315  return false;
1316 }
1317 
1318 void VmInterface::FillV4ExcludeIp(uint64_t plen, const Ip4Address &ip,
1319  VmInterface::FatFlowExcludeList *list) const {
1320  uint64_t value = 0;
1321  if (!ip.is_unspecified()) {
1322  value = plen | htonl(ip.to_ulong());
1323  list->fat_flow_v4_exclude_list_.push_back(value);
1324  }
1325 }
1326 
1327 void VmInterface::FillV6ExcludeIp(uint16_t plen, const IpAddress &ip,
1328  VmInterface::FatFlowExcludeList *list) const {
1329  if (ip.is_v6() && !ip.is_unspecified()) {
1330  uint64_t ip_arr[2];
1331  Ip6AddressToU64Array(ip.to_v6(), ip_arr, 2);
1332  list->fat_flow_v6_exclude_upper_list_.push_back(ip_arr[0]);
1333  list->fat_flow_v6_exclude_lower_list_.push_back(ip_arr[1]);
1334  list->fat_flow_v6_exclude_plen_list_.push_back(plen);
1335  }
1336 }
1337 
1339 (VmInterface::FatFlowExcludeList *list) const {
1340  /* Build the list afresh each time. So clear the list */
1341  list->Clear();
1342 
1343  /* Build IPv4 exclude-list */
1345  uint64_t plen = (uint64_t(Address::kMaxV4PrefixLen) << 32);
1346  FillV4ExcludeIp(plen, gw_ip.to_v4(), list);
1348  FillV4ExcludeIp(plen, service_ip.to_v4(), list);
1349  boost::system::error_code ec;
1350  Ip4Address ll_subnet = Ip4Address::from_string
1351  (agent()->v4_link_local_subnet(), ec);
1352  plen = (uint64_t(agent()->v4_link_local_plen()) << 32);
1353  FillV4ExcludeIp(plen, ll_subnet, list);
1354 
1355  /* Build IPv6 exclude-list */
1357  FillV6ExcludeIp(128, gw6_ip, list);
1358  IpAddress service6_ip = GetServiceIp(primary_ip6_addr_);
1359  FillV6ExcludeIp(128, service6_ip, list);
1360  Ip6Address ll6_subnet = Ip6Address::from_string
1361  (agent()->v6_link_local_subnet(), ec);
1362  FillV6ExcludeIp(agent()->v6_link_local_plen(), ll6_subnet, list);
1363 }
1364 
1365 const MacAddress& VmInterface::GetVifMac(const Agent *agent) const {
1366  if (parent()) {
1367  if (device_type_ == VM_VLAN_ON_VMI) {
1368  const VmInterface *vmi =
1369  static_cast<const VmInterface *>(parent_.get());
1370  return vmi->GetVifMac(agent);
1371  }
1372  return parent()->mac();
1373  } else {
1374  return agent->vrrp_mac();
1375  }
1376 }
1377 
1379  return (l2_active_ & is_hc_active_);
1380 }
1381 
1382 // Policy is disabled only if user explicitly sets disable policy.
1383 // If user changes to disable policy. only policy will be enabled in case of
1384 // link local services & BGP as a service.
1386  if (disable_policy_) {
1387  return false;
1388  }
1389 
1390  /* For a l2-only VN's VMI, policy should be implicitly disabled */
1391  if (layer3_forwarding_ == false) {
1392  return false;
1393  }
1394  return true;
1395 }
1396 
1397 // VN is in VXLAN mode if,
1398 // - Tunnel type computed is VXLAN and
1399 // - vxlan_id_ set in VN is non-zero
1402  return false;
1403 
1404  return vxlan_id_ != 0;
1405 }
1406 
1408  std::vector<std::string> *vect) const {
1409  InstanceIpSet list;
1410  if (family == Address::INET) {
1411  list = instance_ipv4_list_.list_;
1412  } else {
1413  list = instance_ipv6_list_.list_;
1414  }
1415  InstanceIpSet::iterator it = list.begin();
1416  while (it != list.end()) {
1417  const VmInterface::InstanceIp &rt = *it;
1418  it++;
1419  vect->push_back(rt.ip_.to_string());
1420  }
1421 }
1422 
1423 uint32_t VmInterface::GetIsid() const {
1424  BridgeDomainEntrySet::const_iterator it = bridge_domain_list_.list_.begin();
1425  for (; it != bridge_domain_list_.list_.end(); it++) {
1426  return it->bridge_domain_->isid();
1427  }
1428  return kInvalidIsid;
1429 }
1430 
1431 uint32_t VmInterface::GetPbbVrf() const {
1432  BridgeDomainEntrySet::const_iterator it = bridge_domain_list_.list_.begin();
1433  for (; it != bridge_domain_list_.list_.end(); it++) {
1434  if (it->bridge_domain_->vrf()) {
1435  return it->bridge_domain_->vrf()->vrf_id();
1436  }
1437  }
1438  return VrfEntry::kInvalidIndex;
1439 }
1440 
1441 uint32_t VmInterface::GetPbbLabel() const {
1442  BridgeDomainEntrySet::const_iterator it = bridge_domain_list_.list_.begin();
1443  for (; it != bridge_domain_list_.list_.end(); it++) {
1444  if (it->bridge_domain_->vrf()) {
1445  return it->bridge_domain_->vrf()->table_label();
1446  }
1447  }
1448  return MplsTable::kInvalidLabel;
1449 }
1450 
1452 // Metadata related routines
1455  MetaDataIpMap::const_iterator it = metadata_ip_map_.find(ip);
1456  if (it != metadata_ip_map_.end()) {
1457  return it->second;
1458  }
1459 
1460  return NULL;
1461 }
1462 
1464  std::pair<MetaDataIpMap::iterator, bool> ret;
1465  ret = metadata_ip_map_.insert(std::pair<IpAddress, MetaDataIp*>
1466  (mip->GetLinkLocalIp(), mip));
1467  assert(ret.second);
1468 }
1469 
1471  std::size_t ret = metadata_ip_map_.erase(mip->GetLinkLocalIp());
1472  if (ret == 0) {
1473  LOG(DEBUG, "Return code for Metadata IP Map Erase: " <<ret<< " for MetaDataIp: " <<mip->GetLinkLocalIp());
1474  }
1475 }
1476 
1478  MetaDataIpMap::iterator it = metadata_ip_map_.begin();
1479  while (it != metadata_ip_map_.end()) {
1480  it->second->UpdateInterfaceCb();
1481  it++;
1482  }
1483 }
1484 
1486  bool ret = false;
1487  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
1488 
1489  // Support DHCP relay for fabric-ports if IP address is not configured
1490  do_dhcp_relay_ = (fabric_port_ && addr.to_ulong() == 0 && vrf() &&
1491  vrf()->GetName() == table->agent()->fabric_vrf_name());
1492 
1493  if (do_dhcp_relay_) {
1494  // Set config_seen flag on DHCP SNoop entry
1495  table->DhcpSnoopSetConfigSeen(name());
1496  // IP Address not know. Get DHCP Snoop entry.
1497  // Also sets the config_seen_ flag for DHCP Snoop entry
1498  addr = table->GetDhcpSnoopEntry(name());
1499  dhcp_addr_ = addr;
1500  }
1501 
1502  // Retain the old if new IP could not be got
1503  if (addr.to_ulong() == 0) {
1504  addr = primary_ip_addr_;
1505  }
1506 
1507  if (primary_ip_addr_ != addr) {
1508  primary_ip_addr_ = addr;
1509  ret = true;
1510  }
1511 
1512  return ret;
1513 }
1514 
1516  if (si_other_end_vmi_ == nil_uuid()) {
1517  return NULL;
1518  }
1519  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
1521  VmInterface *intf = static_cast<VmInterface *>(table->Find(&key, false));
1522  return intf;
1523 }
1524 
1525 void VmInterface::SendTrace(const AgentDBTable *table, Trace event) const {
1526  InterfaceInfo intf_info;
1527  intf_info.set_name(name());
1528  intf_info.set_index(id_);
1529 
1530  switch(event) {
1531  case ACTIVATED_IPV4:
1532  intf_info.set_op("IPV4 Activated");
1533  break;
1534  case DEACTIVATED_IPV4:
1535  intf_info.set_op("IPV4 Deactivated");
1536  break;
1537  case ACTIVATED_IPV6:
1538  intf_info.set_op("IPV6 Activated");
1539  break;
1540  case DEACTIVATED_IPV6:
1541  intf_info.set_op("IPV6 Deactivated");
1542  break;
1543  case ACTIVATED_L2:
1544  intf_info.set_op("L2 Activated");
1545  break;
1546  case DEACTIVATED_L2:
1547  intf_info.set_op("L2 Deactivated");
1548  break;
1549  case ADD:
1550  intf_info.set_op("Add");
1551  break;
1552  case DEL:
1553  intf_info.set_op("Delete");
1554  break;
1555 
1556  case FLOATING_IP_CHANGE: {
1557  intf_info.set_op("Floating IP change");
1558  std::vector<FloatingIPInfo> fip_list;
1559  FloatingIpSet::iterator it = floating_ip_list_.list_.begin();
1560  while (it != floating_ip_list_.list_.end()) {
1561  const FloatingIp &ip = *it;
1562  FloatingIPInfo fip;
1563  fip.set_ip_address(ip.floating_ip_.to_string());
1564  fip.set_vrf_name(ip.vrf_->GetName());
1565  fip_list.push_back(fip);
1566  it++;
1567  }
1568  intf_info.set_fip(fip_list);
1569  break;
1570  }
1571  case SERVICE_CHANGE:
1572  break;
1573 
1574  case VMI_REUSE:
1575  intf_info.set_op("VMI reuse");
1576  intf_info.set_vrf_on_delete(vrf_name_);
1577  break;
1578 
1579  case VRF_REUSE:
1580  intf_info.set_op("VRF reuse");
1581  intf_info.set_vrf_on_delete(vrf_name_);
1582  break;
1583  }
1584 
1585  intf_info.set_ip_address(primary_ip_addr_.to_string());
1586  if (vm_) {
1587  intf_info.set_vm(UuidToString(vm_->GetUuid()));
1588  }
1589  if (vn_) {
1590  intf_info.set_vn(vn_->GetName());
1591  }
1592  if (vrf_) {
1593  intf_info.set_vrf(vrf_->GetName());
1594  }
1595  intf_info.set_vm_project(UuidToString(vm_project_uuid_));
1597  table,
1598  intf_info);
1599 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet, uint8_t plen)
Definition: address_util.cc:30
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
Definition: address_util.cc:20
void Ip6AddressToU64Array(const Ip6Address &addr, uint64_t *arr, int size)
std::vector< uint64_t > TagList
Definition: agent.h:203
std::vector< int > SecurityGroupList
Definition: agent.h:202
std::set< std::string > VnListType
Definition: agent.h:213
#define OPER_TRACE_ENTRY(obj, table,...)
Definition: agent_db.h:237
std::vector< std::string > CommunityList
Definition: bgp_config.h:348
static const uint8_t kMaxV4PrefixLen
Definition: address.h:21
static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix, uint16_t plen)
Definition: address.cc:180
Family
Definition: address.h:25
@ INET
Definition: address.h:27
@ INET6
Definition: address.h:28
static Ip6Address GetIp6SubnetAddress(const Ip6Address &prefix, uint16_t plen)
Definition: address.cc:201
AgentDBEntry * Find(const DBEntry *key, bool ret_del)
Definition: agent_db.cc:135
virtual AgentPath * FindPath(const Peer *peer) const
Definition: agent_route.cc:866
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
KSync * ksync() const
Definition: agent.cc:905
static const std::string & NullString()
Definition: agent.h:440
VrfEntry * fabric_vrf() const
Definition: agent.h:918
PhysicalDeviceVnTable * physical_device_vn_table() const
Definition: agent.h:638
static const MacAddress & vrrp_mac()
Definition: agent.h:442
const std::string & fabric_vrf_name() const
Definition: agent.h:906
DBTableBase * get_table() const
Definition: db_entry.cc:120
bool IsDeleted() const
Definition: db_entry.h:49
bool Enqueue(DBRequest *req)
Definition: db_table.cc:221
void AddLocalVmRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *intf, const IpAddress &ip, uint32_t label, const std::string &vn_name, const SecurityGroupList &sg_id_list, const TagList &tag_id_list, const PathPreference &path_pref, uint32_t ethernet_tag, bool etree_leaf, const std::string &interface_name)
void DelLocalVmRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *intf, const IpAddress &ip, uint32_t ethernet_tag)
IpAddress destination_ip() const
IpAddress get_source_ip() const
Definition: health_check.h:153
HealthCheckService * service() const
Definition: health_check.h:147
HealthCheckType health_check_type() const
Definition: health_check.h:353
void ResyncHealthCheckInterface(const HealthCheckService *service, const VmInterface *intf)
static void Delete(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen)
static void AddLocalVmRoute(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, const boost::uuids::uuid &intf_uuid, const VnListType &vn_list, uint32_t label, const SecurityGroupList &sg_list, const TagList &tag_list, const CommunityList &communities, bool force_policy, const PathPreference &path_preference, const IpAddress &subnet_service_ip, const EcmpLoadBalance &ecmp_load_balance, bool is_local, bool is_health_check_service, const std::string &intf_name, bool native_encap, const std::string &intf_route_type=VmInterface::kInterface, bool is_learnt_route=false)
const Ip4Address GetDhcpSnoopEntry(const std::string &ifname)
Definition: interface.cc:717
void DhcpSnoopSetConfigSeen(const std::string &ifname)
Definition: interface.cc:739
VmiToPhysicalDeviceVnTree vmi_to_physical_device_vn_tree_
Definition: interface.h:492
void DelPhysicalDeviceVnEntry(const boost::uuids::uuid &vmi)
void UpdatePhysicalDeviceVnEntry(const boost::uuids::uuid &vmi, boost::uuids::uuid &dev, boost::uuids::uuid &vn, IFMapNode *vn_node)
Agent * agent() const
Definition: interface.h:450
VrfEntry * FindVrfRef(const std::string &name) const
Definition: interface.cc:295
Transport transport_
Definition: interface.h:189
const MacAddress & mac() const
Definition: interface.h:134
VrfEntry * vrf() const
Definition: interface.h:118
bool os_oper_state() const
Definition: interface.h:135
bool is_hc_active() const
Definition: interface.h:121
bool is_hc_active_
Definition: interface.h:172
@ TRANSPORT_PMD
Definition: interface.h:70
@ TRANSPORT_ETHERNET
Definition: interface.h:68
const std::string & name() const
Definition: interface.h:117
VrfEntryRef vrf_
Definition: interface.h:166
uint32_t os_index() const
Definition: interface.h:133
uint32_t label() const
Definition: interface.h:130
bool admin_state_
Definition: interface.h:181
struct InterfaceOsParams os_params_
Definition: interface.h:191
uint32_t l2_label_
Definition: interface.h:168
virtual void GetOsParams(Agent *agent)
Definition: interface.cc:536
bool l2_active_
Definition: interface.h:176
static const uint32_t kInvalidIndex
Definition: interface.h:73
const boost::uuids::uuid & GetUuid() const
Definition: interface.h:116
size_t id_
Definition: interface.h:177
bool NeedDefaultOsOperStateDisabled(Agent *agent) const
Definition: interface.cc:1509
Type type() const
Definition: interface.h:115
VnswInterfaceListener * vnsw_interface_listner() const
Definition: ksync_init.h:59
static const MacAddress kZeroMac
Definition: mac_address.h:150
IpAddress GetLinkLocalIp() const
Definition: metadata_ip.cc:80
const std::string GetAnalyzerName() const
Definition: mirror_table.h:78
static const uint32_t kInvalidLabel
Definition: mpls.h:102
const DhcpOptionsList & dhcp_options() const
void set_static_preference(bool static_pref)
Definition: agent_path.h:93
void set_ecmp(bool ecmp)
Definition: agent_path.h:89
void set_dependent_ip(const IpAddress &ip)
Definition: agent_path.h:97
void set_preference(uint32_t preference)
Definition: agent_path.h:83
void set_vrf(const std::string &vrf)
Definition: agent_path.h:101
Definition: peer.h:45
bool DeleteConfigEntry(const boost::uuids::uuid &vmi, const boost::uuids::uuid &dev, const boost::uuids::uuid &vn)
bool AddConfigEntry(const boost::uuids::uuid &vmi, const boost::uuids::uuid &dev, const boost::uuids::uuid &vn)
Definition: trace.h:289
static TypeBmap AllType()
Definition: nexthop.h:322
static Type ComputeType(TypeBmap bmap)
Definition: nexthop.cc:34
const VmiEcmpLoadBalance & ecmp_load_balance() const
const MirrorEntry * mirror_entry() const
void InsertMetaDataIpInfo(MetaDataIp *mip)
bool layer3_forwarding() const
void SetServiceVlanPathPreference(PathPreference *pref, const IpAddress &service_ip) const
Agent * agent() const
bool IsFatFlowPrefixAggregation(bool ingress, uint8_t protocol, uint16_t *sport, uint16_t *dport, bool *same_port_num, IpAddress *SrcIP, IpAddress *DstIP, bool *is_src_prefix, bool *is_dst_prefix, FatFlowIgnoreAddressType *ignore_addr) const
VmEntryBackRef vm_
VmInterface * PortTuplePairedInterface() const
Ip4Address dhcp_addr_
std::string vrf_name_
HealthCheckInstanceSet hc_instance_set_
void DeleteL2InterfaceRoute(const VrfEntry *vrf, uint32_t ethernet_tag, const IpAddress &ip, const MacAddress &mac) const
uint32_t GetPbbLabel() const
const VrfEntry * GetServiceVlanVrf(uint16_t vlan_tag) const
ServiceVlanList service_vlan_list_
static const uint32_t kInvalidIsid
Definition: vm_interface.h:365
@ REMOTE_VM_VLAN_ON_VMI
Definition: vm_interface.h:395
bool GetInterfaceDhcpOptions(std::vector< autogen::DhcpOptionType > *options) const
void DeleteMetaDataIpInfo(MetaDataIp *mip)
bool HasFloatingIp() const
bool CopyIpAddress(Ip4Address &addr)
uint32_t local_preference_
LearntMacIpList learnt_mac_ip_list_
BridgeDomainList bridge_domain_list_
bool IsFatFlowPortBased(uint8_t protocol, uint16_t port, FatFlowIgnoreAddressType *ignore_addr) const
uint32_t ethernet_tag() const
bool NeedOsStateWithoutDevice() const
const Interface * parent() const
std::set< HealthCheckInstanceBase * > HealthCheckInstanceSet
Definition: vm_interface.h:469
bool IsActive() const
AllowedAddressPairList allowed_address_pair_list_
bool ecmp() const
MetaDataIpMap metadata_ip_map_
bool IsIpv6Active() const
VmiEcmpLoadBalance ecmp_load_balance_
bool service_ip_ecmp6_
bool MatchDstPrefixPort(uint8_t protocol, uint16_t port, IpAddress *dst_ip, FatFlowIgnoreAddressType *ignore_addr) const
void AddL2InterfaceRoute(const IpAddress &ip, const MacAddress &mac, const IpAddress &dependent_ip) const
IpAddress GetServiceIp(const IpAddress &ip) const
bool IsFloatingIp(const IpAddress &ip) const
std::unique_ptr< LocalVmPortPeer > peer_
Ip4Address primary_ip_addr_
bool WaitForTraffic() const
bool InstallBridgeRoutes() const
@ IGNORE_ADDRESS_MAX_VAL
Definition: vm_interface.h:441
@ IGNORE_ADDRESS_MIN_VAL
Definition: vm_interface.h:438
void DeleteRoute(const std::string &vrf_name, const IpAddress &ip, uint32_t plen)
bool IsMetaDataIPActive() const
bool IsMetaDataL2Active() const
boost::uuids::uuid vm_project_uuid_
void InsertHealthCheckInstance(HealthCheckInstanceBase *hc_inst)
void CopyTagIdList(TagList *tag_id_list) const
bool IsHealthCheckEnabled() const
std::set< InstanceIp, InstanceIp > InstanceIpSet
Definition: vm_interface.h:936
void DeleteHealthCheckInstance(HealthCheckInstanceBase *hc_inst)
FatFlowPrefixAggregateType
Definition: vm_interface.h:449
@ AGGREGATE_SRC_DST_IPV6
Definition: vm_interface.h:454
@ AGGREGATE_PREFIX_MIN_VAL
Definition: vm_interface.h:451
@ AGGREGATE_SRC_DST_IPV4
Definition: vm_interface.h:457
SecurityGroupEntryList sg_list_
bool GetSubnetDhcpOptions(std::vector< autogen::DhcpOptionType > *options, bool ipv6) const
void FillV4ExcludeIp(uint64_t plen, const Ip4Address &ip, FatFlowExcludeList *list) const
bool service_ip_ecmp_
Ip4Address service_ip_
void FillV6ExcludeIp(uint16_t plen, const IpAddress &ip, FatFlowExcludeList *list) const
bool IsVxlanMode() const
bool MatchDstPrefixRule(uint8_t protocol, uint16_t *sport, uint16_t *dport, bool *same_port_num, IpAddress *DstIP, FatFlowIgnoreAddressType *ignore_addr) const
void BuildFatFlowExcludeList(FatFlowExcludeList *list) const
AliasIpList alias_ip_list_
const MacAddress & GetVifMac(const Agent *) const
const TagEntryList & tag_list() const
VnEntryRef vn_
bool MatchSrcDstPrefixPort(uint8_t protocol, uint16_t port, IpAddress *src_ip, IpAddress *dst_ip) const
uint32_t GetServiceVlanLabel(const VrfEntry *vrf) const
uint32_t GetIsid() const
FloatingIpList floating_ip_list_
bool MatchSrcDstPrefixRule(uint8_t protocol, uint16_t *sport, uint16_t *dport, bool *same_port_num, IpAddress *SrcIP, IpAddress *DstIP) const
uint16_t tx_vlan_id_
const OperDhcpOptions & oper_dhcp_options() const
InstanceIpList instance_ipv4_list_
Ip4Address subnet_
bool bridging() const
bool layer3_forwarding_
const VnEntry * vn() const
const std::string GetAnalyzer() const
bool NeedDevice() const
void UpdateInterfaceHealthCheckService()
static const uint32_t kInvalidVlanId
Definition: vm_interface.h:363
bool do_dhcp_relay_
Ip4Address service_ip()
const Ip4Address & primary_ip_addr() const
const HealthCheckInstanceSet & hc_instance_set() const
bool IsL2Active() const
uint16_t rx_vlan_id_
boost::uuids::uuid si_other_end_vmi_
InterfaceBackRef parent_
void CopySgIdList(SecurityGroupList *sg_id_list) const
void SendTrace(const AgentDBTable *table, Trace event) const
void AddRoute(const std::string &vrf_name, const IpAddress &ip, uint32_t plen, const std::string &vn_name, bool force_policy, bool ecmp, bool is_local, bool proxy_arp, const IpAddress &service_ip, const IpAddress &dependent_ip, const CommunityList &communties, uint32_t label, const string &intf_route_type, bool is_learnt_route=false)
bool disable_policy_
bool MatchAapIp(const IpAddress &ip, uint8_t plen) const
VmInterface::VmiType vmi_type_
bool GetIpamDhcpOptions(std::vector< autogen::DhcpOptionType > *options, bool ipv6) const
bool MatchSrcPrefixPort(uint8_t protocol, uint16_t port, IpAddress *src_ip, FatFlowIgnoreAddressType *ignore_addr) const
MetaDataIp * GetMetaDataIp(const IpAddress &ip) const
void CopyEcmpLoadBalance(EcmpLoadBalance &ecmp_load_balance)
virtual void GetOsParams(Agent *agent)
bool ExcludeFromFatFlow(Address::Family family, const IpAddress &sip, const IpAddress &dip) const
const MacAddress & GetIpMac(const IpAddress &, const uint8_t plen) const
bool pbb_interface() const
MacAddress vm_mac_
uint32_t GetPbbVrf() const
void SetPathPreference(PathPreference *pref, bool ecmp, const IpAddress &dependent_ip) const
Ip6Address service_ip6_
const Ip6Address & primary_ip6_addr() const
friend struct VmInterfaceOsOperStateData
VrfEntry * GetAliasIpVrf(const IpAddress &ip) const
void BuildIpStringList(Address::Family family, std::vector< std::string > *vect) const
bool PolicyEnabled() const
FatFlowList fat_flow_list_
bool MatchSrcPrefixRule(uint8_t protocol, uint16_t *sport, uint16_t *dport, bool *same_port_num, IpAddress *SrcIP, FatFlowIgnoreAddressType *ignore_addr) const
InstanceIpList instance_ipv6_list_
bool IsIpv4Active() const
Ip6Address primary_ip6_addr_
const Peer * peer() const
VmInterface::DeviceType device_type_
const std::string & vrf_name() const
IpAddress GetGatewayIp(const IpAddress &ip) const
bool use_global_vrouter() const
virtual void Copy(const VmiEcmpLoadBalance &rhs)
const std::vector< VnIpam > & GetVnIpam() const
Definition: vn.h:172
const string & GetName() const
Definition: vn.h:163
bool IsHostLinkStateUp(const std::string &name) const
Definition: vrf.h:90
const string & GetName() const
Definition: vrf.h:104
static const uint32_t kInvalidIndex
Definition: vrf.h:92
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:331
VrfEntry * forwarding_vrf() const
Definition: vrf.h:221
#define LOG(_Level, _Msg)
Definition: logging.h:35
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:139
@ ADD_DEL_CHANGE
Definition: agent_db.h:101
@ RESYNC
Definition: agent_db.h:104
@ DB_ENTRY_ADD_CHANGE
Definition: db_table.h:39
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:49
std::unique_ptr< DBRequestData > data
Definition: db_table.h:50
BridgeDomainEntrySet list_
FatFlowPrefixAggregateType prefix_aggregate
FatFlowIgnoreAddressType ignore_address
std::vector< uint64_t > fat_flow_v4_exclude_list_
std::vector< uint64_t > fat_flow_v6_exclude_lower_list_
std::vector< uint64_t > fat_flow_v6_exclude_upper_list_
std::vector< uint16_t > fat_flow_v6_exclude_plen_list_
const IpAddress ip_
Definition: vm_interface.h:925
VmiToPhysicalDeviceVnData(const boost::uuids::uuid &dev, const boost::uuids::uuid &vn)
Definition: vn.h:29
IpAddress dns_server
Definition: vn.h:34
IpAddress default_gw
Definition: vn.h:32
#define FAT_FLOW_ENTRY_MIN_PREFIX_LEN
static IpAddress ipv6_max_addr
static IpAddress ipv6_empty_addr
static IpAddress ipv4_empty_addr
static IpAddress ipv4_max_addr
boost::uuids::uuid uuid