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 1F46AA04C1; Thu, 21 Nov 2019 08:04:56 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CB1CA2BA3; Thu, 21 Nov 2019 08:04:55 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 4AEFD23D for ; Thu, 21 Nov 2019 08:04:53 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2019 23:04:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,224,1571727600"; d="scan'208";a="290228092" Received: from unknown (HELO dpdk-wenjielx-dtspatch135.sh.intel.com) ([10.240.176.135]) by orsmga001.jf.intel.com with ESMTP; 20 Nov 2019 23:04:52 -0800 From: Xiao Qimai To: dts@dpdk.org Cc: Xiao Qimai Date: Thu, 21 Nov 2019 15:07:59 +0800 Message-Id: <1574320079-39675-1-git-send-email-qimaix.xiao@intel.com> X-Mailer: git-send-email 1.9.3 Subject: [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" *.function update_pkt is to update the input pkts to Packet Object, the type of the input pkts could be str, dict and list. Signed-off-by: Xiao Qimai --- framework/packet.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) 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): if pkt_str is not None and type(pkt_str) == str: self._scapy_str_to_pkt(pkt_str) - elif len(options) == 0: - pass - else: + elif len(options) != 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() + 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 = 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 = scapy() + self.pkt_layers = [] + 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=None, pktnum=100, random_type=None, ip_increase=True, random_payload=False, options=None): """ -- 2.17.1