1 # Copyright (c) 2016-2019 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.
15 from itertools import repeat, chain
23 from yardstick.common import utils
24 from yardstick.network_services import constants
25 from yardstick.network_services.vnf_generic.vnf import base as vnf_base
26 from yardstick.network_services.vnf_generic.vnf import prox_helpers
27 from yardstick.network_services.vnf_generic.vnf import sample_vnf
30 class TestCoreTuple(unittest.TestCase):
31 def test___init__(self):
32 core_tuple = prox_helpers.CoreSocketTuple('core 5s6')
33 self.assertEqual(core_tuple.core_id, 5)
34 self.assertEqual(core_tuple.socket_id, 6)
35 self.assertFalse(core_tuple.is_hyperthread())
37 core_tuple = prox_helpers.CoreSocketTuple('core 5s6h')
38 self.assertEqual(core_tuple.core_id, 5)
39 self.assertEqual(core_tuple.socket_id, 6)
40 self.assertTrue(core_tuple.is_hyperthread())
42 def test___init__negative(self):
63 for bad_input in bad_inputs:
64 with self.assertRaises(ValueError):
65 prox_helpers.CoreSocketTuple(bad_input)
67 def test_find_in_topology(self):
77 core_tuple = prox_helpers.CoreSocketTuple('core 5s6')
80 result = core_tuple.find_in_topology(topology_in)
81 self.assertEqual(result, expected)
83 core_tuple = prox_helpers.CoreSocketTuple('core 5s6h')
86 result = core_tuple.find_in_topology(topology_in)
87 self.assertEqual(result, expected)
89 def test_find_in_topology_negative(self):
90 core_tuple = prox_helpers.CoreSocketTuple('core 6s5')
91 with self.assertRaises(ValueError):
93 core_tuple.find_in_topology({})
95 with self.assertRaises(ValueError):
97 core_tuple.find_in_topology({5: {}})
99 with self.assertRaises(ValueError):
100 # no first value (as needed by non-hyperthread core)
101 core_tuple.find_in_topology({5: {6: {'key1': []}}})
103 core_tuple = prox_helpers.CoreSocketTuple('core 6s5h')
104 with self.assertRaises(ValueError):
105 # no second value (as needed by hyperthread core)
106 core_tuple.find_in_topology({5: {6: {'key1': ['e']}}})
109 class TestTotStatsTuple(unittest.TestCase):
110 def test___new___negative(self):
111 with self.assertRaises(TypeError):
113 prox_helpers.TotStatsTuple()
115 with self.assertRaises(TypeError):
116 # one, non-integer value
117 prox_helpers.TotStatsTuple('a')
119 with self.assertRaises(TypeError):
121 prox_helpers.TotStatsTuple(3, 4, 5, 6, 7)
124 class TestProxTestDataTuple(unittest.TestCase):
125 def test___init__(self):
126 prox_test_data = prox_helpers.ProxTestDataTuple(
127 1, 2, 3, 4, 5, 6, 7, 8, 9)
128 self.assertEqual(prox_test_data.tolerated, 1)
129 self.assertEqual(prox_test_data.tsc_hz, 2)
130 self.assertEqual(prox_test_data.delta_rx, 3)
131 self.assertEqual(prox_test_data.delta_tx, 4)
132 self.assertEqual(prox_test_data.delta_tsc, 5)
133 self.assertEqual(prox_test_data.latency, 6)
134 self.assertEqual(prox_test_data.rx_total, 7)
135 self.assertEqual(prox_test_data.tx_total, 8)
136 self.assertEqual(prox_test_data.requested_pps, 9)
138 def test_properties(self):
139 prox_test_data = prox_helpers.ProxTestDataTuple(
140 1, 2, 3, 4, 5, 6, 7, 8, 9)
141 self.assertEqual(prox_test_data.pkt_loss, 12.5)
142 self.assertEqual(prox_test_data.tx_mpps, 1.6 / 1e6)
143 self.assertEqual(prox_test_data.can_be_lost, 0)
144 self.assertEqual(prox_test_data.drop_total, 1)
145 self.assertFalse(prox_test_data.success)
147 prox_test_data = prox_helpers.ProxTestDataTuple(
148 10, 2, 3, 4, 5, 6, 997, 998, 9)
149 self.assertTrue(prox_test_data.success)
151 def test_pkt_loss_zero_division(self):
152 prox_test_data = prox_helpers.ProxTestDataTuple(
153 1, 2, 3, 4, 5, 6, 7, 0, 9)
154 self.assertEqual(prox_test_data.pkt_loss, 100.0)
156 def test_get_samples(self):
157 prox_test_data = prox_helpers.ProxTestDataTuple(
158 1, 2, 3, 4, 5, [6.1, 6.9, 6.4], 7, 8, 9)
161 "Throughput": 1.2 / 1e6,
163 "CurrentDropPackets": 12.5,
164 "RequestedTxThroughput": 9 / 1e6,
165 "TxThroughput": 1.6 / 1e6,
166 "RxThroughput": 1.2 / 1e6,
173 result = prox_test_data.get_samples(64, port_samples={"PortSample": 1})
174 self.assertDictEqual(result, expected)
177 "Throughput": 1.2 / 1e6,
178 "DropPackets": 0.123,
179 "CurrentDropPackets": 0.123,
180 "RequestedTxThroughput": 9 / 1e6,
181 "TxThroughput": 1.6 / 1e6,
182 "RxThroughput": 1.2 / 1e6,
188 result = prox_test_data.get_samples(64, 0.123)
189 self.assertDictEqual(result, expected)
191 @mock.patch('yardstick.LOG_RESULT', create=True)
192 def test_log_data(self, mock_logger):
193 my_mock_logger = mock.MagicMock()
194 prox_test_data = prox_helpers.ProxTestDataTuple(
195 1, 2, 3, 4, 5, [6.1, 6.9, 6.4], 7, 8, 9)
196 prox_test_data.log_data()
198 my_mock_logger.debug.assert_not_called()
199 mock_logger.debug.assert_not_called()
201 mock_logger.debug.reset_mock()
202 prox_test_data.log_data(my_mock_logger)
203 my_mock_logger.assert_not_called()
204 mock_logger.debug.assert_not_called()
207 class TestPacketDump(unittest.TestCase):
210 def test__init__(self):
211 prox_helpers.PacketDump("port_id", len(self.PAYLOAD), self.PAYLOAD)
213 def test___str__(self):
214 expected = '<PacketDump port: port_id payload: {}>'.format(self.PAYLOAD)
215 dump1 = prox_helpers.PacketDump(
216 "port_id", len(self.PAYLOAD), self.PAYLOAD)
217 self.assertEqual(str(dump1), expected)
219 def test_port_id(self):
220 p = prox_helpers.PacketDump("port_id", len(self.PAYLOAD), self.PAYLOAD)
221 self.assertEqual(p.port_id, "port_id")
223 def test_data_len(self):
224 p = prox_helpers.PacketDump("port_id", len(self.PAYLOAD), self.PAYLOAD)
225 self.assertEqual(p.data_len, len(self.PAYLOAD))
227 def test_payload(self):
228 p = prox_helpers.PacketDump("port_id", len(self.PAYLOAD), self.PAYLOAD)
229 self.assertEqual(p.payload(), self.PAYLOAD)
231 self.assertEqual(p.payload(3), self.PAYLOAD[3:])
233 self.assertEqual(p.payload(end=3), self.PAYLOAD[:4])
235 self.assertEqual(p.payload(2, 4), self.PAYLOAD[2:5])
247 brown fox jumped over
253 PACKET_DUMP_NON_1 = """\
258 PACKET_DUMP_MIXED_1 = """\
265 PACKET_DUMP_BAD_1 = """\
270 PACKET_DUMP_BAD_2 = """\
275 PACKET_DUMP_BAD_3 = """\
281 class TestProxSocketHelper(unittest.TestCase):
284 self._mock_time_sleep = mock.patch.object(time, 'sleep')
285 self.mock_time_sleep = self._mock_time_sleep.start()
286 self.addCleanup(self._stop_mocks)
288 def _stop_mocks(self):
289 self._mock_time_sleep.stop()
291 @mock.patch.object(prox_helpers, 'socket')
292 def test___init__(self, mock_socket):
293 expected = mock_socket.socket()
294 prox = prox_helpers.ProxSocketHelper()
296 self.assertEqual(result, expected)
298 def test_connect(self):
299 mock_sock = mock.MagicMock()
300 prox = prox_helpers.ProxSocketHelper(mock_sock)
301 prox.connect('10.20.30.40', 23456)
302 mock_sock.connect.assert_called_once()
304 def test_get_sock(self):
305 mock_sock = mock.MagicMock()
306 prox = prox_helpers.ProxSocketHelper(mock_sock)
307 result = prox.get_socket()
308 self.assertIs(result, mock_sock)
310 # TODO(elfoley): Split this into three tests
311 @mock.patch.object(prox_helpers, 'select')
312 def test_get_data(self, mock_select):
313 mock_select.select.side_effect = [[1], [0]]
314 mock_socket = mock.MagicMock()
315 mock_recv = mock_socket.recv()
316 mock_recv.decode.return_value = ""
317 prox = prox_helpers.ProxSocketHelper(mock_socket)
318 ret = prox.get_data()
319 self.assertEqual(ret, "")
320 self.assertEqual(len(prox._pkt_dumps), 0)
322 mock_select.select.reset_mock()
323 mock_select.select.side_effect = chain([['a'], ['']],
325 mock_recv.decode.return_value = PACKET_DUMP_1
326 ret = prox.get_data()
327 self.assertEqual(mock_select.select.call_count, 2)
328 self.assertEqual(ret, 'pktdump,3,11')
329 self.assertEqual(len(prox._pkt_dumps), 1)
331 mock_select.select.reset_mock()
332 mock_select.select.side_effect = chain([[object()], [None]],
334 mock_recv.decode.return_value = PACKET_DUMP_2
335 ret = prox.get_data()
336 self.assertEqual(mock_select.select.call_count, 1)
337 self.assertEqual(ret, 'jumped over')
338 self.assertEqual(len(prox._pkt_dumps), 3)
340 @mock.patch.object(prox_helpers, 'select')
341 def test_get_string(self, mock_select):
342 mock_select.select.side_effect = [[1], [0]]
343 mock_socket = mock.MagicMock()
344 mock_recv = mock_socket.recv()
345 mock_recv.decode.return_value = ""
346 prox = prox_helpers.ProxSocketHelper(mock_socket)
347 status, ret = prox.get_string()
348 self.assertEqual(ret, "")
349 self.assertTrue(status)
350 self.assertEqual(len(prox._pkt_dumps), 0)
352 @mock.patch.object(prox_helpers, 'select')
353 def test_get_string2(self, mock_select):
354 mock_select.select.side_effect = chain([['a'], ['']],
356 mock_socket = mock.MagicMock()
357 mock_recv = mock_socket.recv()
358 mock_recv.decode.return_value = PACKET_DUMP_1
359 prox = prox_helpers.ProxSocketHelper(mock_socket)
360 status, ret = prox.get_string()
361 self.assertEqual(mock_select.select.call_count, 2)
362 self.assertEqual(ret, 'pktdump,3,11')
363 self.assertTrue(status)
364 self.assertEqual(len(prox._pkt_dumps), 1)
366 @mock.patch.object(prox_helpers, 'select')
367 def test_get_string3(self, mock_select):
368 mock_select.select.side_effect = chain([[object()], [None]],
370 mock_socket = mock.MagicMock()
371 mock_recv = mock_socket.recv()
372 mock_recv.decode.return_value = PACKET_DUMP_2
373 prox = prox_helpers.ProxSocketHelper(mock_socket)
374 status, ret = prox.get_string()
375 self.assertTrue(status)
376 self.assertTrue(mock_select.select.assert_called_once)
377 self.assertEqual(ret, 'jumped over')
378 self.assertEqual(len(prox._pkt_dumps), 2)
380 def test__parse_socket_data_mixed_data(self):
381 prox = prox_helpers.ProxSocketHelper(mock.MagicMock())
382 ret, _ = prox._parse_socket_data(PACKET_DUMP_NON_1, False)
383 self.assertEqual(ret, 'not_a_dump,1,2')
384 self.assertEqual(len(prox._pkt_dumps), 0)
386 ret, _ = prox._parse_socket_data(PACKET_DUMP_MIXED_1, False)
387 self.assertEqual(ret, 'not_a_dump,1,2')
388 self.assertEqual(len(prox._pkt_dumps), 1)
390 def test__parse_socket_data_bad_data(self):
391 prox = prox_helpers.ProxSocketHelper(mock.MagicMock())
392 with self.assertRaises(ValueError):
393 prox._parse_socket_data(PACKET_DUMP_BAD_1, False)
395 with self.assertRaises(ValueError):
396 prox._parse_socket_data(PACKET_DUMP_BAD_2, False)
398 ret, _ = prox._parse_socket_data(PACKET_DUMP_BAD_3, False)
399 self.assertEqual(ret, 'pktdump,3')
401 def test__parse_socket_data_pkt_dump_only(self):
402 prox = prox_helpers.ProxSocketHelper(mock.MagicMock())
403 ret, _ = prox._parse_socket_data('', True)
404 self.assertFalse(ret)
406 ret, _ = prox._parse_socket_data(PACKET_DUMP_1, True)
409 ret, _ = prox._parse_socket_data(PACKET_DUMP_2, True)
412 def test_put_command(self):
413 mock_socket = mock.MagicMock()
414 prox = prox_helpers.ProxSocketHelper(mock_socket)
415 prox.put_command("data")
416 mock_socket.sendall.assert_called_once()
418 def test_put_command_socket_error(self):
419 mock_socket = mock.MagicMock()
420 mock_socket.sendall.side_effect = OSError
421 prox = prox_helpers.ProxSocketHelper(mock_socket)
422 prox.put_command("data")
423 mock_socket.sendall.assert_called_once()
425 def test_get_packet_dump(self):
426 mock_socket = mock.MagicMock()
427 prox = prox_helpers.ProxSocketHelper(mock_socket)
429 self.assertIsNone(prox.get_packet_dump())
431 prox._pkt_dumps = [234]
432 self.assertEqual(prox.get_packet_dump(), 234)
433 self.assertEqual(prox._pkt_dumps, [])
435 def test_stop_all_reset(self):
436 mock_socket = mock.MagicMock()
437 prox = prox_helpers.ProxSocketHelper(mock_socket)
438 prox.stop_all_reset()
439 mock_socket.sendall.assert_called()
441 def test_stop_all(self):
442 mock_socket = mock.MagicMock()
443 prox = prox_helpers.ProxSocketHelper(mock_socket)
445 mock_socket.sendall.assert_called()
448 mock_socket = mock.MagicMock()
449 prox = prox_helpers.ProxSocketHelper(mock_socket)
450 prox.stop([3, 4, 5], 16)
451 mock_socket.sendall.assert_called()
453 def test_start_all(self):
454 mock_socket = mock.MagicMock()
455 prox = prox_helpers.ProxSocketHelper(mock_socket)
457 mock_socket.sendall.assert_called()
459 def test_start(self):
460 mock_socket = mock.MagicMock()
461 prox = prox_helpers.ProxSocketHelper(mock_socket)
462 prox.start([3, 4, 5])
463 mock_socket.sendall.assert_called()
465 def test_reset_stats(self):
466 mock_socket = mock.MagicMock()
467 prox = prox_helpers.ProxSocketHelper(mock_socket)
469 mock_socket.sendall.assert_called()
471 def test_set_pkt_size(self):
472 mock_socket = mock.MagicMock()
473 prox = prox_helpers.ProxSocketHelper(mock_socket)
474 prox.set_pkt_size([3, 4, 5], 1024)
475 self.assertEqual(mock_socket.sendall.call_count, 3)
477 def test_set_value(self):
478 mock_socket = mock.MagicMock()
479 prox = prox_helpers.ProxSocketHelper(mock_socket)
480 prox.set_value([3, 4, 5], 10, 20, 30)
481 self.assertEqual(mock_socket.sendall.call_count, 3)
483 def test_reset_values(self):
484 mock_socket = mock.MagicMock()
485 prox = prox_helpers.ProxSocketHelper(mock_socket)
486 prox.reset_values([3, 4, 5])
487 self.assertEqual(mock_socket.sendall.call_count, 3)
489 def test_set_speed(self):
490 mock_socket = mock.MagicMock()
491 prox = prox_helpers.ProxSocketHelper(mock_socket)
492 prox.set_speed([3, 4, 5], 1000)
493 self.assertEqual(mock_socket.sendall.call_count, 3)
495 def test_slope_speed(self):
502 'cores': [9, 10, 11],
507 mock_socket = mock.MagicMock()
508 prox = prox_helpers.ProxSocketHelper(mock_socket)
509 prox.set_speed = set_speed = mock.MagicMock()
510 prox.slope_speed(core_data, 5)
511 self.assertEqual(set_speed.call_count, 20)
513 set_speed.reset_mock()
514 prox.slope_speed(core_data, 5, 5)
515 self.assertEqual(set_speed.call_count, 10)
517 def test_set_pps(self):
518 mock_socket = mock.MagicMock()
519 prox = prox_helpers.ProxSocketHelper(mock_socket)
520 prox.set_pps([3, 4, 5], 1000, 512)
521 self.assertEqual(mock_socket.sendall.call_count, 3)
523 def test_lat_stats(self):
525 '1, 2 , 3', # has white space
527 '7,8,9,10.5,11', # too long with float, but float is in unused portion
528 'twelve,13,14', # value as English word
529 '15,16.2,17', # float in used portion
532 mock_socket = mock.MagicMock()
533 prox = prox_helpers.ProxSocketHelper(mock_socket)
534 prox.get_data = mock.MagicMock(side_effect=latency_output)
550 result = prox.lat_stats([3, 4, 5, 6, 7], 16)
551 self.assertEqual(mock_socket.sendall.call_count, 5)
552 self.assertEqual(result, expected)
554 def test_get_all_tot_stats_error(self):
555 mock_socket = mock.MagicMock()
556 prox = prox_helpers.ProxSocketHelper(mock_socket)
557 prox.get_data = mock.MagicMock(return_value='3,4,5')
558 expected = [0, 0, 0, 0]
559 result = prox.get_all_tot_stats()
560 self.assertEqual(result, expected)
562 def test_get_all_tot_stats(self):
563 mock_socket = mock.MagicMock()
564 prox = prox_helpers.ProxSocketHelper(mock_socket)
565 prox.get_data = mock.MagicMock(return_value='3,4,5,6')
566 expected = 3, 4, 5, 6
567 result = prox.get_all_tot_stats()
568 self.assertEqual(result, expected)
571 mock_socket = mock.MagicMock()
572 prox = prox_helpers.ProxSocketHelper(mock_socket)
573 prox.get_data = mock.MagicMock(return_value='3,4,5,6')
576 self.assertEqual(result, expected)
578 def test_core_stats(self):
585 mock_socket = mock.MagicMock()
586 prox = prox_helpers.ProxSocketHelper(mock_socket)
587 prox.get_data = mock.MagicMock(side_effect=core_stats)
588 expected = 21, 24, 27, 14
589 result = prox.core_stats([3, 4, 5], 16)
590 self.assertEqual(result, expected)
592 @mock.patch.object(prox_helpers.LOG, 'error')
593 def test_irq_core_stats(self, *args):
594 mock_socket = mock.MagicMock()
595 prox = prox_helpers.ProxSocketHelper(mock_socket)
596 prox.get_data = mock.MagicMock(return_value=('0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3'))
598 data_0 = {"cpu": 0, 'bucket_0': 1, 'bucket_1': 2, 'bucket_2': 3, 'bucket_3': 4,
599 'bucket_4': 5, 'bucket_5': 0, 'bucket_6': 1, 'bucket_7': 2, 'bucket_8': 3,
600 'bucket_9': 4, 'bucket_10': 5, 'bucket_11': 0, 'bucket_12': 1,
601 "max_irq": 0, "overflow": 10}
603 data_1 = {"cpu": 1, 'bucket_0': 1, 'bucket_1': 2, 'bucket_2': 3, 'bucket_3': 4,
604 'bucket_4': 5, 'bucket_5': 0, 'bucket_6': 1, 'bucket_7': 2, 'bucket_8': 3,
605 'bucket_9': 4, 'bucket_10': 5, 'bucket_11': 0, 'bucket_12': 1,
606 "max_irq": 0, "overflow": 10}
608 expected = {"core_0": data_0, "core_1": data_1}
610 result = prox.irq_core_stats([[0, 1], [1, 0]])
611 self.assertDictEqual(result, expected)
613 @mock.patch.object(prox_helpers.LOG, 'error')
614 def test_multi_port_stats(self, *args):
615 mock_socket = mock.MagicMock()
616 prox = prox_helpers.ProxSocketHelper(mock_socket)
617 prox.get_string = mock.MagicMock(return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
618 expected = [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]]
619 status, result = prox.multi_port_stats([0, 1])
620 self.assertEqual(result, expected)
621 self.assertEqual(status, True)
623 prox.get_string = mock.MagicMock(
624 return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
625 status, result = prox.multi_port_stats([0])
626 self.assertEqual(status, False)
628 prox.get_string = mock.MagicMock(
629 return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
630 status, result = prox.multi_port_stats([0, 1, 2])
631 self.assertEqual(status, False)
633 prox.get_string = mock.MagicMock(
634 return_value=(True, '0,1,2,3;1,1,2,3,4,5'))
635 status, result = prox.multi_port_stats([0, 1])
636 self.assertEqual(status, False)
638 prox.get_string = mock.MagicMock(
639 return_value=(True, '99,1,2,3,4,5;1,1,2,3,4,5'))
640 status, result = prox.multi_port_stats([0, 1])
641 self.assertEqual(status, False)
643 prox.get_string = mock.MagicMock(
644 return_value=(True, '99,1,2,3,4,5;1,1,2,3,4,5'))
645 status, result = prox.multi_port_stats([99, 1])
646 expected = [[99, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]]
647 self.assertEqual(status, True)
648 self.assertEqual(result, expected)
650 prox.get_string = mock.MagicMock(
652 '2,21,22,23,24,25;1,11,12,13,14,15;0,1,2,3,4,5'))
654 sample1 = [0, 1, 2, 3, 4, 5]
655 sample2 = [1, 11, 12, 13, 14, 15]
656 sample3 = [2, 21, 22, 23, 24, 25]
657 expected = [sample3, sample2, sample1]
658 status, result = prox.multi_port_stats([1, 2, 0])
659 self.assertTrue(status)
660 self.assertListEqual(result, expected)
662 prox.get_string = mock.MagicMock(
663 return_value=(True, '6,21,22,23,24,25;1,11,12,13,14,15;0,1,2,3,4,5'))
664 ok, result = prox.multi_port_stats([1, 6, 0])
665 sample1 = [6, 21, 22, 23, 24, 25]
666 sample2 = [1, 11, 12, 13, 14, 15]
667 sample3 = [0, 1, 2, 3, 4, 5]
668 expected = [sample1, sample2, sample3]
669 self.assertListEqual(result, expected)
672 @mock.patch.object(prox_helpers.LOG, 'error')
673 def test_multi_port_stats_diff(self, *args):
674 mock_socket = mock.MagicMock()
675 prox = prox_helpers.ProxSocketHelper(mock_socket)
676 prox.get_string = mock.MagicMock(return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
677 _, t1 = prox.multi_port_stats([0, 1])
679 prox.get_string = mock.MagicMock(return_value=(True, '0,2,4,6,8,6;1,4,8,16,32,6'))
680 _, t2 = prox.multi_port_stats([0, 1])
682 prox.get_string = mock.MagicMock(return_value=(True, '0,1,1,1,1,1;1,1,1,1,1,1'))
683 _, t3 = prox.multi_port_stats([0, 1])
685 prox.get_string = mock.MagicMock(return_value=(True, '0,2,2,2,2,2;1,2,2,2,2,2'))
686 _, t4 = prox.multi_port_stats([0, 1])
688 expected = [[0, 1.0, 2.0, 0, 0, 1], [1, 3.0, 6.0, 0, 0, 1]]
689 result = prox.multi_port_stats_diff(t1, t2, 1)
691 self.assertListEqual(result, expected)
693 result = prox.multi_port_stats_diff(t4, t3, 1)
694 expected = [[0, 1.0, 1.0, 0, 0, 1], [1, 1.0, 1.0, 0, 0, 1]]
696 self.assertListEqual(result, expected)
698 prox.get_string = mock.MagicMock(return_value=(True, '0,2,4,6,8,10'))
699 ok, t5 = prox.multi_port_stats([0, 1])
701 self.assertListEqual(t5, [])
703 result = prox.multi_port_stats_diff(t5, t4, 1)
704 expected = [[0, 0.0, 0.0, 0, 0, 0], [1, 0.0, 0.0, 0, 0, 0]]
705 self.assertListEqual(result, expected)
707 prox.get_string = mock.MagicMock(return_value=(True, '0,10,10,20,30,0;1,30,40,50,60,0'))
708 _, t6 = prox.multi_port_stats([0, 1])
711 mock.MagicMock(return_value=(True, '0,100,100,100,100,0;1,100,100,100,100,0'))
712 _, t7 = prox.multi_port_stats([0, 1])
714 result = prox.multi_port_stats_diff(t6, t7, 1)
715 expected = [[0, 0.0, 0.0, 0, 0, 0], [1, 0.0, 0.0, 0, 0, 0]]
716 self.assertListEqual(result, expected)
718 result = prox.multi_port_stats_diff(t1, t2, 0)
719 expected = [[0, 0.0, 0.0, 0, 0, 1], [1, 0.0, 0.0, 0, 0, 1]]
720 self.assertListEqual(result, expected)
722 @mock.patch.object(prox_helpers.LOG, 'error')
723 def test_multi_port_stats_tuple(self, *args):
724 mock_socket = mock.MagicMock()
725 prox = prox_helpers.ProxSocketHelper(mock_socket)
726 prox.get_string = mock.MagicMock(return_value=(True, '0,1,2,3,4,5;1,1,2,3,4,5'))
727 _, result1 = prox.multi_port_stats([0, 1])
728 prox.get_string = mock.MagicMock(return_value=(True, '0,2,4,6,8,6;1,4,8,16,32,6'))
729 _, result2 = prox.multi_port_stats([0, 1])
731 result = prox.multi_port_stats_diff(result1, result2, 1)
733 vnfd_helper = mock.MagicMock()
734 vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
736 expected = {'xe0': {'in_packets': 1.0, 'out_packets': 2.0},
737 'xe1': {'in_packets': 3.0, 'out_packets': 6.0}}
738 live_stats = prox.multi_port_stats_tuple(result, vnfd_helper.ports_iter())
739 self.assertDictEqual(live_stats, expected)
741 live_stats = prox.multi_port_stats_tuple(result, None)
743 self.assertDictEqual(live_stats, expected)
745 live_stats = prox.multi_port_stats_tuple(None, vnfd_helper.ports_iter())
746 self.assertDictEqual(live_stats, expected)
748 def test_port_stats(self):
750 ','.join(str(n) for n in range(3, 15)),
751 ','.join(str(n) for n in range(8, 32, 2)),
752 ','.join(str(n) for n in range(5, 89, 7)),
755 mock_socket = mock.MagicMock()
756 prox = prox_helpers.ProxSocketHelper(mock_socket)
757 prox.get_data = mock.MagicMock(side_effect=port_stats)
758 expected = [16, 26, 36, 46, 56, 66, 76, 86, 96, 106, 116, 126]
759 result = prox.port_stats([3, 4, 5])
760 self.assertEqual(result, expected)
762 def test_measure_tot_stats(self):
763 start_tot = 3, 4, 5, 6
764 end_tot = 7, 9, 11, 13
765 delta_tot = 4, 5, 6, 7
768 ','.join(str(n) for n in start_tot),
769 ','.join(str(n) for n in end_tot),
772 mock_socket = mock.MagicMock()
773 prox = prox_helpers.ProxSocketHelper(mock_socket)
774 prox.get_data = mock.MagicMock(side_effect=get_data_output)
776 'start_tot': start_tot,
780 with prox.measure_tot_stats() as result:
782 self.assertEqual(result, expected)
784 def test_tot_stats(self):
785 mock_socket = mock.MagicMock()
786 prox = prox_helpers.ProxSocketHelper(mock_socket)
787 prox.get_data = mock.MagicMock(return_value='3,4,5,6')
789 result = prox.tot_stats()
790 self.assertEqual(result, expected)
792 def test_tot_ierrors(self):
793 mock_socket = mock.MagicMock()
794 prox = prox_helpers.ProxSocketHelper(mock_socket)
795 prox.get_data = mock.MagicMock(return_value='3,4,5,6')
797 result = prox.tot_ierrors()
798 self.assertEqual(result, expected)
800 def test_set_count(self):
801 mock_socket = mock.MagicMock()
802 prox = prox_helpers.ProxSocketHelper(mock_socket)
803 prox.set_count(432, [3, 4, 5])
804 self.assertEqual(mock_socket.sendall.call_count, 3)
806 def test_dump_rx(self):
807 mock_socket = mock.MagicMock()
808 prox = prox_helpers.ProxSocketHelper(mock_socket)
809 prox.dump_rx(3, 5, 8)
810 mock_socket.sendall.assert_called_once()
813 mock_socket = mock.MagicMock()
814 prox = prox_helpers.ProxSocketHelper(mock_socket)
816 mock_socket.sendall.assert_called()
818 def test_force_quit(self):
819 mock_socket = mock.MagicMock()
820 prox = prox_helpers.ProxSocketHelper(mock_socket)
822 mock_socket.sendall.assert_called()
825 class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
828 'short-name': 'ProxVnf',
833 'network': '152.16.100.20',
834 'netmask': '255.255.255.0',
835 'gateway': '152.16.100.20',
839 'network': '152.16.40.20',
840 'netmask': '255.255.255.0',
841 'gateway': '152.16.40.20',
845 'description': 'PROX approximation using DPDK',
846 'name': 'proxvnf-baremetal',
849 'network': '0064:ff9b:0:0:0:0:9810:6414',
851 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
855 'network': '0064:ff9b:0:0:0:0:9810:2814',
857 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
861 'id': 'proxvnf-baremetal',
862 'external-interface': [
864 'virtual-interface': {
865 'dst_mac': '00:00:00:00:00:04',
866 'vpci': '0000:05:00.0',
867 'local_ip': '152.16.100.19',
868 'type': 'PCI-PASSTHROUGH',
869 'vld_id': 'uplink_0',
870 'netmask': '255.255.255.0',
872 'bandwidth': '10 Gbps',
874 'dst_ip': '152.16.100.19',
875 'local_iface_name': 'xe0',
876 'local_mac': '00:00:00:00:00:02',
879 'vnfd-connection-point-ref': 'xe0',
883 'virtual-interface': {
884 'dst_mac': '00:00:00:00:00:03',
885 'vpci': '0000:05:00.1',
886 'local_ip': '152.16.40.19',
887 'type': 'PCI-PASSTHROUGH',
888 'vld_id': 'downlink_0',
890 'netmask': '255.255.255.0',
892 'bandwidth': '10 Gbps',
893 'dst_ip': '152.16.40.20',
894 'local_iface_name': 'xe1',
895 'local_mac': '00:00:00:00:00:01',
898 'vnfd-connection-point-ref': 'xe1',
904 'description': 'PROX approximation using DPDK',
906 'vdu-id': 'proxvnf-baremetal',
919 'id': 'ProxApproxVnf',
924 'vnfd:vnfd-catalog': {
931 def test_global_section(self):
932 setup_helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
933 mock.MagicMock(), mock.MagicMock(), mock.MagicMock())
935 setup_helper._prox_config_data = [('a', [])]
937 with self.assertRaises(KeyError):
938 _ = setup_helper.global_section
942 ('not_name', 'other data'),
943 ('name_not', 'more data'),
944 ('name', 'prox type'),
948 setup_helper._prox_config_data = [
977 result = setup_helper.global_section
978 self.assertEqual(result, global_section[1])
980 def test_find_in_section(self):
981 setup_helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
982 mock.MagicMock(), mock.MagicMock(), mock.MagicMock())
984 setup_helper._prox_config_data = [
986 ('not_name', 'other data'),
987 ('name_not', 'more data'),
988 ('name', 'prox type'),
1018 result = setup_helper.find_in_section('section3', 'key3')
1019 self.assertEqual(result, expected)
1021 expected = 'default value'
1022 result = setup_helper.find_in_section('section3', 'key4', 'default value')
1023 self.assertEqual(result, expected)
1025 with self.assertRaises(KeyError):
1026 setup_helper.find_in_section('section4', 'key1')
1028 with self.assertRaises(KeyError):
1029 setup_helper.find_in_section('section1', 'key1')
1031 def test__replace_quoted_with_value(self):
1035 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1036 _replace_quoted_with_value(input_str, 'cat'))
1037 self.assertEqual(result, expected)
1039 # no quoted substring
1040 input_str = 'lion tiger bear'
1041 expected = 'lion tiger bear'
1042 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1043 _replace_quoted_with_value(input_str, 'cat'))
1044 self.assertEqual(result, expected)
1046 # partially quoted substring
1047 input_str = 'lion "tiger bear'
1048 expected = 'lion "tiger bear'
1049 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1050 _replace_quoted_with_value(input_str, 'cat'))
1051 self.assertEqual(result, expected)
1053 # one quoted substring
1054 input_str = 'lion "tiger" bear'
1055 expected = 'lion "cat" bear'
1056 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1057 _replace_quoted_with_value(input_str, 'cat'))
1058 self.assertEqual(result, expected)
1060 # two quoted substrings
1061 input_str = 'lion "tiger" bear "shark" whale'
1062 expected = 'lion "cat" bear "shark" whale'
1063 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1064 _replace_quoted_with_value(input_str, 'cat'))
1065 self.assertEqual(result, expected)
1067 # two quoted substrings, both replaced
1068 input_str = 'lion "tiger" bear "shark" whale'
1069 expected = 'lion "cat" bear "cat" whale'
1070 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1071 _replace_quoted_with_value(input_str, 'cat', 2))
1072 self.assertEqual(result, expected)
1074 def test__get_tx_port(self):
1076 input_data = {'section1': []}
1078 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1079 _get_tx_port('section1', input_data))
1080 self.assertEqual(result, expected)
1082 # data for other section
1091 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1092 _get_tx_port('section1', input_data))
1093 self.assertEqual(result, expected)
1096 input_data['section1'] = section1 = [
1097 ('rx port', '4', 'more', 432),
1101 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1102 _get_tx_port('section1', input_data))
1103 self.assertEqual(result, expected)
1105 # more data for section,
1108 ('tx port', '1', 'and more', 234),
1111 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1112 _get_tx_port('section1', input_data))
1113 self.assertEqual(result, expected)
1115 # TODO(elfoley): Split this into several smaller tests
1116 def test_write_prox_config(self):
1119 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1120 write_prox_config(input_data))
1121 self.assertEqual(result, expected)
1129 expected = '[section1]'
1130 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1131 write_prox_config(input_data))
1132 self.assertEqual(result, expected)
1143 ['__name__', 'not this one'],
1146 ['key4', 'multi-line\nvalue'],
1150 expected = os.linesep.join([
1156 'key4=multi-line\n\tvalue',
1158 result = (prox_helpers.ProxDpdkVnfSetupEnvHelper.
1159 write_prox_config(input_data))
1160 self.assertEqual(result, expected)
1162 def test_prox_config_data(self):
1163 setup_helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1164 mock.MagicMock(), mock.MagicMock(), mock.MagicMock())
1166 setup_helper.config_queue = config_queue = mock.MagicMock()
1167 config_queue.get.return_value = expected = [('s', [('a', 3), ('b', 45)])]
1169 result = setup_helper.prox_config_data
1170 self.assertEqual(result, expected)
1172 @mock.patch.object(utils, 'find_relative_file')
1173 def test_build_config_file_no_additional_file(self, mock_find_path):
1175 'prox_args': {'-c': ""},
1177 'prox_config': 'e/f',
1178 'prox_generate_parameter': False,
1181 mock_find_path.side_effect = ['1', '2']
1183 vnfd_helper = mock.MagicMock()
1184 ssh_helper = mock.MagicMock()
1185 scenario_helper = sample_vnf.ScenarioHelper('vnf1')
1186 scenario_helper.scenario_cfg = {
1193 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1194 vnfd_helper, ssh_helper, scenario_helper)
1195 helper.copy_to_target = mock.MagicMock(return_value='3')
1196 helper.generate_prox_config_file = mock.MagicMock(return_value='4')
1197 helper.upload_prox_config = mock.MagicMock(return_value='5')
1199 self.assertEqual(helper.additional_files, {})
1200 self.assertNotEqual(helper._prox_config_data, '4')
1201 self.assertNotEqual(helper.remote_path, '5')
1202 helper.build_config_file()
1203 self.assertEqual(helper.additional_files, {})
1204 self.assertEqual(helper._prox_config_data, '4')
1205 self.assertEqual(helper.remote_path, '5')
1207 @mock.patch.object(utils, 'find_relative_file')
1208 def test_build_config_file_additional_file_string(self, mock_find_path):
1210 'prox_args': {'-c': ""},
1212 'prox_config': 'e/f',
1213 'prox_files': 'g/h.i',
1214 'prox_generate_parameter': True,
1217 mock_find_path.side_effect = ['1', '2']
1218 vnfd_helper = mock.MagicMock()
1219 ssh_helper = mock.MagicMock()
1220 scenario_helper = sample_vnf.ScenarioHelper('vnf1')
1221 scenario_helper.scenario_cfg = {
1228 vnfd_helper.port_pairs.all_ports = ['xe0', 'xe1', 'xe2', 'xe3']
1229 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1230 vnfd_helper, ssh_helper, scenario_helper)
1231 helper.copy_to_target = mock.MagicMock(side_effect=['33', '34', '35'])
1232 helper.generate_prox_config_file = mock.MagicMock(return_value='44')
1233 helper.upload_prox_config = mock.MagicMock(return_value='55')
1235 self.assertEqual(helper.additional_files, {})
1236 expected = {'h.i': '33'}
1237 helper.build_config_file()
1238 self.assertDictEqual(helper.additional_files, expected)
1240 @mock.patch.object(utils, 'find_relative_file')
1241 def test_build_config_file_additional_file(self, mock_find_path):
1243 'prox_args': {'-c': ""},
1245 'prox_config': 'e/f',
1253 mock_find_path.side_effect = ['1', '2'] + [str(i) for i in range(len(vnf1['prox_files']))]
1254 vnfd_helper = mock.MagicMock()
1255 ssh_helper = mock.MagicMock()
1256 scenario_helper = sample_vnf.ScenarioHelper('vnf1')
1257 scenario_helper.scenario_cfg = {
1264 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1265 vnfd_helper, ssh_helper, scenario_helper)
1266 helper.copy_to_target = mock.MagicMock(side_effect=['33', '34', '35'])
1267 helper.generate_prox_config_file = mock.MagicMock(return_value='44')
1268 helper.upload_prox_config = mock.MagicMock(return_value='55')
1270 self.assertEqual(helper.additional_files, {})
1271 self.assertNotEqual(helper._prox_config_data, '44')
1272 self.assertNotEqual(helper.remote_path, '55')
1273 expected = {'h.i': '33', 'l': '34', 'm_n': '35'}
1274 helper.build_config_file()
1275 self.assertDictEqual(helper.additional_files, expected)
1276 self.assertEqual(helper._prox_config_data, '44')
1277 self.assertEqual(helper.remote_path, '55')
1279 def test_build_config(self):
1281 'prox_args': {'-f': ""},
1282 'prox_path': '/opt/nsb_bin/prox',
1283 'prox_config': 'configs/gen_l2fwd-2.cfg',
1291 vnfd_helper = mock.Mock()
1292 ssh_helper = mock.Mock()
1293 ssh_helper.join_bin_path.return_value = '/opt/nsb_bin/prox'
1294 scenario_helper = sample_vnf.ScenarioHelper('vnf1')
1295 scenario_helper.scenario_cfg = {
1302 expected = ("sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli "
1303 "-f -f /tmp/prox.cfg '")
1305 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1306 vnfd_helper, ssh_helper, scenario_helper)
1307 with mock.patch.object(helper, 'build_config_file') as mock_cfg_file:
1308 helper.remote_path = '/tmp/prox.cfg'
1309 prox_cmd = helper.build_config()
1310 self.assertEqual(prox_cmd, expected)
1311 mock_cfg_file.assert_called_once()
1313 def test__insert_additional_file(self):
1314 vnfd_helper = mock.MagicMock()
1315 ssh_helper = mock.MagicMock()
1316 scenario_helper = mock.MagicMock()
1318 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1319 vnfd_helper, ssh_helper, scenario_helper)
1320 helper.additional_files = {"ipv4.lua": "/tmp/ipv4.lua"}
1321 res = helper._insert_additional_file('dofile("ipv4.lua")')
1322 self.assertEqual(res, 'dofile("/tmp/ipv4.lua")')
1324 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ConfigParser')
1325 def test_generate_prox_config_file(self, mock_parser_type):
1328 args[-1].extend(sections_data)
1329 return mock.MagicMock()
1333 mock_parser_type.side_effect = init
1335 vnfd_helper = vnf_base.VnfdHelper(self.VNFD0)
1336 ssh_helper = mock.MagicMock()
1337 scenario_helper = mock.MagicMock()
1339 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1340 vnfd_helper, ssh_helper, scenario_helper)
1341 helper.additional_files = {}
1344 result = helper.generate_prox_config_file('a/b')
1345 self.assertEqual(result, expected)
1347 helper.additional_files = {"ipv4.lua": "/tmp/ipv4.lua"}
1349 helper.remote_prox_file_name = 'remote'
1354 ['dofile("ipv4.lua")', ''],
1370 ['$sut_mac0', '@@dst_mac0'],
1373 ['user_table', 'dofile("ipv4.lua")'],
1374 ['missing_addtional_file', 'dofile("nosuch")'],
1413 ['dofile("/tmp/ipv4.lua")', ''],
1420 ['mac', 'hardware'],
1421 ['dst mac', '00:00:00:00:00:03'],
1429 ['$sut_mac0', '00 00 00 00 00 04'],
1432 ['user_table', 'dofile("/tmp/ipv4.lua")'],
1433 ['missing_addtional_file', 'dofile("nosuch")'],
1485 result = helper.generate_prox_config_file('/c/d/e')
1486 self.assertEqual(result, expected, str(result))
1488 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ConfigParser')
1489 def test_generate_prox_config_file_negative(self, mock_parser_type):
1491 args[-1].update(sections_data)
1492 return mock.MagicMock()
1496 mock_parser_type.side_effect = init
1498 vnfd_helper = mock.MagicMock()
1499 vnfd_helper.interfaces = []
1500 ssh_helper = mock.MagicMock()
1501 scenario_helper = mock.MagicMock()
1503 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1504 vnfd_helper, ssh_helper, scenario_helper)
1505 helper.additional_files = {}
1506 helper.remote_prox_file_name = 'remote'
1507 vnfd_helper.interfaces = [
1509 'virtual-interface': {
1511 'dst_mac': '00:00:00:de:ad:88',
1515 'virtual-interface': {
1517 'dst_mac': '00:00:00:de:ad:ff',
1521 'virtual-interface': {
1523 'dst_mac': '00:00:00:de:ad:ff',
1537 ['???', 'dofile "here" 23'],
1541 with self.assertRaises(Exception):
1542 helper.generate_prox_config_file('a/b')
1544 def test_put_string_to_file(self):
1545 vnfd_helper = mock.MagicMock()
1546 vnfd_helper.interfaces = []
1547 ssh_helper = mock.MagicMock()
1548 scenario_helper = mock.MagicMock()
1550 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1551 vnfd_helper, ssh_helper, scenario_helper)
1554 result = helper.put_string_to_file('my long string', 'a/b')
1555 self.assertEqual(result, expected)
1557 def test_copy_to_target(self):
1558 vnfd_helper = mock.MagicMock()
1559 vnfd_helper.interfaces = []
1560 ssh_helper = mock.MagicMock()
1561 scenario_helper = mock.MagicMock()
1563 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1564 vnfd_helper, ssh_helper, scenario_helper)
1566 result = helper.copy_to_target('a/b', 'c')
1567 self.assertEqual(result, expected)
1569 def test_upload_prox_config(self):
1570 vnfd_helper = mock.MagicMock()
1571 vnfd_helper.interfaces = []
1572 ssh_helper = mock.MagicMock()
1573 scenario_helper = mock.MagicMock()
1575 helper = prox_helpers.ProxDpdkVnfSetupEnvHelper(
1576 vnfd_helper, ssh_helper, scenario_helper)
1577 helper.write_prox_config = mock.MagicMock(return_value='a long string')
1579 result = helper.upload_prox_config('a', {})
1580 self.assertEqual(result, expected)
1583 class TestProxResourceHelper(unittest.TestCase):
1586 'short-name': 'ProxVnf',
1591 'network': '152.16.100.20',
1592 'netmask': '255.255.255.0',
1593 'gateway': '152.16.100.20',
1597 'network': '152.16.40.20',
1598 'netmask': '255.255.255.0',
1599 'gateway': '152.16.40.20',
1603 'description': 'PROX approximation using DPDK',
1604 'name': 'proxvnf-baremetal',
1607 'network': '0064:ff9b:0:0:0:0:9810:6414',
1609 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
1613 'network': '0064:ff9b:0:0:0:0:9810:2814',
1615 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
1619 'id': 'proxvnf-baremetal',
1620 'external-interface': [
1622 'virtual-interface': {
1623 'dst_mac': '00:00:00:00:00:04',
1624 'vpci': '0000:05:00.0',
1625 'local_ip': '152.16.100.19',
1626 'type': 'PCI-PASSTHROUGH',
1627 'vld_id': 'uplink_0',
1628 'netmask': '255.255.255.0',
1630 'bandwidth': '10 Gbps',
1632 'dst_ip': '152.16.100.19',
1633 'local_iface_name': 'xe0',
1634 'local_mac': '00:00:00:00:00:02',
1637 'vnfd-connection-point-ref': 'xe0',
1641 'virtual-interface': {
1642 'dst_mac': '00:00:00:00:00:03',
1643 'vpci': '0000:05:00.1',
1644 'local_ip': '152.16.40.19',
1645 'type': 'PCI-PASSTHROUGH',
1646 'vld_id': 'downlink_0',
1648 'netmask': '255.255.255.0',
1650 'bandwidth': '10 Gbps',
1651 'dst_ip': '152.16.40.20',
1652 'local_iface_name': 'xe1',
1653 'local_mac': '00:00:00:00:00:01',
1656 'vnfd-connection-point-ref': 'xe1',
1662 'description': 'PROX approximation using DPDK',
1664 'vdu-id': 'proxvnf-baremetal',
1677 'id': 'ProxApproxVnf',
1682 'vnfd:vnfd-catalog': {
1689 def test_find_pci(self):
1695 result = prox_helpers.ProxResourceHelper.find_pci('target',
1697 self.assertFalse(result)
1705 result = prox_helpers.ProxResourceHelper.find_pci('target',
1707 self.assertTrue(result)
1709 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.RETRY_INTERVAL', 0)
1710 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper')
1711 def test_sut(self, *args):
1712 helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
1713 self.assertIsNone(helper.client)
1715 self.assertIsNotNone(result)
1716 self.assertIs(result, helper.client)
1717 self.assertIs(result, helper.sut)
1719 def test_test_type(self):
1720 setup_helper = mock.MagicMock()
1721 setup_helper.find_in_section.return_value = expected = 'prox type'
1723 helper = prox_helpers.ProxResourceHelper(setup_helper)
1725 self.assertIsNone(helper._test_type)
1726 self.assertEqual(helper.test_type, expected)
1727 self.assertEqual(helper._test_type, expected)
1728 self.assertEqual(helper.test_type, expected)
1730 def test_collect_collectd_kpi(self):
1731 helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
1732 helper.resource = resource = mock.MagicMock()
1734 resource.check_if_system_agent_running.return_value = 0, '1234'
1735 resource.amqp_collect_nfvi_kpi.return_value = 543
1736 resource.check_if_system_agent_running.return_value = (0, None)
1738 expected = {'core': 543}
1739 result = helper.collect_collectd_kpi()
1740 self.assertDictEqual(result, expected)
1742 def test_collect_kpi(self):
1743 helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
1744 helper._queue = queue = mock.MagicMock()
1745 helper._result = {'z': 123}
1747 helper.client = mock.MagicMock()
1748 helper.client.hz.return_value = 1
1749 helper.client.multi_port_stats.return_value = \
1750 (True, [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
1751 helper.client.multi_port_stats_diff.return_value = \
1752 ([0, 1, 2, 3, 4, 5, 6, 7])
1753 helper.client.multi_port_stats_tuple.return_value = \
1754 {"xe0": {"in_packets": 1, "out_packets": 2}}
1755 helper.resource = resource = mock.MagicMock()
1757 vnfd_helper = mock.MagicMock()
1758 vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
1759 helper.vnfd_helper = vnfd_helper
1761 resource.check_if_system_agent_running.return_value = 0, '1234'
1762 resource.amqp_collect_nfvi_kpi.return_value = 543
1763 resource.check_if_system_agent_running.return_value = (0, None)
1765 queue.empty.return_value = False
1766 queue.get.return_value = {'a': 789}
1768 expected = {'z': 123, 'a': 789,
1769 'collect_stats': {'core': 543},
1770 'live_stats': {'xe0': {'in_packets': 1, 'out_packets': 2}}}
1771 result = helper.collect_kpi()
1772 self.assertDictEqual(result, expected)
1774 def test_collect_kpi_no_hz(self):
1775 helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
1776 helper._queue = queue = mock.MagicMock()
1777 helper._result = {'z': 123}
1779 helper.client = mock.MagicMock()
1780 helper.client.multi_port_stats.return_value = \
1781 (True, [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
1782 helper.client.multi_port_stats_diff.return_value = \
1783 ([0, 1, 2, 3, 4, 5, 6, 7])
1784 helper.client.multi_port_stats_tuple.return_value = \
1785 {"xe0": {"in_packets": 1, "out_packets": 2}}
1786 helper.resource = resource = mock.MagicMock()
1788 vnfd_helper = mock.MagicMock()
1789 vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
1790 helper.vnfd_helper = vnfd_helper
1792 resource.check_if_system_agent_running.return_value = 0, '1234'
1793 resource.amqp_collect_nfvi_kpi.return_value = 543
1794 resource.check_if_system_agent_running.return_value = (0, None)
1796 queue.empty.return_value = False
1797 queue.get.return_value = {'a': 789}
1799 expected = {'z': 123, 'a': 789,
1800 'collect_stats': {'core': 543},
1801 'live_stats': {'xe0': {'in_packets': 1, 'out_packets': 2}}}
1802 result = helper.collect_kpi()
1803 self.assertDictEqual(result, expected)
1805 def test_collect_kpi_bad_data(self):
1806 helper = prox_helpers.ProxResourceHelper(mock.MagicMock())
1807 helper._queue = queue = mock.MagicMock()
1808 helper._result = {'z': 123}
1810 helper.client = mock.MagicMock()
1811 helper.client.multi_port_stats.return_value = \
1812 (False, [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
1813 helper.client.multi_port_stats_diff.return_value = \
1814 ([0, 1, 2, 3, 4, 5, 6, 7])
1815 helper.client.multi_port_stats_tuple.return_value = \
1816 {"xe0": {"in_packets": 1, "out_packets": 2}}
1817 helper.resource = resource = mock.MagicMock()
1819 vnfd_helper = mock.MagicMock()
1820 vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
1821 helper.vnfd_helper = vnfd_helper
1823 resource.check_if_system_agent_running.return_value = 0, '1234'
1824 resource.amqp_collect_nfvi_kpi.return_value = 543
1825 resource.check_if_system_agent_running.return_value = (0, None)
1827 queue.empty.return_value = False
1828 queue.get.return_value = {'a': 789}
1830 expected = {'z': 123, 'a': 789,
1831 'collect_stats': {'core': 543}}
1832 result = helper.collect_kpi()
1833 self.assertDictEqual(result, expected)
1835 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
1836 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper')
1837 def test__connect(self, mock_socket_helper_type, *args):
1838 client = mock_socket_helper_type()
1839 client.connect.side_effect = chain(repeat(socket.error, 5), [None])
1841 setup_helper = mock.MagicMock()
1842 setup_helper.vnfd_helper.interfaces = []
1844 helper = prox_helpers.ProxResourceHelper(setup_helper)
1846 result = helper._connect()
1847 self.assertIs(result, client)
1849 client.connect.side_effect = chain(repeat(socket.error, 65), [None])
1851 with self.assertRaises(Exception):
1854 def test_run_traffic(self):
1855 setup_helper = mock.MagicMock()
1856 helper = prox_helpers.ProxResourceHelper(setup_helper)
1857 traffic_profile = mock.MagicMock()
1858 traffic_profile.done.is_set.return_value = True
1859 helper.run_traffic(traffic_profile)
1860 self.assertEqual(helper._terminated.value, 1)
1862 def test__run_traffic_once(self):
1863 setup_helper = mock.MagicMock()
1864 helper = prox_helpers.ProxResourceHelper(setup_helper)
1865 traffic_profile = mock.MagicMock()
1866 traffic_profile.done.is_set.return_value = True
1867 helper._run_traffic_once(traffic_profile)
1868 self.assertEqual(helper._terminated.value, 1)
1870 def test_start_collect(self):
1871 setup_helper = mock.MagicMock()
1872 helper = prox_helpers.ProxResourceHelper(setup_helper)
1873 helper.resource = resource = mock.MagicMock()
1874 self.assertIsNone(helper.start_collect())
1875 resource.start.assert_called_once()
1877 def test_terminate(self):
1878 setup_helper = mock.MagicMock()
1879 helper = prox_helpers.ProxResourceHelper(setup_helper)
1880 with self.assertRaises(NotImplementedError):
1883 def test_up_post(self):
1884 setup_helper = mock.MagicMock()
1885 helper = prox_helpers.ProxResourceHelper(setup_helper)
1886 helper.client = expected = mock.MagicMock()
1887 result = helper.up_post()
1888 self.assertEqual(result, expected)
1890 def test_execute(self):
1891 setup_helper = mock.MagicMock()
1892 helper = prox_helpers.ProxResourceHelper(setup_helper)
1893 helper.client = mock.MagicMock()
1895 expected = helper.client.my_command()
1896 result = helper.execute('my_command')
1897 self.assertEqual(result, expected)
1899 # TODO(elfoley): Make this a separate test: test_execute_no_client
1900 helper.client = object()
1902 result = helper.execute('my_command')
1903 self.assertIsNone(result)
1906 class TestProxDataHelper(unittest.TestCase):
1908 def test_totals_and_pps(self):
1910 vnfd_helper = mock.MagicMock()
1911 vnfd_helper.port_pairs.all_ports = list(range(4))
1913 sut = mock.MagicMock()
1914 sut.multi_port_stats.return_value = (True,
1915 [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5],
1916 [2, 1, 2, 3, 4, 5], [3, 1, 2, 3, 4, 5]])
1918 data_helper = prox_helpers.ProxDataHelper(
1919 vnfd_helper, sut, pkt_size, 25, None,
1920 constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
1922 self.assertEqual(data_helper.rx_total, 4)
1923 self.assertEqual(data_helper.tx_total, 8)
1924 self.assertEqual(data_helper.requested_pps, 6250000.0)
1926 vnfd_helper = mock.MagicMock()
1927 vnfd_helper.port_pairs.all_ports = [3, 4]
1929 sut = mock.MagicMock()
1930 sut.multi_port_stats.return_value = (True,
1931 [[3, 1, 2, 3, 4, 5], [4, 1, 2, 3, 4, 5]])
1933 data_helper = prox_helpers.ProxDataHelper(
1934 vnfd_helper, sut, pkt_size, 25, None,
1935 constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
1937 self.assertEqual(data_helper.rx_total, 2)
1938 self.assertEqual(data_helper.tx_total, 4)
1939 self.assertEqual(data_helper.requested_pps, 3125000.0)
1941 vnfd_helper = mock.MagicMock()
1942 vnfd_helper.port_pairs.all_ports = [0, 1, 2, 3, 4, 6, 7]
1944 sut = mock.MagicMock()
1945 sut.multi_port_stats.return_value = (True,
1946 [[8, 1, 2, 3, 4, 5], [9, 1, 2, 3, 4, 5]])
1948 data_helper = prox_helpers.ProxDataHelper(
1949 vnfd_helper, sut, pkt_size, 25, None,
1950 constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
1952 self.assertEqual(data_helper.rx_total, 2)
1953 self.assertEqual(data_helper.tx_total, 4)
1954 self.assertEqual(data_helper.requested_pps, 10937500.0)
1956 vnfd_helper = mock.MagicMock()
1957 vnfd_helper.port_pairs.all_ports = []
1959 sut = mock.MagicMock()
1960 sut.multi_port_stats.return_value = (True,
1961 [[8, 1, 2, 3, 4, 5], [9, 1, 2, 3, 4, 5]])
1963 data_helper = prox_helpers.ProxDataHelper(
1964 vnfd_helper, sut, pkt_size, 25, None,
1965 constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
1967 self.assertEqual(data_helper.rx_total, 2)
1968 self.assertEqual(data_helper.tx_total, 4)
1969 self.assertEqual(data_helper.requested_pps, 0.0)
1971 def test_totals_and_pps2(self):
1973 vnfd_helper = mock.MagicMock()
1974 vnfd_helper.port_pairs.all_ports = list(range(4))
1976 sut = mock.MagicMock()
1977 sut.multi_port_stats.return_value = (True,
1978 [[0, 'A', 2, 3, 4, 5], [1, 'B', 'C', 3, 4, 5],
1979 ['D', 1, 2, 3, 4, 5], [3, 1, 2, 3, 4, 'F']])
1981 data_helper = prox_helpers.ProxDataHelper(
1982 vnfd_helper, sut, pkt_size, 25, None,
1983 constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
1985 self.assertEqual(data_helper.rx_total, 0)
1986 self.assertEqual(data_helper.tx_total, 0)
1987 self.assertEqual(data_helper.requested_pps, 0)
1989 def test_samples(self):
1990 vnfd_helper = mock.MagicMock()
1991 vnfd_helper.ports_iter.return_value = [('xe0', 0), ('xe1', 1)]
1993 sut = mock.MagicMock()
1994 sut.multi_port_stats.return_value = (True, [[0, 1, 2, 3, 4, 5], [1, 11, 12, 3, 4, 5]])
1996 data_helper = prox_helpers.ProxDataHelper(
1997 vnfd_helper, sut, None, None, None, None)
2009 result = data_helper.samples
2010 self.assertDictEqual(result, expected)
2012 def test_samples2(self):
2013 vnfd_helper = mock.MagicMock()
2014 vnfd_helper.ports_iter.return_value = [('xe1', 3), ('xe2', 7)]
2016 sut = mock.MagicMock()
2017 sut.multi_port_stats.return_value = (True, [[3, 1, 2, 3, 4, 5], [7, 11, 12, 3, 4, 5]])
2019 data_helper = prox_helpers.ProxDataHelper(
2020 vnfd_helper, sut, None, None, None, None)
2032 result = data_helper.samples
2033 self.assertDictEqual(result, expected)
2035 def test___enter__(self):
2036 vnfd_helper = mock.MagicMock()
2037 vnfd_helper.port_pairs.all_ports = list(range(4))
2038 vnfd_helper.ports_iter.return_value = [('xe1', 3), ('xe2', 7)]
2040 sut = mock.MagicMock()
2042 data_helper = prox_helpers.ProxDataHelper(vnfd_helper, sut, None, None,
2043 5.4, constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2044 data_helper._totals_and_pps = 12, 32, 4.5
2045 data_helper.tsc_hz = 9.8
2046 data_helper.measured_stats = {
2047 'delta': prox_helpers.TotStatsTuple(6.1, 6.2, 6.3, 6.4)}
2048 data_helper.latency = 7
2050 self.assertIsNone(data_helper.result_tuple)
2051 self.assertEqual(data_helper.line_speed, 10000000000)
2053 expected = prox_helpers.ProxTestDataTuple(
2054 5.4, 9.8, 6.1, 6.2, 6.3, 7, 12, 32, 4.5)
2058 result = data_helper.result_tuple
2059 self.assertEqual(result, expected)
2061 data_helper.make_tuple()
2062 self.assertIs(data_helper.result_tuple, result)
2064 def test___enter___negative(self):
2065 vnfd_helper = mock.MagicMock()
2067 data_helper = prox_helpers.ProxDataHelper(
2068 vnfd_helper, None, None, None, None, None)
2070 vnfd_helper.port_pairs.all_ports = []
2071 with self.assertRaises(AssertionError):
2075 vnfd_helper.port_pairs.all_ports = [0, 1, 2]
2076 with self.assertRaises(AssertionError):
2080 def test_measure_tot_stats(self):
2081 vnfd_helper = mock.MagicMock()
2082 vnfd_helper.port_pairs.all_ports = list(range(4))
2084 start = (3, 4, 1, 2)
2087 sut = prox_helpers.ProxSocketHelper(mock.MagicMock())
2088 sut.get_all_tot_stats = mock.MagicMock(side_effect=[start, end])
2090 data_helper = prox_helpers.ProxDataHelper(
2091 vnfd_helper, sut, None, None, 5.4, None)
2093 self.assertIsNone(data_helper.measured_stats)
2098 'delta': prox_helpers.TotStatsTuple(6, 3, 5, 6),
2100 with data_helper.measure_tot_stats():
2103 self.assertEqual(data_helper.measured_stats, expected)
2105 def test_capture_tsc_hz(self):
2106 vnfd_helper = mock.MagicMock()
2107 vnfd_helper.port_pairs.all_ports = list(range(4))
2109 sut = mock.MagicMock()
2110 sut.hz.return_value = '54.6'
2112 data_helper = prox_helpers.ProxDataHelper(
2113 vnfd_helper, sut, None, None, None, None)
2115 self.assertIsNone(data_helper.tsc_hz)
2118 data_helper.capture_tsc_hz()
2119 self.assertEqual(data_helper.tsc_hz, expected)
2122 class TestProxProfileHelper(unittest.TestCase):
2124 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.utils')
2125 def test_get_cls(self, mock_utils):
2126 mock_type1 = mock.MagicMock()
2127 mock_type1.__prox_profile_type__ = 'another_type'
2128 mock_type2 = mock.MagicMock()
2129 mock_type2.__prox_profile_type__ = 'my_type'
2130 mock_utils.itersubclasses.return_value = [mock_type1, mock_type2]
2132 self.assertEqual(prox_helpers.ProxProfileHelper.get_cls('my_type'),
2135 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.utils')
2136 def test_get_cls_default(self, mock_utils):
2137 mock_utils.itersubclasses.return_value = []
2138 prox_helpers.ProxProfileHelper.get_cls('my_type')
2140 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.SocketTopology')
2141 def test_cpu_topology(self, mock_socket_topology):
2142 mock_socket_topology.parse_cpuinfo.return_value = 432
2144 resource_helper = mock.MagicMock()
2145 resource_helper.setup_helper.ssh_helper.execute.return_value = 0, 'output', ''
2147 helper = prox_helpers.ProxProfileHelper(resource_helper)
2148 self.assertIsNone(helper._cpu_topology)
2149 result = helper.cpu_topology
2150 self.assertEqual(result, 432)
2151 self.assertIs(result, helper._cpu_topology)
2152 self.assertIs(result, helper.cpu_topology)
2154 # TODO(elfoley): Split this test; there are two sets of inputs/outputs
2155 def test_test_cores(self):
2156 resource_helper = mock.MagicMock()
2157 resource_helper.setup_helper.prox_config_data = []
2159 helper = prox_helpers.ProxProfileHelper(resource_helper)
2160 helper._cpu_topology = []
2163 result = helper.test_cores
2164 self.assertEqual(result, expected)
2166 resource_helper.setup_helper.prox_config_data = [
2187 helper = prox_helpers.ProxProfileHelper(resource_helper)
2188 helper._cpu_topology = {
2205 self.assertIsNone(helper._test_cores)
2207 result = helper.test_cores
2208 self.assertEqual(result, expected)
2209 self.assertIs(result, helper._test_cores)
2210 self.assertIs(result, helper.test_cores)
2212 # TODO(elfoley): Split this test; there are two sets of inputs/outputs
2213 def test_latency_cores(self):
2214 resource_helper = mock.MagicMock()
2215 resource_helper.setup_helper.prox_config_data = []
2217 helper = prox_helpers.ProxProfileHelper(resource_helper)
2218 helper._cpu_topology = []
2221 result = helper.latency_cores
2222 self.assertEqual(result, expected)
2224 resource_helper.setup_helper.prox_config_data = [
2245 helper = prox_helpers.ProxProfileHelper(resource_helper)
2246 helper._cpu_topology = {
2263 self.assertIsNone(helper._latency_cores)
2265 result = helper.latency_cores
2266 self.assertEqual(result, expected)
2267 self.assertIs(result, helper._latency_cores)
2268 self.assertIs(result, helper.latency_cores)
2270 def test_all_rx_cores(self):
2271 helper = prox_helpers.ProxBngProfileHelper(mock.MagicMock())
2272 helper._latency_cores = expected = [3, 4, 6]
2273 helper._test_cores = [5, 2, 1]
2275 result = helper.all_rx_cores
2276 self.assertEqual(result, expected)
2278 def test_get_cores(self):
2279 resource_helper = mock.MagicMock()
2280 resource_helper.setup_helper.prox_config_data = [
2301 helper = prox_helpers.ProxProfileHelper(resource_helper)
2302 helper._cpu_topology = {
2320 result = helper.get_cores(helper.PROX_CORE_GEN_MODE)
2321 self.assertEqual(result, expected)
2323 def test_get_latency(self):
2324 resource_helper = mock.MagicMock()
2325 resource_helper.setup_helper.vnfd_helper.interfaces = []
2327 helper = prox_helpers.ProxProfileHelper(resource_helper)
2328 helper._latency_cores = []
2331 result = helper.get_latency()
2332 self.assertEqual(result, expected)
2334 helper._latency_cores = [1, 2]
2335 helper.client = mock.MagicMock()
2337 expected = helper.sut.lat_stats()
2338 result = helper.get_latency()
2339 self.assertIs(result, expected)
2341 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
2342 def test_traffic_context(self, *args):
2343 setup_helper = mock.MagicMock()
2344 setup_helper.vnfd_helper.interfaces = []
2346 helper = prox_helpers.ProxProfileHelper(setup_helper)
2347 helper._cpu_topology = {
2364 setup_helper.prox_config_data = [
2366 ('not_name', 'other data'),
2367 ('name_not', 'more data'),
2368 ('name', helper.__prox_profile_type__),
2392 client = mock.MagicMock()
2393 client.hz.return_value = 2
2395 helper.client = client
2396 helper.get_latency = mock.MagicMock(return_value=[3.3, 3.6, 3.8])
2398 helper._test_cores = [3, 4]
2400 with helper.traffic_context(64, 1):
2403 @mock.patch.object(time, 'sleep')
2404 def test_run_test(self, *args):
2405 resource_helper = mock.MagicMock()
2406 resource_helper.step_delta = 0.4
2407 resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2))
2408 resource_helper.sut.multi_port_stats.return_value = (True, [[0, 1, 1, 2, 4, 5],
2409 [1, 1, 2, 3, 4, 5]])
2411 helper = prox_helpers.ProxProfileHelper(resource_helper)
2413 helper.run_test(pkt_size=120, duration=5, value=6.5, tolerated_loss=0.0,
2414 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2415 self.assertTrue(resource_helper.sut.multi_port_stats.called)
2416 self.assertTrue(resource_helper.sut.stop_all.called)
2417 self.assertTrue(resource_helper.sut.reset_stats.called)
2419 class TestProxMplsProfileHelper(unittest.TestCase):
2421 def test_mpls_cores(self):
2422 resource_helper = mock.MagicMock()
2423 resource_helper.setup_helper.prox_config_data = [
2446 helper = prox_helpers.ProxMplsProfileHelper(resource_helper)
2447 helper._cpu_topology = {
2464 expected_tagged = [3]
2465 expected_plain = [4]
2466 self.assertIsNone(helper._cores_tuple)
2467 self.assertEqual(helper.tagged_cores, expected_tagged)
2468 self.assertEqual(helper.plain_cores, expected_plain)
2469 self.assertEqual(helper._cores_tuple, (expected_tagged, expected_plain))
2471 def test_traffic_context(self):
2472 setup_helper = mock.MagicMock()
2473 helper = prox_helpers.ProxMplsProfileHelper(setup_helper)
2475 with helper.traffic_context(120, 5.4):
2479 class TestProxBngProfileHelper(unittest.TestCase):
2481 def test_bng_cores(self):
2482 resource_helper = mock.MagicMock()
2483 resource_helper.setup_helper.prox_config_data = [
2507 ('name', 'arp_task'),
2516 helper = prox_helpers.ProxBngProfileHelper(resource_helper)
2517 helper._cpu_topology = {
2542 expected_arp = [6, 9]
2543 expected_arp_task = [0, 6]
2544 expected_combined = (expected_cpe, expected_inet, expected_arp, expected_arp_task)
2546 self.assertIsNone(helper._cores_tuple)
2547 self.assertEqual(helper.cpe_cores, expected_cpe)
2548 self.assertEqual(helper.inet_cores, expected_inet)
2549 self.assertEqual(helper.arp_cores, expected_arp)
2550 self.assertEqual(helper.arp_task_cores, expected_arp_task)
2551 self.assertEqual(helper._cores_tuple, expected_combined)
2553 @mock.patch.object(time, 'sleep')
2554 def test_run_test(self, *args):
2555 resource_helper = mock.MagicMock()
2556 resource_helper.step_delta = 0.4
2557 resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2))
2558 resource_helper.sut.multi_port_stats.return_value = (True, [[0, 1, 1, 2, 4, 5],
2559 [1, 1, 2, 3, 4, 5]])
2561 helper = prox_helpers.ProxBngProfileHelper(resource_helper)
2563 helper.run_test(pkt_size=120, duration=5, value=6.5, tolerated_loss=0.0,
2564 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2565 self.assertTrue(resource_helper.sut.multi_port_stats.called)
2566 self.assertTrue(resource_helper.sut.stop_all.called)
2567 self.assertTrue(resource_helper.sut.reset_stats.called)
2569 resource_helper.reset_mock()
2571 # negative pkt_size is the only way to make ratio > 1
2572 helper.run_test(pkt_size=-1000, duration=5, value=6.5, tolerated_loss=0.0,
2573 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2575 self.assertTrue(resource_helper.sut.multi_port_stats.called)
2576 self.assertTrue(resource_helper.sut.stop_all.called)
2577 self.assertTrue(resource_helper.sut.reset_stats.called)
2579 class TestProxVpeProfileHelper(unittest.TestCase):
2581 def test_vpe_cores(self):
2582 resource_helper = mock.MagicMock()
2583 resource_helper.setup_helper.prox_config_data = [
2606 helper = prox_helpers.ProxVpeProfileHelper(resource_helper)
2607 helper._cpu_topology = {
2626 expected_combined = (expected_cpe, expected_inet)
2628 self.assertIsNone(helper._cores_tuple)
2629 self.assertEqual(helper.cpe_cores, expected_cpe)
2630 self.assertEqual(helper.inet_cores, expected_inet)
2631 self.assertEqual(helper._cores_tuple, expected_combined)
2633 def test_vpe_ports(self):
2634 resource_helper = mock.MagicMock()
2635 resource_helper.setup_helper.prox_config_data = [
2644 ('mac', 'hardware'),
2649 ('mac', 'hardware'),
2653 helper = prox_helpers.ProxVpeProfileHelper(resource_helper)
2654 helper._port_list = {
2673 expected_combined = (expected_cpe, expected_inet)
2675 self.assertIsNone(helper._ports_tuple)
2676 self.assertEqual(helper.cpe_ports, expected_cpe)
2677 self.assertEqual(helper.inet_ports, expected_inet)
2678 self.assertEqual(helper._ports_tuple, expected_combined)
2680 @mock.patch.object(time, 'sleep')
2681 def test_run_test(self, *args):
2682 resource_helper = mock.MagicMock()
2683 resource_helper.step_delta = 0.4
2684 resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2))
2685 resource_helper.sut.multi_port_stats.return_value = (True, [[0, 1, 1, 2, 4, 5],
2686 [1, 1, 2, 3, 4, 5]])
2688 helper = prox_helpers.ProxVpeProfileHelper(resource_helper)
2690 helper.run_test(pkt_size=120, duration=5, value=6.5, tolerated_loss=0.0,
2691 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2693 # negative pkt_size is the only way to make ratio > 1
2694 helper.run_test(pkt_size=-1000, duration=5, value=6.5, tolerated_loss=0.0,
2695 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2697 class TestProxlwAFTRProfileHelper(unittest.TestCase):
2699 def test_lwaftr_cores(self):
2700 resource_helper = mock.MagicMock()
2701 resource_helper.setup_helper.prox_config_data = [
2724 helper = prox_helpers.ProxlwAFTRProfileHelper(resource_helper)
2725 helper._cpu_topology = {
2744 expected_combined = (expected_tun, expected_inet)
2746 self.assertIsNone(helper._cores_tuple)
2747 self.assertEqual(helper.tun_cores, expected_tun)
2748 self.assertEqual(helper.inet_cores, expected_inet)
2749 self.assertEqual(helper._cores_tuple, expected_combined)
2751 def test_tun_ports(self):
2752 resource_helper = mock.MagicMock()
2753 resource_helper.setup_helper.prox_config_data = [
2762 ('mac', 'hardware'),
2767 ('mac', 'hardware'),
2771 helper = prox_helpers.ProxlwAFTRProfileHelper(resource_helper)
2772 helper._port_list = {
2791 expected_combined = (expected_tun, expected_inet)
2793 self.assertIsNone(helper._ports_tuple)
2794 self.assertEqual(helper.tun_ports, expected_tun)
2795 self.assertEqual(helper.inet_ports, expected_inet)
2796 self.assertEqual(helper._ports_tuple, expected_combined)
2798 @mock.patch.object(time, 'sleep')
2799 def test_run_test(self, *args):
2800 resource_helper = mock.MagicMock()
2801 resource_helper.step_delta = 0.4
2802 resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2))
2803 resource_helper.sut.multi_port_stats.return_value = (True, [[0, 1, 2, 4, 6, 5],
2804 [1, 1, 2, 3, 4, 5]])
2806 helper = prox_helpers.ProxlwAFTRProfileHelper(resource_helper)
2808 helper.run_test(pkt_size=120, duration=5, value=6.5, tolerated_loss=0.0,
2809 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2811 # negative pkt_size is the only way to make ratio > 1
2812 helper.run_test(pkt_size=-1000, duration=5, value=6.5, tolerated_loss=0.0,
2813 line_speed=constants.NIC_GBPS_DEFAULT * constants.ONE_GIGABIT_IN_BITS)
2816 class TestProxIrqProfileHelper(unittest.TestCase):
2818 def test_run_test(self, *args):
2819 resource_helper = mock.MagicMock()
2820 helper = prox_helpers.ProxIrqProfileHelper(resource_helper)
2821 self.assertIsNone(helper._cores_tuple)
2822 self.assertIsNone(helper._ports_tuple)
2823 self.assertIsNone(helper._latency_cores)
2824 self.assertIsNone(helper._test_cores)
2825 self.assertIsNone(helper._cpu_topology)