test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH V1] framework/packet: add function update_pkt
@ 2019-11-21  7:07 Xiao Qimai
  2019-11-22  6:38 ` Tu, Lijuan
  0 siblings, 1 reply; 2+ messages in thread
From: Xiao Qimai @ 2019-11-21  7:07 UTC (permalink / raw)
  To: dts; +Cc: Xiao Qimai

*.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 <qimaix.xiao@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dts] [PATCH V1] framework/packet: add function update_pkt
  2019-11-21  7:07 [dts] [PATCH V1] framework/packet: add function update_pkt Xiao Qimai
@ 2019-11-22  6:38 ` Tu, Lijuan
  0 siblings, 0 replies; 2+ messages in thread
From: Tu, Lijuan @ 2019-11-22  6:38 UTC (permalink / raw)
  To: Xiao, QimaiX, dts; +Cc: Xiao, QimaiX

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 <qimaix.xiao@intel.com>
> Subject: [dts] [PATCH V1] framework/packet: add function update_pkt
> 
> *.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 <qimaix.xiao@intel.com>
> ---
>  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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-22  6:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21  7:07 [dts] [PATCH V1] framework/packet: add function update_pkt Xiao Qimai
2019-11-22  6:38 ` Tu, Lijuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).