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.
23 from tests.unit import STL_MOCKS
24 from yardstick.common import exceptions as y_exc
26 STLClient = mock.MagicMock()
27 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
31 from yardstick.network_services.traffic_profile.base import TrafficProfile
32 from yardstick.network_services.traffic_profile.trex_traffic_profile import TrexProfile
33 from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC
34 from yardstick.network_services.traffic_profile.trex_traffic_profile import DST
35 from yardstick.network_services.traffic_profile.trex_traffic_profile import ETHERNET
36 from yardstick.network_services.traffic_profile.trex_traffic_profile import IP
37 from yardstick.network_services.traffic_profile.trex_traffic_profile import IPv6
38 from yardstick.network_services.traffic_profile.trex_traffic_profile import UDP
39 from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC_PORT
40 from yardstick.network_services.traffic_profile.trex_traffic_profile import DST_PORT
41 from yardstick.network_services.traffic_profile.trex_traffic_profile import TYPE_OF_SERVICE
44 class TestTrexProfile(unittest.TestCase):
46 "schema": "isb:traffic_profile:0.1",
48 "description": "Fixed traffic profile to run UDP traffic",
50 "traffic_type": "FixedTraffic",
51 "frame_rate": 100, # pps
55 EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01"
56 EXAMPLE_IP_ADDR = "10.0.0.1"
57 EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
60 'description': 'Traffic profile to run RFC2544 latency',
62 'traffic_profile': {'traffic_type': 'RFC2544Profile',
64 TrafficProfile.DOWNLINK: {
65 'ipv4': {'outer_l2': {'framesize': {'64B': '100',
72 "srcmac": "00:00:00:00:00:02",
73 "dstmac": "00:00:00:00:00:01"},
74 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
76 'srcip4': '9.9.1.1-90.1.2.2',
79 'outer_l4': {'srcport': '2001',
82 TrafficProfile.UPLINK: {
84 {'outer_l2': {'framesize':
85 {'64B': '100', '1518B': '0',
86 '128B': '0', '1400B': '0',
87 '256B': '0', '373b': '0',
89 "srcmac": "00:00:00:00:00:01",
90 "dstmac": "00:00:00:00:00:02"},
91 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
93 'srcip4': '1.1.1.1-1.15.255.255',
94 'dscp': 0, 'ttl': 32, 'count': 1},
95 'outer_l4': {'dstport': '2001',
98 'schema': 'isb:traffic_profile:0.1'}
100 'description': 'Traffic profile to run RFC2544 latency',
102 'traffic_profile': {'traffic_type': 'RFC2544Profile',
104 TrafficProfile.DOWNLINK: {
105 'ipv6': {'outer_l2': {'framesize':
106 {'64B': '100', '1518B': '0',
107 '128B': '0', '1400B': '0',
108 '256B': '0', '373b': '0',
110 "srcmac": "00:00:00:00:00:02",
111 "dstmac": "00:00:00:00:00:01"},
114 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
117 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
118 'dscp': 0, 'ttl': 32,
120 'outer_l4': {'srcport': '2001',
123 TrafficProfile.UPLINK: {
124 'ipv6': {'outer_l2': {'framesize':
125 {'64B': '100', '1518B': '0',
126 '128B': '0', '1400B': '0',
127 '256B': '0', '373b': '0',
129 "srcmac": "00:00:00:00:00:01",
130 "dstmac": "00:00:00:00:00:02"},
133 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
136 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
137 'dscp': 0, 'ttl': 32,
139 'outer_l4': {'dstport': '2001',
142 'schema': 'isb:traffic_profile:0.1'}
144 def test___init__(self):
145 TrafficProfile.params = self.PROFILE
147 TrexProfile(TrafficProfile)
148 self.assertEqual(trex_profile.pps, 100)
151 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
152 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
155 TrexProfile(TrafficProfile)
156 self.assertEqual(None, trex_profile.set_qinq(qinq))
158 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
159 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
160 self.assertEqual(None, trex_profile.set_qinq(qinq))
162 def test__set_outer_l2_fields(self):
164 TrexProfile(TrafficProfile)
165 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
166 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
167 outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2']
168 outer_l2['QinQ'] = qinq
169 self.assertEqual(None, trex_profile._set_outer_l2_fields(outer_l2))
171 def test__set_outer_l3v4_fields(self):
173 TrexProfile(TrafficProfile)
174 outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
175 outer_l3v4['proto'] = 'tcp'
176 self.assertEqual(None, trex_profile._set_outer_l3v4_fields(outer_l3v4))
178 def test__set_outer_l3v6_fields(self):
180 TrexProfile(TrafficProfile)
181 outer_l3v6 = self.PROFILE_v6[TrafficProfile.UPLINK]['ipv6']['outer_l3v4']
182 outer_l3v6['proto'] = 'tcp'
184 outer_l3v6['hlim'] = 10
185 self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6))
187 def test__set_outer_l4_fields(self):
189 TrexProfile(TrafficProfile)
190 outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4']
191 self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4))
193 def test_get_streams(self):
195 TrexProfile(TrafficProfile)
196 trex_profile.params = self.PROFILE
197 profile_data = self.PROFILE[TrafficProfile.UPLINK]
198 self.assertIsNotNone(trex_profile.get_streams(profile_data))
199 trex_profile.pg_id = 1
200 self.assertIsNotNone(trex_profile.get_streams(profile_data))
201 trex_profile.params = self.PROFILE_v6
202 trex_profile.profile_data = self.PROFILE_v6[TrafficProfile.UPLINK]
203 self.assertIsNotNone(trex_profile.get_streams(profile_data))
204 trex_profile.pg_id = 1
205 self.assertIsNotNone(trex_profile.get_streams(profile_data))
207 def test_generate_packets(self):
209 TrexProfile(TrafficProfile)
210 trex_profile.fsize = 10
211 trex_profile.base_pkt = [10]
212 self.assertIsNone(trex_profile.generate_packets())
214 def test_generate_imix_data_error(self):
216 TrexProfile(TrafficProfile)
217 self.assertEqual({}, trex_profile.generate_imix_data(False))
219 def test__count_ip_ipv4(self):
220 start, end, count = TrexProfile._count_ip('1.1.1.1', '1.2.3.4')
221 self.assertEqual('1.1.1.1', str(start))
222 self.assertEqual('1.2.3.4', str(end))
223 diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
224 int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
225 self.assertEqual(diff, count)
227 def test__count_ip_ipv6(self):
228 start_ip = '0064:ff9b:0:0:0:0:9810:6414'
229 end_ip = '0064:ff9b:0:0:0:0:9810:6420'
230 start, end, count = TrexProfile._count_ip(start_ip, end_ip)
231 self.assertEqual(0x98106414, start)
232 self.assertEqual(0x98106420, end)
233 self.assertEqual(0x98106420 - 0x98106414, count)
235 def test__count_ip_ipv6_exception(self):
236 start_ip = '0064:ff9b:0:0:0:0:9810:6420'
237 end_ip = '0064:ff9b:0:0:0:0:9810:6414'
238 with self.assertRaises(y_exc.IPv6RangeError):
239 TrexProfile._count_ip(start_ip, end_ip)
241 def test__dscp_range_action_partial_actual_count_zero(self):
242 traffic_profile = TrexProfile(TrafficProfile)
243 dscp_partial = traffic_profile._dscp_range_action_partial()
245 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
246 dscp_partial('1', '1', 'unneeded')
247 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
249 def test__dscp_range_action_partial_count_greater_than_actual(self):
250 traffic_profile = TrexProfile(TrafficProfile)
251 dscp_partial = traffic_profile._dscp_range_action_partial()
253 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
254 dscp_partial('1', '10', '100')
255 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
257 def test__udp_range_action_partial_actual_count_zero(self):
258 traffic_profile = TrexProfile(TrafficProfile)
259 traffic_profile.udp['field1'] = 'value1'
260 udp_partial = traffic_profile._udp_range_action_partial('field1')
262 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
263 udp_partial('1', '1', 'unneeded')
264 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
266 def test__udp_range_action_partial_count_greater_than_actual(self):
267 traffic_profile = TrexProfile(TrafficProfile)
268 traffic_profile.udp['field1'] = 'value1'
269 udp_partial = traffic_profile._udp_range_action_partial('field1', 'not_used_count')
271 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
272 udp_partial('1', '10', '100')
273 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
275 def test__general_single_action_partial(self):
276 trex_profile = TrexProfile(TrafficProfile)
278 trex_profile._general_single_action_partial(ETHERNET)(SRC)(
279 self.EXAMPLE_ETHERNET_ADDR)
280 self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
281 trex_profile.ether_packet.src)
283 trex_profile._general_single_action_partial(IP)(DST)(
284 self.EXAMPLE_IP_ADDR)
285 self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
287 trex_profile._general_single_action_partial(IPv6)(DST)(
288 self.EXAMPLE_IPv6_ADDR)
289 self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
291 trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)
292 self.assertEqual(5060, trex_profile.udp_packet.sport)
294 trex_profile._general_single_action_partial(IP)(TYPE_OF_SERVICE)(0)
295 self.assertEqual(0, trex_profile.ip_packet.tos)
297 def test__set_proto_addr(self):
298 trex_profile = TrexProfile(TrafficProfile)
300 ether_range = "00:00:00:00:00:01-00:00:00:00:00:02"
301 ip_range = "1.1.1.2-1.1.1.10"
302 ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420'
304 trex_profile._set_proto_addr(ETHERNET, SRC, ether_range)
305 trex_profile._set_proto_addr(ETHERNET, DST, ether_range)
306 trex_profile._set_proto_addr(IP, SRC, ip_range)
307 trex_profile._set_proto_addr(IP, DST, ip_range)
308 trex_profile._set_proto_addr(IPv6, SRC, ipv6_range)
309 trex_profile._set_proto_addr(IPv6, DST, ipv6_range)
310 trex_profile._set_proto_addr(UDP, SRC_PORT, "5060-5090")
311 trex_profile._set_proto_addr(UDP, DST_PORT, "5060")