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 yardstick.common import exceptions as y_exc
22 from yardstick.tests import STL_MOCKS
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'}
143 self.trex_profile = TrexProfile(self.PROFILE)
145 def test___init__(self):
146 self.assertEqual(self.trex_profile.pps, 100)
149 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
150 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
152 self.assertIsNone(self.trex_profile.set_qinq(qinq))
154 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
155 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
156 self.assertIsNone(self.trex_profile.set_qinq(qinq))
158 def test__set_outer_l2_fields(self):
159 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
160 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
161 outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2']
162 outer_l2['QinQ'] = qinq
163 self.assertIsNone(self.trex_profile._set_outer_l2_fields(outer_l2))
165 def test__set_outer_l3v4_fields(self):
166 outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
167 outer_l3v4['proto'] = 'tcp'
168 self.assertIsNone(self.trex_profile._set_outer_l3v4_fields(outer_l3v4))
170 def test__set_outer_l3v6_fields(self):
171 outer_l3v6 = self.PROFILE_v6[TrafficProfile.UPLINK]['ipv6']['outer_l3v4']
172 outer_l3v6['proto'] = 'tcp'
174 outer_l3v6['hlim'] = 10
175 self.assertIsNone(self.trex_profile._set_outer_l3v6_fields(outer_l3v6))
177 def test__set_outer_l4_fields(self):
178 outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4']
179 self.assertIsNone(self.trex_profile._set_outer_l4_fields(outer_l4))
181 def test_get_streams(self):
182 profile_data = self.PROFILE[TrafficProfile.UPLINK]
183 self.assertIsNotNone(self.trex_profile.get_streams(profile_data))
184 self.trex_profile.pg_id = 1
185 self.assertIsNotNone(self.trex_profile.get_streams(profile_data))
186 self.trex_profile.params = self.PROFILE_v6
187 self.trex_profile.profile_data = self.PROFILE_v6[TrafficProfile.UPLINK]
188 self.assertIsNotNone(self.trex_profile.get_streams(profile_data))
189 self.trex_profile.pg_id = 1
190 self.assertIsNotNone(self.trex_profile.get_streams(profile_data))
192 def test_generate_packets(self):
193 self.trex_profile.fsize = 10
194 self.trex_profile.base_pkt = [10]
195 self.assertIsNone(self.trex_profile.generate_packets())
197 def test_generate_imix_data_error(self):
198 self.assertEqual({}, self.trex_profile.generate_imix_data(False))
200 def test__count_ip_ipv4(self):
201 start, end, count = TrexProfile._count_ip('1.1.1.1', '1.2.3.4')
202 self.assertEqual('1.1.1.1', str(start))
203 self.assertEqual('1.2.3.4', str(end))
204 diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
205 int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
206 self.assertEqual(diff, count)
208 def test__count_ip_ipv6(self):
209 start_ip = '0064:ff9b:0:0:0:0:9810:6414'
210 end_ip = '0064:ff9b:0:0:0:0:9810:6420'
211 start, end, count = TrexProfile._count_ip(start_ip, end_ip)
212 self.assertEqual(0x98106414, start)
213 self.assertEqual(0x98106420, end)
214 self.assertEqual(0x98106420 - 0x98106414, count)
216 def test__count_ip_ipv6_exception(self):
217 start_ip = '0064:ff9b:0:0:0:0:9810:6420'
218 end_ip = '0064:ff9b:0:0:0:0:9810:6414'
219 with self.assertRaises(y_exc.IPv6RangeError):
220 TrexProfile._count_ip(start_ip, end_ip)
222 def test__dscp_range_action_partial_actual_count_zero(self):
223 traffic_profile = TrexProfile(self.PROFILE)
224 dscp_partial = traffic_profile._dscp_range_action_partial()
226 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
227 dscp_partial('1', '1', 'unneeded')
228 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
230 def test__dscp_range_action_partial_count_greater_than_actual(self):
231 traffic_profile = TrexProfile(self.PROFILE)
232 dscp_partial = traffic_profile._dscp_range_action_partial()
234 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
235 dscp_partial('1', '10', '100')
236 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
238 def test__udp_range_action_partial_actual_count_zero(self):
239 traffic_profile = TrexProfile(self.PROFILE)
240 traffic_profile.udp['field1'] = 'value1'
241 udp_partial = traffic_profile._udp_range_action_partial('field1')
243 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
244 udp_partial('1', '1', 'unneeded')
245 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
247 def test__udp_range_action_partial_count_greater_than_actual(self):
248 traffic_profile = TrexProfile(self.PROFILE)
249 traffic_profile.udp['field1'] = 'value1'
250 udp_partial = traffic_profile._udp_range_action_partial('field1', 'not_used_count')
252 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
253 udp_partial('1', '10', '100')
254 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
256 def test__general_single_action_partial(self):
257 self.trex_profile._general_single_action_partial(ETHERNET)(SRC)(
258 self.EXAMPLE_ETHERNET_ADDR)
259 self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
260 self.trex_profile.ether_packet.src)
262 self.trex_profile._general_single_action_partial(IP)(DST)(
263 self.EXAMPLE_IP_ADDR)
264 self.assertEqual(self.EXAMPLE_IP_ADDR, self.trex_profile.ip_packet.dst)
266 self.trex_profile._general_single_action_partial(IPv6)(DST)(
267 self.EXAMPLE_IPv6_ADDR)
268 self.assertEqual(self.EXAMPLE_IPv6_ADDR,
269 self.trex_profile.ip6_packet.dst)
271 self.trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)
272 self.assertEqual(5060, self.trex_profile.udp_packet.sport)
274 self.trex_profile._general_single_action_partial(
275 IP)(TYPE_OF_SERVICE)(0)
276 self.assertEqual(0, self.trex_profile.ip_packet.tos)
278 def test__set_proto_addr(self):
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 self.trex_profile._set_proto_addr(ETHERNET, SRC, ether_range)
284 self.trex_profile._set_proto_addr(ETHERNET, DST, ether_range)
285 self.trex_profile._set_proto_addr(IP, SRC, ip_range)
286 self.trex_profile._set_proto_addr(IP, DST, ip_range)
287 self.trex_profile._set_proto_addr(IPv6, SRC, ipv6_range)
288 self.trex_profile._set_proto_addr(IPv6, DST, ipv6_range)
289 self.trex_profile._set_proto_addr(UDP, SRC_PORT, '5060-5090')
290 self.trex_profile._set_proto_addr(UDP, DST_PORT, '5060')