Performance: Fix l3fwd in 3node
[csit.git] / GPL / traffic_profiles / trex / trex-sl-dot1qip4-vlan1ip4src254ip4dst254.py
1 # Copyright (c) 2020 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 / DOT1Q / IP /
19  - Direction 0 --> 1:
20    - VLAN range:                    100
21    - Source IP address range:       10.10.10.1 - 10.10.10.254
22    - Destination IP address range:  20.20.20.1 - 20.20.20.254
23  - Direction 1 --> 0:
24    - VLAN range:                    200
25    - Source IP address range:       20.20.20.1 - 20.20.20.254
26    - Destination IP address range:  10.10.10.1 - 10.10.10.254
27 """
28
29 from trex.stl.api import *
30 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
31
32
33 class TrafficStreams(TrafficStreamsBaseClass):
34     """Stream profile."""
35
36     def __init__(self):
37         """Initialization and setting of streams' parameters."""
38
39         super(TrafficStreamsBaseClass, self).__init__()
40
41         # VLAN IDs
42         self.p1_vlan_start = 100
43         self.p2_vlan_start = 200
44
45         # IPs used in packet headers.
46         self.p1_src_start_ip = u"10.10.10.1"
47         self.p1_src_end_ip = u"10.10.10.254"
48
49         self.p1_dst_start_ip = u"20.20.20.1"
50         self.p1_dst_end_ip = u"20.20.20.254"
51
52         self.p2_src_start_ip = u"20.20.20.1"
53         self.p2_src_end_ip = u"20.20.20.254"
54
55         self.p2_dst_start_ip = u"10.10.10.1"
56         self.p2_dst_end_ip = u"10.10.10.254"
57
58     def define_packets(self):
59         """Defines the packets to be sent from the traffic generator.
60
61         Packet definition: | ETH | DOT1Q | IP |
62
63         :returns: Packets to be sent from the traffic generator.
64         :rtype: tuple
65         """
66
67         # Direction 0 --> 1
68         base_pkt_a = (
69             Ether() /
70             Dot1Q(
71                 vlan=self.p1_vlan_start
72             ) /
73             IP(
74                 src=self.p1_src_start_ip,
75                 dst=self.p1_dst_start_ip,
76                 proto=61
77             )
78         )
79         # Direction 1 --> 0
80         base_pkt_b = (
81             Ether() /
82             Dot1Q(
83                 vlan=self.p2_vlan_start
84             ) /
85             IP(
86                 src=self.p2_src_start_ip,
87                 dst=self.p2_dst_start_ip,
88                 proto=61
89             )
90         )
91
92         # Direction 0 --> 1
93         vm1 = STLScVmRaw(
94             [
95                 STLVmFlowVar(
96                     name=u"ip_src",
97                     min_value=self.p1_src_start_ip,
98                     max_value=self.p1_src_end_ip,
99                     size=4,
100                     op=u"random"
101                 ),
102                 STLVmWrFlowVar(
103                     fv_name=u"ip_src",
104                     pkt_offset=u"IP.src"
105                 ),
106                 STLVmFlowVar(
107                     name=u"ip_dst",
108                     min_value=self.p1_dst_start_ip,
109                     max_value=self.p1_dst_end_ip,
110                     size=4,
111                     op=u"random"
112                 ),
113                 STLVmWrFlowVar(
114                     fv_name=u"ip_dst",
115                     pkt_offset=u"IP.dst"
116                 ),
117                 STLVmFixIpv4(
118                     offset=u"IP"
119                 )
120             ]
121         )
122         # Direction 1 --> 0
123         vm2 = STLScVmRaw(
124             [
125               STLVmFlowVar(
126                     name=u"ip_src",
127                     min_value=self.p2_src_start_ip,
128                     max_value=self.p2_src_end_ip,
129                     size=4,
130                     op=u"random"
131                 ),
132                 STLVmWrFlowVar(
133                     fv_name=u"ip_src",
134                     pkt_offset=u"IP.src"
135                 ),
136                 STLVmFlowVar(
137                     name=u"ip_dst",
138                     min_value=self.p2_dst_start_ip,
139                     max_value=self.p2_dst_end_ip,
140                     size=4,
141                     op=u"random"
142                 ),
143                 STLVmWrFlowVar(
144                     fv_name=u"ip_dst",
145                     pkt_offset=u"IP.dst"
146                 ),
147                 STLVmFixIpv4(
148                     offset=u"IP"
149                 )
150             ]
151         )
152
153         return base_pkt_a, base_pkt_b, vm1, vm2
154
155
156 def register():
157     """Register this traffic profile to T-rex.
158
159     Do not change this function.
160
161     :returns: Traffic streams.
162     :rtype: Object
163     """
164     return TrafficStreams()