OpenSDN source code
vm_interface.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 #include <cmn/agent_cmn.h>
6 #include <init/agent_param.h>
7 #include <oper/operdb_init.h>
8 #include <oper/route_common.h>
9 #include <oper/vm.h>
10 #include <oper/vn.h>
11 #include <oper/vrf.h>
12 #include <oper/nexthop.h>
13 #include <oper/mpls.h>
14 #include <oper/mirror_table.h>
15 #include <oper/metadata_ip.h>
16 #include <oper/interface_common.h>
17 #include <oper/health_check.h>
18 #include <oper/vrf_assign.h>
19 #include <oper/vxlan.h>
20 #include <oper/oper_dhcp_options.h>
22 #include <oper/global_vrouter.h>
23 #include <oper/qos_config.h>
24 #include <oper/bridge_domain.h>
25 #include <oper/sg.h>
26 #include <oper/tag.h>
27 #include <base/address_util.h>
28 #include <filter/acl.h>
29 #include <filter/policy_set.h>
35 
36 using namespace std;
37 using namespace boost::uuids;
38 using namespace autogen;
40  InitIgnoreAddressMap();
41 
42 const char *VmInterface::kInterface = "interface";
43 const char *VmInterface::kServiceInterface = "service-interface";
44 const char *VmInterface::kInterfaceStatic = "interface-static";
45 
47 // VM-Interface entry routines
50  const std::string &name,
51  bool os_oper_state,
52  const boost::uuids::uuid &logical_router_uuid) :
53  Interface(Interface::VM_INTERFACE, uuid, name, NULL, os_oper_state,
54  logical_router_uuid),
55  vm_(NULL, this), vn_(NULL), primary_ip_addr_(0), subnet_bcast_addr_(0),
56  primary_ip6_addr_(), vm_mac_(MacAddress::kZeroMac), policy_enabled_(false),
57  mirror_entry_(NULL), mirror_direction_(MIRROR_RX_TX), cfg_name_(""),
58  fabric_port_(true), need_linklocal_ip_(false), drop_new_flows_(false),
59  dhcp_enable_(true), dhcp_enable_v6_(false), do_dhcp_relay_(false), proxy_arp_mode_(PROXY_ARP_NONE),
60  vm_name_(), vm_project_uuid_(nil_uuid()), vxlan_id_(0), bridging_(false),
61  layer3_forwarding_(true), flood_unknown_unicast_(false),
62  mac_set_(false), ecmp_(false), ecmp6_(false), disable_policy_(false),
63  tx_vlan_id_(kInvalidVlanId), rx_vlan_id_(kInvalidVlanId), parent_(NULL, this),
64  local_preference_(0), oper_dhcp_options_(),
65  cfg_igmp_enable_(false), igmp_enabled_(false),
66  mac_ip_learning_enable_(false), max_flows_(0),
67  mac_vm_binding_state_(new MacVmBindingState()),
68  nexthop_state_(new NextHopState()),
69  vrf_table_label_state_(new VrfTableLabelState()),
70  metadata_ip_state_(new MetaDataIpState()),
71  metadata_ip6_state_(new MetaDataIpState(false)),
72  resolve_route_state_(new ResolveRouteState()),
73  interface_route_state_(new VmiRouteState()),
74  sg_list_(), tag_list_(), floating_ip_list_(), alias_ip_list_(), service_vlan_list_(),
75  static_route_list_(), allowed_address_pair_list_(),
76  instance_ipv4_list_(true), instance_ipv6_list_(false), fat_flow_list_(),
77  vrf_assign_rule_list_(), vm_ip_service_addr_(0),
78  device_type_(VmInterface::DEVICE_TYPE_INVALID),
79  vmi_type_(VmInterface::VMI_TYPE_INVALID),
80  hbs_intf_type_(VmInterface::HBS_INTF_INVALID),
81  configurer_(0), subnet_(0), subnet_plen_(0), ethernet_tag_(0),
82  logical_interface_(nil_uuid()), nova_ip_addr_(0), nova_ip6_addr_(),
83  dhcp_addr_(0), metadata_ip_map_(), hc_instance_set_(),
84  ecmp_load_balance_(), service_health_check_ip_(), is_vn_qos_config_(false),
85  learning_enabled_(false), etree_leaf_(false), layer2_control_word_(false),
86  slo_list_(), forwarding_vrf_(NULL), vhostuser_mode_(vHostUserClient),
87  is_left_si_(false),
88  service_mode_(VmInterface::SERVICE_MODE_ERROR),
89  service_intf_type_(""),
90  parent_list_() {
91  metadata_ip_active_ = false;
92  metadata_l2_active_ = false;
93  ipv4_active_ = false;
94  ipv6_active_ = false;
95  l2_active_ = false;
96  flow_count_ = 0;
97  vrf_name_ = "";
98 }
99 
101  const std::string &name,
102  const Ip4Address &addr, const MacAddress &mac,
103  const std::string &vm_name,
104  const boost::uuids::uuid &vm_project_uuid,
105  uint16_t tx_vlan_id, uint16_t rx_vlan_id,
106  Interface *parent, const Ip6Address &a6,
107  DeviceType device_type, VmiType vmi_type,
108  uint8_t vhostuser_mode, bool os_oper_state,
109  const boost::uuids::uuid &logical_router_uuid) :
110  Interface(Interface::VM_INTERFACE, uuid, name, NULL, os_oper_state,
111  logical_router_uuid),
112  vm_(NULL, this), vn_(NULL), primary_ip_addr_(addr), subnet_bcast_addr_(0),
113  primary_ip6_addr_(a6), vm_mac_(mac), policy_enabled_(false),
114  mirror_entry_(NULL), mirror_direction_(MIRROR_RX_TX), cfg_name_(""),
115  fabric_port_(true), need_linklocal_ip_(false), drop_new_flows_(false),
116  dhcp_enable_(true), dhcp_enable_v6_(false), do_dhcp_relay_(false), proxy_arp_mode_(PROXY_ARP_NONE),
117  vm_name_(vm_name), vm_project_uuid_(vm_project_uuid), vxlan_id_(0),
118  bridging_(false), layer3_forwarding_(true),
119  flood_unknown_unicast_(false), mac_set_(false),
120  ecmp_(false), ecmp6_(false), disable_policy_(false),
121  tx_vlan_id_(tx_vlan_id), rx_vlan_id_(rx_vlan_id), parent_(parent, this),
122  local_preference_(0), oper_dhcp_options_(),
123  cfg_igmp_enable_(false), igmp_enabled_(false),
124  mac_ip_learning_enable_(false), max_flows_(0),
125  mac_vm_binding_state_(new MacVmBindingState()),
126  nexthop_state_(new NextHopState()),
127  vrf_table_label_state_(new VrfTableLabelState()),
128  metadata_ip_state_(new MetaDataIpState()),
129  metadata_ip6_state_(new MetaDataIpState(false)),
130  resolve_route_state_(new ResolveRouteState()),
131  interface_route_state_(new VmiRouteState()),
132  sg_list_(), tag_list_(),
133  floating_ip_list_(), alias_ip_list_(), service_vlan_list_(),
134  static_route_list_(), allowed_address_pair_list_(),
135  instance_ipv4_list_(true), instance_ipv6_list_(false), fat_flow_list_(),
136  vrf_assign_rule_list_(), device_type_(device_type),
137  vmi_type_(vmi_type), hbs_intf_type_(VmInterface::HBS_INTF_INVALID),
138  configurer_(0), subnet_(0),
139  subnet_plen_(0), ethernet_tag_(0), logical_interface_(nil_uuid()),
140  nova_ip_addr_(0), nova_ip6_addr_(), dhcp_addr_(0), metadata_ip_map_(),
141  hc_instance_set_(), service_health_check_ip_(), is_vn_qos_config_(false),
142  learning_enabled_(false), etree_leaf_(false), layer2_control_word_(false),
143  slo_list_(), forwarding_vrf_(NULL), vhostuser_mode_(vhostuser_mode),
144  is_left_si_(false),
145  service_mode_(VmInterface::SERVICE_MODE_ERROR),
146  service_intf_type_(""),
147  parent_list_() {
148  metadata_ip_active_ = false;
149  metadata_l2_active_ = false;
150  ipv4_active_ = false;
151  ipv6_active_ = false;
152  l2_active_ = false;
153  flow_count_ = 0;
154  vrf_name_ = "";
155 }
156 
158  // Release metadata first to ensure metadata_ip_map_ is empty
159  metadata_ip_state_.reset(NULL);
160  metadata_ip6_state_.reset(NULL);
161  assert(metadata_ip_map_.empty());
162  assert(hc_instance_set_.empty());
163 }
164 
166  configurer_ |= (1 << type);
167 }
168 
170  configurer_ &= ~(1 << type);
171 }
172 
174  return ((configurer_ & (1 << type)) != 0);
175 }
176 
177 bool VmInterface::CmpInterface(const DBEntry &rhs) const {
178  const VmInterface &intf=static_cast<const VmInterface &>(rhs);
179  if (uuid_ == nil_uuid() && intf.uuid_ == nil_uuid()) {
180  return name() < intf.name();
181  }
182 
183  return uuid_ < intf.uuid_;
184 }
185 
186 string VmInterface::ToString() const {
187  return "VM-PORT <" + name() + ">";
188 }
189 
192  return DBEntryBase::KeyPtr(key);
193 }
194 
197 }
198 
199 bool VmInterface::Delete(const DBRequest *req) {
200  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
201  const VmInterfaceData *vm_data = static_cast<const VmInterfaceData *>
202  (req->data.get());
203  if (vrf_ && vrf_->GetName() != "") {
204  vrf_name_ = vrf_->GetName();
205  }
206  vm_data->OnDelete(table, this);
207  if (configurer_) {
208  return false;
209  }
210  table->DeleteDhcpSnoopEntry(name());
211  return true;
212 }
213 
214 // When VMInterface is added from Config (sub-interface, gateway interface etc.)
215 // the RESYNC is not called and some of the config like VN and VRF are not
216 // applied on the interface (See Add() API above). Force change to ensure
217 // RESYNC is called
219  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
220  IFMapNode *node = ifmap_node();
221  if (node == NULL) {
222  PortSubscribeTable *subscribe_table =
224  if (subscribe_table)
225  node = subscribe_table->UuidToIFNode(GetUuid());
226  if (node == NULL)
227  return;
228  }
229 
230  // Config notification would have been ignored till Nova message is
231  // received. Update config now
232  IFMapAgentTable *ifmap_table =
233  static_cast<IFMapAgentTable *>(node->table());
235  req.key = node->GetDBRequestKey();
237  dynamic_cast<IFMapTable::RequestKey *>(req.key.get());
238  key->id_type = "virtual-machine-interface";
239  ifmap_table->Enqueue(&req);
240 }
241 
243  const std::string &vrf_name) {
244  Agent *agent = table->agent();
245  VrfKey vrf_key(vrf_name);
246  VrfEntry *vrf = static_cast<VrfEntry *>(
247  agent->vrf_table()->Find(&vrf_key, true));
248  if (vrf && vrf->IsDeleted()) {
249  SendTrace(table, VRF_REUSE);
250  return vrf->ResetVrfDelete();
251  }
252  return true;
253 }
254 
256  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
257  if (IsDeleted()) {
258  SendTrace(table, VMI_REUSE);
259  ResetVrfDelete(table, vrf_name());
260  }
261  return Resync(table, data);
262 }
263 
264 // Handle RESYNC DB Request. Handles multiple sub-types,
265 // - CONFIG : RESYNC from config message
266 // - IP_ADDR: RESYNC due to learning IP from DHCP
267 // - MIRROR : RESYNC due to change in mirror config
269  const VmInterfaceData *data) {
270  bool ret = false;
271 
272  // Copy old values used to update config below
273  bool old_ipv4_active = ipv4_active_;
274  bool old_ipv6_active = ipv6_active_;
275  bool old_l2_active = l2_active_;
276  bool old_policy = policy_enabled_;
277  VrfEntryRef old_vrf = vrf_;
278  bool force_update = false;
279  Ip4Address old_subnet = subnet_;
280  uint8_t old_subnet_plen = subnet_plen_;
281  bool old_metadata_ip_active = metadata_ip_active_;
282  bool old_metadata_l2_active = metadata_l2_active_;
283 
284  if (data) {
285  ret = data->OnResync(table, this, &force_update);
286  std::string ri_name = "";
287  if (data->vrf_name_ == "" && vrf_name_ == "") {
288  if (vn()) {
289  std::string fqdn_name = vn()->GetName();
290  size_t pos = fqdn_name.rfind(":");
291  if (pos != std::string::npos)
292  pos = pos + 1;
293  else
294  pos = 0;
295  ri_name = fqdn_name + ":" + fqdn_name.substr(pos, fqdn_name.length());
296  }
297  } else {
298  ri_name = data->vrf_name_;
299  }
300  if (ri_name != "" && ri_name != vrf_name_) {
301  if (ResetVrfDelete(table, ri_name))
302  vrf_name_ = ri_name;
303  }
304  }
305 
311 
312  if (metadata_ip_active_ != old_metadata_ip_active) {
313  ret = true;
314  }
315 
316  if (metadata_l2_active_ != old_metadata_l2_active) {
317  ret = true;
318  }
319 
320  if (ipv4_active_ != old_ipv4_active) {
321  InterfaceTable *intf_table = static_cast<InterfaceTable *>(get_table());
322  if (ipv4_active_)
323  intf_table->incr_active_vmi_count();
324  else
325  intf_table->decr_active_vmi_count();
326  ret = true;
327  }
328 
329  if (ipv6_active_ != old_ipv6_active) {
330  ret = true;
331  }
332 
333  if (l2_active_ != old_l2_active) {
334  ret = true;
335  }
336 
338  if (policy_enabled_ != old_policy) {
339  ret = true;
340  }
341 
342  //Update DHCP and DNS flag in Interface Class.
343  if (dhcp_enable_) {
344  dhcp_enabled_ = true;
345  } else {
346  dhcp_enabled_ = false;
347  }
348 
349  //Update DHCP and DNS flag for v6 in Interface Class.
350  if (dhcp_enable_v6_) {
351  dhcp_enabled_v6_ = true;
352  }else {
353  dhcp_enabled_v6_ = false;
354  }
355 
357  dns_enabled_ = true;
358  else
359  dns_enabled_ = false;
360 
361  // Compute service-ip for the interface
363 
364  // Add/Update L2
365  if (l2_active_) {
366  UpdateL2();
367  }
368 
369  // Apply config based on old and new values
370  ApplyConfig(old_ipv4_active, old_l2_active, old_ipv6_active,
371  old_subnet, old_subnet_plen);
372 
373  // Check if Healthcheck service resync is required
375  return ret;
376 }
377 
378 
379 // Apply the latest configuration
380 void VmInterface::ApplyConfig(bool old_ipv4_active, bool old_l2_active,
381  bool old_ipv6_active,
382  const Ip4Address &old_subnet,
383  uint8_t old_subnet_plen) {
386 
387  // For following intf type we dont generate any things like l2 routes,
388  // l3 routes etc
389  // VM_SRIOV, VMI_ON_LR
392  l2_force_op = VmInterfaceState::DEL;
393  l3_force_op = VmInterfaceState::DEL;
394  }
395 
397  // PHASE-1 Updates follows.
398  //
399  // Changes independnt of any state
400  // NOTE: Dont move updates below across PHASE-1 block
402 
403  // DHCP MAC IP binding
404  UpdateState(mac_vm_binding_state_.get(), l2_force_op, l3_force_op);
405 
406  Agent *agent = static_cast<InterfaceTable *>(get_table())->agent();
407  //Update security group and tag list first so that route can
408  //build the tag list and security group list
409  sg_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
410  tag_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
411 
412  // Fat flow configuration
414 
415  // Bridge Domain configuration
417  if (bridge_domain_list_.list_.size() == 0) {
418  pbb_interface_ = false;
419  }
420 
421  // NOTE : The updates are independnt of any state and agent-mode. They
422  // must not move beyond this part
423 
424  // Need not apply config for TOR VMI as it is more of an inidicative
425  // interface. No route addition or NH addition happens for this interface.
426  // Also, when parent is not updated for a non-Nova interface, device type
427  // remains invalid.
428  if ((device_type_ == VmInterface::TOR ||
430  (old_subnet.is_unspecified() && old_subnet_plen == 0)) {
431  // TODO : Should force_op be set to VmInterfaceState::DEL instead?
432  return;
433  }
434 
436  // PHASE-2 Updates follows.
437  //
438  // Appy changes independent of L2/L3 modes first
439  // NOTE: Dont move updates below across PHASE-2 block
441 
442  // Update VRF Table Label
443  UpdateState(vrf_table_label_state_.get(), l2_force_op, l3_force_op);
444 
445  // Update NextHop parameters
446  UpdateState(nexthop_state_.get(), l2_force_op, l3_force_op);
447  GetNextHopInfo();
448 
449  // Add/Update L3 Metadata for v4 and v6 standards
450  UpdateState(metadata_ip_state_.get(), l2_force_op, l3_force_op);
451  UpdateState(metadata_ip6_state_.get(), l2_force_op, l3_force_op);
452 
454  // PHASE-3 Updates follows.
455  //
456  // Updates dependent on l2-active state and healtch-check-state
457  // NOTE : Dont move updates below across PHASE-3
459 
460  // Dont add any l2-states if l2 is not active
461  if (device_type() == VmInterface::TOR ||
463  l2_force_op = VmInterfaceState::DEL;
464  }
465  if (l2_active_ == false || is_hc_active_ == false) {
466  l2_force_op = VmInterfaceState::DEL;
467  }
468 
469  // Add EVPN and L3 route for do_dhcp_relay_ before instance-ip routes
470  UpdateState(interface_route_state_.get(), l2_force_op, l3_force_op);
471 
472  // Add/Update L3/L2 routes routes resulting from instance-ip
473  instance_ipv4_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
474 
475  // Add/Update L3/L2 routes routes resulting from instance-ip
476  instance_ipv6_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
477 
478  // Update floating-ip related configuration
479  floating_ip_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
480 
481  alias_ip_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
482 
483  UpdateState(resolve_route_state_.get(), l2_force_op, l3_force_op);
484 
485  static_route_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
486 
487  service_vlan_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
488 
489  vrf_assign_rule_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
490 
491  allowed_address_pair_list_.UpdateList(agent, this, l2_force_op,
492  l3_force_op);
493  receive_route_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
494  learnt_mac_ip_list_.UpdateList(agent, this, l2_force_op, l3_force_op);
495 
497  // PHASE-3 Updates follows.
498  // Only cleanup and deletes follow below
499  //
500  // NOTE : Dont move updates below across PHASE-3
502 
503  // Delete NextHop if inactive
505  GetNextHopInfo();
506 
507  // Del L3 Metadata after deleting L3 information
510 
511  // Remove floating-ip entries marked for deletion
513 
514  // Remove Alias-ip entries marked for deletion
516 
517  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
518  if (old_l2_active != l2_active_) {
519  if (l2_active_) {
520  SendTrace(table, ACTIVATED_L2);
521  } else {
522  SendTrace(table, DEACTIVATED_L2);
523  }
524  }
525 
526  if (old_ipv4_active != ipv4_active_) {
527  if (ipv4_active_) {
528  SendTrace(table, ACTIVATED_IPV4);
529  } else {
530  SendTrace(table, DEACTIVATED_IPV4);
531  }
532  }
533 
534  if (old_ipv6_active != ipv6_active_) {
535  if (ipv6_active_) {
536  SendTrace(table, ACTIVATED_IPV6);
537  } else {
538  SendTrace(table, DEACTIVATED_IPV6);
539  }
540  }
541 }
542 
544  if (device_type() == VmInterface::TOR ||
546  return;
547 
548  int new_vxlan_id = vn_.get() ? vn_->GetVxLanId() : 0;
549  if (l2_active_ && ((vxlan_id_ == 0) ||
550  (vxlan_id_ != new_vxlan_id))) {
551  vxlan_id_ = new_vxlan_id;
552  }
554 }
555 
557 // VmInterface attribute methods
560  VmInterfaceState::Op l2_force_op,
561  VmInterfaceState::Op l3_force_op) {
562  Agent *agent = static_cast<InterfaceTable *>(get_table())->agent();
563  return state->Update(agent, this, l2_force_op, l3_force_op);
564 }
565 
567  Agent *agent = static_cast<InterfaceTable *>(get_table())->agent();
568  bool ret = true;
569  if (state->l2_installed_) {
570  if (state->DeleteL2(agent, this))
571  state->l2_installed_ = false;
572  else
573  ret = false;
574  }
575  if (state->l3_installed_) {
576  if (state->DeleteL3(agent, this))
577  state->l3_installed_ = false;
578  else
579  ret = false;
580  }
581  return ret;
582 }
583 
585 // VmInterfaceAttr basic routines
588  return (new_op > old_op) ? new_op : old_op;
589 }
590 
592  Op l2_force_op, Op l3_force_op) const {
593  Op l2_op = RecomputeOp(l2_force_op, GetOpL2(agent, vmi));
594  Op l3_op = RecomputeOp(l3_force_op, GetOpL3(agent, vmi));
595 
596  if ((l2_op == DEL || l2_op == DEL_ADD) && l2_installed_) {
597  DeleteL2(agent, vmi);
598  l2_installed_ = false;
599  }
600  if ((l3_op == DEL || l3_op == DEL_ADD) && l3_installed_) {
601  DeleteL3(agent, vmi);
602  l3_installed_ = false;
603  }
604 
605  Copy(agent, vmi);
606 
607  if (l3_op == ADD || l3_op == DEL_ADD) {
608  if (AddL3(agent, vmi))
609  l3_installed_ = true;
610  }
611  if (l2_op == ADD || l2_op == DEL_ADD) {
612  if (AddL2(agent, vmi))
613  l2_installed_ = true;
614  }
615 
616  return true;
617 }
618 
619 // Force operation to be DEL if del_pending_ is set
621  const {
622  if (del_pending_ == false)
623  return op;
624 
626 }
627 
628 static bool GetIpActiveState(const IpAddress &ip, const VmInterface *vmi) {
629  if (ip.is_v6())
630  return vmi->ipv6_active();
631 
632  return vmi->ipv4_active();
633 }
634 
636 // MacVmBinding attribute method
637 // Adds a path to MacVmBinding is responsible to update flood-dhcp flag
640  VmInterfaceState(), vrf_(NULL), dhcp_enabled_(false), dhcp_enabled_v6_(false) {
641 }
642 
644 }
645 
647  const VmInterface *vmi) const {
648  if (vmi->IsActive() == false)
649  return VmInterfaceState::DEL;
650 
651  if (vrf_ != vmi->vrf())
653 
654  return VmInterfaceState::ADD;
655 }
656 
657 bool MacVmBindingState::DeleteL3(const Agent *agent, VmInterface *vmi) const {
658  BridgeAgentRouteTable *table =
660  // return if table is already marked for deletion, bridge route delete might
661  // already be processed in ReComputePathDeletion
662  if (table == NULL)
663  return true;
665  vrf_->GetName(), vmi->vm_mac(), vmi);
666  return true;
667 }
668 
669 void MacVmBindingState::Copy(const Agent *agent, const VmInterface *vmi) const {
670  vrf_ = vmi->vrf();
672 }
673 
674 bool MacVmBindingState::AddL3(const Agent *agent, VmInterface *vmi) const {
675  BridgeAgentRouteTable *table =
677  // flood_dhcp must be set in route if dhcp is disabled for interface
678  bool flood_dhcp = !vmi->dhcp_enable_config();
680  vmi->vm_mac(), vmi, flood_dhcp);
681  return true;
682 }
683 
685 // SecurityGroup routines
686 // Does not generate any new state. Only holds reference to SG for interface
689  (const SecurityGroupEntry *rhs) {
690  list_.insert(*rhs);
691 }
692 
694  (const SecurityGroupEntry *lhs, const SecurityGroupEntry *rhs) {
695 }
696 
698  (SecurityGroupEntrySet::iterator &it) {
699  it->set_del_pending(true);
700 }
701 
703 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
704  VmInterfaceState::Op l3_force_op) {
705  SecurityGroupEntrySet::iterator it = list_.begin();
706  while (it != list_.end()) {
707  SecurityGroupEntrySet::iterator prev = it++;
708  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
709  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
710  vmi->UpdateState(&(*prev), l2_op, l3_op);
711  if (prev->del_pending()) {
712  list_.erase(prev);
713  }
714  }
715 
716  return true;
717 }
718 
720  ListEntry(), VmInterfaceState(), uuid_(nil_uuid()) {
721 }
722 
724 (const SecurityGroupEntry &rhs) :
725  ListEntry(rhs.del_pending_),
726  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
727  uuid_(rhs.uuid_) {
728 }
729 
731  ListEntry(), VmInterfaceState(), uuid_(u) {
732 }
733 
735 }
736 
737 bool VmInterface::SecurityGroupEntry::operator ==
738  (const SecurityGroupEntry &rhs) const {
739  return uuid_ == rhs.uuid_;
740 }
741 
742 bool VmInterface::SecurityGroupEntry::operator()
743  (const SecurityGroupEntry &lhs, const SecurityGroupEntry &rhs) const {
744  return lhs.IsLess(&rhs);
745 }
746 
748  (const SecurityGroupEntry *rhs) const {
749  return uuid_ < rhs->uuid_;
750 }
751 
752 // Remove reference to SG when list entry is deleted. Note, the SG states are
753 // not dependent on any interface active state
755 (const Agent *agent, const VmInterface *vmi) const {
756  if (del_pending_)
758 
759  return VmInterfaceState::ADD;
760 }
761 
763  VmInterface *vmi) const {
764  if (sg_.get() != NULL)
765  return false;
766 
767  SgKey sg_key(uuid_);
768  sg_ = static_cast<SgEntry *>(agent->sg_table()->FindActiveEntry(&sg_key));
769  return true;
770 }
771 
773  VmInterface *vmi) const {
774  sg_ = NULL;
775  return true;
776 }
777 
779 // Fat Flow list routines
780 // Only updates fat-flow configuraion in interface
781 // NOTE: Its not derived from VmInterfaceState and also does not generate
782 // any new states
784 VmInterface::FatFlowEntry::FatFlowEntry(const uint8_t proto, const uint16_t p,
785  std::string ignore_addr_value,
786  FatFlowPrefixAggregateType in_prefix_aggregate,
787  IpAddress in_src_prefix, uint8_t in_src_prefix_mask,
788  uint8_t in_src_aggregate_plen,
789  IpAddress in_dst_prefix, uint8_t in_dst_prefix_mask,
790  uint8_t in_dst_aggregate_plen) :
791  protocol(proto), port(p) {
792  ignore_address = fatflow_ignore_addr_map_.find(ignore_addr_value)->second;
793  prefix_aggregate = in_prefix_aggregate;
794  src_prefix = in_src_prefix;
795  src_prefix_mask = in_src_prefix_mask;
796  src_aggregate_plen = in_src_aggregate_plen;
797  dst_prefix = in_dst_prefix;
798  dst_prefix_mask = in_dst_prefix_mask;
799  dst_aggregate_plen = in_dst_aggregate_plen;
800 }
801 
802 
804 VmInterface::FatFlowEntry::MakeFatFlowEntry(const std::string &proto, const int &port,
805  const std::string &ignore_addr_str,
806  const std::string &in_src_prefix_str, const int &in_src_prefix_mask,
807  const int &in_src_aggregate_plen,
808  const std::string &in_dst_prefix_str, const int &in_dst_prefix_mask,
809  const int &in_dst_aggregate_plen) {
810  uint8_t protocol = (uint8_t) Agent::ProtocolStringToInt(proto);
811  IpAddress src_prefix;
812  uint8_t src_prefix_mask = 0, src_aggregate_plen = 0;
813  IpAddress dst_prefix, empty_prefix, empty_prefix_v6 = IpAddress::from_string("0::0");
814  uint8_t dst_prefix_mask = 0, dst_aggregate_plen = 0;
815  FatFlowPrefixAggregateType prefix_aggregate = AGGREGATE_NONE;
816  FatFlowIgnoreAddressType ignore_address =
817  fatflow_ignore_addr_map_.find(ignore_addr_str)->second;
818  int port_num = port;
819 
820  /*
821  * Protocol is taken as 1 for both IPv4 & IPv6 and Port no should be 0 for ICMP/ICMPv6,
822  * override if we get something else from config
823  */
824  if ((protocol == IPPROTO_ICMP) || (protocol == IPPROTO_ICMPV6)) {
825  protocol = IPPROTO_ICMP;
826  port_num = 0;
827  }
828 
829  if (in_src_prefix_str.length() > 0) {
830 
831  src_prefix = IpAddress::from_string(in_src_prefix_str);
832  src_prefix_mask = in_src_prefix_mask;
833  src_aggregate_plen = in_src_aggregate_plen;
834  if (src_prefix.is_v4()) {
835  // convert to prefix
836  src_prefix = IpAddress(Address::GetIp4SubnetAddress(src_prefix.to_v4(),
837  src_prefix_mask));
838  prefix_aggregate = AGGREGATE_SRC_IPV4;
839  } else {
840  src_prefix = IpAddress(Address::GetIp6SubnetAddress(src_prefix.to_v6(),
841  src_prefix_mask));
842  prefix_aggregate = AGGREGATE_SRC_IPV6;
843  }
844  }
845  if (in_dst_prefix_str.length() > 0) {
846  dst_prefix = IpAddress::from_string(in_dst_prefix_str);
847  dst_prefix_mask = in_dst_prefix_mask;
848  dst_aggregate_plen = in_dst_aggregate_plen;
849  if (dst_prefix.is_v4()) {
850  dst_prefix = IpAddress(Address::GetIp4SubnetAddress(dst_prefix.to_v4(),
851  dst_prefix_mask));
852  } else {
853  dst_prefix = IpAddress(Address::GetIp6SubnetAddress(dst_prefix.to_v6(),
854  dst_prefix_mask));
855  }
856 
857  if (prefix_aggregate == AGGREGATE_NONE) {
858  if (dst_prefix.is_v4()) {
859  prefix_aggregate = AGGREGATE_DST_IPV4;
860  } else {
861  prefix_aggregate = AGGREGATE_DST_IPV6;
862  }
863  } else {
864  if (dst_prefix.is_v4()) {
865  prefix_aggregate = AGGREGATE_SRC_DST_IPV4;
866  } else {
867  prefix_aggregate = AGGREGATE_SRC_DST_IPV6;
868  }
869  }
870  }
871  if (ignore_address == IGNORE_SOURCE) {
872  if ((prefix_aggregate == AGGREGATE_SRC_IPV4) || (prefix_aggregate == AGGREGATE_SRC_IPV6)) {
873  src_prefix = empty_prefix;
874  src_prefix_mask = 0;
875  src_aggregate_plen = 0;
876  prefix_aggregate = AGGREGATE_NONE;
877  } else if (prefix_aggregate == AGGREGATE_SRC_DST_IPV4) {
878  src_prefix = empty_prefix;
879  src_prefix_mask = 0;
880  src_aggregate_plen = 0;
881  prefix_aggregate = AGGREGATE_DST_IPV4;
882  } else if (prefix_aggregate == AGGREGATE_SRC_DST_IPV6) {
883  src_prefix = empty_prefix_v6;
884  src_prefix_mask = 0;
885  src_aggregate_plen = 0;
886  prefix_aggregate = AGGREGATE_DST_IPV6;
887  }
888  } else if (ignore_address == IGNORE_DESTINATION) {
889  if ((prefix_aggregate == AGGREGATE_DST_IPV4) || (prefix_aggregate == AGGREGATE_DST_IPV6)) {
890  dst_prefix = empty_prefix;
891  dst_prefix_mask = 0;
892  dst_aggregate_plen = 0;
893  prefix_aggregate = AGGREGATE_NONE;
894  } else if (prefix_aggregate == AGGREGATE_SRC_DST_IPV4) {
895  dst_prefix = empty_prefix;
896  dst_prefix_mask = 0;
897  dst_aggregate_plen = 0;
898  prefix_aggregate = AGGREGATE_SRC_IPV4;
899  } else if (prefix_aggregate == AGGREGATE_SRC_DST_IPV6) {
900  dst_prefix = empty_prefix_v6;
901  dst_prefix_mask = 0;
902  dst_aggregate_plen = 0;
903  prefix_aggregate = AGGREGATE_SRC_IPV6;
904  }
905  }
906 
907  if ((in_src_prefix_str.length() == 0) && (prefix_aggregate == AGGREGATE_DST_IPV6)) {
908  src_prefix = empty_prefix_v6;
909  }
910  if ((in_dst_prefix_str.length() == 0) && (prefix_aggregate == AGGREGATE_SRC_IPV6)) {
911  dst_prefix = empty_prefix_v6;
912  }
913 
914  VmInterface::FatFlowEntry entry(protocol, port_num,
915  ignore_addr_str, prefix_aggregate, src_prefix, src_prefix_mask,
916  src_aggregate_plen, dst_prefix, dst_prefix_mask, dst_aggregate_plen);
917  return entry;
918 }
919 
921  LOG(ERROR, "Protocol:" << (int) protocol << " Port:" << port << " IgnoreAddr:" << ignore_address
922  << " PrefixAggr:" << prefix_aggregate << " SrcPrefix:" << src_prefix.to_string() << "/" << (int) src_prefix_mask
923  << " SrcAggrPlen:" << (int) src_aggregate_plen << " DstPrefix:" << dst_prefix.to_string() << "/" << (int) dst_prefix_mask
924  << " DstAggrPlen:" << (int) dst_aggregate_plen);
925 }
926 
928  list_.insert(*rhs);
929 }
930 
932  const FatFlowEntry *rhs) {
933  lhs->ignore_address = rhs->ignore_address;
935  lhs->src_prefix = rhs->src_prefix;
936  lhs->src_prefix_mask = rhs->src_prefix_mask;
938  lhs->dst_prefix = rhs->dst_prefix;
939  lhs->dst_prefix_mask = rhs->dst_prefix_mask;
941 }
942 
943 void VmInterface::FatFlowList::Remove(FatFlowEntrySet::iterator &it) {
944  it->set_del_pending(true);
945 }
946 
948  VmInterface *vmi) {
949  FatFlowEntrySet::iterator it = list_.begin();
950  while (it != list_.end()) {
951  FatFlowEntrySet::iterator prev = it++;
952  if (prev->del_pending_) {
953  list_.erase(prev);
954  }
955  }
956  return true;
957 }
958 
960  LOG(ERROR, "Dumping FatFlowList:\n");
961  for (FatFlowEntrySet::iterator it = list_.begin(); it != list_.end(); it++) {
962  it->print();
963  }
964 }
965 
967 // Bridge Domain List
968 // NOTE: Its not derived from VmInterfaceState and also does not generate
969 // any new states
972  list_.insert(*rhs);
973 }
974 
976  const BridgeDomain *rhs) {
977 }
978 
979 void VmInterface::BridgeDomainList::Remove(BridgeDomainEntrySet::iterator &it) {
980  it->set_del_pending(true);
981 }
982 
984  VmInterface *vmi) {
985  InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
986  BridgeDomainEntrySet::iterator it = list_.begin();
987  while (it != list_.end()) {
988  BridgeDomainEntrySet::iterator prev = it++;
989  if (prev->del_pending_ == false) {
990  BridgeDomainKey key(prev->uuid_);
991  prev->bridge_domain_ = static_cast<const BridgeDomainEntry *>
992  (table->agent()->bridge_domain_table()->FindActiveEntry(&key));
993  // Ignore bridge domain without VRF
994  // Interface will get config update again when VRF is created
995  if (prev->bridge_domain_->vrf() == NULL) {
996  prev->del_pending_ = true;
997  }
998  }
999 
1000  if (prev->del_pending_) {
1001  list_.erase(prev);
1002  }
1003  }
1004 
1005  return true;
1006 }
1007 
1009 // VRF Table label
1010 // Create VRF-NextHop based on interface-type. The NextHop is not explicitly
1011 // deleted. It gets deleted when reference count drops to 0
1014 }
1015 
1017 }
1018 
1020  const VmInterface *vmi) const {
1021  return VmInterfaceState::ADD;
1022 }
1023 
1024 // Take care of only adding VRF Table label. The label will be freed when
1025 // VRF is deleted
1026 bool VrfTableLabelState::AddL3(const Agent *agent, VmInterface *vmi) const {
1027  if (vmi->vrf() == NULL || vmi->vmi_type() != VmInterface::GATEWAY) {
1028  return false;
1029  }
1030 
1031  vmi->vrf()->CreateTableLabel(false, false, false, false);
1032  return false;
1033 }
1034 
1036 // NextHop attribute
1037 //
1038 // L2 nexthops:
1039 // These L2 nexthop are used by multicast and bridge. Presence of multicast
1040 // forces it to be present in ipv4 mode(l3-only).
1041 //
1042 // L3 nexthops:
1043 // Also creates L3 interface NH, if layer3_forwarding is set.
1044 // It does not depend on oper state of ip forwarding.
1045 // Needed as health check can disable oper ip_active and will result in flow
1046 // key pointing to L2 interface NH. This has to be avoided as interface still
1047 // points to l3 nh and flow should use same. For this fix it is also required
1048 // that l3 i/f nh is also created on seeing config and not oper state of l3.
1049 // Reason being if vmi(irrespective of health check) is coming up and
1050 // transitioning from ipv4_inactive to ip4_active and during this transition
1051 // a flow is added then flow_key in vmi will return null because l3 config is
1052 // set and interface nh not created yet.
1055 }
1056 
1058 }
1059 
1060 // The nexthops are deleted after all update processing by explicitly
1061 // calling delete. So, dont return DEL operation from here
1063  const VmInterface *vmi) const {
1064  if (vmi->IsActive() == false)
1066  return VmInterfaceState::ADD;
1067 }
1068 
1069 // The nexthops must be deleted after all update processing. So, dont return
1070 // DEL operation from here
1072  const VmInterface *vmi) const {
1073  if ((vmi->IsActive() == false) || (vmi->layer3_forwarding() == false))
1075 
1076  return VmInterfaceState::ADD;
1077 }
1078 
1079 bool NextHopState::AddL2(const Agent *agent, VmInterface *vmi) const {
1081  vmi->forwarding_vrf()->GetName(),
1082  vmi->learning_enabled(),
1083  vmi->etree_leaf(),
1084  vmi->layer2_control_word(),
1085  vmi->name());
1086 
1088  vmi->GetUuid(), vmi->name()),
1089  true, InterfaceNHFlags::BRIDGE, vmi->vm_mac());
1090  l2_nh_policy_ = static_cast<NextHop *>
1091  (agent->nexthop_table()->FindActiveEntry(&key1));
1092 
1094  vmi->GetUuid(), vmi->name()),
1095  false, InterfaceNHFlags::BRIDGE, vmi->vm_mac());
1096  l2_nh_no_policy_ = static_cast<NextHop *>
1097  (agent->nexthop_table()->FindActiveEntry(&key2));
1098 
1099  // Update L2 mpls label from nh entry
1100  if (vmi->policy_enabled()) {
1101  l2_label_ = l2_nh_policy_->mpls_label()->label();
1102  } else {
1103  l2_label_ = l2_nh_no_policy_->mpls_label()->label();
1104  }
1105 
1106  return true;
1107 }
1108 
1109 bool NextHopState::DeleteL2(const Agent *agent, VmInterface *vmi) const {
1110  // Delete is called independent of interface active-state.
1111  // Dont delete NH if interface is still active
1112  if (vmi->IsActive())
1113  return false;
1114 
1115  l2_nh_policy_.reset();
1116  l2_nh_no_policy_.reset();
1119  vmi->name());
1120  return true;
1121 }
1122 
1123 bool NextHopState::AddL3(const Agent *agent, VmInterface *vmi) const {
1125  vmi->forwarding_vrf()->GetName(),
1126  vmi->learning_enabled(),
1127  vmi->name());
1128 
1130  vmi->forwarding_vrf()->GetName(),
1131  vmi->name());
1132 
1134  vmi->GetUuid(), vmi->name()),
1135  true, InterfaceNHFlags::INET4, vmi->vm_mac());
1136  l3_nh_policy_ = static_cast<NextHop *>
1137  (agent->nexthop_table()->FindActiveEntry(&key1));
1138 
1140  vmi->GetUuid(), vmi->name()),
1141  false, InterfaceNHFlags::INET4, vmi->vm_mac());
1142  l3_nh_no_policy_ = static_cast<NextHop *>
1143  (agent->nexthop_table()->FindActiveEntry(&key2));
1144 
1146  vmi->GetUuid(), vmi->name()), false,
1149  vmi->vm_mac());
1150  l3_mcast_nh_no_policy_ = static_cast<NextHop *>
1151  (agent->nexthop_table()->FindActiveEntry(&key3));
1152 
1153  // Update L3 mpls label from nh entry
1154  if (vmi->policy_enabled()) {
1155  l3_label_ = l3_nh_policy_->mpls_label()->label();
1156  } else {
1157  l3_label_ = l3_nh_no_policy_->mpls_label()->label();
1158  }
1159 
1160  return true;
1161 }
1162 
1163 bool NextHopState::DeleteL3(const Agent *agent, VmInterface *vmi) const {
1164  // Delete is called independent of interface active-state.
1165  // Keep NH as long as interface is active and layer3-forwarding is enabled
1166  // TODO : It should be ok to keep the NH even if l3-forwarding is disabled?
1167  if (vmi->IsActive() && vmi->layer3_forwarding())
1168  return false;
1169 
1170  l3_mcast_nh_no_policy_.reset();
1171  l3_nh_policy_.reset();
1172  l3_nh_no_policy_.reset();
1175  vmi->name());
1176  InterfaceNH::DeleteL3InterfaceNH(vmi->GetUuid(), vmi->vm_mac(), vmi->name());
1177  return true;
1178 }
1179 
1181  return nexthop_state_->l3_nh_no_policy_.get();
1182 }
1183 
1185  return nexthop_state_->l2_nh_no_policy_.get();
1186 }
1187 
1189  return nexthop_state_->l2_nh_policy_.get();
1190 }
1191 
1192 uint32_t VmInterface::label_op() const {
1193  Agent *agent = static_cast<InterfaceTable *>(get_table())->agent();
1194  if (nexthop_state_->GetOpL3(agent, this) == VmInterfaceState::INVALID)
1195  return MplsTable::kInvalidLabel;
1196 
1197  if (policy_enabled_)
1198  return nexthop_state_->l3_nh_no_policy_->mpls_label()->label();
1199  else
1200  return nexthop_state_->l3_nh_policy_->mpls_label()->label();
1201 }
1202 
1204  l2_label_ = nexthop_state_->l2_label();
1205  label_ = nexthop_state_->l3_label();
1206  // If Layer3 forwarding is configured irrespective of ipv4/v6 status,
1207  // flow_key_nh should be l3 based.
1208  if (layer3_forwarding()) {
1209  flow_key_nh_ = nexthop_state_->l3_nh_policy_;
1210  } else {
1211  flow_key_nh_ = nexthop_state_->l2_nh_policy_;
1212  }
1213 }
1214 
1216 // MetaData Ip Routines
1219 :
1220 VmInterfaceState(), mdata_ip_(), ipv4_(ipv4) {
1221 }
1222 
1224  mdata_ip_.reset(NULL);
1225 }
1226 
1227 // metadata-ip is deleted after all update processing by explicitly
1228 // calling delete. So, dont return DEL operation from here
1230  const VmInterface *vmi) const {
1231  if (vmi->need_linklocal_ip() == false ||
1232  vmi->metadata_ip_active() == false)
1234 
1235  return VmInterfaceState::ADD;
1236 }
1237 
1238 bool MetaDataIpState::AddL3(const Agent *agent, VmInterface *vmi) const {
1239  if (mdata_ip_.get() == NULL) {
1240  mdata_ip_.reset(new MetaDataIp(
1241  ipv4_ ? agent->metadata_ip_allocator() :
1242  agent->metadata_ip6_allocator(),
1243  vmi,
1244  vmi->id(), ipv4_));
1245  }
1246  mdata_ip_->set_active(true);
1247  vmi->UpdateMetaDataIpInfo();
1248  return true;
1249 }
1250 
1251 // Delete meta-data route
1252 bool MetaDataIpState::DeleteL3(const Agent *agent, VmInterface *vmi) const {
1253  if (vmi->metadata_ip_active() && vmi->need_linklocal_ip())
1254  return false;
1255 
1256  if (mdata_ip_.get() == NULL) {
1257  return true;
1258  }
1259 
1260  // Call UpdateMetaDataIpInfo before setting mdata_ip_ state to inactive
1261  vmi->UpdateMetaDataIpInfo();
1262  mdata_ip_->set_active(false);
1263  return true;
1264 }
1265 
1267  if (metadata_ip_state_.get() == NULL)
1268  return Ip4Address(0);
1269 
1270  if (metadata_ip_state_->mdata_ip_.get() == NULL) {
1271  return Ip4Address(0);
1272  }
1273 
1274  return metadata_ip_state_->mdata_ip_->GetLinkLocalIp4();
1275 }
1276 
1278  if (metadata_ip6_state_.get() == NULL)
1279  return Ip6Address();
1280 
1281  if (metadata_ip6_state_->mdata_ip_.get() == NULL) {
1282  return Ip6Address();
1283  }
1284 
1285  return metadata_ip6_state_->mdata_ip_->GetLinkLocalIp6();
1286 }
1287 
1289 // ResolveRoute Attribute Routines
1292  VmInterfaceState(), vrf_(NULL), subnet_(), plen_(0) {
1293 }
1294 
1296 }
1297 
1298 void ResolveRouteState::Copy(const Agent *agent, const VmInterface *vmi) const {
1299  vrf_ = vmi->forwarding_vrf();
1300  subnet_ = vmi->subnet();
1301  plen_ = vmi->subnet_plen();
1302 }
1303 
1305  const VmInterface *vmi) const {
1306  if (vmi->ipv4_active() == false)
1307  return VmInterfaceState::DEL;
1308 
1309  if (vrf_ != vmi->forwarding_vrf() || subnet_ != vmi->subnet() ||
1310  plen_ != vmi->subnet_plen())
1312 
1313  return VmInterfaceState::ADD;
1314 }
1315 
1316 bool ResolveRouteState::DeleteL3(const Agent *agent, VmInterface *vmi) const {
1317  if (vrf_ == NULL)
1318  return false;
1319 
1320  vmi->DeleteRoute(vrf_->GetName(), subnet_, plen_);
1321  return true;
1322 }
1323 
1324 bool ResolveRouteState::AddL3(const Agent *agent, VmInterface *vmi) const {
1325  /* No need to add resolve route for VHOST in case of l3mh */
1326  if (agent && agent->is_l3mh() && vmi->vmi_type() == VmInterface::VHOST) {
1327  return true;
1328  }
1329 
1330  if (vrf_ == NULL || subnet_.is_unspecified())
1331  return false;
1332 
1333  if (vmi->vmi_type() != VmInterface::VHOST) {
1334  if (vmi->vn() == NULL) {
1335  return false;
1336  }
1337  }
1338 
1339  SecurityGroupList sg_id_list;
1340  vmi->CopySgIdList(&sg_id_list);
1341 
1342  TagList tag_id_list;
1343  vmi->CopyTagIdList(&tag_id_list);
1344 
1345  std::string vn_name;
1346  if (vmi->vn() != NULL) {
1347  vn_name = vmi->vn()->GetName();
1348  }
1349 
1350  bool policy = vmi->policy_enabled();
1351  if (vmi->vmi_type() == VmInterface::VHOST) {
1352  policy = false;
1353  }
1354 
1355  VmInterfaceKey key(AgentKey::ADD_DEL_CHANGE, vmi->GetUuid(), vmi->name());
1357  (vmi->peer(), vrf_->GetName(),
1359  vrf_->table_label(), policy, vn_name,
1360  sg_id_list, tag_id_list);
1361  return true;
1362 }
1363 
1364 // If the interface is Gateway we need to add a receive route,
1365 // such the packet gets routed. Bridging on gateway
1366 // interface is not supported
1368  const VmInterface *vmi) const {
1369  if ((vmi->vmi_type() != VmInterface::GATEWAY &&
1370  vmi->vmi_type() != VmInterface::REMOTE_VM))
1371  return VmInterfaceState::DEL;
1372 
1373  if (vmi->bridging() == false)
1374  return VmInterfaceState::DEL;
1375 
1376  if (vrf_ != vmi->forwarding_vrf())
1378 
1379  return VmInterfaceState::ADD;
1380 }
1381 
1382 bool ResolveRouteState::DeleteL2(const Agent *agent, VmInterface *vmi) const {
1383  if (vrf_ == NULL)
1384  return false;
1385 
1387  vmi->GetVifMac(agent), 0);
1388  return true;
1389 }
1390 
1391 bool ResolveRouteState::AddL2(const Agent *agent, VmInterface *vmi) const {
1392  if (vrf_ == NULL || vmi->vn() == NULL)
1393  return false;
1394 
1395  BridgeAgentRouteTable *table = static_cast<BridgeAgentRouteTable *>
1397  table->AddBridgeReceiveRoute(vmi->peer(), vrf_->GetName(), 0,
1398  vmi->GetVifMac(agent), vmi->vn()->GetName());
1399  return true;
1400 }
1401 
1403 // VmiRouteState Routines
1404 // This is responsible to manage following routes,
1405 // - Manages the <0.0.0.0, MAC> EVPN route for the interface
1406 // - Manage the L3 route for dhcp-relay when do_dhcp_relay_ is enabled
1407 // ip_ here is set to primary-ip when do_dhcp_relay_ is enabled
1408 // When do_dhcp_relay_ is enabled, adds route for ip_ along with service-ip.
1409 //
1410 // Note, instance-ip can also potentially add/delete route for same ip-address
1413  VmInterfaceState(), vrf_(NULL), ip_(), ethernet_tag_(0),
1414  do_dhcp_relay_(false) {
1415 }
1416 
1418 }
1419 
1420 void VmiRouteState::Copy(const Agent *agent, const VmInterface *vmi) const {
1421  vrf_ = vmi->vrf();
1422  ethernet_tag_ = vmi->ethernet_tag();
1423  do_dhcp_relay_ = vmi->do_dhcp_relay();
1424  ip_ = do_dhcp_relay_ ? ip_ = vmi->dhcp_addr() : Ip4Address(0);
1425 }
1426 
1428 (const Agent *agent, const VmInterface *vmi) const {
1429  if (vmi->ipv4_active() == false)
1430  return VmInterfaceState::DEL;
1431 
1432  // On do_dhcp_relay_ change from enable to disbale, delete the route
1433  // Normally, we should not look at old value of do_dhcp_relay_ here, but
1434  // ignoring it will result in delete and add of route for primary-ip
1435  // Check old value of do_dhcp_relay_ to avoid this
1436  //
1437  // Even on transition, if instance-ip is present matching the primary-ip
1438  // the route will added again due to instance-ip later
1439  if (do_dhcp_relay_ && vmi->do_dhcp_relay() == false)
1440  return VmInterfaceState::DEL;
1441 
1442  if (vrf_ != vmi->vrf())
1444 
1445  if (ip_ != vmi->dhcp_addr())
1447 
1448  // Dont have to add L3 route if DHCP Relay not enabled
1449  if (vmi->do_dhcp_relay() == false)
1451 
1452  return VmInterfaceState::ADD;
1453 }
1454 
1455 bool VmiRouteState::DeleteL3(const Agent *agent, VmInterface *vmi) const {
1456  if (vrf_ == NULL || ip_.is_unspecified())
1457  return false;
1458 
1459  vmi->DeleteRoute(vrf_->GetName(), ip_, 32);
1460  return true;
1461 }
1462 
1463 bool VmiRouteState::AddL3(const Agent *agent, VmInterface *vmi) const {
1464  if (vrf_ == NULL || vmi->vn() == NULL || ip_.is_unspecified())
1465  return false;
1466 
1467  /* expected only for instance IP */
1468  vmi->AddRoute(vrf_->GetName(), ip_, 32, vmi->vn()->GetName(), false,
1469  vmi->ecmp(), false, false, vmi->vm_ip_service_addr(),
1470  Ip4Address(0), CommunityList(), vmi->label(),
1472  return true;
1473 }
1474 
1476 (const Agent *agent, const VmInterface *vmi) const {
1477  if (vmi->l2_active() == false || vmi->is_hc_active() == false)
1478  return VmInterfaceState::DEL;
1479 
1480  if (vrf_ != vmi->vrf())
1482 
1483  if (ethernet_tag_ != vmi->ethernet_tag())
1485 
1486  return VmInterfaceState::ADD;
1487 }
1488 
1489 bool VmiRouteState::DeleteL2(const Agent *agent, VmInterface *vmi) const {
1490  if (vrf_ == NULL)
1491  return false;
1492 
1494  vmi->vm_mac());
1495  return true;
1496 }
1497 
1498 bool VmiRouteState::AddL2(const Agent *agent, VmInterface *vmi) const {
1499  if (vrf_ == NULL || vmi->vn() == NULL)
1500  return false;
1501 
1502  vmi->AddL2InterfaceRoute(Ip4Address(), vmi->vm_mac(), Ip4Address(0));
1503  BridgeAgentRouteTable *table =
1505  if(table != NULL){
1506  if(table->FindRoute(agent->vrrp_mac())){
1507  return true;
1508  }else{
1509  table->AddBridgeReceiveRoute(agent->local_vm_peer(),
1510  vrf_->GetName(),
1511  0,
1512  agent->vrrp_mac(),
1513  "");
1514  }
1515  }
1516  return true;
1517 }
1518 
1520 // InstanceIp routines. Manages following,
1521 // - Manages the L3 and L2 routes derived from the instance-ip.
1524  list_.insert(*rhs);
1525 }
1526 
1528  const InstanceIp *rhs) {
1529  lhs->ecmp_ = rhs->ecmp_;
1530  lhs->is_service_ip_ = rhs->is_service_ip_;
1532  lhs->is_local_ = rhs->is_local_;
1533  lhs->tracking_ip_ = rhs->tracking_ip_;
1534 
1535  lhs->set_del_pending(false);
1536 }
1537 
1538 void VmInterface::InstanceIpList::Remove(InstanceIpSet::iterator &it) {
1539  it->set_del_pending(true);
1540 }
1541 
1543 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
1544  VmInterfaceState::Op l3_force_op) {
1545  InstanceIpSet::iterator it = list_.begin();
1546  // Apply the instance-ip configured for interface
1547  while (it != list_.end()) {
1548  InstanceIpSet::iterator prev = it++;
1549  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
1550  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
1551  if (prev->del_pending() == false)
1552  prev->SetPrefixForAllocUnitIpam(vmi);
1553  vmi->UpdateState(&(*prev), l2_op, l3_op);
1554  if (prev->del_pending()) {
1555  list_.erase(prev);
1556  }
1557  }
1558 
1559  return true;
1560 }
1561 
1563  ListEntry(), VmInterfaceState(), ip_(), plen_(), ecmp_(false),
1564  is_primary_(false), is_service_ip_(false),
1565  is_service_health_check_ip_(false), is_local_(false),
1566  tracking_ip_(), vrf_(NULL), ethernet_tag_(0) {
1567 }
1568 
1570  ListEntry(rhs.del_pending_),
1571  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
1572  ip_(rhs.ip_), plen_(rhs.plen_), ecmp_(rhs.ecmp_),
1573  is_primary_(rhs.is_primary_), is_service_ip_(rhs.is_service_ip_),
1574  is_service_health_check_ip_(rhs.is_service_health_check_ip_),
1575  is_local_(rhs.is_local_), tracking_ip_(rhs.tracking_ip_),
1576  vrf_(NULL), ethernet_tag_(0) {
1577 }
1578 
1580  bool ecmp, bool is_primary,
1581  bool is_service_ip,
1582  bool is_service_health_check_ip,
1583  bool is_local,
1584  const IpAddress &tracking_ip) :
1585  ListEntry(), VmInterfaceState(), ip_(addr), plen_(plen), ecmp_(ecmp),
1586  is_primary_(is_primary), is_service_ip_(is_service_ip),
1587  is_service_health_check_ip_(is_service_health_check_ip),
1588  is_local_(is_local), tracking_ip_(tracking_ip), vrf_(NULL),
1589  ethernet_tag_(0) {
1590 }
1591 
1593 }
1594 
1596  const InstanceIp &rhs) const {
1597  return lhs.IsLess(&rhs);
1598 }
1599 
1601  return ip_ < rhs->ip_;
1602 }
1603 
1605  if (vmi->vn() == NULL)
1606  return;
1607 
1608  uint32_t alloc_unit = vmi->vn()->GetAllocUnitFromIpam(ip_);
1609 
1610  uint8_t alloc_prefix = 0;
1611  if (alloc_unit > 0) {
1612  alloc_prefix = log2(alloc_unit);
1613  }
1614 
1615  if (ip_.is_v4()) {
1616  plen_ = Address::kMaxV4PrefixLen - alloc_prefix;
1617  } else if (ip_.is_v6()) {
1618  plen_ = Address::kMaxV6PrefixLen - alloc_prefix;
1619  }
1620 }
1621 
1622 static bool GetInstanceIpActiveState(const VmInterface::InstanceIp *instance_ip,
1623  const VmInterface *vmi) {
1624  if (instance_ip->is_service_health_check_ip_) {
1625  // for service health check instance ip keep the route based on
1626  // metadata-active state
1627  return vmi->metadata_ip_active();
1628  }
1629 
1630  if (instance_ip->ip_.is_v6()) {
1631  return vmi->ipv6_active();
1632  }
1633 
1634  return vmi->ipv4_active();
1635 }
1636 
1638 (const Agent *agent, const VmInterface *vmi) const {
1639  if (GetInstanceIpActiveState(this, vmi) == false)
1640  return VmInterfaceState::DEL;
1641 
1642  if (!is_service_ip_ && vmi->vmi_type() != VmInterface::VHOST) {
1643  // Add route only when vn IPAM exists for the IP
1644  if (vmi->vn() && vmi->vn()->GetIpam(ip_) == NULL)
1645  return VmInterfaceState::DEL;
1646  }
1647 
1648  if (IsL3Only())
1649  return VmInterfaceState::DEL;
1650 
1651  if (vrf_ != vmi->vrf())
1653 
1654  if (ethernet_tag_ != vmi->ethernet_tag())
1656 
1657  return VmInterfaceState::ADD;
1658 }
1659 
1661  VmInterface *vmi) const {
1662  if (vrf_ == NULL)
1663  return false;
1664 
1665  vmi->AddL2InterfaceRoute(ip_, vmi->vm_mac(), tracking_ip_);
1666  return true;
1667 }
1668 
1670  VmInterface *vmi) const {
1671  if (vrf_ == NULL)
1672  return false;
1673 
1674  vmi->DeleteL2InterfaceRoute(vrf_, ethernet_tag_, ip_, vmi->vm_mac());
1675  return true;
1676 }
1677 
1679 (const Agent *agent, const VmInterface *vmi) const {
1680  // TODO : Should be check health-check state here?
1681  if (GetInstanceIpActiveState(this, vmi) == false)
1682  return VmInterfaceState::DEL;
1683 
1684  if (!is_service_ip_ && vmi->vmi_type() != VmInterface::VHOST) {
1685  // Add route only when vn IPAM exists for the IP
1686  if (vmi->vn() && vmi->vn()->GetIpam(ip_) == NULL)
1687  return VmInterfaceState::DEL;
1688  }
1689 
1690  if (vrf_ != vmi->vrf())
1692 
1693  return VmInterfaceState::ADD;
1694 }
1695 
1697  VmInterface *vmi) const {
1698  if (vrf_ == NULL)
1699  return false;
1700  assert(ip_.is_unspecified() == false);
1701  std::string vn_name;
1702  if (vmi->vn()) {
1703  vn_name = vmi->vn()->GetName();
1704  } else if (vmi->vmi_type() == VHOST) {
1705  vn_name = agent->fabric_vn_name();
1706  }
1707 
1708  vmi->AddRoute(vmi->vrf()->GetName(), ip_, plen_, vn_name,
1709  is_force_policy(), ecmp_,is_local_,
1710  is_service_health_check_ip_, vmi->GetServiceIp(ip_),
1711  tracking_ip_, CommunityList(), vmi->label(),
1712  is_service_ip_ ? kServiceInterface : kInterface);
1713  return true;
1714 }
1715 
1717  VmInterface *vmi) const {
1718  if (vrf_ == NULL)
1719  return false;
1720  vmi->DeleteRoute(vrf_->GetName(), ip_, plen_);
1721  return true;
1722 }
1723 
1725  const VmInterface *vmi) const {
1726  vrf_ = vmi->vrf();
1727  ethernet_tag_ = vmi->ethernet_tag();
1728 }
1729 
1731 // MacIp routines. Manages following,
1732 // - Manages the L3 and L2 routes derived from the instance-ip.
1735  list_.insert(*rhs);
1736 }
1737 
1739  const LearntMacIp *rhs) {
1740 
1741  lhs->set_del_pending(rhs->del_pending());
1742 }
1743 
1745  LearntMacIpSet::iterator it = list_.find(*rhs);
1746  if (it != list_.end()) {
1747  it->set_del_pending(true);
1748  }
1749 }
1750 
1752 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
1753  VmInterfaceState::Op l3_force_op) {
1754  LearntMacIpSet::iterator it = list_.begin();
1755  // Apply the instance-ip configured for interface
1756  while (it != list_.end()) {
1757  LearntMacIpSet::iterator prev = it++;
1758  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
1759  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
1760  vmi->UpdateState(&(*prev), l2_op, l3_op);
1761  if (prev->del_pending()) {
1762  list_.erase(prev);
1763  }
1764  }
1765 
1766  return true;
1767 }
1768 
1770  ListEntry(), VmInterfaceState(), ip_(), mac_(),
1771  vrf_(NULL), ethernet_tag_(0) {
1772 }
1773 
1775  ListEntry(rhs.del_pending_),
1776  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
1777  ip_(rhs.ip_), mac_(rhs.mac_),
1778  vrf_(NULL), ethernet_tag_(0) {
1779 }
1780 
1782  const MacAddress &mac) :
1783  ListEntry(), VmInterfaceState(), ip_(ip_addr), mac_(mac),
1784  vrf_(NULL), ethernet_tag_(0) {
1785 }
1786 
1788 }
1789 
1791  const VmInterface *vmi) {
1792  // supporting either L2 mode and L2/L3 mode
1793  if (!vmi->l2_active()) {
1794  return false;
1795  }
1796  if (mac_ip->ip_.is_v6()) {
1797  return vmi->ipv6_active();
1798  }
1799 
1800  return vmi->ipv4_active();
1801 }
1803  const LearntMacIp &rhs) const {
1804  return lhs.IsLess(&rhs);
1805 }
1806 
1808  return ip_ < rhs->ip_;
1809 }
1810 
1812 (const Agent *agent, const VmInterface *vmi) const {
1813  if (del_pending() == true)
1814  return VmInterfaceState::DEL;
1815 
1816 
1817  if (vrf_ != vmi->vrf())
1819 
1820  if (ethernet_tag_ != vmi->ethernet_tag())
1822 
1823  return VmInterfaceState::ADD;
1824 }
1825 
1827  VmInterface *vmi) const {
1828  // IPVLAN subinterface will have the same mac as the parent interface mac
1829  // skip adding the route, as these routes are already installed as part
1830  // of parent interface add.
1831  if (mac_.ToString() == vmi->vm_mac().ToString())
1832  return true;
1833 
1834  if (vrf_ == NULL)
1835  return false;
1837  vmi->forwarding_vrf()->GetName(),
1838  vmi->learning_enabled(),
1839  vmi->etree_leaf(),
1840  vmi->layer2_control_word(),
1841  vmi->name());
1842 
1844  vmi->GetUuid(), vmi->name()),
1845  true, InterfaceNHFlags::BRIDGE, mac_);
1846  l2_nh_policy_ = static_cast<NextHop *>
1847  (agent->nexthop_table()->FindActiveEntry(&key1));
1848 
1850  vmi->GetUuid(), vmi->name()),
1851  false, InterfaceNHFlags::BRIDGE, mac_);
1852  l2_nh_no_policy_ = static_cast<NextHop *>
1853  (agent->nexthop_table()->FindActiveEntry(&key2));
1854 
1855  // Update L2 mpls label from nh entry
1856  if (vmi->policy_enabled()) {
1857  l2_label_ = l2_nh_policy_->mpls_label()->label();
1858  } else {
1859  l2_label_ = l2_nh_no_policy_->mpls_label()->label();
1860  }
1861 
1862  vmi->AddL2InterfaceRoute(IpAddress(), mac_, IpAddress());
1863  return true;
1864 }
1865 
1867  VmInterface *vmi) const {
1868  if (vrf_ == NULL)
1869  return false;
1870 
1871  // IPVLAN subinterface will have the same mac as the parent interface mac
1872  // skip deleting the route as the parent interface is not deleted.
1873  if (mac_.ToString() == vmi->vm_mac().ToString())
1874  return true;
1875 
1877  mac_);
1878  l2_nh_policy_.reset();
1879  l2_nh_no_policy_.reset();
1882  vmi->name());
1883  return true;
1884 }
1885 
1887 (const Agent *agent, const VmInterface *vmi) const {
1888  // TODO : Should be check health-check state here?
1889  if (GetMacIpActiveState(this, vmi) == false)
1890  return VmInterfaceState::DEL;
1891 
1892  if (vrf_ != vmi->vrf())
1894 
1895  if (ethernet_tag_ != vmi->ethernet_tag())
1897 
1898  return VmInterfaceState::ADD;
1899 }
1900 
1902  VmInterface *vmi) const {
1903  if (vrf_ == NULL)
1904  return false;
1906  vmi->forwarding_vrf()->GetName(),
1907  vmi->learning_enabled(),
1908  vmi->name());
1910  vmi->GetUuid(), vmi->name()),
1911  true, InterfaceNHFlags::INET4, mac_);
1912  l3_nh_policy_ = static_cast<NextHop *>
1913  (agent->nexthop_table()->FindActiveEntry(&key1));
1914 
1916  vmi->GetUuid(), vmi->name()),
1917  false, InterfaceNHFlags::INET4, mac_);
1918  l3_nh_no_policy_ = static_cast<NextHop *>
1919  (agent->nexthop_table()->FindActiveEntry(&key2));
1920  // Update L3 mpls label from nh entry
1921  if (vmi->policy_enabled()) {
1922  l3_label_ = l3_nh_policy_->mpls_label()->label();
1923  } else {
1924  l3_label_ = l3_nh_no_policy_->mpls_label()->label();
1925  }
1926  std::string vn_name;
1927  if (vmi->vn()) {
1928  vn_name = vmi->vn()->GetName();
1929  }
1930  uint32_t plen = 0;
1931  if (ip_.is_v4()) {
1932  plen = Address::kMaxV4PrefixLen;
1933  } else {
1934  plen = Address::kMaxV6PrefixLen;
1935  }
1936 
1937 
1938  vmi->AddL2InterfaceRoute(ip_, mac_, IpAddress());
1939  vmi->AddRoute(vrf_->GetName(), ip_, plen, vmi->vn()->GetName(), false,
1940  false, false, false, vmi->vm_ip_service_addr(),
1941  Ip4Address(0), CommunityList(), l3_label_,
1942  VmInterface::kInterface, true);
1943  return true;
1944 }
1945 
1947  VmInterface *vmi) const {
1948  if (vrf_ == NULL)
1949  return false;
1950  uint32_t plen = 0;
1951  if (ip_.is_v4()) {
1952  plen = Address::kMaxV4PrefixLen;
1953  } else {
1954  plen = Address::kMaxV6PrefixLen;
1955  }
1956  vmi->DeleteL2InterfaceRoute(vrf_, ethernet_tag_, ip_, mac_);
1957  vmi->DeleteRoute(vrf_->GetName(), ip_, plen);
1959  mac_, vmi->name());
1960  l3_nh_policy_.reset();
1961  l3_nh_no_policy_.reset();
1962  return true;
1963 }
1964 
1966  const VmInterface *vmi) const {
1967  vrf_ = vmi->vrf();
1968  ethernet_tag_ = vmi->ethernet_tag();
1969 }
1970 
1972  if (learnt_mac_ip_list_.list_.size() >= kMaxMacIpLimit) {
1973  return true;
1974  }
1975  return false;
1976 }
1978 // FloatingIp routines
1981  InterfaceTable *table = static_cast<InterfaceTable *>(get_table());
1982  FloatingIpSet::iterator it = floating_ip_list_.list_.begin();
1983  while (it != floating_ip_list_.list_.end()) {
1984  FloatingIpSet::iterator prev = it++;
1985  if (prev->del_pending_ == false)
1986  continue;
1987 
1988  // The floating-ip is leaving the interface configuration, which is
1989  // the only trigger that withdraws its DNS record. DeleteL3() does not
1990  // withdraw, so that the record survives the instance being powered
1991  // off, and an entry configured while the interface was inactive never
1992  // reached DeleteL3() in the first place.
1993  //
1994  // vn_ has been reset by FloatingIp::Copy() by now, hence the lookup by
1995  // uuid. It returns NULL once the VN is deleted, which is not a missed
1996  // withdraw: DnsProto::VnNotify() withdraws and erases every record of
1997  // a deleted VN, so there is nothing left to withdraw by then.
1998  if (table->update_floatingip_cb().empty() == false) {
1999  VnEntry *vn = table->FindVnRef(prev->vn_uuid_);
2000  if (vn != NULL) {
2001  table->update_floatingip_cb()(this, vn, prev->floating_ip_,
2002  true);
2003  }
2004  }
2005 
2006  if (prev->floating_ip_.is_v4()) {
2008  assert(floating_ip_list_.v4_count_ >= 0);
2009  } else {
2011  assert(floating_ip_list_.v6_count_ >= 0);
2012  }
2013  floating_ip_list_.list_.erase(prev);
2014  }
2015 }
2016 
2018  std::pair<FloatingIpSet::iterator, bool> ret = list_.insert(*rhs);
2019  if (ret.second) {
2020  if (rhs->floating_ip_.is_v4()) {
2021  v4_count_++;
2022  } else {
2023  v6_count_++;
2024  }
2025  }
2026 }
2027 
2029  const FloatingIp *rhs) {
2030  if (lhs->fixed_ip_ != rhs->fixed_ip_) {
2031  lhs->fixed_ip_ = rhs->fixed_ip_;
2032  }
2033 
2034  lhs->direction_ = rhs->direction_;
2036  lhs->src_port_map_ = rhs->src_port_map_;
2037  lhs->dst_port_map_ = rhs->dst_port_map_;
2038  lhs->set_del_pending(false);
2039 }
2040 
2041 void VmInterface::FloatingIpList::Remove(FloatingIpSet::iterator &it) {
2042  it->set_del_pending(true);
2043 }
2044 
2046  VmInterface *vmi,
2047  VmInterfaceState::Op l2_force_op,
2048  VmInterfaceState::Op l3_force_op) {
2049  FloatingIpSet::iterator it = list_.begin();
2050  while (it != list_.end()) {
2051  FloatingIpSet::iterator prev = it++;
2052  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
2053  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
2054  vmi->UpdateState(&(*prev), l2_op, l3_op);
2055  }
2056  return true;
2057 }
2058 
2060  ListEntry(), VmInterfaceState(), floating_ip_(), vn_(NULL),
2061  vrf_(NULL, this), vrf_name_(""), vn_uuid_(),
2062  fixed_ip_(), direction_(DIRECTION_BOTH), port_map_enabled_(false),
2063  src_port_map_(), dst_port_map_(), ethernet_tag_(0), port_nat_(false) {
2064 }
2065 
2067  ListEntry(rhs.del_pending_),
2068  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
2069  floating_ip_(rhs.floating_ip_), vn_(rhs.vn_), vrf_(rhs.vrf_, this),
2070  vrf_name_(rhs.vrf_name_), vn_uuid_(rhs.vn_uuid_), fixed_ip_(rhs.fixed_ip_),
2071  direction_(rhs.direction_), port_map_enabled_(rhs.port_map_enabled_),
2072  src_port_map_(rhs.src_port_map_), dst_port_map_(rhs.dst_port_map_),
2073  ethernet_tag_(rhs.ethernet_tag_), port_nat_(rhs.port_nat_) {
2074 }
2075 
2077  const std::string &vrf,
2078  const boost::uuids::uuid &vn_uuid,
2079  const IpAddress &fixed_ip,
2080  Direction direction,
2081  bool port_map_enabled,
2082  const PortMap &src_port_map,
2083  const PortMap &dst_port_map,
2084  bool port_nat) :
2085  ListEntry(), VmInterfaceState(),floating_ip_(addr), vn_(NULL),
2086  vrf_(NULL, this), vrf_name_(vrf), vn_uuid_(vn_uuid), fixed_ip_(fixed_ip),
2087  direction_(direction), port_map_enabled_(port_map_enabled),
2088  src_port_map_(src_port_map), dst_port_map_(dst_port_map), ethernet_tag_(0),
2089  port_nat_(port_nat) {
2090 }
2091 
2093 }
2094 
2096  const FloatingIp &rhs) const {
2097  return lhs.IsLess(&rhs);
2098 }
2099 
2100 // Compare key for FloatingIp. Key is <floating_ip_ and vrf_name_> for both
2101 // Config and Operational processing
2103  if (floating_ip_ != rhs->floating_ip_)
2104  return floating_ip_ < rhs->floating_ip_;
2105 
2106  return (vrf_name_ < rhs->vrf_name_);
2107 }
2108 
2109 const IpAddress
2111  if (fixed_ip_.is_unspecified()) {
2112  if (floating_ip_.is_v4() == true) {
2113  return vmi->primary_ip_addr();
2114  } else {
2115  return vmi->primary_ip6_addr();
2116  }
2117  }
2118  return fixed_ip_;
2119 }
2120 
2122  return port_map_enabled_;
2123 }
2124 
2126  return src_port_map_.size();
2127 }
2128 
2130  return port_nat_;
2131 }
2132 
2134  uint16_t src_port) const {
2135  PortMapIterator it = src_port_map_.find(PortMapKey(protocol, src_port));
2136  if (it == src_port_map_.end())
2137  return -1;
2138  return it->second;
2139 }
2140 
2142  uint16_t dst_port) const {
2143  PortMapIterator it = dst_port_map_.find(PortMapKey(protocol, dst_port));
2144  if (it == dst_port_map_.end())
2145  return -1;
2146  return it->second;
2147 }
2148 
2150  const VmInterface *vmi) const {
2151  // Delete for FloatingIp happens in CleanupFloatingIpList(). So, dont
2152  // update vn_ and vrf_ fields in case of delete
2153  if (del_pending_) {
2154  vn_ = NULL;
2155  vrf_ = NULL;
2156  return;
2157  }
2158 
2159  InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
2160  if (vn_.get() == NULL)
2161  vn_ = table->FindVnRef(vn_uuid_);
2162 
2163  if (vrf_.get() == NULL)
2164  vrf_ = table->FindVrfRef(vrf_name_);
2165  ethernet_tag_ = vmi->ethernet_tag();
2166 
2167  return;
2168 }
2169 
2171 (const Agent *agent, const VmInterface *vmi) const {
2172  if (GetIpActiveState(floating_ip_, vmi) == false)
2173  return VmInterfaceState::DEL;
2174 
2175  if (vmi->vrf() == NULL || vmi->vn() == NULL)
2176  return VmInterfaceState::DEL;
2177 
2178  return VmInterfaceState::ADD;
2179 }
2180 
2182  VmInterface *vmi) const {
2183  if (vrf_.get() == NULL || vn_.get() == NULL || port_nat_)
2184  return false;
2185 
2186  fixed_ip_ = GetFixedIp(vmi);
2187  uint8_t plen = floating_ip_.is_v4() ?
2190  if (floating_ip_.is_v6())
2191  service_ip = Ip6Address();
2192 
2193  bool ecmp = floating_ip_.is_v4() ? vmi->ecmp() : vmi->ecmp6();
2194  vmi->AddRoute(vrf_.get()->GetName(), floating_ip_, plen, vn_->GetName(),
2195  false, ecmp, false, false, service_ip, fixed_ip_,
2196  CommunityList(), vmi->label(), kInterface);
2197 
2198  InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
2199  if (table->update_floatingip_cb().empty() == false) {
2200  table->update_floatingip_cb()(vmi, vn_.get(), floating_ip_,
2201  false);
2202  //TODO:: callback for DNS handling
2203  }
2204 
2205  return true;
2206 }
2207 
2209  VmInterface *vmi) const {
2210  if (vrf_.get() == NULL)
2211  return false;
2212  uint8_t plen = floating_ip_.is_v4() ?
2214 
2215  vmi->DeleteRoute(vrf_.get()->GetName(), floating_ip_, plen);
2216 
2217  // The DNS record is not withdrawn here. This routine runs whenever the
2218  // interface stops forwarding, which includes the instance being powered
2219  // off - the tap device goes away and ipv4_active() turns false. The
2220  // record tracks floating-ip configuration, not forwarding state, the same
2221  // way the interface's own DNS record does, so it has to survive that.
2222  //
2223  // Withdrawing it is CleanupFloatingIpList(), which ApplyConfig() always
2224  // reaches after the floating-ip list is updated, and which also covers
2225  // the entries that were never installed because the interface was
2226  // inactive while they were configured.
2227  return true;
2228 }
2229 
2231 (const Agent *agent, const VmInterface *vmi) const {
2232  if (GetIpActiveState(floating_ip_, vmi) == false)
2233  return VmInterfaceState::DEL;
2234 
2235  if (vmi->vrf() == NULL || vmi->vn() == NULL)
2236  return VmInterfaceState::DEL;
2237 
2238  if (ethernet_tag_ != vmi->ethernet_tag())
2240 
2241  return VmInterfaceState::ADD;
2242 }
2243 
2245  VmInterface *vmi) const {
2246  if (vrf_.get() == NULL || vn_.get() == NULL || port_nat_)
2247  return false;
2248 
2249  SecurityGroupList sg_id_list;
2250  vmi->CopySgIdList(&sg_id_list);
2251 
2252  TagList tag_id_list;
2253  vmi->CopyTagIdList(&tag_id_list);
2254 
2255  PathPreference path_preference;
2256  vmi->SetPathPreference(&path_preference, false, GetFixedIp(vmi));
2257 
2258  EvpnAgentRouteTable *evpn_table = static_cast<EvpnAgentRouteTable *>
2259  (vrf_->GetEvpnRouteTable());
2260 
2261  std::string vn_name;
2262  if (vmi->vn()) {
2263  vn_name = vmi->vn()->GetName();
2264  }
2265 
2266  evpn_table->AddReceiveRoute(vmi->peer_.get(), vrf_->GetName(),
2267  vmi->l2_label(), vmi->vm_mac(), floating_ip_,
2268  ethernet_tag_, vn_name,
2269  path_preference);
2270  return true;
2271 }
2272 
2274  VmInterface *vmi) const {
2275  if (vrf_.get() == NULL)
2276  return false;
2277 
2278  EvpnAgentRouteTable *evpn_table =
2279  static_cast<EvpnAgentRouteTable *>(vrf_->GetEvpnRouteTable());
2280  if (evpn_table == NULL) {
2281  return false;
2282  }
2283 
2284  evpn_table->DelLocalVmRoute(vmi->peer_.get(), vrf_->GetName(),
2285  vmi->vm_mac(), vmi, floating_ip_,
2286  ethernet_tag_);
2287  return true;
2288 }
2289 
2291 // AliasIp routines
2294  std::pair<AliasIpSet::iterator, bool> ret = list_.insert(*rhs);
2295  if (ret.second) {
2296  if (rhs->alias_ip_.is_v4()) {
2297  v4_count_++;
2298  } else {
2299  v6_count_++;
2300  }
2301  }
2302 }
2303 
2304 void VmInterface::AliasIpList::Update(const AliasIp *lhs, const AliasIp *rhs) {
2305  lhs->set_del_pending(false);
2306 }
2307 
2308 void VmInterface::AliasIpList::Remove(AliasIpSet::iterator &it) {
2309  it->set_del_pending(true);
2310 }
2311 
2313  VmInterfaceState::Op l2_force_op,
2314  VmInterfaceState::Op l3_force_op) {
2315  AliasIpSet::iterator it = list_.begin();
2316  while (it != list_.end()) {
2317  AliasIpSet::iterator prev = it++;
2318  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
2319  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
2320  vmi->UpdateState(&(*prev), l2_op, l3_op);
2321  }
2322  return true;
2323 }
2324 
2326  AliasIpSet::iterator it = alias_ip_list_.list_.begin();
2327  while (it != alias_ip_list_.list_.end()) {
2328  AliasIpSet::iterator prev = it++;
2329  if (prev->del_pending_ == false)
2330  continue;
2331 
2332  if (prev->alias_ip_.is_v4()) {
2334  assert(alias_ip_list_.v4_count_ >= 0);
2335  } else {
2337  assert(alias_ip_list_.v6_count_ >= 0);
2338  }
2339  alias_ip_list_.list_.erase(prev);
2340  }
2341 }
2342 
2344  ListEntry(), VmInterfaceState(), alias_ip_(), vn_(NULL), vrf_(NULL, this),
2345  vrf_name_(""), vn_uuid_() {
2346 }
2347 
2349  ListEntry(rhs.del_pending_),
2350  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
2351  alias_ip_(rhs.alias_ip_), vn_(rhs.vn_), vrf_(rhs.vrf_, this),
2352  vrf_name_(rhs.vrf_name_), vn_uuid_(rhs.vn_uuid_) {
2353 }
2354 
2355 VmInterface::AliasIp::AliasIp(const IpAddress &addr, const std::string &vrf,
2356  const boost::uuids::uuid &vn_uuid) :
2357  ListEntry(), VmInterfaceState(), alias_ip_(addr), vn_(NULL),
2358  vrf_(NULL, this), vrf_name_(vrf), vn_uuid_(vn_uuid) {
2359 }
2360 
2362 }
2363 
2365  const AliasIp &rhs) const {
2366  return lhs.IsLess(&rhs);
2367 }
2368 
2369 // Compare key for AliasIp. Key is <alias_ip_ and vrf_name_> for both
2370 // Config and Operational processing
2371 bool VmInterface::AliasIp::IsLess(const AliasIp *rhs) const {
2372  if (alias_ip_ != rhs->alias_ip_)
2373  return alias_ip_ < rhs->alias_ip_;
2374 
2375  return (vrf_name_ < rhs->vrf_name_);
2376 }
2377 
2379  const VmInterface *vmi) const {
2380  if (GetIpActiveState(alias_ip_, vmi) == false)
2381  return VmInterfaceState::DEL;
2382 
2383  if (vrf_ != vmi->vrf())
2385 
2386  return VmInterfaceState::ADD;
2387 }
2388 
2390  const VmInterface *vmi) const {
2391  if (del_pending_) {
2392  vrf_ = NULL;
2393  vn_ = NULL;
2394  return;
2395  }
2396 
2397  InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
2398  if (vn_.get() == NULL) {
2399  vn_ = table->FindVnRef(vn_uuid_);
2400  assert(vn_.get());
2401  }
2402 
2403  if (vrf_.get() == NULL) {
2404  vrf_ = table->FindVrfRef(vrf_name_);
2405  assert(vrf_.get());
2406  }
2407  return;
2408 }
2409 
2411  if (vrf_.get() == NULL || vn_.get() == NULL)
2412  return false;
2413 
2414  uint8_t plen = alias_ip_.is_v4() ?
2417  if (alias_ip_.is_v6())
2418  service_ip = Ip6Address();
2419  vmi->AddRoute(vrf_->GetName(), alias_ip_, plen, vn_->GetName(), false,
2420  vmi->ecmp(), false, false, service_ip, service_ip,
2421  CommunityList(), vmi->label(), kInterface);
2422  return true;
2423 }
2424 
2426  VmInterface *vmi) const {
2427  if (vrf_ == NULL)
2428  return false;
2429  uint8_t plen = alias_ip_.is_v4() ?
2431  vmi->DeleteRoute(vrf_.get()->GetName(), alias_ip_, plen);
2432  return true;
2433 }
2434 
2436 // StaticRoute routines
2439  list_.insert(*rhs);
2440 }
2441 
2443  const StaticRoute *rhs) {
2444  if (lhs->communities_ != rhs->communities_) {
2445  (const_cast<StaticRoute *>(lhs))->communities_ = rhs->communities_;
2446  }
2447  lhs->set_del_pending(false);
2448 }
2449 
2450 void VmInterface::StaticRouteList::Remove(StaticRouteSet::iterator &it) {
2451  it->set_del_pending(true);
2452 }
2453 
2455 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
2456  VmInterfaceState::Op l3_force_op) {
2457  StaticRouteSet::iterator it = list_.begin();
2458  while (it != list_.end()) {
2459  StaticRouteSet::iterator prev = it++;
2460  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
2461  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
2462  vmi->UpdateState(&(*prev), l2_op, l3_op);
2463  if (prev->del_pending_) {
2464  list_.erase(prev);
2465  }
2466  }
2467  return true;
2468 }
2469 
2471  ListEntry(), VmInterfaceState(), vrf_(), addr_(), plen_(0), gw_list_(),
2472  communities_() {
2473 }
2474 
2476  ListEntry(rhs.del_pending_),
2477  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
2478  vrf_(rhs.vrf_), addr_(rhs.addr_), plen_(rhs.plen_), gw_list_(rhs.gw_list_),
2479  communities_(rhs.communities_) {
2480 }
2481 
2483  uint32_t plen, const AddressList &gw_list,
2484  const CommunityList &communities) :
2485  ListEntry(), VmInterfaceState(), vrf_(), addr_(addr), plen_(plen), gw_list_(gw_list),
2486  communities_(communities) {
2487 }
2488 
2490 }
2491 
2493  const StaticRoute &rhs) const {
2494  return lhs.IsLess(&rhs);
2495 }
2496 
2498  if (addr_ != rhs->addr_)
2499  return addr_ < rhs->addr_;
2500 
2501  if (plen_ != rhs->plen_) {
2502  return plen_ < rhs->plen_;
2503  }
2504 
2505  return gw_list_.size() < rhs->gw_list_.size();
2506 }
2507 
2509  const VmInterface *vmi) const {
2510  if (vmi->vmi_type() == VmInterface::VHOST) {
2511  vrf_ = vmi->forwarding_vrf();
2512  } else {
2513  vrf_ = vmi->vrf();
2514  }
2515 }
2516 
2518 (const Agent *agent, const VmInterface *vmi) const {
2519  if (GetIpActiveState(addr_, vmi) == false)
2520  return VmInterfaceState::DEL;
2521 
2522  if (vrf_ != vmi->vrf())
2524 
2525  return VmInterfaceState::ADD;
2526 }
2527 
2529  VmInterface *vmi) const {
2530  if (vrf_ == NULL)
2531  return false;
2532  std::string vn_name;
2533  if (vmi->vn()) {
2534  vn_name = vmi->vn()->GetName();
2535  } else if (vmi->vmi_type() == VHOST) {
2536  vn_name = agent->fabric_vn_name();
2537  }
2538 
2539  if (addr_.is_v4() && !gw_list_.empty() && gw_list_[0] != Ip4Address(0)) {
2540  SecurityGroupList sg_id_list;
2541  vmi->CopySgIdList(&sg_id_list);
2542 
2543  TagList tag_id_list;
2544  vmi->CopyTagIdList(&tag_id_list);
2545 
2546  VnListType vn_list;
2547  if (vmi->vn()) {
2548  vn_list.insert(vn_name);
2549  }
2550 
2551  bool native_encap = false;
2552  const Peer *peer = vmi->peer_.get();
2553  if (vrf_->GetName() == agent->fabric_vrf_name()) {
2554  vn_list.insert(agent->fabric_vn_name());
2555  native_encap = true;
2556  peer = agent->local_peer();
2557  }
2558 
2560  (peer, vrf_->GetName(), addr_.to_v4(), plen_,
2561  gw_list_, vn_list, vmi->vrf_->table_label(),
2562  sg_id_list, tag_id_list, communities_, native_encap);
2563  } else {
2564  IpAddress dependent_ip;
2565  bool ecmp = false;
2566  if (addr_.is_v4()) {
2567  dependent_ip = vmi->primary_ip_addr();
2568  ecmp = vmi->ecmp();
2569  } else if (addr_.is_v6()) {
2570  dependent_ip = vmi->primary_ip6_addr();
2571  ecmp = vmi->ecmp6();
2572  }
2573  vmi->AddRoute(vrf_->GetName(), addr_, plen_, vn_name,
2574  false, ecmp, false, false, vmi->GetServiceIp(addr_),
2575  dependent_ip, communities_, vmi->label(),
2577  }
2578  return true;
2579 }
2580 
2582  VmInterface *vmi) const {
2583  if (vrf_ == NULL)
2584  return false;
2585 
2586  const Peer *peer = vmi->peer();
2587  if (vmi->vmi_type() == VHOST) {
2588  peer = agent->local_peer();
2589  }
2591  addr_, plen_);
2592  return true;
2593 }
2594 
2596 //Allowed addresss pair route
2599 (const AllowedAddressPair *rhs){
2600  list_.insert(*rhs);
2601 }
2602 
2604 (const AllowedAddressPair *lhs, const AllowedAddressPair *rhs) {
2605  lhs->set_del_pending(false);
2606  if (lhs->ecmp_ != rhs->ecmp_) {
2607  lhs->ecmp_ = rhs->ecmp_;
2608  lhs->ecmp_config_changed_ = true;
2609  }
2610 }
2611 
2613 (AllowedAddressPairSet::iterator &it) {
2614  it->set_del_pending(true);
2615 }
2616 
2618 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
2619  VmInterfaceState::Op l3_force_op) {
2620  AllowedAddressPairSet::iterator it = list_.begin();
2621  while (it != list_.end()) {
2622  AllowedAddressPairSet::iterator prev = it++;
2623  if (!prev->del_pending_)
2624  continue;
2625  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
2626  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
2627  vmi->UpdateState(&(*prev), l2_op, l3_op);
2628  list_.erase(prev);
2629  }
2630  it = list_.begin();
2631  while (it != list_.end()) {
2632  AllowedAddressPairSet::iterator prev = it++;
2633  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
2634  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
2635  vmi->UpdateState(&(*prev), l2_op, l3_op);
2636  }
2637  return true;
2638 }
2639 
2641  ListEntry(), VmInterfaceState(), addr_(), plen_(0), ecmp_(false), mac_(),
2642  ecmp_config_changed_(false),
2643  service_ip_(), label_(MplsTable::kInvalidLabel), policy_enabled_nh_(NULL),
2644  policy_disabled_nh_(NULL), vrf_(NULL), ethernet_tag_(0) {
2645 }
2646 
2648  const AllowedAddressPair &rhs) : ListEntry(rhs.del_pending_),
2649  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
2650  addr_(rhs.addr_), plen_(rhs.plen_), ecmp_(rhs.ecmp_),
2651  mac_(rhs.mac_),
2652  ecmp_config_changed_(rhs.ecmp_config_changed_),
2653  service_ip_(rhs.service_ip_), label_(rhs.label_),
2654  policy_enabled_nh_(rhs.policy_enabled_nh_),
2655  policy_disabled_nh_(rhs.policy_disabled_nh_),
2656  vrf_(rhs.vrf_), ethernet_tag_(rhs.ethernet_tag_) {
2657 }
2658 
2660  uint32_t plen, bool ecmp,
2661  const MacAddress &mac) :
2662  ListEntry(), VmInterfaceState(), addr_(addr), plen_(plen), ecmp_(ecmp),
2663  mac_(mac), ecmp_config_changed_(false),
2664  label_(MplsTable::kInvalidLabel), policy_enabled_nh_(NULL),
2665  policy_disabled_nh_(NULL), vrf_(NULL), ethernet_tag_(0) {
2666 }
2667 
2669 }
2670 
2672  const AllowedAddressPair &rhs)
2673  const {
2674  return lhs.IsLess(&rhs);
2675 }
2676 
2678  const {
2679  if (addr_ != rhs->addr_)
2680  return addr_ < rhs->addr_;
2681 
2682  if (plen_ != rhs->plen_) {
2683  return plen_ < rhs->plen_;
2684  }
2685 
2686  return mac_ < rhs->mac_;
2687 }
2688 
2690  const VmInterface *vmi) const {
2691  vrf_ = vmi->vrf();
2692  ethernet_tag_ = vmi->ethernet_tag();
2693 }
2694 
2696 (const Agent *agent, const VmInterface *vmi) const {
2697  if (vmi->bridging() == false)
2698  return VmInterfaceState::DEL;
2699 
2700  if (ethernet_tag_ != vmi->ethernet_tag())
2702 
2703  return VmInterfaceState::ADD;
2704 }
2705 
2707  VmInterface *vmi) const {
2708  if (vrf_ == NULL || mac_ == MacAddress::kZeroMac)
2709  return false;
2710 
2711  IpAddress dependent_rt;
2712  IpAddress route_addr;
2713  if (addr_.is_v4()) {
2714  if (plen_ == 32) {
2715  route_addr = addr_;
2716  } else {
2717  route_addr = Ip4Address(0);
2718  }
2719  dependent_rt = Ip4Address(0);
2720  } else if (addr_.is_v6()) {
2721  if (plen_ == 128) {
2722  route_addr = addr_;
2723  } else {
2724  route_addr = Ip6Address();
2725  }
2726  dependent_rt = Ip6Address();
2727  }
2728  vmi->AddL2InterfaceRoute(route_addr, mac_, dependent_rt);
2729  return true;
2730 }
2731 
2733  VmInterface *vmi) const {
2734  if (vrf_ == NULL || mac_ == MacAddress::kZeroMac)
2735  return false;
2736 
2737  IpAddress route_addr;
2738  if (addr_.is_v4()) {
2739  if (plen_ == 32) {
2740  route_addr = addr_;
2741  } else {
2742  route_addr = Ip4Address(0);
2743  }
2744  } else if (addr_.is_v6()) {
2745  if (plen_ == 128) {
2746  route_addr = addr_;
2747  } else {
2748  route_addr = Ip6Address();
2749  }
2750  }
2751  vmi->DeleteL2InterfaceRoute(vrf_, ethernet_tag_, route_addr, mac_);
2752  return true;
2753 }
2754 
2756 (const Agent *agent, const VmInterface *vmi) const {
2757  if (GetIpActiveState(addr_, vmi) == false)
2758  return VmInterfaceState::DEL;
2759 
2760  return VmInterfaceState::ADD;
2761 }
2762 
2764  VmInterface *vmi) const {
2765  if (vrf_ == NULL)
2766  return false;
2767 
2768  vmi->DeleteRoute(vrf_->GetName(), addr_, plen_);
2771  }
2772  policy_enabled_nh_ = NULL;
2773  policy_disabled_nh_ = NULL;
2774  return true;
2775 }
2776 
2778  VmInterface *vmi) const {
2779  if (vrf_ == NULL || vmi->vn_ == NULL)
2780  return false;
2781 
2782  service_ip_ = vmi->GetServiceIp(addr_);
2783  if (mac_ == MacAddress::kZeroMac || mac_ == vmi->vm_mac_) {
2784  vmi->AddRoute(vrf_->GetName(), addr_, plen_, vmi->vn_->GetName(),
2785  false, ecmp_, false, false, service_ip_, Ip4Address(0),
2786  CommunityList(), vmi->label(), kInterface);
2787  return true;
2788  }
2789 
2791  (vmi->GetUuid(), mac_, vmi->vrf_->GetName(), vmi->learning_enabled_,
2792  vmi->name());
2793 
2795  vmi->name());
2796 
2797  // Get policy disabled nh first
2798  InterfaceNHKey key(vmi_key.Clone(), false, InterfaceNHFlags::INET4, mac_);
2799  InterfaceNH *nh =static_cast<InterfaceNH *>
2800  (agent->nexthop_table()->FindActiveEntry(&key));
2801  policy_disabled_nh_ = nh;
2802  // Ensure nexthop to be deleted upon refcount falling to 0
2803  nh->set_delete_on_zero_refcount(true);
2804 
2805  // Get policy enabled nh first
2806  InterfaceNHKey key1(vmi_key.Clone(), true, InterfaceNHFlags::INET4, mac_);
2807  nh = static_cast<InterfaceNH *>(agent->
2808  nexthop_table()->FindActiveEntry(&key1));
2809  // Ensure nexthop to be deleted upon refcount falling to 0
2810  nh->set_delete_on_zero_refcount(true);
2811  policy_enabled_nh_ = nh;
2812 
2813  // Update AAP mpls label from nh entry
2814  if (vmi->policy_enabled()) {
2815  label_ = policy_enabled_nh_->mpls_label()->label();
2816  } else {
2817  label_ = policy_disabled_nh_->mpls_label()->label();
2818  }
2819 
2820  vmi->AddRoute(vrf_->GetName(), addr_, plen_, vmi->vn_->GetName(),
2821  false, ecmp_, false, false, service_ip_, Ip6Address(),
2823  return true;
2824 }
2825 
2827 // ServiceVlan routines
2830  list_.insert(*rhs);
2831 }
2832 
2834  const ServiceVlan *rhs) {
2835  if (lhs->vrf_name_ != rhs->vrf_name_) {
2836  lhs->vrf_name_ = rhs->vrf_name_;
2837  lhs->del_add_ = true;
2838  }
2839 
2840  if (lhs->addr_ != rhs->addr_) {
2841  lhs->addr_ = rhs->addr_;
2842  lhs->del_add_ = true;
2843  }
2844 
2845  if (lhs->addr6_ != rhs->addr6_) {
2846  lhs->addr6_ = rhs->addr6_;
2847  lhs->del_add_ = true;
2848  }
2849 
2850  if (lhs->smac_ != rhs->smac_) {
2851  lhs->smac_ = rhs->smac_;
2852  lhs->del_add_ = true;
2853  }
2854 
2855  if (lhs->dmac_ != rhs->dmac_) {
2856  lhs->dmac_ = rhs->dmac_;
2857  lhs->del_add_ = true;
2858  }
2859 
2860  lhs->set_del_pending(false);
2861 }
2862 
2863 void VmInterface::ServiceVlanList::Remove(ServiceVlanSet::iterator &it) {
2864  it->set_del_pending(true);
2865 }
2866 
2868 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
2869  VmInterfaceState::Op l3_force_op) {
2870  ServiceVlanSet::iterator it = list_.begin();
2871  while (it != list_.end()) {
2872  ServiceVlanSet::iterator prev = it++;
2873  if (prev->del_pending_ || prev->del_add_) {
2874  prev->Update(agent, vmi);
2875  if (prev->del_pending_) {
2876  list_.erase(prev);
2877  }
2878  }
2879  }
2880 
2881  it = list_.begin();
2882  while (it != list_.end()) {
2883  ServiceVlanSet::iterator prev = it++;
2884  prev->Update(agent, vmi);
2885  }
2886 
2887  return true;
2888 }
2889 
2891 // TagGroup routines
2894  ListEntry(), VmInterfaceState() , type_(0xFFFFFFFF), uuid_(nil_uuid()) {
2895 }
2896 
2898  ListEntry(rhs.del_pending_),
2899  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
2900  type_(rhs.type_), uuid_(rhs.uuid_) {
2901 }
2902 
2905 }
2906 
2908 }
2909 
2911  return uuid_ == rhs.uuid_;
2912 }
2913 
2915  const TagEntry &rhs) const {
2916  return lhs.IsLess(&rhs);
2917 }
2918 
2919 bool VmInterface::TagEntry::IsLess(const TagEntry *rhs) const {
2920  if (type_ != rhs->type_) {
2921  return type_ < rhs->type_;
2922  }
2923 
2924  //We can only have duplicate of tag of type Label
2925  //Rest of tags would be unique
2926  if (type_ != TagTable::LABEL) {
2927  return false;
2928  }
2929  return uuid_ < rhs->uuid_;
2930 }
2931 
2933  VmInterface *intrface) const {
2934  if (tag_.get() && tag_->tag_uuid() == uuid_) {
2935  return false;
2936  }
2937 
2938  TagKey tag_key(uuid_);
2939  typedef ::TagEntry GlobalTagEntry;
2940  tag_ = static_cast<GlobalTagEntry *>(agent->tag_table()->
2941  FindActiveEntry(&tag_key));
2942  return true;
2943 }
2944 
2946  VmInterface *intrface) const {
2947  tag_.reset();
2948  return true;
2949 }
2950 
2953  const VmInterface *vmi) const {
2954  if (del_pending_)
2956 
2957  return VmInterfaceState::ADD;
2958 }
2959 
2961  list_.insert(*rhs);
2962 }
2963 
2965  const TagEntry *rhs) {
2966  if (lhs->uuid_ != rhs->uuid_) {
2967  lhs->uuid_ = rhs->uuid_;
2968  }
2969 }
2970 
2971 void VmInterface::TagEntryList::Remove(TagEntrySet::iterator &it) {
2972  it->set_del_pending(true);
2973 }
2974 
2976  VmInterface *vmi,
2977  VmInterfaceState::Op l2_force_op,
2978  VmInterfaceState::Op l3_force_op) {
2979  TagEntrySet::iterator it = list_.begin();
2980  while (it != list_.end()) {
2981  TagEntrySet::iterator prev = it++;
2982  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
2983  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
2984  vmi->UpdateState(&(*prev), l2_op, l3_op);
2985  if (prev->del_pending()) {
2986  list_.erase(prev);
2987  }
2988  }
2989 
2990  vmi->UpdatePolicySet(agent);
2991  return true;
2992 }
2993 
2995 // ServiceVlan routines
2998  ListEntry(), tag_(0), vrf_name_(""), addr_(0), old_addr_(0),
2999  addr6_(), old_addr6_(), smac_(), dmac_(), vrf_(NULL, this),
3000  label_(MplsTable::kInvalidLabel), v4_rt_installed_(false),
3001  v6_rt_installed_(false), del_add_(false) {
3002 }
3003 
3005  ListEntry(rhs.del_pending_), tag_(rhs.tag_),
3006  vrf_name_(rhs.vrf_name_), addr_(rhs.addr_), old_addr_(rhs.old_addr_),
3007  addr6_(rhs.addr6_), old_addr6_(rhs.old_addr6_),
3008  vrf_(rhs.vrf_, this), label_(rhs.label_),
3009  v4_rt_installed_(rhs.v4_rt_installed_),
3010  v6_rt_installed_(rhs.v6_rt_installed_), del_add_(false) {
3011  smac_ = rhs.smac_;
3012  dmac_ = rhs.dmac_;
3013 }
3014 
3015 VmInterface::ServiceVlan::ServiceVlan(uint16_t tag, const std::string &vrf_name,
3016  const Ip4Address &addr,
3017  const Ip6Address &addr6,
3018  const MacAddress &smac,
3019  const MacAddress &dmac) :
3020  ListEntry(), tag_(tag), vrf_name_(vrf_name), addr_(addr), old_addr_(addr),
3021  addr6_(addr6), old_addr6_(addr6),
3022  smac_(smac), dmac_(dmac), vrf_(NULL, this),
3023  label_(MplsTable::kInvalidLabel) , v4_rt_installed_(false),
3024  v6_rt_installed_(false), del_add_(false) {
3025 }
3026 
3028 }
3029 
3031  const ServiceVlan &rhs) const {
3032  return lhs.IsLess(&rhs);
3033 }
3034 
3036  return tag_ < rhs->tag_;
3037 }
3038 
3040  VmInterface *vmi) const {
3041  InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
3042  VrfEntry *vrf = table->FindVrfRef(vrf_name_);
3043 
3044  if (del_pending_ || vrf_ != vrf || vmi->ipv4_active() == false || del_add_) {
3045  if (v4_rt_installed_) {
3046  InetUnicastAgentRouteTable::Delete(vmi->peer(), vrf_->GetName(),
3047  old_addr_,
3049  v4_rt_installed_ = false;
3050  }
3051  }
3052 
3053  if (del_pending_ || vrf_ != vrf || vmi->ipv6_active() == false || del_add_) {
3054  if (v6_rt_installed_) {
3055  InetUnicastAgentRouteTable::Delete(vmi->peer(), vrf_->GetName(),
3056  old_addr6_,
3058  v6_rt_installed_ = false;
3059  }
3060  }
3061 
3062  if (del_pending_ || vrf_ != vrf || del_add_) {
3063  DeleteCommon(vmi);
3064  }
3065 
3066  vrf_ = vrf;
3067  old_addr_ = addr_;
3068  old_addr6_ = addr6_;
3069  bool old_del_add = del_add_;
3070  del_add_ = false;
3071 
3072  if (del_pending_ || vrf_ == NULL || old_del_add)
3073  return;
3074 
3075  if (vmi->ipv4_active() == false && vmi->ipv6_active() == false)
3076  return;
3077 
3079  AddCommon(agent, vmi);
3080  }
3081 
3082  SecurityGroupList sg_id_list;
3083  vmi->CopySgIdList(&sg_id_list);
3084 
3085  TagList tag_id_list;
3086  vmi->CopyTagIdList(&tag_id_list);
3087 
3088  VnListType vn_list;
3089  vn_list.insert(vmi->vn()->GetName());
3090 
3091  // Add both ipv4 *and* ipv6 service vlan route if one of v4 or v6 is active
3092  // TODO : Shouldnt route be added only if corresponding state is active?
3093  if (addr_.is_unspecified() == false) {
3094  PathPreference pref;
3095  vmi->SetServiceVlanPathPreference(&pref, addr_);
3096 
3098  (vmi->peer(), vrf_->GetName(), addr_, Address::kMaxV4PrefixLen,
3099  vmi->GetUuid(), tag_, label_, vn_list, sg_id_list,
3100  tag_id_list, pref);
3101  v4_rt_installed_ = true;
3102  }
3103 
3104  if (addr6_.is_unspecified() == false) {
3105  PathPreference pref;
3106  vmi->SetServiceVlanPathPreference(&pref, addr6_);
3107 
3109  (vmi->peer(), vrf_->GetName(), addr6_, Address::kMaxV6PrefixLen,
3110  vmi->GetUuid(), tag_, label_, vn_list, sg_id_list,
3111  tag_id_list, pref);
3112  v6_rt_installed_ = true;
3113  }
3114 
3115  return;
3116 }
3117 
3120  return;
3121 
3122  // Delete the L2 Recive routes added for smac_ and dmac_
3123  BridgeAgentRouteTable *table = static_cast<BridgeAgentRouteTable *>
3124  (vrf_->GetBridgeRouteTable());
3125  if (table) {
3126  table->Delete(vmi->peer(), vrf_->GetName(), dmac_, 0);
3127  table->Delete(vmi->peer(), vrf_->GetName(), smac_, 0);
3128  }
3129 
3130  VrfAssignTable::DeleteVlan(vmi->GetUuid(), tag_);
3131  VlanNH::Delete(vmi->GetUuid(), tag_);
3133 }
3134 
3136  const VmInterface *vmi) const {
3138  return;
3139 
3140  assert(vrf_);
3141  VlanNH::Create(vmi->GetUuid(), tag_, vrf_name_, smac_, dmac_);
3143  // Assign label_ from vlan NH db entry
3144  VlanNHKey key(vmi->GetUuid(), tag_);
3145  const NextHop *nh = static_cast<const NextHop *>
3146  (agent->nexthop_table()->FindActiveEntry(&key));
3147  label_ = nh->mpls_label()->label();
3148 
3149  // With IRB model, add L2 Receive route for SMAC and DMAC to ensure
3150  // packets from service vm go thru routing
3151  BridgeAgentRouteTable *table = static_cast<BridgeAgentRouteTable *>
3152  (vrf_->GetBridgeRouteTable());
3153  table->AddBridgeReceiveRoute(vmi->peer(), vrf_->GetName(), 0, dmac_,
3154  vmi->vn()->GetName());
3155  table->AddBridgeReceiveRoute(vmi->peer(), vrf_->GetName(), 0, smac_,
3156  vmi->vn()->GetName());
3157 }
3158 
3160 // VRF assign rule routines
3163  ListEntry(), id_(0), vrf_name_(" "), ignore_acl_(false) {
3164 }
3165 
3167  ListEntry(rhs.del_pending_), id_(rhs.id_),
3168  vrf_name_(rhs.vrf_name_), ignore_acl_(rhs.ignore_acl_),
3169  match_condition_(rhs.match_condition_) {
3170 }
3171 
3173 (uint32_t id, const autogen::MatchConditionType &match_condition,
3174  const std::string &vrf_name, bool ignore_acl):
3175  ListEntry(), id_(id), vrf_name_(vrf_name), ignore_acl_(ignore_acl),
3176  match_condition_(match_condition) {
3177 }
3178 
3180 }
3181 
3183  const VrfAssignRule &rhs) const {
3184  return lhs.IsLess(&rhs);
3185 }
3186 
3188  return id_ < rhs->id_;
3189 }
3190 
3192  list_.insert(*rhs);
3193 }
3194 
3196  const VrfAssignRule *rhs) {
3197  lhs->set_del_pending(false);
3198  lhs->match_condition_ = rhs->match_condition_;
3199  lhs->ignore_acl_ = rhs->ignore_acl_;
3200  lhs->vrf_name_ = rhs->vrf_name_;
3201 }
3202 
3203 void VmInterface::VrfAssignRuleList::Remove(VrfAssignRuleSet::iterator &it) {
3204  it->set_del_pending(true);
3205 }
3206 
3208 (const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op,
3209  VmInterfaceState::Op l3_force_op) {
3210  // Erase all delete marked entry
3211  VrfAssignRuleSet::iterator it = list_.begin();
3212  while (it != list_.end()) {
3213  VrfAssignRuleSet::iterator prev = it++;
3214  if (prev->del_pending_) {
3215  list_.erase(prev);
3216  }
3217  }
3218 
3219  // Delete vrf_assign_acl_ if there are no more ACE entries
3220  if (list_.size() == 0 || vmi->IsActive() == false) {
3221  if (vrf_assign_acl_.get() != NULL) {
3222  vrf_assign_acl_ = NULL;
3224  req.key.reset(new AclKey(vmi->GetUuid()));
3225  req.data.reset(NULL);
3226  agent->acl_table()->Process(req);
3227  }
3228  return true;
3229  }
3230 
3231  // One or more ace-entries present, create corresponding ACL
3232  AclSpec acl_spec;
3233  acl_spec.acl_id = vmi->GetUuid();
3234  uint32_t id = 0;
3235  for (it = list_.begin(); it != list_.end(); it++) {
3236  AclEntrySpec ace_spec;
3237  ace_spec.id = id++;
3238 
3239  if (ace_spec.Populate(&(it->match_condition_)) == false) {
3240  continue;
3241  }
3242 
3243  // Add both v4 and v6 rules regardless of whether interface is
3244  //ipv4_active_/ipv6_active_
3245  ActionSpec vrf_translate_spec;
3246  vrf_translate_spec.ta_type = TrafficAction::VRF_TRANSLATE_ACTION;
3247  vrf_translate_spec.simple_action = TrafficAction::VRF_TRANSLATE;
3248  vrf_translate_spec.vrf_translate.set_vrf_name(it->vrf_name_);
3249  vrf_translate_spec.vrf_translate.set_ignore_acl(it->ignore_acl_);
3250  ace_spec.action_l.push_back(vrf_translate_spec);
3251  acl_spec.acl_entry_specs_.push_back(ace_spec);
3252  }
3253 
3254  // ACL entries populated, add the DBEntry
3256  req.key.reset(new AclKey(acl_spec.acl_id));
3257  Agent *agent1 = static_cast<InterfaceTable *>(vmi->get_table())->agent();
3258  req.data.reset(new AclData(agent1, NULL, acl_spec));
3259  agent->acl_table()->Process(req);
3260 
3261  // Query the ACL entry and store it
3262  AclKey entry_key(vmi->GetUuid());
3263  vrf_assign_acl_ = static_cast<AclDBEntry *>
3264  (agent->acl_table()->FindActiveEntry(&entry_key));
3265  assert(vrf_assign_acl_);
3266  return true;
3267 }
3268 
3270 // RecevieRoute routines
3273  list_.insert(*rhs);
3274 }
3275 
3277  const VmiReceiveRoute *rhs) {
3278  lhs->set_del_pending(false);
3279 }
3280 
3281 void VmInterface::VmiReceiveRouteList::Remove(VmiReceiveRouteSet::iterator &it) {
3282  it->set_del_pending(true);
3283 }
3284 
3286  VmInterface *vmi,
3287  VmInterfaceState::Op l2_force_op,
3288  VmInterfaceState::Op l3_force_op) {
3289  VmiReceiveRouteSet::iterator it = list_.begin();
3290  while (it != list_.end()) {
3291  VmiReceiveRouteSet::iterator prev = it++;
3292  VmInterfaceState::Op l2_op = prev->GetOp(l2_force_op);
3293  VmInterfaceState::Op l3_op = prev->GetOp(l3_force_op);
3294  vmi->UpdateState(&(*prev), l2_op, l3_op);
3295  if (prev->del_pending_) {
3296  list_.erase(prev);
3297  }
3298  }
3299  return true;
3300 }
3301 
3303  ListEntry(), VmInterfaceState(), addr_(), plen_(0), add_l2_(false) {
3304 }
3305 
3307  ListEntry(rhs.del_pending_),
3308  VmInterfaceState(rhs.l2_installed_, rhs.l3_installed_),
3309  addr_(rhs.addr_), plen_(rhs.plen_), add_l2_(rhs.add_l2_) {
3310 }
3311 
3313  uint32_t plen,
3314  bool add_l2):
3315  ListEntry(), VmInterfaceState(), addr_(addr), plen_(plen), add_l2_(add_l2) {
3316 }
3317 
3319  const VmiReceiveRoute &rhs)
3320  const {
3321  return lhs.IsLess(&rhs);
3322 }
3323 
3325  if (addr_ != rhs->addr_) {
3326  return addr_ < rhs->addr_;
3327  }
3328 
3329  if (plen_ != rhs->plen_) {
3330  return plen_ < rhs->plen_;
3331  }
3332 
3333  return add_l2_ < rhs->add_l2_;
3334 }
3335 
3337  const VmInterface *vmi) const {
3338  vrf_ = vmi->forwarding_vrf();
3339 }
3340 
3343  const VmInterface *vmi) const {
3344  if (GetIpActiveState(addr_, vmi) == false)
3345  return VmInterfaceState::DEL;
3346 
3347  if (vrf_ != vmi->forwarding_vrf())
3349 
3350  return VmInterfaceState::ADD;
3351 }
3352 
3355  const VmInterface *vmi) const {
3356  if (add_l2_ == false) {
3358  }
3359 
3360  if (vrf_ != vmi->forwarding_vrf())
3362 
3363  return VmInterfaceState::ADD;
3364 }
3365 
3367  VmInterface *vmi) const {
3368  if (vrf_ == NULL) {
3369  return false;
3370  }
3371 
3373  ReceiveNH::Create(agent->nexthop_table(), vmi, false);
3374  InetUnicastAgentRouteTable *table = vrf_->GetInet4UnicastRouteTable();
3376  vmi->name());
3377  if (addr_.is_v6()) {
3378  table = vrf_->GetInet6UnicastRouteTable();
3379  }
3380 
3381  table->AddVHostRecvRoute(agent->local_peer(), vrf_->GetName(), vmi_key,
3382  addr_, plen_, agent->fabric_vn_name(),
3383  vmi->policy_enabled(), true);
3384  return true;
3385 }
3386 
3388  VmInterface *vmi) const {
3389  if (vrf_ == NULL)
3390  return false;
3391 
3393  addr_, plen_);
3394  return true;
3395 }
3396 
3398  VmInterface *vmi) const {
3399  if (vrf_ == NULL) {
3400  return false;
3401  }
3402 
3403  BridgeAgentRouteTable *table =
3404  static_cast<BridgeAgentRouteTable *>(vrf_->GetRouteTable(Agent::BRIDGE));
3405  table->AddBridgeReceiveRoute(agent->local_peer(), vrf_->GetName(), 0,
3406  vmi->GetVifMac(agent), agent->fabric_vn_name());
3407  return true;
3408 }
3409 
3411  VmInterface *vmi) const {
3412  if (vrf_ == NULL)
3413  return false;
3414 
3416  vmi->GetVifMac(agent), 0);
3417  return true;
3418 }
3419 //Build ACL list to be applied on VMI
3420 //ACL list build on two criteria
3421 //1> global-application-policy set.
3422 //2> application-policy-set attached via application tag
3424  bool ret = false;
3425  FirewallPolicyList new_firewall_policy_list;
3426  FirewallPolicyList new_fwaas_firewall_policy_list;
3427 
3429  if (gps) {
3430  new_firewall_policy_list = gps->fw_policy_list();
3431  }
3432 
3433  contains_new_tags_ = false;
3434  TagEntrySet::const_iterator it = tag_list_.list_.begin();
3435  for(; it != tag_list_.list_.end(); it++) {
3436  if (it->tag_ == NULL) {
3437  continue;
3438  }
3439  contains_new_tags_ |= it->tag_->is_new_tag();
3440 
3441  ::TagEntry::PolicySetList::const_iterator ps_it =
3442  it->tag_->policy_set_list().begin();
3443  for(; ps_it != it->tag_->policy_set_list().end(); ps_it++) {
3444  FirewallPolicyList &tag_fp_list = ps_it->get()->fw_policy_list();
3445  FirewallPolicyList::iterator fw_policy_it = tag_fp_list.begin();
3446  for (; fw_policy_it != tag_fp_list.end(); fw_policy_it++) {
3447  if (it->tag_->IsNeutronFwaasTag())
3448  new_fwaas_firewall_policy_list.push_back(*fw_policy_it);
3449  else
3450  new_firewall_policy_list.push_back(*fw_policy_it);
3451  }
3452  }
3453  }
3454 
3455  if (fw_policy_list_ != new_firewall_policy_list) {
3456  fw_policy_list_ = new_firewall_policy_list;
3457  ret = true;
3458  }
3459 
3460  if (fwaas_fw_policy_list_ != new_fwaas_firewall_policy_list) {
3461  fwaas_fw_policy_list_ = new_fwaas_firewall_policy_list;
3462  ret = true;
3463  }
3464 
3465  return ret;
3466 }
3467 
3468 void VmInterface::CopyTagIdList(TagList *tag_id_list) const {
3469  TagEntrySet::const_iterator it;
3470  for (it = tag_list_.list_.begin(); it != tag_list_.list_.end(); ++it) {
3471  if (it->del_pending_)
3472  continue;
3473  if (it->tag_.get() == NULL)
3474  continue;
3475  tag_id_list->push_back(it->tag_->tag_id());
3476  }
3477  std::sort(tag_id_list->begin(), tag_id_list->end());
3478 }
3479 
3480 void VmInterface::update_flow_count(int val) const {
3482  int new_flow_count = flow_count_.fetch_add(val);
3483 
3484  {
3485  int maxv = std::max(max_flows_, agent()->global_max_vmi_flows());
3486  int minv = std::min(max_flows_, agent()->global_max_vmi_flows());
3489  maxv * ((max_flows_ != FLOWS_LIMIT_UNLIMITED) !=
3491  }
3492 
3494  // max_flows are not configured,
3495  // disable drop new flows and return
3497  return;
3498  }
3499 
3500  if (val < 0) {
3501  assert(new_flow_count >= val);
3502  if ((new_flow_count + val) <
3505  }
3506  } else {
3507  if ((new_flow_count + val) >= max_flows) {
3509  }
3510  }
3511 }
3512 
3515  return;
3516  }
3518  DBRequest req;
3520  req.key.reset(new VmInterfaceKey(AgentKey::RESYNC,
3521  GetUuid(), ""));
3523  agent()->interface_table()->Enqueue(&req);
3524 }
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
#define FLOWS_LIMIT_UNLIMITED
Definition: agent.h:307
std::vector< uint64_t > TagList
Definition: agent.h:203
std::vector< int > SecurityGroupList
Definition: agent.h:202
std::vector< Ip4Address > AddressList
Definition: agent.h:218
std::set< std::string > VnListType
Definition: agent.h:213
std::vector< std::string > CommunityList
Definition: bgp_config.h:348
Definition: acl.h:92
bool Populate(const autogen::MatchConditionType *match_condition)
std::vector< ActionSpec > action_l
AclEntryID id
static const uint8_t kMaxV4PrefixLen
Definition: address.h:21
static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix, uint16_t plen)
Definition: address.cc:180
static const uint8_t kMaxV6PrefixLen
Definition: address.h:23
static Ip6Address GetIp6SubnetAddress(const Ip6Address &prefix, uint16_t plen)
Definition: address.cc:201
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
AgentDBEntry * Find(const DBEntry *key, bool ret_del)
Definition: agent_db.cc:135
virtual void Process(DBRequest &req)
Definition: agent_db.cc:232
IFMapNode * ifmap_node() const
Definition: oper_db.h:80
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
MetaDataIpAllocator * metadata_ip6_allocator() const
Definition: agent.cc:961
TagTable * tag_table() const
Definition: agent.h:508
PortIpcHandler * port_ipc_handler() const
Definition: agent.cc:1009
@ BRIDGE
Definition: agent.h:423
VrfTable * vrf_table() const
Definition: agent.h:488
const Peer * mac_vm_binding_peer() const
Definition: agent.h:1037
const Peer * local_peer() const
Definition: agent.h:1025
AclTable * acl_table() const
Definition: agent.h:518
uint32_t global_max_vmi_flows() const
Definition: agent.h:1212
static const int kDropNewFlowsRecoveryThreshold
Definition: agent.h:401
const Peer * local_vm_peer() const
Definition: agent.h:1026
const std::string & fabric_vn_name() const
Definition: agent.h:904
bool is_l3mh() const
Definition: agent.h:728
BridgeDomainTable * bridge_domain_table() const
Definition: agent.cc:945
static uint16_t ProtocolStringToInt(const std::string &str)
Definition: agent.cc:1070
NextHopTable * nexthop_table() const
Definition: agent.h:478
static const MacAddress & vrrp_mac()
Definition: agent.h:442
SgTable * sg_table() const
Definition: agent.h:503
const std::string & fabric_vrf_name() const
Definition: agent.h:906
PolicySetTable * policy_set_table() const
Definition: agent.h:523
MetaDataIpAllocator * metadata_ip_allocator() const
Definition: agent.cc:953
void AddMacVmBindingRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *vm_intf, bool flood_dhcp)
BridgeRouteEntry * FindRoute(const MacAddress &mac)
Definition: bridge_route.cc:73
static void AddBridgeReceiveRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const std::string &vn_name, const std::string &interface, bool policy)
void DeleteMacVmBindingRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *vm_intf)
static void Delete(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, uint32_t ethernet_tag)
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
DBTableBase * get_table() const
Definition: db_entry.cc:120
bool IsDeleted() const
Definition: db_entry.h:49
void Delete()
Definition: db_entry.cc:132
bool Enqueue(DBRequest *req)
Definition: db_table.cc:221
void AddReceiveRoute(const Peer *peer, const std::string &vrf_name, uint32_t label, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag, const std::string &vn_name, const PathPreference &pref)
void DelLocalVmRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *intf, const IpAddress &ip, uint32_t ethernet_tag)
IFMapTable * table()
Definition: ifmap_node.h:30
virtual KeyPtr GetDBRequestKey() const
Definition: ifmap_node.cc:122
static void AddVHostRecvRoute(const Peer *peer, const string &vrf, const InterfaceKey &interface, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap, bool ipam_host_route=true)
static void AddResolveRoute(const Peer *peer, const string &vrf_name, const Ip4Address &ip, const uint8_t plen, const InterfaceKey &intf_key, const uint32_t label, bool policy, const std::string &vn_name, const SecurityGroupList &sg_list, const TagList &tag_list)
static void Delete(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen)
static void AddGatewayRoute(const Peer *peer, const string &vrf_name, const Ip4Address &dst_addr, uint8_t plen, const AddressList &gw_list, const VnListType &vn_name, uint32_t label, const SecurityGroupList &sg_list, const TagList &tag_list, const CommunityList &communities, bool native_encap)
static void AddVlanNHRoute(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, const boost::uuids::uuid &intf_uuid, uint16_t tag, uint32_t label, const VnListType &dest_vn_list, const SecurityGroupList &sg_list_, const TagList &tag_list, const PathPreference &path_preference)
static void CreateL2VmInterfaceNH(const boost::uuids::uuid &intf_uuid, const MacAddress &dmac, const string &vrf_name, bool learning_enabled, bool etree_leaf, bool layer2_control_word, const std::string &intf_name)
Definition: nexthop.cc:769
static void DeleteL2InterfaceNH(const boost::uuids::uuid &intf_uuid, const MacAddress &mac, const std::string &intf_name)
Definition: nexthop.cc:782
void set_delete_on_zero_refcount(bool val)
Definition: nexthop.h:1347
static void CreateMulticastVmInterfaceNH(const boost::uuids::uuid &intf_uuid, const MacAddress &dmac, const string &vrf_name, const string &intf_name)
Definition: nexthop.cc:789
static void DeleteMulticastVmInterfaceNH(const boost::uuids::uuid &intf_uuid, const MacAddress &dmac, const std::string &intf_name)
Definition: nexthop.cc:798
static void CreateL3VmInterfaceNH(const boost::uuids::uuid &intf_uuid, const MacAddress &dmac, const string &vrf_name, bool learning_enabled, const std::string &intf_name)
Definition: nexthop.cc:751
static void DeleteL3InterfaceNH(const boost::uuids::uuid &intf_uuid, const MacAddress &mac, const std::string &intf_name)
Definition: nexthop.cc:762
VnEntry * FindVnRef(const boost::uuids::uuid &uuid) const
Definition: interface.cc:306
const UpdateFloatingIpFn & update_floatingip_cb() const
Definition: interface.cc:634
void incr_active_vmi_count()
Definition: interface.h:462
Agent * agent() const
Definition: interface.h:450
void DeleteDhcpSnoopEntry(const std::string &ifname)
Definition: interface.cc:727
void decr_active_vmi_count()
Definition: interface.h:463
VrfEntry * FindVrfRef(const std::string &name) const
Definition: interface.cc:295
bool ipv6_active() const
Definition: interface.h:120
boost::uuids::uuid uuid_
Definition: interface.h:165
bool dhcp_enabled_
Definition: interface.h:178
NextHopConstRef flow_key_nh_
Definition: interface.h:188
const MacAddress & mac() const
Definition: interface.h:134
bool l2_active() const
Definition: interface.h:125
bool dhcp_enabled_v6_
Definition: interface.h:179
VrfEntry * vrf() const
Definition: interface.h:118
bool is_hc_active() const
Definition: interface.h:121
bool is_hc_active_
Definition: interface.h:172
bool metadata_l2_active_
Definition: interface.h:175
bool ipv4_active() const
Definition: interface.h:119
const std::string & name() const
Definition: interface.h:117
VrfEntryRef vrf_
Definition: interface.h:166
bool dns_enabled_
Definition: interface.h:180
bool metadata_ip_active() const
Definition: interface.h:122
bool metadata_ip_active_
Definition: interface.h:174
bool ipv4_active_
Definition: interface.h:169
bool ipv6_active_
Definition: interface.h:170
uint32_t label() const
Definition: interface.h:130
Type type_
Definition: interface.h:164
uint32_t l2_label_
Definition: interface.h:168
uint32_t l2_label() const
Definition: interface.h:131
bool l2_active_
Definition: interface.h:176
const boost::uuids::uuid & GetUuid() const
Definition: interface.h:116
size_t id_
Definition: interface.h:177
uint32_t label_
Definition: interface.h:167
Type type() const
Definition: interface.h:115
const uint32_t id() const
Definition: interface.h:126
std::string ToString() const
Definition: mac_address.cc:54
static const MacAddress kZeroMac
Definition: mac_address.h:150
uint32_t label() const
Definition: mpls.h:80
static const uint32_t kInvalidLabel
Definition: mpls.h:102
const MplsLabel * mpls_label() const
Definition: nexthop.h:435
Definition: peer.h:45
PolicySet * global_policy_set() const
Definition: policy_set.h:141
FirewallPolicyList & fw_policy_list()
Definition: policy_set.h:91
PortSubscribeTable * port_subscribe_table() const
IFMapNode * UuidToIFNode(const boost::uuids::uuid &u) const
static void Create(NextHopTable *table, const Interface *intf, bool policy)
Definition: nexthop.cc:1531
Definition: sg.h:36
static void Create(const boost::uuids::uuid &intf_uuid, uint16_t vlan_tag, const std::string &vrf_name, const MacAddress &smac, const MacAddress &dmac)
Definition: nexthop.cc:1704
bool dhcp_enable_v6_
FirewallPolicyList fw_policy_list_
FirewallPolicyList fwaas_fw_policy_list_
bool layer3_forwarding() const
void SetServiceVlanPathPreference(PathPreference *pref, const IpAddress &service_ip) const
bool UpdateState(const VmInterfaceState *attr, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
Agent * agent() const
VrfAssignRuleList vrf_assign_rule_list_
bool policy_enabled() const
VmInterface::VmiType vmi_type() const
std::string vrf_name_
HealthCheckInstanceSet hc_instance_set_
void DeleteL2InterfaceRoute(const VrfEntry *vrf, uint32_t ethernet_tag, const IpAddress &ip, const MacAddress &mac) const
ServiceVlanList service_vlan_list_
bool Resync(const InterfaceTable *table, const VmInterfaceData *data)
VmiReceiveRouteList receive_route_list_
virtual bool CmpInterface(const DBEntry &rhs) const
bool OnChange(VmInterfaceData *data)
const uint8_t subnet_plen() const
const NextHop * l2_interface_nh_policy() const
const Ip4Address & vm_ip_service_addr() const
bool drop_new_flows() const
LearntMacIpList learnt_mac_ip_list_
BridgeDomainList bridge_domain_list_
uint32_t max_flows() const
uint32_t ethernet_tag() const
bool IsMaxMacIpLearnt() const
virtual ~VmInterface()
bool IsActive() const
static const char * kServiceInterface
Definition: vm_interface.h:372
std::unique_ptr< MetaDataIpState > metadata_ip6_state_
AllowedAddressPairList allowed_address_pair_list_
bool ecmp() const
bool policy_enabled_
MetaDataIpMap metadata_ip_map_
bool IsIpv6Active() const
uint32_t max_flows_
bool etree_leaf() const
Ip4Address dhcp_addr() const
void AddL2InterfaceRoute(const IpAddress &ip, const MacAddress &mac, const IpAddress &dependent_ip) const
bool need_linklocal_ip() const
bool learning_enabled() const
IpAddress GetServiceIp(const IpAddress &ip) const
friend struct VmInterfaceNewFlowDropData
uint32_t label_op() const
void SetConfigurer(VmInterface::Configurer type)
std::unique_ptr< LocalVmPortPeer > peer_
void PostAdd()
std::unique_ptr< ResolveRouteState > resolve_route_state_
void DeleteRoute(const std::string &vrf_name, const IpAddress &ip, uint32_t plen)
bool IsMetaDataIPActive() const
bool IsMetaDataL2Active() const
void CleanupAliasIpList()
bool IsConfigurerSet(VmInterface::Configurer type)
void CopyTagIdList(TagList *tag_id_list) const
FatFlowPrefixAggregateType
Definition: vm_interface.h:449
@ AGGREGATE_SRC_DST_IPV6
Definition: vm_interface.h:454
@ AGGREGATE_SRC_DST_IPV4
Definition: vm_interface.h:457
SecurityGroupEntryList sg_list_
Ip6Address mdata_ip6_addr() const
const NextHop * l2_interface_nh_no_policy() const
void UpdateL2()
bool ResetVrfDelete(const InterfaceTable *table, const std::string &vrf_name)
bool DeleteState(VmInterfaceState *attr)
std::atomic< int > flow_count_
static const char * kInterfaceStatic
Definition: vm_interface.h:373
Ip4Address service_ip_
void CleanupFloatingIpList()
void ResetConfigurer(VmInterface::Configurer type)
bool IsVxlanMode() const
bool learning_enabled_
bool pbb_interface_
bool drop_new_flows_vmi_
std::unique_ptr< VmiRouteState > interface_route_state_
std::string ToString() const
bool contains_new_tags_
std::unique_ptr< NextHopState > nexthop_state_
AliasIpList alias_ip_list_
const MacAddress & GetVifMac(const Agent *) const
void GetNextHopInfo()
std::map< std::string, FatFlowIgnoreAddressType > IgnoreAddressMap
void SetInterfacesDropNewFlows(bool drop_new_flows) const
uint8_t subnet_plen_
Ip4Address vm_ip_service_addr_
bool do_dhcp_relay() const
VnEntryRef vn_
FloatingIpList floating_ip_list_
InstanceIpList instance_ipv4_list_
const MacAddress & vm_mac() const
Ip4Address subnet_
VmInterface(const boost::uuids::uuid &uuid, const std::string &name, bool os_oper_state, const boost::uuids::uuid &logical_router_uuid)
Definition: vm_interface.cc:49
bool UpdatePolicySet(const Agent *agent)
VmInterface::DeviceType device_type() const
bool bridging() const
const VnEntry * vn() const
bool dhcp_enable_config() const
std::unique_ptr< MacVmBindingState > mac_vm_binding_state_
void UpdateInterfaceHealthCheckService()
uint8_t configurer_
Ip4Address service_ip()
const Ip4Address & primary_ip_addr() const
bool IsL2Active() const
StaticRouteList static_route_list_
const Ip4Address & subnet() const
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)
TagEntryList tag_list_
void ApplyConfig(bool old_ipv4_active, bool old_l2_active, bool old_ipv6_active, const Ip4Address &old_subnet, const uint8_t old_subnet_plen)
std::unique_ptr< VrfTableLabelState > vrf_table_label_state_
bool layer2_control_word() const
VrfEntry * forwarding_vrf() const
static const char * kInterface
Definition: vm_interface.h:371
KeyPtr GetDBRequestKey() const
std::unique_ptr< MetaDataIpState > metadata_ip_state_
MacAddress vm_mac_
void SetPathPreference(PathPreference *pref, bool ecmp, const IpAddress &dependent_ip) const
Ip4Address mdata_ip_addr() const
const NextHop * l3_interface_nh_no_policy() const
const Ip6Address & primary_ip6_addr() const
bool PolicyEnabled() const
bool ecmp6() const
FatFlowList fat_flow_list_
static const uint32_t kMaxMacIpLimit
Definition: vm_interface.h:368
InstanceIpList instance_ipv6_list_
bool IsIpv4Active() const
void update_flow_count(int val) const
static IgnoreAddressMap fatflow_ignore_addr_map_
const Peer * peer() const
VmInterface::DeviceType device_type_
const std::string & vrf_name() const
Definition: vn.h:152
const string & GetName() const
Definition: vn.h:163
const VnIpam * GetIpam(const IpAddress &ip) const
Definition: vn.cc:653
uint32_t GetAllocUnitFromIpam(const IpAddress &ip) const
Definition: vn.cc:678
static void DeleteVlan(const boost::uuids::uuid &intf_uuid, uint16_t vlan_tag)
Definition: vrf_assign.cc:133
static void CreateVlan(const boost::uuids::uuid &intf_uuid, const std::string &vrf_name, uint16_t vlan_tag)
Definition: vrf_assign.cc:117
Definition: vrf.h:90
const string & GetName() const
Definition: vrf.h:104
uint32_t table_label() const
Definition: vrf.h:121
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:335
void CreateTableLabel(bool learning_enabled, bool l2, bool flod_unknown_unicast, bool layer2_control_word)
Definition: vrf.cc:119
bool ResetVrfDelete()
Definition: vrf.cc:466
AgentRouteTable * GetRouteTable(uint8_t table_type) const
Definition: vrf.cc:286
uint8_t type
Definition: load_balance.h:2
#define LOG(_Level, _Msg)
Definition: logging.h:35
#define LOCAL_VM_PORT_PEER_NAME
Definition: peer.h:19
Definition: acl.h:69
Definition: acl.h:62
std::vector< AclEntrySpec > acl_entry_specs_
VrfTranslateActionSpec vrf_translate
TrafficAction::TrafficActionType ta_type
TrafficAction::Action simple_action
@ ADD_DEL_CHANGE
Definition: agent_db.h:101
@ RESYNC
Definition: agent_db.h:104
DBOperation oper
Definition: db_table.h:43
@ DB_ENTRY_NOTIFY
Definition: db_table.h:41
@ DB_ENTRY_DELETE
Definition: db_table.h:40
@ 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
std::string vrf_name_
Definition: interface.h:268
void Copy(const Agent *agent, const VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
virtual ~MacVmBindingState()
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
const VrfEntry * vrf_
Definition: vm_interface.h:238
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
virtual ~MetaDataIpState()
MetaDataIpState(bool ipv4=true)
Creates a new instance of MetaDataIpState.
bool AddL3(const Agent *agent, VmInterface *vmi) const
std::unique_ptr< MetaDataIp > mdata_ip_
Definition: vm_interface.h:293
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
NextHopRef l3_mcast_nh_no_policy_
Definition: vm_interface.h:277
uint32_t l3_label_
Definition: vm_interface.h:275
NextHopRef l2_nh_policy_
Definition: vm_interface.h:269
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
uint32_t l2_label_
Definition: vm_interface.h:271
NextHopRef l3_nh_no_policy_
Definition: vm_interface.h:274
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
virtual ~NextHopState()
NextHopRef l2_nh_no_policy_
Definition: vm_interface.h:270
NextHopRef l3_nh_policy_
Definition: vm_interface.h:273
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
virtual ~ResolveRouteState()
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
const VrfEntry * vrf_
Definition: vm_interface.h:311
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
void Copy(const Agent *agent, const VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
Ip4Address subnet_
Definition: vm_interface.h:312
Definition: sg.h:14
virtual bool OnDelete(const InterfaceTable *table, VmInterface *entry) const
virtual bool OnResync(const InterfaceTable *table, VmInterface *vmi, bool *force_update) const =0
InterfaceKey * Clone() const
virtual bool Update(const Agent *agent, VmInterface *vmi, Op l2_force_op, Op l3_force_op) const
virtual bool AddL2(const Agent *agent, VmInterface *vmi) const
Definition: vm_interface.h:204
virtual void Copy(const Agent *agent, const VmInterface *vmi) const
Definition: vm_interface.h:200
virtual bool AddL3(const Agent *agent, VmInterface *vmi) const
Definition: vm_interface.h:214
virtual Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
Definition: vm_interface.h:188
virtual bool DeleteL2(const Agent *agent, VmInterface *vmi) const
Definition: vm_interface.h:209
virtual bool DeleteL3(const Agent *agent, VmInterface *vmi) const
Definition: vm_interface.h:219
virtual Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
Definition: vm_interface.h:195
static Op RecomputeOp(Op old_op, Op new_op)
void Update(const AliasIp *lhs, const AliasIp *rhs)
void Insert(const AliasIp *rhs)
void Remove(AliasIpSet::iterator &it)
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool IsLess(const AliasIp *rhs) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool operator()(const AliasIp &lhs, const AliasIp &rhs) const
void Copy(const Agent *agent, const VmInterface *vmi) const
void Update(const AllowedAddressPair *lhs, const AllowedAddressPair *rhs)
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Remove(AllowedAddressPairSet::iterator &it)
void Insert(const AllowedAddressPair *rhs)
bool AddL2(const Agent *agent, VmInterface *vmi) const
void Copy(const Agent *agent, const VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
bool IsLess(const AllowedAddressPair *rhs) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool operator()(const AllowedAddressPair &lhs, const AllowedAddressPair &rhs) const
void Update(const BridgeDomain *lhs, const BridgeDomain *rhs)
void Remove(BridgeDomainEntrySet::iterator &it)
void Insert(const BridgeDomain *rhs)
BridgeDomainEntrySet list_
static FatFlowEntry MakeFatFlowEntry(const std::string &protocol, const int &port, const std::string &ignore_addr_str, const std::string &src_prefix_str, const int &src_prefix_mask, const int &src_aggregate_plen, const std::string &dst_prefix_str, const int &dst_prefix_mask, const int &dst_aggregate_plen)
FatFlowPrefixAggregateType prefix_aggregate
void print(void) const
FatFlowIgnoreAddressType ignore_address
bool UpdateList(const Agent *agent, VmInterface *vmi)
void Remove(FatFlowEntrySet::iterator &it)
void Insert(const FatFlowEntry *rhs)
void Update(const FatFlowEntry *lhs, const FatFlowEntry *rhs)
void Insert(const FloatingIp *rhs)
void Remove(FloatingIpSet::iterator &it)
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Update(const FloatingIp *lhs, const FloatingIp *rhs)
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
int32_t GetDstPortMap(uint8_t protocol, uint16_t dst_port) const
uint32_t PortMappingSize() const
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
bool IsLess(const FloatingIp *rhs) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
std::map< PortMapKey, uint16_t, PortMapKey > PortMap
Definition: vm_interface.h:512
int32_t GetSrcPortMap(uint8_t protocol, uint16_t src_port) const
void Copy(const Agent *agent, const VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
const IpAddress GetFixedIp(const VmInterface *) const
bool operator()(const FloatingIp &lhs, const FloatingIp &rhs) const
PortMap::iterator PortMapIterator
Definition: vm_interface.h:513
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool port_map_enabled() const
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
virtual bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Insert(const InstanceIp *rhs)
void Remove(InstanceIpSet::iterator &it)
void Update(const InstanceIp *lhs, const InstanceIp *rhs)
const IpAddress ip_
Definition: vm_interface.h:925
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
void SetPrefixForAllocUnitIpam(VmInterface *intrface) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
void Copy(const Agent *agent, const VmInterface *vmi) const
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool IsLess(const InstanceIp *rhs) const
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
bool operator()(const InstanceIp &lhs, const InstanceIp &rhs) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
void Update(const LearntMacIp *lhs, const LearntMacIp *rhs)
virtual bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Insert(const LearntMacIp *rhs)
void Remove(const LearntMacIp *rhs)
void Copy(const Agent *agent, const VmInterface *vmi) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
bool operator()(const LearntMacIp &lhs, const LearntMacIp &rhs) const
bool IsLess(const LearntMacIp *rhs) const
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
bool del_pending() const
Definition: vm_interface.h:479
void set_del_pending(bool val) const
Definition: vm_interface.h:480
VmInterfaceState::Op GetOp(VmInterfaceState::Op op) const
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Insert(const SecurityGroupEntry *rhs)
void Update(const SecurityGroupEntry *lhs, const SecurityGroupEntry *rhs)
void Remove(SecurityGroupEntrySet::iterator &it)
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool IsLess(const SecurityGroupEntry *rhs) const
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Remove(ServiceVlanSet::iterator &it)
void Insert(const ServiceVlan *rhs)
void Update(const ServiceVlan *lhs, const ServiceVlan *rhs)
bool operator()(const ServiceVlan &lhs, const ServiceVlan &rhs) const
void DeleteCommon(const VmInterface *vmi) const
bool IsLess(const ServiceVlan *rhs) const
void AddCommon(const Agent *agent, const VmInterface *vmi) const
void Update(const Agent *agent, VmInterface *vmi) const
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Update(const StaticRoute *lhs, const StaticRoute *rhs)
void Insert(const StaticRoute *rhs)
void Remove(StaticRouteSet::iterator &it)
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool IsLess(const StaticRoute *rhs) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool operator()(const StaticRoute &lhs, const StaticRoute &rhs) const
void Copy(const Agent *agent, const VmInterface *vmi) const
CommunityList communities_
Definition: vm_interface.h:702
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Insert(const TagEntry *rhs)
void Update(const TagEntry *lhs, const TagEntry *rhs)
void Remove(TagEntrySet::iterator &it)
bool operator()(const TagEntry &lhs, const TagEntry &rhs) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
bool IsLess(const TagEntry *rhs) const
bool operator==(const TagEntry &rhs) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
boost::uuids::uuid uuid_
Definition: vm_interface.h:829
void Remove(VmiReceiveRouteSet::iterator &it)
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
void Insert(const VmiReceiveRoute *rhs)
void Update(const VmiReceiveRoute *lhs, const VmiReceiveRoute *rhs)
void Copy(const Agent *agent, const VmInterface *vmi) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
bool IsLess(const VmiReceiveRoute *rhs) const
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
bool AddL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
bool operator()(const VmiReceiveRoute &lhs, const VmiReceiveRoute &rhs) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
void Insert(const VrfAssignRule *rhs)
void Remove(VrfAssignRuleSet::iterator &it)
void Update(const VrfAssignRule *lhs, const VrfAssignRule *rhs)
bool UpdateList(const Agent *agent, VmInterface *vmi, VmInterfaceState::Op l2_force_op, VmInterfaceState::Op l3_force_op)
bool IsLess(const VrfAssignRule *rhs) const
bool operator()(const VrfAssignRule &lhs, const VrfAssignRule &rhs) const
autogen::MatchConditionType match_condition_
Definition: vm_interface.h:865
const VrfEntry * vrf_
Definition: vm_interface.h:330
uint32_t ethernet_tag_
Definition: vm_interface.h:332
bool AddL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL2(const Agent *agent, const VmInterface *vmi) const
bool DeleteL3(const Agent *agent, VmInterface *vmi) const
bool AddL2(const Agent *agent, VmInterface *vmi) const
virtual ~VmiRouteState()
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
Ip4Address ip_
Definition: vm_interface.h:331
bool DeleteL2(const Agent *agent, VmInterface *vmi) const
void Copy(const Agent *agent, const VmInterface *vmi) const
Definition: vrf.h:26
bool AddL3(const Agent *agent, VmInterface *vmi) const
VmInterfaceState::Op GetOpL3(const Agent *agent, const VmInterface *vmi) const
virtual ~VrfTableLabelState()
void set_ignore_acl(bool ignore_acl)
void set_vrf_name(const std::string &vrf_name)
static bool GetIpActiveState(const IpAddress &ip, const VmInterface *vmi)
static bool GetInstanceIpActiveState(const VmInterface::InstanceIp *instance_ip, const VmInterface *vmi)
static bool GetMacIpActiveState(const VmInterface::LearntMacIp *mac_ip, const VmInterface *vmi)
std::vector< AclDBEntryConstRef > FirewallPolicyList
Definition: vm_interface.h:110
boost::uuids::uuid uuid