test suite reviews and discussions
 help / color / mirror / Atom feed
From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH 1/3] framework utils: add function to convert ipaddress
Date: Wed, 26 Oct 2016 15:00:39 +0800	[thread overview]
Message-ID: <1477465241-17826-2-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1477465241-17826-1-git-send-email-yong.liu@intel.com>

Add new function to convert ip address to integer and covert integer to
ip.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

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

  reply	other threads:[~2016-10-26  7:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26  7:00 [dts] [PATCH 0/3] enable random packet check function Marvin Liu
2016-10-26  7:00 ` Marvin Liu [this message]
2016-10-26  7:00 ` [dts] [PATCH 2/3] framework packet: support ip layer elements strip Marvin Liu
2016-10-26  7:00 ` [dts] [PATCH 3/3] framework tester: workaround random packet check issue Marvin Liu

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=1477465241-17826-2-git-send-email-yong.liu@intel.com \
    --to=yong.liu@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).