* [dts] [PATCH V1] framework/packet: update packet module of dts
2019-09-27 18:05 [dts] [PATCH V1] tests/: update cases related to new framework Qimai Xiao
@ 2019-09-27 18:05 ` Qimai Xiao
2019-10-08 2:22 ` Chen, Zhaoyan
2019-10-12 5:30 ` Tu, Lijuan
2019-09-27 18:05 ` [dts] [PATCH V1] framework/tester: update tester " Qimai Xiao
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: Qimai Xiao @ 2019-09-27 18:05 UTC (permalink / raw)
To: dts; +Cc: Qimai Xiao
update API of packet and some other optimization
Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
---
framework/packet.py | 665 +++++++++++++++++++++++---------------------
1 file changed, 354 insertions(+), 311 deletions(-)
diff --git a/framework/packet.py b/framework/packet.py
index 502d85c..05b2367 100755
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -33,35 +33,19 @@
Generic packet create, transmit and analyze module
Base on scapy(python program for packet manipulation)
"""
-import os
-import time
-import sys
-import re
-import signal
-import random
-import subprocess
-import shlex # separate command line for pipe
-from uuid import uuid4
-from settings import FOLDERS
-
-import struct
+
from socket import AF_INET6
-from scapy.all import conf
-from scapy.utils import wrpcap, rdpcap, hexstr
-from scapy.layers.inet import Ether, IP, TCP, UDP, ICMP
-from scapy.layers.inet6 import IPv6, IPv6ExtHdrRouting, IPv6ExtHdrFragment
-from scapy.layers.l2 import Dot1Q, ARP, GRE
+from scapy.all import *
from scapy.layers.sctp import SCTP, SCTPChunkData
-from scapy.sendrecv import sniff
-from scapy.route import *
-from scapy.packet import bind_layers, Raw
-from scapy.sendrecv import sendp
-from scapy.arch import get_if_hwaddr
-from pexpect import pxssh
# load extension layers
exec_file = os.path.realpath(__file__)
DTS_PATH = exec_file.replace('/framework/packet.py', '')
+# exec_file might be .pyc file, if so, remove 'c'.
+TMP_PATH = DTS_PATH[:-1] + '/output/tmp/pcap/' if exec_file.endswith('.pyc') else DTS_PATH + '/output/tmp/pcap/'
+
+if not os.path.exists(TMP_PATH):
+ os.system('mkdir -p %s' % TMP_PATH)
DEP_FOLDER = DTS_PATH + '/dep'
sys.path.append(DEP_FOLDER)
@@ -70,9 +54,8 @@ from nvgre import NVGRE, IPPROTO_NVGRE
from lldp import LLDP, LLDPManagementAddress
from Dot1BR import Dot1BR
-# get tester logger
-from logger import getLogger
-logger = getLogger('tester')
+from utils import convert_ip2int
+from utils import convert_int2ip
# for saving command history
from utils import get_backtrace_object
@@ -150,7 +133,16 @@ class scapy(object):
def __init__(self):
self.pkt = None
- pass
+ self.pkts = []
+
+ def append_pkts(self):
+ self.pkts.append(self.pkt)
+
+ def update_pkts(self):
+ if not self.pkts: # update pkt to a null pkt list.
+ self.pkts.append(self.pkt)
+ else:
+ self.pkts[-1] = self.pkt
def assign_pkt(self, pkt):
self.pkt = pkt
@@ -179,14 +171,14 @@ class scapy(object):
if type is not None:
pkt_layer.type = type
- def strip_vlan(self, element):
+ def strip_vlan(self, element, p_index=0):
value = None
- if self.pkt.haslayer('Dot1Q') is 0:
+ if self.pkts[p_index].haslayer('Dot1Q') is 0:
return None
if element == 'vlan':
- value = int(str(self.pkt[Dot1Q].vlan))
+ value = int(str(self.pkts[p_index][Dot1Q].vlan))
return value
def etag(self, pkt_layer, ECIDbase=0, prio=0, type=None):
@@ -197,19 +189,19 @@ class scapy(object):
if type is not None:
pkt_layer.type = type
- def strip_etag(self, element):
+ def strip_etag(self, element, p_index=0):
value = None
- if self.pkt.haslayer('Dot1BR') is 0:
+ if self.pkts[p_index].haslayer('Dot1BR') is 0:
return None
if element == 'ECIDbase':
- value = int(str(self.pkt[Dot1BR].ECIDbase))
+ value = int(str(self.pkts[p_index][Dot1BR].ECIDbase))
return value
- def strip_layer2(self, element):
+ def strip_layer2(self, element, p_index=0):
value = None
- layer = self.pkt.getlayer(0)
+ layer = self.pkts[p_index].getlayer(0)
if layer is None:
return None
@@ -222,9 +214,9 @@ class scapy(object):
return value
- def strip_layer3(self, element):
+ def strip_layer3(self, element, p_index=0):
value = None
- layer = self.pkt.getlayer(1)
+ layer = self.pkts[p_index].getlayer(1)
if layer is None:
return None
@@ -237,9 +229,9 @@ class scapy(object):
return value
- def strip_layer4(self, element):
+ def strip_layer4(self, element, p_index=0):
value = None
- layer = self.pkt.getlayer(2)
+ layer = self.pkts[p_index].getlayer(2)
if layer is None:
return None
@@ -252,7 +244,8 @@ class scapy(object):
return value
- def ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0, dst="127.0.0.1", chksum=None, len=None, version=4, flags=None, ihl=None, ttl=64, id=1, options=None):
+ def ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0, dst="127.0.0.1", chksum=None, len=None,
+ version=4, flags=None, ihl=None, ttl=64, id=1, options=None):
pkt_layer.frag = frag
pkt_layer.src = src
if proto is not None:
@@ -287,7 +280,7 @@ class scapy(object):
pkt_layer.src = src
pkt_layer.dst = dst
- def tcp(self, pkt_layer, src=53, dst=53, flags=None, len=None, chksum=None):
+ def tcp(self, pkt_layer, src=53, dst=53, flags=0, len=None, chksum=None):
pkt_layer.sport = src
pkt_layer.dport = dst
if flags is not None:
@@ -328,66 +321,6 @@ class scapy(object):
def vxlan(self, pkt_layer, vni=0):
pkt_layer.vni = vni
- def read_pcap(self, file):
- pcap_pkts = []
- try:
- pcap_pkts = rdpcap(file)
- except:
- pass
-
- return pcap_pkts
-
- def write_pcap(self, file):
- try:
- wrpcap(file, self.pkt)
- except:
- pass
-
- def send_pcap_pkt(self, crb=None, file='', intf='', count=1):
- if intf == '' or file == '' or crb is None:
- print "Invalid option for send packet by scapy"
- return
-
- content = 'pkts=rdpcap(\"%s\");sendp(pkts, iface=\"%s\", count=\"%s\" );exit()' % (file, intf, count)
- cmd_file = '/tmp/scapy_%s.cmd' % intf
-
- crb.create_file(content, cmd_file)
- crb.send_expect("scapy -c scapy_%s.cmd &" % intf, "# ")
-
- def print_summary(self):
- # save command into test case history
- history_list = get_backtrace_object('test_case.py', 'test_history')
- if type(history_list) is list:
- history_list.append({"command": "p=%s" % self.pkt.command(), "name": "Scapy", "output": ""})
-
- logger.info("%s" % self.pkt.command())
-
- def send_pkt(self, intf='', count=1):
- self.print_summary()
-
- if intf != '':
- # wait few seconds for link ready
- countdown = 600
- while countdown:
- link_st = subprocess.check_output("ip link show %s" % intf,
- stderr=subprocess.STDOUT,
- shell=True)
- if "LOWER_UP" in link_st:
- break
- else:
- time.sleep(0.01)
- countdown -= 1
- continue
-
- # fix fortville can't receive packets with 00:00:00:00:00:00
- if self.pkt.getlayer(0).src == "00:00:00:00:00:00":
- self.pkt.getlayer(0).src = get_if_hwaddr(intf)
- sendp(self.pkt, iface=intf, count=count)
-
- # save command into test case history
- history_list = get_backtrace_object('test_case.py', 'test_history')
- if type(history_list) is list:
- history_list.append({"command": "sendp(p, iface=\"%s\")" % intf, "name": "Scapy", "output": ""})
class Packet(object):
@@ -413,10 +346,11 @@ class Packet(object):
'IPv6_SCTP': {'layers': ['ether', 'ipv6', 'sctp', 'raw'], 'cfgload': True},
}
- def __init__(self, **options):
+ def __init__(self, pkt_str=None, **options):
"""
pkt_type: description of packet type
defined in def_packet
+ args: specify a packet with a string explicitly, will ignore options
options: special option for Packet module
pkt_len: length of network packet
ran_payload: whether payload of packet is random
@@ -424,14 +358,41 @@ class Packet(object):
pkt_gen: packet generator type
now only support scapy
"""
- self.pkt_layers = []
- self.pkt_len = 64
self.pkt_opts = options
+ self.pkt_layers = []
- self.pkt_type = "UDP"
+ if 'pkt_gen' in self.pkt_opts.keys():
+ if self.pkt_opts['pkt_gen'] == 'scapy':
+ self.pktgen = scapy()
+ else:
+ print "Not support other pktgen yet!!!"
+ else:
+ self.pktgen = scapy()
- if 'pkt_type' in self.pkt_opts.keys():
- self.pkt_type = self.pkt_opts['pkt_type']
+ if pkt_str is not None and type(pkt_str) == str:
+ self._scapy_str_to_pkt(pkt_str)
+ elif len(options) == 0:
+ pass
+ else:
+ self._add_pkt(self.pkt_opts)
+ if self.pktgen.pkt is not None:
+ self.pktgen.append_pkts()
+
+ def __len__(self):
+ return len(self.pktgen.pkts)
+
+ def __getitem__(self, item):
+ return self.pktgen.pkts[item]
+
+ def _add_pkt(self, options):
+ """
+ :param options: packt configuration, dictionary type
+ :return:
+ """
+ self.pkt_len = 64
+ self.pkt_type = "UDP"
+ if 'pkt_type' in options.keys():
+ self.pkt_type = options['pkt_type']
if self.pkt_type in self.def_packet.keys():
self.pkt_layers = self.def_packet[self.pkt_type]['layers']
@@ -441,21 +402,8 @@ class Packet(object):
else:
self._load_pkt_layers()
- if 'pkt_len' in self.pkt_opts.keys():
- self.pkt_len = self.pkt_opts['pkt_len']
-
- if 'pkt_file' in self.pkt_opts.keys():
- self.uni_name = self.pkt_opts['pkt_file']
- else:
- self.uni_name = '/tmp/' + str(uuid4()) + '.pcap'
-
- if 'pkt_gen' in self.pkt_opts.keys():
- if self.pkt_opts['pkt_gen'] == 'scapy':
- self.pktgen = scapy()
- else:
- print "Not support other pktgen yet!!!"
- else:
- self.pktgen = scapy()
+ if 'pkt_len' in options.keys():
+ self.pkt_len = options['pkt_len']
self._load_assign_layers()
@@ -483,32 +431,227 @@ class Packet(object):
raw_confs['payload'] = payload
self.config_layer('raw', raw_confs)
- def send_pkt(self, crb=None, tx_port='', auto_cfg=True, count=1):
- if tx_port == '':
- print "Invalid Tx interface"
- return
+ def _scapy_str_to_pkt(self, scapy_str):
+ """
- self.tx_port = tx_port
+ :param scapy_str: packet str, eg. 'Ether()/IP()/UDP()'
+ :return: None
+ """
+ layer_li = [re.sub('\(.*?\)', '', i) for i in scapy_str.split('/')]
+ self.pkt_type = '_'.join(layer_li)
+ self._load_pkt_layers()
+ pkt = eval(scapy_str)
+ self.pktgen.assign_pkt(pkt)
- # check with port type
- if 'ixia' in self.tx_port:
- print "Not Support Yet"
+ def append_pkt(self, args=None, **kwargs):
+ """
+ :param args: take str type as pkt to append
+ :param kwargs: take dictory type as pkt to append
+ :return: None
+ """
+ if isinstance(args, str):
+ self._scapy_str_to_pkt(args)
+ elif isinstance(kwargs, dict):
+ self.pkt_opts = kwargs
+ if hasattr(self, 'configured_layer_raw'):
+ delattr(self, 'configured_layer_raw')
+ self._add_pkt(kwargs)
+ self.pktgen.append_pkts()
+
+ def generate_random_pkts(self, dstmac=None, pktnum=100, random_type=None, ip_increase=True, random_payload=False,
+ options=None):
+ """
+ # generate random packets
+ :param dstmac: specify the dst mac
+ :param pktnum: packet number to generate
+ :param random_type: specify random packet type
+ :param ip_increase: auto increase ip value
+ :param random_payload: if True, generate random packets with random payload
+ :param options: packet layer configuration
+ :return: None
+ """
- if crb is not None:
- self.pktgen.write_pcap(self.uni_name)
- crb.session.copy_file_to(self.uni_name)
- pcap_file = self.uni_name.split('/')[2]
- self.pktgen.send_pcap_pkt(
- crb=crb, file=pcap_file, intf=self.tx_port, count=count)
+ random_type = ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP'] if random_type is None else random_type
+ options = {'ip': {'src': '192.168.0.1', 'dst': '192.168.1.1'},
+ 'layers_config': []} if options is None else options
+ # give a default value to ip
+ try:
+ src_ip_num = convert_ip2int(options['ip']['src'])
+ except:
+ src_ip_num = 0
+ try:
+ dst_ip_num = convert_ip2int(options['ip']['dst'])
+ except:
+ dst_ip_num = 0
+
+ for i in range(pktnum):
+ # random the packet type
+ self.pkt_type = random.choice(random_type)
+ self.pkt_layers = self.def_packet[self.pkt_type]['layers']
+ self.check_layer_config()
+ self.pktgen.add_layers(self.pkt_layers)
+ # hardcode src/dst port for some protocol may cause issue
+ if "TCP" in self.pkt_type:
+ self.config_layer('tcp', {'src': 65535, 'dst': 65535})
+ if "UDP" in self.pkt_type:
+ self.config_layer('udp', {'src': 65535, 'dst': 65535})
+ if options.has_key('layers_config'):
+ self.config_layers(options['layers_config'])
+ if dstmac:
+ self.config_layer('ether', {'dst': '%s' % dstmac})
+ # generate auto increase dst ip packet
+ if ip_increase:
+ if 'v6' in self.pkt_type:
+ dstip = convert_int2ip(dst_ip_num, ip_type=6)
+ srcip = convert_int2ip(src_ip_num, ip_type=6)
+ self.config_layer('ipv6', config={'dst': '%s' % (dstip), 'src': '%s' % srcip})
+ else:
+ dstip = convert_int2ip(dst_ip_num, ip_type=4)
+ srcip = convert_int2ip(src_ip_num, ip_type=4)
+ self.config_layer('ipv4', config={'dst': '%s' % (dstip), 'src': '%s' % srcip})
+ dst_ip_num += 1
+ # generate random payload of packet
+ if random_payload and self.def_packet[self.pkt_type]['cfgload']:
+ # TCP packet has a default flags S, packet should not load data, so set it to A if has payload
+ if 'TCP' in self.pkt_type:
+ self.config_layer('tcp', {'src': 65535, 'dst': 65535, 'flags': 'A'})
+
+ payload_len = random.randint(64, 100)
+ payload = []
+ for _ in range(payload_len):
+ payload.append("%02x" % random.randrange(0, 255))
+ self.config_layer('raw', config={'payload': payload})
+ self.pktgen.append_pkts()
+
+ def save_pcapfile(self, crb=None, filename='saved_pkts.pcap'):
+ """
+
+ :param crb: session or crb object
+ :param filename: location and name for packets to be saved
+ :return: None
+ """
+ # save pkts to pcap file to local path, then copy to remote tester tmp directory,
+ if crb:
+ trans_path = crb.tmp_file
+ file_name = filename
+ if os.path.isabs(filename): # check if the given filename with a abs path
+ file_dir = os.path.dirname(filename)
+ out = crb.send_expect('ls -d %s' % file_dir, '# ', verify=True)
+ if not isinstance(out, str):
+ raise Exception('%s may not existed on %s' % (file_dir, crb.name))
+ wrpcap(filename, self.pktgen.pkts)
+ trans_path = os.path.abspath(filename)
+ file_name = filename.split(os.path.sep)[-1]
+ # write packets to local tmp path $dts/ouput/tmp/pcap/
+ wrpcap(TMP_PATH + file_name, self.pktgen.pkts)
+ # copy to remote tester tmp path /tmp/tester
+ crb.session.copy_file_to(TMP_PATH + file_name, trans_path)
else:
- self.pktgen.send_pkt(intf=self.tx_port, count=count)
+ wrpcap(filename, self.pktgen.pkts)
- def check_layer_config(self, layer, config):
+ def read_pcapfile(self, filename, crb=None):
+ """
+
+ :param filename: packet to be read from
+ :param crb: session or crb object
+ :return: scapy type packet
+ """
+ # read pcap file from local or remote, then append to pkts list
+ # if crb, read pakcet from remote server, else read from local location
+ if crb:
+ out = crb.send_expect('ls -d %s' % filename, '# ', verify=True)
+ if not isinstance(out, str):
+ raise Exception('%s may not existed on %s' % (filename, crb.name))
+ crb.session.copy_file_from(filename, TMP_PATH)
+ p = rdpcap(TMP_PATH + filename.split(os.path.sep)[-1])
+ else:
+ p = rdpcap(filename)
+ if len(p) == 0:
+ return None
+ self.pktgen.assign_pkt(p[-1])
+ for i in p:
+ self.pktgen.pkts.append(i)
+ return p
+
+ def _send_pkt(self, crb, tx_port='', count=1, send_bg=False, loop=0, inter=0, timeout=15):
+ """
+
+ :param crb: session or crb object
+ :param tx_port: ether to send packet
+ :param count: send times
+ :param send_bg: send packet background
+ :param loop: send packet in a loop
+ :param inter: interval time
+ :return: None
+ """
+ # save pkts to local pcap file, then copy to remote tester tmp directory
+
+ time_stamp = str(time.time())
+ pcap_file = 'scapy_{}.pcap'.format(tx_port) + time_stamp
+ self.save_pcapfile(crb, pcap_file)
+ scapy_cmd = 'scapy_{}.cmd'.format(tx_port) + time_stamp
+ cmd_str = 'from scapy.all import *\np=rdpcap("%s")\nprint("packet ready for sending...")\nfor i in p:\n\tprint(i.command())\nsendp(p, iface="%s", count=%d, loop=%d, inter=%0.3f)' % (
+ crb.tmp_file + pcap_file, tx_port, count, loop, inter)
+ # write send cmd file to local tmp directory then copy to remote tester tmp folder
+ with open(TMP_PATH + scapy_cmd, 'w') as f:
+ f.write(cmd_str)
+ crb.session.copy_file_to(TMP_PATH + scapy_cmd, crb.tmp_file)
+
+ if send_bg: # if send_bg create a new session to execute send action
+ session_prefix = 'scapy_bg_session'
+ scapy_session = crb.create_session(session_prefix + time_stamp)
+ scapy_session.send_command('python %s' % crb.tmp_file + scapy_cmd)
+ else:
+ crb.send_expect('python %s' % crb.tmp_file + scapy_cmd, '# ', timeout=timeout)
+ return crb.tmp_file + scapy_cmd
+
+ def send_pkt(self, crb, tx_port='', count=1, interval=0, timeout=15):
+ self._send_pkt(crb, tx_port, count, inter=interval, timeout=timeout)
+
+ def send_pkt_bg(self, crb, tx_port='', count=-1, loop=1, interval=0, timeout=3):
+ return self._send_pkt(crb, tx_port=tx_port, count=count, send_bg=True, loop=loop, inter=interval,
+ timeout=timeout)
+
+ def stop_send_pkt_bg(self, crb, filenames):
+ # stop sending action
+ pids = []
+ if isinstance(filenames, list):
+ for file in filenames:
+ out = crb.send_expect('ps -ef |grep %s|grep -v grep' % file, expected='# ')
+ try:
+ pids.append(re.search('\d+', out).group())
+ except AttributeError as e:
+ print(e, ' :%s not killed' % file)
+ else:
+ out = crb.send_expect('ps -ef |grep %s|grep -v grep' % filenames, expected='# ')
+ try:
+ pids.append(re.search('\d+', out).group())
+ except AttributeError as e:
+ print(e, ' :%s not killed' % filenames)
+ pid = ' '.join(pids)
+ if pid:
+ crb.send_expect('kill -9 %s' % pid, expected='# ')
+ for i in crb.sessions:
+ if i.name.startswith('scapy_bg_session'):
+ crb.destroy_session(i)
+
+ def check_layer_config(self):
"""
check the format of layer configuration
every layer should has different check function
"""
- pass
+ for layer in self.pkt_layers:
+ found = False
+ l_type = layer.lower()
+
+ for types in LayersTypes.values():
+ if l_type in types:
+ found = True
+ break
+
+ if found is False:
+ self.pkt_layers.remove(l_type)
+ print "INVAILD LAYER TYPE [%s]" % l_type.upper()
def assign_layers(self, layers=None):
"""
@@ -532,6 +675,8 @@ class Packet(object):
print "INVAILD LAYER TYPE [%s]" % l_type.upper()
self.pktgen.add_layers(self.pkt_layers)
+ if layers:
+ self.pktgen.update_pkts()
def _load_pkt_layers(self):
name2type = {
@@ -590,9 +735,9 @@ class Packet(object):
else:
self.config_layer('raw', {'payload': ['00'] * 18})
- if "MAC_IP_IPv6" in self.pkt_type or\
- "MAC_IP_NVGRE" in self.pkt_type or \
- "MAC_IP_UDP_VXLAN" in self.pkt_type:
+ if "MAC_IP_IPv6" in self.pkt_type or \
+ "MAC_IP_NVGRE" in self.pkt_type or \
+ "MAC_IP_UDP_VXLAN" in self.pkt_type:
if "IPv6_SCTP" in self.pkt_type:
self.config_layer('ipv6', {'nh': 132})
if "IPv6_ICMP" in self.pkt_type:
@@ -601,6 +746,8 @@ class Packet(object):
self.config_layer('raw', {'payload': ['00'] * 40})
else:
self.config_layer('raw', {'payload': ['00'] * 18})
+ if 'TCP' in self.pkt_type:
+ self.config_layer('tcp', {'flags': 0})
def config_layer(self, layer, config={}):
"""
@@ -613,22 +760,23 @@ class Packet(object):
print "INVALID LAYER ID %s" % layer
return False
- if self.check_layer_config(layer, config) is False:
+ if self.check_layer_config() is False:
return False
if 'inner' in layer:
layer = layer[6:]
pkt_layer = self.pktgen.pkt.getlayer(idx)
- layer_conf = getattr(self, "_config_layer_%s" % layer)
+ layer_conf = getattr(self.pktgen, layer)
setattr(self, 'configured_layer_%s' % layer, True)
- return layer_conf(pkt_layer, config)
+ layer_conf(pkt_layer, **config)
def config_layers(self, layers=None):
"""
Configure packet with multi configurations
"""
+ layers = [] if layers is None else layers # None object is not Iterable
for layer in layers:
name, config = layer
if name not in self.pkt_layers:
@@ -638,65 +786,28 @@ class Packet(object):
print "[%s] failed to configure!!!" % name
raise
- def _config_layer_ether(self, pkt_layer, config):
- return self.pktgen.ether(pkt_layer, **config)
-
- def _config_layer_mac(self, pkt_layer, config):
- return self.pktgen.ether(pkt_layer, **config)
-
- def _config_layer_vlan(self, pkt_layer, config):
- return self.pktgen.vlan(pkt_layer, **config)
-
- def _config_layer_etag(self, pkt_layer, config):
- return self.pktgen.etag(pkt_layer, **config)
-
- def _config_layer_ipv4(self, pkt_layer, config):
- return self.pktgen.ipv4(pkt_layer, **config)
-
- def _config_layer_ipv6(self, pkt_layer, config):
- return self.pktgen.ipv6(pkt_layer, **config)
-
- def _config_layer_udp(self, pkt_layer, config):
- return self.pktgen.udp(pkt_layer, **config)
-
- def _config_layer_tcp(self, pkt_layer, config):
- return self.pktgen.tcp(pkt_layer, **config)
-
- def _config_layer_sctp(self, pkt_layer, config):
- return self.pktgen.sctp(pkt_layer, **config)
-
- def _config_layer_gre(self, pkt_layer, config):
- return self.pktgen.gre(pkt_layer, **config)
-
- def _config_layer_raw(self, pkt_layer, config):
- return self.pktgen.raw(pkt_layer, **config)
-
- def _config_layer_vxlan(self, pkt_layer, config):
- return self.pktgen.vxlan(pkt_layer, **config)
-
- def strip_layer_element(self, layer, element):
+ def strip_layer_element(self, layer, element, p_index=0):
"""
Strip packet layer elements
return the status of configure result
"""
strip_element = getattr(self, "strip_element_%s" % layer)
+ return strip_element(element, p_index)
- return strip_element(element)
-
- def strip_element_layer2(self, element):
- return self.pktgen.strip_layer2(element)
+ def strip_element_layer2(self, element, p_index=0):
+ return self.pktgen.strip_layer2(element, p_index)
- def strip_element_layer3(self, element):
- return self.pktgen.strip_layer3(element)
+ def strip_element_layer3(self, element, p_index=0):
+ return self.pktgen.strip_layer3(element, p_index)
- def strip_element_vlan(self, element):
- return self.pktgen.strip_vlan(element)
+ def strip_element_vlan(self, element, p_index=0):
+ return self.pktgen.strip_vlan(element, p_index)
- def strip_element_etag(self, element):
- return self.pktgen.strip_etag(element)
+ def strip_element_etag(self, element, p_index=0):
+ return self.pktgen.strip_etag(element, p_index)
- def strip_element_layer4(self, element):
- return self.pktgen.strip_layer4(element)
+ def strip_element_layer4(self, element, p_index=0):
+ return self.pktgen.strip_layer4(element, p_index)
def IncreaseIP(addr):
@@ -725,27 +836,6 @@ def IncreaseIPv6(addr):
return ipv6
-def send_packets(intf, pkts=None, interval=0.01):
- send_pkts = []
- try:
- for pkt in pkts:
- send_pkts.append(pkt.pktgen.pkt)
- sendp(send_pkts, iface=intf, inter=interval, verbose=False)
- except:
- pass
-
-
-def save_packets(pkts=None, filename=None):
- save_pkts = []
- try:
- for pkt in pkts:
- save_pkts.append(pkt.pktgen.pkt)
- if filename:
- wrpcap(filename, save_pkts)
- except:
- pass
-
-
def get_ether_type(eth_type=""):
# need add more types later
if eth_type.lower() == "lldp":
@@ -809,48 +899,46 @@ def get_filter_cmd(filters=[]):
return ""
-def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
+def start_tcpdump(crb, intf, count=0, filters=None, lldp_forbid=True):
"""
- sniff all packets for certain port in certain seconds
+ sniff all packets from certain port
"""
+ filters = [] if filters is None else filters
+ out = crb.send_expect("ls -d %s" % crb.tmp_file, "# ", verify=True)
+ if out == 2:
+ crb.send_expect("mkdir -p %s" % crb.tmp_file, "# ")
+ filename = '{}sniff_{}.pcap'.format(crb.tmp_file, intf)
+ # delete old pcap file
+ crb.send_expect('rm -rf %s' % filename, '# ')
+
param = ""
direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
-
- try:
- tcpdump_help_session=pxssh.pxssh()
- tcpdump_help_session.login(server=target[0], username=target[1],
- password=target[2], original_prompt='[$#>]',
- login_timeout=20)
- tcpdump_help_session.sendline('tcpdump -h')
- tcpdump_help_session.prompt()
- tcpdump_help=tcpdump_help_session.before
- tcpdump_help_session.logout()
- except pxssh.ExceptionPxssh as e:
- print ('pxssh failed on login.')
- print (e)
+ tcpdump_session = crb.create_session('tcpdump_session' + str(time.time()))
+ setattr(tcpdump_session, 'tmp_file', crb.tmp_file)
+ tcpdump_help = tcpdump_session.send_command('tcpdump -h')
for line in tcpdump_help.split('\n'):
m = re.match(direct_param, line)
if m:
- opt = re.search("-Q", m.group(2));
+ opt = re.search("-Q", m.group(2))
if opt:
param = "-Q" + " in"
else:
- opt = re.search("-P", m.group(2));
+ opt = re.search("-P", m.group(2))
if opt:
param = "-P" + " in"
if len(param) == 0:
print "tcpdump not support direction choice!!!"
- if LLDP_FILTER not in filters:
+ if lldp_forbid and (LLDP_FILTER not in filters):
filters.append(LLDP_FILTER)
filter_cmd = get_filter_cmd(filters)
sniff_cmd = 'tcpdump -i %(INTF)s %(FILTER)s %(IN_PARAM)s -w %(FILE)s'
options = {'INTF': intf, 'COUNT': count, 'IN_PARAM': param,
- 'FILE': '/tmp/sniff_%s.pcap' % intf,
+ 'FILE': filename,
'FILTER': filter_cmd}
if count:
sniff_cmd += ' -c %(COUNT)d'
@@ -858,77 +946,27 @@ def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
else:
cmd = sniff_cmd % options
- try:
- tcpdump_session=pxssh.pxssh()
- tcpdump_session.login(server=target[0], username=target[1],
- password=target[2], original_prompt='[$#>]',
- login_timeout=20)
- tcpdump_session.sendline(cmd)
- pipe = tcpdump_session
- except pxssh.ExceptionPxssh as e:
- print ('pxssh failed on login.')
- print (e)
+ tcpdump_session.send_command(cmd)
index = str(time.time())
- SNIFF_PIDS[index] = (pipe, intf, timeout)
+ SNIFF_PIDS[index] = (tcpdump_session, intf, filename)
time.sleep(1)
return index
-def load_sniff_pcap(index='', target=[]):
+def stop_and_load_tcpdump_packets(index='', timeout=1):
"""
- Stop sniffer and return pcap file
+ Stop sniffer and return packet object
"""
- child_exit = False
if index in SNIFF_PIDS.keys():
- pipe, intf, timeout = SNIFF_PIDS[index]
- time_elapse = int(time.time() - float(index))
- while time_elapse < timeout:
- if pipe.prompt(timeout=1):
- child_exit = True
- break
-
- time_elapse += 1
-
- if not child_exit:
- try:
- # Stop Tcpdump on the target server
- tcpdump_quit_session=pxssh.pxssh()
- tcpdump_quit_session.login(server=target[0], username=target[1],
- password=target[2], original_prompt='[$#>]',
- login_timeout=20)
- tcpdump_quit_session.sendline('kill -2 $(pidof tcpdump)')
- tcpdump_quit_session.prompt()
- tcpdump_quit_session.logout()
- child_exit = True
- except pxssh.ExceptionPxssh as e:
- print ('pxssh failed on login.')
- print (e)
-
- # Close the Tcpdump_session
- pipe.prompt()
- pipe.logout()
-
- # wait pcap file ready
- time.sleep(1)
- return "/tmp/sniff_%s.pcap" % intf
-
- return ""
-
-
-def load_pcapfile(filename=""):
- pkts = []
- try:
- cap_pkts = rdpcap(filename)
- for pkt in cap_pkts:
- # packet gen should be scapy
- packet = Packet()
- packet.pktgen.assign_pkt(pkt)
- pkts.append(packet)
- except:
- pass
-
- return pkts
+ pipe, intf, filename = SNIFF_PIDS.pop(index)
+ pipe.get_session_before(timeout)
+ pipe.send_command('^C')
+ pipe.copy_file_from(filename, TMP_PATH)
+ p = Packet()
+ p.read_pcapfile(TMP_PATH + filename.split(os.sep)[-1])
+ pipe.close()
+ return p
def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
@@ -940,8 +978,8 @@ def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
elif layer == "L4":
l_idx = 2
try:
- load1 = hexstr(str(pkt1.pktgen.pkt.getlayer(l_idx)))
- load2 = hexstr(str(pkt2.pktgen.pkt.getlayer(l_idx)))
+ load1 = hexstr(str(pkt1.getlayer(l_idx)))
+ load2 = hexstr(str(pkt2.getlayer(l_idx)))
except:
# return pass when scapy failed to extract packet
return True
@@ -952,7 +990,7 @@ def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
return False
-def strip_pktload(pkt=None, layer="L2"):
+def strip_pktload(pkt=None, layer="L2", p_index=0):
if layer == "L2":
l_idx = 0
elif layer == "L3":
@@ -962,30 +1000,36 @@ def strip_pktload(pkt=None, layer="L2"):
else:
l_idx = 0
try:
- load = hexstr(str(pkt.pktgen.pkt.getlayer(l_idx)), onlyhex=1)
+ load = hexstr(str(pkt.pktgen.pkts[p_index].getlayer(l_idx)), onlyhex=1)
except:
# return pass when scapy failed to extract packet
load = ""
return load
+
###############################################################################
###############################################################################
if __name__ == "__main__":
- pkt = Packet(pkt_type='UDP')
- pkt.send_pkt(tx_port='lo')
+
+ pkt = Packet('Ether(type=0x894f)/NSH(Len=0x6,NextProto=0x0,NSP=0x000002,NSI=0xff)')
+ sendp(pkt, iface='lo')
+ pkt.config_layer('ipv4', {'dst': '192.168.8.8'})
+ pkt.append_pkt(pkt_type='IPv6_TCP', pkt_len=100)
+ pkt.append_pkt(pkt_type='TCP', pkt_len=100)
+ pkt.config_layer('tcp', config={'flags': 'A'})
+ pkt.append_pkt("Ether(dst='11:22:33:44:55:11')/IP(dst='192.168.5.2')/TCP(flags=0)/Raw(load='bbbb')")
+ pkt.generate_random_pkts('11:22:33:44:55:55', random_type=['TCP', 'IPv6_TCP'], random_payload=True, pktnum=10)
+ sendp(pkt, iface='lo')
pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
- pkt.send_pkt(tx_port='lo')
- pkt = Packet(pkt_type='IPv6_TCP')
- pkt.send_pkt(tx_port='lo')
+ sendp(pkt, iface='lo')
pkt = Packet(pkt_type='IPv6_SCTP')
- pkt.send_pkt(tx_port='lo')
+ sendp(pkt, iface='lo')
pkt = Packet(pkt_type='VLAN_UDP')
pkt.config_layer('vlan', {'vlan': 2})
- pkt.send_pkt(tx_port='lo')
+ sendp(pkt, iface='lo')
- pkt = Packet()
pkt.assign_layers(['ether', 'vlan', 'ipv4', 'udp',
'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
pkt.config_layer('ether', {'dst': '00:11:22:33:44:55'})
@@ -994,13 +1038,12 @@ if __name__ == "__main__":
pkt.config_layer('udp', {'src': 4789, 'dst': 4789, 'chksum': 0x1111})
pkt.config_layer('vxlan', {'vni': 2})
pkt.config_layer('raw', {'payload': ['58'] * 18})
- pkt.send_pkt(tx_port='lo')
+ sendp(pkt, iface='lo')
- pkt = Packet()
pkt.assign_layers(['ether', 'vlan', 'ipv4', 'udp',
'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
# config packet
pkt.config_layers([('ether', {'dst': '00:11:22:33:44:55'}), ('ipv4', {'dst': '1.1.1.1'}),
('vxlan', {'vni': 2}), ('raw', {'payload': ['01'] * 18})])
- pkt.send_pkt(tx_port='lo')
+ sendp(pkt, iface='lo')
--
2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dts] [PATCH V1] framework/packet: update packet module of dts
2019-09-27 18:05 ` [dts] [PATCH V1] framework/packet: update packet module of dts Qimai Xiao
@ 2019-10-08 2:22 ` Chen, Zhaoyan
2019-10-12 5:30 ` Tu, Lijuan
1 sibling, 0 replies; 9+ messages in thread
From: Chen, Zhaoyan @ 2019-10-08 2:22 UTC (permalink / raw)
To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX, Chen, Zhaoyan
Acked-by: Chen, Zhaoyan <zhaoyan.chen@intel.com>
Regards,
Zhaoyan Chen
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Qimai Xiao
> Sent: Saturday, September 28, 2019 2:06 AM
> To: dts@dpdk.org
> Cc: Xiao, QimaiX <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] framework/packet: update packet module of dts
>
> update API of packet and some other optimization
>
> Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
> ---
> framework/packet.py | 665 +++++++++++++++++++++++---------------------
> 1 file changed, 354 insertions(+), 311 deletions(-)
>
> diff --git a/framework/packet.py b/framework/packet.py index 502d85c..05b2367
> 100755
> --- a/framework/packet.py
> +++ b/framework/packet.py
> @@ -33,35 +33,19 @@
> Generic packet create, transmit and analyze module Base on scapy(python program
> for packet manipulation) """
> -import os
> -import time
> -import sys
> -import re
> -import signal
> -import random
> -import subprocess
> -import shlex # separate command line for pipe
> -from uuid import uuid4
> -from settings import FOLDERS
> -
> -import struct
> +
> from socket import AF_INET6
> -from scapy.all import conf
> -from scapy.utils import wrpcap, rdpcap, hexstr -from scapy.layers.inet import Ether,
> IP, TCP, UDP, ICMP -from scapy.layers.inet6 import IPv6, IPv6ExtHdrRouting,
> IPv6ExtHdrFragment -from scapy.layers.l2 import Dot1Q, ARP, GRE
> +from scapy.all import *
> from scapy.layers.sctp import SCTP, SCTPChunkData -from scapy.sendrecv import
> sniff -from scapy.route import * -from scapy.packet import bind_layers, Raw -from
> scapy.sendrecv import sendp -from scapy.arch import get_if_hwaddr -from pexpect
> import pxssh
>
> # load extension layers
> exec_file = os.path.realpath(__file__)
> DTS_PATH = exec_file.replace('/framework/packet.py', '')
> +# exec_file might be .pyc file, if so, remove 'c'.
> +TMP_PATH = DTS_PATH[:-1] + '/output/tmp/pcap/' if exec_file.endswith('.pyc')
> else DTS_PATH + '/output/tmp/pcap/'
> +
> +if not os.path.exists(TMP_PATH):
> + os.system('mkdir -p %s' % TMP_PATH)
> DEP_FOLDER = DTS_PATH + '/dep'
> sys.path.append(DEP_FOLDER)
>
> @@ -70,9 +54,8 @@ from nvgre import NVGRE, IPPROTO_NVGRE from lldp import
> LLDP, LLDPManagementAddress from Dot1BR import Dot1BR
>
> -# get tester logger
> -from logger import getLogger
> -logger = getLogger('tester')
> +from utils import convert_ip2int
> +from utils import convert_int2ip
>
> # for saving command history
> from utils import get_backtrace_object
> @@ -150,7 +133,16 @@ class scapy(object):
>
> def __init__(self):
> self.pkt = None
> - pass
> + self.pkts = []
> +
> + def append_pkts(self):
> + self.pkts.append(self.pkt)
> +
> + def update_pkts(self):
> + if not self.pkts: # update pkt to a null pkt list.
> + self.pkts.append(self.pkt)
> + else:
> + self.pkts[-1] = self.pkt
>
> def assign_pkt(self, pkt):
> self.pkt = pkt
> @@ -179,14 +171,14 @@ class scapy(object):
> if type is not None:
> pkt_layer.type = type
>
> - def strip_vlan(self, element):
> + def strip_vlan(self, element, p_index=0):
> value = None
>
> - if self.pkt.haslayer('Dot1Q') is 0:
> + if self.pkts[p_index].haslayer('Dot1Q') is 0:
> return None
>
> if element == 'vlan':
> - value = int(str(self.pkt[Dot1Q].vlan))
> + value = int(str(self.pkts[p_index][Dot1Q].vlan))
> return value
>
> def etag(self, pkt_layer, ECIDbase=0, prio=0, type=None):
> @@ -197,19 +189,19 @@ class scapy(object):
> if type is not None:
> pkt_layer.type = type
>
> - def strip_etag(self, element):
> + def strip_etag(self, element, p_index=0):
> value = None
>
> - if self.pkt.haslayer('Dot1BR') is 0:
> + if self.pkts[p_index].haslayer('Dot1BR') is 0:
> return None
>
> if element == 'ECIDbase':
> - value = int(str(self.pkt[Dot1BR].ECIDbase))
> + value = int(str(self.pkts[p_index][Dot1BR].ECIDbase))
> return value
>
> - def strip_layer2(self, element):
> + def strip_layer2(self, element, p_index=0):
> value = None
> - layer = self.pkt.getlayer(0)
> + layer = self.pkts[p_index].getlayer(0)
> if layer is None:
> return None
>
> @@ -222,9 +214,9 @@ class scapy(object):
>
> return value
>
> - def strip_layer3(self, element):
> + def strip_layer3(self, element, p_index=0):
> value = None
> - layer = self.pkt.getlayer(1)
> + layer = self.pkts[p_index].getlayer(1)
> if layer is None:
> return None
>
> @@ -237,9 +229,9 @@ class scapy(object):
>
> return value
>
> - def strip_layer4(self, element):
> + def strip_layer4(self, element, p_index=0):
> value = None
> - layer = self.pkt.getlayer(2)
> + layer = self.pkts[p_index].getlayer(2)
> if layer is None:
> return None
>
> @@ -252,7 +244,8 @@ class scapy(object):
>
> return value
>
> - def ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0,
> dst="127.0.0.1", chksum=None, len=None, version=4, flags=None, ihl=None, ttl=64,
> id=1, options=None):
> + def ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0,
> dst="127.0.0.1", chksum=None, len=None,
> + version=4, flags=None, ihl=None, ttl=64, id=1, options=None):
> pkt_layer.frag = frag
> pkt_layer.src = src
> if proto is not None:
> @@ -287,7 +280,7 @@ class scapy(object):
> pkt_layer.src = src
> pkt_layer.dst = dst
>
> - def tcp(self, pkt_layer, src=53, dst=53, flags=None, len=None, chksum=None):
> + def tcp(self, pkt_layer, src=53, dst=53, flags=0, len=None, chksum=None):
> pkt_layer.sport = src
> pkt_layer.dport = dst
> if flags is not None:
> @@ -328,66 +321,6 @@ class scapy(object):
> def vxlan(self, pkt_layer, vni=0):
> pkt_layer.vni = vni
>
> - def read_pcap(self, file):
> - pcap_pkts = []
> - try:
> - pcap_pkts = rdpcap(file)
> - except:
> - pass
> -
> - return pcap_pkts
> -
> - def write_pcap(self, file):
> - try:
> - wrpcap(file, self.pkt)
> - except:
> - pass
> -
> - def send_pcap_pkt(self, crb=None, file='', intf='', count=1):
> - if intf == '' or file == '' or crb is None:
> - print "Invalid option for send packet by scapy"
> - return
> -
> - content = 'pkts=rdpcap(\"%s\");sendp(pkts, iface=\"%s\",
> count=\"%s\" );exit()' % (file, intf, count)
> - cmd_file = '/tmp/scapy_%s.cmd' % intf
> -
> - crb.create_file(content, cmd_file)
> - crb.send_expect("scapy -c scapy_%s.cmd &" % intf, "# ")
> -
> - def print_summary(self):
> - # save command into test case history
> - history_list = get_backtrace_object('test_case.py', 'test_history')
> - if type(history_list) is list:
> - history_list.append({"command": "p=%s" % self.pkt.command(), "name":
> "Scapy", "output": ""})
> -
> - logger.info("%s" % self.pkt.command())
> -
> - def send_pkt(self, intf='', count=1):
> - self.print_summary()
> -
> - if intf != '':
> - # wait few seconds for link ready
> - countdown = 600
> - while countdown:
> - link_st = subprocess.check_output("ip link show %s" % intf,
> - stderr=subprocess.STDOUT,
> - shell=True)
> - if "LOWER_UP" in link_st:
> - break
> - else:
> - time.sleep(0.01)
> - countdown -= 1
> - continue
> -
> - # fix fortville can't receive packets with 00:00:00:00:00:00
> - if self.pkt.getlayer(0).src == "00:00:00:00:00:00":
> - self.pkt.getlayer(0).src = get_if_hwaddr(intf)
> - sendp(self.pkt, iface=intf, count=count)
> -
> - # save command into test case history
> - history_list = get_backtrace_object('test_case.py', 'test_history')
> - if type(history_list) is list:
> - history_list.append({"command": "sendp(p, iface=\"%s\")" % intf, "name":
> "Scapy", "output": ""})
>
> class Packet(object):
>
> @@ -413,10 +346,11 @@ class Packet(object):
> 'IPv6_SCTP': {'layers': ['ether', 'ipv6', 'sctp', 'raw'], 'cfgload': True},
> }
>
> - def __init__(self, **options):
> + def __init__(self, pkt_str=None, **options):
> """
> pkt_type: description of packet type
> defined in def_packet
> + args: specify a packet with a string explicitly, will ignore
> + options
> options: special option for Packet module
> pkt_len: length of network packet
> ran_payload: whether payload of packet is random @@ -424,14 +358,41
> @@ class Packet(object):
> pkt_gen: packet generator type
> now only support scapy
> """
> - self.pkt_layers = []
> - self.pkt_len = 64
> self.pkt_opts = options
> + self.pkt_layers = []
>
> - self.pkt_type = "UDP"
> + if 'pkt_gen' in self.pkt_opts.keys():
> + if self.pkt_opts['pkt_gen'] == 'scapy':
> + self.pktgen = scapy()
> + else:
> + print "Not support other pktgen yet!!!"
> + else:
> + self.pktgen = scapy()
>
> - if 'pkt_type' in self.pkt_opts.keys():
> - self.pkt_type = self.pkt_opts['pkt_type']
> + if pkt_str is not None and type(pkt_str) == str:
> + self._scapy_str_to_pkt(pkt_str)
> + elif len(options) == 0:
> + pass
> + else:
> + self._add_pkt(self.pkt_opts)
> + if self.pktgen.pkt is not None:
> + self.pktgen.append_pkts()
> +
> + def __len__(self):
> + return len(self.pktgen.pkts)
> +
> + def __getitem__(self, item):
> + return self.pktgen.pkts[item]
> +
> + def _add_pkt(self, options):
> + """
> + :param options: packt configuration, dictionary type
> + :return:
> + """
> + self.pkt_len = 64
> + self.pkt_type = "UDP"
> + if 'pkt_type' in options.keys():
> + self.pkt_type = options['pkt_type']
>
> if self.pkt_type in self.def_packet.keys():
> self.pkt_layers = self.def_packet[self.pkt_type]['layers']
> @@ -441,21 +402,8 @@ class Packet(object):
> else:
> self._load_pkt_layers()
>
> - if 'pkt_len' in self.pkt_opts.keys():
> - self.pkt_len = self.pkt_opts['pkt_len']
> -
> - if 'pkt_file' in self.pkt_opts.keys():
> - self.uni_name = self.pkt_opts['pkt_file']
> - else:
> - self.uni_name = '/tmp/' + str(uuid4()) + '.pcap'
> -
> - if 'pkt_gen' in self.pkt_opts.keys():
> - if self.pkt_opts['pkt_gen'] == 'scapy':
> - self.pktgen = scapy()
> - else:
> - print "Not support other pktgen yet!!!"
> - else:
> - self.pktgen = scapy()
> + if 'pkt_len' in options.keys():
> + self.pkt_len = options['pkt_len']
>
> self._load_assign_layers()
>
> @@ -483,32 +431,227 @@ class Packet(object):
> raw_confs['payload'] = payload
> self.config_layer('raw', raw_confs)
>
> - def send_pkt(self, crb=None, tx_port='', auto_cfg=True, count=1):
> - if tx_port == '':
> - print "Invalid Tx interface"
> - return
> + def _scapy_str_to_pkt(self, scapy_str):
> + """
>
> - self.tx_port = tx_port
> + :param scapy_str: packet str, eg. 'Ether()/IP()/UDP()'
> + :return: None
> + """
> + layer_li = [re.sub('\(.*?\)', '', i) for i in scapy_str.split('/')]
> + self.pkt_type = '_'.join(layer_li)
> + self._load_pkt_layers()
> + pkt = eval(scapy_str)
> + self.pktgen.assign_pkt(pkt)
>
> - # check with port type
> - if 'ixia' in self.tx_port:
> - print "Not Support Yet"
> + def append_pkt(self, args=None, **kwargs):
> + """
> + :param args: take str type as pkt to append
> + :param kwargs: take dictory type as pkt to append
> + :return: None
> + """
> + if isinstance(args, str):
> + self._scapy_str_to_pkt(args)
> + elif isinstance(kwargs, dict):
> + self.pkt_opts = kwargs
> + if hasattr(self, 'configured_layer_raw'):
> + delattr(self, 'configured_layer_raw')
> + self._add_pkt(kwargs)
> + self.pktgen.append_pkts()
> +
> + def generate_random_pkts(self, dstmac=None, pktnum=100, random_type=None,
> ip_increase=True, random_payload=False,
> + options=None):
> + """
> + # generate random packets
> + :param dstmac: specify the dst mac
> + :param pktnum: packet number to generate
> + :param random_type: specify random packet type
> + :param ip_increase: auto increase ip value
> + :param random_payload: if True, generate random packets with random
> payload
> + :param options: packet layer configuration
> + :return: None
> + """
>
> - if crb is not None:
> - self.pktgen.write_pcap(self.uni_name)
> - crb.session.copy_file_to(self.uni_name)
> - pcap_file = self.uni_name.split('/')[2]
> - self.pktgen.send_pcap_pkt(
> - crb=crb, file=pcap_file, intf=self.tx_port, count=count)
> + random_type = ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP'] if random_type is None
> else random_type
> + options = {'ip': {'src': '192.168.0.1', 'dst': '192.168.1.1'},
> + 'layers_config': []} if options is None else options
> + # give a default value to ip
> + try:
> + src_ip_num = convert_ip2int(options['ip']['src'])
> + except:
> + src_ip_num = 0
> + try:
> + dst_ip_num = convert_ip2int(options['ip']['dst'])
> + except:
> + dst_ip_num = 0
> +
> + for i in range(pktnum):
> + # random the packet type
> + self.pkt_type = random.choice(random_type)
> + self.pkt_layers = self.def_packet[self.pkt_type]['layers']
> + self.check_layer_config()
> + self.pktgen.add_layers(self.pkt_layers)
> + # hardcode src/dst port for some protocol may cause issue
> + if "TCP" in self.pkt_type:
> + self.config_layer('tcp', {'src': 65535, 'dst': 65535})
> + if "UDP" in self.pkt_type:
> + self.config_layer('udp', {'src': 65535, 'dst': 65535})
> + if options.has_key('layers_config'):
> + self.config_layers(options['layers_config'])
> + if dstmac:
> + self.config_layer('ether', {'dst': '%s' % dstmac})
> + # generate auto increase dst ip packet
> + if ip_increase:
> + if 'v6' in self.pkt_type:
> + dstip = convert_int2ip(dst_ip_num, ip_type=6)
> + srcip = convert_int2ip(src_ip_num, ip_type=6)
> + self.config_layer('ipv6', config={'dst': '%s' % (dstip), 'src': '%s' % srcip})
> + else:
> + dstip = convert_int2ip(dst_ip_num, ip_type=4)
> + srcip = convert_int2ip(src_ip_num, ip_type=4)
> + self.config_layer('ipv4', config={'dst': '%s' % (dstip), 'src': '%s' % srcip})
> + dst_ip_num += 1
> + # generate random payload of packet
> + if random_payload and self.def_packet[self.pkt_type]['cfgload']:
> + # TCP packet has a default flags S, packet should not load data, so set it to A
> if has payload
> + if 'TCP' in self.pkt_type:
> + self.config_layer('tcp', {'src': 65535, 'dst':
> + 65535, 'flags': 'A'})
> +
> + payload_len = random.randint(64, 100)
> + payload = []
> + for _ in range(payload_len):
> + payload.append("%02x" % random.randrange(0, 255))
> + self.config_layer('raw', config={'payload': payload})
> + self.pktgen.append_pkts()
> +
> + def save_pcapfile(self, crb=None, filename='saved_pkts.pcap'):
> + """
> +
> + :param crb: session or crb object
> + :param filename: location and name for packets to be saved
> + :return: None
> + """
> + # save pkts to pcap file to local path, then copy to remote tester tmp directory,
> + if crb:
> + trans_path = crb.tmp_file
> + file_name = filename
> + if os.path.isabs(filename): # check if the given filename with a abs path
> + file_dir = os.path.dirname(filename)
> + out = crb.send_expect('ls -d %s' % file_dir, '# ', verify=True)
> + if not isinstance(out, str):
> + raise Exception('%s may not existed on %s' % (file_dir, crb.name))
> + wrpcap(filename, self.pktgen.pkts)
> + trans_path = os.path.abspath(filename)
> + file_name = filename.split(os.path.sep)[-1]
> + # write packets to local tmp path $dts/ouput/tmp/pcap/
> + wrpcap(TMP_PATH + file_name, self.pktgen.pkts)
> + # copy to remote tester tmp path /tmp/tester
> + crb.session.copy_file_to(TMP_PATH + file_name, trans_path)
> else:
> - self.pktgen.send_pkt(intf=self.tx_port, count=count)
> + wrpcap(filename, self.pktgen.pkts)
>
> - def check_layer_config(self, layer, config):
> + def read_pcapfile(self, filename, crb=None):
> + """
> +
> + :param filename: packet to be read from
> + :param crb: session or crb object
> + :return: scapy type packet
> + """
> + # read pcap file from local or remote, then append to pkts list
> + # if crb, read pakcet from remote server, else read from local location
> + if crb:
> + out = crb.send_expect('ls -d %s' % filename, '# ', verify=True)
> + if not isinstance(out, str):
> + raise Exception('%s may not existed on %s' % (filename, crb.name))
> + crb.session.copy_file_from(filename, TMP_PATH)
> + p = rdpcap(TMP_PATH + filename.split(os.path.sep)[-1])
> + else:
> + p = rdpcap(filename)
> + if len(p) == 0:
> + return None
> + self.pktgen.assign_pkt(p[-1])
> + for i in p:
> + self.pktgen.pkts.append(i)
> + return p
> +
> + def _send_pkt(self, crb, tx_port='', count=1, send_bg=False, loop=0, inter=0,
> timeout=15):
> + """
> +
> + :param crb: session or crb object
> + :param tx_port: ether to send packet
> + :param count: send times
> + :param send_bg: send packet background
> + :param loop: send packet in a loop
> + :param inter: interval time
> + :return: None
> + """
> + # save pkts to local pcap file, then copy to remote tester tmp
> + directory
> +
> + time_stamp = str(time.time())
> + pcap_file = 'scapy_{}.pcap'.format(tx_port) + time_stamp
> + self.save_pcapfile(crb, pcap_file)
> + scapy_cmd = 'scapy_{}.cmd'.format(tx_port) + time_stamp
> + cmd_str = 'from scapy.all import *\np=rdpcap("%s")\nprint("packet ready for
> sending...")\nfor i in p:\n\tprint(i.command())\nsendp(p, iface="%s", count=%d,
> loop=%d, inter=%0.3f)' % (
> + crb.tmp_file + pcap_file, tx_port, count, loop, inter)
> + # write send cmd file to local tmp directory then copy to remote tester tmp
> folder
> + with open(TMP_PATH + scapy_cmd, 'w') as f:
> + f.write(cmd_str)
> + crb.session.copy_file_to(TMP_PATH + scapy_cmd, crb.tmp_file)
> +
> + if send_bg: # if send_bg create a new session to execute send action
> + session_prefix = 'scapy_bg_session'
> + scapy_session = crb.create_session(session_prefix + time_stamp)
> + scapy_session.send_command('python %s' % crb.tmp_file + scapy_cmd)
> + else:
> + crb.send_expect('python %s' % crb.tmp_file + scapy_cmd, '# ',
> timeout=timeout)
> + return crb.tmp_file + scapy_cmd
> +
> + def send_pkt(self, crb, tx_port='', count=1, interval=0, timeout=15):
> + self._send_pkt(crb, tx_port, count, inter=interval,
> + timeout=timeout)
> +
> + def send_pkt_bg(self, crb, tx_port='', count=-1, loop=1, interval=0, timeout=3):
> + return self._send_pkt(crb, tx_port=tx_port, count=count, send_bg=True,
> loop=loop, inter=interval,
> + timeout=timeout)
> +
> + def stop_send_pkt_bg(self, crb, filenames):
> + # stop sending action
> + pids = []
> + if isinstance(filenames, list):
> + for file in filenames:
> + out = crb.send_expect('ps -ef |grep %s|grep -v grep' % file, expected='# ')
> + try:
> + pids.append(re.search('\d+', out).group())
> + except AttributeError as e:
> + print(e, ' :%s not killed' % file)
> + else:
> + out = crb.send_expect('ps -ef |grep %s|grep -v grep' % filenames, expected='#
> ')
> + try:
> + pids.append(re.search('\d+', out).group())
> + except AttributeError as e:
> + print(e, ' :%s not killed' % filenames)
> + pid = ' '.join(pids)
> + if pid:
> + crb.send_expect('kill -9 %s' % pid, expected='# ')
> + for i in crb.sessions:
> + if i.name.startswith('scapy_bg_session'):
> + crb.destroy_session(i)
> +
> + def check_layer_config(self):
> """
> check the format of layer configuration
> every layer should has different check function
> """
> - pass
> + for layer in self.pkt_layers:
> + found = False
> + l_type = layer.lower()
> +
> + for types in LayersTypes.values():
> + if l_type in types:
> + found = True
> + break
> +
> + if found is False:
> + self.pkt_layers.remove(l_type)
> + print "INVAILD LAYER TYPE [%s]" % l_type.upper()
>
> def assign_layers(self, layers=None):
> """
> @@ -532,6 +675,8 @@ class Packet(object):
> print "INVAILD LAYER TYPE [%s]" % l_type.upper()
>
> self.pktgen.add_layers(self.pkt_layers)
> + if layers:
> + self.pktgen.update_pkts()
>
> def _load_pkt_layers(self):
> name2type = {
> @@ -590,9 +735,9 @@ class Packet(object):
> else:
> self.config_layer('raw', {'payload': ['00'] * 18})
>
> - if "MAC_IP_IPv6" in self.pkt_type or\
> - "MAC_IP_NVGRE" in self.pkt_type or \
> - "MAC_IP_UDP_VXLAN" in self.pkt_type:
> + if "MAC_IP_IPv6" in self.pkt_type or \
> + "MAC_IP_NVGRE" in self.pkt_type or \
> + "MAC_IP_UDP_VXLAN" in self.pkt_type:
> if "IPv6_SCTP" in self.pkt_type:
> self.config_layer('ipv6', {'nh': 132})
> if "IPv6_ICMP" in self.pkt_type:
> @@ -601,6 +746,8 @@ class Packet(object):
> self.config_layer('raw', {'payload': ['00'] * 40})
> else:
> self.config_layer('raw', {'payload': ['00'] * 18})
> + if 'TCP' in self.pkt_type:
> + self.config_layer('tcp', {'flags': 0})
>
> def config_layer(self, layer, config={}):
> """
> @@ -613,22 +760,23 @@ class Packet(object):
> print "INVALID LAYER ID %s" % layer
> return False
>
> - if self.check_layer_config(layer, config) is False:
> + if self.check_layer_config() is False:
> return False
>
> if 'inner' in layer:
> layer = layer[6:]
>
> pkt_layer = self.pktgen.pkt.getlayer(idx)
> - layer_conf = getattr(self, "_config_layer_%s" % layer)
> + layer_conf = getattr(self.pktgen, layer)
> setattr(self, 'configured_layer_%s' % layer, True)
>
> - return layer_conf(pkt_layer, config)
> + layer_conf(pkt_layer, **config)
>
> def config_layers(self, layers=None):
> """
> Configure packet with multi configurations
> """
> + layers = [] if layers is None else layers # None object is not
> + Iterable
> for layer in layers:
> name, config = layer
> if name not in self.pkt_layers:
> @@ -638,65 +786,28 @@ class Packet(object):
> print "[%s] failed to configure!!!" % name
> raise
>
> - def _config_layer_ether(self, pkt_layer, config):
> - return self.pktgen.ether(pkt_layer, **config)
> -
> - def _config_layer_mac(self, pkt_layer, config):
> - return self.pktgen.ether(pkt_layer, **config)
> -
> - def _config_layer_vlan(self, pkt_layer, config):
> - return self.pktgen.vlan(pkt_layer, **config)
> -
> - def _config_layer_etag(self, pkt_layer, config):
> - return self.pktgen.etag(pkt_layer, **config)
> -
> - def _config_layer_ipv4(self, pkt_layer, config):
> - return self.pktgen.ipv4(pkt_layer, **config)
> -
> - def _config_layer_ipv6(self, pkt_layer, config):
> - return self.pktgen.ipv6(pkt_layer, **config)
> -
> - def _config_layer_udp(self, pkt_layer, config):
> - return self.pktgen.udp(pkt_layer, **config)
> -
> - def _config_layer_tcp(self, pkt_layer, config):
> - return self.pktgen.tcp(pkt_layer, **config)
> -
> - def _config_layer_sctp(self, pkt_layer, config):
> - return self.pktgen.sctp(pkt_layer, **config)
> -
> - def _config_layer_gre(self, pkt_layer, config):
> - return self.pktgen.gre(pkt_layer, **config)
> -
> - def _config_layer_raw(self, pkt_layer, config):
> - return self.pktgen.raw(pkt_layer, **config)
> -
> - def _config_layer_vxlan(self, pkt_layer, config):
> - return self.pktgen.vxlan(pkt_layer, **config)
> -
> - def strip_layer_element(self, layer, element):
> + def strip_layer_element(self, layer, element, p_index=0):
> """
> Strip packet layer elements
> return the status of configure result
> """
> strip_element = getattr(self, "strip_element_%s" % layer)
> + return strip_element(element, p_index)
>
> - return strip_element(element)
> -
> - def strip_element_layer2(self, element):
> - return self.pktgen.strip_layer2(element)
> + def strip_element_layer2(self, element, p_index=0):
> + return self.pktgen.strip_layer2(element, p_index)
>
> - def strip_element_layer3(self, element):
> - return self.pktgen.strip_layer3(element)
> + def strip_element_layer3(self, element, p_index=0):
> + return self.pktgen.strip_layer3(element, p_index)
>
> - def strip_element_vlan(self, element):
> - return self.pktgen.strip_vlan(element)
> + def strip_element_vlan(self, element, p_index=0):
> + return self.pktgen.strip_vlan(element, p_index)
>
> - def strip_element_etag(self, element):
> - return self.pktgen.strip_etag(element)
> + def strip_element_etag(self, element, p_index=0):
> + return self.pktgen.strip_etag(element, p_index)
>
> - def strip_element_layer4(self, element):
> - return self.pktgen.strip_layer4(element)
> + def strip_element_layer4(self, element, p_index=0):
> + return self.pktgen.strip_layer4(element, p_index)
>
>
> def IncreaseIP(addr):
> @@ -725,27 +836,6 @@ def IncreaseIPv6(addr):
> return ipv6
>
>
> -def send_packets(intf, pkts=None, interval=0.01):
> - send_pkts = []
> - try:
> - for pkt in pkts:
> - send_pkts.append(pkt.pktgen.pkt)
> - sendp(send_pkts, iface=intf, inter=interval, verbose=False)
> - except:
> - pass
> -
> -
> -def save_packets(pkts=None, filename=None):
> - save_pkts = []
> - try:
> - for pkt in pkts:
> - save_pkts.append(pkt.pktgen.pkt)
> - if filename:
> - wrpcap(filename, save_pkts)
> - except:
> - pass
> -
> -
> def get_ether_type(eth_type=""):
> # need add more types later
> if eth_type.lower() == "lldp":
> @@ -809,48 +899,46 @@ def get_filter_cmd(filters=[]):
> return ""
>
>
> -def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> +def start_tcpdump(crb, intf, count=0, filters=None, lldp_forbid=True):
> """
> - sniff all packets for certain port in certain seconds
> + sniff all packets from certain port
> """
> + filters = [] if filters is None else filters
> + out = crb.send_expect("ls -d %s" % crb.tmp_file, "# ", verify=True)
> + if out == 2:
> + crb.send_expect("mkdir -p %s" % crb.tmp_file, "# ")
> + filename = '{}sniff_{}.pcap'.format(crb.tmp_file, intf)
> + # delete old pcap file
> + crb.send_expect('rm -rf %s' % filename, '# ')
> +
> param = ""
> direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> -
> - try:
> - tcpdump_help_session=pxssh.pxssh()
> - tcpdump_help_session.login(server=target[0], username=target[1],
> - password=target[2], original_prompt='[$#>]',
> - login_timeout=20)
> - tcpdump_help_session.sendline('tcpdump -h')
> - tcpdump_help_session.prompt()
> - tcpdump_help=tcpdump_help_session.before
> - tcpdump_help_session.logout()
> - except pxssh.ExceptionPxssh as e:
> - print ('pxssh failed on login.')
> - print (e)
> + tcpdump_session = crb.create_session('tcpdump_session' + str(time.time()))
> + setattr(tcpdump_session, 'tmp_file', crb.tmp_file)
> + tcpdump_help = tcpdump_session.send_command('tcpdump -h')
>
> for line in tcpdump_help.split('\n'):
> m = re.match(direct_param, line)
> if m:
> - opt = re.search("-Q", m.group(2));
> + opt = re.search("-Q", m.group(2))
> if opt:
> param = "-Q" + " in"
> else:
> - opt = re.search("-P", m.group(2));
> + opt = re.search("-P", m.group(2))
> if opt:
> param = "-P" + " in"
>
> if len(param) == 0:
> print "tcpdump not support direction choice!!!"
>
> - if LLDP_FILTER not in filters:
> + if lldp_forbid and (LLDP_FILTER not in filters):
> filters.append(LLDP_FILTER)
>
> filter_cmd = get_filter_cmd(filters)
>
> sniff_cmd = 'tcpdump -i %(INTF)s %(FILTER)s %(IN_PARAM)s -w %(FILE)s'
> options = {'INTF': intf, 'COUNT': count, 'IN_PARAM': param,
> - 'FILE': '/tmp/sniff_%s.pcap' % intf,
> + 'FILE': filename,
> 'FILTER': filter_cmd}
> if count:
> sniff_cmd += ' -c %(COUNT)d'
> @@ -858,77 +946,27 @@ def sniff_packets(intf, count=0, timeout=5, filters=[],
> target=[]):
> else:
> cmd = sniff_cmd % options
>
> - try:
> - tcpdump_session=pxssh.pxssh()
> - tcpdump_session.login(server=target[0], username=target[1],
> - password=target[2], original_prompt='[$#>]',
> - login_timeout=20)
> - tcpdump_session.sendline(cmd)
> - pipe = tcpdump_session
> - except pxssh.ExceptionPxssh as e:
> - print ('pxssh failed on login.')
> - print (e)
> + tcpdump_session.send_command(cmd)
>
> index = str(time.time())
> - SNIFF_PIDS[index] = (pipe, intf, timeout)
> + SNIFF_PIDS[index] = (tcpdump_session, intf, filename)
> time.sleep(1)
> return index
>
>
> -def load_sniff_pcap(index='', target=[]):
> +def stop_and_load_tcpdump_packets(index='', timeout=1):
> """
> - Stop sniffer and return pcap file
> + Stop sniffer and return packet object
> """
> - child_exit = False
> if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> - time_elapse = int(time.time() - float(index))
> - while time_elapse < timeout:
> - if pipe.prompt(timeout=1):
> - child_exit = True
> - break
> -
> - time_elapse += 1
> -
> - if not child_exit:
> - try:
> - # Stop Tcpdump on the target server
> - tcpdump_quit_session=pxssh.pxssh()
> - tcpdump_quit_session.login(server=target[0], username=target[1],
> - password=target[2], original_prompt='[$#>]',
> - login_timeout=20)
> - tcpdump_quit_session.sendline('kill -2 $(pidof tcpdump)')
> - tcpdump_quit_session.prompt()
> - tcpdump_quit_session.logout()
> - child_exit = True
> - except pxssh.ExceptionPxssh as e:
> - print ('pxssh failed on login.')
> - print (e)
> -
> - # Close the Tcpdump_session
> - pipe.prompt()
> - pipe.logout()
> -
> - # wait pcap file ready
> - time.sleep(1)
> - return "/tmp/sniff_%s.pcap" % intf
> -
> - return ""
> -
> -
> -def load_pcapfile(filename=""):
> - pkts = []
> - try:
> - cap_pkts = rdpcap(filename)
> - for pkt in cap_pkts:
> - # packet gen should be scapy
> - packet = Packet()
> - packet.pktgen.assign_pkt(pkt)
> - pkts.append(packet)
> - except:
> - pass
> -
> - return pkts
> + pipe, intf, filename = SNIFF_PIDS.pop(index)
> + pipe.get_session_before(timeout)
> + pipe.send_command('^C')
> + pipe.copy_file_from(filename, TMP_PATH)
> + p = Packet()
> + p.read_pcapfile(TMP_PATH + filename.split(os.sep)[-1])
> + pipe.close()
> + return p
>
>
> def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
> @@ -940,8 +978,8 @@ def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
> elif layer == "L4":
> l_idx = 2
> try:
> - load1 = hexstr(str(pkt1.pktgen.pkt.getlayer(l_idx)))
> - load2 = hexstr(str(pkt2.pktgen.pkt.getlayer(l_idx)))
> + load1 = hexstr(str(pkt1.getlayer(l_idx)))
> + load2 = hexstr(str(pkt2.getlayer(l_idx)))
> except:
> # return pass when scapy failed to extract packet
> return True
> @@ -952,7 +990,7 @@ def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
> return False
>
>
> -def strip_pktload(pkt=None, layer="L2"):
> +def strip_pktload(pkt=None, layer="L2", p_index=0):
> if layer == "L2":
> l_idx = 0
> elif layer == "L3":
> @@ -962,30 +1000,36 @@ def strip_pktload(pkt=None, layer="L2"):
> else:
> l_idx = 0
> try:
> - load = hexstr(str(pkt.pktgen.pkt.getlayer(l_idx)), onlyhex=1)
> + load = hexstr(str(pkt.pktgen.pkts[p_index].getlayer(l_idx)),
> + onlyhex=1)
> except:
> # return pass when scapy failed to extract packet
> load = ""
>
> return load
>
> +
>
> ###########################################################
> ####################
>
> ###########################################################
> ####################
> if __name__ == "__main__":
> - pkt = Packet(pkt_type='UDP')
> - pkt.send_pkt(tx_port='lo')
> +
> + pkt =
> Packet('Ether(type=0x894f)/NSH(Len=0x6,NextProto=0x0,NSP=0x000002,NSI=0xff
> )')
> + sendp(pkt, iface='lo')
> + pkt.config_layer('ipv4', {'dst': '192.168.8.8'})
> + pkt.append_pkt(pkt_type='IPv6_TCP', pkt_len=100)
> + pkt.append_pkt(pkt_type='TCP', pkt_len=100)
> + pkt.config_layer('tcp', config={'flags': 'A'})
> +
> pkt.append_pkt("Ether(dst='11:22:33:44:55:11')/IP(dst='192.168.5.2')/TCP(flags=
> 0)/Raw(load='bbbb')")
> + pkt.generate_random_pkts('11:22:33:44:55:55', random_type=['TCP', 'IPv6_TCP'],
> random_payload=True, pktnum=10)
> + sendp(pkt, iface='lo')
>
> pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> - pkt.send_pkt(tx_port='lo')
> - pkt = Packet(pkt_type='IPv6_TCP')
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
> pkt = Packet(pkt_type='IPv6_SCTP')
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
> pkt = Packet(pkt_type='VLAN_UDP')
> pkt.config_layer('vlan', {'vlan': 2})
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
>
> - pkt = Packet()
> pkt.assign_layers(['ether', 'vlan', 'ipv4', 'udp',
> 'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
> pkt.config_layer('ether', {'dst': '00:11:22:33:44:55'}) @@ -994,13 +1038,12 @@ if
> __name__ == "__main__":
> pkt.config_layer('udp', {'src': 4789, 'dst': 4789, 'chksum': 0x1111})
> pkt.config_layer('vxlan', {'vni': 2})
> pkt.config_layer('raw', {'payload': ['58'] * 18})
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
>
> - pkt = Packet()
> pkt.assign_layers(['ether', 'vlan', 'ipv4', 'udp',
> 'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
> # config packet
> pkt.config_layers([('ether', {'dst': '00:11:22:33:44:55'}), ('ipv4', {'dst': '1.1.1.1'}),
> ('vxlan', {'vni': 2}), ('raw', {'payload': ['01'] * 18})])
>
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
> --
> 2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dts] [PATCH V1] framework/packet: update packet module of dts
2019-09-27 18:05 ` [dts] [PATCH V1] framework/packet: update packet module of dts Qimai Xiao
2019-10-08 2:22 ` Chen, Zhaoyan
@ 2019-10-12 5:30 ` Tu, Lijuan
1 sibling, 0 replies; 9+ messages in thread
From: Tu, Lijuan @ 2019-10-12 5:30 UTC (permalink / raw)
To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX
Applied, thanks
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Qimai Xiao
> Sent: Saturday, September 28, 2019 2:06 AM
> To: dts@dpdk.org
> Cc: Xiao, QimaiX <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] framework/packet: update packet module of dts
>
> update API of packet and some other optimization
>
> Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
> ---
> framework/packet.py | 665 +++++++++++++++++++++++---------------------
> 1 file changed, 354 insertions(+), 311 deletions(-)
>
> diff --git a/framework/packet.py b/framework/packet.py index
> 502d85c..05b2367 100755
> --- a/framework/packet.py
> +++ b/framework/packet.py
> @@ -33,35 +33,19 @@
> Generic packet create, transmit and analyze module Base on scapy(python
> program for packet manipulation) """
> -import os
> -import time
> -import sys
> -import re
> -import signal
> -import random
> -import subprocess
> -import shlex # separate command line for pipe
> -from uuid import uuid4
> -from settings import FOLDERS
> -
> -import struct
> +
> from socket import AF_INET6
> -from scapy.all import conf
> -from scapy.utils import wrpcap, rdpcap, hexstr -from scapy.layers.inet
> import Ether, IP, TCP, UDP, ICMP -from scapy.layers.inet6 import IPv6,
> IPv6ExtHdrRouting, IPv6ExtHdrFragment -from scapy.layers.l2 import Dot1Q,
> ARP, GRE
> +from scapy.all import *
> from scapy.layers.sctp import SCTP, SCTPChunkData -from scapy.sendrecv
> import sniff -from scapy.route import * -from scapy.packet import
> bind_layers, Raw -from scapy.sendrecv import sendp -from scapy.arch
> import get_if_hwaddr -from pexpect import pxssh
>
> # load extension layers
> exec_file = os.path.realpath(__file__)
> DTS_PATH = exec_file.replace('/framework/packet.py', '')
> +# exec_file might be .pyc file, if so, remove 'c'.
> +TMP_PATH = DTS_PATH[:-1] + '/output/tmp/pcap/' if
> exec_file.endswith('.pyc') else DTS_PATH + '/output/tmp/pcap/'
> +
> +if not os.path.exists(TMP_PATH):
> + os.system('mkdir -p %s' % TMP_PATH)
> DEP_FOLDER = DTS_PATH + '/dep'
> sys.path.append(DEP_FOLDER)
>
> @@ -70,9 +54,8 @@ from nvgre import NVGRE, IPPROTO_NVGRE from lldp
> import LLDP, LLDPManagementAddress from Dot1BR import Dot1BR
>
> -# get tester logger
> -from logger import getLogger
> -logger = getLogger('tester')
> +from utils import convert_ip2int
> +from utils import convert_int2ip
>
> # for saving command history
> from utils import get_backtrace_object
> @@ -150,7 +133,16 @@ class scapy(object):
>
> def __init__(self):
> self.pkt = None
> - pass
> + self.pkts = []
> +
> + def append_pkts(self):
> + self.pkts.append(self.pkt)
> +
> + def update_pkts(self):
> + if not self.pkts: # update pkt to a null pkt list.
> + self.pkts.append(self.pkt)
> + else:
> + self.pkts[-1] = self.pkt
>
> def assign_pkt(self, pkt):
> self.pkt = pkt
> @@ -179,14 +171,14 @@ class scapy(object):
> if type is not None:
> pkt_layer.type = type
>
> - def strip_vlan(self, element):
> + def strip_vlan(self, element, p_index=0):
> value = None
>
> - if self.pkt.haslayer('Dot1Q') is 0:
> + if self.pkts[p_index].haslayer('Dot1Q') is 0:
> return None
>
> if element == 'vlan':
> - value = int(str(self.pkt[Dot1Q].vlan))
> + value = int(str(self.pkts[p_index][Dot1Q].vlan))
> return value
>
> def etag(self, pkt_layer, ECIDbase=0, prio=0, type=None):
> @@ -197,19 +189,19 @@ class scapy(object):
> if type is not None:
> pkt_layer.type = type
>
> - def strip_etag(self, element):
> + def strip_etag(self, element, p_index=0):
> value = None
>
> - if self.pkt.haslayer('Dot1BR') is 0:
> + if self.pkts[p_index].haslayer('Dot1BR') is 0:
> return None
>
> if element == 'ECIDbase':
> - value = int(str(self.pkt[Dot1BR].ECIDbase))
> + value = int(str(self.pkts[p_index][Dot1BR].ECIDbase))
> return value
>
> - def strip_layer2(self, element):
> + def strip_layer2(self, element, p_index=0):
> value = None
> - layer = self.pkt.getlayer(0)
> + layer = self.pkts[p_index].getlayer(0)
> if layer is None:
> return None
>
> @@ -222,9 +214,9 @@ class scapy(object):
>
> return value
>
> - def strip_layer3(self, element):
> + def strip_layer3(self, element, p_index=0):
> value = None
> - layer = self.pkt.getlayer(1)
> + layer = self.pkts[p_index].getlayer(1)
> if layer is None:
> return None
>
> @@ -237,9 +229,9 @@ class scapy(object):
>
> return value
>
> - def strip_layer4(self, element):
> + def strip_layer4(self, element, p_index=0):
> value = None
> - layer = self.pkt.getlayer(2)
> + layer = self.pkts[p_index].getlayer(2)
> if layer is None:
> return None
>
> @@ -252,7 +244,8 @@ class scapy(object):
>
> return value
>
> - def ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0,
> dst="127.0.0.1", chksum=None, len=None, version=4, flags=None, ihl=None,
> ttl=64, id=1, options=None):
> + def ipv4(self, pkt_layer, frag=0, src="127.0.0.1", proto=None, tos=0,
> dst="127.0.0.1", chksum=None, len=None,
> + version=4, flags=None, ihl=None, ttl=64, id=1, options=None):
> pkt_layer.frag = frag
> pkt_layer.src = src
> if proto is not None:
> @@ -287,7 +280,7 @@ class scapy(object):
> pkt_layer.src = src
> pkt_layer.dst = dst
>
> - def tcp(self, pkt_layer, src=53, dst=53, flags=None, len=None,
> chksum=None):
> + def tcp(self, pkt_layer, src=53, dst=53, flags=0, len=None, chksum=None):
> pkt_layer.sport = src
> pkt_layer.dport = dst
> if flags is not None:
> @@ -328,66 +321,6 @@ class scapy(object):
> def vxlan(self, pkt_layer, vni=0):
> pkt_layer.vni = vni
>
> - def read_pcap(self, file):
> - pcap_pkts = []
> - try:
> - pcap_pkts = rdpcap(file)
> - except:
> - pass
> -
> - return pcap_pkts
> -
> - def write_pcap(self, file):
> - try:
> - wrpcap(file, self.pkt)
> - except:
> - pass
> -
> - def send_pcap_pkt(self, crb=None, file='', intf='', count=1):
> - if intf == '' or file == '' or crb is None:
> - print "Invalid option for send packet by scapy"
> - return
> -
> - content = 'pkts=rdpcap(\"%s\");sendp(pkts, iface=\"%s\",
> count=\"%s\" );exit()' % (file, intf, count)
> - cmd_file = '/tmp/scapy_%s.cmd' % intf
> -
> - crb.create_file(content, cmd_file)
> - crb.send_expect("scapy -c scapy_%s.cmd &" % intf, "# ")
> -
> - def print_summary(self):
> - # save command into test case history
> - history_list = get_backtrace_object('test_case.py', 'test_history')
> - if type(history_list) is list:
> - history_list.append({"command": "p=%s" % self.pkt.command(),
> "name": "Scapy", "output": ""})
> -
> - logger.info("%s" % self.pkt.command())
> -
> - def send_pkt(self, intf='', count=1):
> - self.print_summary()
> -
> - if intf != '':
> - # wait few seconds for link ready
> - countdown = 600
> - while countdown:
> - link_st = subprocess.check_output("ip link show %s" % intf,
> - stderr=subprocess.STDOUT,
> - shell=True)
> - if "LOWER_UP" in link_st:
> - break
> - else:
> - time.sleep(0.01)
> - countdown -= 1
> - continue
> -
> - # fix fortville can't receive packets with 00:00:00:00:00:00
> - if self.pkt.getlayer(0).src == "00:00:00:00:00:00":
> - self.pkt.getlayer(0).src = get_if_hwaddr(intf)
> - sendp(self.pkt, iface=intf, count=count)
> -
> - # save command into test case history
> - history_list = get_backtrace_object('test_case.py', 'test_history')
> - if type(history_list) is list:
> - history_list.append({"command": "sendp(p, iface=\"%s\")" % intf,
> "name": "Scapy", "output": ""})
>
> class Packet(object):
>
> @@ -413,10 +346,11 @@ class Packet(object):
> 'IPv6_SCTP': {'layers': ['ether', 'ipv6', 'sctp', 'raw'], 'cfgload': True},
> }
>
> - def __init__(self, **options):
> + def __init__(self, pkt_str=None, **options):
> """
> pkt_type: description of packet type
> defined in def_packet
> + args: specify a packet with a string explicitly, will ignore
> + options
> options: special option for Packet module
> pkt_len: length of network packet
> ran_payload: whether payload of packet is random @@ -424,14
> +358,41 @@ class Packet(object):
> pkt_gen: packet generator type
> now only support scapy
> """
> - self.pkt_layers = []
> - self.pkt_len = 64
> self.pkt_opts = options
> + self.pkt_layers = []
>
> - self.pkt_type = "UDP"
> + if 'pkt_gen' in self.pkt_opts.keys():
> + if self.pkt_opts['pkt_gen'] == 'scapy':
> + self.pktgen = scapy()
> + else:
> + print "Not support other pktgen yet!!!"
> + else:
> + self.pktgen = scapy()
>
> - if 'pkt_type' in self.pkt_opts.keys():
> - self.pkt_type = self.pkt_opts['pkt_type']
> + if pkt_str is not None and type(pkt_str) == str:
> + self._scapy_str_to_pkt(pkt_str)
> + elif len(options) == 0:
> + pass
> + else:
> + self._add_pkt(self.pkt_opts)
> + if self.pktgen.pkt is not None:
> + self.pktgen.append_pkts()
> +
> + def __len__(self):
> + return len(self.pktgen.pkts)
> +
> + def __getitem__(self, item):
> + return self.pktgen.pkts[item]
> +
> + def _add_pkt(self, options):
> + """
> + :param options: packt configuration, dictionary type
> + :return:
> + """
> + self.pkt_len = 64
> + self.pkt_type = "UDP"
> + if 'pkt_type' in options.keys():
> + self.pkt_type = options['pkt_type']
>
> if self.pkt_type in self.def_packet.keys():
> self.pkt_layers = self.def_packet[self.pkt_type]['layers']
> @@ -441,21 +402,8 @@ class Packet(object):
> else:
> self._load_pkt_layers()
>
> - if 'pkt_len' in self.pkt_opts.keys():
> - self.pkt_len = self.pkt_opts['pkt_len']
> -
> - if 'pkt_file' in self.pkt_opts.keys():
> - self.uni_name = self.pkt_opts['pkt_file']
> - else:
> - self.uni_name = '/tmp/' + str(uuid4()) + '.pcap'
> -
> - if 'pkt_gen' in self.pkt_opts.keys():
> - if self.pkt_opts['pkt_gen'] == 'scapy':
> - self.pktgen = scapy()
> - else:
> - print "Not support other pktgen yet!!!"
> - else:
> - self.pktgen = scapy()
> + if 'pkt_len' in options.keys():
> + self.pkt_len = options['pkt_len']
>
> self._load_assign_layers()
>
> @@ -483,32 +431,227 @@ class Packet(object):
> raw_confs['payload'] = payload
> self.config_layer('raw', raw_confs)
>
> - def send_pkt(self, crb=None, tx_port='', auto_cfg=True, count=1):
> - if tx_port == '':
> - print "Invalid Tx interface"
> - return
> + def _scapy_str_to_pkt(self, scapy_str):
> + """
>
> - self.tx_port = tx_port
> + :param scapy_str: packet str, eg. 'Ether()/IP()/UDP()'
> + :return: None
> + """
> + layer_li = [re.sub('\(.*?\)', '', i) for i in scapy_str.split('/')]
> + self.pkt_type = '_'.join(layer_li)
> + self._load_pkt_layers()
> + pkt = eval(scapy_str)
> + self.pktgen.assign_pkt(pkt)
>
> - # check with port type
> - if 'ixia' in self.tx_port:
> - print "Not Support Yet"
> + def append_pkt(self, args=None, **kwargs):
> + """
> + :param args: take str type as pkt to append
> + :param kwargs: take dictory type as pkt to append
> + :return: None
> + """
> + if isinstance(args, str):
> + self._scapy_str_to_pkt(args)
> + elif isinstance(kwargs, dict):
> + self.pkt_opts = kwargs
> + if hasattr(self, 'configured_layer_raw'):
> + delattr(self, 'configured_layer_raw')
> + self._add_pkt(kwargs)
> + self.pktgen.append_pkts()
> +
> + def generate_random_pkts(self, dstmac=None, pktnum=100,
> random_type=None, ip_increase=True, random_payload=False,
> + options=None):
> + """
> + # generate random packets
> + :param dstmac: specify the dst mac
> + :param pktnum: packet number to generate
> + :param random_type: specify random packet type
> + :param ip_increase: auto increase ip value
> + :param random_payload: if True, generate random packets with
> random payload
> + :param options: packet layer configuration
> + :return: None
> + """
>
> - if crb is not None:
> - self.pktgen.write_pcap(self.uni_name)
> - crb.session.copy_file_to(self.uni_name)
> - pcap_file = self.uni_name.split('/')[2]
> - self.pktgen.send_pcap_pkt(
> - crb=crb, file=pcap_file, intf=self.tx_port, count=count)
> + random_type = ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP'] if random_type is
> None else random_type
> + options = {'ip': {'src': '192.168.0.1', 'dst': '192.168.1.1'},
> + 'layers_config': []} if options is None else options
> + # give a default value to ip
> + try:
> + src_ip_num = convert_ip2int(options['ip']['src'])
> + except:
> + src_ip_num = 0
> + try:
> + dst_ip_num = convert_ip2int(options['ip']['dst'])
> + except:
> + dst_ip_num = 0
> +
> + for i in range(pktnum):
> + # random the packet type
> + self.pkt_type = random.choice(random_type)
> + self.pkt_layers = self.def_packet[self.pkt_type]['layers']
> + self.check_layer_config()
> + self.pktgen.add_layers(self.pkt_layers)
> + # hardcode src/dst port for some protocol may cause issue
> + if "TCP" in self.pkt_type:
> + self.config_layer('tcp', {'src': 65535, 'dst': 65535})
> + if "UDP" in self.pkt_type:
> + self.config_layer('udp', {'src': 65535, 'dst': 65535})
> + if options.has_key('layers_config'):
> + self.config_layers(options['layers_config'])
> + if dstmac:
> + self.config_layer('ether', {'dst': '%s' % dstmac})
> + # generate auto increase dst ip packet
> + if ip_increase:
> + if 'v6' in self.pkt_type:
> + dstip = convert_int2ip(dst_ip_num, ip_type=6)
> + srcip = convert_int2ip(src_ip_num, ip_type=6)
> + self.config_layer('ipv6', config={'dst': '%s' % (dstip), 'src': '%s' %
> srcip})
> + else:
> + dstip = convert_int2ip(dst_ip_num, ip_type=4)
> + srcip = convert_int2ip(src_ip_num, ip_type=4)
> + self.config_layer('ipv4', config={'dst': '%s' % (dstip), 'src': '%s' %
> srcip})
> + dst_ip_num += 1
> + # generate random payload of packet
> + if random_payload and self.def_packet[self.pkt_type]['cfgload']:
> + # TCP packet has a default flags S, packet should not load data, so
> set it to A if has payload
> + if 'TCP' in self.pkt_type:
> + self.config_layer('tcp', {'src': 65535, 'dst':
> + 65535, 'flags': 'A'})
> +
> + payload_len = random.randint(64, 100)
> + payload = []
> + for _ in range(payload_len):
> + payload.append("%02x" % random.randrange(0, 255))
> + self.config_layer('raw', config={'payload': payload})
> + self.pktgen.append_pkts()
> +
> + def save_pcapfile(self, crb=None, filename='saved_pkts.pcap'):
> + """
> +
> + :param crb: session or crb object
> + :param filename: location and name for packets to be saved
> + :return: None
> + """
> + # save pkts to pcap file to local path, then copy to remote tester tmp
> directory,
> + if crb:
> + trans_path = crb.tmp_file
> + file_name = filename
> + if os.path.isabs(filename): # check if the given filename with a abs
> path
> + file_dir = os.path.dirname(filename)
> + out = crb.send_expect('ls -d %s' % file_dir, '# ', verify=True)
> + if not isinstance(out, str):
> + raise Exception('%s may not existed on %s' % (file_dir, crb.name))
> + wrpcap(filename, self.pktgen.pkts)
> + trans_path = os.path.abspath(filename)
> + file_name = filename.split(os.path.sep)[-1]
> + # write packets to local tmp path $dts/ouput/tmp/pcap/
> + wrpcap(TMP_PATH + file_name, self.pktgen.pkts)
> + # copy to remote tester tmp path /tmp/tester
> + crb.session.copy_file_to(TMP_PATH + file_name, trans_path)
> else:
> - self.pktgen.send_pkt(intf=self.tx_port, count=count)
> + wrpcap(filename, self.pktgen.pkts)
>
> - def check_layer_config(self, layer, config):
> + def read_pcapfile(self, filename, crb=None):
> + """
> +
> + :param filename: packet to be read from
> + :param crb: session or crb object
> + :return: scapy type packet
> + """
> + # read pcap file from local or remote, then append to pkts list
> + # if crb, read pakcet from remote server, else read from local location
> + if crb:
> + out = crb.send_expect('ls -d %s' % filename, '# ', verify=True)
> + if not isinstance(out, str):
> + raise Exception('%s may not existed on %s' % (filename, crb.name))
> + crb.session.copy_file_from(filename, TMP_PATH)
> + p = rdpcap(TMP_PATH + filename.split(os.path.sep)[-1])
> + else:
> + p = rdpcap(filename)
> + if len(p) == 0:
> + return None
> + self.pktgen.assign_pkt(p[-1])
> + for i in p:
> + self.pktgen.pkts.append(i)
> + return p
> +
> + def _send_pkt(self, crb, tx_port='', count=1, send_bg=False, loop=0,
> inter=0, timeout=15):
> + """
> +
> + :param crb: session or crb object
> + :param tx_port: ether to send packet
> + :param count: send times
> + :param send_bg: send packet background
> + :param loop: send packet in a loop
> + :param inter: interval time
> + :return: None
> + """
> + # save pkts to local pcap file, then copy to remote tester tmp
> + directory
> +
> + time_stamp = str(time.time())
> + pcap_file = 'scapy_{}.pcap'.format(tx_port) + time_stamp
> + self.save_pcapfile(crb, pcap_file)
> + scapy_cmd = 'scapy_{}.cmd'.format(tx_port) + time_stamp
> + cmd_str = 'from scapy.all import *\np=rdpcap("%s")\nprint("packet
> ready for sending...")\nfor i in p:\n\tprint(i.command())\nsendp(p,
> iface="%s", count=%d, loop=%d, inter=%0.3f)' % (
> + crb.tmp_file + pcap_file, tx_port, count, loop, inter)
> + # write send cmd file to local tmp directory then copy to remote tester
> tmp folder
> + with open(TMP_PATH + scapy_cmd, 'w') as f:
> + f.write(cmd_str)
> + crb.session.copy_file_to(TMP_PATH + scapy_cmd, crb.tmp_file)
> +
> + if send_bg: # if send_bg create a new session to execute send action
> + session_prefix = 'scapy_bg_session'
> + scapy_session = crb.create_session(session_prefix + time_stamp)
> + scapy_session.send_command('python %s' % crb.tmp_file +
> scapy_cmd)
> + else:
> + crb.send_expect('python %s' % crb.tmp_file + scapy_cmd, '# ',
> timeout=timeout)
> + return crb.tmp_file + scapy_cmd
> +
> + def send_pkt(self, crb, tx_port='', count=1, interval=0, timeout=15):
> + self._send_pkt(crb, tx_port, count, inter=interval,
> + timeout=timeout)
> +
> + def send_pkt_bg(self, crb, tx_port='', count=-1, loop=1, interval=0,
> timeout=3):
> + return self._send_pkt(crb, tx_port=tx_port, count=count,
> send_bg=True, loop=loop, inter=interval,
> + timeout=timeout)
> +
> + def stop_send_pkt_bg(self, crb, filenames):
> + # stop sending action
> + pids = []
> + if isinstance(filenames, list):
> + for file in filenames:
> + out = crb.send_expect('ps -ef |grep %s|grep -v grep' % file,
> expected='# ')
> + try:
> + pids.append(re.search('\d+', out).group())
> + except AttributeError as e:
> + print(e, ' :%s not killed' % file)
> + else:
> + out = crb.send_expect('ps -ef |grep %s|grep -v grep' % filenames,
> expected='# ')
> + try:
> + pids.append(re.search('\d+', out).group())
> + except AttributeError as e:
> + print(e, ' :%s not killed' % filenames)
> + pid = ' '.join(pids)
> + if pid:
> + crb.send_expect('kill -9 %s' % pid, expected='# ')
> + for i in crb.sessions:
> + if i.name.startswith('scapy_bg_session'):
> + crb.destroy_session(i)
> +
> + def check_layer_config(self):
> """
> check the format of layer configuration
> every layer should has different check function
> """
> - pass
> + for layer in self.pkt_layers:
> + found = False
> + l_type = layer.lower()
> +
> + for types in LayersTypes.values():
> + if l_type in types:
> + found = True
> + break
> +
> + if found is False:
> + self.pkt_layers.remove(l_type)
> + print "INVAILD LAYER TYPE [%s]" % l_type.upper()
>
> def assign_layers(self, layers=None):
> """
> @@ -532,6 +675,8 @@ class Packet(object):
> print "INVAILD LAYER TYPE [%s]" % l_type.upper()
>
> self.pktgen.add_layers(self.pkt_layers)
> + if layers:
> + self.pktgen.update_pkts()
>
> def _load_pkt_layers(self):
> name2type = {
> @@ -590,9 +735,9 @@ class Packet(object):
> else:
> self.config_layer('raw', {'payload': ['00'] * 18})
>
> - if "MAC_IP_IPv6" in self.pkt_type or\
> - "MAC_IP_NVGRE" in self.pkt_type or \
> - "MAC_IP_UDP_VXLAN" in self.pkt_type:
> + if "MAC_IP_IPv6" in self.pkt_type or \
> + "MAC_IP_NVGRE" in self.pkt_type or \
> + "MAC_IP_UDP_VXLAN" in self.pkt_type:
> if "IPv6_SCTP" in self.pkt_type:
> self.config_layer('ipv6', {'nh': 132})
> if "IPv6_ICMP" in self.pkt_type:
> @@ -601,6 +746,8 @@ class Packet(object):
> self.config_layer('raw', {'payload': ['00'] * 40})
> else:
> self.config_layer('raw', {'payload': ['00'] * 18})
> + if 'TCP' in self.pkt_type:
> + self.config_layer('tcp', {'flags': 0})
>
> def config_layer(self, layer, config={}):
> """
> @@ -613,22 +760,23 @@ class Packet(object):
> print "INVALID LAYER ID %s" % layer
> return False
>
> - if self.check_layer_config(layer, config) is False:
> + if self.check_layer_config() is False:
> return False
>
> if 'inner' in layer:
> layer = layer[6:]
>
> pkt_layer = self.pktgen.pkt.getlayer(idx)
> - layer_conf = getattr(self, "_config_layer_%s" % layer)
> + layer_conf = getattr(self.pktgen, layer)
> setattr(self, 'configured_layer_%s' % layer, True)
>
> - return layer_conf(pkt_layer, config)
> + layer_conf(pkt_layer, **config)
>
> def config_layers(self, layers=None):
> """
> Configure packet with multi configurations
> """
> + layers = [] if layers is None else layers # None object is not
> + Iterable
> for layer in layers:
> name, config = layer
> if name not in self.pkt_layers:
> @@ -638,65 +786,28 @@ class Packet(object):
> print "[%s] failed to configure!!!" % name
> raise
>
> - def _config_layer_ether(self, pkt_layer, config):
> - return self.pktgen.ether(pkt_layer, **config)
> -
> - def _config_layer_mac(self, pkt_layer, config):
> - return self.pktgen.ether(pkt_layer, **config)
> -
> - def _config_layer_vlan(self, pkt_layer, config):
> - return self.pktgen.vlan(pkt_layer, **config)
> -
> - def _config_layer_etag(self, pkt_layer, config):
> - return self.pktgen.etag(pkt_layer, **config)
> -
> - def _config_layer_ipv4(self, pkt_layer, config):
> - return self.pktgen.ipv4(pkt_layer, **config)
> -
> - def _config_layer_ipv6(self, pkt_layer, config):
> - return self.pktgen.ipv6(pkt_layer, **config)
> -
> - def _config_layer_udp(self, pkt_layer, config):
> - return self.pktgen.udp(pkt_layer, **config)
> -
> - def _config_layer_tcp(self, pkt_layer, config):
> - return self.pktgen.tcp(pkt_layer, **config)
> -
> - def _config_layer_sctp(self, pkt_layer, config):
> - return self.pktgen.sctp(pkt_layer, **config)
> -
> - def _config_layer_gre(self, pkt_layer, config):
> - return self.pktgen.gre(pkt_layer, **config)
> -
> - def _config_layer_raw(self, pkt_layer, config):
> - return self.pktgen.raw(pkt_layer, **config)
> -
> - def _config_layer_vxlan(self, pkt_layer, config):
> - return self.pktgen.vxlan(pkt_layer, **config)
> -
> - def strip_layer_element(self, layer, element):
> + def strip_layer_element(self, layer, element, p_index=0):
> """
> Strip packet layer elements
> return the status of configure result
> """
> strip_element = getattr(self, "strip_element_%s" % layer)
> + return strip_element(element, p_index)
>
> - return strip_element(element)
> -
> - def strip_element_layer2(self, element):
> - return self.pktgen.strip_layer2(element)
> + def strip_element_layer2(self, element, p_index=0):
> + return self.pktgen.strip_layer2(element, p_index)
>
> - def strip_element_layer3(self, element):
> - return self.pktgen.strip_layer3(element)
> + def strip_element_layer3(self, element, p_index=0):
> + return self.pktgen.strip_layer3(element, p_index)
>
> - def strip_element_vlan(self, element):
> - return self.pktgen.strip_vlan(element)
> + def strip_element_vlan(self, element, p_index=0):
> + return self.pktgen.strip_vlan(element, p_index)
>
> - def strip_element_etag(self, element):
> - return self.pktgen.strip_etag(element)
> + def strip_element_etag(self, element, p_index=0):
> + return self.pktgen.strip_etag(element, p_index)
>
> - def strip_element_layer4(self, element):
> - return self.pktgen.strip_layer4(element)
> + def strip_element_layer4(self, element, p_index=0):
> + return self.pktgen.strip_layer4(element, p_index)
>
>
> def IncreaseIP(addr):
> @@ -725,27 +836,6 @@ def IncreaseIPv6(addr):
> return ipv6
>
>
> -def send_packets(intf, pkts=None, interval=0.01):
> - send_pkts = []
> - try:
> - for pkt in pkts:
> - send_pkts.append(pkt.pktgen.pkt)
> - sendp(send_pkts, iface=intf, inter=interval, verbose=False)
> - except:
> - pass
> -
> -
> -def save_packets(pkts=None, filename=None):
> - save_pkts = []
> - try:
> - for pkt in pkts:
> - save_pkts.append(pkt.pktgen.pkt)
> - if filename:
> - wrpcap(filename, save_pkts)
> - except:
> - pass
> -
> -
> def get_ether_type(eth_type=""):
> # need add more types later
> if eth_type.lower() == "lldp":
> @@ -809,48 +899,46 @@ def get_filter_cmd(filters=[]):
> return ""
>
>
> -def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> +def start_tcpdump(crb, intf, count=0, filters=None, lldp_forbid=True):
> """
> - sniff all packets for certain port in certain seconds
> + sniff all packets from certain port
> """
> + filters = [] if filters is None else filters
> + out = crb.send_expect("ls -d %s" % crb.tmp_file, "# ", verify=True)
> + if out == 2:
> + crb.send_expect("mkdir -p %s" % crb.tmp_file, "# ")
> + filename = '{}sniff_{}.pcap'.format(crb.tmp_file, intf)
> + # delete old pcap file
> + crb.send_expect('rm -rf %s' % filename, '# ')
> +
> param = ""
> direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> -
> - try:
> - tcpdump_help_session=pxssh.pxssh()
> - tcpdump_help_session.login(server=target[0], username=target[1],
> - password=target[2], original_prompt='[$#>]',
> - login_timeout=20)
> - tcpdump_help_session.sendline('tcpdump -h')
> - tcpdump_help_session.prompt()
> - tcpdump_help=tcpdump_help_session.before
> - tcpdump_help_session.logout()
> - except pxssh.ExceptionPxssh as e:
> - print ('pxssh failed on login.')
> - print (e)
> + tcpdump_session = crb.create_session('tcpdump_session' +
> str(time.time()))
> + setattr(tcpdump_session, 'tmp_file', crb.tmp_file)
> + tcpdump_help = tcpdump_session.send_command('tcpdump -h')
>
> for line in tcpdump_help.split('\n'):
> m = re.match(direct_param, line)
> if m:
> - opt = re.search("-Q", m.group(2));
> + opt = re.search("-Q", m.group(2))
> if opt:
> param = "-Q" + " in"
> else:
> - opt = re.search("-P", m.group(2));
> + opt = re.search("-P", m.group(2))
> if opt:
> param = "-P" + " in"
>
> if len(param) == 0:
> print "tcpdump not support direction choice!!!"
>
> - if LLDP_FILTER not in filters:
> + if lldp_forbid and (LLDP_FILTER not in filters):
> filters.append(LLDP_FILTER)
>
> filter_cmd = get_filter_cmd(filters)
>
> sniff_cmd = 'tcpdump -i %(INTF)s %(FILTER)s %(IN_PARAM)s -w %(FILE)s'
> options = {'INTF': intf, 'COUNT': count, 'IN_PARAM': param,
> - 'FILE': '/tmp/sniff_%s.pcap' % intf,
> + 'FILE': filename,
> 'FILTER': filter_cmd}
> if count:
> sniff_cmd += ' -c %(COUNT)d'
> @@ -858,77 +946,27 @@ def sniff_packets(intf, count=0, timeout=5,
> filters=[], target=[]):
> else:
> cmd = sniff_cmd % options
>
> - try:
> - tcpdump_session=pxssh.pxssh()
> - tcpdump_session.login(server=target[0], username=target[1],
> - password=target[2], original_prompt='[$#>]',
> - login_timeout=20)
> - tcpdump_session.sendline(cmd)
> - pipe = tcpdump_session
> - except pxssh.ExceptionPxssh as e:
> - print ('pxssh failed on login.')
> - print (e)
> + tcpdump_session.send_command(cmd)
>
> index = str(time.time())
> - SNIFF_PIDS[index] = (pipe, intf, timeout)
> + SNIFF_PIDS[index] = (tcpdump_session, intf, filename)
> time.sleep(1)
> return index
>
>
> -def load_sniff_pcap(index='', target=[]):
> +def stop_and_load_tcpdump_packets(index='', timeout=1):
> """
> - Stop sniffer and return pcap file
> + Stop sniffer and return packet object
> """
> - child_exit = False
> if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> - time_elapse = int(time.time() - float(index))
> - while time_elapse < timeout:
> - if pipe.prompt(timeout=1):
> - child_exit = True
> - break
> -
> - time_elapse += 1
> -
> - if not child_exit:
> - try:
> - # Stop Tcpdump on the target server
> - tcpdump_quit_session=pxssh.pxssh()
> - tcpdump_quit_session.login(server=target[0], username=target[1],
> - password=target[2], original_prompt='[$#>]',
> - login_timeout=20)
> - tcpdump_quit_session.sendline('kill -2 $(pidof tcpdump)')
> - tcpdump_quit_session.prompt()
> - tcpdump_quit_session.logout()
> - child_exit = True
> - except pxssh.ExceptionPxssh as e:
> - print ('pxssh failed on login.')
> - print (e)
> -
> - # Close the Tcpdump_session
> - pipe.prompt()
> - pipe.logout()
> -
> - # wait pcap file ready
> - time.sleep(1)
> - return "/tmp/sniff_%s.pcap" % intf
> -
> - return ""
> -
> -
> -def load_pcapfile(filename=""):
> - pkts = []
> - try:
> - cap_pkts = rdpcap(filename)
> - for pkt in cap_pkts:
> - # packet gen should be scapy
> - packet = Packet()
> - packet.pktgen.assign_pkt(pkt)
> - pkts.append(packet)
> - except:
> - pass
> -
> - return pkts
> + pipe, intf, filename = SNIFF_PIDS.pop(index)
> + pipe.get_session_before(timeout)
> + pipe.send_command('^C')
> + pipe.copy_file_from(filename, TMP_PATH)
> + p = Packet()
> + p.read_pcapfile(TMP_PATH + filename.split(os.sep)[-1])
> + pipe.close()
> + return p
>
>
> def compare_pktload(pkt1=None, pkt2=None, layer="L2"):
> @@ -940,8 +978,8 @@ def compare_pktload(pkt1=None, pkt2=None,
> layer="L2"):
> elif layer == "L4":
> l_idx = 2
> try:
> - load1 = hexstr(str(pkt1.pktgen.pkt.getlayer(l_idx)))
> - load2 = hexstr(str(pkt2.pktgen.pkt.getlayer(l_idx)))
> + load1 = hexstr(str(pkt1.getlayer(l_idx)))
> + load2 = hexstr(str(pkt2.getlayer(l_idx)))
> except:
> # return pass when scapy failed to extract packet
> return True
> @@ -952,7 +990,7 @@ def compare_pktload(pkt1=None, pkt2=None,
> layer="L2"):
> return False
>
>
> -def strip_pktload(pkt=None, layer="L2"):
> +def strip_pktload(pkt=None, layer="L2", p_index=0):
> if layer == "L2":
> l_idx = 0
> elif layer == "L3":
> @@ -962,30 +1000,36 @@ def strip_pktload(pkt=None, layer="L2"):
> else:
> l_idx = 0
> try:
> - load = hexstr(str(pkt.pktgen.pkt.getlayer(l_idx)), onlyhex=1)
> + load = hexstr(str(pkt.pktgen.pkts[p_index].getlayer(l_idx)),
> + onlyhex=1)
> except:
> # return pass when scapy failed to extract packet
> load = ""
>
> return load
>
> +
>
> ################################################################
> ###############
>
> ################################################################
> ###############
> if __name__ == "__main__":
> - pkt = Packet(pkt_type='UDP')
> - pkt.send_pkt(tx_port='lo')
> +
> + pkt =
> Packet('Ether(type=0x894f)/NSH(Len=0x6,NextProto=0x0,NSP=0x000002,NSI=
> 0xff)')
> + sendp(pkt, iface='lo')
> + pkt.config_layer('ipv4', {'dst': '192.168.8.8'})
> + pkt.append_pkt(pkt_type='IPv6_TCP', pkt_len=100)
> + pkt.append_pkt(pkt_type='TCP', pkt_len=100)
> + pkt.config_layer('tcp', config={'flags': 'A'})
> +
> pkt.append_pkt("Ether(dst='11:22:33:44:55:11')/IP(dst='192.168.5.2')/TCP(fla
> gs=0)/Raw(load='bbbb')")
> + pkt.generate_random_pkts('11:22:33:44:55:55', random_type=['TCP',
> 'IPv6_TCP'], random_payload=True, pktnum=10)
> + sendp(pkt, iface='lo')
>
> pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> - pkt.send_pkt(tx_port='lo')
> - pkt = Packet(pkt_type='IPv6_TCP')
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
> pkt = Packet(pkt_type='IPv6_SCTP')
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
> pkt = Packet(pkt_type='VLAN_UDP')
> pkt.config_layer('vlan', {'vlan': 2})
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
>
> - pkt = Packet()
> pkt.assign_layers(['ether', 'vlan', 'ipv4', 'udp',
> 'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
> pkt.config_layer('ether', {'dst': '00:11:22:33:44:55'}) @@ -994,13 +1038,12
> @@ if __name__ == "__main__":
> pkt.config_layer('udp', {'src': 4789, 'dst': 4789, 'chksum': 0x1111})
> pkt.config_layer('vxlan', {'vni': 2})
> pkt.config_layer('raw', {'payload': ['58'] * 18})
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
>
> - pkt = Packet()
> pkt.assign_layers(['ether', 'vlan', 'ipv4', 'udp',
> 'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
> # config packet
> pkt.config_layers([('ether', {'dst': '00:11:22:33:44:55'}), ('ipv4', {'dst':
> '1.1.1.1'}),
> ('vxlan', {'vni': 2}), ('raw', {'payload': ['01'] * 18})])
>
> - pkt.send_pkt(tx_port='lo')
> + sendp(pkt, iface='lo')
> --
> 2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [dts] [PATCH V1] framework/tester: update tester module of dts
2019-09-27 18:05 [dts] [PATCH V1] tests/: update cases related to new framework Qimai Xiao
2019-09-27 18:05 ` [dts] [PATCH V1] framework/packet: update packet module of dts Qimai Xiao
@ 2019-09-27 18:05 ` Qimai Xiao
2019-10-08 2:22 ` Chen, Zhaoyan
2019-10-12 5:30 ` Tu, Lijuan
2019-10-08 2:22 ` [dts] [PATCH V1] tests/: update cases related to new framework Chen, Zhaoyan
2019-10-12 5:30 ` Tu, Lijuan
3 siblings, 2 replies; 9+ messages in thread
From: Qimai Xiao @ 2019-09-27 18:05 UTC (permalink / raw)
To: dts; +Cc: Qimai Xiao
update APIs related to packet module and rewrite func check_random_pkts
Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
---
framework/tester.py | 157 ++++++++++++--------------------------------
1 file changed, 43 insertions(+), 114 deletions(-)
diff --git a/framework/tester.py b/framework/tester.py
index 174d0b6..d7e74d4 100644
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -75,6 +75,11 @@ class Tester(Crb):
self.re_run_time = 0
self.pktgen = None
self.ixia_packet_gen = None
+ self.tmp_file = '/tmp/tester/'
+ out = self.send_expect('ls -d %s' % self.tmp_file, '# ', verify=True)
+ if out == 2:
+ self.send_expect('mkdir -p %s' % self.tmp_file, '# ')
+
def init_ext_gen(self):
"""
@@ -639,12 +644,12 @@ class Tester(Crb):
else:
return None
- def parallel_transmit_ptks(self, send_f=None, intf='', pkts=[], interval=0.01):
+ def parallel_transmit_ptks(self, pkt=None, intf='', send_times=1, interval=0.01):
"""
Callable function for parallel processes
"""
print GREEN("Transmitting and sniffing packets, please wait few minutes...")
- send_f(intf=intf, pkts=pkts, interval=interval)
+ return pkt.send_pkt_bg(crb=self, tx_port=intf, count=send_times, loop=0, interval=interval)
def check_random_pkts(self, portList, pktnum=2000, interval=0.01, allow_miss=True, seq_check=False, params=None):
"""
@@ -653,79 +658,49 @@ class Tester(Crb):
# load functions in packet module
module = __import__("packet")
pkt_c = getattr(module, "Packet")
- send_f = getattr(module, "send_packets")
compare_f = getattr(module, "compare_pktload")
strip_f = getattr(module, "strip_pktload")
- save_f = getattr(module, "save_packets")
tx_pkts = {}
rx_inst = {}
# packet type random between tcp/udp/ipv6
random_type = ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP']
- pkt_minlen = {'TCP': 64, 'UDP': 64, 'IPv6_TCP': 74, 'IPv6_UDP': 64}
- # at least wait 2 seconds
- timeout = int(pktnum * (interval + 0.01)) + 2
for txport, rxport in portList:
- pkts = []
txIntf = self.get_interface(txport)
rxIntf = self.get_interface(rxport)
print GREEN("Preparing transmit packets, please wait few minutes...")
- for num in range(pktnum):
- # chose random packet
- pkt_type = random.choice(random_type)
- pkt = pkt_c(pkt_type=pkt_type,
- pkt_len=random.randint(pkt_minlen[pkt_type], 1514),
- ran_payload=True)
- # config packet if has parameters
- if params and len(portList) == len(params):
- for param in params:
- layer, config = param
- pkt.config_layer(layer, config)
- # hardcode src/dst port for some protocol may cause issue
- if "TCP" in pkt_type:
- pkt.config_layer('tcp', {'src': 65535, 'dst': 65535})
- else:
- 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})
+ pkt = pkt_c()
+ pkt.generate_random_pkts(pktnum=pktnum, random_type=random_type, ip_increase=True, random_payload=True,
+ options={"layers_config": params})
- pkts.append(pkt)
- tx_pkts[txport] = pkts
+ tx_pkts[txport] = pkt
+ # sniff packets
+ inst = module.start_tcpdump(self, rxIntf, count=pktnum,
+ filters=[{'layer': 'network', 'config': {'srcport': '65535'}},
+ {'layer': 'network', 'config': {'dstport': '65535'}}])
- # send and sniff packets
- save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
- inst = self.tcpdump_sniff_packets(intf=rxIntf, count=pktnum, timeout=timeout, filters=
- [{'layer': 'network', 'config': {'srcport': '65535'}},
- {'layer': 'network', 'config': {'dstport': '65535'}}])
rx_inst[rxport] = inst
-
- # Transmit packet simultaneously
- processes = []
+ filenames = []
for txport, _ in portList:
txIntf = self.get_interface(txport)
- processes.append(Process(target = self.parallel_transmit_ptks,
- args=(send_f, txIntf, tx_pkts[txport], interval)))
-
- for transmit_proc in processes:
- transmit_proc.start()
-
- for transmit_proc in processes:
- transmit_proc.join()
-
+ filenames.append(self.parallel_transmit_ptks(pkt=tx_pkts[txport], intf=txIntf, send_times=1, interval=interval))
# Verify all packets
+ sleep(interval * pktnum + 1)
+ flag = True
+ while flag:
+ for i in filenames:
+ flag = self.send_expect('ps -ef |grep %s|grep -v grep' % i, expected='# ')
+ if flag:
+ print('wait for the completion of sending pkts...')
+ sleep(1.5)
+ continue
prev_id = -1
for txport, rxport in portList:
- recv_pkts = self.load_tcpdump_sniff_packets(rx_inst[rxport])
-
+ p = module.stop_and_load_tcpdump_packets(rx_inst[rxport])
+ recv_pkts = p.pktgen.pkts
# only report when received number not matched
- if len(tx_pkts[txport]) > len(recv_pkts):
- print ("Pkt number not matched,%d sent and %d received\n" \
- % (len(tx_pkts[txport]), len(recv_pkts)))
-
+ if len(tx_pkts[txport].pktgen.pkts) > len(recv_pkts):
+ print ("Pkt number not matched,%d sent and %d received\n" % (
+ len(tx_pkts[txport].pktgen.pkts), len(recv_pkts)))
if allow_miss is False:
return False
@@ -733,9 +708,9 @@ class Tester(Crb):
print GREEN("Comparing sniffed packets, please wait few minutes...")
for idx in range(len(recv_pkts)):
try:
- l3_type = recv_pkts[idx].strip_element_layer2('type')
- sip = recv_pkts[idx].strip_element_layer3('src')
- except:
+ l3_type = p.strip_element_layer2('type', p_index=idx)
+ sip = p.strip_element_layer3('dst', p_index=idx)
+ except Exception as e:
continue
# ipv4 packet
if l3_type == 2048:
@@ -753,10 +728,10 @@ class Tester(Crb):
else:
prev_id = t_idx
- if compare_f(tx_pkts[txport][t_idx], recv_pkts[idx], "L4") is False:
+ if compare_f(tx_pkts[txport].pktgen.pkts[t_idx], recv_pkts[idx], "L4") is False:
print "Pkt received index %d not match original " \
"index %d" % (idx, t_idx)
- print "Sent: %s" % strip_f(tx_pkts[txport][t_idx], "L4")
+ print "Sent: %s" % strip_f(tx_pkts[txport].pktgen.pkts[t_idx], "L4")
print "Recv: %s" % strip_f(recv_pkts[idx], "L4")
return False
@@ -776,70 +751,24 @@ class Tester(Crb):
instance.__dict__ = self.ixia_packet_gen.__dict__
instance.__dict__.update(current_attrs)
- def sendpkt_bg(self, localPort, dst_mac):
- """
- loop to Send packet in background, should call stop_sendpkt_bg to stop it.
- """
- itf = self.get_interface(localPort)
- src_mac = self.get_mac(localPort)
- script_str = "from scapy.all import *\n" + \
- "sendp([Ether(dst='%s', src='%s')/IP(len=46)], iface='%s', loop=1)\n" % (dst_mac, src_mac, itf)
-
- self.send_expect("rm -fr send_pkg_loop.py", "# ")
- f = open("send_pkt_loop.py", "w")
- f.write(script_str)
- f.close()
-
- self.proc = subprocess.Popen(['python', 'send_pkt_loop.py'])
-
- def stop_sendpkt_bg(self):
- """
- stop send_pkt_loop in background
- """
- if self.proc:
- self.proc.kill()
- self.proc = None
-
- def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
+ def tcpdump_sniff_packets(self, intf, count=0, filters=None, lldp_forbid=True):
"""
Wrapper for packet module sniff_packets
"""
# load functions in packet module
- module = __import__("packet")
- sniff_f = getattr(module, "sniff_packets")
-
- target=[]
- target.append(self.get_ip_address())
- target.append(self.get_username())
- target.append(self.get_password())
- return sniff_f(intf, count, timeout, filters, target)
-
- def load_tcpdump_sniff_pcap(self, index=''):
- """
- Wrapper for packet module load_sniff_pcap
- """
- # load functions in packet module
- module = __import__("packet")
- load_pcap_f = getattr(module, "load_sniff_pcap")
-
- target=[]
- target.append(self.get_ip_address())
- target.append(self.get_username())
- target.append(self.get_password())
- pcap = load_pcap_f(index, target)
- self.session.copy_file_from(pcap)
-
- return pcap.split(os.sep)[-1]
+ packet = __import__("packet")
+ inst = packet.start_tcpdump(self, intf=intf, count=count, filters=filters, lldp_forbid=lldp_forbid)
+ return inst
- def load_tcpdump_sniff_packets(self, index=''):
+ def load_tcpdump_sniff_packets(self, index='', timeout=1):
"""
Wrapper for packet module load_pcapfile
"""
# load functions in packet module
packet = __import__("packet")
- file = self.load_tcpdump_sniff_pcap(index)
+ p = packet.stop_and_load_tcpdump_packets(index, timeout=timeout)
- return packet.load_pcapfile(file)
+ return p
def kill_all(self, killall=False):
"""
--
2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dts] [PATCH V1] framework/tester: update tester module of dts
2019-09-27 18:05 ` [dts] [PATCH V1] framework/tester: update tester " Qimai Xiao
@ 2019-10-08 2:22 ` Chen, Zhaoyan
2019-10-12 5:30 ` Tu, Lijuan
1 sibling, 0 replies; 9+ messages in thread
From: Chen, Zhaoyan @ 2019-10-08 2:22 UTC (permalink / raw)
To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX, Chen, Zhaoyan
Acked-by: Chen, Zhaoyan <zhaoyan.chen@intel.com>
Regards,
Zhaoyan Chen
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Qimai Xiao
> Sent: Saturday, September 28, 2019 2:06 AM
> To: dts@dpdk.org
> Cc: Xiao, QimaiX <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] framework/tester: update tester module of dts
>
> update APIs related to packet module and rewrite func check_random_pkts
>
> Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
> ---
> framework/tester.py | 157 ++++++++++++--------------------------------
> 1 file changed, 43 insertions(+), 114 deletions(-)
>
> diff --git a/framework/tester.py b/framework/tester.py index 174d0b6..d7e74d4
> 100644
> --- a/framework/tester.py
> +++ b/framework/tester.py
> @@ -75,6 +75,11 @@ class Tester(Crb):
> self.re_run_time = 0
> self.pktgen = None
> self.ixia_packet_gen = None
> + self.tmp_file = '/tmp/tester/'
> + out = self.send_expect('ls -d %s' % self.tmp_file, '# ', verify=True)
> + if out == 2:
> + self.send_expect('mkdir -p %s' % self.tmp_file, '# ')
> +
>
> def init_ext_gen(self):
> """
> @@ -639,12 +644,12 @@ class Tester(Crb):
> else:
> return None
>
> - def parallel_transmit_ptks(self, send_f=None, intf='', pkts=[], interval=0.01):
> + def parallel_transmit_ptks(self, pkt=None, intf='', send_times=1, interval=0.01):
> """
> Callable function for parallel processes
> """
> print GREEN("Transmitting and sniffing packets, please wait few minutes...")
> - send_f(intf=intf, pkts=pkts, interval=interval)
> + return pkt.send_pkt_bg(crb=self, tx_port=intf,
> + count=send_times, loop=0, interval=interval)
>
> def check_random_pkts(self, portList, pktnum=2000, interval=0.01,
> allow_miss=True, seq_check=False, params=None):
> """
> @@ -653,79 +658,49 @@ class Tester(Crb):
> # load functions in packet module
> module = __import__("packet")
> pkt_c = getattr(module, "Packet")
> - send_f = getattr(module, "send_packets")
> compare_f = getattr(module, "compare_pktload")
> strip_f = getattr(module, "strip_pktload")
> - save_f = getattr(module, "save_packets")
> tx_pkts = {}
> rx_inst = {}
> # packet type random between tcp/udp/ipv6
> random_type = ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP']
> - pkt_minlen = {'TCP': 64, 'UDP': 64, 'IPv6_TCP': 74, 'IPv6_UDP': 64}
> - # at least wait 2 seconds
> - timeout = int(pktnum * (interval + 0.01)) + 2
> for txport, rxport in portList:
> - pkts = []
> txIntf = self.get_interface(txport)
> rxIntf = self.get_interface(rxport)
> print GREEN("Preparing transmit packets, please wait few minutes...")
> - for num in range(pktnum):
> - # chose random packet
> - pkt_type = random.choice(random_type)
> - pkt = pkt_c(pkt_type=pkt_type,
> - pkt_len=random.randint(pkt_minlen[pkt_type], 1514),
> - ran_payload=True)
> - # config packet if has parameters
> - if params and len(portList) == len(params):
> - for param in params:
> - layer, config = param
> - pkt.config_layer(layer, config)
> - # hardcode src/dst port for some protocol may cause issue
> - if "TCP" in pkt_type:
> - pkt.config_layer('tcp', {'src': 65535, 'dst': 65535})
> - else:
> - 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})
> + pkt = pkt_c()
> + pkt.generate_random_pkts(pktnum=pktnum, random_type=random_type,
> ip_increase=True, random_payload=True,
> + options={"layers_config": params})
>
> - pkts.append(pkt)
> - tx_pkts[txport] = pkts
> + tx_pkts[txport] = pkt
> + # sniff packets
> + inst = module.start_tcpdump(self, rxIntf, count=pktnum,
> + filters=[{'layer': 'network', 'config': {'srcport': '65535'}},
> + {'layer': 'network',
> + 'config': {'dstport': '65535'}}])
>
> - # send and sniff packets
> - save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> - inst = self.tcpdump_sniff_packets(intf=rxIntf, count=pktnum,
> timeout=timeout, filters=
> - [{'layer': 'network', 'config': {'srcport': '65535'}},
> - {'layer': 'network', 'config': {'dstport': '65535'}}])
> rx_inst[rxport] = inst
> -
> - # Transmit packet simultaneously
> - processes = []
> + filenames = []
> for txport, _ in portList:
> txIntf = self.get_interface(txport)
> - processes.append(Process(target = self.parallel_transmit_ptks,
> - args=(send_f, txIntf, tx_pkts[txport], interval)))
> -
> - for transmit_proc in processes:
> - transmit_proc.start()
> -
> - for transmit_proc in processes:
> - transmit_proc.join()
> -
> +
> + filenames.append(self.parallel_transmit_ptks(pkt=tx_pkts[txport],
> + intf=txIntf, send_times=1, interval=interval))
> # Verify all packets
> + sleep(interval * pktnum + 1)
> + flag = True
> + while flag:
> + for i in filenames:
> + flag = self.send_expect('ps -ef |grep %s|grep -v grep' % i, expected='# ')
> + if flag:
> + print('wait for the completion of sending pkts...')
> + sleep(1.5)
> + continue
> prev_id = -1
> for txport, rxport in portList:
> - recv_pkts = self.load_tcpdump_sniff_packets(rx_inst[rxport])
> -
> + p = module.stop_and_load_tcpdump_packets(rx_inst[rxport])
> + recv_pkts = p.pktgen.pkts
> # only report when received number not matched
> - if len(tx_pkts[txport]) > len(recv_pkts):
> - print ("Pkt number not matched,%d sent and %d received\n" \
> - % (len(tx_pkts[txport]), len(recv_pkts)))
> -
> + if len(tx_pkts[txport].pktgen.pkts) > len(recv_pkts):
> + print ("Pkt number not matched,%d sent and %d received\n" % (
> + len(tx_pkts[txport].pktgen.pkts), len(recv_pkts)))
> if allow_miss is False:
> return False
>
> @@ -733,9 +708,9 @@ class Tester(Crb):
> print GREEN("Comparing sniffed packets, please wait few minutes...")
> for idx in range(len(recv_pkts)):
> try:
> - l3_type = recv_pkts[idx].strip_element_layer2('type')
> - sip = recv_pkts[idx].strip_element_layer3('src')
> - except:
> + l3_type = p.strip_element_layer2('type', p_index=idx)
> + sip = p.strip_element_layer3('dst', p_index=idx)
> + except Exception as e:
> continue
> # ipv4 packet
> if l3_type == 2048:
> @@ -753,10 +728,10 @@ class Tester(Crb):
> else:
> prev_id = t_idx
>
> - if compare_f(tx_pkts[txport][t_idx], recv_pkts[idx], "L4") is False:
> + if compare_f(tx_pkts[txport].pktgen.pkts[t_idx], recv_pkts[idx], "L4") is
> False:
> print "Pkt received index %d not match original " \
> "index %d" % (idx, t_idx)
> - print "Sent: %s" % strip_f(tx_pkts[txport][t_idx], "L4")
> + print "Sent: %s" %
> + strip_f(tx_pkts[txport].pktgen.pkts[t_idx], "L4")
> print "Recv: %s" % strip_f(recv_pkts[idx], "L4")
> return False
>
> @@ -776,70 +751,24 @@ class Tester(Crb):
> instance.__dict__ = self.ixia_packet_gen.__dict__
> instance.__dict__.update(current_attrs)
>
> - def sendpkt_bg(self, localPort, dst_mac):
> - """
> - loop to Send packet in background, should call stop_sendpkt_bg to stop it.
> - """
> - itf = self.get_interface(localPort)
> - src_mac = self.get_mac(localPort)
> - script_str = "from scapy.all import *\n" + \
> - "sendp([Ether(dst='%s', src='%s')/IP(len=46)], iface='%s', loop=1)\n" %
> (dst_mac, src_mac, itf)
> -
> - self.send_expect("rm -fr send_pkg_loop.py", "# ")
> - f = open("send_pkt_loop.py", "w")
> - f.write(script_str)
> - f.close()
> -
> - self.proc = subprocess.Popen(['python', 'send_pkt_loop.py'])
> -
> - def stop_sendpkt_bg(self):
> - """
> - stop send_pkt_loop in background
> - """
> - if self.proc:
> - self.proc.kill()
> - self.proc = None
> -
> - def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> + def tcpdump_sniff_packets(self, intf, count=0, filters=None, lldp_forbid=True):
> """
> Wrapper for packet module sniff_packets
> """
> # load functions in packet module
> - module = __import__("packet")
> - sniff_f = getattr(module, "sniff_packets")
> -
> - target=[]
> - target.append(self.get_ip_address())
> - target.append(self.get_username())
> - target.append(self.get_password())
> - return sniff_f(intf, count, timeout, filters, target)
> -
> - def load_tcpdump_sniff_pcap(self, index=''):
> - """
> - Wrapper for packet module load_sniff_pcap
> - """
> - # load functions in packet module
> - module = __import__("packet")
> - load_pcap_f = getattr(module, "load_sniff_pcap")
> -
> - target=[]
> - target.append(self.get_ip_address())
> - target.append(self.get_username())
> - target.append(self.get_password())
> - pcap = load_pcap_f(index, target)
> - self.session.copy_file_from(pcap)
> -
> - return pcap.split(os.sep)[-1]
> + packet = __import__("packet")
> + inst = packet.start_tcpdump(self, intf=intf, count=count, filters=filters,
> lldp_forbid=lldp_forbid)
> + return inst
>
> - def load_tcpdump_sniff_packets(self, index=''):
> + def load_tcpdump_sniff_packets(self, index='', timeout=1):
> """
> Wrapper for packet module load_pcapfile
> """
> # load functions in packet module
> packet = __import__("packet")
> - file = self.load_tcpdump_sniff_pcap(index)
> + p = packet.stop_and_load_tcpdump_packets(index,
> + timeout=timeout)
>
> - return packet.load_pcapfile(file)
> + return p
>
> def kill_all(self, killall=False):
> """
> --
> 2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dts] [PATCH V1] framework/tester: update tester module of dts
2019-09-27 18:05 ` [dts] [PATCH V1] framework/tester: update tester " Qimai Xiao
2019-10-08 2:22 ` Chen, Zhaoyan
@ 2019-10-12 5:30 ` Tu, Lijuan
1 sibling, 0 replies; 9+ messages in thread
From: Tu, Lijuan @ 2019-10-12 5:30 UTC (permalink / raw)
To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX
Applied, thanks
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Qimai Xiao
> Sent: Saturday, September 28, 2019 2:06 AM
> To: dts@dpdk.org
> Cc: Xiao, QimaiX <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] framework/tester: update tester module of dts
>
> update APIs related to packet module and rewrite func check_random_pkts
>
> Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
> ---
> framework/tester.py | 157 ++++++++++++--------------------------------
> 1 file changed, 43 insertions(+), 114 deletions(-)
>
> diff --git a/framework/tester.py b/framework/tester.py index
> 174d0b6..d7e74d4 100644
> --- a/framework/tester.py
> +++ b/framework/tester.py
> @@ -75,6 +75,11 @@ class Tester(Crb):
> self.re_run_time = 0
> self.pktgen = None
> self.ixia_packet_gen = None
> + self.tmp_file = '/tmp/tester/'
> + out = self.send_expect('ls -d %s' % self.tmp_file, '# ', verify=True)
> + if out == 2:
> + self.send_expect('mkdir -p %s' % self.tmp_file, '# ')
> +
>
> def init_ext_gen(self):
> """
> @@ -639,12 +644,12 @@ class Tester(Crb):
> else:
> return None
>
> - def parallel_transmit_ptks(self, send_f=None, intf='', pkts=[],
> interval=0.01):
> + def parallel_transmit_ptks(self, pkt=None, intf='', send_times=1,
> interval=0.01):
> """
> Callable function for parallel processes
> """
> print GREEN("Transmitting and sniffing packets, please wait few
> minutes...")
> - send_f(intf=intf, pkts=pkts, interval=interval)
> + return pkt.send_pkt_bg(crb=self, tx_port=intf,
> + count=send_times, loop=0, interval=interval)
>
> def check_random_pkts(self, portList, pktnum=2000, interval=0.01,
> allow_miss=True, seq_check=False, params=None):
> """
> @@ -653,79 +658,49 @@ class Tester(Crb):
> # load functions in packet module
> module = __import__("packet")
> pkt_c = getattr(module, "Packet")
> - send_f = getattr(module, "send_packets")
> compare_f = getattr(module, "compare_pktload")
> strip_f = getattr(module, "strip_pktload")
> - save_f = getattr(module, "save_packets")
> tx_pkts = {}
> rx_inst = {}
> # packet type random between tcp/udp/ipv6
> random_type = ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP']
> - pkt_minlen = {'TCP': 64, 'UDP': 64, 'IPv6_TCP': 74, 'IPv6_UDP': 64}
> - # at least wait 2 seconds
> - timeout = int(pktnum * (interval + 0.01)) + 2
> for txport, rxport in portList:
> - pkts = []
> txIntf = self.get_interface(txport)
> rxIntf = self.get_interface(rxport)
> print GREEN("Preparing transmit packets, please wait few minutes...")
> - for num in range(pktnum):
> - # chose random packet
> - pkt_type = random.choice(random_type)
> - pkt = pkt_c(pkt_type=pkt_type,
> - pkt_len=random.randint(pkt_minlen[pkt_type], 1514),
> - ran_payload=True)
> - # config packet if has parameters
> - if params and len(portList) == len(params):
> - for param in params:
> - layer, config = param
> - pkt.config_layer(layer, config)
> - # hardcode src/dst port for some protocol may cause issue
> - if "TCP" in pkt_type:
> - pkt.config_layer('tcp', {'src': 65535, 'dst': 65535})
> - else:
> - 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})
> + pkt = pkt_c()
> + pkt.generate_random_pkts(pktnum=pktnum,
> random_type=random_type, ip_increase=True, random_payload=True,
> + options={"layers_config": params})
>
> - pkts.append(pkt)
> - tx_pkts[txport] = pkts
> + tx_pkts[txport] = pkt
> + # sniff packets
> + inst = module.start_tcpdump(self, rxIntf, count=pktnum,
> + filters=[{'layer': 'network', 'config': {'srcport': '65535'}},
> + {'layer': 'network',
> + 'config': {'dstport': '65535'}}])
>
> - # send and sniff packets
> - save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> - inst = self.tcpdump_sniff_packets(intf=rxIntf, count=pktnum,
> timeout=timeout, filters=
> - [{'layer': 'network', 'config': {'srcport': '65535'}},
> - {'layer': 'network', 'config': {'dstport': '65535'}}])
> rx_inst[rxport] = inst
> -
> - # Transmit packet simultaneously
> - processes = []
> + filenames = []
> for txport, _ in portList:
> txIntf = self.get_interface(txport)
> - processes.append(Process(target = self.parallel_transmit_ptks,
> - args=(send_f, txIntf, tx_pkts[txport], interval)))
> -
> - for transmit_proc in processes:
> - transmit_proc.start()
> -
> - for transmit_proc in processes:
> - transmit_proc.join()
> -
> +
> + filenames.append(self.parallel_transmit_ptks(pkt=tx_pkts[txport],
> + intf=txIntf, send_times=1, interval=interval))
> # Verify all packets
> + sleep(interval * pktnum + 1)
> + flag = True
> + while flag:
> + for i in filenames:
> + flag = self.send_expect('ps -ef |grep %s|grep -v grep' % i,
> expected='# ')
> + if flag:
> + print('wait for the completion of sending pkts...')
> + sleep(1.5)
> + continue
> prev_id = -1
> for txport, rxport in portList:
> - recv_pkts = self.load_tcpdump_sniff_packets(rx_inst[rxport])
> -
> + p = module.stop_and_load_tcpdump_packets(rx_inst[rxport])
> + recv_pkts = p.pktgen.pkts
> # only report when received number not matched
> - if len(tx_pkts[txport]) > len(recv_pkts):
> - print ("Pkt number not matched,%d sent and %d received\n" \
> - % (len(tx_pkts[txport]), len(recv_pkts)))
> -
> + if len(tx_pkts[txport].pktgen.pkts) > len(recv_pkts):
> + print ("Pkt number not matched,%d sent and %d received\n" % (
> + len(tx_pkts[txport].pktgen.pkts), len(recv_pkts)))
> if allow_miss is False:
> return False
>
> @@ -733,9 +708,9 @@ class Tester(Crb):
> print GREEN("Comparing sniffed packets, please wait few minutes...")
> for idx in range(len(recv_pkts)):
> try:
> - l3_type = recv_pkts[idx].strip_element_layer2('type')
> - sip = recv_pkts[idx].strip_element_layer3('src')
> - except:
> + l3_type = p.strip_element_layer2('type', p_index=idx)
> + sip = p.strip_element_layer3('dst', p_index=idx)
> + except Exception as e:
> continue
> # ipv4 packet
> if l3_type == 2048:
> @@ -753,10 +728,10 @@ class Tester(Crb):
> else:
> prev_id = t_idx
>
> - if compare_f(tx_pkts[txport][t_idx], recv_pkts[idx], "L4") is False:
> + if compare_f(tx_pkts[txport].pktgen.pkts[t_idx], recv_pkts[idx],
> "L4") is False:
> print "Pkt received index %d not match original " \
> "index %d" % (idx, t_idx)
> - print "Sent: %s" % strip_f(tx_pkts[txport][t_idx], "L4")
> + print "Sent: %s" %
> + strip_f(tx_pkts[txport].pktgen.pkts[t_idx], "L4")
> print "Recv: %s" % strip_f(recv_pkts[idx], "L4")
> return False
>
> @@ -776,70 +751,24 @@ class Tester(Crb):
> instance.__dict__ = self.ixia_packet_gen.__dict__
> instance.__dict__.update(current_attrs)
>
> - def sendpkt_bg(self, localPort, dst_mac):
> - """
> - loop to Send packet in background, should call stop_sendpkt_bg to stop
> it.
> - """
> - itf = self.get_interface(localPort)
> - src_mac = self.get_mac(localPort)
> - script_str = "from scapy.all import *\n" + \
> - "sendp([Ether(dst='%s', src='%s')/IP(len=46)], iface='%s',
> loop=1)\n" % (dst_mac, src_mac, itf)
> -
> - self.send_expect("rm -fr send_pkg_loop.py", "# ")
> - f = open("send_pkt_loop.py", "w")
> - f.write(script_str)
> - f.close()
> -
> - self.proc = subprocess.Popen(['python', 'send_pkt_loop.py'])
> -
> - def stop_sendpkt_bg(self):
> - """
> - stop send_pkt_loop in background
> - """
> - if self.proc:
> - self.proc.kill()
> - self.proc = None
> -
> - def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> + def tcpdump_sniff_packets(self, intf, count=0, filters=None,
> lldp_forbid=True):
> """
> Wrapper for packet module sniff_packets
> """
> # load functions in packet module
> - module = __import__("packet")
> - sniff_f = getattr(module, "sniff_packets")
> -
> - target=[]
> - target.append(self.get_ip_address())
> - target.append(self.get_username())
> - target.append(self.get_password())
> - return sniff_f(intf, count, timeout, filters, target)
> -
> - def load_tcpdump_sniff_pcap(self, index=''):
> - """
> - Wrapper for packet module load_sniff_pcap
> - """
> - # load functions in packet module
> - module = __import__("packet")
> - load_pcap_f = getattr(module, "load_sniff_pcap")
> -
> - target=[]
> - target.append(self.get_ip_address())
> - target.append(self.get_username())
> - target.append(self.get_password())
> - pcap = load_pcap_f(index, target)
> - self.session.copy_file_from(pcap)
> -
> - return pcap.split(os.sep)[-1]
> + packet = __import__("packet")
> + inst = packet.start_tcpdump(self, intf=intf, count=count, filters=filters,
> lldp_forbid=lldp_forbid)
> + return inst
>
> - def load_tcpdump_sniff_packets(self, index=''):
> + def load_tcpdump_sniff_packets(self, index='', timeout=1):
> """
> Wrapper for packet module load_pcapfile
> """
> # load functions in packet module
> packet = __import__("packet")
> - file = self.load_tcpdump_sniff_pcap(index)
> + p = packet.stop_and_load_tcpdump_packets(index,
> + timeout=timeout)
>
> - return packet.load_pcapfile(file)
> + return p
>
> def kill_all(self, killall=False):
> """
> --
> 2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dts] [PATCH V1] tests/: update cases related to new framework
2019-09-27 18:05 [dts] [PATCH V1] tests/: update cases related to new framework Qimai Xiao
2019-09-27 18:05 ` [dts] [PATCH V1] framework/packet: update packet module of dts Qimai Xiao
2019-09-27 18:05 ` [dts] [PATCH V1] framework/tester: update tester " Qimai Xiao
@ 2019-10-08 2:22 ` Chen, Zhaoyan
2019-10-12 5:30 ` Tu, Lijuan
3 siblings, 0 replies; 9+ messages in thread
From: Chen, Zhaoyan @ 2019-10-08 2:22 UTC (permalink / raw)
To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX, Chen, Zhaoyan
Acked-by: Chen, Zhaoyan <zhaoyan.chen@intel.com>
Regards,
Zhaoyan Chen
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Qimai Xiao
> Sent: Saturday, September 28, 2019 2:06 AM
> To: dts@dpdk.org
> Cc: Xiao, QimaiX <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] tests/: update cases related to new framework
>
> update testsuits related to new framework api
>
> Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
> ---
> tests/TestSuite_checksum_offload.py | 35 +-
> tests/TestSuite_cloud_filter.py | 13 +-
> tests/TestSuite_ddp_mpls.py | 3 +-
> tests/TestSuite_dynamic_queue.py | 12 +-
> tests/TestSuite_etag.py | 2 +-
> tests/TestSuite_eventdev_pipeline.py | 14 +-
> tests/TestSuite_floating_veb.py | 4 +-
> tests/TestSuite_flow_classify_softnic.py | 2 +-
> tests/TestSuite_generic_flow_api.py | 528 ++++++++++--------
> tests/TestSuite_hotplug.py | 2 +-
> tests/TestSuite_iavf.py | 2 +-
> tests/TestSuite_ieee1588.py | 9 +-
> tests/TestSuite_ipfrag.py | 30 +-
> tests/TestSuite_ipgre.py | 80 +--
> tests/TestSuite_ipsec_gw_cryptodev_func.py | 29 +-
> tests/TestSuite_jumboframes.py | 2 +-
> tests/TestSuite_kernelpf_iavf.py | 4 +-
> tests/TestSuite_l2fwd_cryptodev_func.py | 11 +-
> tests/TestSuite_l3fwdacl.py | 39 +-
> tests/TestSuite_link_flowctrl.py | 1 +
> tests/TestSuite_link_status_interrupt.py | 2 +-
> tests/TestSuite_loadbalancer.py | 14 +-
> tests/TestSuite_mac_filter.py | 2 +-
> tests/TestSuite_netmap_compat.py | 6 +-
> tests/TestSuite_packet_capture.py | 222 +++-----
> tests/TestSuite_ptype_mapping.py | 2 +-
> .../TestSuite_pvp_multi_paths_performance.py | 4 +-
> ...lti_paths_vhost_single_core_performance.py | 4 +-
> ...ti_paths_virtio_single_core_performance.py | 4 +-
> ...Suite_pvp_qemu_multi_paths_port_restart.py | 13 +-
> tests/TestSuite_pvp_vhost_user_reconnect.py | 13 +-
> tests/TestSuite_pvp_virtio_bonding.py | 9 +-
> tests/TestSuite_pvp_virtio_user_4k_pages.py | 5 +-
> tests/TestSuite_queue_region.py | 4 +-
> tests/TestSuite_queue_start_stop.py | 4 +-
> tests/TestSuite_quota_watermark.py | 2 +-
> tests/TestSuite_runtime_vf_queue_number.py | 13 +-
> ...estSuite_runtime_vf_queue_number_kernel.py | 23 +-
> tests/TestSuite_rxtx_callbacks.py | 4 +-
> tests/TestSuite_scatter.py | 4 +-
> tests/TestSuite_short_live.py | 4 +-
> tests/TestSuite_skeleton.py | 4 +-
> tests/TestSuite_sriov_kvm.py | 11 +-
> tests/TestSuite_uni_pkt.py | 9 +-
> tests/TestSuite_userspace_ethtool.py | 34 +-
> tests/TestSuite_veb_switch.py | 4 +-
> tests/TestSuite_vf_daemon.py | 21 +-
> tests/TestSuite_vf_interrupt_pmd.py | 2 +-
> tests/TestSuite_vf_jumboframe.py | 2 +-
> tests/TestSuite_vf_kernel.py | 13 +-
> tests/TestSuite_vf_macfilter.py | 9 +-
> tests/TestSuite_vf_offload.py | 4 +-
> tests/TestSuite_vf_packet_rxtx.py | 19 +-
> tests/TestSuite_vf_port_start_stop.py | 86 +--
> tests/TestSuite_vf_rss.py | 3 +-
> tests/TestSuite_vf_vlan.py | 12 +-
> tests/TestSuite_vhost_enqueue_interrupt.py | 1 +
> tests/TestSuite_vhost_multi_queue_qemu.py | 15 +-
> tests/TestSuite_vhost_pmd_xstats.py | 2 +-
> tests/TestSuite_vhost_virtio_pmd_interrupt.py | 4 +-
> .../TestSuite_virtio_ipsec_cryptodev_func.py | 12 +-
> tests/TestSuite_vlan.py | 6 +-
> tests/TestSuite_vm2vm_virtio_pmd.py | 9 +-
> tests/TestSuite_vxlan.py | 143 ++---
> tests/TestSuite_vxlan_sample.py | 38 +-
> 65 files changed, 759 insertions(+), 884 deletions(-)
>
> diff --git a/tests/TestSuite_checksum_offload.py
> b/tests/TestSuite_checksum_offload.py
> index 7176cb9..c890671 100644
> --- a/tests/TestSuite_checksum_offload.py
> +++ b/tests/TestSuite_checksum_offload.py
> @@ -46,6 +46,7 @@ from test_case import TestCase
> from pmd_output import PmdOutput
> from test_capabilities import DRIVER_TEST_LACK_CAPA
> from pktgen import PacketGeneratorHelper
> +import packet
>
>
> class TestChecksumOffload(TestCase):
> @@ -110,7 +111,7 @@ class TestChecksumOffload(TestCase):
>
> for packet_type in packets_expected.keys():
> self.tester.send_expect("p = %s" % packets_expected[packet_type], ">>>")
> - out = self.tester.send_expect("p.show2()", ">>>")
> + out = self.tester.send_command("p.show2()", timeout=1)
> chksums = checksum_pattern.findall(out)
> chksum[packet_type] = chksums
>
> @@ -122,15 +123,11 @@ class TestChecksumOffload(TestCase):
> """
> Sends packets and check the checksum valid-flags.
> """
> - self.tester.scapy_foreground()
> self.dut.send_expect("start", "testpmd>")
> - mac = self.dut.get_mac_address(self.dut_ports[0])
> tx_interface =
> self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
> - self.tester.scapy_foreground()
> -
> for packet_type in packets_sent.keys():
> - self.tester.scapy_append('sendp([%s], iface="%s", count=4)' %
> (packets_sent[packet_type], tx_interface))
> - self.tester.scapy_execute()
> + self.pkt = packet.Packet(pkt_str=packets_sent[packet_type])
> + self.pkt.send_pkt(self.tester, tx_interface, count=4)
> out = self.dut.get_session_output(timeout=1)
> lines = out.split("\r\n")
>
> @@ -173,33 +170,21 @@ class TestChecksumOffload(TestCase):
> rx_interface =
> self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
>
> sniff_src = self.dut.get_mac_address(self.dut_ports[0])
> - checksum_pattern = re.compile("chksum.*=.*(0x[0-9a-z]+)")
> -
> - chksum = dict()
> result = dict()
>
> - self.tester.send_expect("scapy", ">>> ")
> -
> - for packet_type in packets_expected.keys():
> - self.tester.send_expect("p = %s" % packets_expected[packet_type], ">>>")
> - out = self.tester.send_expect("p.show2()", ">>>")
> - chksums = checksum_pattern.findall(out)
> - chksum[packet_type] = chksums
> -
> - self.tester.send_expect("exit()", "#")
> + chksum = self.get_chksum_values(packets_expected)
>
> inst = self.tester.tcpdump_sniff_packets(intf=rx_interface,
> count=len(packets_sent)*4,
> filters=[{'layer': 'ether', 'config': {'src': sniff_src}}])
>
> + self.pkt = packet.Packet()
> for packet_type in packets_sent.keys():
> - self.tester.scapy_append('sendp([%s], iface="%s", count=4)' %
> (packets_sent[packet_type], tx_interface))
> + self.pkt.append_pkt(packets_sent[packet_type])
> + self.pkt.send_pkt(crb=self.tester, tx_port=tx_interface, count=4)
>
> - self.tester.scapy_execute()
> p = self.tester.load_tcpdump_sniff_packets(inst)
> nr_packets = len(p)
> - reslist =
> [p[i].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.c
> hksum%") for i in range(nr_packets)]
> - out = string.join(reslist, ",")
> - packets_received = out.split(',')
> + packets_received =
> [p[i].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%")
> for i in range(nr_packets)]
> self.verify(len(packets_sent)*4 == len(packets_received), "Unexpected Packets
> Drop")
>
> for packet_received in packets_received:
> @@ -272,8 +257,6 @@ class TestChecksumOffload(TestCase):
> 'IPv6/UDP': 'Ether(dst="%s",
> src="52:00:00:00:00:00")/IPv6(src="::1")/UDP()/("X"*46)' % mac,
> 'IPv6/TCP': 'Ether(dst="%s",
> src="52:00:00:00:00:00")/IPv6(src="::1")/TCP()/("X"*46)' % mac}
>
> - result = dict()
> -
> self.checksum_enablehw(self.dut_ports[0])
>
> # get the packet checksum value
> diff --git a/tests/TestSuite_cloud_filter.py b/tests/TestSuite_cloud_filter.py
> index 74b3be7..51647ef 100644
> --- a/tests/TestSuite_cloud_filter.py
> +++ b/tests/TestSuite_cloud_filter.py
> @@ -12,7 +12,7 @@ import os
> from test_case import TestCase
> from pmd_output import PmdOutput
> from settings import HEADER_SIZE
> -from packet import Packet, load_pcapfile
> +from packet import Packet
>
> from scapy.layers.inet import UDP, IP
> from scapy.packet import split_layers, bind_layers
> @@ -195,7 +195,7 @@ class CloudFilterConfig(object):
>
> self.pkt.config_layer('ether', ether_cfg)
> self.pkt.config_layer('raw', {'payload': ['01'] * 18})
> - self.pkt.send_pkt(tx_port=self.case.tester_intf)
> + self.pkt.send_pkt(crb=self.case.tester, tx_port=self.case.tester_intf)
>
>
> class TestCloudFilter(TestCase):
> @@ -311,7 +311,6 @@ class TestCloudFilter(TestCase):
> if dpdk:
> cloud_cfg.transmit_packet()
> out = self.pmdout.get_output()
> - print out
> queue = cloud_cfg.cf_rule['queue']
> self.verify("queue %d" %
> queue in out, "Vxlan not received in queue %d" % queue)
> @@ -341,11 +340,11 @@ class TestCloudFilter(TestCase):
> time.sleep(2)
> # copy pcap to tester and then analyze
> self.dut.session.copy_file_from(tmp_file)
> - pkts = load_pcapfile(
> - filename="cloud_filter_%s.pcap" % self.vf_intf)
> + pkt = Packet()
> + pkt.read_pcapfile(filename="cloud_filter_%s.pcap" % self.vf_intf)
> self.verify(
> - len(pkts) == 1, "%d packet recevied on kernel VF" % len(pkts))
> - cap_pkt = pkts[0].pktgen.pkt
> + len(pkt) == 1, "%d packet recevied on kernel VF" % len(pkt))
> + cap_pkt = pkt[0]
> try:
> dport = cap_pkt[UDP].dport
> self.verify(dport == CLOUD_PORT,
> diff --git a/tests/TestSuite_ddp_mpls.py b/tests/TestSuite_ddp_mpls.py
> index 547e1c9..599e5cd 100644
> --- a/tests/TestSuite_ddp_mpls.py
> +++ b/tests/TestSuite_ddp_mpls.py
> @@ -95,11 +95,10 @@ class Testddp_mpls(TestCase):
> self.vm0_dut_ports = self.vm0_dut.get_ports('any')
> self.vm0_testpmd = PmdOutput(self.vm0_dut)
> self.env_done = True
> - eal_param = '-b %(vf0)s' % {'vf0': self.sriov_vfs_port[0].pci}
>
> self.dut_testpmd.start_testpmd(
> "Default","--port-topology=chained --txq=%s --rxq=%s"
> - % (PF_MAX_QUEUE, PF_MAX_QUEUE), eal_param=eal_param)
> + % (PF_MAX_QUEUE, PF_MAX_QUEUE))
> self.vm0_testpmd.start_testpmd(
> VM_CORES_MASK,"--port-topology=chained --txq=%s --rxq=%s"
> % (VF_MAX_QUEUE, VF_MAX_QUEUE))
> diff --git a/tests/TestSuite_dynamic_queue.py b/tests/TestSuite_dynamic_queue.py
> index dd05eab..1f86d1f 100644
> --- a/tests/TestSuite_dynamic_queue.py
> +++ b/tests/TestSuite_dynamic_queue.py
> @@ -63,14 +63,10 @@ class TestDynamicQueue(TestCase):
> Generate packets and send them to dut
> """
> mac = self.dut.get_mac_address(0)
> - for i in range(self.PF_QUEUE * 4):
> - j = i /256
> - k = i % 256
> - pkt = Packet(pkt_type='IP_RAW')
> - pkt.config_layer('ether', {'dst': mac})
> - pkt.config_layer(
> - 'ipv4', {'dst': '192.168.%d.%d' % (j, k), 'src': '191.168.0.1'})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pktnum = self.PF_QUEUE * 4
> + pkt = Packet()
> + pkt.generate_random_pkts(mac, pktnum=pktnum, random_type=['IP_RAW'])
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> def rxq_setup_test(self, chgflag=0):
> """
> diff --git a/tests/TestSuite_etag.py b/tests/TestSuite_etag.py
> index 45c5163..8a67222 100644
> --- a/tests/TestSuite_etag.py
> +++ b/tests/TestSuite_etag.py
> @@ -160,7 +160,7 @@ class TestEtag(TestCase):
> if pkt_configs:
> for layer in pkt_configs.keys():
> pkt.config_layer(layer, pkt_configs[layer])
> - pkt.send_pkt(tx_port=self.src_intf)
> + pkt.send_pkt(self.tester, tx_port=self.src_intf)
>
> # check vm testpmd packet received information
> if 'vm' in pkt_types[pkt_type].keys():
> diff --git a/tests/TestSuite_eventdev_pipeline.py
> b/tests/TestSuite_eventdev_pipeline.py
> index cee636a..9f723cd 100644
> --- a/tests/TestSuite_eventdev_pipeline.py
> +++ b/tests/TestSuite_eventdev_pipeline.py
> @@ -113,8 +113,8 @@ class TestEventdevPipeline(TestCase):
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> i = 0
> while len(pkts) != 0 and i <= len(pkts) - 1:
> - if pkts[i].pktgen.pkt.haslayer('DHCP'):
> - pkts.remove(pkts[i])
> + if pkts[i].haslayer('DHCP'):
> + pkts.pktgen.pkts.pop(i)
> i = i - 1
> i = i + 1
> return pkts
> @@ -152,7 +152,7 @@ class TestEventdevPipeline(TestCase):
> time.sleep(5)
>
> filt = [{'layer': 'ether', 'config': {'src': '%s' % self.s_mac}}]
> - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=15, filters=filt)
> + inst = self.tester.tcpdump_sniff_packets(self.rx_interface, filters=filt)
> self.tester.scapy_append('pkt=rdpcap("pipeline.pcap")')
> self.tester.scapy_append('sendp(pkt, iface="%s")' % self.tx_interface)
> self.tester.scapy_execute()
> @@ -169,13 +169,13 @@ class TestEventdevPipeline(TestCase):
> packet_index = 0
> for i in range(len(self.pkts)):
> pay_load = "0000%.2d" % (packet_index)
> - if self.pkts[i].pktgen.pkt['IP'].src == src_ip:
> - print self.pkts[i].pktgen.pkt.show
> + if self.pkts[i]['IP'].src == src_ip:
> + print(self.pkts[i].show)
> # get the start index load info of each queue
> if packet_index == 0:
> - packet_index = int(self.pkts[i].pktgen.pkt['Raw'].load[-2:])
> + packet_index = int(self.pkts[i]['Raw'].load[-2:])
> pay_load = "0000%.2d" % (packet_index)
> - self.verify(self.pkts[i].pktgen.pkt['Raw'].load == pay_load,
> + self.verify(self.pkts[i]['Raw'].load == pay_load,
> "The packets not ordered")
> packet_index = packet_index + 1
>
> diff --git a/tests/TestSuite_floating_veb.py b/tests/TestSuite_floating_veb.py
> index 40b0ce2..350d8fa 100644
> --- a/tests/TestSuite_floating_veb.py
> +++ b/tests/TestSuite_floating_veb.py
> @@ -120,12 +120,12 @@ class TestFloatingVEBSwitching(TestCase):
> pkt = Packet(pkt_type='VLAN_UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> pkt.config_layer('vlan', {'vlan': 1})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
> else:
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
>
> # Test cases.
> diff --git a/tests/TestSuite_flow_classify_softnic.py
> b/tests/TestSuite_flow_classify_softnic.py
> index 33f701e..a649a44 100644
> --- a/tests/TestSuite_flow_classify_softnic.py
> +++ b/tests/TestSuite_flow_classify_softnic.py
> @@ -72,7 +72,7 @@ class TestFlowClassifySoftnic(TestCase):
> file = 'flow_classify_softnic.tar.gz'
> src_file = r'./dep/%s' % file
> dst1 = '/tmp'
> - dst2 = os.path.join(self.dut.base_dir, 'drivers/net/softnic')
> + dst2 = '/root/dpdk/drivers/net/softnic'
> self.dut.session.copy_file_to(src_file, dst1)
> self.dut.send_expect("tar xf %s/%s -C %s" % (dst1, file, dst2), "#", 30)
>
> diff --git a/tests/TestSuite_generic_flow_api.py
> b/tests/TestSuite_generic_flow_api.py
> index 61af86c..e0a4aa6 100644
> --- a/tests/TestSuite_generic_flow_api.py
> +++ b/tests/TestSuite_generic_flow_api.py
> @@ -49,7 +49,7 @@ from crb import Crb
> from virt_dut import VirtDut
> from project_dpdk import DPDKdut
> from dut import Dut
> -from packet import Packet
> +import packet
>
> import os
> import random
> @@ -99,6 +99,7 @@ class TestGeneric_flow_api(TestCase):
> self.inner_mac = "00:11:22:33:44:66"
> self.wrong_mac = "00:11:22:33:44:77"
> self.vf_flag = 0
> + self.pkt_obj = packet.Packet()
>
> def set_up(self):
> """
> @@ -162,8 +163,8 @@ class TestGeneric_flow_api(TestCase):
> """
> verify the packet to the expected queue or be dropped
> """
> - self.tester.scapy_execute()
> - time.sleep(2)
> + # self.tester.scapy_execute()
> + # time.sleep(2)
> verify_mac = verify_mac.upper()
>
> if self.vf_flag == 1:
> @@ -207,7 +208,7 @@ class TestGeneric_flow_api(TestCase):
> queue_index = 0
> find_index = False
> for i in range(len(m)):
> - cur = out_info.find(m[i], all_queue_index[i-1] + len(m[i-1]) if i > 0 else 0)
> + cur = out_info.find(m[i], all_queue_index[i - 1] + len(m[i - 1]) if i > 0 else 0)
> if cur > mac_index:
> queue_index = i - 1
> find_index = True
> @@ -255,8 +256,8 @@ class TestGeneric_flow_api(TestCase):
> # caculate the rule number created.
> rule_created = self.flow_test_process(flow_process, flow_action)
> if rule_created:
> - rule_num += 1
> - extra_packet.append(flow_process['extrapacket'])
> + rule_num += 1
> + extra_packet.append(flow_process['extrapacket'])
> # Configure a return value.
> extrapkt_rulenum = {'extrapacket': extra_packet, 'rulenum': rule_num, 'queue':
> expected_queue}
>
> @@ -286,26 +287,34 @@ class TestGeneric_flow_api(TestCase):
> if "validate" in flow_cmd:
> # ethertype invalid or queue id exceeds max queue number.
> if "86dd" in flow_cmd or "0800" in flow_cmd or "index %s" % str(MAX_QUEUE
> + 1) in flow_cmd:
> - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortpark_TLV", "niantic", "kawela_4", "kawela", "bartonhills", "twinville", "sagepond",
> "sageville", "powerville"]:
> + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortpark_TLV",
> + "niantic", "kawela_4", "kawela", "bartonhills", "twinville",
> "sagepond", "sageville",
> + "powerville"]:
> self.dut.send_expect(flow_cmd, "error")
> elif "type is 0x8100" in flow_cmd:
> if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortpark_TLV"]:
> self.dut.send_expect(flow_cmd, "error")
> # vf queue id exceeds max vf queue number.
> - elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or ("vf0" in
> flow_action['actions']) or ("vf1" in flow_action['actions'])) and (("index %s" %
> str(MAX_VFQUEUE + 1)) in flow_cmd):
> + elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or (
> + "vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and (
> + ("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd):
> self.dut.send_expect(flow_cmd, "error")
> else:
> self.dut.send_expect(flow_cmd, "validated")
> elif "create" in flow_cmd:
> # ethertype invalid or queue id exceeds max queue number.
> if "86dd" in flow_cmd or "0800" in flow_cmd or "index %s" % str(MAX_QUEUE
> + 1) in flow_cmd:
> - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortpark_TLV", "niantic", "kawela_4", "kawela", "bartonhills", "twinville", "sagepond",
> "sageville", "powerville"]:
> + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortpark_TLV",
> + "niantic", "kawela_4", "kawela", "bartonhills", "twinville",
> "sagepond", "sageville",
> + "powerville"]:
> self.dut.send_expect(flow_cmd, "error")
> elif "type is 0x8100" in flow_cmd:
> if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortpark_TLV"]:
> self.dut.send_expect(flow_cmd, "error")
> # vf queue id exceeds max vf queue number.
> - elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or ("vf0" in
> flow_action['actions']) or ("vf1" in flow_action['actions'])) and (("index %s" %
> str(MAX_VFQUEUE + 1)) in flow_cmd):
> + elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or (
> + "vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and (
> + ("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd):
> self.dut.send_expect(flow_cmd, "error")
> else:
> self.dut.send_expect(flow_cmd, "created")
> @@ -318,7 +327,7 @@ class TestGeneric_flow_api(TestCase):
> self.load_module("nvgre")
>
> # The rule is created successfully, so send the consistent packet.
> - self.tester.scapy_append('sendp(%s, iface="%s")' % (flow_pkt,
> self.tester_itf))
> + self.sendpkt(pktstr=flow_pkt)
> cur_mac = re.search("dst='(\S\S:\S\S:\S\S:\S\S:\S\S:\S\S)'", flow_pkt)
> cur_mac = cur_mac.group(1)
> if ("queue" in flow_action['actions']) or ("passthru" in flow_action['actions']):
> @@ -353,7 +362,7 @@ class TestGeneric_flow_api(TestCase):
> if is_ipv4 == True:
> return '.'.join('%s' % random.randint(0, 255) for i in range(4))
> else:
> - return ':'.join('{:x}'.format(random.randint(0, 2**16 - 1)) for i in range(8))
> + return ':'.join('{:x}'.format(random.randint(0, 2 ** 16 - 1)) for i in range(8))
>
> def generate_random_int(self, minimum, maximum):
> return random.randint(minimum, maximum)
> @@ -376,7 +385,9 @@ class TestGeneric_flow_api(TestCase):
> cmd_fmt = "flow %(create)s 0 ingress pattern %(flow)s / end
> actions %(action)s end"
> # Record the elements of the rule, ready for the configuration
> # of packets inconsistent to the rule.
> - extrapacket = {'vlan': '', 'etag': '', 'ipv4': '', 'ipv6': '', 'sip': '', 'dip': '', 'proto': '', 'tos': '',
> 'ttl': '', 'tcp': '', 'udp': '', 'sctp': '', 'sport': '', 'dport': '', 'vni': '', 'tni': '', 'ineth': '', 'invlan': ''}
> + extrapacket = {'vlan': '', 'etag': '', 'ipv4': '', 'ipv6': '', 'sip': '', 'dip': '', 'proto': '', 'tos':
> '',
> + 'ttl': '', 'tcp': '', 'udp': '', 'sctp': '', 'sport': '', 'dport': '', 'vni': '', 'tni': '',
> + 'ineth': '', 'invlan': ''}
> # Define the packet string, which is consistent to the flow rule.
> if ('vf0' in flows) or ('vf1' in flows) or ('vf0' in actions) or ('vf1' in actions):
> pkt = "Ether(dst='%s')" % self.wrong_mac
> @@ -630,14 +641,24 @@ class TestGeneric_flow_api(TestCase):
> elif action == "mark":
> act_str += "mark id 3 / "
> # Configure the whole flow rule.
> - command = cmd_fmt % { "create": create,
> - "flow": flow_str,
> - "action": act_str}
> + command = cmd_fmt % {"create": create,
> + "flow": flow_str,
> + "action": act_str}
> # Configure the return value.
> flow_process = {'cmd': command, 'pkt': pkt, 'queue': index, 'extrapacket':
> extrapacket}
>
> return flow_process
>
> + def sendpkt(self, pktstr, count=1):
> + import sys
> + py_version = sys.version
> + if py_version.startswith('3.'):
> + self.pkt_obj.pktgen.pkts.clear()
> + else:
> + del self.pkt_obj.pktgen.pkts[:]
> + self.pkt_obj.append_pkt(pktstr)
> + self.pkt_obj.send_pkt(self.tester, tx_port=self.tester_itf, count=count)
> +
> def test_syn_filter(self):
> """
> Only supported by ixgbe and igb.
> @@ -653,14 +674,13 @@ class TestGeneric_flow_api(TestCase):
>
> # create the flow rules
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 / tcp flags spec 0x02 flags mask 0x02
> / end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 / tcp flags spec 0x02 flags mask 0x02
> / end actions queue index 3 / end",
> + "created")
> # send the packets and verify the results
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="S")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> - self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.pf_mac)
> + self.sendpkt(pktstr='Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="S")/Raw("x" * 20)' % self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="PA")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.pf_mac)
> + self.sendpkt(pktstr='Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="PA")/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
>
> # the ipv6 rule is conflicted with ipv4 rule.
> @@ -668,14 +688,13 @@ class TestGeneric_flow_api(TestCase):
>
> # create the flow rules
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv6 / tcp flags spec 0x02 flags mask 0x02
> / end actions queue index 4 / end", "created")
> + "flow create 0 ingress pattern eth / ipv6 / tcp flags spec 0x02 flags mask 0x02
> / end actions queue index 4 / end",
> + "created")
> # send the packets and verify the results
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="S")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="S")/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="PA")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="PA")/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
>
> self.verify_rulenum(1)
> @@ -695,21 +714,24 @@ class TestGeneric_flow_api(TestCase):
> # create the flow rules
> basic_flow_actions = [
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'udp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'sctp', 'sport', 'dport'],
> 'actions': ['queue']}
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'sctp', 'sport', 'dport'],
> + 'actions': ['queue']}
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> # send the packets inconsistent to the rules.
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[0]['dip'], extra_packet[0]['sip'],
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[0]['dip'], extra_packet[0]['sip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[3]['dip'], extra_packet[3]['sip'], extra_packet[3]['sport'],
> extra_packet[3]['dport'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)' % (
> + self.pf_mac, extra_packet[3]['dip'], extra_packet[3]['sip'],
> extra_packet[3]['sport'],
> + extra_packet[3]['dport']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[0]['sip'], extra_packet[0]['dip'], extra_packet[3]['sport'],
> extra_packet[3]['dport'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[0]['sip'], extra_packet[0]['dip'], extra_packet[3]['sport'],
> + extra_packet[3]['dport']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.pf_mac)
>
> rule_num = extrapkt_rulenum['rulenum']
> @@ -736,11 +758,10 @@ class TestGeneric_flow_api(TestCase):
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> # send the packets inconsistent to the rules.
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=22,dport=24)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=22,dport=24)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=32,dport=34)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=32,dport=34)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -792,8 +813,8 @@ class TestGeneric_flow_api(TestCase):
> {'create': 'create', 'flows': ['ether', 'lldp'], 'actions': ['queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s",type=0x88E5)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s",type="0x88E5")/Raw("x" * 20)' %
> self.pf_mac)
> +
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -837,8 +858,7 @@ class TestGeneric_flow_api(TestCase):
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1BR(GRP=0x2, ECIDbase=%s)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[0]['etag'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1BR(GRP=0x2, ECIDbase=%s)/Raw("x" *
> 20)' % (self.pf_mac, extra_packet[0]['etag']))
> self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -911,47 +931,45 @@ class TestGeneric_flow_api(TestCase):
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> # send the packets with dst/src ip and dst/src port.
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=3)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[0]['vlan'], self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=3)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3)/UDP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[1]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3)/UDP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[1]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][1], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[2]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[2]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][2], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3, ttl=3)/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[3]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3, ttl=3)/SCTP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[3]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][3], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[3]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[3]['vlan']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/UDP()/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[2]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/UDP()/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[2]['vlan']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3, ttl=3)/SCTP(sport=44,dport=45,tag=1)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[6]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3, ttl=3)/SCTP(sport=44,dport=45,tag=1)/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[6]['vlan']))
> self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3,
> ttl=3)/UDP(sport=44,dport=45)/SCTPChunkData(data="X" * 20)], iface="%s")' %
> (self.outer_mac, extra_packet[7]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5", dst="192.168.0.6",
> tos=3, ttl=3)/UDP(sport=44,dport=45)/SCTPChunkData(data="X" * 20)' % (
> + self.outer_mac, extra_packet[7]['vlan']))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=1, nh=5, hlim=10)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[8]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=1,
> nh=5, hlim=10)/Raw("x" * 20)' % (
> + self.pf_mac, extra_packet[8]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][8], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[9]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[9]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][9], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[10]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2,
> hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)' % (
> + self.pf_mac, extra_packet[10]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][10], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=4, nh=132,
> hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[11]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=4,
> nh=132, hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" *
> 20)' % (
> + self.pf_mac, extra_packet[11]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][11], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=4, nh=132,
> hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[14]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=4,
> nh=132, hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" *
> 20)' % (
> + self.pf_mac, extra_packet[14]['vlan']))
> self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)],
> iface="%s")' % (self.outer_mac, extra_packet[15]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2", tc=2,
> hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[15]['vlan']))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.outer_mac)
>
> rule_num = extrapkt_rulenum['rulenum']
> @@ -963,7 +981,8 @@ class TestGeneric_flow_api(TestCase):
> """
> self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville",
> "fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support fdir
> ipv4 filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support fdir ipv4 filter" % self.nic)
> # i40e
> if (self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]):
> @@ -990,22 +1009,33 @@ class TestGeneric_flow_api(TestCase):
> # create the flow rules
> basic_flow_actions = [
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport',
> 'dport', 'tag'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport',
> 'dport', 'tag'], 'actions': ['drop']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'],
> + 'actions': ['drop']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'vf0'], 'actions': ['invalid']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'vf0'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport',
> 'dport', 'tag', 'vf1'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport',
> 'dport', 'tag'], 'actions': ['passthru', 'flag']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'],
> 'actions': ['queue', 'flag']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'],
> 'actions': ['queue', 'mark']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag', 'vf1'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport', 'tag'],
> + 'actions': ['passthru', 'flag']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport', 'dport'],
> + 'actions': ['queue', 'flag']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue', 'mark']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto'], 'actions': ['passthru',
> 'mark']}
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4",
> proto=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['proto'],
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4",
> proto=%s)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['proto']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1021,29 +1051,35 @@ class TestGeneric_flow_api(TestCase):
> if (self.nic in ["sagepond", "sageville"]):
> # create the flow rules
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'], 'actions':
> ['drop']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> + 'actions': ['drop']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[2]['sip'], extra_packet[2]['dip'], extra_packet[2]['dport'],
> extra_packet[2]['sport'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)'% (
> + self.pf_mac, extra_packet[2]['sip'], extra_packet[2]['dip'],
> extra_packet[2]['dport'],
> + extra_packet[2]['sport']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> else:
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'], 'actions':
> ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp'], 'actions': ['queue']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp'], 'actions': ['drop']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP()/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[2]['dip'], extra_packet[2]['sip'],
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP()/Raw("x" *
> 20)' % (self.pf_mac, extra_packet[2]['dip'], extra_packet[2]['sip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1054,7 +1090,8 @@ class TestGeneric_flow_api(TestCase):
> """
> self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville",
> "fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support fdir
> ipv6 filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support fdir ipv6 filter" % self.nic)
> # i40e
> if (self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]):
> @@ -1077,19 +1114,30 @@ class TestGeneric_flow_api(TestCase):
>
> # create the flow rules
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'udp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport',
> 'dport', 'tag'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop', 'vf0'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport',
> 'dport', 'vf1'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport',
> 'dport', 'tag'], 'actions': ['drop']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport',
> 'dport', 'vf1'], 'actions': ['drop']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'udp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport', 'tag'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop', 'vf0'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport', 'vf1'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport', 'tag'],
> + 'actions': ['drop']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport', 'vf1'],
> + 'actions': ['drop']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[1]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[1]['vlan']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1106,51 +1154,55 @@ class TestGeneric_flow_api(TestCase):
> basic_flow_actions = [
> {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip'], 'actions': ['queue']},
> {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp'], 'actions':
> ['queue']},
> {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp'], 'actions':
> ['queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh
> mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end
> actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh
> mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end
> actions queue index 1 / end",
> + "created")
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2",nh=132)/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2",nh=132)/SCTP()/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP()/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> - self.verify_rulenum(rule_num+1)
> + self.verify_rulenum(rule_num + 1)
> elif (self.nic in ["sagepond", "sageville"]):
> # create the flow rules
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> + 'actions': ['queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh
> mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end
> actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5 thresh
> mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is 23 / end
> actions queue index 1 / end",
> + "created")
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="%s", dst="%s",
> nh=132)/SCTP(sport=32,dport=33,tag=1)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[3]['sip'], extra_packet[3]['dip'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="%s", dst="%s",
> nh=132)/SCTP(sport=32,dport=33,tag=1)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[3]['sip'], extra_packet[3]['dip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s",
> proto=132)/SCTP(sport=32,dport=33)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[4]['dip'], extra_packet[4]['sip'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s",
> proto=132)/SCTP(sport=32,dport=33)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[4]['dip'], extra_packet[4]['sip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> - self.verify_rulenum(rule_num+1)
> + self.verify_rulenum(rule_num + 1)
>
> def test_fdir_for_flexbytes(self):
> """
> @@ -1158,7 +1210,8 @@ class TestGeneric_flow_api(TestCase):
> """
> self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville",
> "fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support fdir
> flexbytes filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support fdir flexbytes filter" % self.nic)
> # i40e
> if (self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]):
> @@ -1171,46 +1224,47 @@ class TestGeneric_flow_api(TestCase):
> # creat the flow rules
> # l2-payload exceeds the max length of raw match is 16bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern
> is abcdefghijklmnopq / end actions queue index 1 / end", "Exceeds maxmial payload
> limit")
> + "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern
> is abcdefghijklmnopq / end actions queue index 1 / end",
> + "Exceeds maxmial payload limit")
> # l2-payload equal the max length of raw match is 16bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern
> is abcdefghijklmnop / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1 pattern
> is abcdefghijklmnop / end actions queue index 1 / end",
> + "created")
> # ipv4-other the most 3 fields can be matched, and the max sum bytes of the
> three fields is 16 bytes.
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / vlan tci is 4095 / ipv4 proto is 255 ttl is
> 40 / raw relative is 1 offset is 2 pattern is ab / raw relative is 1 offset is 10 pattern is
> abcdefghij / raw relative is 1 offset is 0 pattern is abcd / end actions queue index 2 /
> end", "created")
> + "flow create 0 ingress pattern eth / vlan tci is 4095 / ipv4 proto is 255 ttl is
> 40 / raw relative is 1 offset is 2 pattern is ab / raw relative is 1 offset is 10 pattern is
> abcdefghij / raw relative is 1 offset is 0 pattern is abcd / end actions queue index 2 /
> end",
> + "created")
> # ipv4-udp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / udp src
> is 22 dst is 23 / raw relative is 1 offset is 2 pattern is fhds / end actions queue index
> 3 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / udp
> src is 22 dst is 23 / raw relative is 1 offset is 2 pattern is fhds / end actions queue
> index 3 / end",
> + "created")
> # ipv4-tcp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 tos is 4
> ttl is 3 / tcp src is 32 dst is 33 / raw relative is 1 offset is 2 pattern is hijk / end
> actions queue index 4 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 tos is 4
> ttl is 3 / tcp src is 32 dst is 33 / raw relative is 1 offset is 2 pattern is hijk / end
> actions queue index 4 / end",
> + "created")
> # ipv4-sctp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / sctp src
> is 42 / raw relative is 1 offset is 2 pattern is abcd / end actions queue index 5 / end",
> "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 / sctp
> src is 42 / raw relative is 1 offset is 2 pattern is abcd / end actions queue index 5 /
> end",
> + "created")
>
> # send the packets and verify the results
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s", type=0x0807)/Raw(load="abcdefghijklmnop")],
> iface="%s")' % (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s",
> type=0x0807)/Raw(load="abcdefghijklmnop")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=4095)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=255,
> ttl=40)/Raw(load="xxabxxxxxxxxxxabcdefghijabcdefg")], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=4095)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=255,
> ttl=40)/Raw(load="xxabxxxxxxxxxxabcdefghijabcdefg")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/UDP(sport=22,dport=23)/Raw(load="fhfhdsdsfwef")], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/UDP(sport=22,dport=23)/Raw(load="fhfhdsdsfwef")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5", tos=4,
> ttl=3)/TCP(sport=32,dport=33)/Raw(load="fhhijk")], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5", tos=4,
> ttl=3)/TCP(sport=32,dport=33)/Raw(load="fhhijk")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.pf_mac)
> -
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabcdefghijklmnopqrs
> t")], iface="%s")' % (self.pf_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabcdefghijklmnopqrs
> t")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="5",
> verify_mac=self.pf_mac)
> -
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabxxxabcddxxabcdefg
> hijklmn")], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabxxxabcddxxabcdefg
> hijklmn")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.verify_rulenum(5)
> @@ -1226,11 +1280,12 @@ class TestGeneric_flow_api(TestCase):
>
> # ipv6-tcp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / vlan tci is 1 / ipv6 src is 2001::1 dst is
> 2001::2 tc is 3 hop is 30 / tcp src is 32 dst is 33 / raw relative is 1 offset is 0 pattern
> is hijk / raw relative is 1 offset is 8 pattern is abcdefgh / end actions queue index 6 /
> end", "created")
> + "flow create 0 ingress pattern eth / vlan tci is 1 / ipv6 src is 2001::1 dst is
> 2001::2 tc is 3 hop is 30 / tcp src is 32 dst is 33 / raw relative is 1 offset is 0 pattern
> is hijk / raw relative is 1 offset is 8 pattern is abcdefgh / end actions queue index 6 /
> end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=1)/IPv6(src="2001::1",
> dst="2001::2", tc=3,
> hlim=30)/TCP(sport=32,dport=33)/Raw(load="hijkabcdefghabcdefghijklmn")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=1)/IPv6(src="2001::1", dst="2001::2", tc=3,
> hlim=30)/TCP(sport=32,dport=33)/Raw(load="hijkabcdefghabcdefghijklmn")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="6",
> verify_mac=self.outer_mac)
>
> # ixgbe
> @@ -1243,11 +1298,12 @@ class TestGeneric_flow_api(TestCase):
>
> # ipv4-udp-flexbytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.1 dst is
> 192.168.0.2 / udp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 44 limit is
> 0 pattern is 86 / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.1 dst is
> 192.168.0.2 / udp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 44 limit is
> 0 pattern is 86 / end actions queue index 1 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=24,dport=25)/Raw(load="xx86ddef")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=24,dport=25)/Raw(load="xx86ddef")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.outer_mac)
>
> self.dut.send_expect("quit", "# ")
> @@ -1262,15 +1318,15 @@ class TestGeneric_flow_api(TestCase):
>
> # ipv4-tcp-flexbytes spec-mask
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.3 dst is
> 192.168.0.4 / tcp src is 22 dst is 23 / raw relative spec 0 relative mask 1 search spec
> 0 search mask 1 offset spec 54 offset mask 0xffffffff limit spec 0 limit mask 0xffff
> pattern is ab pattern is cd / end actions queue index 2 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.3 dst is
> 192.168.0.4 / tcp src is 22 dst is 23 / raw relative spec 0 relative mask 1 search spec
> 0 search mask 1 offset spec 54 offset mask 0xffffffff limit spec 0 limit mask 0xffff
> pattern is ab pattern is cd / end actions queue index 2 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="abcdxxx")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="abcdxxx")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> -
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="cdcdxxx")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="cdcdxxx")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.outer_mac)
>
> self.dut.send_expect("quit", "# ")
> @@ -1286,17 +1342,19 @@ class TestGeneric_flow_api(TestCase):
> # ipv4-sctp-flexbytes
> if (self.nic in ["sagepond", "sageville"]):
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp src is 24 dst is 25 / raw relative is 0 search is 0
> offset is 48 limit is 0 pattern is ab / end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp src is 24 dst is 25 / raw relative is 0 search is 0
> offset is 48 limit is 0 pattern is ab / end actions queue index 3 / end",
> + "created")
> else:
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp / raw relative is 0 search is 0 offset is 48 limit is
> 0 pattern is ab / end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp / raw relative is 0 search is 0 offset is 48 limit is
> 0 pattern is ab / end actions queue index 3 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxabcdef")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxabcdef")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxaccdef")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxaccdef")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> # ipv6-other-flexbytes
> @@ -1311,12 +1369,13 @@ class TestGeneric_flow_api(TestCase):
> time.sleep(2)
>
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh is 6 / ipv6 src is 2001::1 dst is
> 2001::2 / raw relative is 0 search is 0 offset is 56 limit is 0 pattern is 86 / end actions
> queue index 4 / end", "created")
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xx86abcd")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + "flow create 0 ingress pattern fuzzy thresh is 6 / ipv6 src is 2001::1 dst is
> 2001::2 / raw relative is 0 search is 0 offset is 56 limit is 0 pattern is 86 / end actions
> queue index 4 / end",
> + "created")
> + self.sendpkt(
> + 'Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xx86abcd")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxx86abcd")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxx86abcd")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> def test_flexbytes_filter(self):
> @@ -1334,79 +1393,77 @@ class TestGeneric_flow_api(TestCase):
> # create the flow rules
> # l2_payload
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 14 pattern is fhds /
> end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 14 pattern is fhds /
> end actions queue index 1 / end",
> + "created")
> # ipv4 packet
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 34 pattern is ab / end
> actions queue index 2 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 34 pattern is ab / end
> actions queue index 2 / end",
> + "created")
> # ipv6 packet
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 58 pattern is efgh /
> end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 58 pattern is efgh /
> end actions queue index 3 / end",
> + "created")
> # 3 fields relative is 0
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 38 pattern is ab / raw
> relative is 0 offset is 34 pattern is cd / raw relative is 0 offset is 42 pattern is efgh /
> end actions queue index 4 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 38 pattern is ab / raw
> relative is 0 offset is 34 pattern is cd / raw relative is 0 offset is 42 pattern is efgh /
> end actions queue index 4 / end",
> + "created")
> # 4 fields relative is 0 and 1
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 48 pattern is ab / raw
> relative is 1 offset is 0 pattern is cd / raw relative is 0 offset is 44 pattern is efgh /
> raw relative is 1 offset is 10 pattern is hijklmnopq / end actions queue index 5 / end",
> "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 48 pattern is ab / raw
> relative is 1 offset is 0 pattern is cd / raw relative is 0 offset is 44 pattern is efgh /
> raw relative is 1 offset is 10 pattern is hijklmnopq / end actions queue index 5 / end",
> + "created")
> # 3 fields offset confilict
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 64 pattern is ab / raw
> relative is 1 offset is 4 pattern is cdefgh / raw relative is 0 offset is 68 pattern is klmn
> / end actions queue index 6 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 64 pattern is ab / raw
> relative is 1 offset is 4 pattern is cdefgh / raw relative is 0 offset is 68 pattern is klmn
> / end actions queue index 6 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Raw(load="fhdsab")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Raw(load="fhdsab")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Raw(load="afhdsb")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Raw(load="afhdsb")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="abcdef")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="abcdef")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxxxefgh")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxxxefgh")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(sport=32,dport=33)/Raw(load="abcdefgh")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(sport=32,dport=33)/Raw(load="abcdefgh")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="cdxxabxxefghxxxx")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="cdxxabxxefghxxxx")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2", tos=4,
> ttl=3)/UDP(sport=32,dport=33)/Raw(load="xxefghabcdxxxxxxhijklmnopqxxxx")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2", tos=4,
> ttl=3)/UDP(sport=32,dport=33)/Raw(load="xxefghabcdxxxxxxhijklmnopqxxxx")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="5",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklmnefgh"
> )], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklmnefgh"
> )' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="6",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklcdefgh")
> ], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklcdefgh")
> ' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.dut.send_expect("flow flush 0", "testpmd> ", 120)
>
> # 1 field 128bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 128 pattern is ab / end
> actions queue index 1 / end", "Failed to create flow")
> + "flow create 0 ingress pattern raw relative is 0 offset is 128 pattern is ab /
> end actions queue index 1 / end",
> + "Failed to create flow")
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is abcd /
> end actions queue index 1 / end", "Failed to create flow")
> + "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is abcd /
> end actions queue index 1 / end",
> + "Failed to create flow")
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is ab / end
> actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is ab /
> end actions queue index 1 / end",
> + "created")
> # 2 field 128bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw
> relative is 1 offset is 58 pattern is cd / end actions queue index 2 / end", "Failed to
> create flow")
> + "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw
> relative is 1 offset is 58 pattern is cd / end actions queue index 2 / end",
> + "Failed to create flow")
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw
> relative is 1 offset is 56 pattern is cd / end actions queue index 2 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is ab / raw
> relative is 1 offset is 56 pattern is cd / end actions queue index 2 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxab")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxab")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcb")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcb")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcd")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcd")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxce")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxce")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.verify_rulenum(2)
> @@ -1481,7 +1538,8 @@ class TestGeneric_flow_api(TestCase):
> only supported by i40e
> """
> self.verify(self.nic in ["fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support
> tunnel vxlan filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support tunnel vxlan filter" % self.nic)
>
> self.setup_env()
> self.pmdout.start_testpmd("%s" % self.pf_cores, "--disable-rss --rxq=%d --
> txq=%d" % (MAX_QUEUE+1, MAX_QUEUE+1), "-w %s --file-prefix=pf --socket-mem
> 1024,1024 --legacy-mem" % self.pf_pci)
> @@ -1506,32 +1564,35 @@ class TestGeneric_flow_api(TestCase):
> {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'ineth'], 'actions': ['pf', 'queue']},
> {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions': ['pf',
> 'queue']},
> {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'ineth', 'invlan'], 'actions': ['pf',
> 'queue']},
> - {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'], 'actions':
> ['pf', 'queue']},
> - {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions':
> ['pf', 'queue']},
> - {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'], 'actions':
> ['vf0', 'queue']},
> - {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions':
> ['vf1', 'queue']},
> + {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'],
> + 'actions': ['pf', 'queue']},
> + {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'],
> + 'actions': ['pf', 'queue']},
> + {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'],
> + 'actions': ['vf0', 'queue']},
> + {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'],
> + 'actions': ['vf1', 'queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN()/Ether(dst="%s")/Dot1Q(vlan=11)/I
> P()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.inner_mac,
> self.tester_itf))
> - self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.outer_mac)
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN()/Ether(dst="%s")/Dot1Q(vlan=
> 11)/IP()/TCP()/Raw("x" * 20)' % (self.outer_mac, self.inner_mac))
> + self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0],
> + verify_mac=self.outer_mac)
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=5)/Ether(dst="%s")/IP()/TCP()/
> Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.wrong_mac, self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=5)/Ether(dst="%s")/IP()/T
> CP()/Raw("x" * 20)' % (self.outer_mac, self.wrong_mac))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/Dot1Q(vla
> n=%s)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac,
> extra_packet[5]['vni'], self.wrong_mac, extra_packet[5]['invlan'], self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/Dot1
> Q(vlan=%s)/IP()/TCP()/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[5]['vni'], self.wrong_mac,
> extra_packet[5]['invlan']))
> self.verify_result("vf0", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/IP()/TCP(
> )/Raw("x" * 20)], iface="%s")' % (self.wrong_mac, extra_packet[6]['vni'],
> self.inner_mac, self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/IP()/
> TCP()/Raw("x" * 20)' % (
> + self.wrong_mac, extra_packet[6]['vni'], self.inner_mac))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.wrong_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1541,7 +1602,8 @@ class TestGeneric_flow_api(TestCase):
> only supported by i40e
> """
> self.verify(self.nic in ["fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not support
> tunnel nvgre filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support tunnel nvgre filter" % self.nic)
>
> self.setup_env()
> self.pmdout.start_testpmd("%s" % self.pf_cores, "--disable-rss --rxq=%d --
> txq=%d" % (MAX_QUEUE+1, MAX_QUEUE+1), "-w %s --file-prefix=pf --socket-mem
> 1024,1024 --legacy-mem" % self.pf_pci)
> @@ -1574,23 +1636,23 @@ class TestGeneric_flow_api(TestCase):
> extra_packet = extrapkt_rulenum['extrapacket']
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE()/Ether(dst="%s")/Dot1Q(vlan=1)/IP()/TCP
> ()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.inner_mac, self.tester_itf))
> - self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.outer_mac)
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE()/Ether(dst="%s")/Dot1Q(vlan=1)/IP()
> /TCP()/Raw("x" * 20)' % (self.outer_mac, self.inner_mac))
> + self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0],
> + verify_mac=self.outer_mac)
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Raw
> ("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[4]['tni'], self.wrong_mac,
> self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/
> Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[4]['tni'], self.wrong_mac))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/Dot1Q(vlan=%s)
> /IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[5]['tni'],
> self.wrong_mac, extra_packet[5]['invlan'], self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/Dot1Q(vlan
> =%s)/IP()/TCP()/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[5]['tni'], self.wrong_mac, extra_packet[5]['invlan']))
> self.verify_result("vf0", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Raw
> ("x" * 20)], iface="%s")' % (self.wrong_mac, extra_packet[6]['tni'], self.inner_mac,
> self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/
> Raw("x" * 20)' % (
> + self.wrong_mac, extra_packet[6]['tni'], self.inner_mac))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.wrong_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> diff --git a/tests/TestSuite_hotplug.py b/tests/TestSuite_hotplug.py
> index a94967a..a7a7228 100644
> --- a/tests/TestSuite_hotplug.py
> +++ b/tests/TestSuite_hotplug.py
> @@ -121,7 +121,7 @@ class TestPortHotPlug(TestCase):
> self.txItf = self.tester.get_interface(txport)
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': self.dmac,})
> - pkt.send_pkt(tx_port=self.txItf)
> + pkt.send_pkt(self.tester, tx_port=self.txItf)
>
> def test_before_attach(self):
> """
> diff --git a/tests/TestSuite_iavf.py b/tests/TestSuite_iavf.py
> index 9395555..af8c747 100644
> --- a/tests/TestSuite_iavf.py
> +++ b/tests/TestSuite_iavf.py
> @@ -588,7 +588,7 @@ class TestIavf(TestCase):
> self.tester.scapy_execute()
> rec_pkt = self.tester.load_tcpdump_sniff_packets(inst)
> # collect checksum values for received packet
> - chksum =
> rec_pkt[0].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%S
> CTP.chksum%").split(";")
> + chksum =
> rec_pkt[0].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksu
> m%").split(";")
> chksum = list(set(chksum))
> chksum.remove("??")
> corrected_checksum_values[packet] = chksum
> diff --git a/tests/TestSuite_ieee1588.py b/tests/TestSuite_ieee1588.py
> index 0dd3d6e..f3fea42 100644
> --- a/tests/TestSuite_ieee1588.py
> +++ b/tests/TestSuite_ieee1588.py
> @@ -91,12 +91,13 @@ class TestIeee1588(TestCase):
>
> self.tester.send_expect(
> "tcpdump -i %s -e ether src %s" % (itf, mac), "tcpdump", 20)
> -
> + self.send_session = self.tester.create_session('send_session')
> + setattr(self.send_session, 'tmp_file', self.tester.tmp_file)
> pkt = Packet(pkt_type='TIMESYNC')
> - pkt.config_layer('ether', {'dst': mac, })
> - pkt.send_pkt(tx_port=itf)
> -
> + pkt.config_layer('ether', {'dst': mac})
> + pkt.send_pkt(self.send_session, tx_port=itf)
> time.sleep(1)
> + self.send_session.close()
> out = self.tester.get_session_output(timeout=20)
>
> self.tester.send_expect("^C", "# ", 20)
> diff --git a/tests/TestSuite_ipfrag.py b/tests/TestSuite_ipfrag.py
> index f6d0373..5edd6c4 100644
> --- a/tests/TestSuite_ipfrag.py
> +++ b/tests/TestSuite_ipfrag.py
> @@ -168,37 +168,36 @@ l3fwd_ipv4_route_array[] = {\\\n"
> expPkts = 1
> val = 2
>
> - inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf)
> # send packet
> for times in range(burst):
> pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
> pkt = Packet(pkt_type='UDP', pkt_len=pkt_size)
> - pkt.config_layer('ether', {'dst': self.dmac})
> + pkt.config_layer('ether', {'dst': '%s' % self.dmac})
> pkt.config_layer('ipv4', {'dst': '100.10.0.1', 'src': '1.2.3.4', 'flags': val})
> - pkt.send_pkt(tx_port=self.txItf)
> + pkt.send_pkt(self.tester, tx_port=self.txItf)
>
> # verify normal packet just by number, verify fragment packet by all elements
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> self.verify(len(pkts) == expPkts, "in functional_check_ipv4(): failed on forward
> packet size " + str(size))
> if flag == 'frag':
> idx = 1
> - for pkt in pkts:
> - # packet index should be same
> - pkt_id = pkt.strip_element_layer3("id")
> + for i in range(len(pkts)):
> + pkt_id = pkts.strip_element_layer3('id', p_index=i)
> if idx == 1:
> prev_idx = pkt_id
> self.verify(prev_idx == pkt_id, "Fragmented packets index not match")
> prev_idx = pkt_id
>
> # last flags should be 0
> - flags = pkt.strip_element_layer3("flags")
> + flags = pkts.strip_element_layer3("flags", p_index=i)
> if idx == expPkts:
> self.verify(flags == 0, "Fragmented last packet flags not match")
> else:
> self.verify(flags == 1, "Fragmented packets flags not match")
>
> # fragment offset should be correct
> - frag = pkt.strip_element_layer3("frag")
> + frag = pkts.strip_element_layer3("frag", p_index=i)
> self.verify((frag == ((idx - 1) * 185)), "Fragment packet frag not match")
> idx += 1
>
> @@ -218,37 +217,36 @@ l3fwd_ipv4_route_array[] = {\\\n"
> expPkts = 1
> val = 2
>
> - inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf)
> # send packet
> for times in range(burst):
> pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
> pkt = Packet(pkt_type='IPv6_UDP', pkt_len=pkt_size)
> - pkt.config_layer('ether', {'dst': self.dmac})
> + pkt.config_layer('ether', {'dst': '%s' % self.dmac})
> pkt.config_layer('ipv6', {'dst': '101:101:101:101:101:101:101:101', 'src':
> 'ee80:ee80:ee80:ee80:ee80:ee80:ee80:ee80'})
> - pkt.send_pkt(tx_port=self.txItf)
> + pkt.send_pkt(self.tester, tx_port=self.txItf)
>
> # verify normal packet just by number, verify fragment packet by all elements
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> self.verify(len(pkts) == expPkts, "In functional_check_ipv6(): failed on
> forward packet size " + str(size))
> if flag == 'frag':
> idx = 1
> - for pkt in pkts:
> - # packet index should be same
> - pkt_id = pkt.strip_element_layer4("id")
> + for i in range(len(pkts)):
> + pkt_id = pkts.strip_element_layer4('id', p_index=i)
> if idx == 1:
> prev_idx = pkt_id
> self.verify(prev_idx == pkt_id, "Fragmented packets index not match")
> prev_idx = pkt_id
>
> # last flags should be 0
> - flags = pkt.strip_element_layer4("m")
> + flags = pkts.strip_element_layer4("m", p_index=i)
> if idx == expPkts:
> self.verify(flags == 0, "Fragmented last packet flags not match")
> else:
> self.verify(flags == 1, "Fragmented packets flags not match")
>
> # fragment offset should be correct
> - frag = pkt.strip_element_layer4("offset")
> + frag = pkts.strip_element_layer4("offset", p_index=i)
> self.verify((frag == int((idx - 1) * 181)), "Fragment packet frag not match")
> idx += 1
>
> diff --git a/tests/TestSuite_ipgre.py b/tests/TestSuite_ipgre.py
> index d08a933..7258db5 100644
> --- a/tests/TestSuite_ipgre.py
> +++ b/tests/TestSuite_ipgre.py
> @@ -100,11 +100,11 @@ class TestIpgre(TestCase):
> if layer_configs:
> for layer in layer_configs.keys():
> pkt.config_layer(layer, layer_configs[layer])
> - inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1, timeout=8)
> - pkt.send_pkt(tx_port=self.tester_iface, count = 4)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1)
> + pkt.send_pkt(crb=self.tester, tx_port=self.tester_iface, count=4)
> out = self.dut.get_session_output(timeout=2)
> time.sleep(1)
> - self.tester.load_tcpdump_sniff_packets(inst)
> + pkt = self.tester.load_tcpdump_sniff_packets(inst)
> if self.printFlag: # debug output
> print out
> for pkt_layer_name in pkt_names:
> @@ -116,7 +116,7 @@ class TestIpgre(TestCase):
> raise VerifyFailure("Failed to detect %s" % pkt_layer_name)
> else:
> print utils.GREEN("Detected %s successfully" % pkt_type)
> - time.sleep(1)
> + time.sleep(1)
> if queue == None: # no filter
> pass
> else:
> @@ -124,6 +124,7 @@ class TestIpgre(TestCase):
> self.verify(("Receive queue=0x%s" % queue) in out, "Failed to enter the
> right queue.")
> else:
> self.verify(("Receive queue=0x%s" % queue) not in out, "Failed to enter
> the right queue.")
> + return pkt
>
>
> def save_ref_packet(self, pkt_types, layer_configs=None):
> @@ -146,13 +147,16 @@ class TestIpgre(TestCase):
> Skip outer udp for it will be calculated by software
> """
> chk_sums = {}
> - pkts = rdpcap(pcap)
> + if isinstance(pcap, str):
> + pkts = rdpcap(pcap)
> + else:
> + pkts = pcap.pktgen.pkts
> for number in range(len(pkts)):
> if pkts[number].guess_payload_class(pkts[number]).name == "gre":
> payload = pkts[number][GRE]
> else:
> payload = pkts[number]
> -
> +
> if payload.guess_payload_class(payload).name == "IP":
> chk_sums['outer_ip'] = hex(payload[IP].chksum)
>
> @@ -170,9 +174,9 @@ class TestIpgre(TestCase):
>
> return chk_sums
>
> - def compare_checksum(self):
> - chksums_ref = self.get_chksums('/tmp/ref_pkt.pcap')
> - chksums = self.get_chksums('/tmp/sniff_{0}.pcap'.format(self.tester_iface))
> + def compare_checksum(self, pkt):
> + chksums_ref = self.get_chksums('/tmp/ref_pkt.pcap')
> + chksums = self.get_chksums(pcap=pkt)
> self.logger.info("chksums_ref :: %s"%chksums_ref)
> self.logger.info("chksums :: %s"%chksums)
> # verify saved pcap checksum same to expected checksum
> @@ -197,8 +201,8 @@ class TestIpgre(TestCase):
> 'ipv4': {'proto': 'gre'}}
> # Start testpmd and enable rxonly forwarding mode
> testpmd_cmd = "./%s/app/testpmd -c ffff -n 4 -- -i --enable-rx-cksum" %
> self.target
> - self.dut.send_expect( testpmd_cmd,
> - "testpmd>",
> + self.dut.send_expect( testpmd_cmd,
> + "testpmd>",
> 20)
> self.dut.send_expect("set fwd rxonly", "testpmd>")
> self.dut.send_expect("set verbose 1", "testpmd>")
> @@ -233,7 +237,7 @@ class TestIpgre(TestCase):
> "MAC_IPv6_GRE_IPv6-TUNNEL_SCTP_PKT": ["TUNNEL_GRENAT",
> "INNER_L4_SCTP"],
> "MAC_VLAN_IPv6_GRE_IPv6-TUNNEL_SCTP_PKT": ["TUNNEL_GRENAT",
> "INNER_L4_SCTP", "PKT_RX_VLAN"]
> }
> -
> +
> # Start testpmd and enable rxonly forwarding mode
> testpmd_cmd = "./%s/app/testpmd -c ffff -n 4 -- -i --enable-rx-cksum --enable-
> hw-vlan" % self.target
> self.dut.send_expect(testpmd_cmd, "testpmd>", 20)
> @@ -258,7 +262,7 @@ class TestIpgre(TestCase):
> config_layers = {'ether': {'src': self.outer_mac_src},
> 'ipv6': {'nh': 47},
> 'gre': {'proto': 0x86dd},
> - 'inner_ipv6': {'nh': 132},
> + 'inner_ipv6': {'nh': 132},
> 'raw': {'payload':['78']*40}}
> self.check_packet_transmission(pkt_types_ipv6_ipv6_SCTP, config_layers)
> self.dut.send_expect("quit", "#")
> @@ -271,7 +275,7 @@ class TestIpgre(TestCase):
> """
> outer_mac = self.tester_iface_mac
> inner_mac = "10:00:00:00:00:00"
> -
> +
> # Start testpmd with multi queues
> #testpmd_cmd = "./%s/app/testpmd -c ff -n 3 -- -i --rxq=4 --txq=4" %
> self.target
> testpmd_cmd = "./%s/app/testpmd -c ff -n 3 -- -i --enable-rx-cksum --rxq=4 --
> txq=4" % self.target
> @@ -284,7 +288,7 @@ class TestIpgre(TestCase):
> # Add GRE filter that forward inner ip address 0.0.0.0 to queue 3
> cmd = "tunnel_filter add 0 %s %s 0.0.0.0 1 ipingre iip 0 3"%(outer_mac,
> inner_mac)
> self.dut.send_expect( cmd, "testpmd>")
> -
> +
> # Send packet inner ip address matched and check packet received by queue 3
> pkt_types = {"MAC_IP_GRE_IPv4-TUNNEL_UDP_PKT": ["TUNNEL_GRENAT",
> "INNER_L4_UDP"]}
> config_layers = {'ether': {'src': self.outer_mac_src},
> @@ -298,7 +302,7 @@ class TestIpgre(TestCase):
> cmd = "tunnel_filter rm 0 %s %s 0.0.0.0 1 ipingre iip 0 3"%(outer_mac,
> inner_mac)
> self.dut.send_expect( cmd, "testpmd>")
> self.check_packet_transmission(pkt_types, config_layers, "3")
> -
> +
> # Add GRE filter that forward outer ip address 0.0.0.0 to queue 3
> cmd = "tunnel_filter add 0 %s %s 0.0.0.0 1 ipingre oip 0 3"%(outer_mac,
> inner_mac)
> self.dut.send_expect( cmd, "testpmd>")
> @@ -341,7 +345,7 @@ class TestIpgre(TestCase):
>
> # Send packet with wrong outer IP checksum and check forwarded packet IP
> checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT": ["PKT_TX_IP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -349,7 +353,7 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -357,12 +361,12 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst,
> 'chksum': 0x0}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
>
> # Send packet with wrong inner IP checksum and check forwarded packet IP
> checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT": ["PKT_TX_IP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -370,7 +374,7 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -378,22 +382,22 @@ class TestIpgre(TestCase):
> 'chksum': 0x0},
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> -
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
> +
> # Send packet with wrong inner TCP checksum and check forwarded packet TCP
> checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT": ["PKT_TX_TCP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> 'dst': self.outer_ip_dst},
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> - 'tcp': {'src': 53,
> + 'tcp': {'src': 53,
> 'dst': 53}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -401,12 +405,12 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> 'tcp': {'chksum': 0x0}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
>
> # Send packet with wrong inner UDP checksum and check forwarded packet
> UDP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_UDP_PKT": ["PKT_TX_UDP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -414,7 +418,7 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -422,8 +426,8 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> 'udp': {'chksum': 0xffff}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
> if self.nic != "cavium_a063":
> # Send packet with wrong inner SCTP checksum and check forwarded packet
> SCTP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_SCTP_PKT":
> ["PKT_TX_SCTP_CKSUM"]}
> @@ -445,20 +449,22 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> 'sctp': {'chksum': 0x0}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
>
> self.dut.send_expect("quit", "#")
>
> def tear_down(self):
> """
> Run after each test case.
> + Nothing to do.
> """
> - self.dut.kill_all()
> + pass
>
> def tear_down_all(self):
> """
> Run after each test suite.
> Nothing to do.
> """
> + self.dut.kill_all()
> pass
> diff --git a/tests/TestSuite_ipsec_gw_cryptodev_func.py
> b/tests/TestSuite_ipsec_gw_cryptodev_func.py
> index 5b815ad..9800886 100644
> --- a/tests/TestSuite_ipsec_gw_cryptodev_func.py
> +++ b/tests/TestSuite_ipsec_gw_cryptodev_func.py
> @@ -35,7 +35,7 @@ import binascii
> import time
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +import packet
>
> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
> from cryptography.hazmat.primitives.ciphers.aead import AESCCM, AESGCM
> @@ -723,7 +723,7 @@ class TestIPsecGW(TestCase):
> self.logger.info("IPsec-gw cmd: " + cmd_str)
> self.dut.send_expect(cmd_str, "IPSEC:", 30)
> time.sleep(3)
> - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=25)
> + inst = self.tester.tcpdump_sniff_packets(self.rx_interface)
>
> PACKET_COUNT = 65
> payload = 256 * ['11']
> @@ -735,7 +735,7 @@ class TestIPsecGW(TestCase):
> expected_src_ip = case_cfgs["expected_src_ip"]
> expected_spi = case_cfgs["expected_spi"]
>
> - pkt = Packet()
> + pkt = packet.Packet()
> if len(dst_ip)<=15:
> pkt.assign_layers(["ether", "ipv4", "udp", "raw"])
> pkt.config_layer("ether", {"src": "52:00:00:00:00:00", "dst":
> "52:00:00:00:00:01"})
> @@ -746,38 +746,37 @@ class TestIPsecGW(TestCase):
> pkt.config_layer("ipv6", {"src": src_ip, "dst": dst_ip})
> pkt.config_layer("udp", {"dst": 0})
> pkt.config_layer("raw", {"payload": payload})
> - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
> + pkt.send_pkt(crb=self.tester, tx_port=self.tx_interface, count=PACKET_COUNT)
>
> pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
>
> - pcap_filename = "output/{0}.pcap".format(self.pcap_filename)
> - self.logger.info("Save pkts to {0}".format(pcap_filename))
> - save_packets(pkt_rec, pcap_filename)
> + pcap_filename = "{0}.pcap".format(self.pcap_filename)
> + self.logger.info("Save pkts to {0}".format(packet.TMP_PATH + pcap_filename))
> + pkt_rec.save_pcapfile(self.tester, pcap_filename)
> self._pcap_idx = self._pcap_idx + 1
>
> if len(pkt_rec) == 0:
> self.logger.error("IPsec forwarding failed")
> result = False
> -
> - for pkt_r in pkt_rec:
> - pkt_src_ip = pkt_r.pktgen.strip_layer3("src")
> + for i in range(len(pkt_rec)):
> + pkt_src_ip = pkt_rec.pktgen.strip_layer3("src", p_index=i)
> if pkt_src_ip != expected_src_ip:
> - pkt_r.pktgen.pkt.show()
> + pkt_rec[i].show()
> self.logger.error("SRC IP does not match. Pkt:{0}, Expected:{1}".format(
> pkt_src_ip, expected_src_ip))
> result = False
> break
>
> - pkt_dst_ip = pkt_r.pktgen.strip_layer3("dst")
> + pkt_dst_ip = pkt_rec.pktgen.strip_layer3("dst", p_index=i)
> self.logger.debug(pkt_dst_ip)
> if pkt_dst_ip != expected_dst_ip:
> - pkt_r.pktgen.pkt.show()
> + pkt_rec[i].show()
> self.logger.error("DST IP does not match. Pkt:{0}, Expected:{1}".format(
> pkt_dst_ip, expected_dst_ip))
> result = False
> break
>
> - packet_hex = pkt_r.pktgen.pkt["ESP"].getfieldval("data")
> + packet_hex = pkt_rec[i]["ESP"].getfieldval("data")
> if packet_hex is None:
> self.logger.error("NO Payload !")
> result = False
> @@ -785,7 +784,7 @@ class TestIPsecGW(TestCase):
> payload_str = binascii.b2a_hex(packet_hex)
> self.logger.debug(payload_str)
>
> - pkt_spi = hex(pkt_r.pktgen.pkt["ESP"].getfieldval("spi"))
> + pkt_spi = hex(pkt_rec[i]["ESP"].getfieldval("spi"))
> self.logger.debug(pkt_spi)
> if pkt_spi != expected_spi:
> self.logger.error("SPI does not match. Pkt:{0}, Expected:{1}".format(
> diff --git a/tests/TestSuite_jumboframes.py b/tests/TestSuite_jumboframes.py
> index 1b5aab5..a883e3e 100644
> --- a/tests/TestSuite_jumboframes.py
> +++ b/tests/TestSuite_jumboframes.py
> @@ -229,7 +229,7 @@ class TestJumboframes(TestCase):
> """
> Run after each test case.
> """
> - pass
> + self.dut.kill_all()
>
> def tear_down_all(self):
> """
> diff --git a/tests/TestSuite_kernelpf_iavf.py b/tests/TestSuite_kernelpf_iavf.py
> index 476b899..4424ae2 100644
> --- a/tests/TestSuite_kernelpf_iavf.py
> +++ b/tests/TestSuite_kernelpf_iavf.py
> @@ -423,7 +423,7 @@ class TestKernelpfIavf(TestCase):
> pkt.config_layer('vlan', {'vlan': vlan})
> pkt.config_layer('ether', {'dst': self.vf_mac})
>
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
> out = self.vm_dut.get_session_output(timeout=2)
>
> return out
> @@ -546,7 +546,7 @@ class TestKernelpfIavf(TestCase):
> pkt = Packet(pkt_type='UDP', pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': self.vf_mac, 'src': self.tester_mac})
> self.vm_testpmd.execute_cmd("clear port stats all")
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> time.sleep(1)
>
> diff --git a/tests/TestSuite_l2fwd_cryptodev_func.py
> b/tests/TestSuite_l2fwd_cryptodev_func.py
> index 7e785dd..e0f0b5b 100644
> --- a/tests/TestSuite_l2fwd_cryptodev_func.py
> +++ b/tests/TestSuite_l2fwd_cryptodev_func.py
> @@ -760,7 +760,6 @@ class TestL2fwdCrypto(TestCase):
> payload = self.__format_hex_to_list(test_vector["input"])
>
> inst = self.tester.tcpdump_sniff_packets(self.rx_interface,
> - timeout=5,
> filters=[{'layer': 'ether',
> 'config': {'dst': '52:00:00:00:00:01'}}])
>
> @@ -770,12 +769,12 @@ class TestL2fwdCrypto(TestCase):
> pkt.config_layer("ether", {"src": "52:00:00:00:00:00",
> "dst":"52:00:00:00:00:01"})
> pkt.config_layer("ipv4", {"src": "192.168.1.1", "dst": "192.168.1.2"})
> pkt.config_layer("raw", {"payload": payload})
> - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
> + pkt.send_pkt(self.tester, tx_port=self.tx_interface, count=PACKET_COUNT)
>
> pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
> self.logger.info("Receive pkgs: {}".format(len(pkt_rec)))
> - for pkt_r in pkt_rec:
> - packet_hex = pkt_r.pktgen.pkt["Raw"].getfieldval("load")
> + for i in range(len(pkt_rec)):
> + packet_hex = pkt_rec[i]["Raw"].getfieldval("load")
> if packet_hex == None:
> result = False
> self.logger.info("no payload !")
> @@ -796,9 +795,9 @@ class TestL2fwdCrypto(TestCase):
> hash_length = len(test_vector["output_hash"])/2
> if hash_length != 0:
> if test_vector["auth_algo"] == "null":
> - hash_text =
> binascii.b2a_hex(pkt_r.pktgen.pkt["Raw"].getfieldval("load"))
> + hash_text = binascii.b2a_hex(pkt_rec[i]["Raw"].getfieldval("load"))
> else:
> - hash_text =
> binascii.b2a_hex(pkt_r.pktgen.pkt["Padding"].getfieldval("load"))
> + hash_text = binascii.b2a_hex(pkt_rec[i]["Padding"].getfieldval("load"))
> if str.lower(hash_text) == str.lower(test_vector["output_hash"]):
> self.logger.info("Hash Matched")
> else:
> diff --git a/tests/TestSuite_l3fwdacl.py b/tests/TestSuite_l3fwdacl.py
> index 9d1c41e..dce37de 100644
> --- a/tests/TestSuite_l3fwdacl.py
> +++ b/tests/TestSuite_l3fwdacl.py
> @@ -38,6 +38,7 @@ import re
> import utils
> import time
> from test_case import TestCase
> +import packet
>
> class TestL3fwdacl(TestCase):
>
> @@ -268,10 +269,10 @@ class TestL3fwdacl(TestCase):
>
> dst_filter = {'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}
> filters = [dst_filter]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=filters)
> -
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (ethernet_str,
> tx_interface))
> - self.tester.scapy_execute()
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters)
> + pkt = packet.Packet()
> + pkt.append_pkt(ethernet_str)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> @@ -298,11 +299,11 @@ class TestL3fwdacl(TestCase):
> ethernet_str = self.create_ipv6_rule_string(rule, "Ether")
>
> fil = [{'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=fil)
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=fil)
> + pkt = packet.Packet()
> + pkt.append_pkt(ethernet_str)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
>
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (ethernet_str,
> tx_interface))
> - self.tester.scapy_execute()
> - time.sleep(3)
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> @@ -316,10 +317,10 @@ class TestL3fwdacl(TestCase):
>
> dst_filter = {'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}
> filters = [dst_filter]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=filters)
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (etherStr, tx_interface))
> - self.tester.scapy_execute()
> -
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters)
> + pkt = packet.Packet()
> + pkt.append_pkt(etherStr)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> @@ -332,20 +333,20 @@ class TestL3fwdacl(TestCase):
> etherStr = self.create_ipv6_rule_string(rule, "Ether")
>
> fil = [{'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5, filters=fil)
> -
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (etherStr, tx_interface))
> - self.tester.scapy_execute()
> - time.sleep(3)
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=fil)
> + pkt = packet.Packet()
> + pkt.append_pkt(etherStr)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
>
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> def remove_dhcp_from_revpackets(self, inst):
> - pkts = self.tester.load_tcpdump_sniff_packets(inst)
> + p = self.tester.load_tcpdump_sniff_packets(inst)
> + pkts = p.pktgen.pkts
> i = 0
> while len(pkts) != 0 and i <= len(pkts) - 1:
> - if pkts[i].pktgen.pkt.haslayer('DHCP'):
> + if pkts[i].haslayer('DHCP'):
> pkts.remove(pkts[i])
> i = i - 1
> i = i + 1
> diff --git a/tests/TestSuite_link_flowctrl.py b/tests/TestSuite_link_flowctrl.py
> index 4229aa4..ed89162 100644
> --- a/tests/TestSuite_link_flowctrl.py
> +++ b/tests/TestSuite_link_flowctrl.py
> @@ -453,4 +453,5 @@ class TestLinkFlowctrl(TestCase):
> """
> Run after each test case.
> """
> + self.dut.kill_all()
> self.dut.send_expect("quit", "# ")
> diff --git a/tests/TestSuite_link_status_interrupt.py
> b/tests/TestSuite_link_status_interrupt.py
> index 1d7e67e..3208d71 100644
> --- a/tests/TestSuite_link_status_interrupt.py
> +++ b/tests/TestSuite_link_status_interrupt.py
> @@ -175,7 +175,7 @@ class TestLinkStatusInterrupt(TestCase):
> self.txItf = self.tester.get_interface(txport)
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': self.dmac})
> - pkt.send_pkt(tx_port=self.txItf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.txItf, count=num)
>
> def tear_down(self):
> """
> diff --git a/tests/TestSuite_loadbalancer.py b/tests/TestSuite_loadbalancer.py
> index 9152c6c..934e291 100644
> --- a/tests/TestSuite_loadbalancer.py
> +++ b/tests/TestSuite_loadbalancer.py
> @@ -90,13 +90,13 @@ class TestLoadbalancer(TestCase):
> for i in range(len(dutPorts)):
> dstport = self.tester.get_local_port(dutPorts[i])
> pkt_count = 10
> - inst =
> self.tester.tcpdump_sniff_packets(intf=self.tester.get_interface(rx_port), timeout=10,
> count=pkt_count)
> + inst =
> self.tester.tcpdump_sniff_packets(intf=self.tester.get_interface(rx_port),
> count=pkt_count)
>
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP', pkt_len=64)
> dst_mac = self.dut.get_mac_address(dutPorts[i])
> - pkt.config_layer('ether', {'dst': dst_mac})
> - pkt.config_layer('ipv4', {'src': "0.0.0.1", 'dst': trafficFlow[flow][1]})
> - pkt.send_pkt(tx_port=self.tester.get_interface(dstport), count=10)
> + pkt.config_layer('ether', {'dst': '%s' % dst_mac})
> + pkt.config_layer('ipv4', {'src': "0.0.0.1", 'dst': '%s' % (trafficFlow[flow][1])})
> + pkt.send_pkt(self.tester, tx_port=self.tester.get_interface(dstport),
> count=10)
> # Wait for the sniffer to finish.
> time.sleep(5)
>
> @@ -104,8 +104,8 @@ class TestLoadbalancer(TestCase):
> len_pkts = len(pkts)
>
> self.verify(len_pkts == pkt_count, "Packet number is wrong")
> - for packet in pkts:
> - result = str(packet.pktgen.pkt.show)
> + for i in range(len_pkts):
> + result = str(pkts[i].show)
> self.verify("Ether" in result, "No packet received")
> self.verify("src=0.0.0.1" + " dst=" + trafficFlow[flow][1] in result, "Wrong
> IP address")
> self.verify("dst=%s" % dst_mac in result, "No packet received or packet
> missed")
> diff --git a/tests/TestSuite_mac_filter.py b/tests/TestSuite_mac_filter.py
> index 7b5eb43..19d250b 100644
> --- a/tests/TestSuite_mac_filter.py
> +++ b/tests/TestSuite_mac_filter.py
> @@ -88,7 +88,7 @@ class TestMacFilter(TestCase):
> itf = self.tester.get_interface(self.tester.get_local_port(portid))
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'src': '52:00:00:00:00:00', 'dst': destMac})
> - pkt.send_pkt(tx_port=itf, count=4)
> + pkt.send_pkt(self.tester, tx_port=itf, count=4)
>
> def test_add_remove_mac_address(self):
> """
> diff --git a/tests/TestSuite_netmap_compat.py b/tests/TestSuite_netmap_compat.py
> index 2f8171c..a7a97ca 100644
> --- a/tests/TestSuite_netmap_compat.py
> +++ b/tests/TestSuite_netmap_compat.py
> @@ -114,9 +114,9 @@ class TestNetmapCompat(TestCase):
>
> def get_tcpdump_package(self):
> pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
> - dsts = []
> - for packet in pkts:
> - dst = packet.strip_element_layer2("dst")
> + dsts = []
> + for i in range(len(pkts)):
> + dst = pkts.strip_element_layer2("dst", p_index=i)
> dsts.append(dst)
> return dsts
>
> diff --git a/tests/TestSuite_packet_capture.py b/tests/TestSuite_packet_capture.py
> index 6e5b98f..fdaa0d0 100644
> --- a/tests/TestSuite_packet_capture.py
> +++ b/tests/TestSuite_packet_capture.py
> @@ -39,8 +39,6 @@ import time
> import re
> import signal
> import subprocess
> -import shutil
> -import socket
> from pprint import pformat
>
> from scapy.utils import rdpcap
> @@ -188,37 +186,19 @@ class parsePacket(object):
>
> class TestPacketCapture(TestCase):
>
> - def get_dts_node_ip(self):
> - ip_addr = None
> - try:
> - socket_inst = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> - socket_inst.connect(('8.8.8.8', 80))
> - ip_addr = socket_inst.getsockname()[0]
> - except Exception as e:
> - msg = "Can't get dts running node ip address"
> - self.logger.warning(msg)
> - return ip_addr
> - return ip_addr
> -
> - @property
> - def is_dts_on_tester(self):
> - if not self.dts_ip:
> - return False
> - # get tester ip to check if dts run on tester
> - tester_ip = self.tester.get_ip_address()
> - return self.dts_ip == tester_ip
> -
> - @property
> - def is_dts_on_dut(self):
> - if not self.dts_ip:
> - return False
> - # get dut ip to check if dts run on dut
> - dut_ip = self.dut.get_ip_address()
> - return self.dts_ip == dut_ip
> + def is_existed_on_crb(self, check_path, crb='dut'):
> + alt_session = self.dut.alt_session \
> + if crb == 'dut' else \
> + self.tester.alt_session
> + alt_session.send_expect("ls %s" % check_path, "# ")
> + cmd = "echo $?"
> + output = alt_session.send_expect(cmd, "# ")
> + ret = True if output and output.strip() == "0" else False
> + return ret
>
> @property
> def is_dut_on_tester(self):
> - # get dut/tester ip to check if they are in one platform
> + # get dut/tester ip to check if they are in a platform
> tester_ip = self.tester.get_ip_address()
> dut_ip = self.dut.get_ip_address()
> return tester_ip == dut_ip
> @@ -231,42 +211,6 @@ class TestPacketCapture(TestCase):
> self.dut.base_dir
> return target_dir
>
> - def __create_log_dir(self, log_dir):
> - # create a log directory on dts running node
> - if not os.path.exists(log_dir):
> - os.makedirs(log_dir)
> - # create a log directory on dut node
> - if not self.is_dts_on_dut and \
> - not self.is_existed_on_crb(log_dir):
> - cmd = "mkdir -p {0}".format(log_dir)
> - self.dut.alt_session.send_expect(cmd, "# ")
> - # create a log directory on tester node
> - if not self.is_dts_on_tester and \
> - not self.is_existed_on_crb(log_dir, crb='tester'):
> - cmd = "mkdir -p {0}".format(log_dir)
> - self.tester.alt_session.send_expect(cmd, "# ")
> -
> - def __clear_log_dir(self, log_dir):
> - if os.path.exists(log_dir):
> - shutil.rmtree(log_dir)
> - os.makedirs(log_dir)
> - if not self.is_dts_on_dut:
> - self.dut.alt_session.send_expect(
> - "rm -fr {0}/*".format(log_dir), "# ", 10)
> - if not self.is_dts_on_tester:
> - self.tester.alt_session.send_expect(
> - "rm -fr {0}/*".format(log_dir), "# ", 10)
> -
> - def is_existed_on_crb(self, check_path, crb='dut'):
> - alt_session = self.dut.alt_session \
> - if crb == 'dut' else \
> - self.tester.alt_session
> - alt_session.send_expect("ls %s > /dev/null 2>&1" % check_path, "# ")
> - cmd = "echo $?"
> - output = alt_session.send_expect(cmd, "# ")
> - ret = True if output and output.strip() == "0" else False
> - return ret
> -
> def get_dut_iface_with_kernel_driver(self):
> # only physical nic support PROMISC
> cmd = "ip link show | grep BROADCAST,MULTICAST | awk {'print $2'}"
> @@ -500,6 +444,11 @@ class TestPacketCapture(TestCase):
> time.sleep(4)
>
> def start_testpmd(self):
> + self.dut.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 10)
> + if not self.is_dut_on_tester:
> + self.tester.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 10)
> param_opt = "--port-topology=chained"
> eal_param = '--file-prefix=test'
> self.testpmd.start_testpmd("Default", param=param_opt,
> @@ -516,14 +465,23 @@ class TestPacketCapture(TestCase):
> def start_tcpdump_iface(self, option):
> if option["rx"][0] is not None and option["tx"][0] is not None and \
> option["rx"][0] == option["tx"][0]:
> + if self.is_existed_on_crb(self.rxtx_pcap):
> + self.dut.alt_session.send_expect(
> + "rm -f %s" % self.rxtx_pcap, "# ")
> cmd = self.tcpdump.format(self.rxtx_iface, self.rxtx_pcap)
> self.session_ex.send_expect(cmd, "# ")
> else:
> if option["rx"][0] is not None:
> + if self.is_existed_on_crb(self.rx_pcap):
> + self.dut.alt_session.send_expect(
> + "rm -f %s" % self.rx_pcap, "# ")
> cmd = self.tcpdump.format(self.rx_iface, self.rx_pcap)
> self.session_ex.send_expect(cmd, "# ")
>
> if option["tx"][0] is not None:
> + if self.is_existed_on_crb(self.tx_pcap):
> + self.dut.alt_session.send_expect(
> + "rm -f %s" % self.tx_pcap, "# ")
> cmd = self.tcpdump.format(self.tx_iface, self.tx_pcap)
> self.session_ex.send_expect(cmd, "# ")
> time.sleep(4)
> @@ -537,6 +495,11 @@ class TestPacketCapture(TestCase):
> msg = ('pdump option string length should be less than {}'
> ).format(length_limit)
> self.verify(len(option) < length_limit, msg)
> + self.dut.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 20)
> + if not self.is_dut_on_tester:
> + self.tester.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 20)
> cmd = ';'.join([
> "cd %s" % self.target_dir,
> self.dpdk_pdump + " '%s' >/dev/null 2>&1 &" % (option[0])])
> @@ -572,13 +535,18 @@ class TestPacketCapture(TestCase):
> # check send tx packet by port 0
> # send packet to dut and compare dpdk-pdump dump pcap with
> # scapy pcap file
> - if self.is_dts_on_tester:
> - intf = self.tester.get_interface(self.tester.get_local_port(port_1))
> - # prepare to catch replay packet in out port
> - recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> - if os.path.exists(recPkt):
> - os.remove(recPkt)
> - index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt)
> + intf = self.tester.get_interface(self.tester.get_local_port(port_1))
> + # prepare to catch replay packet in out port
> + recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> + if os.path.exists(recPkt):
> + os.remove(recPkt)
> + if pkt_type == 'LLDP':
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1,
> lldp_forbid=False)
> + else:
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1)
> + filename = '{}sniff_{}.pcap'.format(self.tester.tmp_file, intf)
> + self.tester.session.copy_file_from(filename, recPkt)
> + # index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt)
> pkt = Packet(pkt_type=pkt_type)
> if pkt_type == 'VLAN_UDP':
> pkt.config_layer('dot1q', {'vlan': 20})
> @@ -588,33 +556,34 @@ class TestPacketCapture(TestCase):
> refPkt = self.send_pcap % (pkt_type, "rx", number)
> if os.path.exists(refPkt):
> os.remove(refPkt)
> - pkt.pktgen.write_pcap(refPkt)
> +
> + pkt.save_pcapfile(filename=refPkt)
> # send out test packet
> tester_port = self.tester.get_local_port(port_0)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(
> - crb= None if self.is_dts_on_tester else self.tester,
> - tx_port=intf)
> + pkt.send_pkt(self.tester, tx_port=intf)
> # load pcap file caught by out port
> time.sleep(1)
> - # when dts doesn't run on tester, ignore this testing content
> - if self.is_dts_on_tester:
> - load_sniff_packets(index)
> - # compare pcap file received by out port with scapy reference
> - # packet pcap file
> - warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> - msg = "tcpdump rx Receive Packet error: {0}".format(warning)
> - self.verify(not warning, msg)
> + pkts = self.tester.load_tcpdump_sniff_packets(index)
> + pkts.save_pcapfile(filename=recPkt)
> + # load_sniff_packets(index)
> + # compare pcap file received by out port with scapy reference
> + # packet pcap file
> + warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> + msg = "tcpdump rx Receive Packet error: {0}".format(warning)
> + self.verify(not warning, msg)
> # check send tx packet by port 1
> # send packet to dut and compare dpdk-pdump dump pcap
> # with scapy pcap file
> - if self.is_dts_on_tester:
> - intf = self.tester.get_interface(self.tester.get_local_port(port_0))
> - # prepare to catch replay packet in out port
> - recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> - if os.path.exists(recPkt):
> - os.remove(recPkt)
> - index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt)
> + intf = self.tester.get_interface(self.tester.get_local_port(port_0))
> + # prepare to catch replay packet in out port
> + recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> + if os.path.exists(recPkt):
> + os.remove(recPkt)
> + if pkt_type == 'LLDP':
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1,
> lldp_forbid=False)
> + else:
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1)
> pkt = Packet(pkt_type=pkt_type)
> if pkt_type == 'VLAN_UDP':
> pkt.config_layer('dot1q', {'vlan': 20})
> @@ -624,23 +593,21 @@ class TestPacketCapture(TestCase):
> refPkt = self.send_pcap % (pkt_type, "tx", number)
> if os.path.exists(refPkt):
> os.remove(refPkt)
> - pkt.pktgen.write_pcap(refPkt)
> + pkt.save_pcapfile(filename=refPkt)
> + # pkt.pktgen.write_pcap(refPkt)
> # send out test packet
> tester_port = self.tester.get_local_port(port_1)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(
> - crb= None if self.is_dts_on_tester else self.tester,
> - tx_port=intf)
> + pkt.send_pkt(self.tester, tx_port=intf)
> # load pcap file caught by out port
> time.sleep(1)
> - # when dts doesn't run on tester, ignore this testing content
> - if self.is_dts_on_tester:
> - load_sniff_packets(index)
> - # compare pcap file received by out port
> - # with scapy reference packet pcap file
> - warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> - msg = "tcpdump tx Receive Packet error: {0}".format(warning)
> - self.verify(not warning, msg)
> + pkts = self.tester.load_tcpdump_sniff_packets(index)
> + pkts.save_pcapfile(filename=recPkt)
> + # compare pcap file received by out port
> + # with scapy reference packet pcap file
> + warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> + msg = "tcpdump tx Receive Packet error: {0}".format(warning)
> + self.verify(not warning, msg)
>
> def check_pdump_pcaps(self, pkt_type, number, **kwargs):
> rx_dump_pcap = kwargs["rx"][0]
> @@ -686,23 +653,8 @@ class TestPacketCapture(TestCase):
> msg = "pdump tx {0} packet content is correct".format(pkt_type)
> self.logger.info(msg)
>
> - def sync_dut_dump_file(self):
> - if self.is_dts_on_dut:
> - return
> - # copy rx pdump data from dut
> - if os.path.exists(self.rx_pcap):
> - os.remove(self.rx_pcap)
> - if self.is_existed_on_crb(self.rx_pcap):
> - self.dut.session.copy_file_from(self.rx_pcap, self.rx_pcap)
> - # copy tx pdump data from dut
> - if os.path.exists(self.tx_pcap):
> - os.remove(self.tx_pcap)
> - if self.is_existed_on_crb(self.tx_pcap):
> - self.dut.session.copy_file_from(self.tx_pcap, self.tx_pcap)
> -
> def packet_capture_test_packets(self, option):
> self.clear_ASLR()
> - self.__clear_log_dir(self.pdump_log)
> self.start_testpmd()
> self.start_dpdk_pdump(option)
> if self.dev_iface_flag:
> @@ -713,7 +665,17 @@ class TestPacketCapture(TestCase):
> time.sleep(2)
> if self.dev_iface_flag:
> self.stop_tcpdump_iface()
> - self.sync_dut_dump_file()
> + if not self.is_dut_on_tester:
> + # copy rx pdump data from dut
> + if self.is_existed_on_crb(self.rx_pcap):
> + if os.path.exists(self.rx_pcap):
> + os.remove(self.rx_pcap)
> + self.dut.session.copy_file_from(self.rx_pcap, self.rx_pcap)
> + # copy tx pdump data from dut
> + if self.is_existed_on_crb(self.tx_pcap):
> + if os.path.exists(self.tx_pcap):
> + os.remove(self.tx_pcap)
> + self.dut.session.copy_file_from(self.tx_pcap, self.tx_pcap)
> self.stop_dpdk_pdump()
> self.stop_testpmd()
> self.reset_ASLR()
> @@ -838,8 +800,6 @@ class TestPacketCapture(TestCase):
> '''
> Run at the start of each test suite.
> '''
> - # get dts running node ip address
> - self.dts_ip = self.get_dts_node_ip()
> self.verify(self.target == "x86_64-native-linuxapp-gcc",
> "only support x86_64-native-linuxapp-gcc")
> self.dut_ports = self.dut.get_ports()
> @@ -851,7 +811,13 @@ class TestPacketCapture(TestCase):
> self.dut_skip_compile = self.dut.skip_setup
> # used for save log
> self.pdump_log = os.sep.join(["/tmp", 'pdumpLog'])
> - self.__create_log_dir(self.pdump_log)
> + if not self.is_existed_on_crb(self.pdump_log):
> + cmd = "mkdir -p {0}".format(self.pdump_log)
> + self.dut.alt_session.send_expect(cmd, "# ")
> + if not self.is_dut_on_tester and \
> + not self.is_existed_on_crb(self.pdump_log, crb='tester'):
> + cmd = "mkdir -p {0}".format(self.pdump_log)
> + self.tester.alt_session.send_expect(cmd, "# ")
> self.pcap_SW = "CONFIG_RTE_LIBRTE_PMD_PCAP"
> self.SW_file = os.path.join(self.target_dir, 'config/common_base')
> if not (self.dut_skip_compile and self.check_pcap_lib()):
> @@ -861,19 +827,17 @@ class TestPacketCapture(TestCase):
> self.dut.skip_setup = False
> self.dut.build_install_dpdk(self.target)
> # secondary process (dpdk-pdump)
> - self.pdump_dir = os.sep.join([
> - self.target_dir,
> - "%s/build/app/pdump/" % self.target])
> + self.pdump_dir = self.target_dir + os.sep + \
> + "%s/build/app/pdump/" % self.target
> cmd = "ls {0} -F | grep '*'".format(self.pdump_dir)
> exe_files = self.dut.alt_session.send_expect(cmd, "# ").splitlines()
> if len(exe_files) == 1:
> self.tool_name = exe_files[0][:-1]
> else:
> self.verify(False, "tool name exception !")
> - self.dut_dpdk_pdump_dir = os.sep.join([
> - self.target_dir,
> - "%s/app/%s" % (self.target, self.tool_name)])
> self.session_ex = self.dut.new_session(self.tool_name)
> + self.dut_dpdk_pdump_dir = self.target_dir + os.sep + \
> + "%s/app/%s" % (self.target, self.tool_name)
> self.dpdk_pdump = self.dut_dpdk_pdump_dir + \
> " -v --file-prefix=test -- --pdump "
> self.send_pcap = os.sep.join([self.pdump_log, "scapy_%s_%s_%d.pcap"])
> diff --git a/tests/TestSuite_ptype_mapping.py b/tests/TestSuite_ptype_mapping.py
> index b0dc70a..b352724 100644
> --- a/tests/TestSuite_ptype_mapping.py
> +++ b/tests/TestSuite_ptype_mapping.py
> @@ -85,7 +85,7 @@ class TestPtype_Mapping(TestCase):
> else:
> pkt_names = pkt_types[pkt_type]
> pkt = Packet(pkt_type=pkt_type)
> - pkt.send_pkt(tx_port=self.tester_iface,count=4)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface,count=4)
> out = self.dut.get_session_output(timeout=2)
> if sw_ptype != None:
> self.verify(sw_ptype in out,
> diff --git a/tests/TestSuite_pvp_multi_paths_performance.py
> b/tests/TestSuite_pvp_multi_paths_performance.py
> index b633b98..65c785a 100644
> --- a/tests/TestSuite_pvp_multi_paths_performance.py
> +++ b/tests/TestSuite_pvp_multi_paths_performance.py
> @@ -36,7 +36,7 @@ Test PVP performance using virtio_user on 8 tx/rx path.
>
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -98,7 +98,7 @@ class TestPVPMultiPathPerformance(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % destination_mac})
> - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port))
> + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" % (self.out_path,
> port))
> tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" %
> (self.out_path, port)))
>
> self.tester.pktgen.clear_streams()
> diff --git a/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> b/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> index fcaadf2..29d87c2 100644
> --- a/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> +++ b/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> @@ -36,7 +36,7 @@ Test PVP vhost single core performance using virtio_user on 8
> tx/rx path.
>
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -95,7 +95,7 @@ class TestPVPMultiPathVhostPerformance(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % destination_mac})
> - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port))
> + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" % (self.out_path,
> port))
> tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" %
> (self.out_path, port)))
>
> self.tester.pktgen.clear_streams()
> diff --git a/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> b/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> index 6cd3a6d..e8807a7 100644
> --- a/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> +++ b/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> @@ -36,7 +36,7 @@ Test PVP virtio single core performance using virtio_user on 8
> tx/rx path.
>
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -98,7 +98,7 @@ class TestPVPMultiPathVirtioPerformance(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % destination_mac})
> - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port))
> + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" % (self.out_path,
> port))
>
> tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" %
> (self.out_path, port)))
>
> diff --git a/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> b/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> index 0095ce2..ea2e1cd 100644
> --- a/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> +++ b/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> @@ -43,7 +43,7 @@ import time
> import re
> from virt_common import VM
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -72,7 +72,6 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> self.tester.send_expect('mkdir -p %s' % self.out_path, '# ')
> # create an instance to set stream field setting
> self.pktgen_helper = PacketGeneratorHelper()
> - self.base_dir = self.dut.base_dir.replace('~', '/root')
>
> def set_up(self):
> """
> @@ -94,14 +93,14 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> start testpmd on vhost
> """
> self.dut.send_expect("killall -s INT testpmd", "#")
> - self.dut.send_expect("rm -rf %s/vhost-net*" % self.base_dir, "#")
> + self.dut.send_expect("rm -rf ./vhost-net*", "#")
> command_client = self.dut.target + "/app/testpmd " + \
> " -n %d -c %s --socket-mem 1024,1024 " + \
> " --legacy-mem --file-prefix=vhost " + \
> - " --vdev 'net_vhost0,iface=%s/vhost-net,queues=1' " + \
> + " --vdev 'net_vhost0,iface=vhost-net,queues=1' " + \
> " -- -i --nb-cores=1 --txd=1024 --rxd=1024"
> command_line_client = command_client % (
> - self.dut.get_memory_channels(), self.core_mask, self.base_dir)
> + self.dut.get_memory_channels(), self.core_mask)
> self.vhost.send_expect(command_line_client, "testpmd> ", 120)
> self.vhost.send_expect("set fwd mac", "testpmd> ", 120)
> self.vhost.send_expect("start", "testpmd> ", 120)
> @@ -134,7 +133,7 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> self.vm = VM(self.dut, 'vm0', 'vhost_sample')
> vm_params = {}
> vm_params['driver'] = 'vhost-user'
> - vm_params['opt_path'] = '%s/vhost-net' % self.base_dir
> + vm_params['opt_path'] = './vhost-net'
> vm_params['opt_mac'] = self.virtio1_mac
> if modem == 1 and mergeable == 0:
> vm_params['opt_settings'] = "disable-
> modern=false,mrg_rxbuf=off,rx_queue_size=1024,tx_queue_size=1024"
> @@ -206,7 +205,7 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> """
> pkt = Packet(pkt_type='IP_RAW', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/pvp_multipath.pcap" % (self.out_path))
> + pkt.save_pcapfile(self.tester, "%s/pvp_multipath.pcap" % (self.out_path))
>
> tgenInput = []
> port = self.tester.get_local_port(self.dut_ports[0])
> diff --git a/tests/TestSuite_pvp_vhost_user_reconnect.py
> b/tests/TestSuite_pvp_vhost_user_reconnect.py
> index c5c7b96..16a93b0 100644
> --- a/tests/TestSuite_pvp_vhost_user_reconnect.py
> +++ b/tests/TestSuite_pvp_vhost_user_reconnect.py
> @@ -41,7 +41,7 @@ import utils
> import time
> from test_case import TestCase
> from virt_common import VM
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -83,7 +83,6 @@ class TestPVPVhostUserReconnect(TestCase):
> self.tester.send_expect('mkdir -p %s' % self.out_path, '# ')
> # create an instance to set stream field setting
> self.pktgen_helper = PacketGeneratorHelper()
> - self.base_dir = self.dut.base_dir.replace('~', '/root')
>
> def set_up(self):
> """
> @@ -92,7 +91,7 @@ class TestPVPVhostUserReconnect(TestCase):
> """
> self.dut.send_expect("killall -s INT testpmd", "# ")
> self.dut.send_expect("killall -s INT qemu-system-x86_64", "# ")
> - self.dut.send_expect("rm -rf %s/vhost-net*" % self.base_dir, "# ")
> + self.dut.send_expect("rm -rf ./vhost-net*", "# ")
> self.vhost_user = self.dut.new_session(suite="vhost-user")
>
> def launch_testpmd_as_vhost_user(self):
> @@ -101,7 +100,7 @@ class TestPVPVhostUserReconnect(TestCase):
> """
> vdev_info = ""
> for i in range(self.vm_num):
> - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-
> net%d,client=1,queues=1' " % (i, self.base_dir, i)
> + vdev_info += "--vdev 'net_vhost%d,iface=vhost-net%d,client=1,queues=1' " %
> (i, i)
> self.vhostapp_testcmd = self.dut.base_dir + \
> "/%s/app/testpmd -c %s -n %d --socket-mem %s --legacy-mem" + \
> " --file-prefix=vhost %s" + \
> @@ -120,7 +119,7 @@ class TestPVPVhostUserReconnect(TestCase):
> """
> vdev_info = ""
> for i in range(self.vm_num):
> - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-
> net%d,client=1,queues=1' " % (i, self.base_dir, i)
> + vdev_info += "--vdev 'net_vhost%d,iface=vhost-net%d,client=1,queues=1' " %
> (i, i)
> self.vhostapp_testcmd = self.dut.base_dir + \
> "/%s/app/testpmd -c %s -n %d --socket-mem %s --legacy-mem" + \
> " --no-pci --file-prefix=vhost %s" + \
> @@ -181,7 +180,7 @@ class TestPVPVhostUserReconnect(TestCase):
> vm_info = VM(self.dut, 'vm%d' % i, 'vhost_sample')
> vm_params = {}
> vm_params['driver'] = 'vhost-user'
> - vm_params['opt_path'] = '%s/vhost-net%d' % (self.base_dir, i)
> + vm_params['opt_path'] = './vhost-net%d' % (i)
> vm_params['opt_mac'] = '52:54:00:00:00:0%d' % (i+1)
> vm_params['opt_server'] = 'server'
> vm_params['opt_settings'] =
> 'mrg_rxbuf=on,rx_queue_size=1024,tx_queue_size=1024'
> @@ -273,7 +272,7 @@ class TestPVPVhostUserReconnect(TestCase):
> pkt = Packet(pkt_type = 'UDP', pkt_len = frame_size)
> pkt.config_layers([('ether', {'dst': '%s' % self.dst_mac}),
> ('ipv4', {'dst': '%s' % self.dst1, 'src': '%s' % self.src1})])
> - save_packets([pkt], "%s/reconnect.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/reconnect.pcap" % self.out_path)
>
> tgenInput = []
> port = self.tester.get_local_port(self.pf)
> diff --git a/tests/TestSuite_pvp_virtio_bonding.py
> b/tests/TestSuite_pvp_virtio_bonding.py
> index 4fb94f2..874c058 100644
> --- a/tests/TestSuite_pvp_virtio_bonding.py
> +++ b/tests/TestSuite_pvp_virtio_bonding.py
> @@ -40,7 +40,7 @@ import utils
> from test_case import TestCase
> from virt_common import VM
> from pmd_output import PmdOutput
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -69,7 +69,6 @@ class TestPVPVirtIOBonding(TestCase):
> self.tester.send_expect('mkdir -p %s' % self.out_path, '# ')
> # create an instance to set stream field setting
> self.pktgen_helper = PacketGeneratorHelper()
> - self.base_dir = self.dut.base_dir.replace('~', '/root')
>
> def set_up(self):
> """
> @@ -87,7 +86,7 @@ class TestPVPVirtIOBonding(TestCase):
> """
> vdev_info = ""
> for i in range(self.queues):
> - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-
> net%d,client=1,queues=1' " % (i, self.base_dir, i)
> + vdev_info += "--vdev 'net_vhost%d,iface=vhost-net%d,client=1,queues=1' " %
> (i, i)
> params = "--port-topology=chained --nb-cores=4 --txd=1024 --rxd=1024"
> eal_param = "--socket-mem 2048,2048 --legacy-mem --file-prefix=vhost %s " %
> vdev_info
> self.vhost_testpmd = PmdOutput(self.dut)
> @@ -168,7 +167,7 @@ class TestPVPVirtIOBonding(TestCase):
> tx_port = self.tester.get_local_port(self.dut_ports[0])
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/bonding.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/bonding.pcap" % self.out_path)
> tgen_input.append((tx_port, rx_port, "%s/bonding.pcap" % self.out_path))
> self.tester.pktgen.clear_streams()
> streams = self.pktgen_helper.prepare_stream_from_tginput(tgen_input, 100,
> None, self.tester.pktgen)
> @@ -196,7 +195,7 @@ class TestPVPVirtIOBonding(TestCase):
> for i in range(self.queues):
> vm_params['opt_server'] = 'server'
> vm_params['driver'] = 'vhost-user'
> - vm_params['opt_path'] = '%s/vhost-net%d' % (self.base_dir, i)
> + vm_params['opt_path'] = './vhost-net%d' % i
> vm_params['opt_mac'] = "%s%d" % (virtio_mac, i+1)
> self.vm.set_vm_device(**vm_params)
> self.set_vm_vcpu()
> diff --git a/tests/TestSuite_pvp_virtio_user_4k_pages.py
> b/tests/TestSuite_pvp_virtio_user_4k_pages.py
> index d2b8df7..95b5494 100644
> --- a/tests/TestSuite_pvp_virtio_user_4k_pages.py
> +++ b/tests/TestSuite_pvp_virtio_user_4k_pages.py
> @@ -37,7 +37,7 @@ vhost/virtio-user pvp with 4K pages.
> import utils
> import time
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -108,7 +108,7 @@ class TestPvpVirtioUser4kPages(TestCase):
> tx_port = self.tester.get_local_port(self.dut_ports[0])
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/vhost.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/vhost.pcap" % self.out_path)
> tgen_input.append((tx_port, rx_port, "%s/vhost.pcap" % self.out_path))
>
> self.tester.pktgen.clear_streams()
> @@ -138,7 +138,6 @@ class TestPvpVirtioUser4kPages(TestCase):
> command_line_client = command_line_client % (self.target,
> self.core_mask_vhost_user, self.mem_channels, self.ports_socket)
> self.vhost_user.send_expect(command_line_client, "testpmd> ", 120)
> - self.vhost_user.send_expect("set fwd mac", "testpmd> ", 120)
> self.vhost_user.send_expect("start", "testpmd> ", 120)
>
> def start_testpmd_as_virtio(self):
> diff --git a/tests/TestSuite_queue_region.py b/tests/TestSuite_queue_region.py
> index a4d9bf7..eea873e 100644
> --- a/tests/TestSuite_queue_region.py
> +++ b/tests/TestSuite_queue_region.py
> @@ -148,7 +148,7 @@ class TestQueue_region(TestCase):
> pkt = Packet()
> pkt.assign_layers(['ether', 'raw'])
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac, 'type': ethertype})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> def send_packet_up(self, mac, pkt_type="udp", prio=0):
> """
> @@ -173,7 +173,7 @@ class TestQueue_region(TestCase):
> pkt.assign_layers(['ether', 'vlan', 'ipv6', 'udp', 'raw'])
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> pkt.config_layer('vlan', {'vlan': 0, 'prio': prio})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> def get_and_compare_rules(self, out, QueueRegion_num, FlowType_num, UP_num):
> """
> diff --git a/tests/TestSuite_queue_start_stop.py
> b/tests/TestSuite_queue_start_stop.py
> index e91ea91..48f9c1a 100644
> --- a/tests/TestSuite_queue_start_stop.py
> +++ b/tests/TestSuite_queue_start_stop.py
> @@ -101,11 +101,11 @@ class TestQueueStartStop(TestCase):
> pkt = Packet(pkt_type="UDP", pkt_len=pktSize)
> inst = self.tester.tcpdump_sniff_packets(rxitf)
> pkt.config_layer('ether', {'dst': dmac})
> - pkt.send_pkt(tx_port=txitf, count=4)
> + pkt.send_pkt(self.tester, tx_port=txitf, count=4)
> sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
>
> if received:
> - res = strip_pktload(sniff_pkts[0], layer="L4")
> + res = strip_pktload(sniff_pkts, layer="L4")
> self.verify("58 58 58 58 58 58 58 58" in res, "receive queue not work as
> expected")
> else:
> self.verify(len(sniff_pkts) == 0, "stop queue not work as expected")
> diff --git a/tests/TestSuite_quota_watermark.py
> b/tests/TestSuite_quota_watermark.py
> index ad4ec3b..0541eef 100644
> --- a/tests/TestSuite_quota_watermark.py
> +++ b/tests/TestSuite_quota_watermark.py
> @@ -310,7 +310,7 @@ class TestQuotaWatermark(TestCase, IxiaPacketGenerator):
> rx_intf = self.tester.get_interface(rev_port)
> tx_intf = self.tester.get_interface(send_port)
> # send and sniff packet
> - rx_inst = self.tester.tcpdump_sniff_packets(rx_intf, timeout=5)
> + rx_inst = self.tester.tcpdump_sniff_packets(rx_intf)
> self.send_pcap_pkt_by_scapy(self.tester, tgen_input[0][2], tx_intf)
> pkts = self.tester.load_tcpdump_sniff_packets(rx_inst)
> self.verify(len(pkts) == pkt_cnt, "Packet not forwarded as expected")
> diff --git a/tests/TestSuite_runtime_vf_queue_number.py
> b/tests/TestSuite_runtime_vf_queue_number.py
> index 63a5e18..227d815 100644
> --- a/tests/TestSuite_runtime_vf_queue_number.py
> +++ b/tests/TestSuite_runtime_vf_queue_number.py
> @@ -39,6 +39,7 @@ import re
> from qemu_kvm import QEMUKvm
> from test_case import TestCase
> from pmd_output import PmdOutput
> +from packet import Packet
>
> RSS_KEY =
> '6EA6A420D5138E712433B813AE45B3C4BECB2B405F31AD6C331835372D15E2
> D5E49566EE0ED1962AFA1B7932F3549520FD71C75E'
> PACKET_COUNT = 100
> @@ -128,15 +129,9 @@ class TestRuntimeVfQn(TestCase):
> """
> Sends packets.
> """
> - self.tester.scapy_foreground()
> - time.sleep(2)
> - for i in range(integer):
> - quotient = i // 254
> - remainder = i % 254
> - packet = r'sendp([Ether(dst="%s",
> src=get_if_hwaddr("%s"))/IP(src="10.0.0.1", dst="192.168.%d.%d")], iface="%s")' %
> (vf_mac, itf, quotient, remainder + 1, itf)
> - self.tester.scapy_append(packet)
> - self.tester.scapy_execute()
> - time.sleep(2)
> + pkt = Packet()
> + pkt.generate_random_pkts(vf_mac, pktnum=integer, random_type=['IP_RAW'])
> + pkt.send_pkt(self.tester, tx_port=itf)
>
> def verify_queue_number(self, outstring, qn, pkt_count):
> total_rx = []
> diff --git a/tests/TestSuite_runtime_vf_queue_number_kernel.py
> b/tests/TestSuite_runtime_vf_queue_number_kernel.py
> index 9416f13..73d40c2 100644
> --- a/tests/TestSuite_runtime_vf_queue_number_kernel.py
> +++ b/tests/TestSuite_runtime_vf_queue_number_kernel.py
> @@ -41,6 +41,7 @@ import utils
> from pmd_output import PmdOutput
> from test_case import TestCase
> from virt_common import VM
> +from packet import Packet
>
> VM_CORES_MASK = 'all'
>
> @@ -75,6 +76,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> def set_up(self):
> pass
> +
> def setup_1pf_2vf_1vm_env(self,driver="default"):
>
> self.used_dut_port = self.dut_ports[0]
> @@ -90,9 +92,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> - self.host_testpmd.start_testpmd("Default", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("Default")
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'runtime_vf_queue_number_kernel')
> self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop)
> @@ -131,15 +131,11 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> self.setup_1pf_2vf_1vm_env_flag = 0
>
> - def send_packet2different_queue(self, dts, src, iface, count):
> - self.tester.scapy_foreground()
> - for i in range(1,count+1):
> - j = (i//255)%255
> - k = i%255
> - pkt = 'sendp([Ether(dst="%s",
> src="%s")/IP(src="192.168.%d.%d",dst="192.168.13.%d")/("test"*10)],iface="%s"
> )' % (
> - dts, src, j,k,k, iface)
> - self.tester.scapy_append(pkt)
> - self.tester.scapy_execute()
> + def send_packet2different_queue(self, dst, src, iface, count):
> + pkt = Packet()
> + pkt.generate_random_pkts(pktnum=count, random_type=['IP_RAW'],
> + options={'layers_config': [('ether', {'dst': '%s' % dst, 'src': '%s' %
> src})]})
> + pkt.send_pkt(self.tester, tx_port=iface)
>
> def check_result(self, nr_queue, out, out2, pkts_num, count, misc):
> if nr_queue == 1:
> @@ -189,7 +185,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> self.vm0_testpmd.execute_cmd('set verbose 1')
> self.vm0_testpmd.execute_cmd('set promisc all off')
> - #set rss-hash-key to a fixed value instead of default random value on vf
> + #set rss-hash-key to a fixed value instead of default random value on vf
> self.vm0_testpmd.execute_cmd('port config 0 rss-hash-key ipv4
> 6EA6A420D5138E712433B813AE45B3C4BECB2B405F31AD6C331835372D15E2D
> 5E49566EE0ED1962AFA1B7932F3549520FD71C75E')
> time.sleep(1)
> self.vm0_testpmd.execute_cmd('set fwd mac')
> @@ -297,6 +293,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> def tear_down(self):
> self.vm0_testpmd.execute_cmd('quit', '# ')
> + self.dut.kill_all()
>
> def tear_down_all(self):
> self.logger.info("tear_down_all")
> diff --git a/tests/TestSuite_rxtx_callbacks.py b/tests/TestSuite_rxtx_callbacks.py
> index 76ad70f..a2da0d9 100644
> --- a/tests/TestSuite_rxtx_callbacks.py
> +++ b/tests/TestSuite_rxtx_callbacks.py
> @@ -90,8 +90,8 @@ class TestRxtxCallbacks(TestCase):
> def get_tcpdump_package(self,inst):
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> dsts = []
> - for packet in pkts:
> - dst = packet.strip_element_layer2("dst")
> + for i in range(len(pkts)):
> + dst = pkts.strip_element_layer2("dst", p_index=i)
> dsts.append(dst)
> return dsts
>
> diff --git a/tests/TestSuite_scatter.py b/tests/TestSuite_scatter.py
> index cc441df..6802f52 100644
> --- a/tests/TestSuite_scatter.py
> +++ b/tests/TestSuite_scatter.py
> @@ -85,12 +85,12 @@ class TestScatter(TestCase):
> inst = self.tester.tcpdump_sniff_packets(self.intf)
> pkt = Packet(pkt_type="IP_RAW", pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': dmac})
> - pkt.send_pkt(tx_port=self.intf)
> + pkt.send_pkt(self.tester, tx_port=self.intf)
> sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
>
> res = ""
> if len(sniff_pkts):
> - res = strip_pktload(sniff_pkts[0], layer="L4")
> + res = strip_pktload(sniff_pkts, layer="L4")
> return res
>
> def set_up(self):
> diff --git a/tests/TestSuite_short_live.py b/tests/TestSuite_short_live.py
> index 93ec587..4e1ee15 100644
> --- a/tests/TestSuite_short_live.py
> +++ b/tests/TestSuite_short_live.py
> @@ -102,7 +102,7 @@ class TestShortLiveApp(TestCase):
> if (txPort == rxPort):
> count = 2
>
> - inst = self.tester.tcpdump_sniff_packets(rxitf, count=count, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(rxitf, count=count)
>
> pktlen = pktSize - 14
> padding = pktlen - 20
> @@ -112,7 +112,7 @@ class TestShortLiveApp(TestCase):
> time.sleep(3)
>
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> - out = str(pkts[0].pktgen.pkt.show)
> + out = str(pkts[0].show)
> self.logger.info('SCAPY Result:\n' + out + '\n\n\n')
> if received:
> self.verify(('PPP' in out) and 'src=%s'% Dut_tx_mac in out, "Receive test
> failed")
> diff --git a/tests/TestSuite_skeleton.py b/tests/TestSuite_skeleton.py
> index 91cf9c4..38bc523 100644
> --- a/tests/TestSuite_skeleton.py
> +++ b/tests/TestSuite_skeleton.py
> @@ -93,8 +93,8 @@ class TestSkeleton(TestCase):
> def get_tcpdump_package(self,inst):
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> dsts = []
> - for packet in pkts:
> - dst = packet.strip_element_layer2("dst")
> + for i in range(len(pkts)):
> + dst = pkts.strip_element_layer2("dst", p_index=i)
> dsts.append(dst)
> return dsts
>
> diff --git a/tests/TestSuite_sriov_kvm.py b/tests/TestSuite_sriov_kvm.py
> index 3518f8f..6a28129 100644
> --- a/tests/TestSuite_sriov_kvm.py
> +++ b/tests/TestSuite_sriov_kvm.py
> @@ -359,10 +359,8 @@ class TestSriovKvm(TestCase):
> if driver == 'igb_uio':
> # start testpmd with the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> self.host_testpmd.start_testpmd(
> - "1S/2C/2T", "--rxq=4 --txq=4", eal_param=eal_param)
> + "1S/2C/2T", "--rxq=4 --txq=4")
> self.host_testpmd.execute_cmd('set fwd rxonly')
> self.host_testpmd.execute_cmd('start')
>
> @@ -439,13 +437,8 @@ class TestSriovKvm(TestCase):
> if driver == 'igb_uio':
> # start testpmd with the four VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0) -b %(vf1)s -b %(vf2)s -b %(vf3)s' % \
> - {'vf0': self.sriov_vfs_pci[0],
> - 'vf1': self.sriov_vfs_pci[1],
> - 'vf2': self.sriov_vfs_pci[2],
> - 'vf3': self.sriov_vfs_pci[3]}
> self.host_testpmd.start_testpmd(
> - "1S/2C/2T", eal_param=eal_param)
> + "1S/2C/2T")
>
> self.vm0 = VM(self.dut, 'vm0', 'sriov_kvm')
> self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop)
> diff --git a/tests/TestSuite_uni_pkt.py b/tests/TestSuite_uni_pkt.py
> index 9a75061..0310e04 100644
> --- a/tests/TestSuite_uni_pkt.py
> +++ b/tests/TestSuite_uni_pkt.py
> @@ -81,7 +81,7 @@ class TestUniPacket(TestCase):
> for pkt_type in pkt_types.keys():
> pkt_names = pkt_types[pkt_type]
> pkt = Packet(pkt_type=pkt_type)
> - pkt.send_pkt(tx_port=self.tester_iface, count=4)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface, count=4)
> out = self.dut.get_session_output(timeout=2)
> for pkt_layer_name in pkt_names:
> if pkt_layer_name not in out:
> @@ -111,10 +111,10 @@ class TestUniPacket(TestCase):
> for l2_type in self.L2_types.keys():
> pkt_name = self.L2_types[l2_type]
> pkt = Packet(pkt_type=l2_type)
> - pkt.send_pkt(tx_port=self.tester_iface)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface)
> out = self.dut.get_session_output(timeout=2)
> if pkt_name in out:
> - print utils.GREEN("Detected L2 %s successfully" % l2_type)
> + print(utils.GREEN("Detected L2 %s successfully" % l2_type))
> else:
> raise VerifyFailure("Failed to detect L2 %s" % l2_type)
>
> @@ -347,7 +347,7 @@ class TestUniPacket(TestCase):
> pkt.config_layers([('ipv6',{'nh':47}), ('inner_ipv6', {'nh': 58})])
> else:
> pkt.config_layers([('ipv6',{'nh':47}),('inner_ipv6', {'nh': 132})])
> - pkt.send_pkt(tx_port=self.tester_iface)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface)
> out = self.dut.get_session_output(timeout=2)
> for pkt_layer_name in pkts[1]:
> if pkt_layer_name not in out:
> @@ -445,7 +445,6 @@ class TestUniPacket(TestCase):
>
> for packet in nsh_packets:
> self.tester.scapy_foreground()
> - self.tester.scapy_append("from scapy.contrib.nsh import *")
> self.tester.scapy_append("sendp([%s],iface='%s')" % (nsh_packets[packet],
> self.tester_iface))
> self.tester.scapy_execute()
> out = self.dut.get_session_output(timeout=2)
> diff --git a/tests/TestSuite_userspace_ethtool.py
> b/tests/TestSuite_userspace_ethtool.py
> index 0a4b772..116fd3a 100644
> --- a/tests/TestSuite_userspace_ethtool.py
> +++ b/tests/TestSuite_userspace_ethtool.py
> @@ -297,7 +297,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> ori_rx_pkts, ori_tx_pkts = self.strip_portstats(port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> time.sleep(1)
> rx_pkts, tx_pkts = self.strip_portstats(port)
> self.verify((rx_pkts == (ori_rx_pkts + 4)), "Failed to record Rx/Tx packets")
> @@ -406,10 +406,10 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> rx_ring, _, tx_ring, _ = self.strip_ringparam(index)
> self.verify(rx_ring == rx_max, "Userspace tool failed to set Rx ring parameter")
> self.verify(tx_ring == tx_max, "Userspace tool failed to set Tx ring parameter")
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP')
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, tx_pkts = self.strip_portstats(index)
> self.verify(rx_pkts == ori_rx_pkts + 4, "Failed to forward after ring parameter
> changed")
> self.dut.send_expect("quit", "# ")
> @@ -441,7 +441,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
> pkt.config_layer('vlan', {'vlan': vlan})
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, tx_pkts = self.strip_portstats(port)
> self.verify(rx_pkts == ori_rx_pkts + 4, "Failed to Rx vlan packet")
> self.verify(tx_pkts == ori_tx_pkts + 4, "Failed to Tx vlan packet")
> @@ -449,7 +449,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
> # send incorrect vlan packet to port
> wrong_vlan = (vlan + 1) % 4096
> pkt.config_layer('vlan', {'vlan': wrong_vlan})
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> time.sleep(2)
> rx_pkts_wrong, tx_pkts_wrong = self.strip_portstats(port)
> self.verify(tx_pkts_wrong == rx_pkts, "Failed to filter Rx vlan packet")
> @@ -458,7 +458,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("vlan %d del %d" % (index, vlan), "EthApp>")
> # send same packet and make sure not received
> pkt.config_layer('vlan', {'vlan': vlan})
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> time.sleep(2)
> rx_pkts_del, tx_pkts_del = self.strip_portstats(port)
> self.verify(tx_pkts_del == rx_pkts, "Failed to remove Rx vlan filter")
> @@ -483,15 +483,15 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> dump_mac = self.strip_mac(index)
> self.verify(dump_mac == valid_mac, "Userspace tool failed to set mac")
> # check forwarded mac has been changed
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP')
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> # send and sniff packet
> - inst = self.tester.tcpdump_sniff_packets(intf, timeout=5)
> - pkt.send_pkt(tx_port=intf, count=4)
> + inst = self.tester.tcpdump_sniff_packets(intf)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> self.verify(len(pkts) == 4, "Packet not forwarded as expected")
> - src_mac = pkts[0].strip_layer_element("layer2", "src")
> + src_mac = pkts.strip_layer_element("layer2", "src", p_index=0)
> self.verify(src_mac == valid_mac, "Forwarded packet not match default mac")
>
> # check multicast will not be valid mac
> @@ -519,10 +519,10 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> self.dut.send_expect("stop %d" % index, "EthApp>")
> time.sleep(10)
> # check packet not forwarded when port is stop
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP')
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, tx_pkts = self.strip_portstats(index)
> self.verify(rx_pkts == ori_rx_pkts, "Failed to stop port")
> # restart port and check packet can normally forwarded
> @@ -531,7 +531,7 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
> # wait few time for port ready
> rx_pkts, tx_pkts = self.strip_portstats(index)
> time.sleep(2)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts_open, tx_pkts_open = self.strip_portstats(index)
> self.verify(rx_pkts_open == rx_pkts + 4, "Failed to reopen port rx")
> self.verify(tx_pkts_open == tx_pkts + 4, "Failed to reopen port tx")
> @@ -568,12 +568,12 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> time.sleep(5)
> ori_rx_pkts, _ = self.strip_portstats(index)
> pkt_size = mtu + HEADER_SIZE['eth'] + offset
> - pkt = Packet(pkt_len=pkt_size)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt = Packet(pkt_type='UDP', pkt_len=pkt_size)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, _ = self.strip_portstats(index)
> self.verify(rx_pkts == ori_rx_pkts + 4, "Packet match mtu not forwarded as
> expected")
> - pkt = Packet(pkt_len=mtu + 1 + HEADER_SIZE['eth'] + offset)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt = Packet(pkt_type='UDP', pkt_len=mtu + 1 + HEADER_SIZE['eth'] +
> offset)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts_over, _ = self.strip_portstats(index)
> self.verify(rx_pkts == rx_pkts_over, "Packet over mtu should not be
> forwarded")
>
> diff --git a/tests/TestSuite_veb_switch.py b/tests/TestSuite_veb_switch.py
> index 78fcbbd..e60a618 100644
> --- a/tests/TestSuite_veb_switch.py
> +++ b/tests/TestSuite_veb_switch.py
> @@ -120,12 +120,12 @@ class TestVEBSwitching(TestCase):
> pkt = Packet(pkt_type='VLAN_UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> pkt.config_layer('vlan', {'vlan': 1})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
> else:
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
>
> def count_packet(self, out, mac):
> diff --git a/tests/TestSuite_vf_daemon.py b/tests/TestSuite_vf_daemon.py
> index fcbf5b8..5b738c7 100644
> --- a/tests/TestSuite_vf_daemon.py
> +++ b/tests/TestSuite_vf_daemon.py
> @@ -90,12 +90,9 @@ class TestVfDaemon(TestCase):
> for port in self.sriov_vfs_port:
> port.bind_driver(self.vf_driver)
> time.sleep(1)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> -
> self.dut_testpmd = PmdOutput(self.dut)
> self.dut_testpmd.start_testpmd(
> - "Default", "--rxq=4 --txq=4 --port-topology=chained", eal_param=eal_param)
> + "Default", "--rxq=4 --txq=4 --port-topology=chained")
> self.dut_testpmd.execute_cmd("start")
> time.sleep(5)
>
> @@ -166,8 +163,8 @@ class TestVfDaemon(TestCase):
> pkt.config_layer('vlan', {'vlan': vlan_id})
> pkt.config_layer('ether', {'dst': dst_mac})
>
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=30)
> - pkt.send_pkt(tx_port=self.tester_intf, count=num)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num)
> return inst
>
> def strip_mac(self, inst, element = "src"):
> @@ -176,8 +173,8 @@ class TestVfDaemon(TestCase):
> """
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> macs = []
> - for pkt in pkts:
> - mac = pkt.strip_element_layer2(element)
> + for i in range(len(pkts)):
> + mac = pkts.strip_element_layer2(element, p_index=i)
> macs.append(mac)
> return macs
>
> @@ -187,8 +184,8 @@ class TestVfDaemon(TestCase):
> """
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> vlans = []
> - for pkt in pkts:
> - vlan = pkt.strip_element_vlan("vlan")
> + for i in range(len(pkts)):
> + vlan = pkts.strip_element_vlan("vlan", p_index=i)
> vlans.append(vlan)
> return vlans
>
> @@ -434,7 +431,7 @@ class TestVfDaemon(TestCase):
> self.dut_testpmd.execute_cmd('set tx loopback 0 off')
> time.sleep(5)
>
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf)
>
> self.vm1_testpmd.execute_cmd('set burst 5')
> self.vm1_testpmd.execute_cmd('start tx_first')
> @@ -450,7 +447,7 @@ class TestVfDaemon(TestCase):
> self.dut_testpmd.execute_cmd('set tx loopback 0 on')
> time.sleep(3)
>
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf)
>
> self.vm1_testpmd.execute_cmd('stop')
> self.vm1_testpmd.execute_cmd('start tx_first')
> diff --git a/tests/TestSuite_vf_interrupt_pmd.py
> b/tests/TestSuite_vf_interrupt_pmd.py
> index cc15ac6..0b1f858 100644
> --- a/tests/TestSuite_vf_interrupt_pmd.py
> +++ b/tests/TestSuite_vf_interrupt_pmd.py
> @@ -108,7 +108,7 @@ class TestVfInterruptPmd(TestCase):
> """
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> - pkt.send_pkt(tx_port=testinterface)
> + pkt.send_pkt(self.tester, tx_port=testinterface)
>
> self.out2 = use_dut.get_session_output(timeout=2)
>
> diff --git a/tests/TestSuite_vf_jumboframe.py b/tests/TestSuite_vf_jumboframe.py
> index f082cec..dd728d9 100644
> --- a/tests/TestSuite_vf_jumboframe.py
> +++ b/tests/TestSuite_vf_jumboframe.py
> @@ -174,7 +174,7 @@ class TestVfJumboFrame(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': mac})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> time.sleep(1)
>
> diff --git a/tests/TestSuite_vf_kernel.py b/tests/TestSuite_vf_kernel.py
> index bee30a0..9a280b1 100644
> --- a/tests/TestSuite_vf_kernel.py
> +++ b/tests/TestSuite_vf_kernel.py
> @@ -119,12 +119,8 @@ class TestVfKernel(TestCase):
> time.sleep(1)
>
> self.dut_testpmd = PmdOutput(self.dut)
> - eal_param = ''
> - for sriov_vf in self.sriov_vfs_port:
> - eal_param += " -b %s" % sriov_vf.pci
> self.dut_testpmd.start_testpmd(
> - "Default", "--rxq=4 --txq=4 --port-topology=chained",
> - eal_param=eal_param)
> + "Default", "--rxq=4 --txq=4 --port-topology=chained")
> # dpdk-2208
> # since there is no forward engine on DPDK PF to forward or drop packet in
> packet pool,
> # so finally the pool will be full, then no more packet will be
> @@ -412,12 +408,12 @@ class TestVfKernel(TestCase):
> if vlan_id == '':
> pkt = Packet(pkt_type='TCP', pkt_len=pkt_lens)
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> - pkt.send_pkt(tx_port=self.tester_intf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num)
> else:
> pkt = Packet(pkt_type='VLAN_UDP', pkt_len=pkt_lens)
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> pkt.config_layer('vlan', {'vlan': vlan_id})
> - pkt.send_pkt(tx_port=self.tester_intf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num)
>
> def test_vlan(self):
> """
> @@ -873,8 +869,7 @@ class TestVfKernel(TestCase):
>
> # Link down DPDK VF0 and expect no impact on other VFs
> self.vm0_testpmd.quit()
> - eal_param = '-b %(vf0)s' % ({'vf0': self.vm0_dut.ports_info[0]['pci']})
> - self.vm0_testpmd.start_testpmd("Default", eal_param=eal_param)
> + self.vm0_testpmd.start_testpmd("Default")
> self.vm0_testpmd.execute_cmd('set promisc all on')
> self.vm0_testpmd.execute_cmd('set fwd rxonly')
> self.vm0_testpmd.execute_cmd('set verbose 1')
> diff --git a/tests/TestSuite_vf_macfilter.py b/tests/TestSuite_vf_macfilter.py
> index f7bba1a..01da9b4 100644
> --- a/tests/TestSuite_vf_macfilter.py
> +++ b/tests/TestSuite_vf_macfilter.py
> @@ -67,12 +67,10 @@ class TestVfMacFilter(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port_0[0].pci,
> - 'vf1': self.sriov_vfs_port_1[0].pci}
> if (self.nic in ["niantic", "sageville", "sagepond"]):
> - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ")
> else:
> - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_macfilter')
> @@ -158,7 +156,7 @@ class TestVfMacFilter(TestCase):
>
> print "\nfirst send packets to the PF set MAC, expected result is RX packets=TX
> packets\n"
> result1 = self.tester.check_random_pkts(tgen_ports, pktnum=100,
> allow_miss=False, params=pkt_param)
> - print "\nshow port stats in testpmd for double check: \n",
> self.vm0_testpmd.execute_cmd('show port stats all')
> + print "\nshow port stats in testpmd for double check: \n",
> self.vm0_testpmd.execute_cmd('show port stats all')
> self.verify(result1 != False, "VF0 failed to forward packets to VF1")
>
> print "\nSecondly, negative test, send packets to a wrong MAC, expected result
> is RX packets=0\n"
> @@ -259,6 +257,7 @@ class TestVfMacFilter(TestCase):
>
> if self.setup_2pf_2vf_1vm_env_flag == 1:
> self.destroy_2pf_2vf_1vm_env()
> + self.dut.kill_all()
>
> def tear_down_all(self):
>
> diff --git a/tests/TestSuite_vf_offload.py b/tests/TestSuite_vf_offload.py
> index dc5cb30..421d9c4 100644
> --- a/tests/TestSuite_vf_offload.py
> +++ b/tests/TestSuite_vf_offload.py
> @@ -71,9 +71,7 @@ class TestVfOffload(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port_0[0].pci,
> - 'vf1': self.sriov_vfs_port_1[0].pci}
> - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_offload')
> diff --git a/tests/TestSuite_vf_packet_rxtx.py b/tests/TestSuite_vf_packet_rxtx.py
> index 8a8816d..c111c9e 100644
> --- a/tests/TestSuite_vf_packet_rxtx.py
> +++ b/tests/TestSuite_vf_packet_rxtx.py
> @@ -6,6 +6,7 @@ import time
> from virt_common import VM
> from test_case import TestCase
> from pmd_output import PmdOutput
> +from packet import Packet
>
> VM_CORES_MASK = 'all'
>
> @@ -64,12 +65,10 @@ class TestVfPacketRxtx(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port_0[0].pci,
> - 'vf1': self.sriov_vfs_port_1[0].pci}
> if (self.nic in ["niantic", "sageville", "sagepond"]):
> - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ")
> else:
> - self.host_testpmd.start_testpmd("1S/5C/1T", "", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/5C/1T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_packet_rxtx')
> @@ -189,13 +188,10 @@ class TestVfPacketRxtx(TestCase):
>
> if driver == 'igb_uio':
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s -b %(vf2)s' % {'vf0':
> self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci,
> - 'vf2': self.sriov_vfs_port[2].pci}
> if (self.nic in ["niantic", "sageville", "sagepond"]):
> - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ")
> else:
> - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_packet_rxtx')
> @@ -290,7 +286,8 @@ class TestVfPacketRxtx(TestCase):
>
> dst_mac = pmd0_vf0_mac
> self.vm0_testpmd.execute_cmd('clear port stats all')
> - self.tester.sendpkt_bg(tx_port, dst_mac)
> + pkt = Packet("Ether(dst='%s', src='%s')/IP(len=46)" % (dst_mac,
> self.tester.get_mac(tx_port)))
> + filename = pkt.send_pkt_bg(crb=self.tester,
> tx_port=self.tester.get_interface(tx_port), loop=1)
>
> #vf port stop/start can trigger reset action
> for num in range(1000):
> @@ -299,7 +296,7 @@ class TestVfPacketRxtx(TestCase):
> self.vm1_testpmd.execute_cmd('port start all')
> time.sleep(0.1)
>
> - self.tester.stop_sendpkt_bg()
> + pkt.stop_send_pkt_bg(self.tester, filename)
>
> pmd0_vf0_stats = self.vm0_testpmd.get_pmd_stats(port_id_0)
> pmd0_vf1_stats = self.vm0_testpmd.get_pmd_stats(port_id_1)
> diff --git a/tests/TestSuite_vf_port_start_stop.py
> b/tests/TestSuite_vf_port_start_stop.py
> index 2ff2d1c..dcd799b 100644
> --- a/tests/TestSuite_vf_port_start_stop.py
> +++ b/tests/TestSuite_vf_port_start_stop.py
> @@ -10,6 +10,7 @@ from utils import RED, GREEN
> from net_device import NetDevice
> from crb import Crb
> from scapy.all import *
> +from scapy.layers.sctp import SCTP, SCTPChunkData
> VM_CORES_MASK = 'all'
>
> class TestVfPortStartStop(TestCase):
> @@ -22,7 +23,9 @@ class TestVfPortStartStop(TestCase):
> self.verify(len(self.dut_ports) >= 1, "Insufficient ports")
> self.vm0 = None
> self.filename = "/tmp/vf.pcap"
> -
> + self.tester_tx_port = self.tester.get_local_port(self.dut_ports[0])
> + self.tester_tintf = self.tester.get_interface(self.tester_tx_port)
> + self.send_pks_session = None
> # set vf assign method and vf driver
> self.vf_driver = self.get_suite_cfg()['vf_driver']
> if self.vf_driver is None:
> @@ -38,71 +41,23 @@ class TestVfPortStartStop(TestCase):
>
> self.setup_1pf_2vf_1vm_env_flag = 0
>
> - def pktgen_prerequisites(self):
> - """
> - igb_uio.ko should be put in ~ before you using pktgen
> - """
> - out = self.tester.send_expect("ls", "#")
> - self.verify("igb_uio.ko" in out, "No file igb_uio.ko, please add it in ~")
> - self.tester.send_expect("modprobe uio", "#", 70)
> - out = self.tester.send_expect("lsmod | grep igb_uio", "#")
> - if "igb_uio" in out:
> - self.tester.send_expect("rmmod -f igb_uio", "#", 70)
> - self.tester.send_expect("insmod ~/igb_uio.ko", "#", 60)
> - out = self.tester.send_expect("lsmod | grep igb_uio", "#")
> - assert ("igb_uio" in out), "Failed to insmod igb_uio"
> -
> - total_huge_pages = self.tester.get_total_huge_pages()
> - if total_huge_pages == 0:
> - self.tester.mount_huge_pages()
> - self.tester.set_huge_pages(2048)
> -
> - def pktgen_kill(self):
> - """
> - Kill all pktgen on tester.
> - """
> - pids = []
> - pid_reg = r'p(\d+)'
> - out = self.tester.alt_session.send_expect("lsof -Fp /var/run/.pg_config", "#", 20)
> - if len(out):
> - lines = out.split('\r\n')
> - for line in lines:
> - m = re.match(pid_reg, line)
> - if m:
> - pids.append(m.group(1))
> - for pid in pids:
> - self.tester.alt_session.send_expect('kill -9 %s' % pid, '# ', 20)
> -
> def send_and_verify(self, dst_mac, testpmd):
> """
> Generates packets by pktgen
> """
> self.testpmd_reset_status(testpmd)
>
> - self.pktgen_prerequisites()
> - # bind ports
> - self.tester_tx_port = self.tester.get_local_port(self.dut_ports[0])
> - self.tester_tx_pci = self.tester.ports_info[self.tester_tx_port]['pci']
> - port = self.tester.ports_info[self.tester_tx_port]['port']
> - self.tester_port_driver = port.get_nic_driver()
> - self.tester.send_expect("./dpdk-devbind.py --force --bind=igb_uio %s" %
> self.tester_tx_pci, "#")
> -
> - src_mac = self.tester.get_mac(self.tester_tx_port)
> + src_mac = self.tester.get_mac(self.tester_tx_port)
> if src_mac == 'N/A':
> src_mac = "02:00:00:00:01"
> -
> - self.create_pcap_file(self.filename, dst_mac, src_mac)
> -
> - self.tester.send_expect("./pktgen -c 0x1f -n 2 --proc-type auto --socket-mem
> 128,128 --file-prefix pg -- -P -T -m '1.0' -s 0:%s" % self.filename, "Pktgen >", 100)
> - time.sleep(1)
> - self.tester.send_expect("start all", "Pktgen>")
> + self.send_pkts(self.filename, dst_mac, src_mac)
> time.sleep(1)
> self.check_port_start_stop(testpmd)
> - # quit pktgen
> - self.tester.send_expect("stop all", "Pktgen>")
> - self.tester.send_expect("quit", "# ")
> + self.tester.send_expect('killall -s INT scapy', '# ')
> + self.tester.destroy_session(self.send_pks_session)
> + self.send_pks_session = None
>
> - def create_pcap_file(self, filename, dst_mac, src_mac):
> + def send_pkts(self, filename, dst_mac, src_mac):
> """
> Generates a valid PCAP file with the given configuration.
> """
> @@ -115,9 +70,14 @@ class TestVfPortStartStop(TestCase):
> pkts = []
> for key in def_pkts.keys():
> pkts.append(def_pkts[key])
> -
> wrpcap(filename, pkts)
>
> + sendp_fmt = "sendp(pk, iface='%s', loop=1)" % (self.tester_tintf)
> + self.send_pks_session = self.tester.create_session("scapy1")
> + self.send_pks_session.send_expect("scapy", ">>>")
> + self.send_pks_session.send_expect("pk=rdpcap('%s')" % filename, ">>>")
> + self.send_pks_session.send_command(sendp_fmt)
> +
> def testpmd_reset_status(self, testpmd):
> """
> Reset testpmd :stop forward & stop port
> @@ -175,9 +135,7 @@ class TestVfPortStartStop(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_port_start_stop')
> @@ -242,13 +200,9 @@ class TestVfPortStartStop(TestCase):
>
> def tear_down_all(self):
>
> - self.pktgen_kill()
> - if getattr(self, 'tester_port_driver', None) and \
> - getattr(self, 'tester_tx_pci', None):
> - self.tester.send_expect("./dpdk-devbind.py --bind=%s %s" \
> - %(self.tester_port_driver, self.tester_tx_pci), "#")
> - tx_interface = self.tester.get_interface(self.tester_tx_port)
> - self.tester.send_expect("ifconfig %s up" % tx_interface, "#")
> + if self.send_pks_session:
> + self.tester.send_expect('killall -s INT scapy', '# ')
> + self.tester.destroy_session(self.send_pks_session)
>
> if getattr(self, 'vm0', None):
> self.vm0.stop()
> diff --git a/tests/TestSuite_vf_rss.py b/tests/TestSuite_vf_rss.py
> index 8220926..95d13cd 100644
> --- a/tests/TestSuite_vf_rss.py
> +++ b/tests/TestSuite_vf_rss.py
> @@ -277,8 +277,7 @@ class TestVfRss(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s ' % {'vf0': self.sriov_vfs_port_0[0].pci}
> - self.host_testpmd.start_testpmd("1S/2C/2T", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_rss')
> diff --git a/tests/TestSuite_vf_vlan.py b/tests/TestSuite_vf_vlan.py
> index f50a7e5..7f46aa6 100644
> --- a/tests/TestSuite_vf_vlan.py
> +++ b/tests/TestSuite_vf_vlan.py
> @@ -173,8 +173,8 @@ class TestVfVlan(TestCase):
>
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': self.vf1_mac})
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
> - pkt.send_pkt(tx_port=self.tester_intf1)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf0)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf1)
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
>
> self.verify(len(pkts), "Not receive expected packet")
> @@ -194,7 +194,7 @@ class TestVfVlan(TestCase):
> pkt.config_layer('vlan', {'vlan': vlan})
> pkt.config_layer('ether', {'dst': self.vf0_mac})
>
> - pkt.send_pkt(tx_port=self.tester_intf0)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf0)
> out = self.vm_dut_0.get_session_output(timeout=2)
>
> return out
> @@ -258,7 +258,7 @@ class TestVfVlan(TestCase):
> "ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ")
>
> def tx_and_check(self, tx_vlan=1):
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf0)
> self.vm0_testpmd.execute_cmd('set burst 1')
> self.vm0_testpmd.execute_cmd('start tx_first')
> self.vm0_testpmd.execute_cmd('stop')
> @@ -266,8 +266,8 @@ class TestVfVlan(TestCase):
> # strip sniffered vlans
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> vlans = []
> - for pkt in pkts:
> - vlan = pkt.strip_element_vlan("vlan")
> + for i in range(len(pkts)):
> + vlan = pkts.strip_element_vlan("vlan", p_index=i)
> vlans.append(vlan)
>
> self.verify(
> diff --git a/tests/TestSuite_vhost_enqueue_interrupt.py
> b/tests/TestSuite_vhost_enqueue_interrupt.py
> index 428cf36..5c4c1df 100644
> --- a/tests/TestSuite_vhost_enqueue_interrupt.py
> +++ b/tests/TestSuite_vhost_enqueue_interrupt.py
> @@ -192,6 +192,7 @@ class TestVhostEnqueueInterrupt(TestCase):
> self.close_testpmd_and_session()
> self.dut.send_expect("killall -s INT l3fwd-power", "#")
> self.dut.send_expect("killall -s INT testpmd", "#")
> + self.dut.kill_all()
>
> def tear_down_all(self):
> """
> diff --git a/tests/TestSuite_vhost_multi_queue_qemu.py
> b/tests/TestSuite_vhost_multi_queue_qemu.py
> index f0dbb90..d31eb57 100644
> --- a/tests/TestSuite_vhost_multi_queue_qemu.py
> +++ b/tests/TestSuite_vhost_multi_queue_qemu.py
> @@ -40,7 +40,7 @@ import utils
> from test_case import TestCase
> from settings import HEADER_SIZE
> from virt_common import VM
> -from packet import Packet, send_packets, save_packets
> +from packet import Packet
> from pmd_output import PmdOutput
> from pktgen import PacketGeneratorHelper
>
> @@ -154,8 +154,7 @@ class TestVhostMultiQueueQemu(TestCase):
> pkt1.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4', {'dst':
> '1.1.1.1'}),
> ('raw', {'payload': ['01'] * int('%d' % payload_size)})])
>
> - pkt = [pkt1]
> - save_packets(pkt, "%s/multiqueue.pcap" % self.out_path)
> + pkt1.save_pcapfile(self.tester, "%s/multiqueue.pcap" % self.out_path)
>
> port = self.tester.get_local_port(self.pf)
> tgenInput.append((port, port, "%s/multiqueue.pcap" % self.out_path))
> @@ -185,7 +184,7 @@ class TestVhostMultiQueueQemu(TestCase):
> self.logger.info(info)
> self.dut.send_expect("clear port stats all", "testpmd> ", 120)
> payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] -
> HEADER_SIZE['udp']
> -
> + pkts = Packet()
> pkt1 = Packet()
> pkt1.assign_layers(['ether', 'ipv4', 'udp', 'raw'])
> pkt1.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4', {'dst':
> '1.1.1.1'}),
> @@ -203,11 +202,13 @@ class TestVhostMultiQueueQemu(TestCase):
> pkt4.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4', {'dst':
> '1.1.1.8'}),
> ('udp', {'src': 4789, 'dst': 4789}), ('raw', {'payload': ['01'] * int('%d' %
> payload_size)})])
>
> - pkt = [pkt1, pkt2, pkt3, pkt4] * 10
> - send_packets(self.tx_interface, pkt)
> + pkt = [pkt1, pkt2, pkt3, pkt4]
> + for i in pkt:
> + pkts.pktgen.pkts.append(i.pktgen.pkt)
> + pkts.send_pkt(self.tester, tx_port=self.tx_interface, count=10)
>
> out = self.dut.send_expect("show port stats 0", "testpmd> ", 120)
> - print out
> + print(out)
> rx_packet = re.search("RX-packets:\s*(\d*)", out)
> rx_num = int(rx_packet.group(1))
> tx_packet = re.search("TX-packets:\s*(\d*)", out)
> diff --git a/tests/TestSuite_vhost_pmd_xstats.py
> b/tests/TestSuite_vhost_pmd_xstats.py
> index a58c107..1e1a323 100755
> --- a/tests/TestSuite_vhost_pmd_xstats.py
> +++ b/tests/TestSuite_vhost_pmd_xstats.py
> @@ -126,7 +126,7 @@ class TestVhostPmdXstats(TestCase):
> self.scapy_num += 1
> pkt = Packet(pkt_type='TCP', pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': dmac, })
> - pkt.send_pkt(tx_port=self.txItf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.txItf, count=num)
>
> def send_verify(self, scope, mun):
> """
> diff --git a/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> b/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> index d31122b..0eeb42e 100644
> --- a/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> +++ b/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> @@ -38,7 +38,7 @@ import utils
> import time
> from virt_common import VM
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -234,7 +234,7 @@ class TestVhostVirtioPmdInterrupt(TestCase):
> else:
> pkt = Packet(pkt_type='IP_RAW')
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/interrupt.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/interrupt.pcap" % self.out_path)
> tgen_input.append((self.tx_port, self.tx_port, "%s/interrupt.pcap" %
> self.out_path))
> self.tester.pktgen.clear_streams()
> vm_config = self.set_fields()
> diff --git a/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> b/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> index d89a93d..6f6aa19 100644
> --- a/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> +++ b/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> @@ -247,7 +247,7 @@ class VirtioCryptodevIpsecTest(TestCase):
> def send_and_dump_pkg(self):
> status = True
>
> - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=25)
> + inst = self.tester.tcpdump_sniff_packets(self.rx_interface)
>
> PACKET_COUNT = 65
> payload = 256 * ['11']
> @@ -261,21 +261,19 @@ class VirtioCryptodevIpsecTest(TestCase):
> pkt.config_layer("ipv4", {"src": src_ip, "dst": dst_ip})
> pkt.config_layer("udp", {"dst": 0})
> pkt.config_layer("raw", {"payload": payload})
> - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
> + pkt.send_pkt(self.tester, tx_port=self.tx_interface, count=PACKET_COUNT)
>
> pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
> self.logger.info("dump: {} packets".format(len(pkt_rec)))
> if len(pkt_rec) != PACKET_COUNT:
> self.logger.info("dump pkg: {}, the num of pkg dumped is
> incorrtct!".format(len(pkt_rec)))
> status = False
> -
> - for pkt_r in pkt_rec:
> - #pkt_r.pktgen.pkt.show()
> - if src_ip != pkt_r.pktgen.strip_layer3("src") or dst_ip !=
> pkt_r.pktgen.strip_layer3("dst"):
> + for i in range(len(pkt_rec)):
> + if src_ip != pkt_rec.pktgen.strip_layer3("src", p_index=i) or dst_ip !=
> pkt_rec.pktgen.strip_layer3("dst", p_index=i):
> self.logger.info("the ip of pkg dumped is incorrtct!")
> status = False
>
> - dump_text = binascii.b2a_hex(pkt_r.pktgen.pkt["Raw"].getfieldval("load"))
> + dump_text = binascii.b2a_hex(pkt_rec[i]["Raw"].getfieldval("load"))
> if dump_text != ''.join(payload):
> self.logger.info("the text of pkg dumped is incorrtct!")
> status = False
> diff --git a/tests/TestSuite_vlan.py b/tests/TestSuite_vlan.py
> index 9c58b0c..77c33d0 100644
> --- a/tests/TestSuite_vlan.py
> +++ b/tests/TestSuite_vlan.py
> @@ -86,8 +86,8 @@ class TestVlan(TestCase):
> def get_tcpdump_package(self):
> pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
> vlans = []
> - for packet in pkts:
> - vlan = packet.strip_element_vlan("vlan")
> + for i in range(len(pkts)):
> + vlan = pkts.strip_element_vlan("vlan", p_index=i)
> vlans.append(vlan)
> return vlans
>
> @@ -116,7 +116,7 @@ class TestVlan(TestCase):
> pkt.config_layer('ether', {'dst': self.dmac, 'src': self.smac})
> pkt.config_layer('vlan', {'vlan': vid})
>
> - pkt.send_pkt(tx_port=self.txItf, count=4)
> + pkt.send_pkt(self.tester, tx_port=self.txItf, count=4)
>
> def set_up(self):
> """
> diff --git a/tests/TestSuite_vm2vm_virtio_pmd.py
> b/tests/TestSuite_vm2vm_virtio_pmd.py
> index 2db020f..da8f939 100644
> --- a/tests/TestSuite_vm2vm_virtio_pmd.py
> +++ b/tests/TestSuite_vm2vm_virtio_pmd.py
> @@ -42,7 +42,7 @@ import time
> import utils
> from virt_common import VM
> from test_case import TestCase
> -from packet import load_pcapfile
> +from packet import Packet
>
>
> class TestVM2VMVirtioPMD(TestCase):
> @@ -211,11 +211,12 @@ class TestVM2VMVirtioPMD(TestCase):
> vm_dut.send_expect('quit', '#', 60)
> time.sleep(2)
> vm_dut.session.copy_file_from(src="%s" % self.dump_pcap, dst="%s" %
> self.dump_pcap)
> - pkts = load_pcapfile(self.dump_pcap)
> + pkt = Packet()
> + pkts = pkt.read_pcapfile(self.dump_pcap)
> self.verify(len(pkts) == 10, "The vm0 do not capture all the packets")
> - data = str(pkts[0].pktgen.pkt['Raw'])
> + data = str(pkts[0]['Raw'])
> for i in range(1, 10):
> - value = str(pkts[i].pktgen.pkt['Raw'])
> + value = str(pkts[i]['Raw'])
> self.verify(data == value, "the payload in receive packets has been changed")
>
> def stop_all_apps(self):
> diff --git a/tests/TestSuite_vxlan.py b/tests/TestSuite_vxlan.py
> index 2be5741..2046abe 100644
> --- a/tests/TestSuite_vxlan.py
> +++ b/tests/TestSuite_vxlan.py
> @@ -26,6 +26,7 @@ from scapy.route import *
> from test_case import TestCase
> from settings import HEADER_SIZE, FOLDERS
> from etgen import IxiaPacketGenerator
> +import packet
>
> #
> #
> @@ -48,6 +49,7 @@ class VxlanTestConfig(object):
> self.init()
> for name in kwargs:
> setattr(self, name, kwargs[name])
> + self.pkt_obj = packet.Packet()
>
> def init(self):
> self.packets_config()
> @@ -56,8 +58,8 @@ class VxlanTestConfig(object):
> """
> Default vxlan packet format
> """
> - self.pcap_file = '/root/vxlan.pcap'
> - self.capture_file = '/root/vxlan_capture.pcap'
> + self.pcap_file = packet.TMP_PATH + 'vxlan.pcap'
> + self.capture_file = packet.TMP_PATH + 'vxlan_capture.pcap'
> self.outer_mac_src = '00:00:10:00:00:00'
> self.outer_mac_dst = '11:22:33:44:55:66'
> self.outer_vlan = 'N/A'
> @@ -186,29 +188,28 @@ class VxlanTestConfig(object):
>
> return self.pkt
>
> - def get_chksums(self, pcap=None):
> + def get_chksums(self, pkt=None):
> """
> get chksum values of Outer and Inner packet L3&L4
> Skip outer udp for it will be calculated by software
> """
> chk_sums = {}
> - if pcap is None:
> - pkts = rdpcap(self.pcap_file)
> + if pkt is None:
> + pkt = rdpcap(self.pcap_file)
> else:
> - pkts = rdpcap(pcap)
> + pkt = pkt.pktgen.pkt
>
> time.sleep(1)
> -
> - if pkts[0].guess_payload_class(pkts[0]).name == "802.1Q":
> - payload = pkts[0][Dot1Q]
> + if pkt[0].guess_payload_class(pkt[0]).name == "802.1Q":
> + payload = pkt[0][Dot1Q]
> else:
> - payload = pkts[0]
> + payload = pkt[0]
>
> if payload.guess_payload_class(payload).name == "IP":
> chk_sums['outer_ip'] = hex(payload[IP].chksum)
>
> - if pkts[0].haslayer('VXLAN') == 1:
> - inner = pkts[0]['VXLAN']
> + if pkt[0].haslayer('VXLAN') == 1:
> + inner = pkt[0]['VXLAN']
> if inner.haslayer(IP) == 1:
> chk_sums['inner_ip'] = hex(inner[IP].chksum)
> if inner[IP].proto == 6:
> @@ -236,16 +237,10 @@ class VxlanTestConfig(object):
> """
> Send vxlan pcap file by iface
> """
> - # load vxlan module to scapy
> - cwd = os.getcwd()
> - dir_vxlan_module = cwd + r'/' + FOLDERS['Depends']
> - self.test_case.tester.scapy_append("sys.path.append('%s')" % dir_vxlan_module)
> - self.test_case.tester.scapy_append("from vxlan import VXLAN")
> - self.test_case.tester.scapy_append(
> - 'pcap = rdpcap("%s")' % self.pcap_file)
> - self.test_case.tester.scapy_append(
> - 'sendp(pcap, iface="%s")' % iface)
> - self.test_case.tester.scapy_execute()
> + del self.pkt_obj.pktgen.pkts[:]
> + self.pkt_obj.pktgen.assign_pkt(self.pkt)
> + self.pkt_obj.pktgen.update_pkts()
> + self.pkt_obj.send_pkt(crb=self.test_case.tester, tx_port=iface)
>
> def pcap_len(self):
> """
> @@ -262,12 +257,10 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> vxlan Prerequisites
> """
> # this feature only enable in FVL now
> - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortville_25g", "fortpark_TLV", "carlsville"]:
> + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortville_25g", "fortpark_TLV"]:
> self.compile_switch = 'CONFIG_RTE_LIBRTE_I40E_INC_VECTOR'
> elif self.nic in ["sageville", "sagepond"]:
> self.compile_switch = 'CONFIG_RTE_IXGBE_INC_VECTOR'
> - elif self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> else:
> self.verify(False, "%s not support this vxlan" % self.nic)
> # Based on h/w type, choose how many ports to use
> @@ -448,20 +441,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> config.outer_mac_dst = self.dut_port_mac
> config.create_pcap()
>
> - # remove tempory files
> - config.capture_file = "/tmp/sniff_%s.pcap" % self.recv_iface
> - self.tester.send_expect("rm -rf %s" % config.capture_file, "# ")
> # save the capture packet into pcap format
> - self.tester.scapy_background()
> -
> - inst = self.tester.tcpdump_sniff_packets(self.recv_iface, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(self.recv_iface)
> config.send_pcap(self.tester_iface)
> - self.tester.load_tcpdump_sniff_packets(inst)
> + pkt = self.tester.load_tcpdump_sniff_packets(inst)
> time.sleep(5)
>
> # extract the checksum offload from saved pcap file
> - chksums = config.get_chksums(pcap=config.capture_file)
> - os.remove(config.capture_file)
> + chksums = config.get_chksums(pkt=pkt)
> self.logger.info("chksums" + str(chksums))
>
> out = self.dut.send_expect("stop", "testpmd>", 10)
> @@ -535,19 +522,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> """
> verify vxlan packet detection
> """
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - src_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model == 'y':
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=n/' config/common_base" % self.compile_switch, "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + src_vec_model = re.search("%s=." % self.compile_switch, out).group()[-1]
> + if src_vec_model == 'y':
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=n/' config/common_base" % self.compile_switch, "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> -
> pmd_temp = "./%(TARGET)s/app/testpmd -c %(COREMASK)s -n " + \
> "%(CHANNEL)d -- -i --disable-rss --rxq=4 --txq=4" + \
> " --nb-cores=4 --portmask=%(PORT)s"
> @@ -561,8 +543,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("set verbose 1", "testpmd>", 10)
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
>
> # check normal packet
> self.send_and_detect(outer_udp_dst=1234)
> @@ -579,33 +559,26 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
>
> out = self.dut.send_expect("stop", "testpmd>", 10)
> self.dut.send_expect("quit", "#", 10)
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model != dst_vec_model:
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> +
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> + if src_vec_model != dst_vec_model:
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> def test_vxlan_ipv6_detect(self):
> """
> verify vxlan packet detection with ipv6 header
> """
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - src_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model == 'y':
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=n/' config/common_base" % self.compile_switch, "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + src_vec_model = re.search("%s=." % self.compile_switch, out).group()[-1]
> + if src_vec_model == 'y':
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=n/' config/common_base" % self.compile_switch, "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> pmd_temp = "./%(TARGET)s/app/testpmd -c %(COREMASK)s -n " + \
> "%(CHANNEL)d -- -i --disable-rss --rxq=4 --txq=4" + \
> @@ -620,8 +593,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("set verbose 1", "testpmd>", 10)
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
>
> # check normal ipv6 packet
> self.send_and_detect(outer_ip6_src="FE80:0:0:0:0:0:0:0",
> @@ -642,17 +613,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
>
> out = self.dut.send_expect("stop", "testpmd>", 10)
> self.dut.send_expect("quit", "#", 10)
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model != dst_vec_model:
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> +
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> + if src_vec_model != dst_vec_model:
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> def test_vxlan_ipv4_checksum_offload(self):
> """
> @@ -682,9 +650,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("port start all", "testpmd>")
> self.dut.send_expect("csum parse-tunnel on %d" %
> self.recv_port, "testpmd>", 10)
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
> -
>
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> @@ -759,7 +724,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
>
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> - time.sleep(10) #lwj
>
> # check normal ipv6 packet
> self.send_and_check(outer_ip6_src="FE80:0:0:0:0:0:0:0",
> @@ -1169,8 +1133,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("port start all", "testpmd>")
> self.verify("Bad arguments" not in out, "Failed to set vxlan csum")
> self.verify("error" not in out, "Failed to set vxlan csum")
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
>
> def csum_set_sw(self, proto, port):
> self.dut.send_expect("port stop all", "testpmd>")
> @@ -1179,9 +1141,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("port start all", "testpmd>")
> self.verify("Bad arguments" not in out, "Failed to set vxlan csum")
> self.verify("error" not in out, "Failed to set vxlan csum")
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
> -
>
> def tunnel_filter_add(self, *args):
> # tunnel_filter add port_id outer_mac inner_mac ip inner_vlan
> diff --git a/tests/TestSuite_vxlan_sample.py b/tests/TestSuite_vxlan_sample.py
> index 5bc9269..df7bbcf 100644
> --- a/tests/TestSuite_vxlan_sample.py
> +++ b/tests/TestSuite_vxlan_sample.py
> @@ -48,7 +48,7 @@ from etgen import IxiaPacketGenerator
> from qemu_kvm import QEMUKvm
> from TestSuite_vxlan import VxlanTestConfig
> from pmd_output import PmdOutput
> -from packet import IncreaseIP, IncreaseIPv6
> +from packet import Packet
>
> from scapy.utils import wrpcap, rdpcap
> from scapy.layers.inet import Ether, IP, TCP, UDP
> @@ -106,7 +106,6 @@ class TestVxlanSample(TestCase):
>
> # params for tep_termination
> self.cores = self.dut.get_core_list("1S/4C/1T", socket=self.socket)
> - self.capture_file = "/tmp/vxlan_cap.pcap"
> self.def_mss = 256
>
> # performance measurement, checksum based on encap
> @@ -266,32 +265,18 @@ class TestVxlanSample(TestCase):
> self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_tcp_tso")
>
> def start_capture(self, itf, pkt_smac="", pkt_dmac="", count=1):
> - self.tester.send_expect("rm -f %s" % self.capture_file, "# ")
> - self.tester.scapy_background()
> + self.inst = None
> + filter_param = []
> if pkt_smac != "":
> - self.tester.scapy_append(
> - 'p = sniff(filter="ether src %s",' % pkt_smac +
> - 'iface="%s", count=%d, timeout=5)' % (itf, count))
> - if pkt_dmac != "":
> - self.tester.scapy_append(
> - 'p = sniff(filter="ether dst %s",' % pkt_dmac +
> - 'iface="%s", count=%d, timeout=5)' % (itf, count))
> - self.tester.scapy_append(
> - 'wrpcap(\"%s\", p)' % self.capture_file)
> - self.tester.scapy_foreground()
> + filter_param = [{'layer': 'ether', 'config': {'src': '%s' % pkt_smac}}]
> + if pkt_dmac != "":
> + filter_param = [{'layer': 'ether', 'config': {'dst': '%s' % pkt_dmac}}]
> + self.inst = self.tester.tcpdump_sniff_packets(itf, count, filters=filter_param)
>
> def transfer_capture_file(self):
> # copy capture file from tester
> - if os.path.isfile('vxlan_cap.pcap'):
> - os.remove('vxlan_cap.pcap')
> - self.tester.session.copy_file_from(self.capture_file)
> -
> - if os.path.isfile('vxlan_cap.pcap'):
> - self.verify(os.path.getsize('vxlan_cap.pcap') != 0, "Packets receive error")
> - pkts = rdpcap('vxlan_cap.pcap')
> - else:
> - pkts = []
> - return pkts
> + pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
> + return pkts.pktgen.pkts
>
> def send_and_verify(self, vm_id, vf_id, pkt_type):
> params = {}
> @@ -430,7 +415,10 @@ class TestVxlanSample(TestCase):
> self.verify(len(pkts) >= 1, "Failed to capture packets")
> self.verify(pkts[0].haslayer('VXLAN') == 1,
> "Packet not encapsulated")
> - chksums = vxlan_pkt.get_chksums(pcap='vxlan_cap.pcap')
> + pk_new = Packet()
> + pk_new.pktgen.assign_pkt(pkts)
> + pk_new.pktgen.update_pkts()
> + chksums = vxlan_pkt.get_chksums(pk_new)
> print utils.GREEN("Checksum : %s" % chksums)
> for key in chksums_ref:
> if 'inner' in key: # only check inner packet chksum
> --
> 2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [dts] [PATCH V1] tests/: update cases related to new framework
2019-09-27 18:05 [dts] [PATCH V1] tests/: update cases related to new framework Qimai Xiao
` (2 preceding siblings ...)
2019-10-08 2:22 ` [dts] [PATCH V1] tests/: update cases related to new framework Chen, Zhaoyan
@ 2019-10-12 5:30 ` Tu, Lijuan
3 siblings, 0 replies; 9+ messages in thread
From: Tu, Lijuan @ 2019-10-12 5:30 UTC (permalink / raw)
To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX
Applied, thanks
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Qimai Xiao
> Sent: Saturday, September 28, 2019 2:06 AM
> To: dts@dpdk.org
> Cc: Xiao, QimaiX <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] tests/: update cases related to new framework
>
> update testsuits related to new framework api
>
> Signed-off-by: Qimai Xiao <qimaix.xiao@intel.com>
> ---
> tests/TestSuite_checksum_offload.py | 35 +-
> tests/TestSuite_cloud_filter.py | 13 +-
> tests/TestSuite_ddp_mpls.py | 3 +-
> tests/TestSuite_dynamic_queue.py | 12 +-
> tests/TestSuite_etag.py | 2 +-
> tests/TestSuite_eventdev_pipeline.py | 14 +-
> tests/TestSuite_floating_veb.py | 4 +-
> tests/TestSuite_flow_classify_softnic.py | 2 +-
> tests/TestSuite_generic_flow_api.py | 528 ++++++++++--------
> tests/TestSuite_hotplug.py | 2 +-
> tests/TestSuite_iavf.py | 2 +-
> tests/TestSuite_ieee1588.py | 9 +-
> tests/TestSuite_ipfrag.py | 30 +-
> tests/TestSuite_ipgre.py | 80 +--
> tests/TestSuite_ipsec_gw_cryptodev_func.py | 29 +-
> tests/TestSuite_jumboframes.py | 2 +-
> tests/TestSuite_kernelpf_iavf.py | 4 +-
> tests/TestSuite_l2fwd_cryptodev_func.py | 11 +-
> tests/TestSuite_l3fwdacl.py | 39 +-
> tests/TestSuite_link_flowctrl.py | 1 +
> tests/TestSuite_link_status_interrupt.py | 2 +-
> tests/TestSuite_loadbalancer.py | 14 +-
> tests/TestSuite_mac_filter.py | 2 +-
> tests/TestSuite_netmap_compat.py | 6 +-
> tests/TestSuite_packet_capture.py | 222 +++-----
> tests/TestSuite_ptype_mapping.py | 2 +-
> .../TestSuite_pvp_multi_paths_performance.py | 4 +-
> ...lti_paths_vhost_single_core_performance.py | 4 +-
> ...ti_paths_virtio_single_core_performance.py | 4 +-
> ...Suite_pvp_qemu_multi_paths_port_restart.py | 13 +-
> tests/TestSuite_pvp_vhost_user_reconnect.py | 13 +-
> tests/TestSuite_pvp_virtio_bonding.py | 9 +-
> tests/TestSuite_pvp_virtio_user_4k_pages.py | 5 +-
> tests/TestSuite_queue_region.py | 4 +-
> tests/TestSuite_queue_start_stop.py | 4 +-
> tests/TestSuite_quota_watermark.py | 2 +-
> tests/TestSuite_runtime_vf_queue_number.py | 13 +-
> ...estSuite_runtime_vf_queue_number_kernel.py | 23 +-
> tests/TestSuite_rxtx_callbacks.py | 4 +-
> tests/TestSuite_scatter.py | 4 +-
> tests/TestSuite_short_live.py | 4 +-
> tests/TestSuite_skeleton.py | 4 +-
> tests/TestSuite_sriov_kvm.py | 11 +-
> tests/TestSuite_uni_pkt.py | 9 +-
> tests/TestSuite_userspace_ethtool.py | 34 +-
> tests/TestSuite_veb_switch.py | 4 +-
> tests/TestSuite_vf_daemon.py | 21 +-
> tests/TestSuite_vf_interrupt_pmd.py | 2 +-
> tests/TestSuite_vf_jumboframe.py | 2 +-
> tests/TestSuite_vf_kernel.py | 13 +-
> tests/TestSuite_vf_macfilter.py | 9 +-
> tests/TestSuite_vf_offload.py | 4 +-
> tests/TestSuite_vf_packet_rxtx.py | 19 +-
> tests/TestSuite_vf_port_start_stop.py | 86 +--
> tests/TestSuite_vf_rss.py | 3 +-
> tests/TestSuite_vf_vlan.py | 12 +-
> tests/TestSuite_vhost_enqueue_interrupt.py | 1 +
> tests/TestSuite_vhost_multi_queue_qemu.py | 15 +-
> tests/TestSuite_vhost_pmd_xstats.py | 2 +-
> tests/TestSuite_vhost_virtio_pmd_interrupt.py | 4 +-
> .../TestSuite_virtio_ipsec_cryptodev_func.py | 12 +-
> tests/TestSuite_vlan.py | 6 +-
> tests/TestSuite_vm2vm_virtio_pmd.py | 9 +-
> tests/TestSuite_vxlan.py | 143 ++---
> tests/TestSuite_vxlan_sample.py | 38 +-
> 65 files changed, 759 insertions(+), 884 deletions(-)
>
> diff --git a/tests/TestSuite_checksum_offload.py
> b/tests/TestSuite_checksum_offload.py
> index 7176cb9..c890671 100644
> --- a/tests/TestSuite_checksum_offload.py
> +++ b/tests/TestSuite_checksum_offload.py
> @@ -46,6 +46,7 @@ from test_case import TestCase
> from pmd_output import PmdOutput
> from test_capabilities import DRIVER_TEST_LACK_CAPA
> from pktgen import PacketGeneratorHelper
> +import packet
>
>
> class TestChecksumOffload(TestCase):
> @@ -110,7 +111,7 @@ class TestChecksumOffload(TestCase):
>
> for packet_type in packets_expected.keys():
> self.tester.send_expect("p = %s" % packets_expected[packet_type],
> ">>>")
> - out = self.tester.send_expect("p.show2()", ">>>")
> + out = self.tester.send_command("p.show2()", timeout=1)
> chksums = checksum_pattern.findall(out)
> chksum[packet_type] = chksums
>
> @@ -122,15 +123,11 @@ class TestChecksumOffload(TestCase):
> """
> Sends packets and check the checksum valid-flags.
> """
> - self.tester.scapy_foreground()
> self.dut.send_expect("start", "testpmd>")
> - mac = self.dut.get_mac_address(self.dut_ports[0])
> tx_interface =
> self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
> - self.tester.scapy_foreground()
> -
> for packet_type in packets_sent.keys():
> - self.tester.scapy_append('sendp([%s], iface="%s", count=4)' %
> (packets_sent[packet_type], tx_interface))
> - self.tester.scapy_execute()
> + self.pkt = packet.Packet(pkt_str=packets_sent[packet_type])
> + self.pkt.send_pkt(self.tester, tx_interface, count=4)
> out = self.dut.get_session_output(timeout=1)
> lines = out.split("\r\n")
>
> @@ -173,33 +170,21 @@ class TestChecksumOffload(TestCase):
> rx_interface =
> self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
>
> sniff_src = self.dut.get_mac_address(self.dut_ports[0])
> - checksum_pattern = re.compile("chksum.*=.*(0x[0-9a-z]+)")
> -
> - chksum = dict()
> result = dict()
>
> - self.tester.send_expect("scapy", ">>> ")
> -
> - for packet_type in packets_expected.keys():
> - self.tester.send_expect("p = %s" % packets_expected[packet_type],
> ">>>")
> - out = self.tester.send_expect("p.show2()", ">>>")
> - chksums = checksum_pattern.findall(out)
> - chksum[packet_type] = chksums
> -
> - self.tester.send_expect("exit()", "#")
> + chksum = self.get_chksum_values(packets_expected)
>
> inst = self.tester.tcpdump_sniff_packets(intf=rx_interface,
> count=len(packets_sent)*4,
> filters=[{'layer': 'ether', 'config': {'src': sniff_src}}])
>
> + self.pkt = packet.Packet()
> for packet_type in packets_sent.keys():
> - self.tester.scapy_append('sendp([%s], iface="%s", count=4)' %
> (packets_sent[packet_type], tx_interface))
> + self.pkt.append_pkt(packets_sent[packet_type])
> + self.pkt.send_pkt(crb=self.tester, tx_port=tx_interface, count=4)
>
> - self.tester.scapy_execute()
> p = self.tester.load_tcpdump_sniff_packets(inst)
> nr_packets = len(p)
> - reslist =
> [p[i].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCT
> P.chksum%") for i in range(nr_packets)]
> - out = string.join(reslist, ",")
> - packets_received = out.split(',')
> + packets_received =
> [p[i].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%
> ") for i in range(nr_packets)]
> self.verify(len(packets_sent)*4 == len(packets_received), "Unexpected
> Packets Drop")
>
> for packet_received in packets_received:
> @@ -272,8 +257,6 @@ class TestChecksumOffload(TestCase):
> 'IPv6/UDP': 'Ether(dst="%s",
> src="52:00:00:00:00:00")/IPv6(src="::1")/UDP()/("X"*46)' % mac,
> 'IPv6/TCP': 'Ether(dst="%s",
> src="52:00:00:00:00:00")/IPv6(src="::1")/TCP()/("X"*46)' % mac}
>
> - result = dict()
> -
> self.checksum_enablehw(self.dut_ports[0])
>
> # get the packet checksum value
> diff --git a/tests/TestSuite_cloud_filter.py b/tests/TestSuite_cloud_filter.py
> index 74b3be7..51647ef 100644
> --- a/tests/TestSuite_cloud_filter.py
> +++ b/tests/TestSuite_cloud_filter.py
> @@ -12,7 +12,7 @@ import os
> from test_case import TestCase
> from pmd_output import PmdOutput
> from settings import HEADER_SIZE
> -from packet import Packet, load_pcapfile
> +from packet import Packet
>
> from scapy.layers.inet import UDP, IP
> from scapy.packet import split_layers, bind_layers
> @@ -195,7 +195,7 @@ class CloudFilterConfig(object):
>
> self.pkt.config_layer('ether', ether_cfg)
> self.pkt.config_layer('raw', {'payload': ['01'] * 18})
> - self.pkt.send_pkt(tx_port=self.case.tester_intf)
> + self.pkt.send_pkt(crb=self.case.tester, tx_port=self.case.tester_intf)
>
>
> class TestCloudFilter(TestCase):
> @@ -311,7 +311,6 @@ class TestCloudFilter(TestCase):
> if dpdk:
> cloud_cfg.transmit_packet()
> out = self.pmdout.get_output()
> - print out
> queue = cloud_cfg.cf_rule['queue']
> self.verify("queue %d" %
> queue in out, "Vxlan not received in queue %d" % queue)
> @@ -341,11 +340,11 @@ class TestCloudFilter(TestCase):
> time.sleep(2)
> # copy pcap to tester and then analyze
> self.dut.session.copy_file_from(tmp_file)
> - pkts = load_pcapfile(
> - filename="cloud_filter_%s.pcap" % self.vf_intf)
> + pkt = Packet()
> + pkt.read_pcapfile(filename="cloud_filter_%s.pcap" % self.vf_intf)
> self.verify(
> - len(pkts) == 1, "%d packet recevied on kernel VF" % len(pkts))
> - cap_pkt = pkts[0].pktgen.pkt
> + len(pkt) == 1, "%d packet recevied on kernel VF" % len(pkt))
> + cap_pkt = pkt[0]
> try:
> dport = cap_pkt[UDP].dport
> self.verify(dport == CLOUD_PORT,
> diff --git a/tests/TestSuite_ddp_mpls.py b/tests/TestSuite_ddp_mpls.py
> index 547e1c9..599e5cd 100644
> --- a/tests/TestSuite_ddp_mpls.py
> +++ b/tests/TestSuite_ddp_mpls.py
> @@ -95,11 +95,10 @@ class Testddp_mpls(TestCase):
> self.vm0_dut_ports = self.vm0_dut.get_ports('any')
> self.vm0_testpmd = PmdOutput(self.vm0_dut)
> self.env_done = True
> - eal_param = '-b %(vf0)s' % {'vf0': self.sriov_vfs_port[0].pci}
>
> self.dut_testpmd.start_testpmd(
> "Default","--port-topology=chained --txq=%s --rxq=%s"
> - % (PF_MAX_QUEUE, PF_MAX_QUEUE), eal_param=eal_param)
> + % (PF_MAX_QUEUE, PF_MAX_QUEUE))
> self.vm0_testpmd.start_testpmd(
> VM_CORES_MASK,"--port-topology=chained --txq=%s --rxq=%s"
> % (VF_MAX_QUEUE, VF_MAX_QUEUE))
> diff --git a/tests/TestSuite_dynamic_queue.py
> b/tests/TestSuite_dynamic_queue.py
> index dd05eab..1f86d1f 100644
> --- a/tests/TestSuite_dynamic_queue.py
> +++ b/tests/TestSuite_dynamic_queue.py
> @@ -63,14 +63,10 @@ class TestDynamicQueue(TestCase):
> Generate packets and send them to dut
> """
> mac = self.dut.get_mac_address(0)
> - for i in range(self.PF_QUEUE * 4):
> - j = i /256
> - k = i % 256
> - pkt = Packet(pkt_type='IP_RAW')
> - pkt.config_layer('ether', {'dst': mac})
> - pkt.config_layer(
> - 'ipv4', {'dst': '192.168.%d.%d' % (j, k), 'src': '191.168.0.1'})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pktnum = self.PF_QUEUE * 4
> + pkt = Packet()
> + pkt.generate_random_pkts(mac, pktnum=pktnum,
> random_type=['IP_RAW'])
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> def rxq_setup_test(self, chgflag=0):
> """
> diff --git a/tests/TestSuite_etag.py b/tests/TestSuite_etag.py
> index 45c5163..8a67222 100644
> --- a/tests/TestSuite_etag.py
> +++ b/tests/TestSuite_etag.py
> @@ -160,7 +160,7 @@ class TestEtag(TestCase):
> if pkt_configs:
> for layer in pkt_configs.keys():
> pkt.config_layer(layer, pkt_configs[layer])
> - pkt.send_pkt(tx_port=self.src_intf)
> + pkt.send_pkt(self.tester, tx_port=self.src_intf)
>
> # check vm testpmd packet received information
> if 'vm' in pkt_types[pkt_type].keys():
> diff --git a/tests/TestSuite_eventdev_pipeline.py
> b/tests/TestSuite_eventdev_pipeline.py
> index cee636a..9f723cd 100644
> --- a/tests/TestSuite_eventdev_pipeline.py
> +++ b/tests/TestSuite_eventdev_pipeline.py
> @@ -113,8 +113,8 @@ class TestEventdevPipeline(TestCase):
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> i = 0
> while len(pkts) != 0 and i <= len(pkts) - 1:
> - if pkts[i].pktgen.pkt.haslayer('DHCP'):
> - pkts.remove(pkts[i])
> + if pkts[i].haslayer('DHCP'):
> + pkts.pktgen.pkts.pop(i)
> i = i - 1
> i = i + 1
> return pkts
> @@ -152,7 +152,7 @@ class TestEventdevPipeline(TestCase):
> time.sleep(5)
>
> filt = [{'layer': 'ether', 'config': {'src': '%s' % self.s_mac}}]
> - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=15,
> filters=filt)
> + inst = self.tester.tcpdump_sniff_packets(self.rx_interface, filters=filt)
> self.tester.scapy_append('pkt=rdpcap("pipeline.pcap")')
> self.tester.scapy_append('sendp(pkt, iface="%s")' % self.tx_interface)
> self.tester.scapy_execute()
> @@ -169,13 +169,13 @@ class TestEventdevPipeline(TestCase):
> packet_index = 0
> for i in range(len(self.pkts)):
> pay_load = "0000%.2d" % (packet_index)
> - if self.pkts[i].pktgen.pkt['IP'].src == src_ip:
> - print self.pkts[i].pktgen.pkt.show
> + if self.pkts[i]['IP'].src == src_ip:
> + print(self.pkts[i].show)
> # get the start index load info of each queue
> if packet_index == 0:
> - packet_index = int(self.pkts[i].pktgen.pkt['Raw'].load[-2:])
> + packet_index = int(self.pkts[i]['Raw'].load[-2:])
> pay_load = "0000%.2d" % (packet_index)
> - self.verify(self.pkts[i].pktgen.pkt['Raw'].load == pay_load,
> + self.verify(self.pkts[i]['Raw'].load == pay_load,
> "The packets not ordered")
> packet_index = packet_index + 1
>
> diff --git a/tests/TestSuite_floating_veb.py b/tests/TestSuite_floating_veb.py
> index 40b0ce2..350d8fa 100644
> --- a/tests/TestSuite_floating_veb.py
> +++ b/tests/TestSuite_floating_veb.py
> @@ -120,12 +120,12 @@ class TestFloatingVEBSwitching(TestCase):
> pkt = Packet(pkt_type='VLAN_UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> pkt.config_layer('vlan', {'vlan': 1})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
> else:
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
>
> # Test cases.
> diff --git a/tests/TestSuite_flow_classify_softnic.py
> b/tests/TestSuite_flow_classify_softnic.py
> index 33f701e..a649a44 100644
> --- a/tests/TestSuite_flow_classify_softnic.py
> +++ b/tests/TestSuite_flow_classify_softnic.py
> @@ -72,7 +72,7 @@ class TestFlowClassifySoftnic(TestCase):
> file = 'flow_classify_softnic.tar.gz'
> src_file = r'./dep/%s' % file
> dst1 = '/tmp'
> - dst2 = os.path.join(self.dut.base_dir, 'drivers/net/softnic')
> + dst2 = '/root/dpdk/drivers/net/softnic'
> self.dut.session.copy_file_to(src_file, dst1)
> self.dut.send_expect("tar xf %s/%s -C %s" % (dst1, file, dst2), "#", 30)
>
> diff --git a/tests/TestSuite_generic_flow_api.py
> b/tests/TestSuite_generic_flow_api.py
> index 61af86c..e0a4aa6 100644
> --- a/tests/TestSuite_generic_flow_api.py
> +++ b/tests/TestSuite_generic_flow_api.py
> @@ -49,7 +49,7 @@ from crb import Crb
> from virt_dut import VirtDut
> from project_dpdk import DPDKdut
> from dut import Dut
> -from packet import Packet
> +import packet
>
> import os
> import random
> @@ -99,6 +99,7 @@ class TestGeneric_flow_api(TestCase):
> self.inner_mac = "00:11:22:33:44:66"
> self.wrong_mac = "00:11:22:33:44:77"
> self.vf_flag = 0
> + self.pkt_obj = packet.Packet()
>
> def set_up(self):
> """
> @@ -162,8 +163,8 @@ class TestGeneric_flow_api(TestCase):
> """
> verify the packet to the expected queue or be dropped
> """
> - self.tester.scapy_execute()
> - time.sleep(2)
> + # self.tester.scapy_execute()
> + # time.sleep(2)
> verify_mac = verify_mac.upper()
>
> if self.vf_flag == 1:
> @@ -207,7 +208,7 @@ class TestGeneric_flow_api(TestCase):
> queue_index = 0
> find_index = False
> for i in range(len(m)):
> - cur = out_info.find(m[i], all_queue_index[i-1] + len(m[i-1]) if i > 0
> else 0)
> + cur = out_info.find(m[i], all_queue_index[i - 1] + len(m[i - 1]) if i > 0
> else 0)
> if cur > mac_index:
> queue_index = i - 1
> find_index = True
> @@ -255,8 +256,8 @@ class TestGeneric_flow_api(TestCase):
> # caculate the rule number created.
> rule_created = self.flow_test_process(flow_process, flow_action)
> if rule_created:
> - rule_num += 1
> - extra_packet.append(flow_process['extrapacket'])
> + rule_num += 1
> + extra_packet.append(flow_process['extrapacket'])
> # Configure a return value.
> extrapkt_rulenum = {'extrapacket': extra_packet, 'rulenum': rule_num,
> 'queue': expected_queue}
>
> @@ -286,26 +287,34 @@ class TestGeneric_flow_api(TestCase):
> if "validate" in flow_cmd:
> # ethertype invalid or queue id exceeds max queue number.
> if "86dd" in flow_cmd or "0800" in flow_cmd or "index %s" %
> str(MAX_QUEUE + 1) in flow_cmd:
> - if self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV", "niantic", "kawela_4", "kawela",
> "bartonhills", "twinville", "sagepond", "sageville", "powerville"]:
> + if self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV",
> + "niantic", "kawela_4", "kawela", "bartonhills", "twinville",
> "sagepond", "sageville",
> + "powerville"]:
> self.dut.send_expect(flow_cmd, "error")
> elif "type is 0x8100" in flow_cmd:
> if self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]:
> self.dut.send_expect(flow_cmd, "error")
> # vf queue id exceeds max vf queue number.
> - elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or
> ("vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and
> (("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd):
> + elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or
> (
> + "vf0" in flow_action['actions']) or ("vf1" in flow_action['actions']))
> and (
> + ("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd):
> self.dut.send_expect(flow_cmd, "error")
> else:
> self.dut.send_expect(flow_cmd, "validated")
> elif "create" in flow_cmd:
> # ethertype invalid or queue id exceeds max queue number.
> if "86dd" in flow_cmd or "0800" in flow_cmd or "index %s" %
> str(MAX_QUEUE + 1) in flow_cmd:
> - if self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV", "niantic", "kawela_4", "kawela",
> "bartonhills", "twinville", "sagepond", "sageville", "powerville"]:
> + if self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV",
> + "niantic", "kawela_4", "kawela", "bartonhills", "twinville",
> "sagepond", "sageville",
> + "powerville"]:
> self.dut.send_expect(flow_cmd, "error")
> elif "type is 0x8100" in flow_cmd:
> if self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]:
> self.dut.send_expect(flow_cmd, "error")
> # vf queue id exceeds max vf queue number.
> - elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or
> ("vf0" in flow_action['actions']) or ("vf1" in flow_action['actions'])) and
> (("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd):
> + elif (("vf0" in flow_action['flows']) or ("vf1" in flow_action['flows']) or
> (
> + "vf0" in flow_action['actions']) or ("vf1" in flow_action['actions']))
> and (
> + ("index %s" % str(MAX_VFQUEUE + 1)) in flow_cmd):
> self.dut.send_expect(flow_cmd, "error")
> else:
> self.dut.send_expect(flow_cmd, "created")
> @@ -318,7 +327,7 @@ class TestGeneric_flow_api(TestCase):
> self.load_module("nvgre")
>
> # The rule is created successfully, so send the consistent packet.
> - self.tester.scapy_append('sendp(%s, iface="%s")' % (flow_pkt,
> self.tester_itf))
> + self.sendpkt(pktstr=flow_pkt)
> cur_mac = re.search("dst='(\S\S:\S\S:\S\S:\S\S:\S\S:\S\S)'",
> flow_pkt)
> cur_mac = cur_mac.group(1)
> if ("queue" in flow_action['actions']) or ("passthru" in
> flow_action['actions']):
> @@ -353,7 +362,7 @@ class TestGeneric_flow_api(TestCase):
> if is_ipv4 == True:
> return '.'.join('%s' % random.randint(0, 255) for i in range(4))
> else:
> - return ':'.join('{:x}'.format(random.randint(0, 2**16 - 1)) for i in
> range(8))
> + return ':'.join('{:x}'.format(random.randint(0, 2 ** 16 - 1)) for i in
> range(8))
>
> def generate_random_int(self, minimum, maximum):
> return random.randint(minimum, maximum)
> @@ -376,7 +385,9 @@ class TestGeneric_flow_api(TestCase):
> cmd_fmt = "flow %(create)s 0 ingress pattern %(flow)s / end
> actions %(action)s end"
> # Record the elements of the rule, ready for the configuration
> # of packets inconsistent to the rule.
> - extrapacket = {'vlan': '', 'etag': '', 'ipv4': '', 'ipv6': '', 'sip': '', 'dip': '', 'proto':
> '', 'tos': '', 'ttl': '', 'tcp': '', 'udp': '', 'sctp': '', 'sport': '', 'dport': '', 'vni': '', 'tni': '',
> 'ineth': '', 'invlan': ''}
> + extrapacket = {'vlan': '', 'etag': '', 'ipv4': '', 'ipv6': '', 'sip': '', 'dip': '',
> 'proto': '', 'tos': '',
> + 'ttl': '', 'tcp': '', 'udp': '', 'sctp': '', 'sport': '', 'dport': '', 'vni': '', 'tni':
> '',
> + 'ineth': '', 'invlan': ''}
> # Define the packet string, which is consistent to the flow rule.
> if ('vf0' in flows) or ('vf1' in flows) or ('vf0' in actions) or ('vf1' in actions):
> pkt = "Ether(dst='%s')" % self.wrong_mac
> @@ -630,14 +641,24 @@ class TestGeneric_flow_api(TestCase):
> elif action == "mark":
> act_str += "mark id 3 / "
> # Configure the whole flow rule.
> - command = cmd_fmt % { "create": create,
> - "flow": flow_str,
> - "action": act_str}
> + command = cmd_fmt % {"create": create,
> + "flow": flow_str,
> + "action": act_str}
> # Configure the return value.
> flow_process = {'cmd': command, 'pkt': pkt, 'queue': index, 'extrapacket':
> extrapacket}
>
> return flow_process
>
> + def sendpkt(self, pktstr, count=1):
> + import sys
> + py_version = sys.version
> + if py_version.startswith('3.'):
> + self.pkt_obj.pktgen.pkts.clear()
> + else:
> + del self.pkt_obj.pktgen.pkts[:]
> + self.pkt_obj.append_pkt(pktstr)
> + self.pkt_obj.send_pkt(self.tester, tx_port=self.tester_itf, count=count)
> +
> def test_syn_filter(self):
> """
> Only supported by ixgbe and igb.
> @@ -653,14 +674,13 @@ class TestGeneric_flow_api(TestCase):
>
> # create the flow rules
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 / tcp flags spec 0x02 flags
> mask 0x02 / end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 / tcp flags spec 0x02 flags
> mask 0x02 / end actions queue index 3 / end",
> + "created")
> # send the packets and verify the results
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="S")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> - self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.pf_mac)
> + self.sendpkt(pktstr='Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="S")/Raw("x" * 20)' % self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="PA")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.pf_mac)
> + self.sendpkt(pktstr='Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(dport=80,flags="PA")/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
>
> # the ipv6 rule is conflicted with ipv4 rule.
> @@ -668,14 +688,13 @@ class TestGeneric_flow_api(TestCase):
>
> # create the flow rules
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv6 / tcp flags spec 0x02 flags
> mask 0x02 / end actions queue index 4 / end", "created")
> + "flow create 0 ingress pattern eth / ipv6 / tcp flags spec 0x02 flags
> mask 0x02 / end actions queue index 4 / end",
> + "created")
> # send the packets and verify the results
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="S")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="S")/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="PA")/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(dport=80,flags="PA")/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
>
> self.verify_rulenum(1)
> @@ -695,21 +714,24 @@ class TestGeneric_flow_api(TestCase):
> # create the flow rules
> basic_flow_actions = [
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'udp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'sctp', 'sport',
> 'dport'], 'actions': ['queue']}
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'udp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'sctp', 'sport',
> 'dport'],
> + 'actions': ['queue']}
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> # send the packets inconsistent to the rules.
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[0]['dip'], extra_packet[0]['sip'],
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s")/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[0]['dip'], extra_packet[0]['sip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[3]['dip'], extra_packet[3]['sip'],
> extra_packet[3]['sport'], extra_packet[3]['dport'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)' % (
> + self.pf_mac, extra_packet[3]['dip'], extra_packet[3]['sip'],
> extra_packet[3]['sport'],
> + extra_packet[3]['dport']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[0]['sip'], extra_packet[0]['dip'],
> extra_packet[3]['sport'], extra_packet[3]['dport'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[0]['sip'], extra_packet[0]['dip'], extra_packet[3]['sport'],
> + extra_packet[3]['dport']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.pf_mac)
>
> rule_num = extrapkt_rulenum['rulenum']
> @@ -736,11 +758,10 @@ class TestGeneric_flow_api(TestCase):
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> # send the packets inconsistent to the rules.
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=22,dport=24)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=22,dport=24)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=32,dport=34)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=32,dport=34)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -792,8 +813,8 @@ class TestGeneric_flow_api(TestCase):
> {'create': 'create', 'flows': ['ether', 'lldp'], 'actions': ['queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s",type=0x88E5)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(pktstr='Ether(dst="%s",type="0x88E5")/Raw("x" * 20)' %
> self.pf_mac)
> +
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -837,8 +858,7 @@ class TestGeneric_flow_api(TestCase):
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1BR(GRP=0x2, ECIDbase=%s)/Raw("x" *
> 20)], iface="%s")' % (self.pf_mac, extra_packet[0]['etag'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1BR(GRP=0x2,
> ECIDbase=%s)/Raw("x" * 20)' % (self.pf_mac, extra_packet[0]['etag']))
> self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -911,47 +931,45 @@ class TestGeneric_flow_api(TestCase):
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> # send the packets with dst/src ip and dst/src port.
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=3)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[0]['vlan'], self.tester_itf))
> +
> self.sendpkt(pktstr='Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=3)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[0]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3)/UDP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[1]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3)/UDP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[1]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][1], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[2]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[2]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][2], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3, ttl=3)/SCTP()/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[3]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", tos=3, ttl=3)/SCTP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[3]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][3], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[3]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.1",
> dst="192.168.0.2", ttl=3)/TCP()/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[3]['vlan']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/UDP()/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[2]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP()/UDP()/Raw("x" *
> 20)' % (self.pf_mac, extra_packet[2]['vlan']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3, ttl=3)/SCTP(sport=44,dport=45,tag=1)/Raw("x" *
> 20)], iface="%s")' % (self.pf_mac, extra_packet[6]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3, ttl=3)/SCTP(sport=44,dport=45,tag=1)/Raw("x" *
> 20)' % (self.pf_mac, extra_packet[6]['vlan']))
> self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3,
> ttl=3)/UDP(sport=44,dport=45)/SCTPChunkData(data="X" * 20)], iface="%s")' %
> (self.outer_mac, extra_packet[7]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IP(src="192.168.0.5",
> dst="192.168.0.6", tos=3,
> ttl=3)/UDP(sport=44,dport=45)/SCTPChunkData(data="X" * 20)' % (
> + self.outer_mac, extra_packet[7]['vlan']))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=1, nh=5, hlim=10)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[8]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2",
> tc=1, nh=5, hlim=10)/Raw("x" * 20)' % (
> + self.pf_mac, extra_packet[8]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][8], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[9]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[9]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][9], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[10]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2",
> tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)' % (
> + self.pf_mac, extra_packet[10]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][10], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=4, nh=132,
> hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[11]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2",
> tc=4, nh=132,
> hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)' % (
> + self.pf_mac, extra_packet[11]['vlan']))
> self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][11], verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=4, nh=132,
> hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[14]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2",
> tc=4, nh=132,
> hlim=40)/SCTP(sport=44,dport=45,tag=1)/SCTPChunkData(data="X" * 20)' % (
> + self.pf_mac, extra_packet[14]['vlan']))
> self.verify_result("pf", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)],
> iface="%s")' % (self.outer_mac, extra_packet[15]['vlan'], self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1", dst="2001::2",
> tc=2, hlim=20)/TCP(sport=32,dport=33)/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[15]['vlan']))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.outer_mac)
>
> rule_num = extrapkt_rulenum['rulenum']
> @@ -963,7 +981,8 @@ class TestGeneric_flow_api(TestCase):
> """
> self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville",
> "fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not
> support fdir ipv4 filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support fdir ipv4 filter" % self.nic)
> # i40e
> if (self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]):
> @@ -990,22 +1009,33 @@ class TestGeneric_flow_api(TestCase):
> # create the flow rules
> basic_flow_actions = [
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp',
> 'sport', 'dport', 'tag'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp',
> 'sport', 'dport', 'tag'], 'actions': ['drop']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport',
> 'tag'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport',
> 'tag'],
> + 'actions': ['drop']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'vf0'], 'actions':
> ['invalid']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto', 'vf0'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp',
> 'sport', 'dport', 'tag', 'vf1'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp',
> 'sport', 'dport', 'tag'], 'actions': ['passthru', 'flag']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport',
> 'dport'], 'actions': ['queue', 'flag']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport',
> 'dport'], 'actions': ['queue', 'mark']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport',
> 'tag', 'vf1'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv4', 'sip', 'dip', 'tos', 'ttl', 'sctp', 'sport', 'dport',
> 'tag'],
> + 'actions': ['passthru', 'flag']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'ttl', 'udp', 'sport',
> 'dport'],
> + 'actions': ['queue', 'flag']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tos', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue', 'mark']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'proto'], 'actions':
> ['passthru', 'mark']}
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3", dst="192.168.0.4",
> proto=%s)/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> extra_packet[0]['proto'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4", proto=%s)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[0]['proto']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1021,29 +1051,35 @@ class TestGeneric_flow_api(TestCase):
> if (self.nic in ["sagepond", "sageville"]):
> # create the flow rules
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> 'actions': ['drop']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp', 'sport', 'dport'],
> + 'actions': ['drop']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[2]['sip'], extra_packet[2]['dip'],
> extra_packet[2]['dport'], extra_packet[2]['sport'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP(sport=%s,dport=%s)/Raw("x" * 20)'% (
> + self.pf_mac, extra_packet[2]['sip'], extra_packet[2]['dip'],
> extra_packet[2]['dport'],
> + extra_packet[2]['sport']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> else:
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'udp', 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'tcp', 'sport', 'dport'],
> + 'actions': ['queue']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp'], 'actions':
> ['queue']},
> {'create': 'create', 'flows': ['ipv4', 'sip', 'dip', 'sctp'], 'actions':
> ['drop']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s")/SCTP()/Raw("x"
> * 20)], iface="%s")' % (self.pf_mac, extra_packet[2]['dip'],
> extra_packet[2]['sip'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s",
> dst="%s")/SCTP()/Raw("x" * 20)' % (self.pf_mac, extra_packet[2]['dip'],
> extra_packet[2]['sip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1054,7 +1090,8 @@ class TestGeneric_flow_api(TestCase):
> """
> self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville",
> "fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not
> support fdir ipv6 filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support fdir ipv6 filter" % self.nic)
> # i40e
> if (self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]):
> @@ -1077,19 +1114,30 @@ class TestGeneric_flow_api(TestCase):
>
> # create the flow rules
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop'],
> 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'udp',
> 'sport', 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp',
> 'sport', 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp',
> 'sport', 'dport', 'tag'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop',
> 'vf0'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp',
> 'sport', 'dport', 'vf1'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp',
> 'sport', 'dport', 'tag'], 'actions': ['drop']},
> - {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp',
> 'sport', 'dport', 'vf1'], 'actions': ['drop']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc',
> 'hop'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'udp',
> 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp',
> 'sport', 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport',
> 'tag'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'proto', 'tc', 'hop',
> 'vf0'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport',
> 'vf1'],
> + 'actions': ['queue']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'sctp', 'sport', 'dport',
> 'tag'],
> + 'actions': ['drop']},
> + {'create': 'create',
> + 'flows': ['vlan', 'ipv6', 'sip', 'dip', 'tc', 'hop', 'tcp', 'sport', 'dport',
> 'vf1'],
> + 'actions': ['drop']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)],
> iface="%s")' % (self.pf_mac, extra_packet[1]['vlan'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=%s)/IPv6(src="2001::1",
> dst="2001::2", tc=2, hlim=20)/UDP(sport=22,dport=23)/Raw("x" * 20)' %
> (self.pf_mac, extra_packet[1]['vlan']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1106,51 +1154,55 @@ class TestGeneric_flow_api(TestCase):
> basic_flow_actions = [
> {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip'], 'actions':
> ['queue']},
> {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip'], 'actions':
> ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp'],
> 'actions': ['queue']},
> {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp'],
> 'actions': ['queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5
> thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is
> 23 / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5
> thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is
> 23 / end actions queue index 1 / end",
> + "created")
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2",nh=132)/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2",nh=132)/SCTP()/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP()/Raw("x" * 20)], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP()/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> - self.verify_rulenum(rule_num+1)
> + self.verify_rulenum(rule_num + 1)
> elif (self.nic in ["sagepond", "sageville"]):
> # create the flow rules
> basic_flow_actions = [
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp', 'sport',
> 'dport'], 'actions': ['queue']},
> - {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp', 'sport',
> 'dport'], 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'udp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'tcp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv6', 'sip', 'dip', 'sctp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> + {'create': 'create', 'flows': ['fuzzy', 'ipv4', 'sip', 'dip', 'sctp', 'sport',
> 'dport'],
> + 'actions': ['queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5
> thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is
> 23 / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh spec 2 thresh last 5
> thresh mask 0xffffffff / ipv6 src is 2001::1 dst is 2001::2 / udp src is 22 dst is
> 23 / end actions queue index 1 / end",
> + "created")
> extra_packet = extrapkt_rulenum['extrapacket']
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="%s", dst="%s",
> nh=132)/SCTP(sport=32,dport=33,tag=1)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[3]['sip'], extra_packet[3]['dip'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="%s", dst="%s",
> nh=132)/SCTP(sport=32,dport=33,tag=1)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[3]['sip'], extra_packet[3]['dip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="%s", dst="%s",
> proto=132)/SCTP(sport=32,dport=33)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, extra_packet[4]['dip'], extra_packet[4]['sip'], self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="%s", dst="%s",
> proto=132)/SCTP(sport=32,dport=33)/Raw("x" * 20)' % (self.pf_mac,
> extra_packet[4]['dip'], extra_packet[4]['sip']))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.pf_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/UDP(sport=22,dport=23)/Raw("x" * 20)' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.pf_mac)
> rule_num = extrapkt_rulenum['rulenum']
> - self.verify_rulenum(rule_num+1)
> + self.verify_rulenum(rule_num + 1)
>
> def test_fdir_for_flexbytes(self):
> """
> @@ -1158,7 +1210,8 @@ class TestGeneric_flow_api(TestCase):
> """
> self.verify(self.nic in ["niantic", "twinville", "sagepond", "sageville",
> "fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not
> support fdir flexbytes filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support fdir flexbytes filter" % self.nic)
> # i40e
> if (self.nic in ["fortville_eagle", "fortville_spirit",
> "fortville_spirit_single", "fortpark_TLV"]):
> @@ -1171,46 +1224,47 @@ class TestGeneric_flow_api(TestCase):
> # creat the flow rules
> # l2-payload exceeds the max length of raw match is 16bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1
> pattern is abcdefghijklmnopq / end actions queue index 1 / end", "Exceeds
> maxmial payload limit")
> + "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1
> pattern is abcdefghijklmnopq / end actions queue index 1 / end",
> + "Exceeds maxmial payload limit")
> # l2-payload equal the max length of raw match is 16bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1
> pattern is abcdefghijklmnop / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern eth type is 0x0807 / raw relative is 1
> pattern is abcdefghijklmnop / end actions queue index 1 / end",
> + "created")
> # ipv4-other the most 3 fields can be matched, and the max sum bytes
> of the three fields is 16 bytes.
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / vlan tci is 4095 / ipv4 proto is
> 255 ttl is 40 / raw relative is 1 offset is 2 pattern is ab / raw relative is 1 offset
> is 10 pattern is abcdefghij / raw relative is 1 offset is 0 pattern is abcd / end
> actions queue index 2 / end", "created")
> + "flow create 0 ingress pattern eth / vlan tci is 4095 / ipv4 proto is
> 255 ttl is 40 / raw relative is 1 offset is 2 pattern is ab / raw relative is 1 offset
> is 10 pattern is abcdefghij / raw relative is 1 offset is 0 pattern is abcd / end
> actions queue index 2 / end",
> + "created")
> # ipv4-udp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 /
> udp src is 22 dst is 23 / raw relative is 1 offset is 2 pattern is fhds / end
> actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 /
> udp src is 22 dst is 23 / raw relative is 1 offset is 2 pattern is fhds / end
> actions queue index 3 / end",
> + "created")
> # ipv4-tcp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5
> tos is 4 ttl is 3 / tcp src is 32 dst is 33 / raw relative is 1 offset is 2 pattern is
> hijk / end actions queue index 4 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5
> tos is 4 ttl is 3 / tcp src is 32 dst is 33 / raw relative is 1 offset is 2 pattern is
> hijk / end actions queue index 4 / end",
> + "created")
> # ipv4-sctp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 /
> sctp src is 42 / raw relative is 1 offset is 2 pattern is abcd / end actions queue
> index 5 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 2.2.2.4 dst is 2.2.2.5 /
> sctp src is 42 / raw relative is 1 offset is 2 pattern is abcd / end actions queue
> index 5 / end",
> + "created")
>
> # send the packets and verify the results
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s",
> type=0x0807)/Raw(load="abcdefghijklmnop")], iface="%s")' % (self.pf_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s",
> type=0x0807)/Raw(load="abcdefghijklmnop")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=4095)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=255,
> ttl=40)/Raw(load="xxabxxxxxxxxxxabcdefghijabcdefg")], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/Dot1Q(vlan=4095)/IP(src="192.168.0.1",
> dst="192.168.0.2", proto=255,
> ttl=40)/Raw(load="xxabxxxxxxxxxxabcdefghijabcdefg")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/UDP(sport=22,dport=23)/Raw(load="fhfhdsdsfwef")],
> iface="%s")' % (self.pf_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/UDP(sport=22,dport=23)/Raw(load="fhfhdsdsfwef")' %
> self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.pf_mac)
>
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5", tos=4,
> ttl=3)/TCP(sport=32,dport=33)/Raw(load="fhhijk")], iface="%s")' %
> (self.pf_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="2.2.2.4", dst="2.2.2.5", tos=4,
> ttl=3)/TCP(sport=32,dport=33)/Raw(load="fhhijk")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.pf_mac)
> -
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabcdefghijklmn
> opqrst")], iface="%s")' % (self.pf_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabcdefghijklmn
> opqrst")' % self.pf_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="5",
> verify_mac=self.pf_mac)
> -
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabxxxabcddxxa
> bcdefghijklmn")], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="2.2.2.4",
> dst="2.2.2.5")/SCTP(sport=42,dport=43,tag=1)/Raw(load="xxabxxxabcddxxa
> bcdefghijklmn")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.verify_rulenum(5)
> @@ -1226,11 +1280,12 @@ class TestGeneric_flow_api(TestCase):
>
> # ipv6-tcp
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / vlan tci is 1 / ipv6 src is 2001::1
> dst is 2001::2 tc is 3 hop is 30 / tcp src is 32 dst is 33 / raw relative is 1 offset is
> 0 pattern is hijk / raw relative is 1 offset is 8 pattern is abcdefgh / end actions
> queue index 6 / end", "created")
> + "flow create 0 ingress pattern eth / vlan tci is 1 / ipv6 src is 2001::1
> dst is 2001::2 tc is 3 hop is 30 / tcp src is 32 dst is 33 / raw relative is 1 offset is
> 0 pattern is hijk / raw relative is 1 offset is 8 pattern is abcdefgh / end actions
> queue index 6 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Dot1Q(vlan=1)/IPv6(src="2001::1",
> dst="2001::2", tc=3,
> hlim=30)/TCP(sport=32,dport=33)/Raw(load="hijkabcdefghabcdefghijklmn")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/Dot1Q(vlan=1)/IPv6(src="2001::1", dst="2001::2",
> tc=3,
> hlim=30)/TCP(sport=32,dport=33)/Raw(load="hijkabcdefghabcdefghijklmn")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="6",
> verify_mac=self.outer_mac)
>
> # ixgbe
> @@ -1243,11 +1298,12 @@ class TestGeneric_flow_api(TestCase):
>
> # ipv4-udp-flexbytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.1 dst is
> 192.168.0.2 / udp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 44
> limit is 0 pattern is 86 / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.1 dst is
> 192.168.0.2 / udp src is 24 dst is 25 / raw relative is 0 search is 0 offset is 44
> limit is 0 pattern is 86 / end actions queue index 1 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=24,dport=25)/Raw(load="xx86ddef")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/UDP(sport=24,dport=25)/Raw(load="xx86ddef")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.outer_mac)
>
> self.dut.send_expect("quit", "# ")
> @@ -1262,15 +1318,15 @@ class TestGeneric_flow_api(TestCase):
>
> # ipv4-tcp-flexbytes spec-mask
> self.dut.send_expect(
> - "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.3 dst is
> 192.168.0.4 / tcp src is 22 dst is 23 / raw relative spec 0 relative mask 1 search
> spec 0 search mask 1 offset spec 54 offset mask 0xffffffff limit spec 0 limit
> mask 0xffff pattern is ab pattern is cd / end actions queue index 2 / end",
> "created")
> + "flow create 0 ingress pattern eth / ipv4 src is 192.168.0.3 dst is
> 192.168.0.4 / tcp src is 22 dst is 23 / raw relative spec 0 relative mask 1 search
> spec 0 search mask 1 offset spec 54 offset mask 0xffffffff limit spec 0 limit
> mask 0xffff pattern is ab pattern is cd / end actions queue index 2 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="abcdxxx")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="abcdxxx")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> -
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="cdcdxxx")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.3",
> dst="192.168.0.4")/TCP(sport=22,dport=23)/Raw(load="cdcdxxx")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.outer_mac)
>
> self.dut.send_expect("quit", "# ")
> @@ -1286,17 +1342,19 @@ class TestGeneric_flow_api(TestCase):
> # ipv4-sctp-flexbytes
> if (self.nic in ["sagepond", "sageville"]):
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp src is 24 dst is 25 / raw relative is 0
> search is 0 offset is 48 limit is 0 pattern is ab / end actions queue index 3 /
> end", "created")
> + "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp src is 24 dst is 25 / raw relative is 0
> search is 0 offset is 48 limit is 0 pattern is ab / end actions queue index 3 /
> end",
> + "created")
> else:
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp / raw relative is 0 search is 0 offset is 48
> limit is 0 pattern is ab / end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern fuzzy thresh is 6 / eth / ipv4 src is
> 192.168.0.1 dst is 192.168.0.2 / sctp / raw relative is 0 search is 0 offset is 48
> limit is 0 pattern is ab / end actions queue index 3 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxabcdef")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxabcdef")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxaccdef")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/SCTP(sport=24,dport=25)/Raw(load="xxaccdef")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> # ipv6-other-flexbytes
> @@ -1311,12 +1369,13 @@ class TestGeneric_flow_api(TestCase):
> time.sleep(2)
>
> self.dut.send_expect(
> - "flow create 0 ingress pattern fuzzy thresh is 6 / ipv6 src is
> 2001::1 dst is 2001::2 / raw relative is 0 search is 0 offset is 56 limit is 0
> pattern is 86 / end actions queue index 4 / end", "created")
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xx86abcd")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + "flow create 0 ingress pattern fuzzy thresh is 6 / ipv6 src is
> 2001::1 dst is 2001::2 / raw relative is 0 search is 0 offset is 56 limit is 0
> pattern is 86 / end actions queue index 4 / end",
> + "created")
> + self.sendpkt(
> + 'Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xx86abcd")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxx86abcd")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt(
> + 'Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxx86abcd")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> def test_flexbytes_filter(self):
> @@ -1334,79 +1393,77 @@ class TestGeneric_flow_api(TestCase):
> # create the flow rules
> # l2_payload
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 14 pattern is
> fhds / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 14 pattern is
> fhds / end actions queue index 1 / end",
> + "created")
> # ipv4 packet
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 34 pattern is
> ab / end actions queue index 2 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 34 pattern is
> ab / end actions queue index 2 / end",
> + "created")
> # ipv6 packet
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 58 pattern is
> efgh / end actions queue index 3 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 58 pattern is
> efgh / end actions queue index 3 / end",
> + "created")
> # 3 fields relative is 0
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 38 pattern is
> ab / raw relative is 0 offset is 34 pattern is cd / raw relative is 0 offset is 42
> pattern is efgh / end actions queue index 4 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 38 pattern is
> ab / raw relative is 0 offset is 34 pattern is cd / raw relative is 0 offset is 42
> pattern is efgh / end actions queue index 4 / end",
> + "created")
> # 4 fields relative is 0 and 1
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 48 pattern is
> ab / raw relative is 1 offset is 0 pattern is cd / raw relative is 0 offset is 44
> pattern is efgh / raw relative is 1 offset is 10 pattern is hijklmnopq / end
> actions queue index 5 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 48 pattern is
> ab / raw relative is 1 offset is 0 pattern is cd / raw relative is 0 offset is 44
> pattern is efgh / raw relative is 1 offset is 10 pattern is hijklmnopq / end
> actions queue index 5 / end",
> + "created")
> # 3 fields offset confilict
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 64 pattern is
> ab / raw relative is 1 offset is 4 pattern is cdefgh / raw relative is 0 offset is 68
> pattern is klmn / end actions queue index 6 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 64 pattern is
> ab / raw relative is 1 offset is 4 pattern is cdefgh / raw relative is 0 offset is 68
> pattern is klmn / end actions queue index 6 / end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Raw(load="fhdsab")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Raw(load="fhdsab")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/Raw(load="afhdsb")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/Raw(load="afhdsb")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="abcdef")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="abcdef")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxxxefgh")], iface="%s")' % (self.outer_mac,
> self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/Raw(load="xxxxefgh")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="3",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(sport=32,dport=33)/Raw(load="abcdefgh")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IPv6(src="2001::1",
> dst="2001::2")/TCP(sport=32,dport=33)/Raw(load="abcdefgh")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="cdxxabxxefghxxxx")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/Raw(load="cdxxabxxefghxxxx")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="4",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2",
> tos=4,
> ttl=3)/UDP(sport=32,dport=33)/Raw(load="xxefghabcdxxxxxxhijklmnopqxxxx
> ")], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1", dst="192.168.0.2",
> tos=4,
> ttl=3)/UDP(sport=32,dport=33)/Raw(load="xxefghabcdxxxxxxhijklmnopqxxxx
> ")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="5",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklmn
> efgh")], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklmn
> efgh")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="6",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklcde
> fgh")], iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxabxxklcde
> fgh")' % self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.dut.send_expect("flow flush 0", "testpmd> ", 120)
>
> # 1 field 128bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 128 pattern is
> ab / end actions queue index 1 / end", "Failed to create flow")
> + "flow create 0 ingress pattern raw relative is 0 offset is 128 pattern is
> ab / end actions queue index 1 / end",
> + "Failed to create flow")
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is
> abcd / end actions queue index 1 / end", "Failed to create flow")
> + "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is
> abcd / end actions queue index 1 / end",
> + "Failed to create flow")
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is
> ab / end actions queue index 1 / end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 126 pattern is
> ab / end actions queue index 1 / end",
> + "created")
> # 2 field 128bytes
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is
> ab / raw relative is 1 offset is 58 pattern is cd / end actions queue index 2 /
> end", "Failed to create flow")
> + "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is
> ab / raw relative is 1 offset is 58 pattern is cd / end actions queue index 2 /
> end",
> + "Failed to create flow")
> self.dut.send_expect(
> - "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is
> ab / raw relative is 1 offset is 56 pattern is cd / end actions queue index 2 /
> end", "created")
> + "flow create 0 ingress pattern raw relative is 0 offset is 68 pattern is
> ab / raw relative is 1 offset is 56 pattern is cd / end actions queue index 2 /
> end",
> + "created")
>
> # send the packet and verify the result
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxab")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxab")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="1",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcb")], iface="%s")' %
> (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcb")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcd")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcd")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="2",
> verify_mac=self.outer_mac)
> - self.tester.scapy_append(
> - 'sendp([Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxce")],
> iface="%s")' % (self.outer_mac, self.tester_itf))
> + self.sendpkt('Ether(dst="%s")/IP(src="192.168.0.1",
> dst="192.168.0.2")/TCP(sport=22,dport=23)/Raw(load="xxxxxxxxxxxxxxabxx
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxce")' %
> self.outer_mac)
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.verify_rulenum(2)
> @@ -1481,7 +1538,8 @@ class TestGeneric_flow_api(TestCase):
> only supported by i40e
> """
> self.verify(self.nic in ["fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not
> support tunnel vxlan filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support tunnel vxlan filter" % self.nic)
>
> self.setup_env()
> self.pmdout.start_testpmd("%s" % self.pf_cores, "--disable-rss --rxq=%d
> --txq=%d" % (MAX_QUEUE+1, MAX_QUEUE+1), "-w %s --file-prefix=pf --
> socket-mem 1024,1024 --legacy-mem" % self.pf_pci)
> @@ -1506,32 +1564,35 @@ class TestGeneric_flow_api(TestCase):
> {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'ineth'], 'actions': ['pf',
> 'queue']},
> {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth'], 'actions':
> ['pf', 'queue']},
> {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'ineth', 'invlan'],
> 'actions': ['pf', 'queue']},
> - {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'],
> 'actions': ['pf', 'queue']},
> - {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'],
> 'actions': ['pf', 'queue']},
> - {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'],
> 'actions': ['vf0', 'queue']},
> - {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni', 'ineth'],
> 'actions': ['vf1', 'queue']},
> + {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'],
> + 'actions': ['pf', 'queue']},
> + {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni',
> 'ineth'],
> + 'actions': ['pf', 'queue']},
> + {'create': 'create', 'flows': ['ipv4', 'udp', 'vxlan', 'vni', 'ineth', 'invlan'],
> + 'actions': ['vf0', 'queue']},
> + {'create': 'create', 'flows': ['dst_mac', 'ipv4', 'udp', 'vxlan', 'vni',
> 'ineth'],
> + 'actions': ['vf1', 'queue']},
> ]
> extrapkt_rulenum = self.all_flows_process(basic_flow_actions)
> extra_packet = extrapkt_rulenum['extrapacket']
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN()/Ether(dst="%s")/Dot1Q(vlan=11
> )/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.inner_mac,
> self.tester_itf))
> - self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.outer_mac)
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN()/Ether(dst="%s")/Dot1Q(vl
> an=11)/IP()/TCP()/Raw("x" * 20)' % (self.outer_mac, self.inner_mac))
> + self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0],
> + verify_mac=self.outer_mac)
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=5)/Ether(dst="%s")/IP()/TCP()
> /Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.wrong_mac,
> self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=5)/Ether(dst="%s")/IP()/
> TCP()/Raw("x" * 20)' % (self.outer_mac, self.wrong_mac))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/Dot1Q(
> vlan=%s)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac,
> extra_packet[5]['vni'], self.wrong_mac, extra_packet[5]['invlan'],
> self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/Do
> t1Q(vlan=%s)/IP()/TCP()/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[5]['vni'], self.wrong_mac,
> extra_packet[5]['invlan']))
> self.verify_result("vf0", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("vxlan")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/IP()/TCP
> ()/Raw("x" * 20)], iface="%s")' % (self.wrong_mac, extra_packet[6]['vni'],
> self.inner_mac, self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/UDP()/VXLAN(vni=%s)/Ether(dst="%s")/IP(
> )/TCP()/Raw("x" * 20)' % (
> + self.wrong_mac, extra_packet[6]['vni'], self.inner_mac))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.wrong_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> @@ -1541,7 +1602,8 @@ class TestGeneric_flow_api(TestCase):
> only supported by i40e
> """
> self.verify(self.nic in ["fortville_eagle", "fortville_spirit",
> - "fortville_spirit_single", "fortpark_TLV"], "%s nic not
> support tunnel nvgre filter" % self.nic)
> + "fortville_spirit_single", "fortpark_TLV"],
> + "%s nic not support tunnel nvgre filter" % self.nic)
>
> self.setup_env()
> self.pmdout.start_testpmd("%s" % self.pf_cores, "--disable-rss --rxq=%d
> --txq=%d" % (MAX_QUEUE+1, MAX_QUEUE+1), "-w %s --file-prefix=pf --
> socket-mem 1024,1024 --legacy-mem" % self.pf_pci)
> @@ -1574,23 +1636,23 @@ class TestGeneric_flow_api(TestCase):
> extra_packet = extrapkt_rulenum['extrapacket']
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE()/Ether(dst="%s")/Dot1Q(vlan=1)/IP()/T
> CP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac, self.inner_mac,
> self.tester_itf))
> - self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0], verify_mac=self.outer_mac)
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE()/Ether(dst="%s")/Dot1Q(vlan=1)/
> IP()/TCP()/Raw("x" * 20)' % (self.outer_mac, self.inner_mac))
> + self.verify_result("pf", expect_rxpkts="1",
> expect_queue=extrapkt_rulenum['queue'][0],
> + verify_mac=self.outer_mac)
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Ra
> w("x" * 20)], iface="%s")' % (self.outer_mac, extra_packet[4]['tni'],
> self.wrong_mac, self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP
> ()/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[4]['tni'], self.wrong_mac))
> self.verify_result("pf", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/Dot1Q(vlan=
> %s)/IP()/TCP()/Raw("x" * 20)], iface="%s")' % (self.outer_mac,
> extra_packet[5]['tni'], self.wrong_mac, extra_packet[5]['invlan'],
> self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/Dot1Q(v
> lan=%s)/IP()/TCP()/Raw("x" * 20)' % (
> + self.outer_mac, extra_packet[5]['tni'], self.wrong_mac,
> extra_packet[5]['invlan']))
> self.verify_result("vf0", expect_rxpkts="1", expect_queue="0",
> verify_mac=self.outer_mac)
>
> self.load_module("nvgre")
> - self.tester.scapy_append(
> -
> 'sendp([Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP()/Ra
> w("x" * 20)], iface="%s")' % (self.wrong_mac, extra_packet[6]['tni'],
> self.inner_mac, self.tester_itf))
> +
> self.sendpkt('Ether(dst="%s")/IP()/NVGRE(TNI=%s)/Ether(dst="%s")/IP()/TCP
> ()/Raw("x" * 20)' % (
> + self.wrong_mac, extra_packet[6]['tni'], self.inner_mac))
> self.verify_result("vf1", expect_rxpkts="0", expect_queue="NULL",
> verify_mac=self.wrong_mac)
> rule_num = extrapkt_rulenum['rulenum']
> self.verify_rulenum(rule_num)
> diff --git a/tests/TestSuite_hotplug.py b/tests/TestSuite_hotplug.py
> index a94967a..a7a7228 100644
> --- a/tests/TestSuite_hotplug.py
> +++ b/tests/TestSuite_hotplug.py
> @@ -121,7 +121,7 @@ class TestPortHotPlug(TestCase):
> self.txItf = self.tester.get_interface(txport)
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': self.dmac,})
> - pkt.send_pkt(tx_port=self.txItf)
> + pkt.send_pkt(self.tester, tx_port=self.txItf)
>
> def test_before_attach(self):
> """
> diff --git a/tests/TestSuite_iavf.py b/tests/TestSuite_iavf.py
> index 9395555..af8c747 100644
> --- a/tests/TestSuite_iavf.py
> +++ b/tests/TestSuite_iavf.py
> @@ -588,7 +588,7 @@ class TestIavf(TestCase):
> self.tester.scapy_execute()
> rec_pkt = self.tester.load_tcpdump_sniff_packets(inst)
> # collect checksum values for received packet
> - chksum =
> rec_pkt[0].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%
> ;%SCTP.chksum%").split(";")
> + chksum =
> rec_pkt[0].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chk
> sum%").split(";")
> chksum = list(set(chksum))
> chksum.remove("??")
> corrected_checksum_values[packet] = chksum
> diff --git a/tests/TestSuite_ieee1588.py b/tests/TestSuite_ieee1588.py
> index 0dd3d6e..f3fea42 100644
> --- a/tests/TestSuite_ieee1588.py
> +++ b/tests/TestSuite_ieee1588.py
> @@ -91,12 +91,13 @@ class TestIeee1588(TestCase):
>
> self.tester.send_expect(
> "tcpdump -i %s -e ether src %s" % (itf, mac), "tcpdump", 20)
> -
> + self.send_session = self.tester.create_session('send_session')
> + setattr(self.send_session, 'tmp_file', self.tester.tmp_file)
> pkt = Packet(pkt_type='TIMESYNC')
> - pkt.config_layer('ether', {'dst': mac, })
> - pkt.send_pkt(tx_port=itf)
> -
> + pkt.config_layer('ether', {'dst': mac})
> + pkt.send_pkt(self.send_session, tx_port=itf)
> time.sleep(1)
> + self.send_session.close()
> out = self.tester.get_session_output(timeout=20)
>
> self.tester.send_expect("^C", "# ", 20)
> diff --git a/tests/TestSuite_ipfrag.py b/tests/TestSuite_ipfrag.py
> index f6d0373..5edd6c4 100644
> --- a/tests/TestSuite_ipfrag.py
> +++ b/tests/TestSuite_ipfrag.py
> @@ -168,37 +168,36 @@ l3fwd_ipv4_route_array[] = {\\\n"
> expPkts = 1
> val = 2
>
> - inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf)
> # send packet
> for times in range(burst):
> pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
> pkt = Packet(pkt_type='UDP', pkt_len=pkt_size)
> - pkt.config_layer('ether', {'dst': self.dmac})
> + pkt.config_layer('ether', {'dst': '%s' % self.dmac})
> pkt.config_layer('ipv4', {'dst': '100.10.0.1', 'src': '1.2.3.4', 'flags': val})
> - pkt.send_pkt(tx_port=self.txItf)
> + pkt.send_pkt(self.tester, tx_port=self.txItf)
>
> # verify normal packet just by number, verify fragment packet by all
> elements
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> self.verify(len(pkts) == expPkts, "in functional_check_ipv4(): failed on
> forward packet size " + str(size))
> if flag == 'frag':
> idx = 1
> - for pkt in pkts:
> - # packet index should be same
> - pkt_id = pkt.strip_element_layer3("id")
> + for i in range(len(pkts)):
> + pkt_id = pkts.strip_element_layer3('id', p_index=i)
> if idx == 1:
> prev_idx = pkt_id
> self.verify(prev_idx == pkt_id, "Fragmented packets index not
> match")
> prev_idx = pkt_id
>
> # last flags should be 0
> - flags = pkt.strip_element_layer3("flags")
> + flags = pkts.strip_element_layer3("flags", p_index=i)
> if idx == expPkts:
> self.verify(flags == 0, "Fragmented last packet flags not match")
> else:
> self.verify(flags == 1, "Fragmented packets flags not match")
>
> # fragment offset should be correct
> - frag = pkt.strip_element_layer3("frag")
> + frag = pkts.strip_element_layer3("frag", p_index=i)
> self.verify((frag == ((idx - 1) * 185)), "Fragment packet frag not
> match")
> idx += 1
>
> @@ -218,37 +217,36 @@ l3fwd_ipv4_route_array[] = {\\\n"
> expPkts = 1
> val = 2
>
> - inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf)
> # send packet
> for times in range(burst):
> pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
> pkt = Packet(pkt_type='IPv6_UDP', pkt_len=pkt_size)
> - pkt.config_layer('ether', {'dst': self.dmac})
> + pkt.config_layer('ether', {'dst': '%s' % self.dmac})
> pkt.config_layer('ipv6', {'dst': '101:101:101:101:101:101:101:101',
> 'src': 'ee80:ee80:ee80:ee80:ee80:ee80:ee80:ee80'})
> - pkt.send_pkt(tx_port=self.txItf)
> + pkt.send_pkt(self.tester, tx_port=self.txItf)
>
> # verify normal packet just by number, verify fragment packet by all
> elements
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> self.verify(len(pkts) == expPkts, "In functional_check_ipv6(): failed on
> forward packet size " + str(size))
> if flag == 'frag':
> idx = 1
> - for pkt in pkts:
> - # packet index should be same
> - pkt_id = pkt.strip_element_layer4("id")
> + for i in range(len(pkts)):
> + pkt_id = pkts.strip_element_layer4('id', p_index=i)
> if idx == 1:
> prev_idx = pkt_id
> self.verify(prev_idx == pkt_id, "Fragmented packets index not
> match")
> prev_idx = pkt_id
>
> # last flags should be 0
> - flags = pkt.strip_element_layer4("m")
> + flags = pkts.strip_element_layer4("m", p_index=i)
> if idx == expPkts:
> self.verify(flags == 0, "Fragmented last packet flags not match")
> else:
> self.verify(flags == 1, "Fragmented packets flags not match")
>
> # fragment offset should be correct
> - frag = pkt.strip_element_layer4("offset")
> + frag = pkts.strip_element_layer4("offset", p_index=i)
> self.verify((frag == int((idx - 1) * 181)), "Fragment packet frag not
> match")
> idx += 1
>
> diff --git a/tests/TestSuite_ipgre.py b/tests/TestSuite_ipgre.py
> index d08a933..7258db5 100644
> --- a/tests/TestSuite_ipgre.py
> +++ b/tests/TestSuite_ipgre.py
> @@ -100,11 +100,11 @@ class TestIpgre(TestCase):
> if layer_configs:
> for layer in layer_configs.keys():
> pkt.config_layer(layer, layer_configs[layer])
> - inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1,
> timeout=8)
> - pkt.send_pkt(tx_port=self.tester_iface, count = 4)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1)
> + pkt.send_pkt(crb=self.tester, tx_port=self.tester_iface, count=4)
> out = self.dut.get_session_output(timeout=2)
> time.sleep(1)
> - self.tester.load_tcpdump_sniff_packets(inst)
> + pkt = self.tester.load_tcpdump_sniff_packets(inst)
> if self.printFlag: # debug output
> print out
> for pkt_layer_name in pkt_names:
> @@ -116,7 +116,7 @@ class TestIpgre(TestCase):
> raise VerifyFailure("Failed to detect %s" % pkt_layer_name)
> else:
> print utils.GREEN("Detected %s successfully" % pkt_type)
> - time.sleep(1)
> + time.sleep(1)
> if queue == None: # no filter
> pass
> else:
> @@ -124,6 +124,7 @@ class TestIpgre(TestCase):
> self.verify(("Receive queue=0x%s" % queue) in out, "Failed to
> enter the right queue.")
> else:
> self.verify(("Receive queue=0x%s" % queue) not in out, "Failed to
> enter the right queue.")
> + return pkt
>
>
> def save_ref_packet(self, pkt_types, layer_configs=None):
> @@ -146,13 +147,16 @@ class TestIpgre(TestCase):
> Skip outer udp for it will be calculated by software
> """
> chk_sums = {}
> - pkts = rdpcap(pcap)
> + if isinstance(pcap, str):
> + pkts = rdpcap(pcap)
> + else:
> + pkts = pcap.pktgen.pkts
> for number in range(len(pkts)):
> if pkts[number].guess_payload_class(pkts[number]).name == "gre":
> payload = pkts[number][GRE]
> else:
> payload = pkts[number]
> -
> +
> if payload.guess_payload_class(payload).name == "IP":
> chk_sums['outer_ip'] = hex(payload[IP].chksum)
>
> @@ -170,9 +174,9 @@ class TestIpgre(TestCase):
>
> return chk_sums
>
> - def compare_checksum(self):
> - chksums_ref = self.get_chksums('/tmp/ref_pkt.pcap')
> - chksums =
> self.get_chksums('/tmp/sniff_{0}.pcap'.format(self.tester_iface))
> + def compare_checksum(self, pkt):
> + chksums_ref = self.get_chksums('/tmp/ref_pkt.pcap')
> + chksums = self.get_chksums(pcap=pkt)
> self.logger.info("chksums_ref :: %s"%chksums_ref)
> self.logger.info("chksums :: %s"%chksums)
> # verify saved pcap checksum same to expected checksum
> @@ -197,8 +201,8 @@ class TestIpgre(TestCase):
> 'ipv4': {'proto': 'gre'}}
> # Start testpmd and enable rxonly forwarding mode
> testpmd_cmd = "./%s/app/testpmd -c ffff -n 4 -- -i --enable-rx-cksum" %
> self.target
> - self.dut.send_expect( testpmd_cmd,
> - "testpmd>",
> + self.dut.send_expect( testpmd_cmd,
> + "testpmd>",
> 20)
> self.dut.send_expect("set fwd rxonly", "testpmd>")
> self.dut.send_expect("set verbose 1", "testpmd>")
> @@ -233,7 +237,7 @@ class TestIpgre(TestCase):
> "MAC_IPv6_GRE_IPv6-TUNNEL_SCTP_PKT": ["TUNNEL_GRENAT",
> "INNER_L4_SCTP"],
> "MAC_VLAN_IPv6_GRE_IPv6-TUNNEL_SCTP_PKT":
> ["TUNNEL_GRENAT", "INNER_L4_SCTP", "PKT_RX_VLAN"]
> }
> -
> +
> # Start testpmd and enable rxonly forwarding mode
> testpmd_cmd = "./%s/app/testpmd -c ffff -n 4 -- -i --enable-rx-cksum --
> enable-hw-vlan" % self.target
> self.dut.send_expect(testpmd_cmd, "testpmd>", 20)
> @@ -258,7 +262,7 @@ class TestIpgre(TestCase):
> config_layers = {'ether': {'src': self.outer_mac_src},
> 'ipv6': {'nh': 47},
> 'gre': {'proto': 0x86dd},
> - 'inner_ipv6': {'nh': 132},
> + 'inner_ipv6': {'nh': 132},
> 'raw': {'payload':['78']*40}}
> self.check_packet_transmission(pkt_types_ipv6_ipv6_SCTP,
> config_layers)
> self.dut.send_expect("quit", "#")
> @@ -271,7 +275,7 @@ class TestIpgre(TestCase):
> """
> outer_mac = self.tester_iface_mac
> inner_mac = "10:00:00:00:00:00"
> -
> +
> # Start testpmd with multi queues
> #testpmd_cmd = "./%s/app/testpmd -c ff -n 3 -- -i --rxq=4 --txq=4" %
> self.target
> testpmd_cmd = "./%s/app/testpmd -c ff -n 3 -- -i --enable-rx-cksum --
> rxq=4 --txq=4" % self.target
> @@ -284,7 +288,7 @@ class TestIpgre(TestCase):
> # Add GRE filter that forward inner ip address 0.0.0.0 to queue 3
> cmd = "tunnel_filter add 0 %s %s 0.0.0.0 1 ipingre iip 0 3"%(outer_mac,
> inner_mac)
> self.dut.send_expect( cmd, "testpmd>")
> -
> +
> # Send packet inner ip address matched and check packet received by
> queue 3
> pkt_types = {"MAC_IP_GRE_IPv4-TUNNEL_UDP_PKT":
> ["TUNNEL_GRENAT", "INNER_L4_UDP"]}
> config_layers = {'ether': {'src': self.outer_mac_src},
> @@ -298,7 +302,7 @@ class TestIpgre(TestCase):
> cmd = "tunnel_filter rm 0 %s %s 0.0.0.0 1 ipingre iip 0 3"%(outer_mac,
> inner_mac)
> self.dut.send_expect( cmd, "testpmd>")
> self.check_packet_transmission(pkt_types, config_layers, "3")
> -
> +
> # Add GRE filter that forward outer ip address 0.0.0.0 to queue 3
> cmd = "tunnel_filter add 0 %s %s 0.0.0.0 1 ipingre oip 0 3"%(outer_mac,
> inner_mac)
> self.dut.send_expect( cmd, "testpmd>")
> @@ -341,7 +345,7 @@ class TestIpgre(TestCase):
>
> # Send packet with wrong outer IP checksum and check forwarded
> packet IP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT":
> ["PKT_TX_IP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -349,7 +353,7 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -357,12 +361,12 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst,
> 'chksum': 0x0}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
>
> # Send packet with wrong inner IP checksum and check forwarded
> packet IP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT":
> ["PKT_TX_IP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -370,7 +374,7 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -378,22 +382,22 @@ class TestIpgre(TestCase):
> 'chksum': 0x0},
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> -
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
> +
> # Send packet with wrong inner TCP checksum and check forwarded
> packet TCP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_TCP_PKT":
> ["PKT_TX_TCP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> 'dst': self.outer_ip_dst},
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> - 'tcp': {'src': 53,
> + 'tcp': {'src': 53,
> 'dst': 53}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -401,12 +405,12 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> 'tcp': {'chksum': 0x0}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
>
> # Send packet with wrong inner UDP checksum and check forwarded
> packet UDP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_UDP_PKT":
> ["PKT_TX_UDP_CKSUM"]}
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -414,7 +418,7 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst}}
> self.save_ref_packet(pkt_types, config_layers)
> - config_layers = {'ether': {'src': self.outer_mac_src,
> + config_layers = {'ether': {'src': self.outer_mac_src,
> 'dst': self.outer_mac_dst},
> 'ipv4': {'proto': 'gre',
> 'src': self.outer_ip_src,
> @@ -422,8 +426,8 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> 'udp': {'chksum': 0xffff}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
> if self.nic != "cavium_a063":
> # Send packet with wrong inner SCTP checksum and check forwarded
> packet SCTP checksum is correct
> pkt_types = { "MAC_IP_GRE_IPv4-TUNNEL_SCTP_PKT":
> ["PKT_TX_SCTP_CKSUM"]}
> @@ -445,20 +449,22 @@ class TestIpgre(TestCase):
> 'inner_ipv4':{'src':self.inner_ip_src,
> 'dst':self.inner_ip_dst},
> 'sctp': {'chksum': 0x0}}
> - self.check_packet_transmission(pkt_types, config_layers)
> - self.compare_checksum()
> + pkt = self.check_packet_transmission(pkt_types, config_layers)
> + self.compare_checksum(pkt)
>
> self.dut.send_expect("quit", "#")
>
> def tear_down(self):
> """
> Run after each test case.
> + Nothing to do.
> """
> - self.dut.kill_all()
> + pass
>
> def tear_down_all(self):
> """
> Run after each test suite.
> Nothing to do.
> """
> + self.dut.kill_all()
> pass
> diff --git a/tests/TestSuite_ipsec_gw_cryptodev_func.py
> b/tests/TestSuite_ipsec_gw_cryptodev_func.py
> index 5b815ad..9800886 100644
> --- a/tests/TestSuite_ipsec_gw_cryptodev_func.py
> +++ b/tests/TestSuite_ipsec_gw_cryptodev_func.py
> @@ -35,7 +35,7 @@ import binascii
> import time
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +import packet
>
> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms,
> modes
> from cryptography.hazmat.primitives.ciphers.aead import AESCCM,
> AESGCM
> @@ -723,7 +723,7 @@ class TestIPsecGW(TestCase):
> self.logger.info("IPsec-gw cmd: " + cmd_str)
> self.dut.send_expect(cmd_str, "IPSEC:", 30)
> time.sleep(3)
> - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=25)
> + inst = self.tester.tcpdump_sniff_packets(self.rx_interface)
>
> PACKET_COUNT = 65
> payload = 256 * ['11']
> @@ -735,7 +735,7 @@ class TestIPsecGW(TestCase):
> expected_src_ip = case_cfgs["expected_src_ip"]
> expected_spi = case_cfgs["expected_spi"]
>
> - pkt = Packet()
> + pkt = packet.Packet()
> if len(dst_ip)<=15:
> pkt.assign_layers(["ether", "ipv4", "udp", "raw"])
> pkt.config_layer("ether", {"src": "52:00:00:00:00:00", "dst":
> "52:00:00:00:00:01"})
> @@ -746,38 +746,37 @@ class TestIPsecGW(TestCase):
> pkt.config_layer("ipv6", {"src": src_ip, "dst": dst_ip})
> pkt.config_layer("udp", {"dst": 0})
> pkt.config_layer("raw", {"payload": payload})
> - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
> + pkt.send_pkt(crb=self.tester, tx_port=self.tx_interface,
> count=PACKET_COUNT)
>
> pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
>
> - pcap_filename = "output/{0}.pcap".format(self.pcap_filename)
> - self.logger.info("Save pkts to {0}".format(pcap_filename))
> - save_packets(pkt_rec, pcap_filename)
> + pcap_filename = "{0}.pcap".format(self.pcap_filename)
> + self.logger.info("Save pkts to {0}".format(packet.TMP_PATH +
> pcap_filename))
> + pkt_rec.save_pcapfile(self.tester, pcap_filename)
> self._pcap_idx = self._pcap_idx + 1
>
> if len(pkt_rec) == 0:
> self.logger.error("IPsec forwarding failed")
> result = False
> -
> - for pkt_r in pkt_rec:
> - pkt_src_ip = pkt_r.pktgen.strip_layer3("src")
> + for i in range(len(pkt_rec)):
> + pkt_src_ip = pkt_rec.pktgen.strip_layer3("src", p_index=i)
> if pkt_src_ip != expected_src_ip:
> - pkt_r.pktgen.pkt.show()
> + pkt_rec[i].show()
> self.logger.error("SRC IP does not match. Pkt:{0},
> Expected:{1}".format(
> pkt_src_ip, expected_src_ip))
> result = False
> break
>
> - pkt_dst_ip = pkt_r.pktgen.strip_layer3("dst")
> + pkt_dst_ip = pkt_rec.pktgen.strip_layer3("dst", p_index=i)
> self.logger.debug(pkt_dst_ip)
> if pkt_dst_ip != expected_dst_ip:
> - pkt_r.pktgen.pkt.show()
> + pkt_rec[i].show()
> self.logger.error("DST IP does not match. Pkt:{0},
> Expected:{1}".format(
> pkt_dst_ip, expected_dst_ip))
> result = False
> break
>
> - packet_hex = pkt_r.pktgen.pkt["ESP"].getfieldval("data")
> + packet_hex = pkt_rec[i]["ESP"].getfieldval("data")
> if packet_hex is None:
> self.logger.error("NO Payload !")
> result = False
> @@ -785,7 +784,7 @@ class TestIPsecGW(TestCase):
> payload_str = binascii.b2a_hex(packet_hex)
> self.logger.debug(payload_str)
>
> - pkt_spi = hex(pkt_r.pktgen.pkt["ESP"].getfieldval("spi"))
> + pkt_spi = hex(pkt_rec[i]["ESP"].getfieldval("spi"))
> self.logger.debug(pkt_spi)
> if pkt_spi != expected_spi:
> self.logger.error("SPI does not match. Pkt:{0}, Expected:{1}".format(
> diff --git a/tests/TestSuite_jumboframes.py
> b/tests/TestSuite_jumboframes.py
> index 1b5aab5..a883e3e 100644
> --- a/tests/TestSuite_jumboframes.py
> +++ b/tests/TestSuite_jumboframes.py
> @@ -229,7 +229,7 @@ class TestJumboframes(TestCase):
> """
> Run after each test case.
> """
> - pass
> + self.dut.kill_all()
>
> def tear_down_all(self):
> """
> diff --git a/tests/TestSuite_kernelpf_iavf.py
> b/tests/TestSuite_kernelpf_iavf.py
> index 476b899..4424ae2 100644
> --- a/tests/TestSuite_kernelpf_iavf.py
> +++ b/tests/TestSuite_kernelpf_iavf.py
> @@ -423,7 +423,7 @@ class TestKernelpfIavf(TestCase):
> pkt.config_layer('vlan', {'vlan': vlan})
> pkt.config_layer('ether', {'dst': self.vf_mac})
>
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
> out = self.vm_dut.get_session_output(timeout=2)
>
> return out
> @@ -546,7 +546,7 @@ class TestKernelpfIavf(TestCase):
> pkt = Packet(pkt_type='UDP', pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': self.vf_mac, 'src': self.tester_mac})
> self.vm_testpmd.execute_cmd("clear port stats all")
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> time.sleep(1)
>
> diff --git a/tests/TestSuite_l2fwd_cryptodev_func.py
> b/tests/TestSuite_l2fwd_cryptodev_func.py
> index 7e785dd..e0f0b5b 100644
> --- a/tests/TestSuite_l2fwd_cryptodev_func.py
> +++ b/tests/TestSuite_l2fwd_cryptodev_func.py
> @@ -760,7 +760,6 @@ class TestL2fwdCrypto(TestCase):
> payload = self.__format_hex_to_list(test_vector["input"])
>
> inst = self.tester.tcpdump_sniff_packets(self.rx_interface,
> - timeout=5,
> filters=[{'layer': 'ether',
> 'config': {'dst': '52:00:00:00:00:01'}}])
>
> @@ -770,12 +769,12 @@ class TestL2fwdCrypto(TestCase):
> pkt.config_layer("ether", {"src": "52:00:00:00:00:00",
> "dst":"52:00:00:00:00:01"})
> pkt.config_layer("ipv4", {"src": "192.168.1.1", "dst": "192.168.1.2"})
> pkt.config_layer("raw", {"payload": payload})
> - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
> + pkt.send_pkt(self.tester, tx_port=self.tx_interface,
> count=PACKET_COUNT)
>
> pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
> self.logger.info("Receive pkgs: {}".format(len(pkt_rec)))
> - for pkt_r in pkt_rec:
> - packet_hex = pkt_r.pktgen.pkt["Raw"].getfieldval("load")
> + for i in range(len(pkt_rec)):
> + packet_hex = pkt_rec[i]["Raw"].getfieldval("load")
> if packet_hex == None:
> result = False
> self.logger.info("no payload !")
> @@ -796,9 +795,9 @@ class TestL2fwdCrypto(TestCase):
> hash_length = len(test_vector["output_hash"])/2
> if hash_length != 0:
> if test_vector["auth_algo"] == "null":
> - hash_text =
> binascii.b2a_hex(pkt_r.pktgen.pkt["Raw"].getfieldval("load"))
> + hash_text =
> binascii.b2a_hex(pkt_rec[i]["Raw"].getfieldval("load"))
> else:
> - hash_text =
> binascii.b2a_hex(pkt_r.pktgen.pkt["Padding"].getfieldval("load"))
> + hash_text =
> binascii.b2a_hex(pkt_rec[i]["Padding"].getfieldval("load"))
> if str.lower(hash_text) == str.lower(test_vector["output_hash"]):
> self.logger.info("Hash Matched")
> else:
> diff --git a/tests/TestSuite_l3fwdacl.py b/tests/TestSuite_l3fwdacl.py
> index 9d1c41e..dce37de 100644
> --- a/tests/TestSuite_l3fwdacl.py
> +++ b/tests/TestSuite_l3fwdacl.py
> @@ -38,6 +38,7 @@ import re
> import utils
> import time
> from test_case import TestCase
> +import packet
>
> class TestL3fwdacl(TestCase):
>
> @@ -268,10 +269,10 @@ class TestL3fwdacl(TestCase):
>
> dst_filter = {'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}
> filters = [dst_filter]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5,
> filters=filters)
> -
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (ethernet_str,
> tx_interface))
> - self.tester.scapy_execute()
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters)
> + pkt = packet.Packet()
> + pkt.append_pkt(ethernet_str)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> @@ -298,11 +299,11 @@ class TestL3fwdacl(TestCase):
> ethernet_str = self.create_ipv6_rule_string(rule, "Ether")
>
> fil = [{'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5,
> filters=fil)
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=fil)
> + pkt = packet.Packet()
> + pkt.append_pkt(ethernet_str)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
>
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (ethernet_str,
> tx_interface))
> - self.tester.scapy_execute()
> - time.sleep(3)
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> @@ -316,10 +317,10 @@ class TestL3fwdacl(TestCase):
>
> dst_filter = {'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}
> filters = [dst_filter]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5,
> filters=filters)
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (etherStr,
> tx_interface))
> - self.tester.scapy_execute()
> -
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=filters)
> + pkt = packet.Packet()
> + pkt.append_pkt(etherStr)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> @@ -332,20 +333,20 @@ class TestL3fwdacl(TestCase):
> etherStr = self.create_ipv6_rule_string(rule, "Ether")
>
> fil = [{'layer': 'ether', 'config': {'dst': 'not ff:ff:ff:ff:ff:ff'}}]
> - inst = self.tester.tcpdump_sniff_packets(rx_interface, timeout=5,
> filters=fil)
> -
> - self.tester.scapy_append('sendp([%s],iface="%s")' % (etherStr,
> tx_interface))
> - self.tester.scapy_execute()
> - time.sleep(3)
> + inst = self.tester.tcpdump_sniff_packets(rx_interface, filters=fil)
> + pkt = packet.Packet()
> + pkt.append_pkt(etherStr)
> + pkt.send_pkt(crb=self.tester, tx_port=tx_interface)
>
> out = self.remove_dhcp_from_revpackets(inst)
> return len(out)
>
> def remove_dhcp_from_revpackets(self, inst):
> - pkts = self.tester.load_tcpdump_sniff_packets(inst)
> + p = self.tester.load_tcpdump_sniff_packets(inst)
> + pkts = p.pktgen.pkts
> i = 0
> while len(pkts) != 0 and i <= len(pkts) - 1:
> - if pkts[i].pktgen.pkt.haslayer('DHCP'):
> + if pkts[i].haslayer('DHCP'):
> pkts.remove(pkts[i])
> i = i - 1
> i = i + 1
> diff --git a/tests/TestSuite_link_flowctrl.py b/tests/TestSuite_link_flowctrl.py
> index 4229aa4..ed89162 100644
> --- a/tests/TestSuite_link_flowctrl.py
> +++ b/tests/TestSuite_link_flowctrl.py
> @@ -453,4 +453,5 @@ class TestLinkFlowctrl(TestCase):
> """
> Run after each test case.
> """
> + self.dut.kill_all()
> self.dut.send_expect("quit", "# ")
> diff --git a/tests/TestSuite_link_status_interrupt.py
> b/tests/TestSuite_link_status_interrupt.py
> index 1d7e67e..3208d71 100644
> --- a/tests/TestSuite_link_status_interrupt.py
> +++ b/tests/TestSuite_link_status_interrupt.py
> @@ -175,7 +175,7 @@ class TestLinkStatusInterrupt(TestCase):
> self.txItf = self.tester.get_interface(txport)
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': self.dmac})
> - pkt.send_pkt(tx_port=self.txItf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.txItf, count=num)
>
> def tear_down(self):
> """
> diff --git a/tests/TestSuite_loadbalancer.py
> b/tests/TestSuite_loadbalancer.py
> index 9152c6c..934e291 100644
> --- a/tests/TestSuite_loadbalancer.py
> +++ b/tests/TestSuite_loadbalancer.py
> @@ -90,13 +90,13 @@ class TestLoadbalancer(TestCase):
> for i in range(len(dutPorts)):
> dstport = self.tester.get_local_port(dutPorts[i])
> pkt_count = 10
> - inst =
> self.tester.tcpdump_sniff_packets(intf=self.tester.get_interface(rx_port),
> timeout=10, count=pkt_count)
> + inst =
> self.tester.tcpdump_sniff_packets(intf=self.tester.get_interface(rx_port),
> count=pkt_count)
>
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP', pkt_len=64)
> dst_mac = self.dut.get_mac_address(dutPorts[i])
> - pkt.config_layer('ether', {'dst': dst_mac})
> - pkt.config_layer('ipv4', {'src': "0.0.0.1", 'dst': trafficFlow[flow][1]})
> - pkt.send_pkt(tx_port=self.tester.get_interface(dstport), count=10)
> + pkt.config_layer('ether', {'dst': '%s' % dst_mac})
> + pkt.config_layer('ipv4', {'src': "0.0.0.1", 'dst': '%s' %
> (trafficFlow[flow][1])})
> + pkt.send_pkt(self.tester, tx_port=self.tester.get_interface(dstport),
> count=10)
> # Wait for the sniffer to finish.
> time.sleep(5)
>
> @@ -104,8 +104,8 @@ class TestLoadbalancer(TestCase):
> len_pkts = len(pkts)
>
> self.verify(len_pkts == pkt_count, "Packet number is wrong")
> - for packet in pkts:
> - result = str(packet.pktgen.pkt.show)
> + for i in range(len_pkts):
> + result = str(pkts[i].show)
> self.verify("Ether" in result, "No packet received")
> self.verify("src=0.0.0.1" + " dst=" + trafficFlow[flow][1] in result,
> "Wrong IP address")
> self.verify("dst=%s" % dst_mac in result, "No packet received or
> packet missed")
> diff --git a/tests/TestSuite_mac_filter.py b/tests/TestSuite_mac_filter.py
> index 7b5eb43..19d250b 100644
> --- a/tests/TestSuite_mac_filter.py
> +++ b/tests/TestSuite_mac_filter.py
> @@ -88,7 +88,7 @@ class TestMacFilter(TestCase):
> itf = self.tester.get_interface(self.tester.get_local_port(portid))
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'src': '52:00:00:00:00:00', 'dst': destMac})
> - pkt.send_pkt(tx_port=itf, count=4)
> + pkt.send_pkt(self.tester, tx_port=itf, count=4)
>
> def test_add_remove_mac_address(self):
> """
> diff --git a/tests/TestSuite_netmap_compat.py
> b/tests/TestSuite_netmap_compat.py
> index 2f8171c..a7a97ca 100644
> --- a/tests/TestSuite_netmap_compat.py
> +++ b/tests/TestSuite_netmap_compat.py
> @@ -114,9 +114,9 @@ class TestNetmapCompat(TestCase):
>
> def get_tcpdump_package(self):
> pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
> - dsts = []
> - for packet in pkts:
> - dst = packet.strip_element_layer2("dst")
> + dsts = []
> + for i in range(len(pkts)):
> + dst = pkts.strip_element_layer2("dst", p_index=i)
> dsts.append(dst)
> return dsts
>
> diff --git a/tests/TestSuite_packet_capture.py
> b/tests/TestSuite_packet_capture.py
> index 6e5b98f..fdaa0d0 100644
> --- a/tests/TestSuite_packet_capture.py
> +++ b/tests/TestSuite_packet_capture.py
> @@ -39,8 +39,6 @@ import time
> import re
> import signal
> import subprocess
> -import shutil
> -import socket
> from pprint import pformat
>
> from scapy.utils import rdpcap
> @@ -188,37 +186,19 @@ class parsePacket(object):
>
> class TestPacketCapture(TestCase):
>
> - def get_dts_node_ip(self):
> - ip_addr = None
> - try:
> - socket_inst = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> - socket_inst.connect(('8.8.8.8', 80))
> - ip_addr = socket_inst.getsockname()[0]
> - except Exception as e:
> - msg = "Can't get dts running node ip address"
> - self.logger.warning(msg)
> - return ip_addr
> - return ip_addr
> -
> - @property
> - def is_dts_on_tester(self):
> - if not self.dts_ip:
> - return False
> - # get tester ip to check if dts run on tester
> - tester_ip = self.tester.get_ip_address()
> - return self.dts_ip == tester_ip
> -
> - @property
> - def is_dts_on_dut(self):
> - if not self.dts_ip:
> - return False
> - # get dut ip to check if dts run on dut
> - dut_ip = self.dut.get_ip_address()
> - return self.dts_ip == dut_ip
> + def is_existed_on_crb(self, check_path, crb='dut'):
> + alt_session = self.dut.alt_session \
> + if crb == 'dut' else \
> + self.tester.alt_session
> + alt_session.send_expect("ls %s" % check_path, "# ")
> + cmd = "echo $?"
> + output = alt_session.send_expect(cmd, "# ")
> + ret = True if output and output.strip() == "0" else False
> + return ret
>
> @property
> def is_dut_on_tester(self):
> - # get dut/tester ip to check if they are in one platform
> + # get dut/tester ip to check if they are in a platform
> tester_ip = self.tester.get_ip_address()
> dut_ip = self.dut.get_ip_address()
> return tester_ip == dut_ip
> @@ -231,42 +211,6 @@ class TestPacketCapture(TestCase):
> self.dut.base_dir
> return target_dir
>
> - def __create_log_dir(self, log_dir):
> - # create a log directory on dts running node
> - if not os.path.exists(log_dir):
> - os.makedirs(log_dir)
> - # create a log directory on dut node
> - if not self.is_dts_on_dut and \
> - not self.is_existed_on_crb(log_dir):
> - cmd = "mkdir -p {0}".format(log_dir)
> - self.dut.alt_session.send_expect(cmd, "# ")
> - # create a log directory on tester node
> - if not self.is_dts_on_tester and \
> - not self.is_existed_on_crb(log_dir, crb='tester'):
> - cmd = "mkdir -p {0}".format(log_dir)
> - self.tester.alt_session.send_expect(cmd, "# ")
> -
> - def __clear_log_dir(self, log_dir):
> - if os.path.exists(log_dir):
> - shutil.rmtree(log_dir)
> - os.makedirs(log_dir)
> - if not self.is_dts_on_dut:
> - self.dut.alt_session.send_expect(
> - "rm -fr {0}/*".format(log_dir), "# ", 10)
> - if not self.is_dts_on_tester:
> - self.tester.alt_session.send_expect(
> - "rm -fr {0}/*".format(log_dir), "# ", 10)
> -
> - def is_existed_on_crb(self, check_path, crb='dut'):
> - alt_session = self.dut.alt_session \
> - if crb == 'dut' else \
> - self.tester.alt_session
> - alt_session.send_expect("ls %s > /dev/null 2>&1" % check_path, "# ")
> - cmd = "echo $?"
> - output = alt_session.send_expect(cmd, "# ")
> - ret = True if output and output.strip() == "0" else False
> - return ret
> -
> def get_dut_iface_with_kernel_driver(self):
> # only physical nic support PROMISC
> cmd = "ip link show | grep BROADCAST,MULTICAST | awk {'print $2'}"
> @@ -500,6 +444,11 @@ class TestPacketCapture(TestCase):
> time.sleep(4)
>
> def start_testpmd(self):
> + self.dut.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 10)
> + if not self.is_dut_on_tester:
> + self.tester.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 10)
> param_opt = "--port-topology=chained"
> eal_param = '--file-prefix=test'
> self.testpmd.start_testpmd("Default", param=param_opt,
> @@ -516,14 +465,23 @@ class TestPacketCapture(TestCase):
> def start_tcpdump_iface(self, option):
> if option["rx"][0] is not None and option["tx"][0] is not None and \
> option["rx"][0] == option["tx"][0]:
> + if self.is_existed_on_crb(self.rxtx_pcap):
> + self.dut.alt_session.send_expect(
> + "rm -f %s" % self.rxtx_pcap, "# ")
> cmd = self.tcpdump.format(self.rxtx_iface, self.rxtx_pcap)
> self.session_ex.send_expect(cmd, "# ")
> else:
> if option["rx"][0] is not None:
> + if self.is_existed_on_crb(self.rx_pcap):
> + self.dut.alt_session.send_expect(
> + "rm -f %s" % self.rx_pcap, "# ")
> cmd = self.tcpdump.format(self.rx_iface, self.rx_pcap)
> self.session_ex.send_expect(cmd, "# ")
>
> if option["tx"][0] is not None:
> + if self.is_existed_on_crb(self.tx_pcap):
> + self.dut.alt_session.send_expect(
> + "rm -f %s" % self.tx_pcap, "# ")
> cmd = self.tcpdump.format(self.tx_iface, self.tx_pcap)
> self.session_ex.send_expect(cmd, "# ")
> time.sleep(4)
> @@ -537,6 +495,11 @@ class TestPacketCapture(TestCase):
> msg = ('pdump option string length should be less than {}'
> ).format(length_limit)
> self.verify(len(option) < length_limit, msg)
> + self.dut.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 20)
> + if not self.is_dut_on_tester:
> + self.tester.alt_session.send_expect(
> + "rm -fr {0}/*".format(self.pdump_log), "# ", 20)
> cmd = ';'.join([
> "cd %s" % self.target_dir,
> self.dpdk_pdump + " '%s' >/dev/null 2>&1 &" % (option[0])])
> @@ -572,13 +535,18 @@ class TestPacketCapture(TestCase):
> # check send tx packet by port 0
> # send packet to dut and compare dpdk-pdump dump pcap with
> # scapy pcap file
> - if self.is_dts_on_tester:
> - intf = self.tester.get_interface(self.tester.get_local_port(port_1))
> - # prepare to catch replay packet in out port
> - recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> - if os.path.exists(recPkt):
> - os.remove(recPkt)
> - index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt)
> + intf = self.tester.get_interface(self.tester.get_local_port(port_1))
> + # prepare to catch replay packet in out port
> + recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> + if os.path.exists(recPkt):
> + os.remove(recPkt)
> + if pkt_type == 'LLDP':
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1,
> lldp_forbid=False)
> + else:
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1)
> + filename = '{}sniff_{}.pcap'.format(self.tester.tmp_file, intf)
> + self.tester.session.copy_file_from(filename, recPkt)
> + # index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt)
> pkt = Packet(pkt_type=pkt_type)
> if pkt_type == 'VLAN_UDP':
> pkt.config_layer('dot1q', {'vlan': 20})
> @@ -588,33 +556,34 @@ class TestPacketCapture(TestCase):
> refPkt = self.send_pcap % (pkt_type, "rx", number)
> if os.path.exists(refPkt):
> os.remove(refPkt)
> - pkt.pktgen.write_pcap(refPkt)
> +
> + pkt.save_pcapfile(filename=refPkt)
> # send out test packet
> tester_port = self.tester.get_local_port(port_0)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(
> - crb= None if self.is_dts_on_tester else self.tester,
> - tx_port=intf)
> + pkt.send_pkt(self.tester, tx_port=intf)
> # load pcap file caught by out port
> time.sleep(1)
> - # when dts doesn't run on tester, ignore this testing content
> - if self.is_dts_on_tester:
> - load_sniff_packets(index)
> - # compare pcap file received by out port with scapy reference
> - # packet pcap file
> - warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> - msg = "tcpdump rx Receive Packet error: {0}".format(warning)
> - self.verify(not warning, msg)
> + pkts = self.tester.load_tcpdump_sniff_packets(index)
> + pkts.save_pcapfile(filename=recPkt)
> + # load_sniff_packets(index)
> + # compare pcap file received by out port with scapy reference
> + # packet pcap file
> + warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> + msg = "tcpdump rx Receive Packet error: {0}".format(warning)
> + self.verify(not warning, msg)
> # check send tx packet by port 1
> # send packet to dut and compare dpdk-pdump dump pcap
> # with scapy pcap file
> - if self.is_dts_on_tester:
> - intf = self.tester.get_interface(self.tester.get_local_port(port_0))
> - # prepare to catch replay packet in out port
> - recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> - if os.path.exists(recPkt):
> - os.remove(recPkt)
> - index = sniff_packets(intf, count=1, timeout=20, pcap=recPkt)
> + intf = self.tester.get_interface(self.tester.get_local_port(port_0))
> + # prepare to catch replay packet in out port
> + recPkt = os.path.join('/tmp', "sniff_%s.pcap" % intf)
> + if os.path.exists(recPkt):
> + os.remove(recPkt)
> + if pkt_type == 'LLDP':
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1,
> lldp_forbid=False)
> + else:
> + index = self.tester.tcpdump_sniff_packets(intf=intf, count=1)
> pkt = Packet(pkt_type=pkt_type)
> if pkt_type == 'VLAN_UDP':
> pkt.config_layer('dot1q', {'vlan': 20})
> @@ -624,23 +593,21 @@ class TestPacketCapture(TestCase):
> refPkt = self.send_pcap % (pkt_type, "tx", number)
> if os.path.exists(refPkt):
> os.remove(refPkt)
> - pkt.pktgen.write_pcap(refPkt)
> + pkt.save_pcapfile(filename=refPkt)
> + # pkt.pktgen.write_pcap(refPkt)
> # send out test packet
> tester_port = self.tester.get_local_port(port_1)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(
> - crb= None if self.is_dts_on_tester else self.tester,
> - tx_port=intf)
> + pkt.send_pkt(self.tester, tx_port=intf)
> # load pcap file caught by out port
> time.sleep(1)
> - # when dts doesn't run on tester, ignore this testing content
> - if self.is_dts_on_tester:
> - load_sniff_packets(index)
> - # compare pcap file received by out port
> - # with scapy reference packet pcap file
> - warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> - msg = "tcpdump tx Receive Packet error: {0}".format(warning)
> - self.verify(not warning, msg)
> + pkts = self.tester.load_tcpdump_sniff_packets(index)
> + pkts.save_pcapfile(filename=recPkt)
> + # compare pcap file received by out port
> + # with scapy reference packet pcap file
> + warning = self.compare_pkts(refPkt, recPkt, pkt_type)
> + msg = "tcpdump tx Receive Packet error: {0}".format(warning)
> + self.verify(not warning, msg)
>
> def check_pdump_pcaps(self, pkt_type, number, **kwargs):
> rx_dump_pcap = kwargs["rx"][0]
> @@ -686,23 +653,8 @@ class TestPacketCapture(TestCase):
> msg = "pdump tx {0} packet content is correct".format(pkt_type)
> self.logger.info(msg)
>
> - def sync_dut_dump_file(self):
> - if self.is_dts_on_dut:
> - return
> - # copy rx pdump data from dut
> - if os.path.exists(self.rx_pcap):
> - os.remove(self.rx_pcap)
> - if self.is_existed_on_crb(self.rx_pcap):
> - self.dut.session.copy_file_from(self.rx_pcap, self.rx_pcap)
> - # copy tx pdump data from dut
> - if os.path.exists(self.tx_pcap):
> - os.remove(self.tx_pcap)
> - if self.is_existed_on_crb(self.tx_pcap):
> - self.dut.session.copy_file_from(self.tx_pcap, self.tx_pcap)
> -
> def packet_capture_test_packets(self, option):
> self.clear_ASLR()
> - self.__clear_log_dir(self.pdump_log)
> self.start_testpmd()
> self.start_dpdk_pdump(option)
> if self.dev_iface_flag:
> @@ -713,7 +665,17 @@ class TestPacketCapture(TestCase):
> time.sleep(2)
> if self.dev_iface_flag:
> self.stop_tcpdump_iface()
> - self.sync_dut_dump_file()
> + if not self.is_dut_on_tester:
> + # copy rx pdump data from dut
> + if self.is_existed_on_crb(self.rx_pcap):
> + if os.path.exists(self.rx_pcap):
> + os.remove(self.rx_pcap)
> + self.dut.session.copy_file_from(self.rx_pcap, self.rx_pcap)
> + # copy tx pdump data from dut
> + if self.is_existed_on_crb(self.tx_pcap):
> + if os.path.exists(self.tx_pcap):
> + os.remove(self.tx_pcap)
> + self.dut.session.copy_file_from(self.tx_pcap, self.tx_pcap)
> self.stop_dpdk_pdump()
> self.stop_testpmd()
> self.reset_ASLR()
> @@ -838,8 +800,6 @@ class TestPacketCapture(TestCase):
> '''
> Run at the start of each test suite.
> '''
> - # get dts running node ip address
> - self.dts_ip = self.get_dts_node_ip()
> self.verify(self.target == "x86_64-native-linuxapp-gcc",
> "only support x86_64-native-linuxapp-gcc")
> self.dut_ports = self.dut.get_ports()
> @@ -851,7 +811,13 @@ class TestPacketCapture(TestCase):
> self.dut_skip_compile = self.dut.skip_setup
> # used for save log
> self.pdump_log = os.sep.join(["/tmp", 'pdumpLog'])
> - self.__create_log_dir(self.pdump_log)
> + if not self.is_existed_on_crb(self.pdump_log):
> + cmd = "mkdir -p {0}".format(self.pdump_log)
> + self.dut.alt_session.send_expect(cmd, "# ")
> + if not self.is_dut_on_tester and \
> + not self.is_existed_on_crb(self.pdump_log, crb='tester'):
> + cmd = "mkdir -p {0}".format(self.pdump_log)
> + self.tester.alt_session.send_expect(cmd, "# ")
> self.pcap_SW = "CONFIG_RTE_LIBRTE_PMD_PCAP"
> self.SW_file = os.path.join(self.target_dir, 'config/common_base')
> if not (self.dut_skip_compile and self.check_pcap_lib()):
> @@ -861,19 +827,17 @@ class TestPacketCapture(TestCase):
> self.dut.skip_setup = False
> self.dut.build_install_dpdk(self.target)
> # secondary process (dpdk-pdump)
> - self.pdump_dir = os.sep.join([
> - self.target_dir,
> - "%s/build/app/pdump/" % self.target])
> + self.pdump_dir = self.target_dir + os.sep + \
> + "%s/build/app/pdump/" % self.target
> cmd = "ls {0} -F | grep '*'".format(self.pdump_dir)
> exe_files = self.dut.alt_session.send_expect(cmd, "# ").splitlines()
> if len(exe_files) == 1:
> self.tool_name = exe_files[0][:-1]
> else:
> self.verify(False, "tool name exception !")
> - self.dut_dpdk_pdump_dir = os.sep.join([
> - self.target_dir,
> - "%s/app/%s" % (self.target, self.tool_name)])
> self.session_ex = self.dut.new_session(self.tool_name)
> + self.dut_dpdk_pdump_dir = self.target_dir + os.sep + \
> + "%s/app/%s" % (self.target, self.tool_name)
> self.dpdk_pdump = self.dut_dpdk_pdump_dir + \
> " -v --file-prefix=test -- --pdump "
> self.send_pcap = os.sep.join([self.pdump_log,
> "scapy_%s_%s_%d.pcap"])
> diff --git a/tests/TestSuite_ptype_mapping.py
> b/tests/TestSuite_ptype_mapping.py
> index b0dc70a..b352724 100644
> --- a/tests/TestSuite_ptype_mapping.py
> +++ b/tests/TestSuite_ptype_mapping.py
> @@ -85,7 +85,7 @@ class TestPtype_Mapping(TestCase):
> else:
> pkt_names = pkt_types[pkt_type]
> pkt = Packet(pkt_type=pkt_type)
> - pkt.send_pkt(tx_port=self.tester_iface,count=4)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface,count=4)
> out = self.dut.get_session_output(timeout=2)
> if sw_ptype != None:
> self.verify(sw_ptype in out,
> diff --git a/tests/TestSuite_pvp_multi_paths_performance.py
> b/tests/TestSuite_pvp_multi_paths_performance.py
> index b633b98..65c785a 100644
> --- a/tests/TestSuite_pvp_multi_paths_performance.py
> +++ b/tests/TestSuite_pvp_multi_paths_performance.py
> @@ -36,7 +36,7 @@ Test PVP performance using virtio_user on 8 tx/rx path.
>
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -98,7 +98,7 @@ class TestPVPMultiPathPerformance(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % destination_mac})
> - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port))
> + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" %
> (self.out_path, port))
> tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" %
> (self.out_path, port)))
>
> self.tester.pktgen.clear_streams()
> diff --git
> a/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> b/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> index fcaadf2..29d87c2 100644
> --- a/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> +++ b/tests/TestSuite_pvp_multi_paths_vhost_single_core_performance.py
> @@ -36,7 +36,7 @@ Test PVP vhost single core performance using
> virtio_user on 8 tx/rx path.
>
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -95,7 +95,7 @@ class TestPVPMultiPathVhostPerformance(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % destination_mac})
> - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port))
> + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" %
> (self.out_path, port))
> tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" %
> (self.out_path, port)))
>
> self.tester.pktgen.clear_streams()
> diff --git
> a/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> b/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> index 6cd3a6d..e8807a7 100644
> --- a/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> +++ b/tests/TestSuite_pvp_multi_paths_virtio_single_core_performance.py
> @@ -36,7 +36,7 @@ Test PVP virtio single core performance using
> virtio_user on 8 tx/rx path.
>
> import utils
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -98,7 +98,7 @@ class TestPVPMultiPathVirtioPerformance(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % destination_mac})
> - save_packets([pkt], "%s/multi_path_%d.pcap" % (self.out_path, port))
> + pkt.save_pcapfile(self.tester, "%s/multi_path_%d.pcap" %
> (self.out_path, port))
>
> tgen_input.append((tx_port, rx_port, "%s/multi_path_%d.pcap" %
> (self.out_path, port)))
>
> diff --git a/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> b/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> index 0095ce2..ea2e1cd 100644
> --- a/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> +++ b/tests/TestSuite_pvp_qemu_multi_paths_port_restart.py
> @@ -43,7 +43,7 @@ import time
> import re
> from virt_common import VM
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -72,7 +72,6 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> self.tester.send_expect('mkdir -p %s' % self.out_path, '# ')
> # create an instance to set stream field setting
> self.pktgen_helper = PacketGeneratorHelper()
> - self.base_dir = self.dut.base_dir.replace('~', '/root')
>
> def set_up(self):
> """
> @@ -94,14 +93,14 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> start testpmd on vhost
> """
> self.dut.send_expect("killall -s INT testpmd", "#")
> - self.dut.send_expect("rm -rf %s/vhost-net*" % self.base_dir, "#")
> + self.dut.send_expect("rm -rf ./vhost-net*", "#")
> command_client = self.dut.target + "/app/testpmd " + \
> " -n %d -c %s --socket-mem 1024,1024 " + \
> " --legacy-mem --file-prefix=vhost " + \
> - " --vdev 'net_vhost0,iface=%s/vhost-net,queues=1' " + \
> + " --vdev 'net_vhost0,iface=vhost-net,queues=1' " + \
> " -- -i --nb-cores=1 --txd=1024 --rxd=1024"
> command_line_client = command_client % (
> - self.dut.get_memory_channels(), self.core_mask, self.base_dir)
> + self.dut.get_memory_channels(), self.core_mask)
> self.vhost.send_expect(command_line_client, "testpmd> ", 120)
> self.vhost.send_expect("set fwd mac", "testpmd> ", 120)
> self.vhost.send_expect("start", "testpmd> ", 120)
> @@ -134,7 +133,7 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> self.vm = VM(self.dut, 'vm0', 'vhost_sample')
> vm_params = {}
> vm_params['driver'] = 'vhost-user'
> - vm_params['opt_path'] = '%s/vhost-net' % self.base_dir
> + vm_params['opt_path'] = './vhost-net'
> vm_params['opt_mac'] = self.virtio1_mac
> if modem == 1 and mergeable == 0:
> vm_params['opt_settings'] = "disable-
> modern=false,mrg_rxbuf=off,rx_queue_size=1024,tx_queue_size=1024"
> @@ -206,7 +205,7 @@ class TestPVPQemuMultiPathPortRestart(TestCase):
> """
> pkt = Packet(pkt_type='IP_RAW', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/pvp_multipath.pcap" % (self.out_path))
> + pkt.save_pcapfile(self.tester, "%s/pvp_multipath.pcap" %
> (self.out_path))
>
> tgenInput = []
> port = self.tester.get_local_port(self.dut_ports[0])
> diff --git a/tests/TestSuite_pvp_vhost_user_reconnect.py
> b/tests/TestSuite_pvp_vhost_user_reconnect.py
> index c5c7b96..16a93b0 100644
> --- a/tests/TestSuite_pvp_vhost_user_reconnect.py
> +++ b/tests/TestSuite_pvp_vhost_user_reconnect.py
> @@ -41,7 +41,7 @@ import utils
> import time
> from test_case import TestCase
> from virt_common import VM
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -83,7 +83,6 @@ class TestPVPVhostUserReconnect(TestCase):
> self.tester.send_expect('mkdir -p %s' % self.out_path, '# ')
> # create an instance to set stream field setting
> self.pktgen_helper = PacketGeneratorHelper()
> - self.base_dir = self.dut.base_dir.replace('~', '/root')
>
> def set_up(self):
> """
> @@ -92,7 +91,7 @@ class TestPVPVhostUserReconnect(TestCase):
> """
> self.dut.send_expect("killall -s INT testpmd", "# ")
> self.dut.send_expect("killall -s INT qemu-system-x86_64", "# ")
> - self.dut.send_expect("rm -rf %s/vhost-net*" % self.base_dir, "# ")
> + self.dut.send_expect("rm -rf ./vhost-net*", "# ")
> self.vhost_user = self.dut.new_session(suite="vhost-user")
>
> def launch_testpmd_as_vhost_user(self):
> @@ -101,7 +100,7 @@ class TestPVPVhostUserReconnect(TestCase):
> """
> vdev_info = ""
> for i in range(self.vm_num):
> - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-
> net%d,client=1,queues=1' " % (i, self.base_dir, i)
> + vdev_info += "--vdev 'net_vhost%d,iface=vhost-
> net%d,client=1,queues=1' " % (i, i)
> self.vhostapp_testcmd = self.dut.base_dir + \
> "/%s/app/testpmd -c %s -n %d --socket-mem %s --legacy-mem" +
> \
> " --file-prefix=vhost %s" + \
> @@ -120,7 +119,7 @@ class TestPVPVhostUserReconnect(TestCase):
> """
> vdev_info = ""
> for i in range(self.vm_num):
> - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-
> net%d,client=1,queues=1' " % (i, self.base_dir, i)
> + vdev_info += "--vdev 'net_vhost%d,iface=vhost-
> net%d,client=1,queues=1' " % (i, i)
> self.vhostapp_testcmd = self.dut.base_dir + \
> "/%s/app/testpmd -c %s -n %d --socket-mem %s --legacy-mem" +
> \
> " --no-pci --file-prefix=vhost %s" + \
> @@ -181,7 +180,7 @@ class TestPVPVhostUserReconnect(TestCase):
> vm_info = VM(self.dut, 'vm%d' % i, 'vhost_sample')
> vm_params = {}
> vm_params['driver'] = 'vhost-user'
> - vm_params['opt_path'] = '%s/vhost-net%d' % (self.base_dir, i)
> + vm_params['opt_path'] = './vhost-net%d' % (i)
> vm_params['opt_mac'] = '52:54:00:00:00:0%d' % (i+1)
> vm_params['opt_server'] = 'server'
> vm_params['opt_settings'] =
> 'mrg_rxbuf=on,rx_queue_size=1024,tx_queue_size=1024'
> @@ -273,7 +272,7 @@ class TestPVPVhostUserReconnect(TestCase):
> pkt = Packet(pkt_type = 'UDP', pkt_len = frame_size)
> pkt.config_layers([('ether', {'dst': '%s' % self.dst_mac}),
> ('ipv4', {'dst': '%s' % self.dst1, 'src': '%s' % self.src1})])
> - save_packets([pkt], "%s/reconnect.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/reconnect.pcap" % self.out_path)
>
> tgenInput = []
> port = self.tester.get_local_port(self.pf)
> diff --git a/tests/TestSuite_pvp_virtio_bonding.py
> b/tests/TestSuite_pvp_virtio_bonding.py
> index 4fb94f2..874c058 100644
> --- a/tests/TestSuite_pvp_virtio_bonding.py
> +++ b/tests/TestSuite_pvp_virtio_bonding.py
> @@ -40,7 +40,7 @@ import utils
> from test_case import TestCase
> from virt_common import VM
> from pmd_output import PmdOutput
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -69,7 +69,6 @@ class TestPVPVirtIOBonding(TestCase):
> self.tester.send_expect('mkdir -p %s' % self.out_path, '# ')
> # create an instance to set stream field setting
> self.pktgen_helper = PacketGeneratorHelper()
> - self.base_dir = self.dut.base_dir.replace('~', '/root')
>
> def set_up(self):
> """
> @@ -87,7 +86,7 @@ class TestPVPVirtIOBonding(TestCase):
> """
> vdev_info = ""
> for i in range(self.queues):
> - vdev_info += "--vdev 'net_vhost%d,iface=%s/vhost-
> net%d,client=1,queues=1' " % (i, self.base_dir, i)
> + vdev_info += "--vdev 'net_vhost%d,iface=vhost-
> net%d,client=1,queues=1' " % (i, i)
> params = "--port-topology=chained --nb-cores=4 --txd=1024 --rxd=1024"
> eal_param = "--socket-mem 2048,2048 --legacy-mem --file-
> prefix=vhost %s " % vdev_info
> self.vhost_testpmd = PmdOutput(self.dut)
> @@ -168,7 +167,7 @@ class TestPVPVirtIOBonding(TestCase):
> tx_port = self.tester.get_local_port(self.dut_ports[0])
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/bonding.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/bonding.pcap" % self.out_path)
> tgen_input.append((tx_port, rx_port, "%s/bonding.pcap" %
> self.out_path))
> self.tester.pktgen.clear_streams()
> streams = self.pktgen_helper.prepare_stream_from_tginput(tgen_input,
> 100, None, self.tester.pktgen)
> @@ -196,7 +195,7 @@ class TestPVPVirtIOBonding(TestCase):
> for i in range(self.queues):
> vm_params['opt_server'] = 'server'
> vm_params['driver'] = 'vhost-user'
> - vm_params['opt_path'] = '%s/vhost-net%d' % (self.base_dir, i)
> + vm_params['opt_path'] = './vhost-net%d' % i
> vm_params['opt_mac'] = "%s%d" % (virtio_mac, i+1)
> self.vm.set_vm_device(**vm_params)
> self.set_vm_vcpu()
> diff --git a/tests/TestSuite_pvp_virtio_user_4k_pages.py
> b/tests/TestSuite_pvp_virtio_user_4k_pages.py
> index d2b8df7..95b5494 100644
> --- a/tests/TestSuite_pvp_virtio_user_4k_pages.py
> +++ b/tests/TestSuite_pvp_virtio_user_4k_pages.py
> @@ -37,7 +37,7 @@ vhost/virtio-user pvp with 4K pages.
> import utils
> import time
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -108,7 +108,7 @@ class TestPvpVirtioUser4kPages(TestCase):
> tx_port = self.tester.get_local_port(self.dut_ports[0])
> pkt = Packet(pkt_type='UDP', pkt_len=frame_size)
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/vhost.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/vhost.pcap" % self.out_path)
> tgen_input.append((tx_port, rx_port, "%s/vhost.pcap" %
> self.out_path))
>
> self.tester.pktgen.clear_streams()
> @@ -138,7 +138,6 @@ class TestPvpVirtioUser4kPages(TestCase):
> command_line_client = command_line_client % (self.target,
> self.core_mask_vhost_user, self.mem_channels,
> self.ports_socket)
> self.vhost_user.send_expect(command_line_client, "testpmd> ", 120)
> - self.vhost_user.send_expect("set fwd mac", "testpmd> ", 120)
> self.vhost_user.send_expect("start", "testpmd> ", 120)
>
> def start_testpmd_as_virtio(self):
> diff --git a/tests/TestSuite_queue_region.py
> b/tests/TestSuite_queue_region.py
> index a4d9bf7..eea873e 100644
> --- a/tests/TestSuite_queue_region.py
> +++ b/tests/TestSuite_queue_region.py
> @@ -148,7 +148,7 @@ class TestQueue_region(TestCase):
> pkt = Packet()
> pkt.assign_layers(['ether', 'raw'])
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac, 'type':
> ethertype})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> def send_packet_up(self, mac, pkt_type="udp", prio=0):
> """
> @@ -173,7 +173,7 @@ class TestQueue_region(TestCase):
> pkt.assign_layers(['ether', 'vlan', 'ipv6', 'udp', 'raw'])
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> pkt.config_layer('vlan', {'vlan': 0, 'prio': prio})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> def get_and_compare_rules(self, out, QueueRegion_num, FlowType_num,
> UP_num):
> """
> diff --git a/tests/TestSuite_queue_start_stop.py
> b/tests/TestSuite_queue_start_stop.py
> index e91ea91..48f9c1a 100644
> --- a/tests/TestSuite_queue_start_stop.py
> +++ b/tests/TestSuite_queue_start_stop.py
> @@ -101,11 +101,11 @@ class TestQueueStartStop(TestCase):
> pkt = Packet(pkt_type="UDP", pkt_len=pktSize)
> inst = self.tester.tcpdump_sniff_packets(rxitf)
> pkt.config_layer('ether', {'dst': dmac})
> - pkt.send_pkt(tx_port=txitf, count=4)
> + pkt.send_pkt(self.tester, tx_port=txitf, count=4)
> sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
>
> if received:
> - res = strip_pktload(sniff_pkts[0], layer="L4")
> + res = strip_pktload(sniff_pkts, layer="L4")
> self.verify("58 58 58 58 58 58 58 58" in res, "receive queue not work as
> expected")
> else:
> self.verify(len(sniff_pkts) == 0, "stop queue not work as expected")
> diff --git a/tests/TestSuite_quota_watermark.py
> b/tests/TestSuite_quota_watermark.py
> index ad4ec3b..0541eef 100644
> --- a/tests/TestSuite_quota_watermark.py
> +++ b/tests/TestSuite_quota_watermark.py
> @@ -310,7 +310,7 @@ class TestQuotaWatermark(TestCase,
> IxiaPacketGenerator):
> rx_intf = self.tester.get_interface(rev_port)
> tx_intf = self.tester.get_interface(send_port)
> # send and sniff packet
> - rx_inst = self.tester.tcpdump_sniff_packets(rx_intf, timeout=5)
> + rx_inst = self.tester.tcpdump_sniff_packets(rx_intf)
> self.send_pcap_pkt_by_scapy(self.tester, tgen_input[0][2], tx_intf)
> pkts = self.tester.load_tcpdump_sniff_packets(rx_inst)
> self.verify(len(pkts) == pkt_cnt, "Packet not forwarded as expected")
> diff --git a/tests/TestSuite_runtime_vf_queue_number.py
> b/tests/TestSuite_runtime_vf_queue_number.py
> index 63a5e18..227d815 100644
> --- a/tests/TestSuite_runtime_vf_queue_number.py
> +++ b/tests/TestSuite_runtime_vf_queue_number.py
> @@ -39,6 +39,7 @@ import re
> from qemu_kvm import QEMUKvm
> from test_case import TestCase
> from pmd_output import PmdOutput
> +from packet import Packet
>
> RSS_KEY =
> '6EA6A420D5138E712433B813AE45B3C4BECB2B405F31AD6C331835372D15E
> 2D5E49566EE0ED1962AFA1B7932F3549520FD71C75E'
> PACKET_COUNT = 100
> @@ -128,15 +129,9 @@ class TestRuntimeVfQn(TestCase):
> """
> Sends packets.
> """
> - self.tester.scapy_foreground()
> - time.sleep(2)
> - for i in range(integer):
> - quotient = i // 254
> - remainder = i % 254
> - packet = r'sendp([Ether(dst="%s",
> src=get_if_hwaddr("%s"))/IP(src="10.0.0.1", dst="192.168.%d.%d")],
> iface="%s")' % (vf_mac, itf, quotient, remainder + 1, itf)
> - self.tester.scapy_append(packet)
> - self.tester.scapy_execute()
> - time.sleep(2)
> + pkt = Packet()
> + pkt.generate_random_pkts(vf_mac, pktnum=integer,
> random_type=['IP_RAW'])
> + pkt.send_pkt(self.tester, tx_port=itf)
>
> def verify_queue_number(self, outstring, qn, pkt_count):
> total_rx = []
> diff --git a/tests/TestSuite_runtime_vf_queue_number_kernel.py
> b/tests/TestSuite_runtime_vf_queue_number_kernel.py
> index 9416f13..73d40c2 100644
> --- a/tests/TestSuite_runtime_vf_queue_number_kernel.py
> +++ b/tests/TestSuite_runtime_vf_queue_number_kernel.py
> @@ -41,6 +41,7 @@ import utils
> from pmd_output import PmdOutput
> from test_case import TestCase
> from virt_common import VM
> +from packet import Packet
>
> VM_CORES_MASK = 'all'
>
> @@ -75,6 +76,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> def set_up(self):
> pass
> +
> def setup_1pf_2vf_1vm_env(self,driver="default"):
>
> self.used_dut_port = self.dut_ports[0]
> @@ -90,9 +92,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0':
> self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> - self.host_testpmd.start_testpmd("Default", eal_param=eal_param)
> + self.host_testpmd.start_testpmd("Default")
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'runtime_vf_queue_number_kernel')
> self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop)
> @@ -131,15 +131,11 @@ class
> TestRuntimeVfQueueNumberKernel(TestCase):
>
> self.setup_1pf_2vf_1vm_env_flag = 0
>
> - def send_packet2different_queue(self, dts, src, iface, count):
> - self.tester.scapy_foreground()
> - for i in range(1,count+1):
> - j = (i//255)%255
> - k = i%255
> - pkt = 'sendp([Ether(dst="%s",
> src="%s")/IP(src="192.168.%d.%d",dst="192.168.13.%d")/("test"*10)],iface="
> %s")' % (
> - dts, src, j,k,k, iface)
> - self.tester.scapy_append(pkt)
> - self.tester.scapy_execute()
> + def send_packet2different_queue(self, dst, src, iface, count):
> + pkt = Packet()
> + pkt.generate_random_pkts(pktnum=count, random_type=['IP_RAW'],
> + options={'layers_config': [('ether', {'dst': '%s' % dst, 'src':
> '%s' % src})]})
> + pkt.send_pkt(self.tester, tx_port=iface)
>
> def check_result(self, nr_queue, out, out2, pkts_num, count, misc):
> if nr_queue == 1:
> @@ -189,7 +185,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> self.vm0_testpmd.execute_cmd('set verbose 1')
> self.vm0_testpmd.execute_cmd('set promisc all off')
> - #set rss-hash-key to a fixed value instead of default random value
> on vf
> + #set rss-hash-key to a fixed value instead of default random value on vf
> self.vm0_testpmd.execute_cmd('port config 0 rss-hash-key ipv4
> 6EA6A420D5138E712433B813AE45B3C4BECB2B405F31AD6C331835372D15E
> 2D5E49566EE0ED1962AFA1B7932F3549520FD71C75E')
> time.sleep(1)
> self.vm0_testpmd.execute_cmd('set fwd mac')
> @@ -297,6 +293,7 @@ class TestRuntimeVfQueueNumberKernel(TestCase):
>
> def tear_down(self):
> self.vm0_testpmd.execute_cmd('quit', '# ')
> + self.dut.kill_all()
>
> def tear_down_all(self):
> self.logger.info("tear_down_all")
> diff --git a/tests/TestSuite_rxtx_callbacks.py
> b/tests/TestSuite_rxtx_callbacks.py
> index 76ad70f..a2da0d9 100644
> --- a/tests/TestSuite_rxtx_callbacks.py
> +++ b/tests/TestSuite_rxtx_callbacks.py
> @@ -90,8 +90,8 @@ class TestRxtxCallbacks(TestCase):
> def get_tcpdump_package(self,inst):
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> dsts = []
> - for packet in pkts:
> - dst = packet.strip_element_layer2("dst")
> + for i in range(len(pkts)):
> + dst = pkts.strip_element_layer2("dst", p_index=i)
> dsts.append(dst)
> return dsts
>
> diff --git a/tests/TestSuite_scatter.py b/tests/TestSuite_scatter.py
> index cc441df..6802f52 100644
> --- a/tests/TestSuite_scatter.py
> +++ b/tests/TestSuite_scatter.py
> @@ -85,12 +85,12 @@ class TestScatter(TestCase):
> inst = self.tester.tcpdump_sniff_packets(self.intf)
> pkt = Packet(pkt_type="IP_RAW", pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': dmac})
> - pkt.send_pkt(tx_port=self.intf)
> + pkt.send_pkt(self.tester, tx_port=self.intf)
> sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
>
> res = ""
> if len(sniff_pkts):
> - res = strip_pktload(sniff_pkts[0], layer="L4")
> + res = strip_pktload(sniff_pkts, layer="L4")
> return res
>
> def set_up(self):
> diff --git a/tests/TestSuite_short_live.py b/tests/TestSuite_short_live.py
> index 93ec587..4e1ee15 100644
> --- a/tests/TestSuite_short_live.py
> +++ b/tests/TestSuite_short_live.py
> @@ -102,7 +102,7 @@ class TestShortLiveApp(TestCase):
> if (txPort == rxPort):
> count = 2
>
> - inst = self.tester.tcpdump_sniff_packets(rxitf, count=count, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(rxitf, count=count)
>
> pktlen = pktSize - 14
> padding = pktlen - 20
> @@ -112,7 +112,7 @@ class TestShortLiveApp(TestCase):
> time.sleep(3)
>
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> - out = str(pkts[0].pktgen.pkt.show)
> + out = str(pkts[0].show)
> self.logger.info('SCAPY Result:\n' + out + '\n\n\n')
> if received:
> self.verify(('PPP' in out) and 'src=%s'% Dut_tx_mac in out, "Receive
> test failed")
> diff --git a/tests/TestSuite_skeleton.py b/tests/TestSuite_skeleton.py
> index 91cf9c4..38bc523 100644
> --- a/tests/TestSuite_skeleton.py
> +++ b/tests/TestSuite_skeleton.py
> @@ -93,8 +93,8 @@ class TestSkeleton(TestCase):
> def get_tcpdump_package(self,inst):
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> dsts = []
> - for packet in pkts:
> - dst = packet.strip_element_layer2("dst")
> + for i in range(len(pkts)):
> + dst = pkts.strip_element_layer2("dst", p_index=i)
> dsts.append(dst)
> return dsts
>
> diff --git a/tests/TestSuite_sriov_kvm.py b/tests/TestSuite_sriov_kvm.py
> index 3518f8f..6a28129 100644
> --- a/tests/TestSuite_sriov_kvm.py
> +++ b/tests/TestSuite_sriov_kvm.py
> @@ -359,10 +359,8 @@ class TestSriovKvm(TestCase):
> if driver == 'igb_uio':
> # start testpmd with the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0':
> self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> self.host_testpmd.start_testpmd(
> - "1S/2C/2T", "--rxq=4 --txq=4", eal_param=eal_param)
> + "1S/2C/2T", "--rxq=4 --txq=4")
> self.host_testpmd.execute_cmd('set fwd rxonly')
> self.host_testpmd.execute_cmd('start')
>
> @@ -439,13 +437,8 @@ class TestSriovKvm(TestCase):
> if driver == 'igb_uio':
> # start testpmd with the four VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0) -b %(vf1)s -b %(vf2)s -b %(vf3)s' % \
> - {'vf0': self.sriov_vfs_pci[0],
> - 'vf1': self.sriov_vfs_pci[1],
> - 'vf2': self.sriov_vfs_pci[2],
> - 'vf3': self.sriov_vfs_pci[3]}
> self.host_testpmd.start_testpmd(
> - "1S/2C/2T", eal_param=eal_param)
> + "1S/2C/2T")
>
> self.vm0 = VM(self.dut, 'vm0', 'sriov_kvm')
> self.vm0.set_vm_device(driver=self.vf_assign_method, **vf0_prop)
> diff --git a/tests/TestSuite_uni_pkt.py b/tests/TestSuite_uni_pkt.py
> index 9a75061..0310e04 100644
> --- a/tests/TestSuite_uni_pkt.py
> +++ b/tests/TestSuite_uni_pkt.py
> @@ -81,7 +81,7 @@ class TestUniPacket(TestCase):
> for pkt_type in pkt_types.keys():
> pkt_names = pkt_types[pkt_type]
> pkt = Packet(pkt_type=pkt_type)
> - pkt.send_pkt(tx_port=self.tester_iface, count=4)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface, count=4)
> out = self.dut.get_session_output(timeout=2)
> for pkt_layer_name in pkt_names:
> if pkt_layer_name not in out:
> @@ -111,10 +111,10 @@ class TestUniPacket(TestCase):
> for l2_type in self.L2_types.keys():
> pkt_name = self.L2_types[l2_type]
> pkt = Packet(pkt_type=l2_type)
> - pkt.send_pkt(tx_port=self.tester_iface)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface)
> out = self.dut.get_session_output(timeout=2)
> if pkt_name in out:
> - print utils.GREEN("Detected L2 %s successfully" % l2_type)
> + print(utils.GREEN("Detected L2 %s successfully" % l2_type))
> else:
> raise VerifyFailure("Failed to detect L2 %s" % l2_type)
>
> @@ -347,7 +347,7 @@ class TestUniPacket(TestCase):
> pkt.config_layers([('ipv6',{'nh':47}), ('inner_ipv6', {'nh': 58})])
> else:
> pkt.config_layers([('ipv6',{'nh':47}),('inner_ipv6', {'nh': 132})])
> - pkt.send_pkt(tx_port=self.tester_iface)
> + pkt.send_pkt(self.tester, tx_port=self.tester_iface)
> out = self.dut.get_session_output(timeout=2)
> for pkt_layer_name in pkts[1]:
> if pkt_layer_name not in out:
> @@ -445,7 +445,6 @@ class TestUniPacket(TestCase):
>
> for packet in nsh_packets:
> self.tester.scapy_foreground()
> - self.tester.scapy_append("from scapy.contrib.nsh import *")
> self.tester.scapy_append("sendp([%s],iface='%s')" %
> (nsh_packets[packet], self.tester_iface))
> self.tester.scapy_execute()
> out = self.dut.get_session_output(timeout=2)
> diff --git a/tests/TestSuite_userspace_ethtool.py
> b/tests/TestSuite_userspace_ethtool.py
> index 0a4b772..116fd3a 100644
> --- a/tests/TestSuite_userspace_ethtool.py
> +++ b/tests/TestSuite_userspace_ethtool.py
> @@ -297,7 +297,7 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> ori_rx_pkts, ori_tx_pkts = self.strip_portstats(port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> time.sleep(1)
> rx_pkts, tx_pkts = self.strip_portstats(port)
> self.verify((rx_pkts == (ori_rx_pkts + 4)), "Failed to record Rx/Tx
> packets")
> @@ -406,10 +406,10 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> rx_ring, _, tx_ring, _ = self.strip_ringparam(index)
> self.verify(rx_ring == rx_max, "Userspace tool failed to set Rx ring
> parameter")
> self.verify(tx_ring == tx_max, "Userspace tool failed to set Tx ring
> parameter")
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP')
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, tx_pkts = self.strip_portstats(index)
> self.verify(rx_pkts == ori_rx_pkts + 4, "Failed to forward after ring
> parameter changed")
> self.dut.send_expect("quit", "# ")
> @@ -441,7 +441,7 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> pkt.config_layer('vlan', {'vlan': vlan})
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, tx_pkts = self.strip_portstats(port)
> self.verify(rx_pkts == ori_rx_pkts + 4, "Failed to Rx vlan packet")
> self.verify(tx_pkts == ori_tx_pkts + 4, "Failed to Tx vlan packet")
> @@ -449,7 +449,7 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> # send incorrect vlan packet to port
> wrong_vlan = (vlan + 1) % 4096
> pkt.config_layer('vlan', {'vlan': wrong_vlan})
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> time.sleep(2)
> rx_pkts_wrong, tx_pkts_wrong = self.strip_portstats(port)
> self.verify(tx_pkts_wrong == rx_pkts, "Failed to filter Rx vlan packet")
> @@ -458,7 +458,7 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> self.dut.send_expect("vlan %d del %d" % (index, vlan), "EthApp>")
> # send same packet and make sure not received
> pkt.config_layer('vlan', {'vlan': vlan})
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> time.sleep(2)
> rx_pkts_del, tx_pkts_del = self.strip_portstats(port)
> self.verify(tx_pkts_del == rx_pkts, "Failed to remove Rx vlan filter")
> @@ -483,15 +483,15 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> dump_mac = self.strip_mac(index)
> self.verify(dump_mac == valid_mac, "Userspace tool failed to set
> mac")
> # check forwarded mac has been changed
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP')
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> # send and sniff packet
> - inst = self.tester.tcpdump_sniff_packets(intf, timeout=5)
> - pkt.send_pkt(tx_port=intf, count=4)
> + inst = self.tester.tcpdump_sniff_packets(intf)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> self.verify(len(pkts) == 4, "Packet not forwarded as expected")
> - src_mac = pkts[0].strip_layer_element("layer2", "src")
> + src_mac = pkts.strip_layer_element("layer2", "src", p_index=0)
> self.verify(src_mac == valid_mac, "Forwarded packet not match
> default mac")
>
> # check multicast will not be valid mac
> @@ -519,10 +519,10 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> self.dut.send_expect("stop %d" % index, "EthApp>")
> time.sleep(10)
> # check packet not forwarded when port is stop
> - pkt = Packet()
> + pkt = Packet(pkt_type='UDP')
> tester_port = self.tester.get_local_port(port)
> intf = self.tester.get_interface(tester_port)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, tx_pkts = self.strip_portstats(index)
> self.verify(rx_pkts == ori_rx_pkts, "Failed to stop port")
> # restart port and check packet can normally forwarded
> @@ -531,7 +531,7 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> # wait few time for port ready
> rx_pkts, tx_pkts = self.strip_portstats(index)
> time.sleep(2)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts_open, tx_pkts_open = self.strip_portstats(index)
> self.verify(rx_pkts_open == rx_pkts + 4, "Failed to reopen port rx")
> self.verify(tx_pkts_open == tx_pkts + 4, "Failed to reopen port tx")
> @@ -568,12 +568,12 @@ class TestUserspaceEthtool(TestCase,
> IxiaPacketGenerator):
> time.sleep(5)
> ori_rx_pkts, _ = self.strip_portstats(index)
> pkt_size = mtu + HEADER_SIZE['eth'] + offset
> - pkt = Packet(pkt_len=pkt_size)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt = Packet(pkt_type='UDP', pkt_len=pkt_size)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts, _ = self.strip_portstats(index)
> self.verify(rx_pkts == ori_rx_pkts + 4, "Packet match mtu not
> forwarded as expected")
> - pkt = Packet(pkt_len=mtu + 1 + HEADER_SIZE['eth'] + offset)
> - pkt.send_pkt(tx_port=intf, count=4)
> + pkt = Packet(pkt_type='UDP', pkt_len=mtu + 1 + HEADER_SIZE['eth']
> + offset)
> + pkt.send_pkt(self.tester, tx_port=intf, count=4)
> rx_pkts_over, _ = self.strip_portstats(index)
> self.verify(rx_pkts == rx_pkts_over, "Packet over mtu should not be
> forwarded")
>
> diff --git a/tests/TestSuite_veb_switch.py b/tests/TestSuite_veb_switch.py
> index 78fcbbd..e60a618 100644
> --- a/tests/TestSuite_veb_switch.py
> +++ b/tests/TestSuite_veb_switch.py
> @@ -120,12 +120,12 @@ class TestVEBSwitching(TestCase):
> pkt = Packet(pkt_type='VLAN_UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> pkt.config_layer('vlan', {'vlan': 1})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
> else:
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': vf_mac})
> - pkt.send_pkt(tx_port=itf)
> + pkt.send_pkt(self.tester, tx_port=itf)
> time.sleep(.5)
>
> def count_packet(self, out, mac):
> diff --git a/tests/TestSuite_vf_daemon.py b/tests/TestSuite_vf_daemon.py
> index fcbf5b8..5b738c7 100644
> --- a/tests/TestSuite_vf_daemon.py
> +++ b/tests/TestSuite_vf_daemon.py
> @@ -90,12 +90,9 @@ class TestVfDaemon(TestCase):
> for port in self.sriov_vfs_port:
> port.bind_driver(self.vf_driver)
> time.sleep(1)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0': self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> -
> self.dut_testpmd = PmdOutput(self.dut)
> self.dut_testpmd.start_testpmd(
> - "Default", "--rxq=4 --txq=4 --port-topology=chained",
> eal_param=eal_param)
> + "Default", "--rxq=4 --txq=4 --port-topology=chained")
> self.dut_testpmd.execute_cmd("start")
> time.sleep(5)
>
> @@ -166,8 +163,8 @@ class TestVfDaemon(TestCase):
> pkt.config_layer('vlan', {'vlan': vlan_id})
> pkt.config_layer('ether', {'dst': dst_mac})
>
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=30)
> - pkt.send_pkt(tx_port=self.tester_intf, count=num)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num)
> return inst
>
> def strip_mac(self, inst, element = "src"):
> @@ -176,8 +173,8 @@ class TestVfDaemon(TestCase):
> """
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> macs = []
> - for pkt in pkts:
> - mac = pkt.strip_element_layer2(element)
> + for i in range(len(pkts)):
> + mac = pkts.strip_element_layer2(element, p_index=i)
> macs.append(mac)
> return macs
>
> @@ -187,8 +184,8 @@ class TestVfDaemon(TestCase):
> """
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> vlans = []
> - for pkt in pkts:
> - vlan = pkt.strip_element_vlan("vlan")
> + for i in range(len(pkts)):
> + vlan = pkts.strip_element_vlan("vlan", p_index=i)
> vlans.append(vlan)
> return vlans
>
> @@ -434,7 +431,7 @@ class TestVfDaemon(TestCase):
> self.dut_testpmd.execute_cmd('set tx loopback 0 off')
> time.sleep(5)
>
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf)
>
> self.vm1_testpmd.execute_cmd('set burst 5')
> self.vm1_testpmd.execute_cmd('start tx_first')
> @@ -450,7 +447,7 @@ class TestVfDaemon(TestCase):
> self.dut_testpmd.execute_cmd('set tx loopback 0 on')
> time.sleep(3)
>
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf)
>
> self.vm1_testpmd.execute_cmd('stop')
> self.vm1_testpmd.execute_cmd('start tx_first')
> diff --git a/tests/TestSuite_vf_interrupt_pmd.py
> b/tests/TestSuite_vf_interrupt_pmd.py
> index cc15ac6..0b1f858 100644
> --- a/tests/TestSuite_vf_interrupt_pmd.py
> +++ b/tests/TestSuite_vf_interrupt_pmd.py
> @@ -108,7 +108,7 @@ class TestVfInterruptPmd(TestCase):
> """
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> - pkt.send_pkt(tx_port=testinterface)
> + pkt.send_pkt(self.tester, tx_port=testinterface)
>
> self.out2 = use_dut.get_session_output(timeout=2)
>
> diff --git a/tests/TestSuite_vf_jumboframe.py
> b/tests/TestSuite_vf_jumboframe.py
> index f082cec..dd728d9 100644
> --- a/tests/TestSuite_vf_jumboframe.py
> +++ b/tests/TestSuite_vf_jumboframe.py
> @@ -174,7 +174,7 @@ class TestVfJumboFrame(TestCase):
>
> pkt = Packet(pkt_type='UDP', pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': mac})
> - pkt.send_pkt(tx_port=self.tester_intf)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf)
>
> time.sleep(1)
>
> diff --git a/tests/TestSuite_vf_kernel.py b/tests/TestSuite_vf_kernel.py
> index bee30a0..9a280b1 100644
> --- a/tests/TestSuite_vf_kernel.py
> +++ b/tests/TestSuite_vf_kernel.py
> @@ -119,12 +119,8 @@ class TestVfKernel(TestCase):
> time.sleep(1)
>
> self.dut_testpmd = PmdOutput(self.dut)
> - eal_param = ''
> - for sriov_vf in self.sriov_vfs_port:
> - eal_param += " -b %s" % sriov_vf.pci
> self.dut_testpmd.start_testpmd(
> - "Default", "--rxq=4 --txq=4 --port-topology=chained",
> - eal_param=eal_param)
> + "Default", "--rxq=4 --txq=4 --port-topology=chained")
> # dpdk-2208
> # since there is no forward engine on DPDK PF to forward or drop
> packet in packet pool,
> # so finally the pool will be full, then no more packet will be
> @@ -412,12 +408,12 @@ class TestVfKernel(TestCase):
> if vlan_id == '':
> pkt = Packet(pkt_type='TCP', pkt_len=pkt_lens)
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> - pkt.send_pkt(tx_port=self.tester_intf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num)
> else:
> pkt = Packet(pkt_type='VLAN_UDP', pkt_len=pkt_lens)
> pkt.config_layer('ether', {'dst': mac, 'src': self.tester_mac})
> pkt.config_layer('vlan', {'vlan': vlan_id})
> - pkt.send_pkt(tx_port=self.tester_intf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf, count=num)
>
> def test_vlan(self):
> """
> @@ -873,8 +869,7 @@ class TestVfKernel(TestCase):
>
> # Link down DPDK VF0 and expect no impact on other VFs
> self.vm0_testpmd.quit()
> - eal_param = '-b %(vf0)s' % ({'vf0': self.vm0_dut.ports_info[0]['pci']})
> - self.vm0_testpmd.start_testpmd("Default", eal_param=eal_param)
> + self.vm0_testpmd.start_testpmd("Default")
> self.vm0_testpmd.execute_cmd('set promisc all on')
> self.vm0_testpmd.execute_cmd('set fwd rxonly')
> self.vm0_testpmd.execute_cmd('set verbose 1')
> diff --git a/tests/TestSuite_vf_macfilter.py b/tests/TestSuite_vf_macfilter.py
> index f7bba1a..01da9b4 100644
> --- a/tests/TestSuite_vf_macfilter.py
> +++ b/tests/TestSuite_vf_macfilter.py
> @@ -67,12 +67,10 @@ class TestVfMacFilter(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0':
> self.sriov_vfs_port_0[0].pci,
> - 'vf1': self.sriov_vfs_port_1[0].pci}
> if (self.nic in ["niantic", "sageville", "sagepond"]):
> - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ")
> else:
> - self.host_testpmd.start_testpmd("1S/2C/2T",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_macfilter')
> @@ -158,7 +156,7 @@ class TestVfMacFilter(TestCase):
>
> print "\nfirst send packets to the PF set MAC, expected result is RX
> packets=TX packets\n"
> result1 = self.tester.check_random_pkts(tgen_ports, pktnum=100,
> allow_miss=False, params=pkt_param)
> - print "\nshow port stats in testpmd for double check: \n",
> self.vm0_testpmd.execute_cmd('show port stats all')
> + print "\nshow port stats in testpmd for double check: \n",
> self.vm0_testpmd.execute_cmd('show port stats all')
> self.verify(result1 != False, "VF0 failed to forward packets to VF1")
>
> print "\nSecondly, negative test, send packets to a wrong MAC,
> expected result is RX packets=0\n"
> @@ -259,6 +257,7 @@ class TestVfMacFilter(TestCase):
>
> if self.setup_2pf_2vf_1vm_env_flag == 1:
> self.destroy_2pf_2vf_1vm_env()
> + self.dut.kill_all()
>
> def tear_down_all(self):
>
> diff --git a/tests/TestSuite_vf_offload.py b/tests/TestSuite_vf_offload.py
> index dc5cb30..421d9c4 100644
> --- a/tests/TestSuite_vf_offload.py
> +++ b/tests/TestSuite_vf_offload.py
> @@ -71,9 +71,7 @@ class TestVfOffload(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0':
> self.sriov_vfs_port_0[0].pci,
> - 'vf1': self.sriov_vfs_port_1[0].pci}
> - self.host_testpmd.start_testpmd("1S/2C/2T",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_offload')
> diff --git a/tests/TestSuite_vf_packet_rxtx.py
> b/tests/TestSuite_vf_packet_rxtx.py
> index 8a8816d..c111c9e 100644
> --- a/tests/TestSuite_vf_packet_rxtx.py
> +++ b/tests/TestSuite_vf_packet_rxtx.py
> @@ -6,6 +6,7 @@ import time
> from virt_common import VM
> from test_case import TestCase
> from pmd_output import PmdOutput
> +from packet import Packet
>
> VM_CORES_MASK = 'all'
>
> @@ -64,12 +65,10 @@ class TestVfPacketRxtx(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0':
> self.sriov_vfs_port_0[0].pci,
> - 'vf1': self.sriov_vfs_port_1[0].pci}
> if (self.nic in ["niantic", "sageville", "sagepond"]):
> - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ")
> else:
> - self.host_testpmd.start_testpmd("1S/5C/1T", "",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/5C/1T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_packet_rxtx')
> @@ -189,13 +188,10 @@ class TestVfPacketRxtx(TestCase):
>
> if driver == 'igb_uio':
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s -b %(vf2)s' % {'vf0':
> self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci,
> - 'vf2': self.sriov_vfs_port[2].pci}
> if (self.nic in ["niantic", "sageville", "sagepond"]):
> - self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/9C/1T", "--txq=4 --rxq=4 ")
> else:
> - self.host_testpmd.start_testpmd("1S/2C/2T",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_packet_rxtx')
> @@ -290,7 +286,8 @@ class TestVfPacketRxtx(TestCase):
>
> dst_mac = pmd0_vf0_mac
> self.vm0_testpmd.execute_cmd('clear port stats all')
> - self.tester.sendpkt_bg(tx_port, dst_mac)
> + pkt = Packet("Ether(dst='%s', src='%s')/IP(len=46)" % (dst_mac,
> self.tester.get_mac(tx_port)))
> + filename = pkt.send_pkt_bg(crb=self.tester,
> tx_port=self.tester.get_interface(tx_port), loop=1)
>
> #vf port stop/start can trigger reset action
> for num in range(1000):
> @@ -299,7 +296,7 @@ class TestVfPacketRxtx(TestCase):
> self.vm1_testpmd.execute_cmd('port start all')
> time.sleep(0.1)
>
> - self.tester.stop_sendpkt_bg()
> + pkt.stop_send_pkt_bg(self.tester, filename)
>
> pmd0_vf0_stats = self.vm0_testpmd.get_pmd_stats(port_id_0)
> pmd0_vf1_stats = self.vm0_testpmd.get_pmd_stats(port_id_1)
> diff --git a/tests/TestSuite_vf_port_start_stop.py
> b/tests/TestSuite_vf_port_start_stop.py
> index 2ff2d1c..dcd799b 100644
> --- a/tests/TestSuite_vf_port_start_stop.py
> +++ b/tests/TestSuite_vf_port_start_stop.py
> @@ -10,6 +10,7 @@ from utils import RED, GREEN
> from net_device import NetDevice
> from crb import Crb
> from scapy.all import *
> +from scapy.layers.sctp import SCTP, SCTPChunkData
> VM_CORES_MASK = 'all'
>
> class TestVfPortStartStop(TestCase):
> @@ -22,7 +23,9 @@ class TestVfPortStartStop(TestCase):
> self.verify(len(self.dut_ports) >= 1, "Insufficient ports")
> self.vm0 = None
> self.filename = "/tmp/vf.pcap"
> -
> + self.tester_tx_port = self.tester.get_local_port(self.dut_ports[0])
> + self.tester_tintf = self.tester.get_interface(self.tester_tx_port)
> + self.send_pks_session = None
> # set vf assign method and vf driver
> self.vf_driver = self.get_suite_cfg()['vf_driver']
> if self.vf_driver is None:
> @@ -38,71 +41,23 @@ class TestVfPortStartStop(TestCase):
>
> self.setup_1pf_2vf_1vm_env_flag = 0
>
> - def pktgen_prerequisites(self):
> - """
> - igb_uio.ko should be put in ~ before you using pktgen
> - """
> - out = self.tester.send_expect("ls", "#")
> - self.verify("igb_uio.ko" in out, "No file igb_uio.ko, please add it in ~")
> - self.tester.send_expect("modprobe uio", "#", 70)
> - out = self.tester.send_expect("lsmod | grep igb_uio", "#")
> - if "igb_uio" in out:
> - self.tester.send_expect("rmmod -f igb_uio", "#", 70)
> - self.tester.send_expect("insmod ~/igb_uio.ko", "#", 60)
> - out = self.tester.send_expect("lsmod | grep igb_uio", "#")
> - assert ("igb_uio" in out), "Failed to insmod igb_uio"
> -
> - total_huge_pages = self.tester.get_total_huge_pages()
> - if total_huge_pages == 0:
> - self.tester.mount_huge_pages()
> - self.tester.set_huge_pages(2048)
> -
> - def pktgen_kill(self):
> - """
> - Kill all pktgen on tester.
> - """
> - pids = []
> - pid_reg = r'p(\d+)'
> - out = self.tester.alt_session.send_expect("lsof -Fp /var/run/.pg_config",
> "#", 20)
> - if len(out):
> - lines = out.split('\r\n')
> - for line in lines:
> - m = re.match(pid_reg, line)
> - if m:
> - pids.append(m.group(1))
> - for pid in pids:
> - self.tester.alt_session.send_expect('kill -9 %s' % pid, '# ', 20)
> -
> def send_and_verify(self, dst_mac, testpmd):
> """
> Generates packets by pktgen
> """
> self.testpmd_reset_status(testpmd)
>
> - self.pktgen_prerequisites()
> - # bind ports
> - self.tester_tx_port = self.tester.get_local_port(self.dut_ports[0])
> - self.tester_tx_pci = self.tester.ports_info[self.tester_tx_port]['pci']
> - port = self.tester.ports_info[self.tester_tx_port]['port']
> - self.tester_port_driver = port.get_nic_driver()
> - self.tester.send_expect("./dpdk-devbind.py --force --bind=igb_uio %s" %
> self.tester_tx_pci, "#")
> -
> - src_mac = self.tester.get_mac(self.tester_tx_port)
> + src_mac = self.tester.get_mac(self.tester_tx_port)
> if src_mac == 'N/A':
> src_mac = "02:00:00:00:01"
> -
> - self.create_pcap_file(self.filename, dst_mac, src_mac)
> -
> - self.tester.send_expect("./pktgen -c 0x1f -n 2 --proc-type auto --socket-
> mem 128,128 --file-prefix pg -- -P -T -m '1.0' -s 0:%s" % self.filename,
> "Pktgen >", 100)
> - time.sleep(1)
> - self.tester.send_expect("start all", "Pktgen>")
> + self.send_pkts(self.filename, dst_mac, src_mac)
> time.sleep(1)
> self.check_port_start_stop(testpmd)
> - # quit pktgen
> - self.tester.send_expect("stop all", "Pktgen>")
> - self.tester.send_expect("quit", "# ")
> + self.tester.send_expect('killall -s INT scapy', '# ')
> + self.tester.destroy_session(self.send_pks_session)
> + self.send_pks_session = None
>
> - def create_pcap_file(self, filename, dst_mac, src_mac):
> + def send_pkts(self, filename, dst_mac, src_mac):
> """
> Generates a valid PCAP file with the given configuration.
> """
> @@ -115,9 +70,14 @@ class TestVfPortStartStop(TestCase):
> pkts = []
> for key in def_pkts.keys():
> pkts.append(def_pkts[key])
> -
> wrpcap(filename, pkts)
>
> + sendp_fmt = "sendp(pk, iface='%s', loop=1)" % (self.tester_tintf)
> + self.send_pks_session = self.tester.create_session("scapy1")
> + self.send_pks_session.send_expect("scapy", ">>>")
> + self.send_pks_session.send_expect("pk=rdpcap('%s')" % filename,
> ">>>")
> + self.send_pks_session.send_command(sendp_fmt)
> +
> def testpmd_reset_status(self, testpmd):
> """
> Reset testpmd :stop forward & stop port
> @@ -175,9 +135,7 @@ class TestVfPortStartStop(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s -b %(vf1)s' % {'vf0':
> self.sriov_vfs_port[0].pci,
> - 'vf1': self.sriov_vfs_port[1].pci}
> - self.host_testpmd.start_testpmd("1S/2C/2T",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_port_start_stop')
> @@ -242,13 +200,9 @@ class TestVfPortStartStop(TestCase):
>
> def tear_down_all(self):
>
> - self.pktgen_kill()
> - if getattr(self, 'tester_port_driver', None) and \
> - getattr(self, 'tester_tx_pci', None):
> - self.tester.send_expect("./dpdk-devbind.py --bind=%s %s" \
> - %(self.tester_port_driver, self.tester_tx_pci), "#")
> - tx_interface = self.tester.get_interface(self.tester_tx_port)
> - self.tester.send_expect("ifconfig %s up" % tx_interface, "#")
> + if self.send_pks_session:
> + self.tester.send_expect('killall -s INT scapy', '# ')
> + self.tester.destroy_session(self.send_pks_session)
>
> if getattr(self, 'vm0', None):
> self.vm0.stop()
> diff --git a/tests/TestSuite_vf_rss.py b/tests/TestSuite_vf_rss.py
> index 8220926..95d13cd 100644
> --- a/tests/TestSuite_vf_rss.py
> +++ b/tests/TestSuite_vf_rss.py
> @@ -277,8 +277,7 @@ class TestVfRss(TestCase):
> if driver == 'igb_uio':
> # start testpmd without the two VFs on the host
> self.host_testpmd = PmdOutput(self.dut)
> - eal_param = '-b %(vf0)s ' % {'vf0': self.sriov_vfs_port_0[0].pci}
> - self.host_testpmd.start_testpmd("1S/2C/2T",
> eal_param=eal_param)
> + self.host_testpmd.start_testpmd("1S/2C/2T")
>
> # set up VM0 ENV
> self.vm0 = VM(self.dut, 'vm0', 'vf_rss')
> diff --git a/tests/TestSuite_vf_vlan.py b/tests/TestSuite_vf_vlan.py
> index f50a7e5..7f46aa6 100644
> --- a/tests/TestSuite_vf_vlan.py
> +++ b/tests/TestSuite_vf_vlan.py
> @@ -173,8 +173,8 @@ class TestVfVlan(TestCase):
>
> pkt = Packet(pkt_type='UDP')
> pkt.config_layer('ether', {'dst': self.vf1_mac})
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
> - pkt.send_pkt(tx_port=self.tester_intf1)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf0)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf1)
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
>
> self.verify(len(pkts), "Not receive expected packet")
> @@ -194,7 +194,7 @@ class TestVfVlan(TestCase):
> pkt.config_layer('vlan', {'vlan': vlan})
> pkt.config_layer('ether', {'dst': self.vf0_mac})
>
> - pkt.send_pkt(tx_port=self.tester_intf0)
> + pkt.send_pkt(self.tester, tx_port=self.tester_intf0)
> out = self.vm_dut_0.get_session_output(timeout=2)
>
> return out
> @@ -258,7 +258,7 @@ class TestVfVlan(TestCase):
> "ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ")
>
> def tx_and_check(self, tx_vlan=1):
> - inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(self.tester_intf0)
> self.vm0_testpmd.execute_cmd('set burst 1')
> self.vm0_testpmd.execute_cmd('start tx_first')
> self.vm0_testpmd.execute_cmd('stop')
> @@ -266,8 +266,8 @@ class TestVfVlan(TestCase):
> # strip sniffered vlans
> pkts = self.tester.load_tcpdump_sniff_packets(inst)
> vlans = []
> - for pkt in pkts:
> - vlan = pkt.strip_element_vlan("vlan")
> + for i in range(len(pkts)):
> + vlan = pkts.strip_element_vlan("vlan", p_index=i)
> vlans.append(vlan)
>
> self.verify(
> diff --git a/tests/TestSuite_vhost_enqueue_interrupt.py
> b/tests/TestSuite_vhost_enqueue_interrupt.py
> index 428cf36..5c4c1df 100644
> --- a/tests/TestSuite_vhost_enqueue_interrupt.py
> +++ b/tests/TestSuite_vhost_enqueue_interrupt.py
> @@ -192,6 +192,7 @@ class TestVhostEnqueueInterrupt(TestCase):
> self.close_testpmd_and_session()
> self.dut.send_expect("killall -s INT l3fwd-power", "#")
> self.dut.send_expect("killall -s INT testpmd", "#")
> + self.dut.kill_all()
>
> def tear_down_all(self):
> """
> diff --git a/tests/TestSuite_vhost_multi_queue_qemu.py
> b/tests/TestSuite_vhost_multi_queue_qemu.py
> index f0dbb90..d31eb57 100644
> --- a/tests/TestSuite_vhost_multi_queue_qemu.py
> +++ b/tests/TestSuite_vhost_multi_queue_qemu.py
> @@ -40,7 +40,7 @@ import utils
> from test_case import TestCase
> from settings import HEADER_SIZE
> from virt_common import VM
> -from packet import Packet, send_packets, save_packets
> +from packet import Packet
> from pmd_output import PmdOutput
> from pktgen import PacketGeneratorHelper
>
> @@ -154,8 +154,7 @@ class TestVhostMultiQueueQemu(TestCase):
> pkt1.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4',
> {'dst': '1.1.1.1'}),
> ('raw', {'payload': ['01'] * int('%d' % payload_size)})])
>
> - pkt = [pkt1]
> - save_packets(pkt, "%s/multiqueue.pcap" % self.out_path)
> + pkt1.save_pcapfile(self.tester, "%s/multiqueue.pcap" % self.out_path)
>
> port = self.tester.get_local_port(self.pf)
> tgenInput.append((port, port, "%s/multiqueue.pcap" %
> self.out_path))
> @@ -185,7 +184,7 @@ class TestVhostMultiQueueQemu(TestCase):
> self.logger.info(info)
> self.dut.send_expect("clear port stats all", "testpmd> ", 120)
> payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] -
> HEADER_SIZE['udp']
> -
> + pkts = Packet()
> pkt1 = Packet()
> pkt1.assign_layers(['ether', 'ipv4', 'udp', 'raw'])
> pkt1.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4',
> {'dst': '1.1.1.1'}),
> @@ -203,11 +202,13 @@ class TestVhostMultiQueueQemu(TestCase):
> pkt4.config_layers([('ether', {'dst': '%s' % self.virtio1_mac}), ('ipv4',
> {'dst': '1.1.1.8'}),
> ('udp', {'src': 4789, 'dst': 4789}), ('raw', {'payload': ['01'] *
> int('%d' % payload_size)})])
>
> - pkt = [pkt1, pkt2, pkt3, pkt4] * 10
> - send_packets(self.tx_interface, pkt)
> + pkt = [pkt1, pkt2, pkt3, pkt4]
> + for i in pkt:
> + pkts.pktgen.pkts.append(i.pktgen.pkt)
> + pkts.send_pkt(self.tester, tx_port=self.tx_interface, count=10)
>
> out = self.dut.send_expect("show port stats 0", "testpmd> ", 120)
> - print out
> + print(out)
> rx_packet = re.search("RX-packets:\s*(\d*)", out)
> rx_num = int(rx_packet.group(1))
> tx_packet = re.search("TX-packets:\s*(\d*)", out)
> diff --git a/tests/TestSuite_vhost_pmd_xstats.py
> b/tests/TestSuite_vhost_pmd_xstats.py
> index a58c107..1e1a323 100755
> --- a/tests/TestSuite_vhost_pmd_xstats.py
> +++ b/tests/TestSuite_vhost_pmd_xstats.py
> @@ -126,7 +126,7 @@ class TestVhostPmdXstats(TestCase):
> self.scapy_num += 1
> pkt = Packet(pkt_type='TCP', pkt_len=pktsize)
> pkt.config_layer('ether', {'dst': dmac, })
> - pkt.send_pkt(tx_port=self.txItf, count=num)
> + pkt.send_pkt(self.tester, tx_port=self.txItf, count=num)
>
> def send_verify(self, scope, mun):
> """
> diff --git a/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> b/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> index d31122b..0eeb42e 100644
> --- a/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> +++ b/tests/TestSuite_vhost_virtio_pmd_interrupt.py
> @@ -38,7 +38,7 @@ import utils
> import time
> from virt_common import VM
> from test_case import TestCase
> -from packet import Packet, save_packets
> +from packet import Packet
> from pktgen import PacketGeneratorHelper
>
>
> @@ -234,7 +234,7 @@ class TestVhostVirtioPmdInterrupt(TestCase):
> else:
> pkt = Packet(pkt_type='IP_RAW')
> pkt.config_layer('ether', {'dst': '%s' % self.dst_mac})
> - save_packets([pkt], "%s/interrupt.pcap" % self.out_path)
> + pkt.save_pcapfile(self.tester, "%s/interrupt.pcap" % self.out_path)
> tgen_input.append((self.tx_port, self.tx_port, "%s/interrupt.pcap" %
> self.out_path))
> self.tester.pktgen.clear_streams()
> vm_config = self.set_fields()
> diff --git a/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> b/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> index d89a93d..6f6aa19 100644
> --- a/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> +++ b/tests/TestSuite_virtio_ipsec_cryptodev_func.py
> @@ -247,7 +247,7 @@ class VirtioCryptodevIpsecTest(TestCase):
> def send_and_dump_pkg(self):
> status = True
>
> - inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=25)
> + inst = self.tester.tcpdump_sniff_packets(self.rx_interface)
>
> PACKET_COUNT = 65
> payload = 256 * ['11']
> @@ -261,21 +261,19 @@ class VirtioCryptodevIpsecTest(TestCase):
> pkt.config_layer("ipv4", {"src": src_ip, "dst": dst_ip})
> pkt.config_layer("udp", {"dst": 0})
> pkt.config_layer("raw", {"payload": payload})
> - pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
> + pkt.send_pkt(self.tester, tx_port=self.tx_interface,
> count=PACKET_COUNT)
>
> pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
> self.logger.info("dump: {} packets".format(len(pkt_rec)))
> if len(pkt_rec) != PACKET_COUNT:
> self.logger.info("dump pkg: {}, the num of pkg dumped is
> incorrtct!".format(len(pkt_rec)))
> status = False
> -
> - for pkt_r in pkt_rec:
> - #pkt_r.pktgen.pkt.show()
> - if src_ip != pkt_r.pktgen.strip_layer3("src") or dst_ip !=
> pkt_r.pktgen.strip_layer3("dst"):
> + for i in range(len(pkt_rec)):
> + if src_ip != pkt_rec.pktgen.strip_layer3("src", p_index=i) or dst_ip !=
> pkt_rec.pktgen.strip_layer3("dst", p_index=i):
> self.logger.info("the ip of pkg dumped is incorrtct!")
> status = False
>
> - dump_text =
> binascii.b2a_hex(pkt_r.pktgen.pkt["Raw"].getfieldval("load"))
> + dump_text = binascii.b2a_hex(pkt_rec[i]["Raw"].getfieldval("load"))
> if dump_text != ''.join(payload):
> self.logger.info("the text of pkg dumped is incorrtct!")
> status = False
> diff --git a/tests/TestSuite_vlan.py b/tests/TestSuite_vlan.py
> index 9c58b0c..77c33d0 100644
> --- a/tests/TestSuite_vlan.py
> +++ b/tests/TestSuite_vlan.py
> @@ -86,8 +86,8 @@ class TestVlan(TestCase):
> def get_tcpdump_package(self):
> pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
> vlans = []
> - for packet in pkts:
> - vlan = packet.strip_element_vlan("vlan")
> + for i in range(len(pkts)):
> + vlan = pkts.strip_element_vlan("vlan", p_index=i)
> vlans.append(vlan)
> return vlans
>
> @@ -116,7 +116,7 @@ class TestVlan(TestCase):
> pkt.config_layer('ether', {'dst': self.dmac, 'src': self.smac})
> pkt.config_layer('vlan', {'vlan': vid})
>
> - pkt.send_pkt(tx_port=self.txItf, count=4)
> + pkt.send_pkt(self.tester, tx_port=self.txItf, count=4)
>
> def set_up(self):
> """
> diff --git a/tests/TestSuite_vm2vm_virtio_pmd.py
> b/tests/TestSuite_vm2vm_virtio_pmd.py
> index 2db020f..da8f939 100644
> --- a/tests/TestSuite_vm2vm_virtio_pmd.py
> +++ b/tests/TestSuite_vm2vm_virtio_pmd.py
> @@ -42,7 +42,7 @@ import time
> import utils
> from virt_common import VM
> from test_case import TestCase
> -from packet import load_pcapfile
> +from packet import Packet
>
>
> class TestVM2VMVirtioPMD(TestCase):
> @@ -211,11 +211,12 @@ class TestVM2VMVirtioPMD(TestCase):
> vm_dut.send_expect('quit', '#', 60)
> time.sleep(2)
> vm_dut.session.copy_file_from(src="%s" % self.dump_pcap, dst="%s" %
> self.dump_pcap)
> - pkts = load_pcapfile(self.dump_pcap)
> + pkt = Packet()
> + pkts = pkt.read_pcapfile(self.dump_pcap)
> self.verify(len(pkts) == 10, "The vm0 do not capture all the packets")
> - data = str(pkts[0].pktgen.pkt['Raw'])
> + data = str(pkts[0]['Raw'])
> for i in range(1, 10):
> - value = str(pkts[i].pktgen.pkt['Raw'])
> + value = str(pkts[i]['Raw'])
> self.verify(data == value, "the payload in receive packets has been
> changed")
>
> def stop_all_apps(self):
> diff --git a/tests/TestSuite_vxlan.py b/tests/TestSuite_vxlan.py
> index 2be5741..2046abe 100644
> --- a/tests/TestSuite_vxlan.py
> +++ b/tests/TestSuite_vxlan.py
> @@ -26,6 +26,7 @@ from scapy.route import *
> from test_case import TestCase
> from settings import HEADER_SIZE, FOLDERS
> from etgen import IxiaPacketGenerator
> +import packet
>
> #
> #
> @@ -48,6 +49,7 @@ class VxlanTestConfig(object):
> self.init()
> for name in kwargs:
> setattr(self, name, kwargs[name])
> + self.pkt_obj = packet.Packet()
>
> def init(self):
> self.packets_config()
> @@ -56,8 +58,8 @@ class VxlanTestConfig(object):
> """
> Default vxlan packet format
> """
> - self.pcap_file = '/root/vxlan.pcap'
> - self.capture_file = '/root/vxlan_capture.pcap'
> + self.pcap_file = packet.TMP_PATH + 'vxlan.pcap'
> + self.capture_file = packet.TMP_PATH + 'vxlan_capture.pcap'
> self.outer_mac_src = '00:00:10:00:00:00'
> self.outer_mac_dst = '11:22:33:44:55:66'
> self.outer_vlan = 'N/A'
> @@ -186,29 +188,28 @@ class VxlanTestConfig(object):
>
> return self.pkt
>
> - def get_chksums(self, pcap=None):
> + def get_chksums(self, pkt=None):
> """
> get chksum values of Outer and Inner packet L3&L4
> Skip outer udp for it will be calculated by software
> """
> chk_sums = {}
> - if pcap is None:
> - pkts = rdpcap(self.pcap_file)
> + if pkt is None:
> + pkt = rdpcap(self.pcap_file)
> else:
> - pkts = rdpcap(pcap)
> + pkt = pkt.pktgen.pkt
>
> time.sleep(1)
> -
> - if pkts[0].guess_payload_class(pkts[0]).name == "802.1Q":
> - payload = pkts[0][Dot1Q]
> + if pkt[0].guess_payload_class(pkt[0]).name == "802.1Q":
> + payload = pkt[0][Dot1Q]
> else:
> - payload = pkts[0]
> + payload = pkt[0]
>
> if payload.guess_payload_class(payload).name == "IP":
> chk_sums['outer_ip'] = hex(payload[IP].chksum)
>
> - if pkts[0].haslayer('VXLAN') == 1:
> - inner = pkts[0]['VXLAN']
> + if pkt[0].haslayer('VXLAN') == 1:
> + inner = pkt[0]['VXLAN']
> if inner.haslayer(IP) == 1:
> chk_sums['inner_ip'] = hex(inner[IP].chksum)
> if inner[IP].proto == 6:
> @@ -236,16 +237,10 @@ class VxlanTestConfig(object):
> """
> Send vxlan pcap file by iface
> """
> - # load vxlan module to scapy
> - cwd = os.getcwd()
> - dir_vxlan_module = cwd + r'/' + FOLDERS['Depends']
> - self.test_case.tester.scapy_append("sys.path.append('%s')" %
> dir_vxlan_module)
> - self.test_case.tester.scapy_append("from vxlan import VXLAN")
> - self.test_case.tester.scapy_append(
> - 'pcap = rdpcap("%s")' % self.pcap_file)
> - self.test_case.tester.scapy_append(
> - 'sendp(pcap, iface="%s")' % iface)
> - self.test_case.tester.scapy_execute()
> + del self.pkt_obj.pktgen.pkts[:]
> + self.pkt_obj.pktgen.assign_pkt(self.pkt)
> + self.pkt_obj.pktgen.update_pkts()
> + self.pkt_obj.send_pkt(crb=self.test_case.tester, tx_port=iface)
>
> def pcap_len(self):
> """
> @@ -262,12 +257,10 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> vxlan Prerequisites
> """
> # this feature only enable in FVL now
> - if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortville_25g", "fortpark_TLV", "carlsville"]:
> + if self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single",
> "fortville_25g", "fortpark_TLV"]:
> self.compile_switch = 'CONFIG_RTE_LIBRTE_I40E_INC_VECTOR'
> elif self.nic in ["sageville", "sagepond"]:
> self.compile_switch = 'CONFIG_RTE_IXGBE_INC_VECTOR'
> - elif self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> else:
> self.verify(False, "%s not support this vxlan" % self.nic)
> # Based on h/w type, choose how many ports to use
> @@ -448,20 +441,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> config.outer_mac_dst = self.dut_port_mac
> config.create_pcap()
>
> - # remove tempory files
> - config.capture_file = "/tmp/sniff_%s.pcap" % self.recv_iface
> - self.tester.send_expect("rm -rf %s" % config.capture_file, "# ")
> # save the capture packet into pcap format
> - self.tester.scapy_background()
> -
> - inst = self.tester.tcpdump_sniff_packets(self.recv_iface, timeout=5)
> + inst = self.tester.tcpdump_sniff_packets(self.recv_iface)
> config.send_pcap(self.tester_iface)
> - self.tester.load_tcpdump_sniff_packets(inst)
> + pkt = self.tester.load_tcpdump_sniff_packets(inst)
> time.sleep(5)
>
> # extract the checksum offload from saved pcap file
> - chksums = config.get_chksums(pcap=config.capture_file)
> - os.remove(config.capture_file)
> + chksums = config.get_chksums(pkt=pkt)
> self.logger.info("chksums" + str(chksums))
>
> out = self.dut.send_expect("stop", "testpmd>", 10)
> @@ -535,19 +522,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> """
> verify vxlan packet detection
> """
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - src_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model == 'y':
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=n/' config/common_base" % self.compile_switch,
> "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + src_vec_model = re.search("%s=." % self.compile_switch, out).group()[-
> 1]
> + if src_vec_model == 'y':
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=n/' config/common_base" % self.compile_switch,
> "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> -
> pmd_temp = "./%(TARGET)s/app/testpmd -c %(COREMASK)s -n " + \
> "%(CHANNEL)d -- -i --disable-rss --rxq=4 --txq=4" + \
> " --nb-cores=4 --portmask=%(PORT)s"
> @@ -561,8 +543,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("set verbose 1", "testpmd>", 10)
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
>
> # check normal packet
> self.send_and_detect(outer_udp_dst=1234)
> @@ -579,33 +559,26 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
>
> out = self.dut.send_expect("stop", "testpmd>", 10)
> self.dut.send_expect("quit", "#", 10)
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model != dst_vec_model:
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> +
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> + if src_vec_model != dst_vec_model:
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> def test_vxlan_ipv6_detect(self):
> """
> verify vxlan packet detection with ipv6 header
> """
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - src_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model == 'y':
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=n/' config/common_base" % self.compile_switch,
> "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + src_vec_model = re.search("%s=." % self.compile_switch, out).group()[-
> 1]
> + if src_vec_model == 'y':
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=n/' config/common_base" % self.compile_switch,
> "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> pmd_temp = "./%(TARGET)s/app/testpmd -c %(COREMASK)s -n " + \
> "%(CHANNEL)d -- -i --disable-rss --rxq=4 --txq=4" + \
> @@ -620,8 +593,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("set verbose 1", "testpmd>", 10)
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
>
> # check normal ipv6 packet
> self.send_and_detect(outer_ip6_src="FE80:0:0:0:0:0:0:0",
> @@ -642,17 +613,14 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
>
> out = self.dut.send_expect("stop", "testpmd>", 10)
> self.dut.send_expect("quit", "#", 10)
> - if self.nic in ["columbiaville_25g","columbiaville_100g"]:
> - print "CVL support default none VECTOR"
> - src_vec_model = 'n'
> - else:
> - out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> - dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> - if src_vec_model != dst_vec_model:
> - self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> - + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> - self.dut.skip_setup = False
> - self.dut.build_install_dpdk(self.target)
> +
> + out = self.dut.send_expect("cat config/common_base", "]# ", 10)
> + dst_vec_model = re.findall("%s=." % self.compile_switch, out)[0][-1]
> + if src_vec_model != dst_vec_model:
> + self.dut.send_expect("sed -i -e 's/%s=.*$/" % self.compile_switch
> + + "%s=%s/' config/common_base" % (self.compile_switch,
> src_vec_model), "# ", 30)
> + self.dut.skip_setup = False
> + self.dut.build_install_dpdk(self.target)
>
> def test_vxlan_ipv4_checksum_offload(self):
> """
> @@ -682,9 +650,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("port start all", "testpmd>")
> self.dut.send_expect("csum parse-tunnel on %d" %
> self.recv_port, "testpmd>", 10)
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
> -
>
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> @@ -759,7 +724,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
>
> self.enable_vxlan(self.dut_port)
> self.enable_vxlan(self.recv_port)
> - time.sleep(10) #lwj
>
> # check normal ipv6 packet
> self.send_and_check(outer_ip6_src="FE80:0:0:0:0:0:0:0",
> @@ -1169,8 +1133,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("port start all", "testpmd>")
> self.verify("Bad arguments" not in out, "Failed to set vxlan csum")
> self.verify("error" not in out, "Failed to set vxlan csum")
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
>
> def csum_set_sw(self, proto, port):
> self.dut.send_expect("port stop all", "testpmd>")
> @@ -1179,9 +1141,6 @@ class TestVxlan(TestCase, IxiaPacketGenerator):
> self.dut.send_expect("port start all", "testpmd>")
> self.verify("Bad arguments" not in out, "Failed to set vxlan csum")
> self.verify("error" not in out, "Failed to set vxlan csum")
> - res = self.pmdout.wait_link_status_up("all")
> - self.verify(res is True, "link is donw")
> -
>
> def tunnel_filter_add(self, *args):
> # tunnel_filter add port_id outer_mac inner_mac ip inner_vlan
> diff --git a/tests/TestSuite_vxlan_sample.py
> b/tests/TestSuite_vxlan_sample.py
> index 5bc9269..df7bbcf 100644
> --- a/tests/TestSuite_vxlan_sample.py
> +++ b/tests/TestSuite_vxlan_sample.py
> @@ -48,7 +48,7 @@ from etgen import IxiaPacketGenerator
> from qemu_kvm import QEMUKvm
> from TestSuite_vxlan import VxlanTestConfig
> from pmd_output import PmdOutput
> -from packet import IncreaseIP, IncreaseIPv6
> +from packet import Packet
>
> from scapy.utils import wrpcap, rdpcap
> from scapy.layers.inet import Ether, IP, TCP, UDP
> @@ -106,7 +106,6 @@ class TestVxlanSample(TestCase):
>
> # params for tep_termination
> self.cores = self.dut.get_core_list("1S/4C/1T", socket=self.socket)
> - self.capture_file = "/tmp/vxlan_cap.pcap"
> self.def_mss = 256
>
> # performance measurement, checksum based on encap
> @@ -266,32 +265,18 @@ class TestVxlanSample(TestCase):
> self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_tcp_tso")
>
> def start_capture(self, itf, pkt_smac="", pkt_dmac="", count=1):
> - self.tester.send_expect("rm -f %s" % self.capture_file, "# ")
> - self.tester.scapy_background()
> + self.inst = None
> + filter_param = []
> if pkt_smac != "":
> - self.tester.scapy_append(
> - 'p = sniff(filter="ether src %s",' % pkt_smac +
> - 'iface="%s", count=%d, timeout=5)' % (itf, count))
> - if pkt_dmac != "":
> - self.tester.scapy_append(
> - 'p = sniff(filter="ether dst %s",' % pkt_dmac +
> - 'iface="%s", count=%d, timeout=5)' % (itf, count))
> - self.tester.scapy_append(
> - 'wrpcap(\"%s\", p)' % self.capture_file)
> - self.tester.scapy_foreground()
> + filter_param = [{'layer': 'ether', 'config': {'src': '%s' % pkt_smac}}]
> + if pkt_dmac != "":
> + filter_param = [{'layer': 'ether', 'config': {'dst': '%s' % pkt_dmac}}]
> + self.inst = self.tester.tcpdump_sniff_packets(itf, count,
> filters=filter_param)
>
> def transfer_capture_file(self):
> # copy capture file from tester
> - if os.path.isfile('vxlan_cap.pcap'):
> - os.remove('vxlan_cap.pcap')
> - self.tester.session.copy_file_from(self.capture_file)
> -
> - if os.path.isfile('vxlan_cap.pcap'):
> - self.verify(os.path.getsize('vxlan_cap.pcap') != 0, "Packets receive
> error")
> - pkts = rdpcap('vxlan_cap.pcap')
> - else:
> - pkts = []
> - return pkts
> + pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
> + return pkts.pktgen.pkts
>
> def send_and_verify(self, vm_id, vf_id, pkt_type):
> params = {}
> @@ -430,7 +415,10 @@ class TestVxlanSample(TestCase):
> self.verify(len(pkts) >= 1, "Failed to capture packets")
> self.verify(pkts[0].haslayer('VXLAN') == 1,
> "Packet not encapsulated")
> - chksums = vxlan_pkt.get_chksums(pcap='vxlan_cap.pcap')
> + pk_new = Packet()
> + pk_new.pktgen.assign_pkt(pkts)
> + pk_new.pktgen.update_pkts()
> + chksums = vxlan_pkt.get_chksums(pk_new)
> print utils.GREEN("Checksum : %s" % chksums)
> for key in chksums_ref:
> if 'inner' in key: # only check inner packet chksum
> --
> 2.17.1
^ permalink raw reply [flat|nested] 9+ messages in thread