From bdfca054d8425a57496cca8308da36c118b5340f Mon Sep 17 00:00:00 2001 From: Jan Gelety Date: Mon, 14 Aug 2017 16:25:46 +0200 Subject: CSIT-778: Add mac-ip binding acl l2bd perf test Change-Id: Iaced68458b0e4070f861be7854ee428ae8ca4e13 Signed-off-by: Jan Gelety --- resources/libraries/python/IPUtil.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'resources/libraries/python/IPUtil.py') 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 @@ -24,6 +24,30 @@ from resources.libraries.python.topology import Topology 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. -- cgit 1.2.3-korg