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 053DFA04C1; Fri, 22 Nov 2019 07:38:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E4B0A2C2B; Fri, 22 Nov 2019 07:38:12 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 6A3C02C23 for ; Fri, 22 Nov 2019 07:38:11 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 22:38:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,228,1571727600"; d="scan'208";a="232577140" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga004.fm.intel.com with ESMTP; 21 Nov 2019 22:38:10 -0800 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 21 Nov 2019 22:38:10 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 21 Nov 2019 22:38:10 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.213]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.248]) with mapi id 14.03.0439.000; Fri, 22 Nov 2019 14:38:08 +0800 From: "Tu, Lijuan" To: "Xiao, QimaiX" , "dts@dpdk.org" CC: "Xiao, QimaiX" Thread-Topic: [dts] [PATCH V1] framework/packet: add function update_pkt Thread-Index: AQHVoDoTe08WJgR960WnJ/68IWW2YKeWvk1Q Date: Fri, 22 Nov 2019 06:38:07 +0000 Message-ID: <8CE3E05A3F976642AAB0F4675D0AD20E0BB67997@SHSMSX101.ccr.corp.intel.com> References: <1574320079-39675-1-git-send-email-qimaix.xiao@intel.com> In-Reply-To: <1574320079-39675-1-git-send-email-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: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDUyYzUyNmQtMmJjNC00ZDcwLWIyZjYtOTVkNGQ5NzE1NWMxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiZDhUSVArb01xSHVYTzdZNmlZK1NjRXM5YWRNUSt6Y0pzNzFzbHdsekJKUjZKUkNNUHozRXhxZDRmYlFMVzEzWCJ9 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/packet: add function update_pkt 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 Xiao Qimai > Sent: Thursday, November 21, 2019 3:08 PM > To: dts@dpdk.org > Cc: Xiao, QimaiX > Subject: [dts] [PATCH V1] framework/packet: add function update_pkt >=20 > *.function update_pkt is to update the input pkts to Packet Object, > the type of the input pkts could be str, dict and list. >=20 > Signed-off-by: Xiao Qimai > --- > framework/packet.py | 43 ++++++++++++++++++++++++++++++++++++++++-- > - > 1 file changed, 40 insertions(+), 3 deletions(-) >=20 > diff --git a/framework/packet.py b/framework/packet.py index > 05b2367..a742bd4 100755 > --- a/framework/packet.py > +++ b/framework/packet.py > @@ -371,9 +371,7 @@ class Packet(object): >=20 > if pkt_str is not None and type(pkt_str) =3D=3D str: > self._scapy_str_to_pkt(pkt_str) > - elif len(options) =3D=3D 0: > - pass > - else: > + elif len(options) !=3D 0: > self._add_pkt(self.pkt_opts) > if self.pktgen.pkt is not None: > self.pktgen.append_pkts() > @@ -458,6 +456,45 @@ class Packet(object): > self._add_pkt(kwargs) > self.pktgen.append_pkts() >=20 > + def update_pkt_str(self, pkt): > + self._scapy_str_to_pkt(pkt) > + self.pktgen.append_pkts() > + > + def update_pkt_dict(self, pkt): > + self.pkt_opts =3D pkt > + if hasattr(self, 'configured_layer_raw'): > + delattr(self, 'configured_layer_raw') > + self._add_pkt(pkt) > + self.pktgen.append_pkts() > + > + def update_pkt(self, pkts): > + """ > + update pkts to packet object > + :param pkts: pkts to update > + :type str|dict|list > + :return: None > + """ > + self.pktgen =3D scapy() > + self.pkt_layers =3D [] > + if isinstance(pkts, str): > + self.update_pkt_str(pkts) > + elif isinstance(pkts, dict): > + self.update_pkt_dict(pkts) > + elif isinstance(pkts, list): > + for i in pkts: > + if isinstance(i, str): > + try: > + self.update_pkt_str(i) > + except: > + print("warning: packet %s update failed" % i) > + elif isinstance(i, dict): > + try: > + self.update_pkt_dict(i) > + except: > + print("warning: packet %s update failed" % i) > + else: > + print("packet {} is not acceptable".format(i)) > + > def generate_random_pkts(self, dstmac=3DNone, pktnum=3D100, > random_type=3DNone, ip_increase=3DTrue, random_payload=3DFalse, > options=3DNone): > """ > -- > 2.17.1