aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2018-05-11 10:36:41 +0200
committerJan Gelety <jgelety@cisco.com>2018-05-31 06:41:15 +0000
commitb5782684055409315412d94d1de2e5f78cffac4d (patch)
tree9b7bd941d3cdb35ad2c0fd861cb156c767606443 /resources/libraries/python
parent0eeaf6eeeac256a8dfba297c57247b261912d2ca (diff)
DPDK link bonding: xor mode
CSIT-1073 CSIT-1074 CSIT-1077 Change-Id: I248e079021c30988210fd792b32d5afdca71aadb Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/InterfaceUtil.py23
-rw-r--r--resources/libraries/python/VatJsonUtil.py36
-rw-r--r--resources/libraries/python/VppConfigGenerator.py69
-rw-r--r--resources/libraries/python/topology.py2
4 files changed, 118 insertions, 12 deletions
diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py
index aac78c9e44..6c3aa46a40 100644
--- a/resources/libraries/python/InterfaceUtil.py
+++ b/resources/libraries/python/InterfaceUtil.py
@@ -909,6 +909,29 @@ class InterfaceUtil(object):
.format(node['host']))
@staticmethod
+ def add_bond_eth_interface(node, ifc_name):
+ """Add BondEthernet interface to current topology.
+
+ :param node: Node to add BondEthernet interface for.
+ :param ifc_name: Name of the BondEthernet interface.
+ :type node: dict
+ :type ifc_name: str
+ """
+ if_key = Topology.add_new_port(node, 'eth_bond')
+ Topology.update_interface_name(node, if_key, ifc_name)
+
+ vat_executor = VatExecutor()
+ vat_executor.execute_script_json_out("dump_interfaces.vat", node)
+ interface_dump_json = vat_executor.get_script_stdout()
+
+ sw_if_idx = VatJsonUtil.get_interface_sw_index_from_json(
+ interface_dump_json, ifc_name)
+ Topology.update_interface_sw_if_index(node, if_key, sw_if_idx)
+ ifc_mac = VatJsonUtil.get_interface_mac_from_json(
+ interface_dump_json, sw_if_idx)
+ Topology.update_interface_mac_address(node, if_key, ifc_mac)
+
+ @staticmethod
def vpp_enable_input_acl_interface(node, interface, ip_version,
table_index):
"""Enable input acl on interface.
diff --git a/resources/libraries/python/VatJsonUtil.py b/resources/libraries/python/VatJsonUtil.py
index 4db4eb641a..8414838715 100644
--- a/resources/libraries/python/VatJsonUtil.py
+++ b/resources/libraries/python/VatJsonUtil.py
@@ -148,8 +148,9 @@ class VatJsonUtil(object):
try:
if interface['sw_if_index'] == sw_if_index:
interface_name = interface['interface_name']
- logger.debug('Interface with name {} has sw_if_index {}.'
- .format(interface_name, sw_if_index))
+ logger.debug('Interface with sw_if_index {idx} has name'
+ ' {name}.'.format(idx=sw_if_index,
+ name=interface_name))
return interface_name
except KeyError:
pass
@@ -157,6 +158,37 @@ class VatJsonUtil(object):
.format(sw_if_index))
@staticmethod
+ def get_interface_mac_from_json(interface_dump_json, sw_if_index):
+ """Get interface MAC address from given JSON output by sw_if_index.
+
+ :param interface_dump_json: JSON output from dump_interface_list VAT
+ command.
+ :param sw_if_index: SW interface index.
+ :type interface_dump_json: str
+ :type sw_if_index: int
+ :returns: Interface MAC address.
+ :rtype: str
+ :raises ValueError: If interface not found in interface_dump_json.
+ """
+ logger.trace(interface_dump_json)
+ interface_list = JsonParser().parse_data(interface_dump_json)
+ for interface in interface_list:
+ try:
+ if interface['sw_if_index'] == sw_if_index:
+ mac_from_json = interface['l2_address'][:6] \
+ if 'l2_address' in interface.keys() else ''
+ mac_address = ':'.join('{:02x}'.format(item)
+ for item in mac_from_json)
+ logger.debug('Interface with sw_if_index {idx} has MAC'
+ ' address {addr}.'.format(idx=sw_if_index,
+ addr=mac_address))
+ return mac_address
+ except KeyError:
+ pass
+ raise ValueError('Interface with sw_if_index {idx} not found.'
+ .format(idx=sw_if_index))
+
+ @staticmethod
def verify_vat_retval(vat_out, exp_retval=0, err_msg='VAT cmd failed'):
"""Verify return value of VAT command.
diff --git a/resources/libraries/python/VppConfigGenerator.py b/resources/libraries/python/VppConfigGenerator.py
index d1fc32ef9d..e9933f2a18 100644
--- a/resources/libraries/python/VppConfigGenerator.py
+++ b/resources/libraries/python/VppConfigGenerator.py
@@ -25,6 +25,23 @@ from resources.libraries.python.topology import Topology
__all__ = ['VppConfigGenerator']
+def pci_dev_check(pci_dev):
+ """Check if provided PCI address is in correct format.
+
+ :param pci_dev: PCI address (expected format: xxxx:xx:xx.x).
+ :type pci_dev: str
+ :returns: True if PCI address is in correct format.
+ :rtype: bool
+ :raises ValueError: If PCI address is in incorrect format.
+ """
+ pattern = re.compile("^[0-9A-Fa-f]{4}:[0-9A-Fa-f]{2}:"
+ "[0-9A-Fa-f]{2}\\.[0-9A-Fa-f]$")
+ if not pattern.match(pci_dev):
+ raise ValueError('PCI address {addr} is not in valid format '
+ 'xxxx:xx:xx.x'.format(addr=pci_dev))
+ return True
+
+
class VppConfigGenerator(object):
"""VPP Configuration File Generator."""
@@ -100,6 +117,9 @@ class VppConfigGenerator(object):
return
if path[0] not in config:
config[path[0]] = {}
+ elif isinstance(config[path[0]], str):
+ config[path[0]] = {} if config[path[0]] == '' \
+ else {config[path[0]]: ''}
self.add_config_item(config[path[0]], value, path[1:])
def dump_config(self, obj, level=-1):
@@ -205,17 +225,25 @@ class VppConfigGenerator(object):
:param devices: PCI device(s) (format xxxx:xx:xx.x)
:type devices: tuple
- :raises ValueError: If PCI address format is not valid.
"""
- pattern = re.compile("^[0-9A-Fa-f]{4}:[0-9A-Fa-f]{2}:"
- "[0-9A-Fa-f]{2}\\.[0-9A-Fa-f]$")
for device in devices:
- if not pattern.match(device):
- raise ValueError('PCI address {} to be added to host {} '
- 'is not in valid format xxxx:xx:xx.x'.
- format(device, self._hostname))
- path = ['dpdk', 'dev {0}'.format(device)]
- self.add_config_item(self._nodeconfig, '', path)
+ if pci_dev_check(device):
+ path = ['dpdk', 'dev {0}'.format(device)]
+ self.add_config_item(self._nodeconfig, '', path)
+
+ def add_dpdk_dev_parameter(self, device, parameter, value):
+ """Add parameter for DPDK device.
+
+ :param device: PCI device (format xxxx:xx:xx.x).
+ :param parameter: Parameter name.
+ :param value: Parameter value.
+ :type device: str
+ :type parameter: str
+ :type value: str
+ """
+ if pci_dev_check(device):
+ path = ['dpdk', 'dev {0}'.format(device), parameter]
+ self.add_config_item(self._nodeconfig, value, path)
def add_dpdk_cryptodev(self, count):
"""Add DPDK Crypto PCI device configuration.
@@ -247,6 +275,29 @@ class VppConfigGenerator(object):
path = ['dpdk', cryptodev_config]
self.add_config_item(self._nodeconfig, '', path)
+ def add_dpdk_eth_bond_dev(self, ethbond_id, mode, xmit_policy, *slaves):
+ """Add DPDK Eth_bond device configuration.
+
+ :param ethbond_id: Eth_bond device ID.
+ :param mode: Link bonding mode.
+ :param xmit_policy: Transmission policy.
+ :param slaves: PCI device(s) to be bonded (format xxxx:xx:xx.x).
+ :type ethbond_id: str or int
+ :type mode: str or int
+ :type xmit_policy: str
+ :type slaves: list
+ """
+ slaves_config = ',slave=' + \
+ ',slave='.join(slave if pci_dev_check(slave) else ''
+ for slave in slaves)
+ ethbond_config = 'vdev eth_bond{id},mode={mode}{slaves},' \
+ 'xmit_policy={xmit_pol}'.format(id=ethbond_id,
+ mode=mode,
+ slaves=slaves_config,
+ xmit_pol=xmit_policy)
+ path = ['dpdk', ethbond_config]
+ self.add_config_item(self._nodeconfig, '', path)
+
def add_dpdk_dev_default_rxq(self, value):
"""Add DPDK dev default rxq configuration.
diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py
index 2f4fd023ba..d60bed1b5b 100644
--- a/resources/libraries/python/topology.py
+++ b/resources/libraries/python/topology.py
@@ -138,7 +138,7 @@ class Topology(object):
:returns: Nothing
"""
port_types = ('subinterface', 'vlan_subif', 'memif', 'tap', 'vhost',
- 'loopback', 'gre_tunnel', 'vxlan_tunnel')
+ 'loopback', 'gre_tunnel', 'vxlan_tunnel', 'eth_bond')
for node_data in nodes.values():
if node_data['type'] == NodeType.DUT: