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.
20 from yardstick.common import exceptions as y_exc
21 from yardstick.network_services.traffic_profile import base as tp_base
22 from yardstick.network_services.traffic_profile import trex_traffic_profile
25 class TestTrexProfile(unittest.TestCase):
27 "schema": "isb:traffic_profile:0.1",
29 "description": "Fixed traffic profile to run UDP traffic",
31 "traffic_type": "FixedTraffic",
32 "frame_rate": 100, # pps
36 EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01"
37 EXAMPLE_IP_ADDR = "10.0.0.1"
38 EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
41 'description': 'Traffic profile to run RFC2544 latency',
43 'traffic_profile': {'traffic_type': 'RFC2544Profile',
45 tp_base.TrafficProfile.DOWNLINK: {
46 'ipv4': {'outer_l2': {'framesize': {'64B': '100',
53 "srcmac": "00:00:00:00:00:02",
54 "dstmac": "00:00:00:00:00:01"},
55 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
57 'srcip4': '9.9.1.1-90.1.2.2',
60 'outer_l4': {'srcport': '2001',
63 tp_base.TrafficProfile.UPLINK: {
65 {'outer_l2': {'framesize':
66 {'64B': '100', '1518B': '0',
67 '128B': '0', '1400B': '0',
68 '256B': '0', '373b': '0',
70 "srcmac": "00:00:00:00:00:01",
71 "dstmac": "00:00:00:00:00:02"},
72 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
74 'srcip4': '1.1.1.1-1.15.255.255',
75 'dscp': 0, 'ttl': 32, 'count': 1},
76 'outer_l4': {'dstport': '2001',
79 'schema': 'isb:traffic_profile:0.1'}
81 'description': 'Traffic profile to run RFC2544 latency',
83 'traffic_profile': {'traffic_type': 'RFC2544Profile',
85 tp_base.TrafficProfile.DOWNLINK: {
86 'ipv6': {'outer_l2': {'framesize':
87 {'64B': '100', '1518B': '0',
88 '128B': '0', '1400B': '0',
89 '256B': '0', '373b': '0',
91 "srcmac": "00:00:00:00:00:02",
92 "dstmac": "00:00:00:00:00:01"},
95 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
98 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
101 'outer_l4': {'srcport': '2001',
104 tp_base.TrafficProfile.UPLINK: {
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:01",
111 "dstmac": "00:00:00:00:00:02"},
114 '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
117 '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
118 'dscp': 0, 'ttl': 32,
120 'outer_l4': {'dstport': '2001',
123 'schema': 'isb:traffic_profile:0.1'}
125 def test___init__(self):
126 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
127 self.assertEqual(trex_profile.pps, 100)
130 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
131 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
132 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
134 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
135 self.assertIsNone(trex_profile.set_qinq(qinq))
137 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
138 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
139 self.assertIsNone(trex_profile.set_qinq(qinq))
141 def test__set_outer_l2_fields(self):
142 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
143 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
144 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
145 outer_l2 = self.PROFILE[
146 tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l2']
147 outer_l2['QinQ'] = qinq
148 self.assertIsNone(trex_profile._set_outer_l2_fields(outer_l2))
150 def test__set_outer_l3v4_fields(self):
151 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
152 outer_l3v4 = self.PROFILE[
153 tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
154 outer_l3v4['proto'] = 'tcp'
155 self.assertIsNone(trex_profile._set_outer_l3v4_fields(outer_l3v4))
157 def test__set_outer_l3v6_fields(self):
158 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
159 outer_l3v6 = self.PROFILE_v6[
160 tp_base.TrafficProfile.UPLINK]['ipv6']['outer_l3v4']
161 outer_l3v6['proto'] = 'tcp'
163 outer_l3v6['hlim'] = 10
164 self.assertIsNone(trex_profile._set_outer_l3v6_fields(outer_l3v6))
166 def test__set_outer_l4_fields(self):
167 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
168 outer_l4 = self.PROFILE[
169 tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l4']
170 self.assertIsNone(trex_profile._set_outer_l4_fields(outer_l4))
172 def test__count_ip_ipv4(self):
173 start, end, count = trex_traffic_profile.TrexProfile._count_ip(
174 '1.1.1.1', '1.2.3.4')
175 self.assertEqual('1.1.1.1', str(start))
176 self.assertEqual('1.2.3.4', str(end))
177 diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
178 int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
179 self.assertEqual(diff, count)
181 def test__count_ip_ipv6(self):
182 start_ip = '0064:ff9b:0:0:0:0:9810:6414'
183 end_ip = '0064:ff9b:0:0:0:0:9810:6420'
184 start, end, count = trex_traffic_profile.TrexProfile._count_ip(
186 self.assertEqual(0x98106414, start)
187 self.assertEqual(0x98106420, end)
188 self.assertEqual(0x98106420 - 0x98106414, count)
190 def test__count_ip_ipv6_exception(self):
191 start_ip = '0064:ff9b:0:0:0:0:9810:6420'
192 end_ip = '0064:ff9b:0:0:0:0:9810:6414'
193 with self.assertRaises(y_exc.IPv6RangeError):
194 trex_traffic_profile.TrexProfile._count_ip(start_ip, end_ip)
196 def test__dscp_range_action_partial_actual_count_zero(self):
197 traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
198 dscp_partial = traffic_profile._dscp_range_action_partial()
200 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
201 dscp_partial('1', '1', 'unneeded')
202 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
204 def test__dscp_range_action_partial_count_greater_than_actual(self):
205 traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
206 dscp_partial = traffic_profile._dscp_range_action_partial()
208 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
209 dscp_partial('1', '10', '100')
210 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
212 def test__udp_range_action_partial_actual_count_zero(self):
213 traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
214 traffic_profile.udp['field1'] = 'value1'
215 udp_partial = traffic_profile._udp_range_action_partial('field1')
217 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
218 udp_partial('1', '1', 'unneeded')
219 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
221 def test__udp_range_action_partial_count_greater_than_actual(self):
222 traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
223 traffic_profile.udp['field1'] = 'value1'
224 udp_partial = traffic_profile._udp_range_action_partial(
225 'field1', 'not_used_count')
226 flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
227 udp_partial('1', '10', '100')
228 self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
230 def test__general_single_action_partial(self):
231 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
232 trex_profile._general_single_action_partial(
233 trex_traffic_profile.ETHERNET)(trex_traffic_profile.SRC)(
234 self.EXAMPLE_ETHERNET_ADDR)
235 self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
236 trex_profile.ether_packet.src)
238 trex_profile._general_single_action_partial(trex_traffic_profile.IP)(
239 trex_traffic_profile.DST)(self.EXAMPLE_IP_ADDR)
240 self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
242 trex_profile._general_single_action_partial(trex_traffic_profile.IPv6)(
243 trex_traffic_profile.DST)(self.EXAMPLE_IPv6_ADDR)
244 self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
246 trex_profile._general_single_action_partial(trex_traffic_profile.UDP)(
247 trex_traffic_profile.SRC_PORT)(5060)
248 self.assertEqual(5060, trex_profile.udp_packet.sport)
250 trex_profile._general_single_action_partial(trex_traffic_profile.IP)(
251 trex_traffic_profile.TYPE_OF_SERVICE)(0)
252 self.assertEqual(0, trex_profile.ip_packet.tos)
254 def test__set_proto_addr(self):
255 trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
257 ether_range = "00:00:00:00:00:01-00:00:00:00:00:02"
258 ip_range = "1.1.1.2-1.1.1.10"
259 ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420'
261 trex_profile._set_proto_addr(trex_traffic_profile.ETHERNET,
262 trex_traffic_profile.SRC, ether_range)
263 trex_profile._set_proto_addr(trex_traffic_profile.ETHERNET,
264 trex_traffic_profile.DST, ether_range)
265 trex_profile._set_proto_addr(trex_traffic_profile.IP,
266 trex_traffic_profile.SRC, ip_range)
267 trex_profile._set_proto_addr(trex_traffic_profile.IP,
268 trex_traffic_profile.DST, ip_range)
269 trex_profile._set_proto_addr(trex_traffic_profile.IPv6,
270 trex_traffic_profile.SRC, ipv6_range)
271 trex_profile._set_proto_addr(trex_traffic_profile.IPv6,
272 trex_traffic_profile.DST, ipv6_range)
273 trex_profile._set_proto_addr(trex_traffic_profile.UDP,
274 trex_traffic_profile.SRC_PORT,
276 trex_profile._set_proto_addr(trex_traffic_profile.UDP,
277 trex_traffic_profile.DST_PORT, '5060')