1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
21 from tests.unit import STL_MOCKS
22 from yardstick.common import exceptions as y_exc
24 STLClient = mock.MagicMock()
25 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
29 from yardstick.network_services.traffic_profile.base import TrafficProfile
30 from yardstick.network_services.traffic_profile.trex_traffic_profile import TrexProfile
31 from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC
32 from yardstick.network_services.traffic_profile.trex_traffic_profile import DST
33 from yardstick.network_services.traffic_profile.trex_traffic_profile import ETHERNET
34 from yardstick.network_services.traffic_profile.trex_traffic_profile import IP
35 from yardstick.network_services.traffic_profile.trex_traffic_profile import IPv6
36 from yardstick.network_services.traffic_profile.trex_traffic_profile import UDP
37 from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC_PORT
38 from yardstick.network_services.traffic_profile.trex_traffic_profile import DST_PORT
39 from yardstick.network_services.traffic_profile.trex_traffic_profile import TYPE_OF_SERVICE
42 class TestTrexProfile(unittest.TestCase):
44 "schema": "isb:traffic_profile:0.1",
46 "description": "Fixed traffic profile to run UDP traffic",
48 "traffic_type": "FixedTraffic",
49 "frame_rate": 100, # pps
53 EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01"
54 EXAMPLE_IP_ADDR = "10.0.0.1"
55 EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
58 'description': 'Traffic profile to run RFC2544 latency',
60 'traffic_profile': {'traffic_type': 'RFC2544Profile',
62 TrafficProfile.DOWNLINK: {
63 'ipv4': {'outer_l2': {'framesize': {'64B': '100',
70 "srcmac": "00:00:00:00:00:02",
71 "dstmac": "00:00:00:00:00:01"},
72 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
74 'srcip4': '9.9.1.1-90.1.2.2',
77 'outer_l4': {'srcport': '2001',
80 TrafficProfile.UPLINK: {
82 {'outer_l2': {'framesize':
83 {'64B': '100', '1518B': '0',
84 '128B': '0', '1400B': '0',
85 '256B': '0', '373b': '0',
87 "srcmac": "00:00:00:00:00:01",
88 "dstmac": "00:00:00:00:00:02"},
89 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
91 'srcip4': '1.1.1.1-1.15.255.255',
92 'dscp': 0, 'ttl': 32, 'count': 1},
93 'outer_l4': {'dstport': '2001',
96 'schema': 'isb:traffic_profile:0.1'}
98 'description': 'Traffic profile to run RFC2544 latency',
100 'traffic_profile': {'traffic_type': 'RFC2544Profile',
102 TrafficProfile.DOWNLINK: {
103 'ipv6': {'outer_l2': {'framesize':
104 {'64B': '100', '1518B': '0',
105 '128B': '0', '1400B': '0',
106 '256B': '0', '373b': '0',
108 "srcmac": "00:00:00:00:00:02",
109 "dstmac": "00:00:00:00:00:01"},
112 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
115 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
116 'dscp': 0, 'ttl': 32,
118 'outer_l4': {'srcport': '2001',
121 TrafficProfile.UPLINK: {
122 'ipv6': {'outer_l2': {'framesize':
123 {'64B': '100', '1518B': '0',
124 '128B': '0', '1400B': '0',
125 '256B': '0', '373b': '0',
127 "srcmac": "00:00:00:00:00:01",
128 "dstmac": "00:00:00:00:00:02"},
131 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
134 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
135 'dscp': 0, 'ttl': 32,
137 'outer_l4': {'dstport': '2001',
140 'schema': 'isb:traffic_profile:0.1'}
142 def test___init__(self):
143 TrafficProfile.params = self.PROFILE
145 TrexProfile(TrafficProfile)
146 self.assertEqual(trex_profile.pps, 100)
149 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
150 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
153 TrexProfile(TrafficProfile)
154 self.assertIsNone(trex_profile.set_qinq(qinq))
156 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
157 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
158 self.assertIsNone(trex_profile.set_qinq(qinq))
160 def test__set_outer_l2_fields(self):
162 TrexProfile(TrafficProfile)
163 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
164 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
165 outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2']
166 outer_l2['QinQ'] = qinq
167 self.assertIsNone(trex_profile._set_outer_l2_fields(outer_l2))
169 def test__set_outer_l3v4_fields(self):
171 TrexProfile(TrafficProfile)
172 outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
173 outer_l3v4['proto'] = 'tcp'
174 self.assertIsNone(trex_profile._set_outer_l3v4_fields(outer_l3v4))
176 def test__set_outer_l3v6_fields(self):
178 TrexProfile(TrafficProfile)
179 outer_l3v6 = self.PROFILE_v6[TrafficProfile.UPLINK]['ipv6']['outer_l3v4']
180 outer_l3v6['proto'] = 'tcp'
182 outer_l3v6['hlim'] = 10
183 self.assertIsNone(trex_profile._set_outer_l3v6_fields(outer_l3v6))
185 def test__set_outer_l4_fields(self):
187 TrexProfile(TrafficProfile)
188 outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4']
189 self.assertIsNone(trex_profile._set_outer_l4_fields(outer_l4))
191 def test_get_streams(self):
193 TrexProfile(TrafficProfile)
194 trex_profile.params = self.PROFILE
195 profile_data = self.PROFILE[TrafficProfile.UPLINK]
196 self.assertIsNotNone(trex_profile.get_streams(profile_data))
197 trex_profile.pg_id = 1
198 self.assertIsNotNone(trex_profile.get_streams(profile_data))
199 trex_profile.params = self.PROFILE_v6
200 trex_profile.profile_data = self.PROFILE_v6[TrafficProfile.UPLINK]
201 self.assertIsNotNone(trex_profile.get_streams(profile_data))
202 trex_profile.pg_id = 1
203 self.assertIsNotNone(trex_profile.get_streams(profile_data))
205 def test_generate_packets(self):
207 TrexProfile(TrafficProfile)
208 trex_profile.fsize = 10
209 trex_profile.base_pkt = [10]
210 self.assertIsNone(trex_profile.generate_packets())
212 def test_generate_imix_data_error(self):
214 TrexProfile(TrafficProfile)
215 self.assertEqual({}, trex_profile.generate_imix_data(False))
217 def test__count_ip_ipv4(self):
218 start, end, count = TrexProfile._count_ip('1.1.1.1', '1.2.3.4')
219 self.assertEqual('1.1.1.1', str(start))
220 self.assertEqual('1.2.3.4', str(end))
221 diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
222 int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
223 self.assertEqual(diff, count)
225 def test__count_ip_ipv6(self):
226 start_ip = '0064:ff9b:0:0:0:0:9810:6414'
227 end_ip = '0064:ff9b:0:0:0:0:9810:6420'
228 start, end, count = TrexProfile._count_ip(start_ip, end_ip)
229 self.assertEqual(0x98106414, start)
230 self.assertEqual(0x98106420, end)
231 self.assertEqual(0x98106420 - 0x98106414, count)
233 def test__count_ip_ipv6_exception(self):
234 start_ip = '0064:ff9b:0:0:0:0:9810:6420'
235 end_ip = '0064:ff9b:0:0:0:0:9810:6414'
236 with self.assertRaises(y_exc.IPv6RangeError):
237 TrexProfile._count_ip(start_ip, end_ip)
239 def test__dscp_range_action_partial_actual_count_zero(self):
240 traffic_profile = TrexProfile(TrafficProfile)
241 dscp_partial = traffic_profile._dscp_range_action_partial()
243 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
244 dscp_partial('1', '1', 'unneeded')
245 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
247 def test__dscp_range_action_partial_count_greater_than_actual(self):
248 traffic_profile = TrexProfile(TrafficProfile)
249 dscp_partial = traffic_profile._dscp_range_action_partial()
251 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
252 dscp_partial('1', '10', '100')
253 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
255 def test__udp_range_action_partial_actual_count_zero(self):
256 traffic_profile = TrexProfile(TrafficProfile)
257 traffic_profile.udp['field1'] = 'value1'
258 udp_partial = traffic_profile._udp_range_action_partial('field1')
260 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
261 udp_partial('1', '1', 'unneeded')
262 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
264 def test__udp_range_action_partial_count_greater_than_actual(self):
265 traffic_profile = TrexProfile(TrafficProfile)
266 traffic_profile.udp['field1'] = 'value1'
267 udp_partial = traffic_profile._udp_range_action_partial('field1', 'not_used_count')
269 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
270 udp_partial('1', '10', '100')
271 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
273 def test__general_single_action_partial(self):
274 trex_profile = TrexProfile(TrafficProfile)
276 trex_profile._general_single_action_partial(ETHERNET)(SRC)(
277 self.EXAMPLE_ETHERNET_ADDR)
278 self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
279 trex_profile.ether_packet.src)
281 trex_profile._general_single_action_partial(IP)(DST)(
282 self.EXAMPLE_IP_ADDR)
283 self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
285 trex_profile._general_single_action_partial(IPv6)(DST)(
286 self.EXAMPLE_IPv6_ADDR)
287 self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
289 trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)
290 self.assertEqual(5060, trex_profile.udp_packet.sport)
292 trex_profile._general_single_action_partial(IP)(TYPE_OF_SERVICE)(0)
293 self.assertEqual(0, trex_profile.ip_packet.tos)
295 def test__set_proto_addr(self):
296 trex_profile = TrexProfile(TrafficProfile)
298 ether_range = "00:00:00:00:00:01-00:00:00:00:00:02"
299 ip_range = "1.1.1.2-1.1.1.10"
300 ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420'
302 trex_profile._set_proto_addr(ETHERNET, SRC, ether_range)
303 trex_profile._set_proto_addr(ETHERNET, DST, ether_range)
304 trex_profile._set_proto_addr(IP, SRC, ip_range)
305 trex_profile._set_proto_addr(IP, DST, ip_range)
306 trex_profile._set_proto_addr(IPv6, SRC, ipv6_range)
307 trex_profile._set_proto_addr(IPv6, DST, ipv6_range)
308 trex_profile._set_proto_addr(UDP, SRC_PORT, "5060-5090")
309 trex_profile._set_proto_addr(UDP, DST_PORT, "5060")