From bb1fcc4e0dbfa2e575570d75d209c5308be41f6d Mon Sep 17 00:00:00 2001 From: Saravanan KR Date: Tue, 5 Jul 2016 14:47:00 +0530 Subject: Add support for OVS DPDK Bridge and Port Add support in os-net-config for DPDK ports and OVS user bridges, and implement parameters which will be set by the TripleO Heat Templates when using TripleO. Implements: blueprint tripleo-ovs-dpdk Change-Id: Id4a23ced28b92a642c180a35c55080e5f4e2e05d --- os_net_config/utils.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'os_net_config/utils.py') diff --git a/os_net_config/utils.py b/os_net_config/utils.py index 83aae63..7b85d91 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -19,11 +19,17 @@ import logging import os import re +from oslo_concurrency import processutils + logger = logging.getLogger(__name__) _SYS_CLASS_NET = '/sys/class/net' +class OvsDpdkBindException(ValueError): + pass + + def write_config(filename, data): with open(filename, 'w') as f: f.write(str(data)) @@ -118,3 +124,39 @@ def diff(filename, data): logger.debug("Diff data:\n%s" % data) # convert to string as JSON may have unicode in it return not file_data == data + + +def bind_dpdk_interfaces(ifname, driver, noop): + pci_addres = _get_pci_address(ifname, noop) + if not noop: + if pci_addres: + # modbprobe of the driver has to be done before binding. + # for reboots, puppet will add the modprobe to /etc/rc.modules + processutils.execute('modprobe', 'vfio-pci') + + out, err = processutils.execute('driverctl', 'set-override', + pci_addres, driver) + if err: + msg = "Failed to bind interface %s with dpdk" % ifname + raise OvsDpdkBindException(msg) + else: + processutils.execute('driverctl', 'load-override', pci_addres) + else: + logger.info('Interface %(name)s bound to DPDK driver %(driver)s ' + 'using driverctl command' % + {'name': ifname, 'driver': driver}) + + +def _get_pci_address(ifname, noop): + # TODO(skramaja): Validate if the given interface supports dpdk + if not noop: + # If ifname is already bound, then ethtool will not be able to list the + # device, in which case, binding is already done, proceed with scripts + out, err = processutils.execute('ethtool', '-i', ifname) + if not err: + for item in out.split('\n'): + if 'bus-info' in item: + return item.split(' ')[1] + else: + logger.info('Fetch the PCI address of the interface %s using ' + 'ethtool' % ifname) -- cgit 1.2.3-korg