aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/IPUtil.py24
-rw-r--r--resources/libraries/python/L2Util.py26
2 files changed, 50 insertions, 0 deletions
diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py
index 4bd8869cb6..d2f2adcf28 100644
--- a/resources/libraries/python/IPUtil.py
+++ b/resources/libraries/python/IPUtil.py
@@ -25,6 +25,30 @@ class IPUtil(object):
"""Common IP utilities"""
@staticmethod
+ def ip_to_int(ip_str):
+ """Convert IP address from string format (e.g. 10.0.0.1) to integer
+ representation (167772161).
+
+ :param ip_str: IP address in string representation.
+ :type ip_str: str
+ :returns: Integer representation of IP address.
+ :rtype: int
+ """
+ return int(ip_address(unicode(ip_str)))
+
+ @staticmethod
+ def int_to_ip(ip_int):
+ """Convert IP address from integer representation (e.g. 167772161) to
+ string format (10.0.0.1).
+
+ :param ip_int: IP address in integer representation.
+ :type ip_int: int
+ :returns: String representation of IP address.
+ :rtype: str
+ """
+ return str(ip_address(ip_int))
+
+ @staticmethod
def vpp_ip_probe(node, interface, addr, if_type="key"):
"""Run ip probe on VPP node.
diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py
index a909e8611b..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
@@ -24,6 +26,30 @@ 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.