X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FL2Util.py;h=6b8bc042e317ab0418377721e78e4283fdb1638c;hp=566b69bf1c8c248be2395942b3eced4c1dd9c54c;hb=bdfca054d8425a57496cca8308da36c118b5340f;hpb=c915202367120c68703c73299d0d38124bb15d12 diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py index 566b69bf1c..6b8bc042e3 100644 --- a/resources/libraries/python/L2Util.py +++ b/resources/libraries/python/L2Util.py @@ -13,6 +13,8 @@ """L2 Utilities Library.""" +from textwrap import wrap + from robot.api.deco import keyword from resources.libraries.python.topology import Topology @@ -23,6 +25,30 @@ from resources.libraries.python.ssh import exec_cmd_no_error class L2Util(object): """Utilities for l2 configuration.""" + @staticmethod + def mac_to_int(mac_str): + """Convert MAC address from string format (e.g. 01:02:03:04:05:06) to + integer representation (1108152157446). + + :param mac_str: MAC address in string representation. + :type mac_str: str + :returns: Integer representation of MAC address. + :rtype: int + """ + return int(mac_str.replace(':', ''), 16) + + @staticmethod + def int_to_mac(mac_int): + """Convert MAC address from integer representation (e.g. 1108152157446) + to string format (01:02:03:04:05:06). + + :param mac_int: MAC address in integer representation. + :type mac_int: str + :returns: String representation of MAC address. + :rtype: int + """ + return ':'.join(wrap("{:012x}".format(mac_int), width=2)) + @staticmethod def vpp_add_l2fib_entry(node, mac, interface, bd_id): """ Create a static L2FIB entry on a vpp node. @@ -217,35 +243,6 @@ class L2Util(object): cmd = 'ip link set dev {0} up'.format(br_name) exec_cmd_no_error(node, cmd, sudo=True) - @staticmethod - def setup_network_namespace(node, namespace_name, interface_name, - ip_address, prefix): - """Setup namespace on given node and attach interface and IP to - this namespace. Applicable also on TG node. - - :param node: Node to set namespace on. - :param namespace_name: Namespace name. - :param interface_name: Interface name. - :param ip_address: IP address of namespace's interface. - :param prefix: IP address prefix length. - :type node: dict - :type namespace_name: str - :type vhost_if: str - :type ip_address: str - :type prefix: int - - """ - cmd = ('ip netns add {0}'.format(namespace_name)) - exec_cmd_no_error(node, cmd, sudo=True) - - cmd = ('ip link set dev {0} up netns {1}'.format(interface_name, - namespace_name)) - exec_cmd_no_error(node, cmd, sudo=True) - - cmd = ('ip netns exec {0} ip addr add {1}/{2} dev {3}'.format( - namespace_name, ip_address, prefix, interface_name)) - exec_cmd_no_error(node, cmd, sudo=True) - @staticmethod def linux_del_bridge(node, br_name, set_down=True): """Delete bridge from linux node.