def _write_router_journal(self, context, router_id, router_dict): etcd_dir = (server.LEADIN + '/nodes/' + self.l3_host + '/' + server.ROUTER_DIR + router_id) router_dict['vrf_id'] = db.get_router_vrf(context.session, router_id) # Get the external network details network = self._core_plugin.get_network( context, router_dict['external_gateway_info']['network_id']) # Grab the external network info router_dict['external_physnet'] = network[provider.PHYSICAL_NETWORK] router_dict['external_segment'] = network[provider.SEGMENTATION_ID] router_dict['external_net_type'] = network[provider.NETWORK_TYPE] # Grab all external subnets' gateway IPs # This is added to the router dictionary in the format: # [(Router's IP Address from the external network's subnet, # External Subnet's prefix)] fixed_ips = router_dict['external_gateway_info']['external_fixed_ips'] gateways = [] for fixed_ip in fixed_ips: subnet = self._core_plugin.get_subnet(context, fixed_ip['subnet_id']) gateways.append( (fixed_ip['ip_address'], ip_network(subnet['cidr']).prefixlen)) router_dict['gateways'] = gateways db.journal_write(context.session, etcd_dir, router_dict) self.communicator.kick()
def _write_router_external_gw_journal(self, context, router_id, router_dict, delete=False): LOG.info("Writing router external gateway using router_dict: %s", router_dict) router_dict['vrf_id'] = db.get_router_vrf(context.session, router_id) # Get the external network details network = self._core_plugin.get_network( context, router_dict['external_gateway_info']['network_id']) LOG.debug("Router external gateway network data: %s", network) # Grab the external network info router_dict['external_physnet'] = network[provider.PHYSICAL_NETWORK] router_dict['external_segmentation_id'] = network[ provider.SEGMENTATION_ID] router_dict['external_net_type'] = network[provider.NETWORK_TYPE] router_dict['mtu'] = network['mtu'] # The Neutron port created for the gateway gateway_port = router_dict['gw_port_id'] # Get the mac-addr of the port to create the port if not delete: gw_port = self._core_plugin.get_port(context.elevated(), gateway_port) router_dict['loopback_mac'] = gw_port['mac_address'] # Grab all external subnets' gateway IPs # This is added to the router dictionary using the key: gateways # The value of gateways is a list of tuples: # (gateway_ip, prefix_len, is_ipv6) fixed_ips = router_dict['external_gateway_info']['external_fixed_ips'] gateways = [] # For each subnet/fixed-ip, write a key to create a gateway uplink # on that subnet with the correct IP address for fixed_ip in fixed_ips: subnet_id = fixed_ip['subnet_id'] subnet = self._core_plugin.get_subnet(context.elevated(), subnet_id) address = ip_network(six.text_type(subnet['cidr'])) is_ipv6 = True if address.version == 6 else False gateways.append( (fixed_ip['ip_address'], address.prefixlen, is_ipv6)) # IP addresses to be set on VPP's external interface connecting # to an external gateway router_dict['gateways'] = gateways # This the IP address of the external gateway that functions as # the default gateway for the tenant's router router_dict['external_gateway_ip'] = subnet['gateway_ip'] for l3_host in self.l3_hosts: etcd_key = self._get_router_intf_path(l3_host, router_id, gateway_port) if delete: db.journal_write(context.session, etcd_key, None) else: db.journal_write(context.session, etcd_key, router_dict) self.communicator.kick()
def _write_router_external_gw_journal(self, context, router_id, router_dict, delete=False): LOG.info("Writing router external gateway using router_dict: %s", router_dict) router_dict['vrf_id'] = db.get_router_vrf(context.session, router_id) # Get the external network details network = self._core_plugin.get_network( context, router_dict['external_gateway_info']['network_id']) LOG.debug("Router external gateway network data: %s", network) # Grab the external network info router_dict['external_physnet'] = network[provider.PHYSICAL_NETWORK] router_dict['external_segmentation_id'] = network[ provider.SEGMENTATION_ID] router_dict['external_net_type'] = network[provider.NETWORK_TYPE] router_dict['mtu'] = network['mtu'] # The Neutron port created for the gateway gateway_port = router_dict['gw_port_id'] # Get the mac-addr of the port to create the port if not delete: gw_port = self._core_plugin.get_port( context.elevated(), gateway_port) router_dict['loopback_mac'] = gw_port['mac_address'] # Grab all external subnets' gateway IPs # This is added to the router dictionary using the key: gateways # The value of gateways is a list of tuples: # (gateway_ip, prefix_len, is_ipv6) fixed_ips = router_dict['external_gateway_info']['external_fixed_ips'] gateways = [] # For each subnet/fixed-ip, write a key to create a gateway uplink # on that subnet with the correct IP address for fixed_ip in fixed_ips: subnet_id = fixed_ip['subnet_id'] subnet = self._core_plugin.get_subnet( context.elevated(), subnet_id) address = ip_network(six.text_type(subnet['cidr'])) is_ipv6 = True if address.version == 6 else False gateways.append((fixed_ip['ip_address'], address.prefixlen, is_ipv6)) # IP addresses to be set on VPP's external interface connecting # to an external gateway router_dict['gateways'] = gateways # This the IP address of the external gateway that functions as # the default gateway for the tenant's router router_dict['external_gateway_ip'] = subnet['gateway_ip'] for l3_host in self.l3_hosts: etcd_key = self._get_router_intf_path(l3_host, router_id, gateway_port) if delete: db.journal_write(context.session, etcd_key, None) else: db.journal_write(context.session, etcd_key, router_dict) self.communicator.kick()
def _get_router_interface(self, context, router_id, router_dict): """Populate the param: "router_dict" with values and return. SideEffect: Changes the parameter: router_dict Returns the router_dict populated with the network, subnet gateway ip_address, GPE locators for gpe, network type, segmentation ID, is_ipv6, VRF and prefix-length information so vpp-agent can create the vpp router interface. Arguments:- 1. router_dict: The router dictionary to be populated with data. It must contain the key "port_id", which is used to populate the router dict. 2. router_id: Router ID """ port_id = router_dict['port_id'] port = self._core_plugin.get_port(context, port_id) network = self._core_plugin.get_network(context, port['network_id']) fixed_ips = [ip for ip in port['fixed_ips']] if not fixed_ips: n_exc.BadRequest('vpp-router-service: A router port must ' 'have at least one fixed IP address') # TODO(najoy): Handle multiple fixed-ips on a router port fixed_ip = fixed_ips[0] subnet = self._core_plugin.get_subnet(context, fixed_ip['subnet_id']) router_dict['gateway_ip'] = fixed_ip['ip_address'] router_dict['subnet_id'] = subnet['id'] router_dict['fixed_ips'] = fixed_ips address = ip_network(six.text_type(subnet['cidr'])) router_dict['network_id'] = network['id'] router_dict['is_ipv6'] = True if address.version == 6 else False router_dict['prefixlen'] = address.prefixlen router_dict['mtu'] = network['mtu'] router_dict['segmentation_id'] = network[provider.SEGMENTATION_ID] router_dict['net_type'] = network[provider.NETWORK_TYPE] if router_dict['net_type'] == nvpp_const.TYPE_GPE: router_dict['physnet'] = self.gpe_physnet else: router_dict['physnet'] = network[provider.PHYSICAL_NETWORK] # Get VRF corresponding to the router vrf_id = db.get_router_vrf(context.session, router_id) router_dict['vrf_id'] = vrf_id return router_dict
def _get_router_interface(self, context, router_id, router_dict): """Populate the param: "router_dict" with values and return. SideEffect: Changes the parameter: router_dict Returns the router_dict populated with the network, subnet gateway ip_address, GPE locators for vxlan, network type, segmentation ID, is_ipv6, VRF and prefix-length information so vpp-agent can create the vpp router interface. Arguments:- 1. router_dict: The router dictionary to be populated with data. It must contain the key "port_id", which is used to populate the router dict. 2. router_id: Router ID """ port_id = router_dict['port_id'] port = self._core_plugin.get_port(context, port_id) network = self._core_plugin.get_network(context, port['network_id']) fixed_ips = [ip for ip in port['fixed_ips']] if not fixed_ips: n_exc.BadRequest('vpp-router-service: A router port must ' 'have at least one fixed IP address') # TODO(najoy): Handle multiple fixed-ips on a router port fixed_ip = fixed_ips[0] subnet = self._core_plugin.get_subnet(context, fixed_ip['subnet_id']) router_dict['gateway_ip'] = fixed_ip['ip_address'] router_dict['subnet_id'] = subnet['id'] router_dict['fixed_ips'] = fixed_ips address = ip_network(subnet['cidr']) router_dict['network_id'] = network['id'] router_dict['is_ipv6'] = True if address.version == 6 else False router_dict['prefixlen'] = address.prefixlen router_dict['mtu'] = network['mtu'] router_dict['segmentation_id'] = network[provider.SEGMENTATION_ID] router_dict['net_type'] = network[provider.NETWORK_TYPE] if router_dict['net_type'] == 'vxlan': router_dict['physnet'] = self.gpe_physnet else: router_dict['physnet'] = network[provider.PHYSICAL_NETWORK] # Get VRF corresponding to the router vrf_id = db.get_router_vrf(context.session, router_id) router_dict['vrf_id'] = vrf_id return router_dict
def _get_router_intf_details(self, context, router_id, interface_info, router_dict): # Returns a router dictionary populated with network and # subnet information for the associated subnet # Get vlan id for this subnet's network subnet = self._core_plugin.get_subnet(context, interface_info['subnet_id']) network = self._core_plugin.get_network(context, subnet['network_id']) router_dict['mtu'] = network['mtu'] router_dict['segmentation_id'] = network[provider.SEGMENTATION_ID] router_dict['net_type'] = network[provider.NETWORK_TYPE] router_dict['physnet'] = network[provider.PHYSICAL_NETWORK] # Get VRF corresponding to the router vrf_id = db.get_router_vrf(context.session, router_id) router_dict['vrf_id'] = vrf_id # Get internal gateway address for this subnet router_dict['gateway_ip'] = subnet['gateway_ip'] # Get prefix and type for this subnet router_dict['is_ipv6'] = False address = ip_network(subnet['cidr']) if address.version == 6: router_dict['is_ipv6'] = True router_dict['prefixlen'] = address.prefixlen