Пример #1
0
    def _get_pcidp_network_resources_by_ifclass(self, ifclass):
        resources = {}

        interfaces = self._get_network_interfaces_by_class(ifclass)
        for iface in interfaces:
            port = interface.get_interface_port(self.context, iface)
            datanets = interface.get_interface_datanets(self.context, iface)
            for datanet in datanets:
                dn_name = datanet['name'].strip()
                resource = resources.get(dn_name, None)
                if resource:
                    # Add to the list of pci addreses for this data network
                    resource['rootDevices'].append(port['pciaddr'])
                else:
                    device_type = iface.get('sriov_vf_driver', None)
                    if not device_type:
                        device_type = constants.SRIOV_DRIVER_TYPE_NETDEVICE

                    # PCI addresses don't exist for this data network yet
                    resource = {
                        dn_name: {
                            "resourceName":
                            "{}_net_{}".format(ifclass,
                                               dn_name).replace("-", "_"),
                            "deviceType":
                            device_type,
                            "rootDevices": [port['pciaddr']],
                            "sriovMode":
                            ifclass == constants.INTERFACE_CLASS_PCI_SRIOV
                        }
                    }
                    resources.update(resource)
        return list(resources.values())
Пример #2
0
    def get_host_config(self, host):
        if (constants.CONTROLLER not in utils.get_personalities(host) and
                constants.WORKER not in utils.get_personalities(host)):
            return {}

        device_mappings = []
        for iface in self.context['interfaces'].values():
            if (iface['ifclass'] in [constants.INTERFACE_CLASS_PCI_SRIOV]):
                port = interface.get_interface_port(self.context, iface)

                datanets = interface.get_interface_datanets(
                    self.context, iface)
                for dnet in datanets:
                    device_mappings.append(
                        "%s:%s" % (dnet['name'], port['name']))
                    LOG.debug("get_host_config device_mappings=%s" %
                              device_mappings)

        config = {
            'neutron::agents::ml2::sriov::physical_device_mappings':
                device_mappings,
        }

        if host.personality == constants.CONTROLLER:
            service_parameters = self._get_service_parameter_configs(
                constants.SERVICE_TYPE_NETWORK)

            if service_parameters is None:
                return config

            # check if neutron bgp speaker is configured
            if host.hostname == constants.CONTROLLER_0_HOSTNAME:
                bgp_router_id = self._service_parameter_lookup_one(
                    service_parameters,
                    constants.SERVICE_PARAM_SECTION_NETWORK_BGP,
                    constants.SERVICE_PARAM_NAME_BGP_ROUTER_ID_C0,
                    None)
            else:
                bgp_router_id = self._service_parameter_lookup_one(
                    service_parameters,
                    constants.SERVICE_PARAM_SECTION_NETWORK_BGP,
                    constants.SERVICE_PARAM_NAME_BGP_ROUTER_ID_C1,
                    None)

            if bgp_router_id is not None:
                config.update({
                    'openstack::neutron::params::bgp_router_id':
                    bgp_router_id})

        return config
