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