コード例 #1
0
    def setup_ovs(self):
        """Initialize OVS-DPDK"""
        vpath = self.ovs_properties.get('vpath', self.DEFAULT_USER_PATH)
        create_from = os.path.join(vpath, 'etc/openvswitch/conf.db')
        create_to = os.path.join(vpath, 'share/openvswitch/vswitch.ovsschema')

        cmd_list = [
            'killall -r "ovs.*" -q | true',
            'mkdir -p {0}/etc/openvswitch'.format(vpath),
            'mkdir -p {0}/var/run/openvswitch'.format(vpath),
            'rm {0}/etc/openvswitch/conf.db | true'.format(vpath),
            'ovsdb-tool create {0} {1}'.format(create_from, create_to),
            'modprobe vfio-pci',
            'chmod a+x /dev/vfio',
            'chmod 0666 /dev/vfio/*',
        ]

        bind_cmd = '%s --force -b vfio-pci {port}' % self.dpdk_devbind
        for port in self.networks.values():
            cmd_list.append(bind_cmd.format(port=port.get('phy_port')))

        for cmd in cmd_list:
            LOG.info(cmd)
            exit_status, _, stderr = self.connection.execute(
                cmd, timeout=self.CMD_TIMEOUT)
            if exit_status:
                raise exceptions.OVSSetupError(command=cmd, error=stderr)
コード例 #2
0
    def setup_ovs_bridge_add_flows(self):
        dpdk_args = ""
        dpdk_list = []
        vpath = self.ovs_properties.get("vpath", "/usr/local")
        version = self.ovs_properties.get('version', {})
        ovs_ver = [
            int(x) for x in version.get('ovs', self.DEFAULT_OVS).split('.')
        ]
        ovs_add_port = ('ovs-vsctl add-port {br} {port} -- '
                        'set Interface {port} type={type_}{dpdk_args}')
        ovs_add_queue = 'ovs-vsctl set Interface {port} options:n_rxq={queue}'
        chmod_vpath = 'chmod 0777 {0}/var/run/openvswitch/dpdkvhostuser*'

        cmd_list = [
            'ovs-vsctl --if-exists del-br {0}'.format(MAIN_BRIDGE),
            'rm -rf {0}/var/run/openvswitch/dpdkvhostuser*'.format(vpath),
            'ovs-vsctl add-br {0} -- set bridge {0} datapath_type=netdev'.
            format(MAIN_BRIDGE)
        ]

        ordered_network = collections.OrderedDict(self.networks)
        for index, vnf in enumerate(ordered_network.values()):
            if ovs_ver >= [2, 7, 0]:
                dpdk_args = " options:dpdk-devargs=%s" % vnf.get("phy_port")
            dpdk_list.append(
                ovs_add_port.format(br=MAIN_BRIDGE,
                                    port='dpdk%s' % vnf.get("port_num", 0),
                                    type_='dpdk',
                                    dpdk_args=dpdk_args))
            dpdk_list.append(
                ovs_add_queue.format(port='dpdk%s' % vnf.get("port_num", 0),
                                     queue=self.ovs_properties.get(
                                         "queues", 1)))

        # Sorting the array to make sure we execute dpdk0... in the order
        list.sort(dpdk_list)
        cmd_list.extend(dpdk_list)

        # Need to do two for loop to maintain the dpdk/vhost ports.
        for index, _ in enumerate(ordered_network):
            cmd_list.append(
                ovs_add_port.format(br=MAIN_BRIDGE,
                                    port='dpdkvhostuser%s' % index,
                                    type_='dpdkvhostuser',
                                    dpdk_args=""))

        ovs_flow = ("ovs-ofctl add-flow {0} in_port=%s,action=output:%s".
                    format(MAIN_BRIDGE))
        network_count = len(ordered_network) + 1
        for in_port, out_port in zip(range(1, network_count),
                                     range(network_count, network_count * 2)):
            cmd_list.append(ovs_flow % (in_port, out_port))
            cmd_list.append(ovs_flow % (out_port, in_port))

        cmd_list.append(chmod_vpath.format(vpath))

        for cmd in cmd_list:
            LOG.info(cmd)
            exit_status, _, stderr = self.connection.execute(
                cmd, timeout=self.CMD_TIMEOUT)
            if exit_status:
                raise exceptions.OVSSetupError(command=cmd, error=stderr)
