X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FIPUtil.py;h=d2f2adcf286479b2ed29fd29c22dc3f7025a721c;hp=4bd8869cb63fdd1fe3a5f49824c6c8623f651cfd;hb=bdfca054d8425a57496cca8308da36c118b5340f;hpb=66039913f070f4bb81e10f6ed503e0f2242ff70d 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.