From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 716A2A3160 for ; Sat, 12 Oct 2019 07:30:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6491C1EB91; Sat, 12 Oct 2019 07:30:50 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 38D441EB3F for ; Sat, 12 Oct 2019 07:30:48 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2019 22:30:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,286,1566889200"; d="scan'208";a="395972242" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga006.fm.intel.com with ESMTP; 11 Oct 2019 22:30:47 -0700 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 11 Oct 2019 22:30:47 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 11 Oct 2019 22:30:46 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.96]) by shsmsx102.ccr.corp.intel.com ([169.254.2.176]) with mapi id 14.03.0439.000; Sat, 12 Oct 2019 13:30:44 +0800 From: "Tu, Lijuan" To: "Xiao, QimaiX" , "dts@dpdk.org" CC: "Xiao, QimaiX" Thread-Topic: [dts] [PATCH V1] framework/tester: update tester module of dts Thread-Index: AQHVdRtlOG52Oc+abUeywswL4gIzSKdWkh+g Date: Sat, 12 Oct 2019 05:30:44 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BB3E9D6@SHSMSX101.ccr.corp.intel.com> References: <20190927180539.2344-1-qimaix.xiao@intel.com> <20190927180539.2344-3-qimaix.xiao@intel.com> In-Reply-To: <20190927180539.2344-3-qimaix.xiao@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYjVmZmNkMjQtMDA1OC00ZDQ4LThlZWQtN2E2NDZmMmIwMGJjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTFNpQkJTbGNsU041bFwveThJbjlpSEtXOHdTVlBTR2FiZUt3SVwveG5GSDBRN1BlS01tcllWYWhLamR0cjJWVXUwIn0= x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1] framework/tester: update tester module of dts X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" 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 > Subject: [dts] [PATCH V1] framework/tester: update tester module of dts >=20 > update APIs related to packet module and rewrite func check_random_pkts >=20 > Signed-off-by: Qimai Xiao > --- > framework/tester.py | 157 ++++++++++++-------------------------------- > 1 file changed, 43 insertions(+), 114 deletions(-) >=20 > 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 =3D 0 > self.pktgen =3D None > self.ixia_packet_gen =3D None > + self.tmp_file =3D '/tmp/tester/' > + out =3D self.send_expect('ls -d %s' % self.tmp_file, '# ', verif= y=3DTrue) > + if out =3D=3D 2: > + self.send_expect('mkdir -p %s' % self.tmp_file, '# ') > + >=20 > def init_ext_gen(self): > """ > @@ -639,12 +644,12 @@ class Tester(Crb): > else: > return None >=20 > - def parallel_transmit_ptks(self, send_f=3DNone, intf=3D'', pkts=3D[]= , > interval=3D0.01): > + def parallel_transmit_ptks(self, pkt=3DNone, intf=3D'', send_times= =3D1, > interval=3D0.01): > """ > Callable function for parallel processes > """ > print GREEN("Transmitting and sniffing packets, please wait few > minutes...") > - send_f(intf=3Dintf, pkts=3Dpkts, interval=3Dinterval) > + return pkt.send_pkt_bg(crb=3Dself, tx_port=3Dintf, > + count=3Dsend_times, loop=3D0, interval=3Dinterval) >=20 > def check_random_pkts(self, portList, pktnum=3D2000, interval=3D0.01= , > allow_miss=3DTrue, seq_check=3DFalse, params=3DNone): > """ > @@ -653,79 +658,49 @@ class Tester(Crb): > # load functions in packet module > module =3D __import__("packet") > pkt_c =3D getattr(module, "Packet") > - send_f =3D getattr(module, "send_packets") > compare_f =3D getattr(module, "compare_pktload") > strip_f =3D getattr(module, "strip_pktload") > - save_f =3D getattr(module, "save_packets") > tx_pkts =3D {} > rx_inst =3D {} > # packet type random between tcp/udp/ipv6 > random_type =3D ['TCP', 'UDP', 'IPv6_TCP', 'IPv6_UDP'] > - pkt_minlen =3D {'TCP': 64, 'UDP': 64, 'IPv6_TCP': 74, 'IPv6_UDP'= : 64} > - # at least wait 2 seconds > - timeout =3D int(pktnum * (interval + 0.01)) + 2 > for txport, rxport in portList: > - pkts =3D [] > txIntf =3D self.get_interface(txport) > rxIntf =3D self.get_interface(rxport) > print GREEN("Preparing transmit packets, please wait few min= utes...") > - for num in range(pktnum): > - # chose random packet > - pkt_type =3D random.choice(random_type) > - pkt =3D pkt_c(pkt_type=3Dpkt_type, > - pkt_len=3Drandom.randint(pkt_minlen[pkt_type= ], 1514), > - ran_payload=3DTrue) > - # config packet if has parameters > - if params and len(portList) =3D=3D len(params): > - for param in params: > - layer, config =3D param > - pkt.config_layer(layer, config) > - # hardcode src/dst port for some protocol may cause issu= e > - 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 =3D convert_int2ip(num, 6) > - pkt.config_layer('ipv6', {'src': ip_str}) > - else: > - ip_str =3D convert_int2ip(num, 4) > - pkt.config_layer('ipv4', {'src': ip_str}) > + pkt =3D pkt_c() > + pkt.generate_random_pkts(pktnum=3Dpktnum, > random_type=3Drandom_type, ip_increase=3DTrue, random_payload=3DTrue, > + options=3D{"layers_config": params}= ) >=20 > - pkts.append(pkt) > - tx_pkts[txport] =3D pkts > + tx_pkts[txport] =3D pkt > + # sniff packets > + inst =3D module.start_tcpdump(self, rxIntf, count=3Dpktnum, > + filters=3D[{'layer': 'network', = 'config': {'srcport': '65535'}}, > + {'layer': 'network', > + 'config': {'dstport': '65535'}}]) >=20 > - # send and sniff packets > - save_f(pkts=3Dpkts, filename=3D"/tmp/%s_tx.pcap" % txIntf) > - inst =3D self.tcpdump_sniff_packets(intf=3DrxIntf, count=3Dp= ktnum, > timeout=3Dtimeout, filters=3D > - [{'layer': 'network', 'config': {'srcport': '65535'}}, > - {'layer': 'network', 'config': {'dstport': '65535'}}]) > rx_inst[rxport] =3D inst > - > - # Transmit packet simultaneously > - processes =3D [] > + filenames =3D [] > for txport, _ in portList: > txIntf =3D self.get_interface(txport) > - processes.append(Process(target =3D self.parallel_transmit_p= tks, > - args=3D(send_f, txIntf, tx_pkts[txport], in= terval))) > - > - for transmit_proc in processes: > - transmit_proc.start() > - > - for transmit_proc in processes: > - transmit_proc.join() > - > + > + filenames.append(self.parallel_transmit_ptks(pkt=3Dtx_pkts[txport], > + intf=3DtxIntf, send_times=3D1, interval=3Dinterval)) > # Verify all packets > + sleep(interval * pktnum + 1) > + flag =3D True > + while flag: > + for i in filenames: > + flag =3D self.send_expect('ps -ef |grep %s|grep -v grep'= % i, > expected=3D'# ') > + if flag: > + print('wait for the completion of sending pkts...') > + sleep(1.5) > + continue > prev_id =3D -1 > for txport, rxport in portList: > - recv_pkts =3D self.load_tcpdump_sniff_packets(rx_inst[rxport= ]) > - > + p =3D module.stop_and_load_tcpdump_packets(rx_inst[rxport]) > + recv_pkts =3D 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 >=20 > @@ -733,9 +708,9 @@ class Tester(Crb): > print GREEN("Comparing sniffed packets, please wait few minu= tes...") > for idx in range(len(recv_pkts)): > try: > - l3_type =3D recv_pkts[idx].strip_element_layer2('typ= e') > - sip =3D recv_pkts[idx].strip_element_layer3('src') > - except: > + l3_type =3D p.strip_element_layer2('type', p_index= =3Didx) > + sip =3D p.strip_element_layer3('dst', p_index=3Didx) > + except Exception as e: > continue > # ipv4 packet > if l3_type =3D=3D 2048: > @@ -753,10 +728,10 @@ class Tester(Crb): > else: > prev_id =3D t_idx >=20 > - 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_pk= ts[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 >=20 > @@ -776,70 +751,24 @@ class Tester(Crb): > instance.__dict__ =3D self.ixia_packet_gen.__dict__ > instance.__dict__.update(current_attrs) >=20 > - def sendpkt_bg(self, localPort, dst_mac): > - """ > - loop to Send packet in background, should call stop_sendpkt_bg t= o stop > it. > - """ > - itf =3D self.get_interface(localPort) > - src_mac =3D self.get_mac(localPort) > - script_str =3D "from scapy.all import *\n" + \ > - "sendp([Ether(dst=3D'%s', src=3D'%s')/IP(len=3D46)]= , iface=3D'%s', > loop=3D1)\n" % (dst_mac, src_mac, itf) > - > - self.send_expect("rm -fr send_pkg_loop.py", "# ") > - f =3D open("send_pkt_loop.py", "w") > - f.write(script_str) > - f.close() > - > - self.proc =3D 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 =3D None > - > - def tcpdump_sniff_packets(self, intf, count=3D0, timeout=3D5, filter= s=3D[]): > + def tcpdump_sniff_packets(self, intf, count=3D0, filters=3DNone, > lldp_forbid=3DTrue): > """ > Wrapper for packet module sniff_packets > """ > # load functions in packet module > - module =3D __import__("packet") > - sniff_f =3D getattr(module, "sniff_packets") > - > - target=3D[] > - 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=3D''): > - """ > - Wrapper for packet module load_sniff_pcap > - """ > - # load functions in packet module > - module =3D __import__("packet") > - load_pcap_f =3D getattr(module, "load_sniff_pcap") > - > - target=3D[] > - target.append(self.get_ip_address()) > - target.append(self.get_username()) > - target.append(self.get_password()) > - pcap =3D load_pcap_f(index, target) > - self.session.copy_file_from(pcap) > - > - return pcap.split(os.sep)[-1] > + packet =3D __import__("packet") > + inst =3D packet.start_tcpdump(self, intf=3Dintf, count=3Dcount, = filters=3Dfilters, > lldp_forbid=3Dlldp_forbid) > + return inst >=20 > - def load_tcpdump_sniff_packets(self, index=3D''): > + def load_tcpdump_sniff_packets(self, index=3D'', timeout=3D1): > """ > Wrapper for packet module load_pcapfile > """ > # load functions in packet module > packet =3D __import__("packet") > - file =3D self.load_tcpdump_sniff_pcap(index) > + p =3D packet.stop_and_load_tcpdump_packets(index, > + timeout=3Dtimeout) >=20 > - return packet.load_pcapfile(file) > + return p >=20 > def kill_all(self, killall=3DFalse): > """ > -- > 2.17.1