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 DCAC6A04AA; Tue, 8 Sep 2020 05:51:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D4F741C196; Tue, 8 Sep 2020 05:51:35 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 827021C134 for ; Tue, 8 Sep 2020 05:51:34 +0200 (CEST) IronPort-SDR: BEuT44m2lnX5ZIhexpuYhq5GmsyvZTH4iqSWJF+OQyppX+7/UkHriBowojeJT5oGqBjkZTfIc4 7VWnNJ1UMarQ== X-IronPort-AV: E=McAfee;i="6000,8403,9737"; a="158088236" X-IronPort-AV: E=Sophos;i="5.76,404,1592895600"; d="scan'208";a="158088236" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2020 20:51:33 -0700 IronPort-SDR: b5b7x+WS3EtnpORLxWO3tkBcdZ7sTk1QccyERgf5iwgj0daC+oVD533osKW6cHOvHeN3wPmV+t FbJUwHmhOlwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,404,1592895600"; d="scan'208";a="407003009" Received: from unknown (HELO localhost.localdomain) ([10.240.183.52]) by fmsmga001.fm.intel.com with ESMTP; 07 Sep 2020 20:51:32 -0700 From: Xiao Qimai To: dts@dpdk.org Cc: Xiao Qimai Date: Tue, 8 Sep 2020 03:26:42 +0000 Message-Id: <20200908032645.11852-5-qimaix.xiao@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908032645.11852-1-qimaix.xiao@intel.com> References: <20200908032645.11852-1-qimaix.xiao@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dts] [PATCH V1 4/7]framework/tester: prepare packet send session and update other packet related part 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" Signed-off-by: Xiao Qimai --- framework/tester.py | 70 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/framework/tester.py b/framework/tester.py index f55818e3..ca179b28 100644 --- a/framework/tester.py +++ b/framework/tester.py @@ -46,9 +46,9 @@ import random from utils import GREEN, convert_int2ip, convert_ip2int from exception import ParameterInvalidException from multiprocessing import Process - from pktgen import getPacketGenerator from config import PktgenConf +from packet import SCAPY_IMP_CMD class Tester(Crb): @@ -64,6 +64,7 @@ class Tester(Crb): def __init__(self, crb, serializer): self.NAME = 'tester' + self.scapy_session = None super(Tester, self).__init__(crb, serializer, self.NAME) self.bgProcIsRunning = False @@ -75,11 +76,34 @@ class Tester(Crb): self.re_run_time = 0 self.pktgen = None self.ixia_packet_gen = None + self.tmp_scapy_module_dir = '/tmp/dep' + # prepare for scapy env + self.scapy_sessions_li = list() + self.scapy_session = self.prepare_scapy_env() 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 prepare_scapy_env(self): + session_name = 'tester_scapy' if not self.scapy_sessions_li else f'tester_scapy_{random.random()}' + session = self.create_session(session_name) + self.scapy_sessions_li.append(session) + session.send_expect('scapy', '>>> ') + file_dir = os.path.dirname(__file__).split(os.path.sep) + lib_path = os.path.sep.join(file_dir[:-1]) + '/dep/scapy_modules/' + exists_flag = self.alt_session.session.send_expect(f'ls {self.tmp_scapy_module_dir}', '# ', verify=True) + if exists_flag == 2: + self.alt_session.session.send_expect(f'mkdir -p {self.tmp_scapy_module_dir}', '# ', verify=True) + scapy_modules_path = [lib_path+i for i in os.listdir(lib_path) if i.endswith('.py')] + path = ' '.join(scapy_modules_path) + session.copy_file_to(src=path, dst=self.tmp_scapy_module_dir) + session.session.send_expect(f"sys.path.append('{self.tmp_scapy_module_dir}')", ">>> ") + + out = session.session.send_expect(SCAPY_IMP_CMD, '>>> ') + if 'ImportError' in out: + session.logger.warning(f'entering import error: {out}') + return session def init_ext_gen(self): """ @@ -688,7 +712,7 @@ class Tester(Crb): Callable function for parallel processes """ print(GREEN("Transmitting and sniffing packets, please wait few minutes...")) - return pkt.send_pkt_bg(crb=self, tx_port=intf, count=send_times, loop=0, interval=interval) + return pkt.send_pkt_bg_with_pcapfile(crb=self, tx_port=intf, count=send_times, loop=0, inter=interval) def check_random_pkts(self, portList, pktnum=2000, interval=0.01, allow_miss=True, seq_check=False, params=None): """ @@ -716,22 +740,28 @@ class Tester(Crb): inst = module.start_tcpdump(self, rxIntf, count=pktnum, filters=[{'layer': 'network', 'config': {'srcport': '65535'}}, {'layer': 'network', 'config': {'dstport': '65535'}}]) - rx_inst[rxport] = inst - filenames = [] + bg_sessions = list() for txport, _ in portList: txIntf = self.get_interface(txport) - filenames.append(self.parallel_transmit_ptks(pkt=tx_pkts[txport], intf=txIntf, send_times=1, interval=interval)) + bg_sessions.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: + timeout = 60 + for i in bg_sessions: + while timeout: + try: + i.send_expect('', '>>> ', timeout=1) + except Exception as e: + print(e) self.logger.info('wait for the completion of sending pkts...') - sleep(1.5) + timeout -= 1 continue + else: + break + else: + self.logger.info('exceeded timeout, force to stop background packet sending to avoid dead loop') + pkt_c.stop_send_pkt_bg(i) prev_id = -1 for txport, rxport in portList: p = module.stop_and_load_tcpdump_packets(rx_inst[rxport]) @@ -814,7 +844,9 @@ class Tester(Crb): Kill all scapy process or DPDK application on tester. """ if not self.has_external_traffic_generator(): - self.alt_session.send_expect('killall scapy 2>/dev/null; echo tester', '# ', 5) + out = self.session.send_command('') + if '>>>' in out: + self.session.send_expect('quit()', '# ', timeout=3) if killall: super(Tester, self).kill_all() @@ -833,12 +865,20 @@ class Tester(Crb): self.ixia_packet_gen.close() self.ixia_packet_gen = None - if self.session: - self.session.close() - self.session = None + if self.scapy_sessions_li: + for i in self.scapy_sessions_li: + if i.session.isalive(): + i.session.send_expect("^c", ">>> ", timeout=2) + i.session.send_expect("^d", "#", timeout=2) + i.session.close() + self.scapy_sessions_li.clear() + if self.alt_session: self.alt_session.close() self.alt_session = None + if self.session: + self.session.close() + self.session = None def crb_exit(self): """ -- 2.25.1