From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id E44B9BB0A for ; Wed, 26 Oct 2016 09:00:51 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP; 26 Oct 2016 00:00:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,549,1473145200"; d="scan'208";a="1059267433" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga001.fm.intel.com with ESMTP; 26 Oct 2016 00:00:50 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u9Q70lWH015602; Wed, 26 Oct 2016 15:00:47 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u9Q70jj0017869; Wed, 26 Oct 2016 15:00:47 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u9Q70iae017865; Wed, 26 Oct 2016 15:00:44 +0800 From: Marvin Liu To: dts@dpdk.org Date: Wed, 26 Oct 2016 15:00:39 +0800 Message-Id: <1477465241-17826-2-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1477465241-17826-1-git-send-email-yong.liu@intel.com> References: <1477465241-17826-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 1/3] framework utils: add function to convert ipaddress X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2016 07:00:52 -0000 Add new function to convert ip address to integer and covert integer to ip. Signed-off-by: Marvin Liu diff --git a/framework/utils.py b/framework/utils.py index edfeeca..1ecef09 100644 --- a/framework/utils.py +++ b/framework/utils.py @@ -33,6 +33,8 @@ import json # json format import re import os import inspect +import socket +import struct DTS_ENV_PAT = r"DTS_*" @@ -138,3 +140,23 @@ def create_mask(indexes): val |= 1 << int(index) return hex(val).rstrip("L") + +def convert_int2ip(value, ip_type): + if ip_type == 4: + ip_str = socket.inet_ntop(socket.AF_INET, struct.pack('!I', value)) + else: + h = value >> 64 + l = value & ((1 << 64) - 1) + ip_str = socket.inet_ntop(socket.AF_INET6, struct.pack('!QQ', h, l)) + + return ip_str + +def convert_ip2int(ip_str, ip_type): + if ip_type == 4: + ip_val = struct.unpack("!I", socket.inet_aton(ip_str))[0] + else: + _hex = socket.inet_pton(socket.AF_INET6, ip_str) + h, l = struct.unpack('!QQ', _hex) + ip_val = (h << 64) | l + + return ip_val -- 1.9.3