From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 3CA1AA0679 for ; Sun, 28 Apr 2019 04:45:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 33C631B4C9; Sun, 28 Apr 2019 04:45:46 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id A29F81B54D for ; Sun, 28 Apr 2019 04:45:42 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2019 19:45:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,403,1549958400"; d="scan'208";a="146438623" Received: from itecstvdts01.sh.intel.com ([10.67.111.114]) by fmsmga007.fm.intel.com with ESMTP; 27 Apr 2019 19:45:41 -0700 From: yufengmx To: dts@dpdk.org Cc: yufengmx Date: Sun, 28 Apr 2019 10:49:11 +0800 Message-Id: <1556419751-41723-15-git-send-email-yufengx.mo@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1556419751-41723-1-git-send-email-yufengx.mo@intel.com> References: <1556419751-41723-1-git-send-email-yufengx.mo@intel.com> Subject: [dts] [next][PATCH V1 4/14] framework/pktgen: utils methods 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: , Errors-To: dts-bounces@dpdk.org Sender: "dts" new utils methods used by pktgen Set convert_int2ip/convert_ip2int input parameter with a default ipv4 value. Add convert_mac2long/convert_mac2str methods to deal with mac convert(str <--> int). Signed-off-by: yufengmx --- framework/utils.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/framework/utils.py b/framework/utils.py index ce97d5f..8f5a233 100644 --- a/framework/utils.py +++ b/framework/utils.py @@ -214,7 +214,11 @@ def create_mask(indexes): return hex(val).rstrip("L") -def convert_int2ip(value, ip_type): +def convert_int2ip(value, ip_type=4): + ''' + @change: + 2019.0403 set default value + ''' if ip_type == 4: ip_str = socket.inet_ntop(socket.AF_INET, struct.pack('!I', value)) else: @@ -224,7 +228,11 @@ def convert_int2ip(value, ip_type): return ip_str -def convert_ip2int(ip_str, ip_type): +def convert_ip2int(ip_str, ip_type=4): + ''' + @change: + 2019.0403 set default value + ''' if ip_type == 4: ip_val = struct.unpack("!I", socket.inet_aton(ip_str))[0] else: @@ -234,6 +242,26 @@ def convert_ip2int(ip_str, ip_type): return ip_val +def convert_mac2long(mac_str): + """ + convert the MAC type from the string into the int. + """ + mac_hex = '0x' + for mac_part in mac_str.lower().split(':'): + mac_hex += mac_part + ret = long(mac_hex, 16) + return ret + +def convert_mac2str(mac_long): + """ + convert the MAC type from the int into the string. + """ + mac = hex(mac_long)[2:-1].zfill(12) + b = [] + [b.append(mac[n:n+2]) for n in range(len(mac)) if n % 2 == 0 ] + new_mac = ":".join(b) + return new_mac + def get_backtrace_object(file_name, obj_name): import inspect frame = inspect.currentframe() -- 1.9.3