* [dts] [PATCH 1/3] framework utils: add function to convert ipaddress
2016-10-26 7:00 [dts] [PATCH 0/3] enable random packet check function Marvin Liu
@ 2016-10-26 7:00 ` Marvin Liu
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
2 siblings, 0 replies; 4+ messages in thread
From: Marvin Liu @ 2016-10-26 7:00 UTC (permalink / raw)
To: dts
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [dts] [PATCH 3/3] framework tester: workaround random packet check issue
2016-10-26 7:00 [dts] [PATCH 0/3] enable random packet check function Marvin Liu
2016-10-26 7:00 ` [dts] [PATCH 1/3] framework utils: add function to convert ipaddress Marvin Liu
2016-10-26 7:00 ` [dts] [PATCH 2/3] framework packet: support ip layer elements strip Marvin Liu
@ 2016-10-26 7:00 ` Marvin Liu
2 siblings, 0 replies; 4+ messages in thread
From: Marvin Liu @ 2016-10-26 7:00 UTC (permalink / raw)
To: dts
Random packet check maybe failed for scapy can't correct handle some
types of protocals. Make a workaround of this issue. Packet index will
be saved in source ip address. Source and destination ports will be hard
code to 65535.
Signed-off-by: Marvin Liu <yong.liu@intel.com>
diff --git a/framework/tester.py b/framework/tester.py
index b95cfc3..55395a8 100644
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -42,7 +42,7 @@ from net_device import GetNicObj
from etgen import IxiaPacketGenerator, SoftwarePacketGenerator
from settings import IXIA
import random
-from utils import GREEN
+from utils import GREEN, convert_int2ip, convert_ip2int
from exception import ParameterInvalidException
@@ -557,16 +557,25 @@ class Tester(Crb):
for param in params:
layer, config = param
pkt.config_layer(layer, config)
- # sequence saved in layer4 source port
+ # hardcode src/dst port for some protocal may cause issue
if "TCP" in pkt_type:
- pkt.config_layer('tcp', {'src': num % 65536})
+ pkt.config_layer('tcp', {'src': 65535, 'dst': 65535})
else:
- pkt.config_layer('udp', {'src': num % 65536})
+ pkt.config_layer('udp', {'src': 65535, 'dst': 65535})
+ # sequence saved in layer3 source ip
+ if "IPv6" in pkt_type:
+ ip_str = convert_int2ip(num, 6)
+ pkt.config_layer('ipv6', {'src': ip_str})
+ else:
+ ip_str = convert_int2ip(num, 4)
+ pkt.config_layer('ipv4', {'src': ip_str})
+
pkts.append(pkt)
# send and sniff packets
save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout)
+ print GREEN("Transmitting and sniffing packets, please wait few minutes...")
send_f(intf=txIntf, pkts=pkts, interval=interval)
recv_pkts = load_f(inst)
@@ -578,9 +587,19 @@ class Tester(Crb):
return False
# check each received packet content
- print GREEN("Comparing sniff packets, please wait few minutes...")
+ print GREEN("Comparing sniffed packets, please wait few minutes...")
for idx in range(len(recv_pkts)):
- t_idx = recv_pkts[idx].strip_element_layer4('src')
+ l3_type = recv_pkts[idx].strip_element_layer2('type')
+ sip = recv_pkts[idx].strip_element_layer3('src')
+ # ipv4 packet
+ if l3_type == 2048:
+ t_idx = convert_ip2int(sip, 4)
+ # ipv6 packet
+ elif l3_type == 34525:
+ t_idx = convert_ip2int(sip, 6)
+ else:
+ continue
+
if compare_f(pkts[t_idx], recv_pkts[idx], "L4") is False:
print "Pkt recevied index %d not match original " \
"index %d" % (idx, t_idx)
--
1.9.3
^ permalink raw reply [flat|nested] 4+ messages in thread