test suite reviews and discussions
 help / color / mirror / Atom feed
From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH] framework packet: support configure multiple layers
Date: Wed, 20 Apr 2016 09:07:16 +0800	[thread overview]
Message-ID: <1461114436-9544-1-git-send-email-yong.liu@intel.com> (raw)

Add new function config_layers in packet module which support configure
multiple layers in one function.
Raw content will be in hexadecimal format, it will be easier for
configuration.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/packet.py b/framework/packet.py
index 2f3bf53..42ac4a5 100755
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -60,16 +60,15 @@ from scapy.route import *
 from scapy.packet import bind_layers, Raw
 from scapy.sendrecv import sendp
 
-
 # load extension layers
+exec_file = os.path.realpath(__file__)
+DTS_PATH = exec_file.replace('/framework/packet.py', '')
+DEP_FOLDER = DTS_PATH + '/dep'
+sys.path.append(DEP_FOLDER)
+
 from vxlan import Vxlan
-bind_layers(UDP, Vxlan, dport=4789)
-bind_layers(Vxlan, Ether)
 from nvgre import NVGRE, IPPROTO_NVGRE
-bind_layers(IP, NVGRE, proto=IPPROTO_NVGRE)
-bind_layers(NVGRE, Ether)
 from lldp import LLDP, LLDPManagementAddress
-bind_layers(Ether, LLDP, type=0x88cc)
 
 # packet generator type should be configured later
 PACKETGEN = "scapy"
@@ -269,8 +268,8 @@ class scapy(object):
     def raw(self, payload=None):
         if payload is not None:
             self.pkt[Raw].load = ''
-            for load in payload:
-                self.pkt[Raw].load += '%c' % int(load, 16)
+            for hex1, hex2 in payload:
+                self.pkt[Raw].load += struct.pack("=B", int('%s%s' %(hex1, hex2), 16))
 
     def vxlan(self, vni=0):
         self.pkt[Vxlan].vni = vni
@@ -534,16 +533,29 @@ class Packet(object):
                 idx = self.pkt_layers.index(layer)
         except Exception as e:
             print "INVALID LAYER ID %s" % layer
-            return -1
+            return False
 
         if self.check_layer_config(layer, config) is False:
-            return -1
+            return False
 
         layer_conf = getattr(self, "_config_layer_%s" % layer)
         setattr(self, 'configured_layer_%s' % layer, True)
 
         return layer_conf(config)
 
+    def config_layers(self, layers=None):
+        """
+        Configure packet with multi configurations
+        """
+        for layer in layers:
+            name, config = layer
+            if name not in self.pkt_layers:
+                print "[%s] is missing in packet!!!" % name
+                raise
+            if self.config_layer(name, config) is False:
+                print "[%s] failed to configure!!!" % name
+                raise
+
     def _config_layer_ether(self, config):
         return self.pktgen.ether(**config)
 
@@ -767,3 +779,13 @@ if __name__ == "__main__":
     pkt.config_layer('udp', {'src': 4789, 'dst': 4789, 'chksum': 0x1111})
     pkt.config_layer('vxlan', {'vni': 2})
     pkt.config_layer('raw', {'payload': ['58'] * 18})
+    pkt.send_pkt(tx_port='lo')
+
+    pkt = Packet()
+    pkt.assign_layers(['ether', 'dot1q', 'ipv4', 'udp',
+                       'vxlan', 'inner_mac', 'inner_ipv4', 'inner_udp', 'raw'])
+    # config packet
+    pkt.config_layers([('ether', {'dst': '00:11:22:33:44:55'}), ('ipv4', {'dst': '1.1.1.1'}),
+                        ('vxlan', {'vni': 2}), ('raw', {'payload': ['01'] * 18})])
+
+    pkt.send_pkt(tx_port='lo')
-- 
1.9.3

             reply	other threads:[~2016-04-20  1:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20  1:07 Marvin Liu [this message]
2016-04-22  1:16 ` [dts] [PATCH v2] framework packet: support configure inner layers Marvin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461114436-9544-1-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).