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 _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 _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) self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']], namespace=ns_name) ip_address = str(netaddr.IPNetwork(ex_gw_port['ip_cidr']).ip) ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.agent_conf.send_arp_for_ha) gw_ip = ex_gw_port['subnet']['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): 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() if not ip_lib.device_exists(interface_name, root_helper=self.root_helper, 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) self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']], namespace=ns_name) ip_address = str(netaddr.IPNetwork(ex_gw_port['ip_cidr']).ip) ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.agent_conf.send_arp_for_ha, self.root_helper) gw_ip = ex_gw_port['subnet']['gateway_ip'] if gw_ip: ipd = ip_lib.IPDevice(interface_name, self.root_helper, 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(self.root_helper, 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.""" 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): 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 add_floating_ip(self, fip, interface_name, device): if not self._add_fip_addr_to_device(fip, device): return l3_constants.FLOATINGIP_STATUS_ERROR # As GARP is processed in a distinct thread the call below # won't raise an exception to be handled. ip_lib.send_gratuitous_arp(self.ns_name, interface_name, fip['floating_ip_address'], self.agent_conf.send_arp_for_ha) return l3_constants.FLOATINGIP_STATUS_ACTIVE
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 _external_gateway_added(self, ex_gw_port, interface_name, ns_name, preserve_ips): self._plug_external_gateway(ex_gw_port, interface_name, ns_name) self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']], namespace=ns_name, gateway=ex_gw_port['subnet'].get('gateway_ip'), extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips) ip_address = ex_gw_port['ip_cidr'].split('/')[0] ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.agent_conf.send_arp_for_ha)
def _internal_network_added(self, ns_name, network_id, port_id, internal_cidr, 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) self.driver.init_l3(interface_name, [internal_cidr], namespace=ns_name) ip_address = internal_cidr.split('/')[0] ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.agent_conf.send_arp_for_ha)
def _internal_network_added(self, ns_name, network_id, port_id, internal_cidr, mac_address, interface_name, prefix, is_ha=False): 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) if not is_ha: self.driver.init_l3(interface_name, [internal_cidr], namespace=ns_name) ip_address = internal_cidr.split('/')[0] ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.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 = 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 _external_gateway_added(self, ri, ex_gw_port, interface_name, ns_name, preserve_ips): 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.conf.external_network_bridge, namespace=ns_name, prefix=EXTERNAL_DEV_PREFIX) if not ri.is_ha: self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']], namespace=ns_name, gateway=ex_gw_port['subnet'].get('gateway_ip'), extra_subnets=ex_gw_port.get( 'extra_subnets', []), preserve_ips=preserve_ips) ip_address = ex_gw_port['ip_cidr'].split('/')[0] ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.conf.send_arp_for_ha)
def _external_gateway_added(self, ri, ex_gw_port, interface_name, ns_name, preserve_ips): 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.conf.external_network_bridge, namespace=ns_name, prefix=EXTERNAL_DEV_PREFIX) if not ri.is_ha: self.driver.init_l3( interface_name, [ex_gw_port['ip_cidr']], namespace=ns_name, gateway=ex_gw_port['subnet'].get('gateway_ip'), extra_subnets=ex_gw_port.get('extra_subnets', []), preserve_ips=preserve_ips) ip_address = ex_gw_port['ip_cidr'].split('/')[0] ip_lib.send_gratuitous_arp(ns_name, interface_name, ip_address, self.conf.send_arp_for_ha)
def floating_ip_added_dist(self, fip, fip_cidr): """Add floating IP to FIP namespace.""" floating_ip = fip['floating_ip_address'] fixed_ip = fip['fixed_ip_address'] rule_pr = self.fip_ns.allocate_rule_priority() self.floating_ips_dict[floating_ip] = rule_pr fip_2_rtr_name = self.fip_ns.get_int_device_name(self.router_id) ip_rule = ip_lib.IPRule(namespace=self.ns_name) ip_rule.rule.add(fixed_ip, dvr_fip_ns.FIP_RT_TBL, rule_pr) #Add routing rule in fip namespace fip_ns_name = self.fip_ns.get_name() rtr_2_fip, _ = self.rtr_fip_subnet.get_pair() device = ip_lib.IPDevice(fip_2_rtr_name, namespace=fip_ns_name) device.route.add_route(fip_cidr, str(rtr_2_fip.ip)) interface_name = ( self.fip_ns.get_ext_device_name( self.fip_ns.agent_gateway_port['id'])) ip_lib.send_gratuitous_arp(fip_ns_name, interface_name, floating_ip, self.agent_conf.send_arp_for_ha) # update internal structures self.dist_fip_count = self.dist_fip_count + 1