From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 0B4DC7ED0 for ; Wed, 18 Apr 2018 08:23:15 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2018 23:23:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,464,1517904000"; d="scan'208";a="51655304" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga002.jf.intel.com with ESMTP; 17 Apr 2018 23:23:13 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 17 Apr 2018 23:23:13 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 17 Apr 2018 23:23:13 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.40]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.210]) with mapi id 14.03.0319.002; Wed, 18 Apr 2018 14:23:11 +0800 From: "Liu, Yong" To: Phil Yang , "dts@dpdk.org" CC: "nd@arm.com" Thread-Topic: [PATCH v4] framwork/packet: sniff_packet specify running target support Thread-Index: AQHT0kQfr6Wb/Ztdo0uAHUGdHzgDpKQGFJHw Date: Wed, 18 Apr 2018 06:23:10 +0000 Message-ID: <86228AFD5BCD8E4EBFD2B90117B5E81E63011A25@SHSMSX101.ccr.corp.intel.com> References: <1522640786-26646-1-git-send-email-phil.yang@arm.com> <1523526771-7437-1-git-send-email-phil.yang@arm.com> In-Reply-To: <1523526771-7437-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: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjdlZDIxM2QtOTE0ZC00YTZkLTkwZjItMzc2MjgxYzMwYmUzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJrdWVGanJ0Q2RpdFwvRW1ZWG54UERFd2pOeFRPSGd1Zmk3bVNZbGtGbDZcL2JcL3VVZEVLcmxSdlMwblRkdFVkQTIxIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action 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 v4] framwork/packet: sniff_packet specify running target support 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: Wed, 18 Apr 2018 06:23:16 -0000 Hi Phil, I tried your patch set and met such issues.=20 1. load_sniff_packet function will send signal to child process to stop sni= ff. But this method will not work with remote ssh. After received signal on= ly ssh process is exited and meanwhile tcpdump process is still alive. 2. In v3 patch set, code for import packet module has been remove. That wil= l cause some suites can't run. Thanks, Marvin > -----Original Message----- > From: Phil Yang [mailto:phil.yang@arm.com] > Sent: Thursday, April 12, 2018 5:53 PM > To: dts@dpdk.org > Cc: nd@arm.com; Liu, Yong > Subject: [PATCH v4] framwork/packet: sniff_packet specify running target > support >=20 > If tester in crb file was not the machine which running dts, > the sniff_packet process will not running on tester. >=20 > Create a ssh connection to the tester and run tcpdump to make sure > sniff_packet process running on the machine we expected. >=20 > Removed load_sniff_packets function in packet module as it will be > useless. >=20 > Signed-off-by: Phil Yang > Suggested-by: Marvin Liu > --- > framework/packet.py | 70 +++++++++++++++++++++--------------------------= - > ----- > framework/tester.py | 37 ++++++++++++++++++++++++++++ > 2 files changed, 65 insertions(+), 42 deletions(-) >=20 > diff --git a/framework/packet.py b/framework/packet.py > index 976b82b..f99ead8 100755 > --- a/framework/packet.py > +++ b/framework/packet.py > @@ -812,15 +812,30 @@ 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) > + > + # target[] contain the remote machine info for ssh connection > + # target[0]: username > + # target[1]: ip address > + # target[2]: pass word > + if target: > + tcpdump_help_pipe =3D subprocess.Popen(["ssh", > + "%s@%s" % (target[0], target[1]), > + "tcpdump -h"], > + stderr=3Dsubprocess.PIPE, > + stdout=3Dsubprocess.PIPE, > + shell=3DFalse) > + tcpdump_help =3D "".join(tuple(tcpdump_help_pipe.communicate())) > + tcpdump_help_pipe.wait() > + else: > + tcpdump_help =3D subprocess.check_output("tcpdump -h; echo 0", > + stderr=3Dsubprocess.STDOUT, shell=3D= True) > + > for line in tcpdump_help.split('\n'): > m =3D re.match(direct_param, line) > if m: > @@ -850,9 +865,16 @@ def sniff_packets(intf, count=3D0, timeout=3D5, > filters=3D[]): > else: > cmd =3D sniff_cmd % options >=20 > - args =3D shlex.split(cmd) > + if target: > + pipe =3D subprocess.Popen(["ssh", > + "%s@%s" % (target[0], target[1]), > + cmd], > + stdin=3Dsubprocess.PIPE, > + shell=3DFalse) > + else: > + args =3D shlex.split(cmd) > + pipe =3D subprocess.Popen(args) >=20 > - pipe =3D subprocess.Popen(args) > index =3D str(time.time()) > SNIFF_PIDS[index] =3D (pipe, intf, timeout) > time.sleep(1) > @@ -886,42 +908,6 @@ def load_sniff_pcap(index=3D''): > return "" >=20 >=20 > -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: > - child_exit =3D True > - break > - > - time.sleep(1) > - time_elapse +=3D 1 > - > - if not child_exit: > - pipe.send_signal(signal.SIGINT) > - pipe.wait() > - > - # 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 pkts > - > - > def load_pcapfile(filename=3D""): > pkts =3D [] > try: > diff --git a/framework/tester.py b/framework/tester.py > index a775f68..c787b89 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 > @@ -704,6 +705,42 @@ 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_username()) > + target.append(self.get_ip_address()) > + 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") > + pcap =3D load_pcap_f(index) > + 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_sniff_packets > + """ > + # 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