コード例 #3
0
ファイル: ovs_dpdk.py プロジェクト: yc18/yardstick
    def setup_ovs_bridge_add_flows(self):
        dpdk_args = ""
        vpath = self.ovs_properties.get("vpath", "/usr/local")
        version = self.ovs_properties.get('version', {})
        ovs_ver = [
            int(x) for x in version.get('ovs', self.DEFAULT_OVS).split('.')
        ]
        ovs_add_port = ('ovs-vsctl add-port {br} {port} -- '
                        'set Interface {port} type={type_}{dpdk_args}'
                        '{dpdk_rxq}{pmd_rx_aff}')
        chmod_vpath = 'chmod 0777 {0}/var/run/openvswitch/dpdkvhostuser*'

        cmd_list = [
            'ovs-vsctl --if-exists del-br {0}'.format(MAIN_BRIDGE),
            'rm -rf {0}/var/run/openvswitch/dpdkvhostuser*'.format(vpath),
            'ovs-vsctl add-br {0} -- set bridge {0} datapath_type=netdev'.
            format(MAIN_BRIDGE)
        ]
        dpdk_rxq = ""
        queues = self.ovs_properties.get("queues")
        if queues:
            dpdk_rxq = " options:n_rxq={queue}".format(queue=queues)

        # Sorting the array to make sure we execute dpdk0... in the order
        ordered_network = collections.OrderedDict(
            sorted(self.networks.items(),
                   key=lambda t: t[1].get('port_num', 0)))
        pmd_rx_aff_ports = self.ovs_properties.get("dpdk_pmd-rxq-affinity", {})
        for index, vnf in enumerate(ordered_network.values()):
            if ovs_ver >= [2, 7, 0]:
                dpdk_args = " options:dpdk-devargs=%s" % vnf.get("phy_port")
            affinity = pmd_rx_aff_ports.get(vnf.get("port_num", -1), "")
            if affinity:
                pmd_rx_aff = ' other_config:pmd-rxq-affinity=' \
                             '"{affinity}"'.format(affinity=affinity)
            else:
                pmd_rx_aff = ""
            cmd_list.append(
                ovs_add_port.format(br=MAIN_BRIDGE,
                                    port='dpdk%s' % vnf.get("port_num", 0),
                                    type_='dpdk',
                                    dpdk_args=dpdk_args,
                                    dpdk_rxq=dpdk_rxq,
                                    pmd_rx_aff=pmd_rx_aff))

        # Need to do two for loop to maintain the dpdk/vhost ports.
        pmd_rx_aff_ports = self.ovs_properties.get("vhost_pmd-rxq-affinity",
                                                   {})
        for index, _ in enumerate(ordered_network):
            affinity = pmd_rx_aff_ports.get(index)
            if affinity:
                pmd_rx_aff = ' other_config:pmd-rxq-affinity=' \
                             '"{affinity}"'.format(affinity=affinity)
            else:
                pmd_rx_aff = ""
            cmd_list.append(
                ovs_add_port.format(br=MAIN_BRIDGE,
                                    port='dpdkvhostuser%s' % index,
                                    type_='dpdkvhostuser',
                                    dpdk_args="",
                                    dpdk_rxq=dpdk_rxq,
                                    pmd_rx_aff=pmd_rx_aff))

        ovs_flow = ("ovs-ofctl add-flow {0} in_port=%s,action=output:%s".
                    format(MAIN_BRIDGE))
        network_count = len(ordered_network) + 1
        for in_port, out_port in zip(range(1, network_count),
                                     range(network_count, network_count * 2)):
            cmd_list.append(ovs_flow % (in_port, out_port))
            cmd_list.append(ovs_flow % (out_port, in_port))

        cmd_list.append(chmod_vpath.format(vpath))

        for cmd in cmd_list:
            LOG.info(cmd)
            exit_status, _, stderr = self.connection.execute(
                cmd, timeout=self.CMD_TIMEOUT)
            if exit_status:
                raise exceptions.OVSSetupError(command=cmd, error=stderr)