3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
23 from tests.unit import STL_MOCKS
25 STLClient = mock.MagicMock()
26 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
30 from yardstick.network_services.traffic_profile.base import TrafficProfile
31 from yardstick.network_services.traffic_profile.traffic_profile import TrexProfile
32 from yardstick.network_services.traffic_profile.traffic_profile import SRC
33 from yardstick.network_services.traffic_profile.traffic_profile import DST
34 from yardstick.network_services.traffic_profile.traffic_profile import ETHERNET
35 from yardstick.network_services.traffic_profile.traffic_profile import IP
36 from yardstick.network_services.traffic_profile.traffic_profile import IPv6
37 from yardstick.network_services.traffic_profile.traffic_profile import UDP
38 from yardstick.network_services.traffic_profile.traffic_profile import SRC_PORT
39 from yardstick.network_services.traffic_profile.traffic_profile import DST_PORT
40 from yardstick.network_services.traffic_profile.traffic_profile import TYPE_OF_SERVICE
43 class TestTrexProfile(unittest.TestCase):
45 "schema": "isb:traffic_profile:0.1",
47 "description": "Fixed traffic profile to run UDP traffic",
49 "traffic_type": "FixedTraffic",
50 "frame_rate": 100, # pps
54 EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01"
55 EXAMPLE_IP_ADDR = "10.0.0.1"
56 EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
59 'description': 'Traffic profile to run RFC2544 latency',
61 'traffic_profile': {'traffic_type': 'RFC2544Profile',
63 TrafficProfile.DOWNLINK: {
64 'ipv4': {'outer_l2': {'framesize': {'64B': '100',
71 "srcmac": "00:00:00:00:00:02",
72 "dstmac": "00:00:00:00:00:01"},
73 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
75 'srcip4': '9.9.1.1-90.1.2.2',
78 'outer_l4': {'srcport': '2001',
81 TrafficProfile.UPLINK: {
83 {'outer_l2': {'framesize':
84 {'64B': '100', '1518B': '0',
85 '128B': '0', '1400B': '0',
86 '256B': '0', '373b': '0',
88 "srcmac": "00:00:00:00:00:01",
89 "dstmac": "00:00:00:00:00:02"},
90 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
92 'srcip4': '1.1.1.1-1.15.255.255',
93 'dscp': 0, 'ttl': 32, 'count': 1},
94 'outer_l4': {'dstport': '2001',
97 'schema': 'isb:traffic_profile:0.1'}
99 'description': 'Traffic profile to run RFC2544 latency',
101 'traffic_profile': {'traffic_type': 'RFC2544Profile',
103 TrafficProfile.DOWNLINK: {
104 'ipv6': {'outer_l2': {'framesize':
105 {'64B': '100', '1518B': '0',
106 '128B': '0', '1400B': '0',
107 '256B': '0', '373b': '0',
109 "srcmac": "00:00:00:00:00:02",
110 "dstmac": "00:00:00:00:00:01"},
113 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
116 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
117 'dscp': 0, 'ttl': 32,
119 'outer_l4': {'srcport': '2001',
122 TrafficProfile.UPLINK: {
123 'ipv6': {'outer_l2': {'framesize':
124 {'64B': '100', '1518B': '0',
125 '128B': '0', '1400B': '0',
126 '256B': '0', '373b': '0',
128 "srcmac": "00:00:00:00:00:01",
129 "dstmac": "00:00:00:00:00:02"},
132 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
135 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
136 'dscp': 0, 'ttl': 32,
138 'outer_l4': {'dstport': '2001',
141 'schema': 'isb:traffic_profile:0.1'}
143 def test___init__(self):
144 TrafficProfile.params = self.PROFILE
146 TrexProfile(TrafficProfile)
147 self.assertEqual(trex_profile.pps, 100)
150 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
151 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
154 TrexProfile(TrafficProfile)
155 self.assertEqual(None, trex_profile.set_qinq(qinq))
157 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
158 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
159 self.assertEqual(None, trex_profile.set_qinq(qinq))
161 def test__set_outer_l2_fields(self):
163 TrexProfile(TrafficProfile)
164 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
165 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
166 outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2']
167 outer_l2['QinQ'] = qinq
168 self.assertEqual(None, trex_profile._set_outer_l2_fields(outer_l2))
170 def test__set_outer_l3v4_fields(self):
172 TrexProfile(TrafficProfile)
173 outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
174 outer_l3v4['proto'] = 'tcp'
175 self.assertEqual(None, trex_profile._set_outer_l3v4_fields(outer_l3v4))
177 def test__set_outer_l3v6_fields(self):
179 TrexProfile(TrafficProfile)
180 outer_l3v6 = self.PROFILE_v6[TrafficProfile.UPLINK]['ipv6']['outer_l3v4']
181 outer_l3v6['proto'] = 'tcp'
183 outer_l3v6['hlim'] = 10
184 self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6))
186 def test__set_outer_l4_fields(self):
188 TrexProfile(TrafficProfile)
189 outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4']
190 self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4))
192 def test_get_streams(self):
194 TrexProfile(TrafficProfile)
195 trex_profile.params = self.PROFILE
196 profile_data = self.PROFILE[TrafficProfile.UPLINK]
197 self.assertIsNotNone(trex_profile.get_streams(profile_data))
198 trex_profile.pg_id = 1
199 self.assertIsNotNone(trex_profile.get_streams(profile_data))
200 trex_profile.params = self.PROFILE_v6
201 trex_profile.profile_data = self.PROFILE_v6[TrafficProfile.UPLINK]
202 self.assertIsNotNone(trex_profile.get_streams(profile_data))
203 trex_profile.pg_id = 1
204 self.assertIsNotNone(trex_profile.get_streams(profile_data))
206 def test_generate_packets(self):
208 TrexProfile(TrafficProfile)
209 trex_profile.fsize = 10
210 trex_profile.base_pkt = [10]
211 self.assertIsNone(trex_profile.generate_packets())
213 def test_generate_imix_data_error(self):
215 TrexProfile(TrafficProfile)
216 self.assertEqual({}, trex_profile.generate_imix_data(False))
218 def test__get_start_end_ipv6(self):
220 TrexProfile(TrafficProfile)
221 self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
222 "1.1.1.3", "1.1.1.1")
224 def test__dscp_range_action_partial_actual_count_zero(self):
225 traffic_profile = TrexProfile(TrafficProfile)
226 dscp_partial = traffic_profile._dscp_range_action_partial()
228 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
229 dscp_partial('1', '1', 'unneeded')
230 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
232 def test__dscp_range_action_partial_count_greater_than_actual(self):
233 traffic_profile = TrexProfile(TrafficProfile)
234 dscp_partial = traffic_profile._dscp_range_action_partial()
236 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
237 dscp_partial('1', '10', '100')
238 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
240 def test__udp_range_action_partial_actual_count_zero(self):
241 traffic_profile = TrexProfile(TrafficProfile)
242 traffic_profile.udp['field1'] = 'value1'
243 udp_partial = traffic_profile._udp_range_action_partial('field1')
245 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
246 udp_partial('1', '1', 'unneeded')
247 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
249 def test__udp_range_action_partial_count_greater_than_actual(self):
250 traffic_profile = TrexProfile(TrafficProfile)
251 traffic_profile.udp['field1'] = 'value1'
252 udp_partial = traffic_profile._udp_range_action_partial('field1', 'not_used_count')
254 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
255 udp_partial('1', '10', '100')
256 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
258 def test__general_single_action_partial(self):
259 trex_profile = TrexProfile(TrafficProfile)
261 trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR)
262 self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src)
264 trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR)
265 self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
267 trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR)
268 self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
270 trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)
271 self.assertEqual(5060, trex_profile.udp_packet.sport)
273 trex_profile._general_single_action_partial(IP)(TYPE_OF_SERVICE)(0)
274 self.assertEqual(0, trex_profile.ip_packet.tos)
276 def test__set_proto_addr(self):
277 trex_profile = TrexProfile(TrafficProfile)
279 ether_range = "00:00:00:00:00:01-00:00:00:00:00:02"
280 ip_range = "1.1.1.2-1.1.1.10"
281 ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420'
283 trex_profile._set_proto_addr(ETHERNET, SRC, ether_range)
284 trex_profile._set_proto_addr(ETHERNET, DST, ether_range)
285 trex_profile._set_proto_addr(IP, SRC, ip_range)
286 trex_profile._set_proto_addr(IP, DST, ip_range)
287 trex_profile._set_proto_addr(IPv6, SRC, ipv6_range)
288 trex_profile._set_proto_addr(IPv6, DST, ipv6_range)
289 trex_profile._set_proto_addr(UDP, SRC_PORT, "5060-5090")
290 trex_profile._set_proto_addr(UDP, DST_PORT, "5060")