Revert "fix(jobspec): Delete ipsec nfv density tests"
[csit.git] / GPL / traffic_profiles / trex / trex-stl-ethip6-ip6dst-rnd10000-6p.py
1 # Copyright (c) 2024 Cisco and/or its affiliates.
2 #
3 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
4 #
5 # Licensed under the Apache License 2.0 or
6 # GNU General Public License v2.0 or later;  you may not use this file
7 # except in compliance with one of these Licenses. You
8 # may obtain a copy of the Licenses at:
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #     https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 #
13 # Note: If this file is linked with Scapy, which is GPLv2+, your use of it
14 # must be under GPLv2+.  If at any point in the future it is no longer linked
15 # with Scapy (or other GPLv2+ licensed software), you are free to choose
16 # Apache 2.
17 #
18 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
23
24 """Stream profile for T-rex traffic generator.
25
26 Stream profile:
27  - Three parallel bi-directional streams sent as W --> E and E --> W
28    at the same time.
29  - Packet: ETH / IPv6 /
30 """
31
32 from trex.stl.api import *
33 from profile_trex_stateless_scale_class import TrafficStreamsScaleClass
34
35
36 class TrafficStreams(TrafficStreamsScaleClass):
37     """Stream profile."""
38
39     def __init__(self):
40         """Initialization and setting of streams' parameters."""
41
42         super(TrafficStreamsScaleClass, self).__init__()
43
44         self.pkt_data = [
45             # Direction W --> E:
46             {
47                 "src_start_ip": "2100::1",
48                 "dst_start_ip": "2200::0",
49                 "dst_end_ip": "2200::270F",
50                 "seed": 1
51             },
52             # Direction W --> E:
53             {
54                 "src_start_ip": "2300::1",
55                 "dst_start_ip": "2400::0",
56                 "dst_end_ip": "2400::270F",
57                 "seed": 2
58             },
59             # Direction W --> E:
60             {
61                 "src_start_ip": "2500::1",
62                 "dst_start_ip": "2600::0",
63                 "dst_end_ip": "2600::270F",
64                 "seed": 1
65             },
66             # Direction E --> W:
67             {
68                 "src_start_ip": "2200::1",
69                 "dst_start_ip": "2100::0",
70                 "dst_end_ip": "2100::270F",
71                 "seed": 2
72             },
73             # Direction E --> W:
74             {
75                 "src_start_ip": "2400::1",
76                 "dst_start_ip": "2300::0",
77                 "dst_end_ip": "2300::270F",
78                 "seed": 1
79             },
80             # Direction E --> W:
81             {
82                 "src_start_ip": "2600::1",
83                 "dst_start_ip": "2500::0",
84                 "dst_end_ip": "2500::270F",
85                 "seed": 2
86             }
87         ]
88         self.pkt_base = []
89         self.pkt_vm = []
90
91     def define_packets(self):
92         """Defines the packets to be sent from the traffic generator.
93
94         Packet definition: | ETH | IPv6 |
95
96         :returns: Packets to be sent from the traffic generator.
97         :rtype: tuple
98         """
99         for i in range(len(self.pkt_data)):
100             base, count = self._get_start_end_ipv6(
101                 self.pkt_data[i]["dst_start_ip"],
102                 self.pkt_data[i]["dst_end_ip"]
103             )
104
105             self.pkt_base.append(
106                 Ether() /
107                 IPv6(
108                     src=self.pkt_data[i]["src_start_ip"],
109                     dst=self.pkt_data[i]["dst_start_ip"]
110                 )
111             )
112             self.pkt_vm.append(
113                 STLScVmRaw(
114                     [
115                         STLVmFlowVarRepeatableRandom(
116                             name="ipv6_dst",
117                             min_value=base,
118                             max_value=base + count,
119                             size=8,
120                             seed=self.pkt_data[i]["seed"],
121                             limit=(2**24 - 1)
122                         ),
123                         STLVmWrFlowVar(
124                             fv_name="ipv6_dst",
125                             pkt_offset="IPv6.dst",
126                             offset_fixup=8
127                         )
128                     ]
129                 )
130             )
131
132         return self.pkt_base, self.pkt_vm
133
134
135 def register():
136     """Register this traffic profile to T-rex.
137
138     Do not change this function.
139
140     :return: Traffic streams.
141     :rtype: Object
142     """
143     return TrafficStreams()