def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" LOG.debug("add gateway interface(%s)", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, mtu=ex_gw_port.get('mtu')) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) self.update_gateway_port(ex_gw_port) cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] # TODO(Carl) mlavelle's work has self.ip_wrapper ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name, prefix, mtu=None): LOG.debug("adding internal network: prefix(%s), port(%s)", prefix, port_id) self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ns_name, prefix=prefix, mtu=mtu) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_router_port(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in fixed_ips: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def external_gateway_updated(self, ex_gw_port, interface_name): self._plug_external_gateway( ex_gw_port, interface_name, self.ha_namespace) ip_cidrs = common_utils.fixed_ip_cidrs(self.ex_gw_port['fixed_ips']) for old_gateway_cidr in ip_cidrs: self._remove_vip(old_gateway_cidr) self._add_gateway_vip(ex_gw_port, interface_name)
def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" LOG.debug("add gateway interface(%s)", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, mtu=ex_gw_port.get('mtu')) # Remove stale fg devices ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) devices = ip_wrapper.get_devices() for device in devices: name = device.name if name.startswith(FIP_EXT_DEV_PREFIX) and name != interface_name: ext_net_bridge = self.agent_conf.external_network_bridge self.driver.unplug(name, bridge=ext_net_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) self.update_gateway_port(ex_gw_port) cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): LOG.debug("External gateway added: port(%s), interface(%s), ns(%s)", ex_gw_port, interface_name, ns_name) self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips, enable_ra_on_gw = self._get_external_gw_ips(ex_gw_port) self.driver.init_router_port( interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw, clean_connections=True) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" LOG.debug("add gateway interface(%s)", interface_name) ns_name = self.get_name() self.driver.plug( ex_gw_port["network_id"], ex_gw_port["id"], interface_name, ex_gw_port["mac_address"], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, ) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port["fixed_ips"]) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) for fixed_ip in ex_gw_port["fixed_ips"]: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip["ip_address"], self.agent_conf) for subnet in ex_gw_port["subnets"]: gw_ip = subnet.get("gateway_ip") if gw_ip: ipd = ip_lib.IPDevice(interface_name, namespace=ns_name) ipd.route.add_gateway(gw_ip) cmd = ["sysctl", "-w", "net.ipv4.conf.%s.proxy_arp=1" % interface_name] # TODO(Carl) mlavelle's work has self.ip_wrapper ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): call_create_ratelimit_qdisc = True self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) # add TC root qdisc when add external gateway if call_create_ratelimit_qdisc: LOG.info('router %s in netns %s _create_ratelimit_qdisc called', self.router_id, ns_name) self._create_ratelimit_qdisc(ip_wrapper, interface_name) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" ns_name = self.get_name() if not ip_lib.device_exists(interface_name, namespace=ns_name): self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha) for subnet in ex_gw_port['subnets']: gw_ip = subnet.get('gateway_ip') if gw_ip: ipd = ip_lib.IPDevice(interface_name, namespace=ns_name) ipd.route.add_gateway(gw_ip) cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] # TODO(Carl) mlavelle's work has self.ip_wrapper ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): LOG.debug("External gateway added: port(%s), interface(%s), ns(%s)", ex_gw_port, interface_name, ns_name) self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port["fixed_ips"]) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True self.driver.init_router_port( interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get("extra_subnets", []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw, clean_connections=True, ) for fixed_ip in ex_gw_port["fixed_ips"]: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip["ip_address"], self.agent_conf)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = [] enable_ra_on_gw = False if 'subnets' in ex_gw_port: gateway_ips = [subnet['gateway_ip'] for subnet in ex_gw_port['subnets'] if subnet['gateway_ip']] if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # No IPv6 gateway is available, but IPv6 is enabled. if self.agent_conf.ipv6_gateway: # ipv6_gateway configured, use address for default route. gateway_ips.append(self.agent_conf.ipv6_gateway) else: # ipv6_gateway is also not configured. # Use RA for default route. enable_ra_on_gw = True self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = [] enable_ra_on_gw = False if 'subnets' in ex_gw_port: gateway_ips = [ subnet['gateway_ip'] for subnet in ex_gw_port['subnets'] if subnet['gateway_ip'] ] if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # No IPv6 gateway is available, but IPv6 is enabled. if self.agent_conf.ipv6_gateway: # ipv6_gateway configured, use address for default route. gateway_ips.append(self.agent_conf.ipv6_gateway) else: # ipv6_gateway is also not configured. # Use RA for default route. enable_ra_on_gw = True self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): call_create_ratelimit_qdisc = True self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) # add TC root qdisc when add external gateway if call_create_ratelimit_qdisc: LOG.info('router %s in netns %s _create_ratelimit_qdisc called', self.router_id, ns_name) self._create_ratelimit_qdisc( ip_wrapper, interface_name) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha) for subnet in ex_gw_port['subnets']: gw_ip = subnet.get('gateway_ip') if gw_ip: ipd = ip_lib.IPDevice(interface_name, namespace=ns_name) ipd.route.add_gateway(gw_ip) cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] # TODO(Carl) mlavelle's work has self.ip_wrapper ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): LOG.debug("External gateway added: port(%s), interface(%s), ns(%s)", ex_gw_port, interface_name, ns_name) self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True self.driver.init_router_port( interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw, clean_connections=True) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name, prefix): LOG.debug("adding internal network: prefix(%s), port(%s)", prefix, port_id) self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ns_name, prefix=prefix) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_router_port(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in fixed_ips: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip["ip_address"], self.agent_conf)
def _create_gateway_port(self, ex_gw_port, interface_name): """Create namespace, request port creationg from Plugin, then configure Floating IP gateway port. """ self.create() LOG.debug("DVR: adding gateway interface: %s", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, mtu=ex_gw_port.get('mtu')) if self.agent_conf.external_network_bridge: # NOTE(Swami): for OVS implementations remove the DEAD VLAN tag # on ports. DEAD VLAN tag is added to each newly created port # and should be removed by L2 agent but if # external_network_bridge is set than external gateway port is # created in this bridge and will not be touched by L2 agent. # This is related to lp#1767422 self.driver.remove_vlan_tag( self.agent_conf.external_network_bridge, interface_name) # Remove stale fg devices ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) devices = ip_wrapper.get_devices() for device in devices: name = device.name if name.startswith(FIP_EXT_DEV_PREFIX) and name != interface_name: LOG.debug('DVR: unplug: %s', name) ext_net_bridge = self.agent_conf.external_network_bridge self.driver.unplug(name, bridge=ext_net_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) gw_cidrs = [ sn['cidr'] for sn in ex_gw_port['subnets'] if sn.get('cidr') ] self.driver.set_onlink_routes(interface_name, ns_name, ex_gw_port.get('extra_subnets', []), preserve_ips=gw_cidrs, is_ipv6=False) self.agent_gateway_port = ex_gw_port cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] ip_wrapper.netns.execute(cmd, check_exit_code=False)
def internal_network_updated(self, port): interface_name = self.get_internal_device_name(port['id']) ip_cidrs = common_utils.fixed_ip_cidrs(port['fixed_ips']) mtu = port['mtu'] self.driver.set_mtu(interface_name, mtu, namespace=self.ns_name, prefix=router.INTERNAL_DEV_PREFIX) self._clear_vips(interface_name) self._disable_ipv6_addressing_on_interface(interface_name) for ip_cidr in ip_cidrs: self._add_vip(ip_cidr, interface_name)
def _get_port_devicename_scopemark(self, ports, name_generator): devicename_scopemark = {l3_constants.IP_VERSION_4: dict(), l3_constants.IP_VERSION_6: dict()} for p in ports: device_name = name_generator(p["id"]) ip_cidrs = common_utils.fixed_ip_cidrs(p["fixed_ips"]) port_as_marks = self.get_port_address_scope_mark(p) for ip_version in {ip_lib.get_ip_version(cidr) for cidr in ip_cidrs}: devicename_scopemark[ip_version][device_name] = port_as_marks[ip_version] return devicename_scopemark
def _process_internal_ports(self): existing_port_ids = set(p['id'] for p in self.internal_ports) internal_ports = self.router.get(l3_constants.INTERFACE_KEY, []) current_port_ids = set(p['id'] for p in internal_ports if p['admin_state_up']) new_port_ids = current_port_ids - existing_port_ids new_ports = [p for p in internal_ports if p['id'] in new_port_ids] old_ports = [ p for p in self.internal_ports if p['id'] not in current_port_ids ] updated_ports = self._get_updated_ports(self.internal_ports, internal_ports) enable_ra = False for p in new_ports: self.internal_network_added(p) self.internal_ports.append(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) for p in old_ports: self.internal_network_removed(p) self.internal_ports.remove(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) if updated_ports: for index, p in enumerate(internal_ports): if not updated_ports.get(p['id']): continue self.internal_ports[index] = updated_ports[p['id']] interface_name = self.get_internal_device_name(p['id']) ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs=ip_cidrs, namespace=self.ns_name) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) # Enable RA if enable_ra: self.enable_radvd(internal_ports) existing_devices = self._get_existing_devices() current_internal_devs = set(n for n in existing_devices if n.startswith(INTERNAL_DEV_PREFIX)) current_port_devs = set( self.get_internal_device_name(port_id) for port_id in current_port_ids) stale_devs = current_internal_devs - current_port_devs for stale_dev in stale_devs: LOG.debug('Deleting stale internal router device: %s', stale_dev) self.driver.unplug(stale_dev, namespace=self.ns_name, prefix=INTERNAL_DEV_PREFIX)
def _check_if_route_applicable_to_fip_namespace( self, route, agent_gateway_port): ip_cidrs = common_utils.fixed_ip_cidrs(agent_gateway_port['fixed_ips']) nexthop_cidr = netaddr.IPAddress(route['nexthop']) for gw_cidr in ip_cidrs: gw_subnet_cidr = netaddr.IPNetwork(gw_cidr) # NOTE: In the case of DVR routers apply the extra routes # on the FIP namespace only if it is associated with the # external agent gateway subnets. if nexthop_cidr in gw_subnet_cidr: return True return False
def _process_internal_ports(self): existing_port_ids = set(p['id'] for p in self.internal_ports) internal_ports = self.router.get(l3_constants.INTERFACE_KEY, []) current_port_ids = set(p['id'] for p in internal_ports if p['admin_state_up']) new_port_ids = current_port_ids - existing_port_ids new_ports = [p for p in internal_ports if p['id'] in new_port_ids] old_ports = [p for p in self.internal_ports if p['id'] not in current_port_ids] updated_ports = self._get_updated_ports(self.internal_ports, internal_ports) enable_ra = False for p in new_ports: self.internal_network_added(p) self.internal_ports.append(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) for p in old_ports: self.internal_network_removed(p) self.internal_ports.remove(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) if updated_ports: for index, p in enumerate(internal_ports): if not updated_ports.get(p['id']): continue self.internal_ports[index] = updated_ports[p['id']] interface_name = self.get_internal_device_name(p['id']) ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs=ip_cidrs, namespace=self.ns_name) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) # Enable RA if enable_ra: self.enable_radvd(internal_ports) existing_devices = self._get_existing_devices() current_internal_devs = set(n for n in existing_devices if n.startswith(INTERNAL_DEV_PREFIX)) current_port_devs = set(self.get_internal_device_name(port_id) for port_id in current_port_ids) stale_devs = current_internal_devs - current_port_devs for stale_dev in stale_devs: LOG.debug('Deleting stale internal router device: %s', stale_dev) self.driver.unplug(stale_dev, namespace=self.ns_name, prefix=INTERNAL_DEV_PREFIX)
def _create_gateway_port(self, ex_gw_port, interface_name): """Create namespace, request port creationg from Plugin, then configure Floating IP gateway port. """ self.create() LOG.debug("DVR: adding gateway interface: %s", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, mtu=ex_gw_port.get('mtu')) if self.agent_conf.external_network_bridge: # NOTE(Swami): for OVS implementations remove the DEAD VLAN tag # on ports. DEAD VLAN tag is added to each newly created port # and should be removed by L2 agent but if # external_network_bridge is set than external gateway port is # created in this bridge and will not be touched by L2 agent. # This is related to lp#1767422 self.driver.remove_vlan_tag( self.agent_conf.external_network_bridge, interface_name) # Remove stale fg devices ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) devices = ip_wrapper.get_devices() for device in devices: name = device.name if name.startswith(FIP_EXT_DEV_PREFIX) and name != interface_name: LOG.debug('DVR: unplug: %s', name) ext_net_bridge = self.agent_conf.external_network_bridge self.driver.unplug(name, bridge=ext_net_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) gw_cidrs = [sn['cidr'] for sn in ex_gw_port['subnets'] if sn.get('cidr')] self.driver.set_onlink_routes( interface_name, ns_name, ex_gw_port.get('extra_subnets', []), preserve_ips=gw_cidrs, is_ipv6=False) self.agent_gateway_port = ex_gw_port cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] ip_wrapper.netns.execute(cmd, check_exit_code=False)
def ha_network_added(self): interface_name = self.get_ha_device_name() self.driver.plug(self.ha_port['network_id'], self.ha_port['id'], interface_name, self.ha_port['mac_address'], namespace=self.ns_name, prefix=HA_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(self.ha_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=self.ns_name, preserve_ips=[self._get_primary_vip()])
def _get_port_devicename_scopemark(self, ports, name_generator): devicename_scopemark = {lib_constants.IP_VERSION_4: dict(), lib_constants.IP_VERSION_6: dict()} for p in ports: device_name = name_generator(p['id']) ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips']) port_as_marks = self.get_port_address_scope_mark(p) for ip_version in {common_utils.get_ip_version(cidr) for cidr in ip_cidrs}: devicename_scopemark[ip_version][device_name] = ( port_as_marks[ip_version]) return devicename_scopemark
def internal_network_added(self, port): port_id = port['id'] interface_name = self.get_internal_device_name(port_id) self.driver.plug(port['network_id'], port_id, interface_name, port['mac_address'], namespace=self.ns_name, prefix=router.INTERNAL_DEV_PREFIX) self._disable_ipv6_addressing_on_interface(interface_name) for ip_cidr in common_utils.fixed_ip_cidrs(port['fixed_ips']): self._add_vip(ip_cidr, interface_name)
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name, prefix): self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ns_name, prefix=prefix) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in fixed_ips: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name, prefix): self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ns_name, prefix=prefix) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in fixed_ips: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name, prefix): if not ip_lib.device_exists(interface_name, namespace=ns_name): self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ns_name, prefix=prefix) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in fixed_ips: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def ha_network_added(self): interface_name = self.get_ha_device_name() self.driver.plug( self.ha_port["network_id"], self.ha_port["id"], interface_name, self.ha_port["mac_address"], namespace=self.ha_namespace, prefix=HA_DEV_PREFIX, mtu=self.ha_port.get("mtu"), ) ip_cidrs = common_utils.fixed_ip_cidrs(self.ha_port["fixed_ips"]) self.driver.init_l3( interface_name, ip_cidrs, namespace=self.ha_namespace, preserve_ips=[self._get_primary_vip()] )
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name, prefix): if not ip_lib.device_exists(interface_name, namespace=ns_name): self.driver.plug(network_id, port_id, interface_name, mac_address, namespace=ns_name, prefix=prefix) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name) for fixed_ip in fixed_ips: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): LOG.debug("External gateway added: port(%s), interface(%s), ns(%s)", ex_gw_port, interface_name, ns_name) self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True self._add_route_to_gw(ex_gw_port, device_name=interface_name, namespace=ns_name, preserve_ips=preserve_ips) self.driver.init_router_port(interface_name, ip_cidrs, namespace=ns_name, extra_subnets=ex_gw_port.get( 'extra_subnets', []), preserve_ips=preserve_ips, clean_connections=True) device = ip_lib.IPDevice(interface_name, namespace=ns_name) current_gateways = set() for ip_version in (l3_constants.IP_VERSION_4, l3_constants.IP_VERSION_6): gateway = device.route.get_gateway(ip_version=ip_version) if gateway and gateway.get('gateway'): current_gateways.add(gateway.get('gateway')) for ip in current_gateways - set(gateway_ips): device.route.delete_gateway(ip) for ip in gateway_ips: device.route.add_gateway(ip) if enable_ra_on_gw: self.driver.configure_ipv6_ra(ns_name, interface_name) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def _internal_network_added(self, ns_name, network_id, port_id, fixed_ips, mac_address, interface_name): LOG.debug("adding internal network: port(%s)", port_id) #import ipdb;ipdb.set_trace() self.driver.plug_new(network_id, port_id, interface_name, fixed_ips, mac_address, namespace=ns_name) ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_router_port( interface_name, ip_cidrs, namespace=ns_name) if interface_name not in consts.FTNT_PORTS: for fixed_ip in fixed_ips: # samsu: arp maynot needed in this case ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): LOG.debug("External gateway added: port(%s), interface(%s), ns(%s)", ex_gw_port, interface_name, ns_name) self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips = self._get_external_gw_ips(ex_gw_port) enable_ra_on_gw = False if self.use_ipv6 and not self.is_v6_gateway_set(gateway_ips): # There is no IPv6 gw_ip, use RouterAdvt for default route. enable_ra_on_gw = True self._add_route_to_gw(ex_gw_port, device_name=interface_name, namespace=ns_name, preserve_ips=preserve_ips) self.driver.init_router_port( interface_name, ip_cidrs, namespace=ns_name, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, clean_connections=True) device = ip_lib.IPDevice(interface_name, namespace=ns_name) current_gateways = set() for ip_version in (l3_constants.IP_VERSION_4, l3_constants.IP_VERSION_6): gateway = device.route.get_gateway(ip_version=ip_version) if gateway and gateway.get('gateway'): current_gateways.add(gateway.get('gateway')) for ip in current_gateways - set(gateway_ips): device.route.delete_gateway(ip) for ip in gateway_ips: device.route.add_gateway(ip) if enable_ra_on_gw: self.driver.configure_ipv6_ra(ns_name, interface_name) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf)
def internal_network_updated(self, port): interface_name = self.get_internal_device_name(port['id']) ip_cidrs = common_utils.fixed_ip_cidrs(port['fixed_ips']) mtu = port['mtu'] self.driver.set_mtu(interface_name, mtu, namespace=self.ns_name, prefix=router_info.INTERNAL_DEV_PREFIX) self._clear_vips(interface_name) # NOTE(slaweq): qr- interface is not in ha_namespace but in qrouter # namespace in case of dvr ha ruter self._disable_ipv6_addressing_on_interface(interface_name, namespace=self.ns_name) for ip_cidr in ip_cidrs: self._add_vip(ip_cidr, interface_name) self._set_snat_interfce_mtu(port)
def external_gateway_added(self, ex_gw_port, external_dlname): LOG.debug("External gateway added: port(%s), interface(%s)", ex_gw_port, external_dlname) # TODO(gmoodalb): add MTU to plug()? self.driver.plug(ex_gw_port['tenant_id'], ex_gw_port['network_id'], ex_gw_port['id'], external_dlname, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, vif_type=ex_gw_port.get('binding:vif_type')) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(external_dlname, ip_cidrs) for fixed_ip in ex_gw_port['fixed_ips']: net_lib.send_ip_addr_adv_notif(external_dlname, fixed_ip['ip_address'], self.agent_conf) # add nested anchor rule first anchor_option = "on %s" % external_dlname self.pf.add_nested_anchor_rule(None, external_dlname, anchor_option) gw_ip = ex_gw_port['subnets'][0]['gateway_ip'] if gw_ip: cmd = ['/usr/bin/pfexec', '/usr/sbin/route', 'add', 'default', gw_ip] stdout = utils.execute(cmd, extra_ok_codes=[errno.EEXIST]) if 'entry exists' not in stdout: self.remove_route = True # for each of the internal ports, add Policy Based Routing (PBR) # rule iff ex_gw_ip is IPv4 and the internal port is IPv4 if netaddr.IPAddress(gw_ip).version != 4: return for port in self.internal_ports: port_subnet = port['subnets'][0]['cidr'] if netaddr.IPNetwork(port_subnet).version != 4: continue internal_dlname = self.get_internal_device_name(port['id']) label = 'pbr_%s' % internal_dlname pbr_rules = ['pass in quick to !%s route-to {(%s %s)} ' 'label %s_in' % (port_subnet, external_dlname, gw_ip, label)] pbr_rules.append('pass out quick received-on %s reply-to %s@%s' ' label %s_out' % (external_dlname, gw_ip, external_dlname, label)) self.pf.add_rules(pbr_rules, [internal_dlname, 'pbr'])
def _create_gateway_port(self, ex_gw_port, interface_name): """Create namespace, request port creationg from Plugin, then configure Floating IP gateway port. """ self.create() LOG.debug("DVR: adding gateway interface: %s", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, mtu=ex_gw_port.get('mtu')) # Remove stale fg devices ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) devices = ip_wrapper.get_devices() for device in devices: name = device.name if name.startswith(FIP_EXT_DEV_PREFIX) and name != interface_name: LOG.debug('DVR: unplug: %s', name) self.driver.unplug(name, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) gw_cidrs = [ sn['cidr'] for sn in ex_gw_port['subnets'] if sn.get('cidr') ] self.driver.set_onlink_routes(interface_name, ns_name, ex_gw_port.get('extra_subnets', []), preserve_ips=gw_cidrs, is_ipv6=False) self.agent_gateway_port = ex_gw_port cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): self._plug_external_gateway(ex_gw_port, interface_name, ns_name) # Build up the interface and gateway IP addresses that # will be added to the interface. ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) gateway_ips, enable_ra_on_gw = self._get_external_gw_ips(ex_gw_port) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, gateway_ips=gateway_ips, extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips, enable_ra_on_gw=enable_ra_on_gw) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_gratuitous_arp(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha)
def _create_gateway_port(self, ex_gw_port, interface_name): """Create namespace, request port creationg from Plugin, then configure Floating IP gateway port. """ self.create() LOG.debug("DVR: adding gateway interface: %s", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX, mtu=ex_gw_port.get('mtu')) # Remove stale fg devices ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) devices = ip_wrapper.get_devices() for device in devices: name = device.name if name.startswith(FIP_EXT_DEV_PREFIX) and name != interface_name: LOG.debug('DVR: unplug: %s', name) self.driver.unplug(name, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) gw_cidrs = [sn['cidr'] for sn in ex_gw_port['subnets'] if sn.get('cidr')] self.driver.set_onlink_routes( interface_name, ns_name, ex_gw_port.get('extra_subnets', []), preserve_ips=gw_cidrs, is_ipv6=False) self.agent_gateway_port = ex_gw_port cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" LOG.debug("add gateway interface(%s)", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) self.update_gateway_port(ex_gw_port) cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] # TODO(Carl) mlavelle's work has self.ip_wrapper ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _gateway_added(self, ex_gw_port, interface_name): """Add Floating IP gateway port.""" LOG.debug("add gateway interface(%s)", interface_name) ns_name = self.get_name() self.driver.plug(ex_gw_port['network_id'], ex_gw_port['id'], interface_name, ex_gw_port['mac_address'], bridge=self.agent_conf.external_network_bridge, namespace=ns_name, prefix=FIP_EXT_DEV_PREFIX) ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']) self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name, clean_connections=True) for fixed_ip in ex_gw_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf) for subnet in ex_gw_port['subnets']: gw_ip = subnet.get('gateway_ip') if gw_ip: is_gateway_not_in_subnet = not ipam_utils.check_subnet_ip( subnet.get('cidr'), gw_ip) ipd = ip_lib.IPDevice(interface_name, namespace=ns_name) if is_gateway_not_in_subnet: ipd.route.add_route(gw_ip, scope='link') ipd.route.add_gateway(gw_ip) cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name] # TODO(Carl) mlavelle's work has self.ip_wrapper ip_wrapper = ip_lib.IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(cmd, check_exit_code=False)
def _add_gateway_vip(self, ex_gw_port, interface_name): for ip_cidr in common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips']): self._add_vip(ip_cidr, interface_name) self._add_default_gw_virtual_route(ex_gw_port, interface_name)
def internal_network_added(self, port): internal_dlname = self.get_internal_device_name(port['id']) LOG.debug("adding internal network: port(%s), interface(%s)", port['id'], internal_dlname) # driver just returns if datalink and IP interface already exists self.driver.plug(port['tenant_id'], port['network_id'], port['id'], internal_dlname, port['mac_address'], vif_type=port.get('binding:vif_type')) fixed_ips = port['fixed_ips'] ip_cidrs = common_utils.fixed_ip_cidrs(fixed_ips) self.driver.init_l3(internal_dlname, ip_cidrs) for fixed_ip in fixed_ips: net_lib.send_ip_addr_adv_notif(internal_dlname, fixed_ip['ip_address'], self.agent_conf) port_subnet = port['subnets'][0]['cidr'] ipversion = netaddr.IPNetwork(port_subnet).version rules = [] # if metadata is enabled, then we need to redirect all the packets # arriving at 169.254.169.254:80 to neutron-metadata-proxy server # listening at self.agent_conf.metadata_port if self.agent_conf.enable_metadata_proxy and ipversion == 4: rules.append('pass in quick proto tcp to 169.254.169.254/32 ' 'port 80 rdr-to 127.0.0.1 port %s label metadata_%s' % (self.agent_conf.metadata_port, internal_dlname)) # Since we support shared router model, we need to block the new # internal port from reaching other tenant's ports. However, if # allow_forwarding_between_networks is set, then we need to # allow forwarding of packets between same tenant's ports. block_tblname = 'block_%s' % internal_dlname rules.append('block in quick to <%s> label %s' % (block_tblname, block_tblname)) if self.agent_conf.allow_forwarding_between_networks: allow_tblname = 'allow_%s' % internal_dlname rules.append('pass in quick to <%s> reply-to %s label %s' % (allow_tblname, internal_dlname, allow_tblname)) # finally add all the rules in one shot self.pf.add_rules(rules, [internal_dlname, 'normal']) ex_gw_port = self.ex_gw_port if not ex_gw_port: return ex_gw_ip = ex_gw_port['subnets'][0]['gateway_ip'] if not ex_gw_ip: return if netaddr.IPAddress(ex_gw_ip).version != 4 or ipversion != 4: return # if the external gateway is already setup for the shared router, # then we need to add Policy Based Routing (PBR) for both inbound # and outbound for this internal network external_dlname = self.get_external_device_name(ex_gw_port['id']) label = 'pbr_%s' % internal_dlname pbr_rules = ['pass in quick to !%s route-to {(%s %s)} label %s_in' % (port_subnet, external_dlname, ex_gw_ip, label)] pbr_rules.append('pass out quick received-on %s reply-to %s@%s ' 'label %s_out' % (external_dlname, ex_gw_ip, external_dlname, label)) self.pf.add_rules(pbr_rules, [internal_dlname, 'pbr']) if self._snat_enabled: ex_gw_port_ip = ex_gw_port['fixed_ips'][0]['ip_address'] label = 'snat_%s' % internal_dlname snat_rule = ('pass out quick from %s to any nat-to %s label %s ' 'reply-to %s' % (port_subnet, ex_gw_port_ip, label, internal_dlname)) self.pf.add_rules([snat_rule], [external_dlname, internal_dlname])
def _add_vips(self, port, interface_name): for ip_cidr in common_utils.fixed_ip_cidrs(port['fixed_ips']): self._add_vip(ip_cidr, interface_name)
def _process_internal_ports(self, pd): existing_port_ids = set(p['id'] for p in self.internal_ports) internal_ports = self.router.get(l3_constants.INTERFACE_KEY, []) current_port_ids = set(p['id'] for p in internal_ports if p['admin_state_up']) new_port_ids = current_port_ids - existing_port_ids new_ports = [p for p in internal_ports if p['id'] in new_port_ids] old_ports = [p for p in self.internal_ports if p['id'] not in current_port_ids] updated_ports = self._get_updated_ports(self.internal_ports, internal_ports) enable_ra = False for p in new_ports: self.internal_network_added(p) LOG.debug("appending port %s to internal_ports cache", p) self.internal_ports.append(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) for subnet in p['subnets']: if ipv6_utils.is_ipv6_pd_enabled(subnet): interface_name = self.get_internal_device_name(p['id']) pd.enable_subnet(self.router_id, subnet['id'], subnet['cidr'], interface_name, p['mac_address']) for p in old_ports: self.internal_network_removed(p) LOG.debug("removing port %s from internal_ports cache", p) self.internal_ports.remove(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) for subnet in p['subnets']: if ipv6_utils.is_ipv6_pd_enabled(subnet): pd.disable_subnet(self.router_id, subnet['id']) updated_cidrs = [] if updated_ports: for index, p in enumerate(internal_ports): if not updated_ports.get(p['id']): continue self.internal_ports[index] = updated_ports[p['id']] interface_name = self.get_internal_device_name(p['id']) ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips']) LOG.debug("updating internal network for port %s", p) updated_cidrs += ip_cidrs self.internal_network_updated(interface_name, ip_cidrs) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) # Check if there is any pd prefix update for p in internal_ports: if p['id'] in (set(current_port_ids) & set(existing_port_ids)): for subnet in p.get('subnets', []): if ipv6_utils.is_ipv6_pd_enabled(subnet): old_prefix = pd.update_subnet(self.router_id, subnet['id'], subnet['cidr']) if old_prefix: self._internal_network_updated(p, subnet['id'], subnet['cidr'], old_prefix, updated_cidrs) enable_ra = True # Enable RA if enable_ra: self.enable_radvd(internal_ports) existing_devices = self._get_existing_devices() current_internal_devs = set(n for n in existing_devices if n.startswith(INTERNAL_DEV_PREFIX)) current_port_devs = set(self.get_internal_device_name(port_id) for port_id in current_port_ids) stale_devs = current_internal_devs - current_port_devs for stale_dev in stale_devs: LOG.debug('Deleting stale internal router device: %s', stale_dev) pd.remove_stale_ri_ifname(self.router_id, stale_dev) self.driver.unplug(stale_dev, namespace=self.ns_name, prefix=INTERNAL_DEV_PREFIX)
def device_exists_with_ips_and_mac(self, expected_device, name_getter, namespace): ip_cidrs = common_utils.fixed_ip_cidrs(expected_device['fixed_ips']) return ip_lib.device_exists_with_ips_and_mac( name_getter(expected_device['id']), ip_cidrs, expected_device['mac_address'], namespace)
def _add_gateway_vip(self, ex_gw_port, interface_name): for ip_cidr in common_utils.fixed_ip_cidrs(ex_gw_port["fixed_ips"]): self._add_vip(ip_cidr, interface_name) self._add_default_gw_virtual_route(ex_gw_port, interface_name) self._add_extra_subnet_onlink_routes(ex_gw_port, interface_name)
def verify_ip_in_keepalived_config(router, iface): config = router.keepalived_manager.config.get_config_str() ip_cidrs = common_utils.fixed_ip_cidrs(iface['fixed_ips']) for ip_addr in ip_cidrs: self.assertIn(ip_addr, config)
def _process_internal_ports(self, pd): existing_port_ids = set(p['id'] for p in self.internal_ports) internal_ports = self.router.get(lib_constants.INTERFACE_KEY, []) current_port_ids = set(p['id'] for p in internal_ports if p['admin_state_up']) new_port_ids = current_port_ids - existing_port_ids new_ports = [p for p in internal_ports if p['id'] in new_port_ids] old_ports = [ p for p in self.internal_ports if p['id'] not in current_port_ids ] updated_ports = self._get_updated_ports(self.internal_ports, internal_ports) enable_ra = False for p in new_ports: self.internal_network_added(p) LOG.debug("appending port %s to internal_ports cache", p) self.internal_ports.append(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) for subnet in p['subnets']: if ipv6_utils.is_ipv6_pd_enabled(subnet): interface_name = self.get_internal_device_name(p['id']) pd.enable_subnet(self.router_id, subnet['id'], subnet['cidr'], interface_name, p['mac_address']) for p in old_ports: self.internal_network_removed(p) LOG.debug("removing port %s from internal_ports cache", p) self.internal_ports.remove(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) for subnet in p['subnets']: if ipv6_utils.is_ipv6_pd_enabled(subnet): pd.disable_subnet(self.router_id, subnet['id']) updated_cidrs = [] if updated_ports: for index, p in enumerate(internal_ports): if not updated_ports.get(p['id']): continue self.internal_ports[index] = updated_ports[p['id']] interface_name = self.get_internal_device_name(p['id']) ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips']) LOG.debug("updating internal network for port %s", p) updated_cidrs += ip_cidrs self.internal_network_updated(interface_name, ip_cidrs) enable_ra = enable_ra or self._port_has_ipv6_subnet(p) # Check if there is any pd prefix update for p in internal_ports: if p['id'] in (set(current_port_ids) & set(existing_port_ids)): for subnet in p.get('subnets', []): if ipv6_utils.is_ipv6_pd_enabled(subnet): old_prefix = pd.update_subnet(self.router_id, subnet['id'], subnet['cidr']) if old_prefix: self._internal_network_updated( p, subnet['id'], subnet['cidr'], old_prefix, updated_cidrs) enable_ra = True # Enable RA if enable_ra: self.enable_radvd(internal_ports) existing_devices = self._get_existing_devices() current_internal_devs = set(n for n in existing_devices if n.startswith(INTERNAL_DEV_PREFIX)) current_port_devs = set( self.get_internal_device_name(port_id) for port_id in current_port_ids) stale_devs = current_internal_devs - current_port_devs for stale_dev in stale_devs: LOG.debug('Deleting stale internal router device: %s', stale_dev) pd.remove_stale_ri_ifname(self.router_id, stale_dev) self.driver.unplug(stale_dev, namespace=self.ns_name, prefix=INTERNAL_DEV_PREFIX)
def _add_vips(self, port, interface_name): for ip_cidr in common_utils.fixed_ip_cidrs(port['fixed_ips']): try: self._add_vip(ip_cidr, interface_name) except keepalived.VIPDuplicateAddressException: LOG.debug("%s has already been added to keepalive", ip_cidr)