Пример #3
0
    def _get_port_config(self, host):
        ovs_devices = {}
        ovs_bridges = {}
        ovs_ports = {}
        ovs_addresses = {}
        ovs_flows = {}

        index = 0
        for iface in sorted(self.context['interfaces'].values(),
                            key=interface.interface_sort_key):
            if interface.is_data_network_type(iface):
                # create a separate bridge for every configured data interface
                brname = 'br-phy%d' % index
                ovs_bridges[brname] = {}

                # save the associated bridge for provider network mapping
                iface['_ovs_bridge'] = brname

                if iface['iftype'] == constants.INTERFACE_TYPE_ETHERNET:
                    port, devices = self._get_ethernet_port(
                        host, iface, brname, index)
                elif iface['iftype'] == constants.INTERFACE_TYPE_AE:
                    port, devices = self._get_bond_port(
                        host, iface, brname, index)
                elif iface['iftype'] == constants.INTERFACE_TYPE_VLAN:
                    port, devices = self._get_vlan_port(
                        host, iface, brname, index)
                else:
                    raise Exception("unsupported interface type: %s" %
                                    iface['iftype'])

                ovs_ports.update({port['name']: port})
                ovs_devices.update({d['pci_addr']: d for d in devices})

                if iface['iftype'] == constants.INTERFACE_TYPE_ETHERNET:
                    ovs_ifname = port['interfaces'][0]['name']
                    lldp_port = self._get_lldp_port(iface,
                                                    brname,
                                                    ovs_ifname=ovs_ifname)
                    ovs_ports.update({lldp_port['name']: lldp_port})
                    flow = self._get_lldp_flow(brname, ovs_ifname,
                                               lldp_port['name'])
                    ovs_flows.update({port['name']: flow})

                if iface['iftype'] == constants.INTERFACE_TYPE_AE:
                    slaves = interface.get_interface_slaves(
                        self.context, iface)
                    for member, slave in enumerate(slaves):
                        ovs_ifname = port['interfaces'][member]['name']

                        lldp_port = self._get_lldp_port(slave,
                                                        brname,
                                                        ovs_ifname=ovs_ifname)
                        ovs_ports.update({lldp_port['name']: lldp_port})
                        flow = self._get_lldp_flow(brname, ovs_ifname,
                                                   lldp_port['name'])
                        ovs_flows.update({flow['name']: flow})
                        flow = self._get_lldp_flow(brname, lldp_port['name'],
                                                   ovs_ifname)
                        ovs_flows.update({flow['name']: flow})

                index += 1

                datanets = interface.get_interface_datanets(
                    self.context, iface)

                # setup tunnel address if assigned provider network is vxlan
                if datanets and self._is_vxlan_datanet(datanets[0]):
                    address = interface.get_interface_primary_address(
                        self.context, iface)
                    if address:
                        ovs_addresses[brname] = {
                            'ifname': brname,
                            'address': address['address'],
                            'prefixlen': address['prefix'],
                        }

        ovs_dict = {
            'platform::vswitch::ovs::devices': ovs_devices,
            'platform::vswitch::ovs::bridges': ovs_bridges,
            'platform::vswitch::ovs::ports': ovs_ports,
            'platform::vswitch::ovs::addresses': ovs_addresses,
            'platform::vswitch::ovs::flows': ovs_flows,
        }

        LOG.debug("_get_port_config=%s" % ovs_dict)

        return ovs_dict
Пример #4
0
    def _get_pcidp_network_resources_by_ifclass(self, ifclass):
        resources = {}

        interfaces = self._get_network_interfaces_by_class(ifclass)
        for iface in interfaces:

            if ifclass == constants.INTERFACE_CLASS_PCI_SRIOV:
                port = interface.get_sriov_interface_port(self.context, iface)
            else:
                port = interface.get_interface_port(self.context, iface)
            if not port:
                continue

            datanets = interface.get_interface_datanets(self.context, iface)
            for datanet in datanets:
                dn_name = datanet['name'].strip()
                resource = resources.get(dn_name, None)
                if not resource:
                    resource = {
                        "resourceName":
                        "{}_net_{}".format(ifclass, dn_name).replace("-", "_"),
                        "selectors": {
                            "vendors": [],
                            "devices": [],
                            "drivers": [],
                            "pfNames": []
                        }
                    }

                vendor = self._get_pcidp_vendor_id(port)
                if not vendor:
                    LOG.error("Failed to get vendor id for pci device %s",
                              port['pciaddr'])
                    continue

                device = self._get_pcidp_device_id(port, ifclass)
                if not device:
                    LOG.error("Failed to get device id for pci device %s",
                              port['pciaddr'])
                    continue

                driver = self._get_pcidp_driver(port, iface, ifclass)
                if not driver:
                    LOG.error("Failed to get driver for pci device %s",
                              port['pciaddr'])
                    continue

                vendor_list = resource['selectors']['vendors']
                if vendor not in vendor_list:
                    vendor_list.append(vendor)

                device_list = resource['selectors']['devices']
                if device not in device_list:
                    device_list.append(device)

                driver_list = resource['selectors']['drivers']
                if driver not in driver_list:
                    driver_list.append(driver)

                pf_name_list = resource['selectors']['pfNames']
                if port['name'] not in pf_name_list:
                    pf_name_list.append(port['name'])

                if interface.is_a_mellanox_device(self.context, iface):
                    resource['selectors']['isRdma'] = True

                resources[dn_name] = resource

        return list(resources.values())
