Separate files needing GPL license
[csit.git] / GPL / traffic_profiles / trex / trex-sl-3n-ethip6-ip6dst10000.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 / IPv6 /
19  - Direction 0 --> 1:
20    - Source IP address range:      2001:1::1
21    - Destination IP address range: 2001:2::0 - 2001:2::270F
22  - Direction 1 --> 0:
23    - Source IP address range:      2001:2::1
24    - Destination IP address range: 2001:1::0 - 2001:1::270F
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         # IPs used in packet headers.
40         self.p1_src_start_ip = u"2001:1::1"
41         self.p1_dst_start_ip = u"2001:2::0"
42         self.p1_dst_end_ip = u"2001:2::270F"
43
44         self.p2_src_start_ip = u"2001:2::1"
45         self.p2_dst_start_ip = u"2001:1::0"
46         self.p2_dst_end_ip = u"2001:1::270F"
47
48     def define_packets(self):
49         """Defines the packets to be sent from the traffic generator.
50
51         Packet definition: | ETH | IPv6 |
52
53         :returns: Packets to be sent from the traffic generator.
54         :rtype: tuple
55         """
56
57         base_p1, count_p1 = self._get_start_end_ipv6(
58             self.p1_dst_start_ip,
59             self.p1_dst_end_ip
60         )
61         base_p2, count_p2 = self._get_start_end_ipv6(
62             self.p2_dst_start_ip,
63             self.p2_dst_end_ip
64         )
65
66         # Direction 0 --> 1
67         base_pkt_a = (
68             Ether() /
69             IPv6(
70                 src=self.p1_src_start_ip,
71                 dst=self.p1_dst_start_ip
72             )
73         )
74         # Direction 1 --> 0
75         base_pkt_b = (
76             Ether() /
77             IPv6(
78                 src=self.p2_src_start_ip,
79                 dst=self.p2_dst_start_ip
80             )
81         )
82
83         # Direction 0 --> 1
84         vm1 = STLScVmRaw(
85             [
86                 STLVmFlowVar(
87                     name=u"ipv6_dst",
88                     min_value=base_p1,
89                     max_value=base_p1 + count_p1,
90                     size=8,
91                     op=u"inc"
92                 ),
93                 STLVmWrFlowVar(
94                     fv_name=u"ipv6_dst",
95                     pkt_offset=u"IPv6.dst",
96                     offset_fixup=8
97                 )
98             ]
99         )
100         # Direction 1 --> 0
101         vm2 = STLScVmRaw(
102             [
103                 STLVmFlowVar(
104                     name=u"ipv6_dst",
105                     min_value=base_p2,
106                     max_value=base_p2 + count_p2,
107                     size=8,
108                     op=u"inc"
109                 ),
110                 STLVmWrFlowVar(
111                     fv_name=u"ipv6_dst",
112                     pkt_offset=u"IPv6.dst",
113                     offset_fixup=8
114                 )
115             ]
116         )
117
118         return base_pkt_a, base_pkt_b, vm1, vm2
119
120
121 def register():
122     """Register this traffic profile to T-rex.
123
124     Do not change this function.
125
126     :return: Traffic streams.
127     :rtype: Object
128     """
129     return TrafficStreams()