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