1018c13c53e1856c0743bae5e5f05d7664e00397
[csit.git] / resources / traffic_profiles / trex / trex-sl-ethip4-vxlansrc253.py
1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """Stream profile for T-rex traffic generator.
15
16 Stream profile:
17  - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
18  - Packet: ETH / IP / VXLAN / ETH / IP
19  - Direction 0 --> 1:
20    - Source IP address:                172.17.0.2
21    - Destination IP address:           172.16.0.1
22    - VXLAN VNI:                        24
23    - Payload source MAC address:       00:de:ad:00:00:00
24    - Payload source IP address:        10.0.0.2
25    - Payload destination MAC address:  00:de:ad:00:00:01
26    - Payload destination IP address:   10.0.0.1
27  - Direction 1 --> 0:
28    - Source IP address:                172.27.0.2
29    - Destination IP address:           172.26.0.1
30    - VXLAN VNI:                        24
31    - Payload source MAC address:       00:de:ad:00:00:01
32    - Payload source IP address:        10.0.0.1
33    - Payload destination MAC address:  00:de:ad:00:00:00
34    - Payload destination IP address:   10.0.0.2
35
36 """
37
38 from trex_stl_lib.api import *
39 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
40
41 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
42 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
43 # http://tools.ietf.org/html/rfc7348
44 _VXLAN_FLAGS = list('R'*24 + "RRRIRRRRR")
45
46
47 class VXLAN(Packet):
48     name = "VXLAN"
49     fields_desc = [FlagsField("flags", 0x08000000, 32, _VXLAN_FLAGS),
50                    ThreeBytesField("vni", 0),
51                    XByteField("reserved", 0x00)]
52
53     def mysummary(self):
54         return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
55
56
57 bind_layers(UDP, VXLAN, dport=4789)
58 bind_layers(VXLAN, Ether)
59
60
61 class TrafficStreams(TrafficStreamsBaseClass):
62     """Stream profile."""
63
64     def __init__(self):
65         """Initialization and setting of streams' parameters."""
66
67         super(TrafficStreamsBaseClass, self).__init__()
68
69     def define_packets(self):
70         """Defines the packets to be sent from the traffic generator.
71
72         Packet definition: | ETH | IP |
73
74         :returns: Packets to be sent from the traffic generator.
75         :rtype: tuple
76         """
77
78         # Direction 0 --> 1
79         base_pkt_a = (
80             Ether()/
81             IP(src="172.17.0.2",dst="172.16.0.1")/
82             UDP(sport=1337,dport=4789)/
83             VXLAN(vni=24)/
84             Ether(src="00:de:ad:00:00:00",dst="00:de:ad:00:00:01")/
85             IP(src="10.0.0.2",dst="10.0.0.1"))
86
87         # Direction 1 --> 0
88         base_pkt_b = (
89             Ether()/
90             IP(src="172.27.0.2",dst="172.26.0.1")/
91             UDP(sport=1337,dport=4789)/
92             VXLAN(vni=24)/
93             Ether(src="00:de:ad:00:00:01",dst="00:de:ad:00:00:00")/
94             IP(src="10.0.0.1",dst="10.0.0.2"))
95
96
97         # Direction 0 --> 1
98         vm1 = STLScVmRaw([
99             STLVmFlowVar(name="src", min_value="172.17.0.2" ,
100                          max_value="172.17.0.254", size=4, op="inc"),
101             STLVmFlowVar(name="src_mac", min_value=2 , max_value=3100,
102                          size=2, op="inc"),
103             STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
104             STLVmWrFlowVar(fv_name="src_mac", pkt_offset=60),
105             STLVmFixIpv4(offset = "IP")
106         ])
107
108         # Direction 1 --> 0
109         vm2 = STLScVmRaw([
110             STLVmFlowVar(name="src", min_value="172.27.0.2" ,
111                          max_value="172.27.0.254", size=4, op="inc"),
112             STLVmFlowVar(name="src_mac", min_value=2 , max_value=3100,
113                          size=2, op="inc"),
114             STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
115             STLVmWrFlowVar(fv_name="src_mac", pkt_offset=60),
116             STLVmFixIpv4(offset = "IP")
117         ])
118
119         # for now there's a single VXLAN tunnel per direction, the above
120         # variations are for reference only
121         vm1, vm2 = [], []
122
123         return base_pkt_a, base_pkt_b, vm1, vm2
124
125 def register():
126     """Register this traffic profile to T-rex.
127
128     Do not change this function.
129
130     :return: Traffic streams.
131     :rtype: Object
132     """
133     return TrafficStreams()
134