Пример #5
0
    def _get_pcidp_network_resources_by_ifclass(self, ifclass):
        resources = {}

        interfaces = self._get_network_interfaces_by_class(ifclass)
        for iface in interfaces:

            if ifclass == constants.INTERFACE_CLASS_PCI_SRIOV:
                port = interface.get_sriov_interface_port(self.context, iface)
            else:
                port = interface.get_interface_port(self.context, iface)
            if not port:
                continue

            datanets = interface.get_interface_datanets(self.context, iface)
            for datanet in datanets:
                dn_name = datanet['name'].strip()
                resource = resources.get(dn_name, None)
                if not resource:
                    resource = {
                        "resourceName":
                        "{}_net_{}".format(ifclass, dn_name).replace("-", "_"),
                        "selectors": {
                            "vendors": [],
                            "devices": [],
                            "drivers": [],
                            "pfNames": []
                        }
                    }

                vendor = self._get_pcidp_vendor_id(port)
                if not vendor:
                    LOG.error("Failed to get vendor id for pci device %s",
                              port['pciaddr'])
                    continue

                device = self._get_pcidp_device_id(port, ifclass)
                if not device:
                    LOG.error("Failed to get device id for pci device %s",
                              port['pciaddr'])
                    continue

                driver = self._get_pcidp_driver(port, iface, ifclass)
                if not driver:
                    LOG.error("Failed to get driver for pci device %s",
                              port['pciaddr'])
                    continue

                vendor_list = resource['selectors']['vendors']
                if vendor not in vendor_list:
                    vendor_list.append(vendor)

                device_list = resource['selectors']['devices']
                if device not in device_list:
                    device_list.append(device)

                driver_list = resource['selectors']['drivers']
                if driver not in driver_list:
                    driver_list.append(driver)

                pf_name_list = resource['selectors']['pfNames']
                if ifclass == constants.INTERFACE_CLASS_PCI_SRIOV:
                    # In sriov case, we need specify each VF for resource pool
                    # Get VF addresses assigned to this logical VF interface
                    vf_addr_list = []
                    all_vf_addr_list = []
                    vf_addrs = port.get('sriov_vfs_pci_address', None)
                    if vf_addrs:
                        all_vf_addr_list = vf_addrs.split(',')
                        vf_addr_list = interface.get_sriov_interface_vf_addrs(
                            self.context, iface, all_vf_addr_list)

                    vfnolst = [
                        utils.get_sriov_vf_index(addr, all_vf_addr_list)
                        for addr in vf_addr_list
                    ]
                    vfnolst = [str(vfno) for vfno in vfnolst]
                    vfnolist_str = ",".join(vfnolst)
                    if vfnolist_str:
                        # concat into the form of 'ens785f0#0,2,7,9'
                        pfname_with_vfs = "%s#%s" % (port['name'],
                                                     vfnolist_str)
                        pf_name_list.append(pfname_with_vfs)
                    else:
                        # error case, cannot find the vf numbers in sriov case
                        LOG.error("Failed to get vf numbers for pci device %s",
                                  port['name'])
                        continue
                else:
                    if port['name'] not in pf_name_list:
                        pf_name_list.append(port['name'])

                if interface.is_a_mellanox_device(self.context, iface):
                    resource['selectors']['isRdma'] = True

                resources[dn_name] = resource

        return list(resources.values())