From: yufengmx <yufengx.mo@intel.com>
To: dts@dpdk.org
Cc: yufengmx <yufengx.mo@intel.com>
Subject: [dts] [next][PATCH V1 4/14] framework/pktgen: utils methods
Date: Sun, 28 Apr 2019 10:49:11 +0800 [thread overview]
Message-ID: <1556419751-41723-15-git-send-email-yufengx.mo@intel.com> (raw)
In-Reply-To: <1556419751-41723-1-git-send-email-yufengx.mo@intel.com>
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 <yufengx.mo@intel.com>
---
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
next prev parent reply other threads:[~2019-04-28 2:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-28 2:48 [dts] [next][PATCH V1 0/14] [dts/pktgen]: dts packet generator api yufengmx
2019-04-28 2:48 ` [dts] [next][PATCH V1 1/14] conf/pktgen: add pktgen key word in crbs.cfg yufengmx
2019-04-28 2:48 ` [dts] [next][PATCH V1 2/14] conf/pktgen: packet generator configure file definition yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 3/14] doc/pktgen: trex tool known issues yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 4/14] doc/pktgen: migrate from etgen api to pktgen api yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 5/14] doc/pktgen: pktgen api program guide document yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 6/14] framework/pktgen: packet generator configure file parse yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 7/14] framework/pktgen: initialize pktgen logger yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 8/14] framework/pktgen: packet generator base class yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 9/14] framework/pktgen: ixia packet generator relevant classes yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 0/14] framework/pktgen: trex " yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 1/14] framework/pktgen: pktgen instance creation and helper yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 2/14] framework/pktgen: packet generator types definition yufengmx
2019-04-28 2:49 ` [dts] [next][PATCH V1 3/14] framework/pktgen: packet generator init and trex port yufengmx
2019-04-28 2:49 ` yufengmx [this message]
2019-05-29 2:45 ` [dts] [next][PATCH V1 0/14] [dts/pktgen]: dts packet generator api Tu, Lijuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1556419751-41723-15-git-send-email-yufengx.mo@intel.com \
--to=yufengx.mo@intel.com \
--cc=dts@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).