add vxlan example
authorHanoh Haim <[email protected]>
Sun, 14 Feb 2016 08:41:49 +0000 (10:41 +0200)
committerHanoh Haim <[email protected]>
Sun, 14 Feb 2016 08:41:49 +0000 (10:41 +0200)
scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py
scripts/exp/udp_1pkt_vxlan.pcap [new file with mode: 0644]
scripts/external_libs/scapy-2.3.1/scapy/fields.py
scripts/stl/udp_1pkt_vxlan.py [new file with mode: 0644]

index 280a95e..393fdbf 100644 (file)
@@ -148,7 +148,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
 
     def test_stl_profiles (self):
 
-        p = [ 
+        p1 = [ 
             ["udp_1pkt_1mac_override.py","-m 1 -l 50",True],
             ["syn_attack.py","-m 1 -l 50",False],               # can't compare random now 
             ["udp_1pkt_1mac.py","-m 1 -l 50",True],
@@ -176,12 +176,13 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
             #["udp_1pkt_simple.py","-m 1 -l 3",True],
             ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True],
             ["udp_1pkt_tuple_gen_split.py","-m 1 -c 2 -l 100",True],
-            ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True]
+            ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True],
+
 
           ];
 
 
-        p1  = [ ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True] ]
+        p  = [ ["udp_1pkt_vxlan.py","-m 1 -c 1 -l 17",True] ]
         
 
         for obj in p:
diff --git a/scripts/exp/udp_1pkt_vxlan.pcap b/scripts/exp/udp_1pkt_vxlan.pcap
new file mode 100644 (file)
index 0000000..601185a
Binary files /dev/null and b/scripts/exp/udp_1pkt_vxlan.pcap differ
index 1b8d860..8bb8c97 100644 (file)
@@ -282,6 +282,10 @@ class X3BytesField(XByteField):
     def getfield(self, pkt, s):
         return  s[3:], self.m2i(pkt, struct.unpack(self.fmt, "\x00"+s[:3])[0])
 
+class ThreeBytesField(X3BytesField, ByteField):
+    def i2repr(self, pkt, x):
+        return ByteField.i2repr(self, pkt, x)
 
 class ShortField(Field):
     def __init__(self, name, default):
diff --git a/scripts/stl/udp_1pkt_vxlan.py b/scripts/stl/udp_1pkt_vxlan.py
new file mode 100644 (file)
index 0000000..3cb3dfb
--- /dev/null
@@ -0,0 +1,48 @@
+from trex_stl_lib.api import *
+
+# Adding header that does not exists yet in Scapy
+# This was taken from pull request of Scapy 
+# 
+
+
+# RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
+# A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
+# http://tools.ietf.org/html/rfc7348
+_VXLAN_FLAGS = ['R' for i in range(0, 24)] + ['R', 'R', 'R', 'I', 'R', 'R', 'R', 'R', 'R'] 
+
+class VXLAN(Packet):
+    name = "VXLAN"
+    fields_desc = [FlagsField("flags", 0x08000000, 32, _VXLAN_FLAGS),
+                   ThreeBytesField("vni", 0),
+                   XByteField("reserved", 0x00)]
+
+    def mysummary(self):
+        return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
+
+bind_layers(UDP, VXLAN, dport=4789)
+bind_layers(VXLAN, Ether)
+
+
+class STLS1(object):
+
+    def __init__ (self):
+        pass;
+
+    def create_stream (self):
+        pkt =  Ether()/IP()/UDP(sport=1337,dport=4789)/VXLAN(vni=42)/Ether()/IP()/('x'*20)
+        pkt.show2()
+
+        # burst of 17 packets
+        return STLStream(packet = STLPktBuilder(pkt = pkt ,vm = []),
+                         mode = STLTXSingleBurst( pps = 1, total_pkts = 17) )
+
+
+    def get_streams (self, direction = 0):
+        # create 1 stream 
+        return [ self.create_stream() ]
+
+def register():
+    return STLS1()
+
+
+