From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 75C581B456 for ; Tue, 23 Oct 2018 11:44:27 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2018 02:44:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,415,1534834800"; d="scan'208";a="268030830" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga005.jf.intel.com with ESMTP; 23 Oct 2018 02:44:26 -0700 Received: from fmsmsx121.amr.corp.intel.com (10.18.125.36) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 23 Oct 2018 02:44:26 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx121.amr.corp.intel.com (10.18.125.36) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 23 Oct 2018 02:44:25 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.46]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.131]) with mapi id 14.03.0319.002; Tue, 23 Oct 2018 17:44:23 +0800 From: "Tu, Lijuan" To: "phil.yang@arm.com" , "dts@dpdk.org" CC: "nd@arm.com" Thread-Topic: [PATCH v7] framework/packet: support packet sniffer to specify running machine Thread-Index: AQHUZ43J7yxbjCW+yEi0AqS2jMwpbKUsmsbA Date: Tue, 23 Oct 2018 09:44:23 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0B996DB8@SHSMSX101.ccr.corp.intel.com> References: <1539670802-15603-1-git-send-email-phil.yang@arm.com> <1539941101-7773-1-git-send-email-phil.yang@arm.com> In-Reply-To: <1539941101-7773-1-git-send-email-phil.yang@arm.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.0.400.15 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNGYwZTJlMzUtYTA5NS00MGI2LWE4ZTktOThkYTZlNjJhNDZjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiS1ZRU0NweENHV3JBeVwvd245dmtaRkZnNkZVNzZnM3dBenMyd0NCR25FdmVLbjcrK2JYbzNROGRGQUg3UWRtYVkifQ== 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 v7] framework/packet: support packet sniffer to specify running machine 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: , X-List-Received-Date: Tue, 23 Oct 2018 09:44:28 -0000 Applied, thanks > -----Original Message----- > From: phil.yang@arm.com [mailto:phil.yang@arm.com] > Sent: Friday, October 19, 2018 5:25 PM > To: dts@dpdk.org > Cc: nd@arm.com; Tu, Lijuan > Subject: [PATCH v7] framework/packet: support packet sniffer to specify > running machine >=20 > By default, the Tester is supposed to be the server which running DTS and= the > packet sniff methods are running on it. > However, if DTS was not running on the Tester and the Tester is another > remote server, so packet sniff methods cannot sniff Tester's packets > correctly. >=20 > This patch adds support for packet sniff methods to specify running machi= ne > and implements sniff packet methods in class tester. >=20 > 1. Add parameter to sniff_packet and load_sniff_pcap methods to specify > the running machine. > 2. Remove load_sniff_packets method in packet.py. > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and > load_tcpdump_sniff_packets for class tester with the new sniff_packet API= . > 4. Update tester.check_random_pkts method with > tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to > make it execution on the Tester. >=20 > Signed-off-by: Phil Yang > Suggested-by: Marvin Liu > Suggested-by: Tu Lijuan > --- > framework/packet.py | 97 > +++++++++++++++++++++++++---------------------------- > framework/tester.py | 48 +++++++++++++++++++++++--- > 2 files changed, 89 insertions(+), 56 deletions(-) >=20 > diff --git a/framework/packet.py b/framework/packet.py index > 976b82b..d5b8517 100755 > --- a/framework/packet.py > +++ b/framework/packet.py > @@ -33,7 +33,6 @@ > Generic packet create, transmit and analyze module Base on > scapy(python program for packet manipulation) """ > - > import os > import time > import sys > @@ -61,6 +60,7 @@ 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 >=20 > # load extension layers > exec_file =3D os.path.realpath(__file__) > @@ -812,15 +812,26 @@ def get_filter_cmd(filters=3D[]): > return "" >=20 >=20 > -def sniff_packets(intf, count=3D0, timeout=3D5, filters=3D[]): > +def sniff_packets(intf, count=3D0, timeout=3D5, filters=3D[], target=3D[= ]): > """ > sniff all packets for certain port in certain seconds > """ > param =3D "" > direct_param =3D r"(\s+)\[ (\S+) in\|out\|inout \]" > - tcpdump_help =3D subprocess.check_output("tcpdump -h; echo 0", > - > stderr=3Dsubprocess.STDOUT, > - shell=3DTrue) > + > + try: > + tcpdump_help_session=3Dpxssh.pxssh() > + tcpdump_help_session.login(server=3Dtarget[0], > username=3Dtarget[1], > + password=3Dtarget[2], > original_prompt=3D'[$#>]', > + login_timeout=3D20) > + tcpdump_help_session.sendline('tcpdump -h') > + tcpdump_help_session.prompt() > + tcpdump_help=3Dtcpdump_help_session.before > + tcpdump_help_session.logout() > + except pxssh.ExceptionPxssh as e: > + print ('pxssh failed on login.') > + print (e) > + > for line in tcpdump_help.split('\n'): > m =3D re.match(direct_param, line) > if m: > @@ -850,16 +861,24 @@ def sniff_packets(intf, count=3D0, timeout=3D5, > filters=3D[]): > else: > cmd =3D sniff_cmd % options >=20 > - args =3D shlex.split(cmd) > + try: > + tcpdump_session=3Dpxssh.pxssh() > + tcpdump_session.login(server=3Dtarget[0], username=3Dtarget[1], > + password=3Dtarget[2], > original_prompt=3D'[$#>]', > + login_timeout=3D20) > + tcpdump_session.sendline(cmd) > + pipe =3D tcpdump_session > + except pxssh.ExceptionPxssh as e: > + print ('pxssh failed on login.') > + print (e) >=20 > - pipe =3D subprocess.Popen(args) > index =3D str(time.time()) > SNIFF_PIDS[index] =3D (pipe, intf, timeout) > time.sleep(1) > return index >=20 >=20 > -def load_sniff_pcap(index=3D''): > +def load_sniff_pcap(index=3D'', target=3D[]): > """ > Stop sniffer and return pcap file > """ > @@ -868,58 +887,36 @@ def load_sniff_pcap(index=3D''): > pipe, intf, timeout =3D SNIFF_PIDS[index] > time_elapse =3D int(time.time() - float(index)) > while time_elapse < timeout: > - if pipe.poll() is not None: > + if pipe.prompt(timeout=3D1): > child_exit =3D True > break >=20 > - time.sleep(1) > time_elapse +=3D 1 >=20 > if not child_exit: > - pipe.send_signal(signal.SIGINT) > - pipe.wait() > - > - # wait pcap file ready > - time.sleep(1) > - return "/tmp/sniff_%s.pcap" % intf > - > - return "" > - > - > -def load_sniff_packets(index=3D''): > - """ > - Stop sniffer and return packet objects > - """ > - pkts =3D [] > - child_exit =3D False > - if index in SNIFF_PIDS.keys(): > - pipe, intf, timeout =3D SNIFF_PIDS[index] > - time_elapse =3D int(time.time() - float(index)) > - while time_elapse < timeout: > - if pipe.poll() is not None: > + try: > + # Stop Tcpdump on the target server > + tcpdump_quit_session=3Dpxssh.pxssh() > + tcpdump_quit_session.login(server=3Dtarget[0], > username=3Dtarget[1], > + password=3Dtarget[2], > original_prompt=3D'[$#>]', > + login_timeout=3D20) > + tcpdump_quit_session.sendline('kill -2 $(pidof > tcpdump)') > + tcpdump_quit_session.prompt() > + tcpdump_quit_session.logout() > child_exit =3D True > - break > + except pxssh.ExceptionPxssh as e: > + print ('pxssh failed on login.') > + print (e) >=20 > - time.sleep(1) > - time_elapse +=3D 1 > - > - if not child_exit: > - pipe.send_signal(signal.SIGINT) > - pipe.wait() > + # Close the Tcpdump_session > + pipe.prompt() > + pipe.logout() >=20 > # wait pcap file ready > time.sleep(1) > - try: > - cap_pkts =3D rdpcap("/tmp/sniff_%s.pcap" % intf) > - for pkt in cap_pkts: > - # packet gen should be scapy > - packet =3D Packet(tx_port=3Dintf) > - packet.pktgen.assign_pkt(pkt) > - pkts.append(packet) > - except: > - pass > + return "/tmp/sniff_%s.pcap" % intf >=20 > - return pkts > + return "" >=20 >=20 > def load_pcapfile(filename=3D""): > @@ -978,12 +975,8 @@ def strip_pktload(pkt=3DNone, layer=3D"L2"): >=20 > ############################################################## > ################# >=20 > ############################################################## > ################# > if __name__ =3D=3D "__main__": > - inst =3D sniff_packets("lo", timeout=3D5, filters=3D[{'layer': 'ethe= r', > - 'config': {'dst': 'FF:FF:FF:FF:FF:FF'}}]) > - inst =3D sniff_packets("lo", timeout=3D5) > pkt =3D Packet(pkt_type=3D'UDP') > pkt.send_pkt(tx_port=3D'lo') > - pkts =3D load_sniff_packets(inst) >=20 > pkt =3D Packet(pkt_type=3D'UDP', pkt_len=3D1500, ran_payload=3DTrue) > pkt.send_pkt(tx_port=3D'lo') > diff --git a/framework/tester.py b/framework/tester.py index > a775f68..4e651a1 100755 > --- a/framework/tester.py > +++ b/framework/tester.py > @@ -35,6 +35,7 @@ Interface for bulk traffic generators. >=20 > import re > import subprocess > +import os > from time import sleep > from settings import NICS, load_global_setting, PERF_SETTING from crb > import Crb @@ -560,8 +561,6 @@ class Tester(Crb): > module =3D __import__("packet") > pkt_c =3D getattr(module, "Packet") > send_f =3D getattr(module, "send_packets") > - sniff_f =3D getattr(module, "sniff_packets") > - load_f =3D getattr(module, "load_sniff_packets") > compare_f =3D getattr(module, "compare_pktload") > strip_f =3D getattr(module, "strip_pktload") > save_f =3D getattr(module, "save_packets") @@ -606,7 +605,7 @@ > class Tester(Crb): >=20 > # send and sniff packets > save_f(pkts=3Dpkts, filename=3D"/tmp/%s_tx.pcap" % txIntf) > - inst =3D sniff_f(intf=3DrxIntf, count=3Dpktnum, timeout=3Dti= meout, > filters=3D > + inst =3D self.tcpdump_sniff_packets(intf=3DrxIntf, > + count=3Dpktnum, timeout=3Dtimeout, filters=3D > [{'layer': 'network', 'config': {'srcport': '65535'}}, > {'layer': 'network', 'config': {'dstport': '65535'}}]) > rx_inst[rxport] =3D inst > @@ -627,7 +626,7 @@ class Tester(Crb): > # Verify all packets > prev_id =3D -1 > for txport, rxport in portList: > - recv_pkts =3D load_f(rx_inst[rxport]) > + recv_pkts =3D > + self.load_tcpdump_sniff_packets(rx_inst[rxport]) >=20 > # only report when recevied number not matched > if len(tx_pkts[txport]) > len(recv_pkts): > @@ -704,6 +703,47 @@ class Tester(Crb): > self.proc.kill() > self.proc =3D None >=20 > + def tcpdump_sniff_packets(self, intf, count=3D0, timeout=3D5, filter= s=3D[]): > + """ > + 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] > + > + def load_tcpdump_sniff_packets(self, index=3D''): > + """ > + Wrapper for packet module load_pcapfile > + """ > + # load functions in packet module > + packet =3D __import__("packet") > + file =3D self.load_tcpdump_sniff_pcap(index) > + > + return packet.load_pcapfile(file) > + > def kill_all(self, killall=3DFalse): > """ > Kill all scapy process or DPDK application on tester. > -- > 2.7.4