diff options
Diffstat (limited to 'yardstick/tests/unit')
50 files changed, 12595 insertions, 656 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py index 3ccae44c7..96946cded 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_heat.py +++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py @@ -13,6 +13,7 @@ import os import mock import unittest +import collections from yardstick.benchmark.contexts import base from yardstick.benchmark.contexts import heat @@ -81,6 +82,7 @@ class HeatContextTestCase(unittest.TestCase): self.assertIsNone(self.test_context.template_file) self.assertIsNone(self.test_context.heat_parameters) self.assertIsNone(self.test_context.key_filename) + self.assertTrue(self.test_context.yardstick_gen_key_file) @mock.patch.object(yaml_loader, 'read_yaml_file') @mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup') @@ -173,6 +175,23 @@ class HeatContextTestCase(unittest.TestCase): self.assertTrue(self.test_context._flags.no_setup) self.assertTrue(self.test_context._flags.no_teardown) + def test_init_key_filename(self): + attrs = {'name': 'foo', + 'file': 'pod.yaml', + 'task_id': '1234567890', + 'server_groups': {}, + 'networks': {}, + 'servers': {}, + 'heat_template': "/root/clearwater.yaml", + 'key_filename': '/etc/yardstick/yardstick.pem'} + + with mock.patch.object(openstack_utils, 'get_shade_client'), \ + mock.patch.object(openstack_utils, 'get_shade_operator_client'): + self.test_context.init(attrs) + + self.assertIsNotNone(self.test_context.key_filename) + self.assertFalse(self.test_context.yardstick_gen_key_file) + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_resources_to_template_no_servers(self, mock_template): self.test_context._name = 'ctx' @@ -373,6 +392,25 @@ class HeatContextTestCase(unittest.TestCase): self.assertTrue(mock_manager.mock_calls.index(mock_call_gen_keys) < mock_manager.mock_calls.index(mock_call_add_resources)) + @mock.patch.object(heat, 'HeatTemplate') + @mock.patch.object(ssh.SSH, 'gen_keys') + @mock.patch.object(heat.HeatContext, '_create_new_stack') + def test_deploy_with_key_filename_provided(self, mock_create_new_stack, + mock_gen_keys, *args): + self.test_context._name = 'foo' + self.test_context._task_id = '1234567890' + self.test_context._name_task_id = '{}-{}'.format( + self.test_context._name, self.test_context._task_id[:8]) + self.test_context.template_file = '/bar/baz/some-heat-file' + self.test_context.heat_parameters = {'image': 'cirros'} + self.test_context.yardstick_gen_key_file = False + self.test_context.key_filename = '/etc/yardstick/yardstick.pem' + self.test_context.get_neutron_info = mock.MagicMock() + self.test_context.deploy() + + mock_create_new_stack.assert_called() + mock_gen_keys.assert_not_called() + def test_check_for_context(self): pass # check that the context exists @@ -705,6 +743,50 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict_found_interfaces_dict(self, *args): + """ + Use HeatContext._get_server to get a server that matches + based on a dictionary input. + """ + self.test_context._name = 'bar' + self.test_context._task_id = '1234567890' + self.test_context._name_task_id = '{}-{}'.format( + self.test_context._name, self.test_context._task_id[:8]) + self.test_context._user = 'bot' + self.test_context.stack = mock.Mock() + self.test_context.stack.outputs = { + 'private_ip': '10.0.0.1', + 'public_ip': '127.0.0.1', + 'local_mac_addr': '64:00:6a:18:0f:d6', + 'private_netmask': '255.255.255.0', + 'private_net_name': 'private_network', + 'private_net_gateway': '127.0.0.254' + } + + attr_name = { + 'name': 'foo.bar-12345678', + 'private_ip_attr': 'private_ip', + 'public_ip_attr': 'public_ip', + 'interfaces': { + 'data_net': { + 'local_ip': 'private_ip', + 'local_mac': 'local_mac_addr', + 'netmask': 'private_netmask', + 'network': 'private_net_name', + 'gateway_ip': 'private_net_gateway' + } + } + } + self.test_context.key_uuid = 'foo-42' + result = self.test_context._get_server(attr_name) + self.assertIsInstance(result['interfaces'], collections.Mapping) + for key in attr_name.get("interfaces").keys(): + self.assertEqual(result['interfaces'][key]['local_ip'], '10.0.0.1') + self.assertEqual(result['interfaces'][key]['local_mac'], '64:00:6a:18:0f:d6') + self.assertEqual(result['interfaces'][key]['netmask'], '255.255.255.0') + self.assertEqual(result['interfaces'][key]['gateway_ip'], '127.0.0.254') + # TODO: Split this into more granular tests def test__get_network(self): network1 = mock.MagicMock() diff --git a/yardstick/tests/unit/benchmark/core/test_report.py b/yardstick/tests/unit/benchmark/core/test_report.py index 4683c26b0..b498299a9 100644 --- a/yardstick/tests/unit/benchmark/core/test_report.py +++ b/yardstick/tests/unit/benchmark/core/test_report.py @@ -1,6 +1,6 @@ ############################################################################## # Copyright (c) 2017 Rajesh Kudaka. -# Copyright (c) 2018 Intel Corporation. +# Copyright (c) 2018-2019 Intel Corporation. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -219,6 +219,14 @@ class ReportTestCase(unittest.TestCase): self.rep.task_id = GOOD_TASK_ID six.assertRaisesRegex(self, KeyError, "Task ID", self.rep._get_metrics) + def test__get_timestamps(self): + + metrics = MORE_DB_METRICS + self.assertEqual( + MORE_TIMESTAMP, + self.rep._get_timestamps(metrics) + ) + @mock.patch.object(report.Report, '_get_metrics') @mock.patch.object(report.Report, '_get_fieldkeys') def test__generate_common(self, mock_keys, mock_metrics): diff --git a/yardstick/tests/unit/benchmark/core/test_task.py b/yardstick/tests/unit/benchmark/core/test_task.py index e1414c2ae..0f09b3e59 100644 --- a/yardstick/tests/unit/benchmark/core/test_task.py +++ b/yardstick/tests/unit/benchmark/core/test_task.py @@ -18,6 +18,7 @@ import six from six.moves import builtins import unittest import uuid +import collections from yardstick.benchmark.contexts import base from yardstick.benchmark.contexts import dummy @@ -30,6 +31,14 @@ from yardstick.common import utils class TaskTestCase(unittest.TestCase): + def setUp(self): + self._mock_log = mock.patch.object(task, 'LOG') + self.mock_log = self._mock_log.start() + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_log.stop() + @mock.patch.object(base, 'Context') def test_parse_nodes_with_context_same_context(self, mock_context): scenario_cfg = { @@ -487,6 +496,42 @@ key2: self.parser._change_node_names(scenario, [my_context]) self.assertIsNone(scenario['options']['server_name']) + def test__change_node_names_target_map(self): + ctx_attrs = { + 'name': 'demo', + 'task_id': '1234567890' + } + my_context = dummy.DummyContext() + self.addCleanup(self._remove_contexts) + my_context.init(ctx_attrs) + scenario = copy.deepcopy(self.scenario) + scenario['nodes'] = { + 'tg__0': { + 'name': 'tg__0.demo', + 'public_ip_attr': "1.1.1.1", + }, + 'vnf__0': { + 'name': 'vnf__0.demo', + 'public_ip_attr': "2.2.2.2", + } + } + self.parser._change_node_names(scenario, [my_context]) + for target in scenario['nodes'].values(): + self.assertIsInstance(target, collections.Mapping) + + def test__change_node_names_not_target_map(self): + ctx_attrs = { + 'name': 'demo', + 'task_id': '1234567890' + } + my_context = dummy.DummyContext() + self.addCleanup(self._remove_contexts) + my_context.init(ctx_attrs) + scenario = copy.deepcopy(self.scenario) + self.parser._change_node_names(scenario, [my_context]) + for target in scenario['nodes'].values(): + self.assertNotIsInstance(target, collections.Mapping) + def test__parse_tasks(self): task_obj = task.Task() _uuid = uuid.uuid4() diff --git a/yardstick/tests/unit/benchmark/runner/test_base.py b/yardstick/tests/unit/benchmark/runner/test_base.py index 559c991f3..07d6f1843 100644 --- a/yardstick/tests/unit/benchmark/runner/test_base.py +++ b/yardstick/tests/unit/benchmark/runner/test_base.py @@ -43,6 +43,29 @@ class ActionTestCase(ut_base.BaseUnitTestCase): runner_base._periodic_action(0, 'echo', mock.Mock()) +class ScenarioOutputTestCase(ut_base.BaseUnitTestCase): + + def setUp(self): + self.output_queue = mock.Mock() + self.scenario_output = runner_base.ScenarioOutput(self.output_queue, + sequence=1) + + @mock.patch.object(time, 'time') + def test_push(self, mock_time): + mock_time.return_value = 2 + data = {"value1": 1} + self.scenario_output.push(data) + self.output_queue.put.assert_called_once_with({'timestamp': 2, + 'sequence': 1, + 'data': data}, True, 10) + + def test_push_no_timestamp(self): + self.scenario_output["value1"] = 1 + self.scenario_output.push(None, False) + self.output_queue.put.assert_called_once_with({'sequence': 1, + 'value1': 1}, True, 10) + + class RunnerTestCase(ut_base.BaseUnitTestCase): def setUp(self): diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index addd72bd5..cf9a26a76 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -159,7 +159,7 @@ TRAFFIC_PROFILE = { class TestNetworkServiceTestCase(unittest.TestCase): def setUp(self): - self.tg__1 = { + self.tg__0 = { 'name': 'trafficgen_1.yardstick', 'ip': '10.10.10.11', 'role': 'TrafficGen', @@ -185,7 +185,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): }, } - self.vnf__1 = { + self.vnf__0 = { 'name': 'vnf.yardstick', 'ip': '10.10.10.12', 'host': '10.223.197.164', @@ -242,8 +242,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.context_cfg = { 'nodes': { - 'tg__1': self.tg__1, - 'vnf__1': self.vnf__1, + 'tg__0': self.tg__0, + 'vnf__0': self.vnf__0, }, 'networks': { GenericVNF.UPLINK: { @@ -270,7 +270,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ], 'type': 'ELAN', 'id': GenericVNF.UPLINK, - 'name': 'tg__1 to vnf__1 link 1' + 'name': 'tg__0 to vnf__0 link 1' } self.vld1 = { @@ -288,7 +288,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ], 'type': 'ELAN', 'id': GenericVNF.DOWNLINK, - 'name': 'vnf__1 to tg__1 link 2' + 'name': 'vnf__0 to tg__0 link 2' } self.topology = { @@ -300,12 +300,12 @@ class TestNetworkServiceTestCase(unittest.TestCase): { 'member-vnf-index': '1', 'VNF model': 'tg_trex_tpl.yaml', - 'vnfd-id-ref': 'tg__1', + 'vnfd-id-ref': 'tg__0', }, { 'member-vnf-index': '2', 'VNF model': 'tg_trex_tpl.yaml', - 'vnfd-id-ref': 'vnf__1', + 'vnfd-id-ref': 'vnf__0', }, ], 'vld': [self.vld0, self.vld1], @@ -343,8 +343,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): }, 'nodes': { 'tg__2': 'trafficgen_2.yardstick', - 'tg__1': 'trafficgen_1.yardstick', - 'vnf__1': 'vnf.yardstick', + 'tg__0': 'trafficgen_1.yardstick', + 'vnf__0': 'vnf.yardstick', }, } @@ -411,12 +411,12 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'flow': { 'src_ip': [ { - 'tg__1': 'xe0', + 'tg__0': 'xe0', }, ], 'dst_ip': [ { - 'tg__1': 'xe1', + 'tg__0': 'xe1', }, ], 'public_ip': ['1.1.1.1'], @@ -446,9 +446,9 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertIn('found in', exc_str) def test_load_vnf_models_invalid(self): - self.context_cfg["nodes"]['tg__1']['VNF model'] = \ + self.context_cfg["nodes"]['tg__0']['VNF model'] = \ self._get_file_abspath("tg_trex_tpl.yaml") - self.context_cfg["nodes"]['vnf__1']['VNF model'] = \ + self.context_cfg["nodes"]['vnf__0']['VNF model'] = \ self._get_file_abspath("tg_trex_tpl.yaml") vnf = mock.Mock(autospec=GenericVNF) @@ -469,13 +469,13 @@ class TestNetworkServiceTestCase(unittest.TestCase): nodes = self.context_cfg["nodes"] self.assertEqual('../../vnf_descriptors/tg_rfc2544_tpl.yaml', - nodes['tg__1']['VNF model']) + nodes['tg__0']['VNF model']) self.assertEqual('../../vnf_descriptors/vpe_vnf.yaml', - nodes['vnf__1']['VNF model']) + nodes['vnf__0']['VNF model']) def test_map_topology_to_infrastructure_insufficient_nodes(self): cfg = deepcopy(self.context_cfg) - del cfg['nodes']['vnf__1'] + del cfg['nodes']['vnf__0'] cfg_patch = mock.patch.object(self.s, 'context_cfg', cfg) with cfg_patch: @@ -489,10 +489,10 @@ class TestNetworkServiceTestCase(unittest.TestCase): cfg = deepcopy(self.s.context_cfg) # delete all, we don't know which will come first - del cfg['nodes']['vnf__1']['interfaces']['xe0']['local_mac'] - del cfg['nodes']['vnf__1']['interfaces']['xe1']['local_mac'] - del cfg['nodes']['tg__1']['interfaces']['xe0']['local_mac'] - del cfg['nodes']['tg__1']['interfaces']['xe1']['local_mac'] + del cfg['nodes']['vnf__0']['interfaces']['xe0']['local_mac'] + del cfg['nodes']['vnf__0']['interfaces']['xe1']['local_mac'] + del cfg['nodes']['tg__0']['interfaces']['xe0']['local_mac'] + del cfg['nodes']['tg__0']['interfaces']['xe1']['local_mac'] config_patch = mock.patch.object(self.s, 'context_cfg', cfg) with config_patch: @@ -507,7 +507,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh.from_node.return_value = ssh_mock # purge an important key from the data structure - for interface in self.tg__1['interfaces'].values(): + for interface in self.tg__0['interfaces'].values(): del interface['local_mac'] with self.assertRaises(exceptions.IncorrectConfig) as raised: @@ -516,7 +516,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertIn('not found', str(raised.exception)) # restore local_mac - for index, interface in enumerate(self.tg__1['interfaces'].values()): + for index, interface in enumerate(self.tg__0['interfaces'].values()): interface['local_mac'] = '00:00:00:00:00:{:2x}'.format(index) # make a connection point ref with 3 points @@ -640,6 +640,14 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertEqual({'imix': {'64B': 100}}, self.s._get_traffic_imix()) + def test__get_ip_priority(self): + with mock.patch.dict(self.scenario_cfg["options"], + {'priority': {'raw': '0x01'}}): + self.assertEqual({'raw': '0x01'}, self.s._get_ip_priority()) + + def test__get_ip_priority_exception(self): + self.assertEqual({}, self.s._get_ip_priority()) + @mock.patch.object(base.TrafficProfile, 'get') @mock.patch.object(vnfdgen, 'generate_vnfd') def test__fill_traffic_profile(self, mock_generate, mock_tprofile_get): @@ -656,6 +664,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'extra_args': {'arg1': 'value1', 'arg2': 'value2'}, 'flow': {'flow': {}}, 'imix': {'imix': {'64B': 100}}, + 'priority': {}, 'uplink': {}, 'duration': 30, 'simulated_users': { @@ -727,3 +736,138 @@ class TestNetworkServiceTestCase(unittest.TestCase): mock.Mock(return_value=True) with self.assertRaises(RuntimeError): self.s.teardown() + + +class TestNetworkServiceRFC2544TestCase(TestNetworkServiceTestCase): + + def setUp(self): + super(TestNetworkServiceRFC2544TestCase, self).setUp() + self.s = vnf_generic.NetworkServiceRFC2544(self.scenario_cfg, + self.context_cfg) + + def test_run(self): + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.name = "tgen__1" + tgen.wait_on_trafic.return_value = 'COMPLETE' + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s._fill_traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = mock.Mock( + return_value={tgen.name: verified_dict}) + result = mock.Mock() + self.s.run(result) + self.s._fill_traffic_profile.assert_called_once() + result.push.assert_called_once() + + def test_setup(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) + ssh.from_node.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + tgen.run_traffic.return_value = 'tg_id' + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s.setup() + + def test_setup_exception(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) + ssh.from_node.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.instantiate.side_effect = RuntimeError( + "error during instantiate") + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s._fill_traffic_profile = \ + mock.Mock(return_value=TRAFFIC_PROFILE) + with self.assertRaises(RuntimeError): + self.s.setup() + +class TestNetworkServiceRFC3511TestCase(TestNetworkServiceTestCase): + + def setUp(self): + super(TestNetworkServiceRFC3511TestCase, self).setUp() + self.s = vnf_generic.NetworkServiceRFC3511(self.scenario_cfg, + self.context_cfg) + + def test_run(self): + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.name = "tgen__1" + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s._fill_traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = mock.Mock() + result = mock.Mock() + self.s.run(result) + self.s._fill_traffic_profile.assert_called_once() + result.push.assert_called_once() + + def test_setup(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) + ssh.from_node.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + tgen.run_traffic.return_value = 'tg_id' + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s.setup() diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml b/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml index 1ac6c1f89..aaf84bb5e 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml +++ b/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,31 +20,31 @@ nsd:nsd-catalog: description: scenario with VPE,L3fwd and VNF constituent-vnfd: - member-vnf-index: '1' - vnfd-id-ref: tg__1 - VNF model: ../../vnf_descriptors/tg_rfc2544_tpl.yaml #tg_vpe_upstream.yaml #VPE VNF + vnfd-id-ref: tg__0 + VNF model: ../../vnf_descriptors/tg_rfc2544_tpl.yaml #tg_trex_tpl.yaml #TREX - member-vnf-index: '2' - vnfd-id-ref: vnf__1 - VNF model: ../../vnf_descriptors/vpe_vnf.yaml #tg_l3fwd.yaml #tg_trex_tpl.yaml #TREX + vnfd-id-ref: vnf__0 + VNF model: ../../vnf_descriptors/vpe_vnf.yaml #VPE VNF vld: - id: uplink - name: tg__1 to vnf__1 link 1 + name: tg__0 to vnf__0 link 1 type: ELAN vnfd-connection-point-ref: - member-vnf-index-ref: '1' vnfd-connection-point-ref: xe0 - vnfd-id-ref: tg__1 #TREX + vnfd-id-ref: tg__0 - member-vnf-index-ref: '2' vnfd-connection-point-ref: xe0 - vnfd-id-ref: vnf__1 #VNF + vnfd-id-ref: vnf__0 - id: downlink - name: vnf__1 to tg__1 link 2 + name: vnf__0 to tg__0 link 2 type: ELAN vnfd-connection-point-ref: - member-vnf-index-ref: '2' vnfd-connection-point-ref: xe1 - vnfd-id-ref: vnf__1 #L3fwd + vnfd-id-ref: vnf__0 - member-vnf-index-ref: '1' vnfd-connection-point-ref: xe1 - vnfd-id-ref: tg__1 #VPE VNF + vnfd-id-ref: tg__0 diff --git a/yardstick/tests/unit/network_services/helpers/test_cpu.py b/yardstick/tests/unit/network_services/helpers/test_cpu.py index 871fbf8c9..a1c0826fb 100644 --- a/yardstick/tests/unit/network_services/helpers/test_cpu.py +++ b/yardstick/tests/unit/network_services/helpers/test_cpu.py @@ -119,3 +119,97 @@ class TestCpuSysCores(unittest.TestCase): vnf_cfg = {'lb_config': 'SW', 'lb_count': 1, 'worker_config': '1C/1T', 'worker_threads': 1} self.assertEqual(-1, cpu_topo.validate_cpu_cfg(vnf_cfg)) + + def test_get_cpu_layout(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock( + return_value=(1, "# CPU,Core,Socket,Node,,L1d,L1i,L2,L3\n'" + "0,0,0,0,,0,0,0,0\n" + "1,1,0,0,,1,1,1,0\n", "")) + ssh_mock.put = \ + mock.Mock(return_value=(1, "", "")) + cpu_topo = CpuSysCores(ssh_mock) + subprocess.check_output = mock.Mock(return_value=0) + self.assertEqual({'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]}, + cpu_topo.get_cpu_layout()) + + def test__str2int(self): + self.assertEqual(1, CpuSysCores._str2int("1")) + + def test__str2int_error(self): + self.assertEqual(0, CpuSysCores._str2int("err")) + + def test_smt_enabled(self): + self.assertEqual(False, CpuSysCores.smt_enabled( + {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]})) + + def test_is_smt_enabled(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + self.assertEqual(False, cpu_topo.is_smt_enabled()) + + def test_cpu_list_per_node(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + self.assertEqual([0, 1], cpu_topo.cpu_list_per_node(0, False)) + + def test_cpu_list_per_node_error(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'err': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + with self.assertRaises(RuntimeError) as raised: + cpu_topo.cpu_list_per_node(0, False) + self.assertIn('Node cpuinfo not available.', str(raised.exception)) + + def test_cpu_list_per_node_smt_error(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + with self.assertRaises(RuntimeError) as raised: + cpu_topo.cpu_list_per_node(0, True) + self.assertIn('SMT is not enabled.', str(raised.exception)) + + def test_cpu_slice_of_list_per_node(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + self.assertEqual([1], + cpu_topo.cpu_slice_of_list_per_node(0, 1, 0, + False)) + + def test_cpu_slice_of_list_per_node_error(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + with self.assertRaises(RuntimeError) as raised: + cpu_topo.cpu_slice_of_list_per_node(1, 1, 1, False) + self.assertIn('cpu_cnt + skip_cnt > length(cpu list).', + str(raised.exception)) + + def test_cpu_list_per_node_str(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + cpu_topo = CpuSysCores(ssh_mock) + cpu_topo.cpuinfo = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 0, 0, 0, 1, 1, 1, 0]]} + self.assertEqual("1", + cpu_topo.cpu_list_per_node_str(0, 1, 1, ',', + False)) diff --git a/yardstick/tests/unit/network_services/helpers/vpp_helpers/__init__.py b/yardstick/tests/unit/network_services/helpers/vpp_helpers/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/yardstick/tests/unit/network_services/helpers/vpp_helpers/__init__.py diff --git a/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_multiple_loss_ratio_search.py b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_multiple_loss_ratio_search.py new file mode 100644 index 000000000..d3145546a --- /dev/null +++ b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_multiple_loss_ratio_search.py @@ -0,0 +1,2164 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +import mock + +from yardstick.network_services.helpers.vpp_helpers.multiple_loss_ratio_search import \ + MultipleLossRatioSearch +from yardstick.network_services.helpers.vpp_helpers.ndr_pdr_result import \ + NdrPdrResult +from yardstick.network_services.helpers.vpp_helpers.receive_rate_interval import \ + ReceiveRateInterval +from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \ + ReceiveRateMeasurement +from yardstick.network_services.traffic_profile.rfc2544 import PortPgIDMap + + +class TestMultipleLossRatioSearch(unittest.TestCase): + + def test___init__(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(True, algorithm.latency) + self.assertEqual(64, algorithm.pkt_size) + self.assertEqual(30, algorithm.final_trial_duration) + self.assertEqual(0.005, algorithm.final_relative_width) + self.assertEqual(2, algorithm.number_of_intermediate_phases) + self.assertEqual(1, algorithm.initial_trial_duration) + self.assertEqual(720, algorithm.timeout) + self.assertEqual(1, algorithm.doublings) + + def test_double_relative_width(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(0.00997, algorithm.double_relative_width(0.005)) + + def test_double_step_down(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(99003.0, algorithm.double_step_down(0.005, 100000)) + + def test_expand_down(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(99003.0, algorithm.expand_down(0.005, 1, 100000)) + + def test_double_step_up(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(101007.0401907013, + algorithm.double_step_up(0.005, 100000)) + + def test_expand_up(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(101007.0401907013, + algorithm.expand_up(0.005, 1, 100000)) + + def test_half_relative_width(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(0.0025031328369998773, + algorithm.half_relative_width(0.005)) + + def test_half_step_up(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + self.assertEqual(100250.94142341711, + algorithm.half_step_up(0.005, 100000)) + + def test_init_generator(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), + mock.Mock(), mock.Mock())) + self.assertEqual(ports, algorithm.ports) + self.assertEqual(port_pg_id, algorithm.port_pg_id) + + def test_collect_kpi(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + algorithm.init_generator(ports, port_pg_id, mock.Mock, mock.Mock, + mock.Mock()) + self.assertIsNone(algorithm.collect_kpi({}, 100000)) + + def test_narrow_down_ndr_and_pdr(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, 'ndrpdr') as \ + mock_ndrpdr: + ndr_measured_low = ReceiveRateMeasurement(10, 13880000, 13879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(10, 14880000, 14879927, + 0) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(10, 11880000, 11879927, + 0) + pdr_measured_high = ReceiveRateMeasurement(10, 12880000, 12879927, + 0) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock_ndrpdr.return_value = MultipleLossRatioSearch.ProgressState( + starting_result, 2, 30, 0.005, 0.0, + 4857361, 4977343) + self.assertEqual( + {'Result_NDR_LOWER': {'bandwidth_total_Gbps': 0.9327310944, + 'rate_total_pps': 1387992.7}, + 'Result_NDR_UPPER': { + 'bandwidth_total_Gbps': 0.9999310943999999, + 'rate_total_pps': 1487992.7}, + 'Result_NDR_packets_lost': {'packet_loss_ratio': 0.0, + 'packets_lost': 0.0}, + 'Result_PDR_LOWER': { + 'bandwidth_total_Gbps': 0.7983310943999999, + 'rate_total_pps': 1187992.7}, + 'Result_PDR_UPPER': {'bandwidth_total_Gbps': 0.8655310944, + 'rate_total_pps': 1287992.7}, + 'Result_PDR_packets_lost': {'packet_loss_ratio': 0.0, + 'packets_lost': 0.0}, + 'Result_stream0_NDR_LOWER': {'avg_latency': 3081.0, + 'max_latency': 3962.0, + 'min_latency': 1000.0}, + 'Result_stream0_PDR_LOWER': {'avg_latency': 3081.0, + 'max_latency': 3962.0, + 'min_latency': 1000.0}, + 'Result_stream1_NDR_LOWER': {'avg_latency': 3149.0, + 'max_latency': 3730.0, + 'min_latency': 500.0}, + 'Result_stream1_PDR_LOWER': {'avg_latency': 3149.0, + 'max_latency': 3730.0, + 'min_latency': 500.0}}, + algorithm.narrow_down_ndr_and_pdr(12880000, 15880000, 0.0)) + + def test__measure_and_update_state(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + starting_interval = ReceiveRateInterval(measured_low, measured_high) + starting_result = NdrPdrResult(starting_interval, starting_interval) + previous_state = MultipleLossRatioSearch.ProgressState(starting_result, + 2, 30, 0.005, + 0.0, 4857361, + 4977343) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure: + mock_measure.return_value = ReceiveRateMeasurement(1, + 4626121.09635, + 4626100, 13074) + state = algorithm._measure_and_update_state(previous_state, + 4626121.09635) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(1, state.result.ndr_interval.measured_low.duration) + self.assertEqual(4626121.09635, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(4626100, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(13074, + state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(4613026, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(4626100, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(13074.0, + state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(4613026.0, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.00283, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(1, state.result.ndr_interval.measured_high.duration) + self.assertEqual(4857361, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(4857339, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(84965, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(4772374, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(4857339, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(84965.0, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(4772374.0, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.01749, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(1, state.result.pdr_interval.measured_low.duration) + self.assertEqual(4626121.09635, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(4626100, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(13074, + state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(4613026, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(4626100, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(13074.0, + state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(4613026.0, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.00283, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(1, state.result.pdr_interval.measured_high.duration) + self.assertEqual(4857361, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(4857339, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(84965, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(4772374, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(4857339, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(84965.0, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(4772374.0, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.01749, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(2, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.005, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(4857361, state.minimum_transmit_rate) + self.assertEqual(4977343, state.maximum_transmit_rate) + + def test_new_interval(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 3972540.4108, 21758482, 0) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.0) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(3972540.4108, result.measured_low.target_tr) + self.assertEqual(21758482, result.measured_low.transmit_count) + self.assertEqual(0, result.measured_low.loss_count) + self.assertEqual(21758482, result.measured_low.receive_count) + self.assertEqual(21758482, result.measured_low.transmit_rate) + self.assertEqual(0.0, result.measured_low.loss_rate) + self.assertEqual(21758482.0, result.measured_low.receive_rate) + self.assertEqual(0.0, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4857361, result.measured_high.target_tr) + self.assertEqual(4857339, result.measured_high.transmit_count) + self.assertEqual(84965, result.measured_high.loss_count) + self.assertEqual(4772374, result.measured_high.receive_count) + self.assertEqual(4857339, result.measured_high.transmit_rate) + self.assertEqual(84965.0, result.measured_high.loss_rate) + self.assertEqual(4772374.0, result.measured_high.receive_rate) + self.assertEqual(0.01749, result.measured_high.loss_fraction) + + def test_new_interval_zero(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 4977343, 21758482, 0) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.0) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4857361.0, result.measured_low.target_tr) + self.assertEqual(4857339, result.measured_low.transmit_count) + self.assertEqual(84965, result.measured_low.loss_count) + self.assertEqual(4772374, result.measured_low.receive_count) + self.assertEqual(4857339.0, result.measured_low.transmit_rate) + self.assertEqual(84965.0, result.measured_low.loss_rate) + self.assertEqual(4772374.0, result.measured_low.receive_rate) + self.assertEqual(0.01749, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4977343.0, result.measured_high.target_tr) + self.assertEqual(21758482, result.measured_high.transmit_count) + self.assertEqual(0, result.measured_high.loss_count) + self.assertEqual(21758482, result.measured_high.receive_count) + self.assertEqual(21758482.0, result.measured_high.transmit_rate) + self.assertEqual(0.0, result.measured_high.loss_rate) + self.assertEqual(21758482.0, result.measured_high.receive_rate) + self.assertEqual(0.0, result.measured_high.loss_fraction) + + def test_new_interval_one(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 5000000, 2175848, 0) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.0) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4857361.0, result.measured_low.target_tr) + self.assertEqual(4857339, result.measured_low.transmit_count) + self.assertEqual(84965, result.measured_low.loss_count) + self.assertEqual(4772374, result.measured_low.receive_count) + self.assertEqual(4857339.0, result.measured_low.transmit_rate) + self.assertEqual(84965.0, result.measured_low.loss_rate) + self.assertEqual(4772374.0, result.measured_low.receive_rate) + self.assertEqual(0.01749, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4977343.0, result.measured_high.target_tr) + self.assertEqual(4977320, result.measured_high.transmit_count) + self.assertEqual(119959, result.measured_high.loss_count) + self.assertEqual(4857361, result.measured_high.receive_count) + self.assertEqual(4977320.0, result.measured_high.transmit_rate) + self.assertEqual(119959.0, result.measured_high.loss_rate) + self.assertEqual(4857361.0, result.measured_high.receive_rate) + self.assertEqual(0.0241, result.measured_high.loss_fraction) + + def test_new_interval_valid_1st(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 4000000, 2175848, 0) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.5) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4857361.0, result.measured_low.target_tr) + self.assertEqual(4857339, result.measured_low.transmit_count) + self.assertEqual(84965, result.measured_low.loss_count) + self.assertEqual(4772374, result.measured_low.receive_count) + self.assertEqual(4857339.0, result.measured_low.transmit_rate) + self.assertEqual(84965.0, result.measured_low.loss_rate) + self.assertEqual(4772374.0, result.measured_low.receive_rate) + self.assertEqual(0.01749, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4977343.0, result.measured_high.target_tr) + self.assertEqual(4977320, result.measured_high.transmit_count) + self.assertEqual(119959, result.measured_high.loss_count) + self.assertEqual(4857361, result.measured_high.receive_count) + self.assertEqual(4977320.0, result.measured_high.transmit_rate) + self.assertEqual(119959.0, result.measured_high.loss_rate) + self.assertEqual(4857361.0, result.measured_high.receive_rate) + self.assertEqual(0.0241, result.measured_high.loss_fraction) + + def test_new_interval_valid_1st_loss(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 4000000, 2175848, 1000000) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.02) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4000000.0, result.measured_low.target_tr) + self.assertEqual(2175848, result.measured_low.transmit_count) + self.assertEqual(1000000, result.measured_low.loss_count) + self.assertEqual(1175848, result.measured_low.receive_count) + self.assertEqual(2175848.0, result.measured_low.transmit_rate) + self.assertEqual(1000000.0, result.measured_low.loss_rate) + self.assertEqual(1175848.0, result.measured_low.receive_rate) + self.assertEqual(0.45959, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4977343.0, result.measured_high.target_tr) + self.assertEqual(4977320, result.measured_high.transmit_count) + self.assertEqual(119959, result.measured_high.loss_count) + self.assertEqual(4857361, result.measured_high.receive_count) + self.assertEqual(4977320.0, result.measured_high.transmit_rate) + self.assertEqual(119959.0, result.measured_high.loss_rate) + self.assertEqual(4857361.0, result.measured_high.receive_rate) + self.assertEqual(0.0241, result.measured_high.loss_fraction) + + def test_new_interval_valid_2nd(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 5000000, 2175848, 0) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.5) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4977343.0, result.measured_low.target_tr) + self.assertEqual(4977320, result.measured_low.transmit_count) + self.assertEqual(119959, result.measured_low.loss_count) + self.assertEqual(4857361, result.measured_low.receive_count) + self.assertEqual(4977320.0, result.measured_low.transmit_rate) + self.assertEqual(119959.0, result.measured_low.loss_rate) + self.assertEqual(4857361.0, result.measured_low.receive_rate) + self.assertEqual(0.0241, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(5000000.0, result.measured_high.target_tr) + self.assertEqual(2175848, result.measured_high.transmit_count) + self.assertEqual(0, result.measured_high.loss_count) + self.assertEqual(2175848, result.measured_high.receive_count) + self.assertEqual(2175848.0, result.measured_high.transmit_rate) + self.assertEqual(0.0, result.measured_high.loss_rate) + self.assertEqual(2175848.0, result.measured_high.receive_rate) + self.assertEqual(0.0, result.measured_high.loss_fraction) + + def test_new_interval_valid_3rd(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 4867361, 2175848, 0) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.5) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4867361.0, result.measured_low.target_tr) + self.assertEqual(2175848, result.measured_low.transmit_count) + self.assertEqual(0, result.measured_low.loss_count) + self.assertEqual(2175848, result.measured_low.receive_count) + self.assertEqual(2175848.0, result.measured_low.transmit_rate) + self.assertEqual(0.0, result.measured_low.loss_rate) + self.assertEqual(2175848.0, result.measured_low.receive_rate) + self.assertEqual(0.0, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4977343.0, result.measured_high.target_tr) + self.assertEqual(4977320, result.measured_high.transmit_count) + self.assertEqual(119959, result.measured_high.loss_count) + self.assertEqual(4857361, result.measured_high.receive_count) + self.assertEqual(4977320.0, result.measured_high.transmit_rate) + self.assertEqual(119959.0, result.measured_high.loss_rate) + self.assertEqual(4857361.0, result.measured_high.receive_rate) + self.assertEqual(0.0241, result.measured_high.loss_fraction) + + def test_new_interval_valid_3rd_loss(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + measured = ReceiveRateMeasurement(1, 4867361, 2175848, 1000000) + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + result = algorithm._new_interval(receive_rate_interval, measured, 0.2) + self.assertIsInstance(result, ReceiveRateInterval) + self.assertEqual(1, result.measured_low.duration) + self.assertEqual(4857361.0, result.measured_low.target_tr) + self.assertEqual(4857339, result.measured_low.transmit_count) + self.assertEqual(84965, result.measured_low.loss_count) + self.assertEqual(4772374, result.measured_low.receive_count) + self.assertEqual(4857339.0, result.measured_low.transmit_rate) + self.assertEqual(84965.0, result.measured_low.loss_rate) + self.assertEqual(4772374.0, result.measured_low.receive_rate) + self.assertEqual(0.01749, result.measured_low.loss_fraction) + self.assertEqual(1, result.measured_high.duration) + self.assertEqual(4867361.0, result.measured_high.target_tr) + self.assertEqual(2175848, result.measured_high.transmit_count) + self.assertEqual(1000000, result.measured_high.loss_count) + self.assertEqual(1175848, result.measured_high.receive_count) + self.assertEqual(2175848.0, result.measured_high.transmit_rate) + self.assertEqual(1000000.0, result.measured_high.loss_rate) + self.assertEqual(1175848.0, result.measured_high.receive_rate) + self.assertEqual(0.45959, result.measured_high.loss_fraction) + + def test_ndrpdr(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure: + measured_low = ReceiveRateMeasurement(30, 14880000, 14879927, 0) + measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, 0) + measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + starting_interval = ReceiveRateInterval(measured_low, + measured_high) + starting_result = NdrPdrResult(starting_interval, + starting_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.005, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_ndr_rel_width(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + measured_low = ReceiveRateMeasurement(30, 880000, 879927, 0) + measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, 0) + measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + starting_interval = ReceiveRateInterval(measured_low, + measured_high) + ending_interval = ReceiveRateInterval(measured_high, measured_high) + starting_result = NdrPdrResult(starting_interval, + starting_interval) + ending_result = NdrPdrResult(ending_interval, ending_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.005, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.005, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_pdr_rel_width(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 14880000, 14879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 0) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 880000, 879927, 0) + pdr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 0) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(ndr_interval, ndr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.005, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.005, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_ndr_lo_duration(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + measured_low = ReceiveRateMeasurement(30, 14880000, 14879927, 0) + measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, 100) + measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + starting_interval = ReceiveRateInterval(measured_low, + measured_high) + starting_result = NdrPdrResult(starting_interval, + starting_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(starting_result, -1, 30, + 0.005, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 50, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879827, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495994.23333, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(1e-05, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879827, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495994.23333, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(1e-05, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.005, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_ndr_hi_duration(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + measured_low = ReceiveRateMeasurement(60, 14880000, 14879927, 0) + measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, 100) + measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + starting_interval = ReceiveRateInterval(measured_low, + measured_high) + starting_result = NdrPdrResult(starting_interval, + starting_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(starting_result, -1, 30, + 0.005, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 50, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(60.0, state.result.ndr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(247998.78333, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(247998.78333, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879827, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495994.23333, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(1e-05, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(60.0, state.result.pdr_interval.measured_low.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(247998.78333, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(247998.78333, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879827, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495994.23333, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(1e-05, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.005, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_error(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=0) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure: + measured_low = ReceiveRateMeasurement(30, 14880000, 14879927, 0) + measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, 0) + measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + starting_interval = ReceiveRateInterval(measured_low, + measured_high) + starting_result = NdrPdrResult(starting_interval, + starting_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 14880000, + 14880000) + with self.assertRaises(RuntimeError) as raised: + algorithm.ndrpdr(previous_state) + + self.assertIn('Optimized search takes too long.', + str(raised.exception)) + + def test_ndrpdr_update_state_ndr_hi(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + pdr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 0) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(pdr_interval, pdr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_update_state_ndr_hi_duration(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + pdr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 0) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(pdr_interval, pdr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 50, 0.005, 0.0, 4880000, + 10880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(0, state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_update_state_ndr_lo(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 100000) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 100000) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 100000) + pdr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 100000) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(pdr_interval, pdr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 100000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(12779927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(425997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.00776, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14779927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(492664.23333, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.00672, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(12779927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(425997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.00776, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14779927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(492664.23333, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.00672, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_update_state_pdr_lo(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 100000) + pdr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 100000) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(pdr_interval, pdr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 100000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(12779927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(425997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.00776, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14779927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(492664.23333, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.00672, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(12779927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(425997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.00776, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14779927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(492664.23333, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.00672, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_update_state_pdr_lo_duration(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 100000) + pdr_measured_high = ReceiveRateMeasurement(30, 14880000, 14879927, + 100000) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(pdr_interval, pdr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 50, 0.005, 0.0, 14880000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(12779927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(425997.56667, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.00776, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(14880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(14779927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(492664.23333, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.00672, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(12880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(12779927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(425997.56667, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.00776, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(14880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(14879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(14779927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(495997.56667, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(492664.23333, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.00672, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_update_state_pdr_hi(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 100000) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + pdr_measured_high = ReceiveRateMeasurement(30, 13880000, 14879927, + 0) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(ndr_interval, ndr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 30, 0.005, 0.0, 100000, + 14880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(10880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(10879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, + state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(10879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(362664.23333, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(362664.23333, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(12779927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(425997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.00776, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(10880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(10879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, + state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(10879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(362664.23333, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(362664.23333, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(12880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(12779927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(425997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.00776, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_ndrpdr_update_state_pdr_hi_duration(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock(), mock.Mock, + mock.Mock())) + with mock.patch.object(algorithm, 'measure') as \ + mock_measure, \ + mock.patch.object(algorithm, '_measure_and_update_state') as \ + mock__measure_and_update_state: + ndr_measured_low = ReceiveRateMeasurement(30, 10880000, 10879927, + 0) + ndr_measured_high = ReceiveRateMeasurement(30, 12880000, 12879927, + 100000) + ndr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_low = ReceiveRateMeasurement(30, 12880000, 12879927, + 0) + pdr_measured_high = ReceiveRateMeasurement(30, 13880000, 14879927, + 0) + pdr_measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + pdr_measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + ndr_interval = ReceiveRateInterval(ndr_measured_low, + ndr_measured_high) + pdr_interval = ReceiveRateInterval(pdr_measured_low, + pdr_measured_high) + starting_result = NdrPdrResult(ndr_interval, pdr_interval) + ending_result = NdrPdrResult(ndr_interval, ndr_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock__measure_and_update_state.return_value = \ + MultipleLossRatioSearch.ProgressState(ending_result, -1, 30, + 0.2, 0.0, 14880000, + 14880000) + previous_state = MultipleLossRatioSearch.ProgressState( + starting_result, -1, 50, 0.005, 0.0, 100000, + 10880000) + state = algorithm.ndrpdr(previous_state) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertIsInstance(state, MultipleLossRatioSearch.ProgressState) + self.assertEqual(30, state.result.ndr_interval.measured_low.duration) + self.assertEqual(10880000.0, + state.result.ndr_interval.measured_low.target_tr) + self.assertEqual(10879927, + state.result.ndr_interval.measured_low.transmit_count) + self.assertEqual(0, + state.result.ndr_interval.measured_low.loss_count) + self.assertEqual(10879927, + state.result.ndr_interval.measured_low.receive_count) + self.assertEqual(362664.23333, + state.result.ndr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_rate) + self.assertEqual(362664.23333, + state.result.ndr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.ndr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.ndr_interval.measured_high.duration) + self.assertEqual(12880000.0, + state.result.ndr_interval.measured_high.target_tr) + self.assertEqual(12879927, + state.result.ndr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.ndr_interval.measured_high.loss_count) + self.assertEqual(12779927, + state.result.ndr_interval.measured_high.receive_count) + self.assertEqual(429330.9, + state.result.ndr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.ndr_interval.measured_high.loss_rate) + self.assertEqual(425997.56667, + state.result.ndr_interval.measured_high.receive_rate) + self.assertEqual(0.00776, + state.result.ndr_interval.measured_high.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_low.duration) + self.assertEqual(10880000.0, + state.result.pdr_interval.measured_low.target_tr) + self.assertEqual(10879927, + state.result.pdr_interval.measured_low.transmit_count) + self.assertEqual(0, + state.result.pdr_interval.measured_low.loss_count) + self.assertEqual(10879927, + state.result.pdr_interval.measured_low.receive_count) + self.assertEqual(362664.23333, + state.result.pdr_interval.measured_low.transmit_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_rate) + self.assertEqual(362664.23333, + state.result.pdr_interval.measured_low.receive_rate) + self.assertEqual(0.0, + state.result.pdr_interval.measured_low.loss_fraction) + self.assertEqual(30, state.result.pdr_interval.measured_high.duration) + self.assertEqual(12880000, + state.result.pdr_interval.measured_high.target_tr) + self.assertEqual(12879927, + state.result.pdr_interval.measured_high.transmit_count) + self.assertEqual(100000, + state.result.pdr_interval.measured_high.loss_count) + self.assertEqual(12779927, + state.result.pdr_interval.measured_high.receive_count) + self.assertEqual(429330.9, + state.result.pdr_interval.measured_high.transmit_rate) + self.assertEqual(3333.33333, + state.result.pdr_interval.measured_high.loss_rate) + self.assertEqual(425997.56667, + state.result.pdr_interval.measured_high.receive_rate) + self.assertEqual(0.00776, + state.result.pdr_interval.measured_high.loss_fraction) + self.assertEqual(-1, state.phases) + self.assertEqual(30, state.duration) + self.assertEqual(0.2, state.width_goal) + self.assertEqual(0.0, state.packet_loss_ratio) + self.assertEqual(14880000, state.minimum_transmit_rate) + self.assertEqual(14880000, state.maximum_transmit_rate) + + def test_measure(self): + measurer = mock.MagicMock() + measurer.sent = 102563094 + measurer.loss = 30502 + algorithm = MultipleLossRatioSearch(measurer=measurer, latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.MagicMock(), + mock.Mock, mock.Mock())) + measurement = algorithm.measure(30, 3418770.3425, True) + self.assertIsInstance(measurement, ReceiveRateMeasurement) + self.assertEqual(30, measurement.duration) + self.assertEqual(3418770.3425, measurement.target_tr) + self.assertEqual(102563094, measurement.transmit_count) + self.assertEqual(30502, measurement.loss_count) + self.assertEqual(102532592, measurement.receive_count) + self.assertEqual(3418769.8, measurement.transmit_rate) + self.assertEqual(1016.73333, measurement.loss_rate) + self.assertEqual(3417753.06667, measurement.receive_rate) + self.assertEqual(0.0003, measurement.loss_fraction) + + def test_perform_additional_measurements_based_on_ndrpdr_result(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + ports = [0, 1] + port_pg_id = PortPgIDMap() + port_pg_id.add_port(0) + port_pg_id.add_port(1) + self.assertIsNone( + algorithm.init_generator(ports, port_pg_id, mock.Mock, mock.Mock, + mock.Mock())) + result = mock.MagicMock() + result.ndr_interval.measured_low.target_tr.return_result = 100000 + self.assertIsNone( + algorithm.perform_additional_measurements_based_on_ndrpdr_result( + result)) + + def test_display_single_bound(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + result_samples = {} + self.assertIsNone( + algorithm.display_single_bound(result_samples, 'NDR_LOWER', + 4857361, 64, + ['20/849/1069', '40/69/183'])) + self.assertEqual( + {'Result_NDR_LOWER': {'bandwidth_total_Gbps': 3.264146592, + 'rate_total_pps': 4857361.0}, + 'Result_stream0_NDR_LOWER': {'avg_latency': 849.0, + 'max_latency': 1069.0, + 'min_latency': 20.0}, + 'Result_stream1_NDR_LOWER': {'avg_latency': 69.0, + 'max_latency': 183.0, + 'min_latency': 40.0}}, + result_samples) + + def test_check_ndrpdr_interval_validity(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + result_samples = {} + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 0) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 0) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertEqual('Minimal rate loss fraction 0.0 reach target 0.0', + algorithm.check_ndrpdr_interval_validity( + result_samples, 'NDR_LOWER', + receive_rate_interval)) + self.assertEqual( + {'Result_NDR_LOWER_packets_lost': {'packet_loss_ratio': 0.0, + 'packets_lost': 0.0}}, + result_samples) + + def test_check_ndrpdr_interval_validity_fail(self): + algorithm = MultipleLossRatioSearch(measurer=mock.Mock(), latency=True, + pkt_size=64, + final_trial_duration=30, + final_relative_width=0.005, + number_of_intermediate_phases=2, + initial_trial_duration=1, + timeout=720) + result_samples = {} + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertEqual( + 'Minimal rate loss fraction 0.01749 does not reach target 0.005\n84965 packets lost.', + algorithm.check_ndrpdr_interval_validity(result_samples, + 'NDR_LOWER', + receive_rate_interval, + 0.005)) + self.assertEqual({'Result_NDR_LOWER_packets_lost': { + 'packet_loss_ratio': 0.01749, + 'packets_lost': 84965.0}}, result_samples) diff --git a/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_ndr_pdr_result.py b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_ndr_pdr_result.py new file mode 100644 index 000000000..ea9c39a03 --- /dev/null +++ b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_ndr_pdr_result.py @@ -0,0 +1,91 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +import mock + +from yardstick.network_services.helpers.vpp_helpers.ndr_pdr_result import \ + NdrPdrResult +from yardstick.network_services.helpers.vpp_helpers.receive_rate_interval import \ + ReceiveRateInterval +from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \ + ReceiveRateMeasurement + + +class TestNdrPdrResult(unittest.TestCase): + + def test___init__(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + starting_interval = ReceiveRateInterval(measured_low, measured_high) + ndrpdr_result = NdrPdrResult(starting_interval, starting_interval) + self.assertIsInstance(ndrpdr_result.ndr_interval, ReceiveRateInterval) + self.assertIsInstance(ndrpdr_result.pdr_interval, ReceiveRateInterval) + + def test___init__ndr_error(self): + starting_interval = mock.MagicMock() + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + end_interval = ReceiveRateInterval(measured_low, measured_high) + with self.assertRaises(TypeError) as raised: + NdrPdrResult(starting_interval, end_interval) + self.assertIn('ndr_interval, is not a ReceiveRateInterval: ', + str(raised.exception)) + + def test___init__pdr_error(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + starting_interval = ReceiveRateInterval(measured_low, measured_high) + end_interval = mock.MagicMock() + with self.assertRaises(TypeError) as raised: + NdrPdrResult(starting_interval, end_interval) + self.assertIn('pdr_interval, is not a ReceiveRateInterval: ', + str(raised.exception)) + + def test_width_in_goals(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + starting_interval = ReceiveRateInterval(measured_low, measured_high) + ndrpdr_result = NdrPdrResult(starting_interval, starting_interval) + self.assertEqual('ndr 4.86887; pdr 4.86887', + ndrpdr_result.width_in_goals(0.005)) + + def test___str__(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + starting_interval = ReceiveRateInterval(measured_low, measured_high) + ndrpdr_result = NdrPdrResult(starting_interval, starting_interval) + self.assertEqual( + 'NDR=[d=1.0,Tr=4857361.0,Df=0.01749;d=1.0,Tr=4977343.0,Df=0.0241);' + 'PDR=[d=1.0,Tr=4857361.0,Df=0.01749;d=1.0,Tr=4977343.0,Df=0.0241)', + ndrpdr_result.__str__()) + + def test___repr__(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + starting_interval = ReceiveRateInterval(measured_low, measured_high) + ndrpdr_result = NdrPdrResult(starting_interval, starting_interval) + self.assertEqual( + 'NdrPdrResult(ndr_interval=ReceiveRateInterval(measured_low=' \ + 'ReceiveRateMeasurement(duration=1.0,target_tr=4857361.0,' \ + 'transmit_count=4857339,loss_count=84965),measured_high=' \ + 'ReceiveRateMeasurement(duration=1.0,target_tr=4977343.0,' \ + 'transmit_count=4977320,loss_count=119959)),pdr_interval=' \ + 'ReceiveRateInterval(measured_low=ReceiveRateMeasurement' \ + '(duration=1.0,target_tr=4857361.0,transmit_count=4857339,' \ + 'loss_count=84965),measured_high=ReceiveRateMeasurement' \ + '(duration=1.0,target_tr=4977343.0,transmit_count=4977320,' \ + 'loss_count=119959)))', + ndrpdr_result.__repr__()) diff --git a/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_receive_rate_interval.py b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_receive_rate_interval.py new file mode 100644 index 000000000..bbf241613 --- /dev/null +++ b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_receive_rate_interval.py @@ -0,0 +1,100 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +import mock + +from yardstick.network_services.helpers.vpp_helpers.receive_rate_interval import \ + ReceiveRateInterval +from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \ + ReceiveRateMeasurement + + +class TestReceiveRateInterval(unittest.TestCase): + + def test__init__(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertIsInstance(receive_rate_interval.measured_low, + ReceiveRateMeasurement) + self.assertIsInstance(receive_rate_interval.measured_high, + ReceiveRateMeasurement) + + def test__init__measured_low_error(self): + measured_low = mock.MagicMock() + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + with self.assertRaises(TypeError) as raised: + ReceiveRateInterval(measured_low, measured_high) + self.assertIn('measured_low is not a ReceiveRateMeasurement: ', + str(raised.exception)) + + def test__init__measured_high_error(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = mock.MagicMock() + with self.assertRaises(TypeError) as raised: + ReceiveRateInterval(measured_low, measured_high) + self.assertIn('measured_high is not a ReceiveRateMeasurement: ', + str(raised.exception)) + + def test_sort(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertIsNone(receive_rate_interval.sort()) + self.assertEqual(119982.0, receive_rate_interval.abs_tr_width) + self.assertEqual(0.02411, + receive_rate_interval.rel_tr_width) + + def test_sort_swap(self): + measured_low = ReceiveRateMeasurement(1, 14857361, 14857339, 184965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertIsNone(receive_rate_interval.sort()) + self.assertEqual(9880018.0, receive_rate_interval.abs_tr_width) + self.assertEqual(0.66499, + receive_rate_interval.rel_tr_width) + + def test_width_in_goals(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertEqual(4.86887, + receive_rate_interval.width_in_goals(0.005)) + + def test___str__(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertEqual( + '[d=1.0,Tr=4857361.0,Df=0.01749;d=1.0,Tr=4977343.0,Df=0.0241)', + receive_rate_interval.__str__()) + + def test___repr__(self): + measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959) + receive_rate_interval = ReceiveRateInterval(measured_low, + measured_high) + self.assertEqual('ReceiveRateInterval(measured_low=' \ + 'ReceiveRateMeasurement(duration=1.0,target_tr=4857361.0,' \ + 'transmit_count=4857339,loss_count=84965),measured_high=' \ + 'ReceiveRateMeasurement(duration=1.0,target_tr=4977343.0,' \ + 'transmit_count=4977320,loss_count=119959))', + receive_rate_interval.__repr__()) diff --git a/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_receive_rate_measurement.py b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_receive_rate_measurement.py new file mode 100644 index 000000000..d4e2d7920 --- /dev/null +++ b/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_receive_rate_measurement.py @@ -0,0 +1,44 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \ + ReceiveRateMeasurement + + +class TestReceiveRateMeasurement(unittest.TestCase): + + def test__init__(self): + measured = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + self.assertEqual(1, measured.duration) + self.assertEqual(4857361, measured.target_tr) + self.assertEqual(4857339, measured.transmit_count) + self.assertEqual(84965, measured.loss_count) + self.assertEqual(4772374, measured.receive_count) + self.assertEqual(4857339, measured.transmit_rate) + self.assertEqual(84965.0, measured.loss_rate) + self.assertEqual(4772374.0, measured.receive_rate) + self.assertEqual(0.01749, measured.loss_fraction) + + def test___str__(self): + measured = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + self.assertEqual('d=1.0,Tr=4857361.0,Df=0.01749', + measured.__str__()) + + def test___repr__(self): + measured = ReceiveRateMeasurement(1, 4857361, 4857339, 84965) + self.assertEqual('ReceiveRateMeasurement(duration=1.0,' \ + 'target_tr=4857361.0,transmit_count=4857339,loss_count=84965)', + measured.__repr__()) diff --git a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py index 110224742..a20592dc7 100644 --- a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py +++ b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,54 @@ import mock import IxNetwork import unittest +import re from copy import deepcopy +from collections import OrderedDict from yardstick.common import exceptions from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api +from yardstick.network_services.traffic_profile import ixia_rfc2544 UPLINK = 'uplink' DOWNLINK = 'downlink' +TRAFFIC_PROFILE = { + 'uplink_0': { + 'ipv4': { + 'outer_l2': { + 'framesize': { + '128B': '0', + '1518B': '0', + '64B': '0', + '373b': '0', + '256B': '0', + '1400B': '0', + '570B': '0'}}, + 'id': 1}}, + 'description': 'Traffic profile to run RFC2544 latency', + 'name': 'rfc2544', + 'schema': 'isb:traffic_profile:0.1', + 'traffic_profile': { + 'injection_time': None, + 'enable_latency': True, + 'frame_rate': '100%', + 'traffic_type': 'IXIARFC2544Profile'}, + 'downlink_0': { + 'ipv4': { + 'outer_l2': { + 'framesize': { + '128B': '0', + '1518B': '0', + '64B': '0', + '373b': '0', + '256B': '0', + '1400B': '0', + '570B': '0'}}, + 'id': 2}}} + + TRAFFIC_PARAMETERS = { UPLINK: { 'id': 1, @@ -504,12 +542,17 @@ class TestIxNextgen(unittest.TestCase): 'my_root/traffic/protocolTemplate:"my_protocol"') def test__setup_config_elements(self): + # the config parsed from some_file + yaml_data = {'traffic_profile': {} + } + traffic_profile = ixia_rfc2544.IXIARFC2544Profile(yaml_data) + traffic_profile.params = TRAFFIC_PROFILE self.ixnet_gen.ixnet.getList.side_effect = [['traffic_item'], ['cfg_element']] with mock.patch.object(self.ixnet_gen, '_append_procotol_to_stack') as \ mock_append_proto: - self.ixnet_gen._setup_config_elements() - mock_append_proto.assert_has_calls([ + self.ixnet_gen._setup_config_elements(traffic_profile=traffic_profile) + mock_append_proto.assert_has_calls([ mock.call(ixnet_api.PROTO_UDP, 'cfg_element/stack:"ethernet-1"'), mock.call(ixnet_api.PROTO_IPV4, 'cfg_element/stack:"ethernet-1"')]) self.ixnet_gen.ixnet.setAttribute.assert_has_calls([ @@ -524,11 +567,15 @@ class TestIxNextgen(unittest.TestCase): def test_create_traffic_model(self, mock__setup_config_elements, mock__create_flow_groups, mock__create_traffic_item): + # the config parsed from some_file + yaml_data = {'traffic_profile': {}} + traffic_profile = ixia_rfc2544.IXIARFC2544Profile(yaml_data) uplink_ports = ['port1', 'port3'] downlink_ports = ['port2', 'port4'] uplink_endpoints = ['port1/protocols', 'port3/protocols'] downlink_endpoints = ['port2/protocols', 'port4/protocols'] - self.ixnet_gen.create_traffic_model(uplink_ports, downlink_ports) + self.ixnet_gen.create_traffic_model(uplink_ports, downlink_ports, + traffic_profile=traffic_profile) mock__create_traffic_item.assert_called_once_with('raw') mock__create_flow_groups.assert_called_once_with(uplink_endpoints, downlink_endpoints) @@ -542,12 +589,65 @@ class TestIxNextgen(unittest.TestCase): mock__create_traffic_item): uplink_topologies = ['up1', 'up3'] downlink_topologies = ['down2', 'down4'] + traffic_profile = 'fake_profile' self.ixnet_gen.create_ipv4_traffic_model(uplink_topologies, - downlink_topologies) + downlink_topologies, + traffic_profile) mock__create_traffic_item.assert_called_once_with('ipv4') mock__create_flow_groups.assert_called_once_with(uplink_topologies, downlink_topologies) - mock__setup_config_elements.assert_called_once_with(False) + mock__setup_config_elements.assert_called_once_with( + traffic_profile='fake_profile', add_default_proto=False) + + def test_flows_settings(self): + cfg = {'uplink_0': { + 'ipv4': { + 'outer_l2': { + 'framesize': { + '128B': '0', + '1518B': '0', + '64B': '0', + '373b': '0', + '256B': '0', + '1400B': '0', + '570B': '0'}}, + 'id': 1}}} + + expected = [ + {'ipv4': { + 'id': 1, + 'outer_l2': { + 'framesize': { + '1518B': '0', + '1400B': '0', + '128B': '0', + '64B': '0', + '256B': '0', + '373b': '0', + '570B': '0'}}}}] + + self.assertEqual(expected, self.ixnet_gen._flows_settings(cfg=cfg)) + + def test_is_qinq(self): + flow_data = {'ipv4': { + 'outer_l2': {}, + 'id': 1}} + self.assertEqual(False, self.ixnet_gen.is_qinq(flow_data=flow_data)) + + flow_data = {'ipv4': { + 'outer_l2': { + 'QinQ': { + 'C-VLAN': { + 'priority': 0, + 'cfi': 0, + 'id': 512}, + 'S-VLAN': { + 'priority': 0, + 'cfi': 0, + 'id': 128}}, + }, + 'id': 1}} + self.assertEqual(True, self.ixnet_gen.is_qinq(flow_data=flow_data)) def test__update_frame_mac(self): with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item') as \ @@ -633,9 +733,9 @@ class TestIxNextgen(unittest.TestCase): mock.call(self.ixnet_gen.FLOW_STATISTICS, self.ixnet_gen.LATENCY_NAME_MAP)]) - def test__set_flow_tracking(self): + def test_set_flow_tracking(self): self.ixnet_gen._ixnet.getList.return_value = ['traffic_item'] - self.ixnet_gen._set_flow_tracking(track_by=['vlanVlanId0']) + self.ixnet_gen.set_flow_tracking(track_by=['vlanVlanId0']) self.ixnet_gen.ixnet.setAttribute.assert_called_once_with( 'traffic_item/tracking', '-trackBy', ['vlanVlanId0']) self.assertEqual(self.ixnet.commit.call_count, 1) @@ -653,17 +753,77 @@ class TestIxNextgen(unittest.TestCase): 'encapsulation', '-offset', 'IPv4 TOS Precedence') self.assertEqual(self.ixnet.commit.call_count, 2) - def test_get_pppoe_scenario_statistics(self): - with mock.patch.object(self.ixnet_gen, '_build_stats_map') as \ - mock_build_stats: - self.ixnet_gen.get_pppoe_scenario_statistics() - - mock_build_stats.assert_any_call(self.ixnet_gen.PORT_STATISTICS, - self.ixnet_gen.PORT_STATS_NAME_MAP) - mock_build_stats.assert_any_call(self.ixnet_gen.FLOW_STATISTICS, - self.ixnet_gen.LATENCY_NAME_MAP) - mock_build_stats.assert_any_call(self.ixnet_gen.PPPOX_CLIENT_PER_PORT, - self.ixnet_gen.PPPOX_CLIENT_PER_PORT_NAME_MAP) + def test__get_view_page_stats(self): + expected_stats = [ + {'header1': 'row1_1', 'header2': 'row1_2'}, + {'header1': 'row2_1', 'header2': 'row2_2'} + ] + self.ixnet_gen._ixnet.getAttribute.side_effect = [ + ['header1', 'header2'], + [ + [['row1_1', 'row1_2']], + [['row2_1', 'row2_2']] + ] + ] + stats = self.ixnet_gen._get_view_page_stats('view_obj') + self.assertListEqual(stats, expected_stats) + + @mock.patch.object(ixnet_api.IxNextgen, '_get_view_page_stats') + def test_get_pppoe_scenario_statistics(self, mock_get_view): + + pattern = re.compile('Flow 2') + + expected_stats = { + 'port_statistics': [{ + 'port_1': 'port_stat1', + 'port_2': 'port_stat2' + }], + 'flow_statistic': [{ + 'flow_1': 'flow_stat1', + 'flow_2': 'flow_stat2' + }], + 'pppox_client_per_port': [{ + 'sub_1': 'sub_stat1', + 'sub_2': 'sub_stat2' + }] + } + + pppoe_scenario_stats = OrderedDict([ + ('port_statistics', 'view_obj'), + ('flow_statistic', 'view_obj'), + ('pppox_client_per_port', 'view_obj') + ]) + + pppoe_scenario_stats_map = { + 'port_statistics': {'port_1': 'Port 1', + 'port_2': 'Port 2'}, + 'flow_statistic': {'flow_1': 'Flow 1', + 'flow_2': pattern}, + 'pppox_client_per_port': {'sub_1': 'Sub 1', + 'sub_2': 'Sub 2'} + } + + # All stats keys + port_stats = [{'Port 1': 'port_stat1', + 'Port 2': 'port_stat2', + 'Port 3': 'port_stat3'}] + flows_stats = [{'Flow 1': 'flow_stat1', + 'Flow 2': 'flow_stat2', + 'Flow 3': 'flow_stat3'}] + pppoe_sub_stats = [{'Sub 1': 'sub_stat1', + 'Sub 2': 'sub_stat2', + 'Sub 3': 'sub_stat3'}] + + mock_get_view.side_effect = [port_stats, flows_stats, pppoe_sub_stats] + self.ixnet_gen._ixnet.getAttribute.return_value = '1' + + with mock.patch.multiple(ixnet_api.IxNextgen, + PPPOE_SCENARIO_STATS=pppoe_scenario_stats, + PPPOE_SCENARIO_STATS_MAP=pppoe_scenario_stats_map): + stats = self.ixnet_gen.get_pppoe_scenario_statistics() + self.assertDictEqual(stats, expected_stats) + self.assertEqual(self.ixnet_gen.ixnet.getAttribute.call_count, 6) + self.ixnet_gen.ixnet.setAttribute.assert_not_called() def test__update_ipv4_address(self): with mock.patch.object(self.ixnet_gen, '_get_field_in_stack_item', diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py b/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py index c9be200b2..996360c2e 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2017-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ import mock from oslo_serialization import jsonutils -from yardstick.common import exceptions from yardstick.network_services.traffic_profile import http_ixload from yardstick.network_services.traffic_profile.http_ixload import \ join_non_strings, validate_non_string_sequence @@ -288,7 +287,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): net_traffic.network.getL1Plugin.return_value = Exception - with self.assertRaises(exceptions.InvalidRxfFile): + with self.assertRaises(http_ixload.InvalidRxfFile): ixload.update_network_mac_address(net_traffic, "auto") def test_update_network_address(self): @@ -312,7 +311,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): net_traffic.network.getL1Plugin.return_value = Exception - with self.assertRaises(exceptions.InvalidRxfFile): + with self.assertRaises(http_ixload.InvalidRxfFile): ixload.update_network_address(net_traffic, "address", "gateway", "prefix") @@ -375,7 +374,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): pageObject="page_object") net_traffic.activityList = [] - with self.assertRaises(exceptions.InvalidRxfFile): + with self.assertRaises(http_ixload.InvalidRxfFile): ixload.update_page_size(net_traffic, "page_object") def test_update_user_count(self): @@ -390,7 +389,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): activity.config.assert_called_once_with(userObjectiveValue=123) net_traffic.activityList = [] - with self.assertRaises(exceptions.InvalidRxfFile): + with self.assertRaises(http_ixload.InvalidRxfFile): ixload.update_user_count(net_traffic, 123) @mock.patch('yardstick.network_services.traffic_profile.http_ixload.IxLoad') diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py index ef16676c7..ddd1828ae 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -487,7 +487,9 @@ class TestIXIARFC2544Profile(unittest.TestCase): result = r_f_c2544_profile._get_ixia_traffic_profile({}) self.assertDictEqual(result, expected) - def test__ixia_traffic_generate(self): + @mock.patch.object(ixia_rfc2544.IXIARFC2544Profile, + '_update_traffic_tracking_options') + def test__ixia_traffic_generate(self, mock_upd_tracking_opts): traffic_generator = mock.Mock( autospec=trex_traffic_profile.TrexProfile) traffic_generator.networks = { @@ -502,19 +504,69 @@ class TestIXIARFC2544Profile(unittest.TestCase): r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile( self.TRAFFIC_PROFILE) r_f_c2544_profile.rate = 100 - result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj) + result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj, + traffic_generator) self.assertIsNone(result) + mock_upd_tracking_opts.assert_called_once_with(traffic_generator) + + def test__update_traffic_tracking_options(self): + mock_traffic_gen = mock.Mock() + rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile._update_traffic_tracking_options(mock_traffic_gen) + mock_traffic_gen.update_tracking_options.assert_called_once() + + def test__get_framesize(self): + traffic_profile = { + 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}}, + 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}}, + 'uplink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}}, + 'downlink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}} + } + rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile.params = traffic_profile + result = rfc2544_profile._get_framesize() + self.assertEqual(result, '64B') + + def test__get_framesize_IMIX_traffic(self): + traffic_profile = { + 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 50, + '128B': 50}}}}, + 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 50, + '128B': 50}}}}, + 'uplink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 50, + '128B': 50}}}}, + 'downlink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 50, + '128B': 50}}}} + } + rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile.params = traffic_profile + result = rfc2544_profile._get_framesize() + self.assertEqual(result, 'IMIX') + + def test__get_framesize_zero_pkt_size_weight(self): + traffic_profile = { + 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}}, + 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}}, + 'uplink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}}, + 'downlink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}} + } + rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile.params = traffic_profile + result = rfc2544_profile._get_framesize() + self.assertEqual(result, '') def test_execute_traffic_first_run(self): rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) rfc2544_profile.first_run = True rfc2544_profile.rate = 50 + traffic_gen = mock.Mock() + traffic_gen.rfc_helper.iteration.value = 0 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \ as mock_get_tp, \ mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \ as mock_tgenerate: mock_get_tp.return_value = 'fake_tprofile' - output = rfc2544_profile.execute_traffic(mock.ANY, + output = rfc2544_profile.execute_traffic(traffic_gen, ixia_obj=mock.ANY) self.assertTrue(output) @@ -529,13 +581,15 @@ class TestIXIARFC2544Profile(unittest.TestCase): rfc2544_profile.first_run = False rfc2544_profile.max_rate = 70 rfc2544_profile.min_rate = 0 + traffic_gen = mock.Mock() + traffic_gen.rfc_helper.iteration.value = 0 with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \ as mock_get_tp, \ mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \ as mock_tgenerate: mock_get_tp.return_value = 'fake_tprofile' rfc2544_profile.full_profile = mock.ANY - output = rfc2544_profile.execute_traffic(mock.ANY, + output = rfc2544_profile.execute_traffic(traffic_gen, ixia_obj=mock.ANY) self.assertFalse(output) @@ -573,43 +627,53 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_completed(self): samples = {'iface_name_1': - {'in_packets': 1000, 'out_packets': 1000, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25}, + {'InPackets': 1000, 'OutPackets': 1000, + 'InBytes': 64000, 'OutBytes': 64000, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, 'iface_name_2': - {'in_packets': 1005, 'out_packets': 1007, - 'Store-Forward_Avg_latency_ns': 23, - 'Store-Forward_Min_latency_ns': 13, - 'Store-Forward_Max_latency_ns': 28} + {'InPackets': 1005, 'OutPackets': 1007, + 'InBytes': 64320, 'OutBytes': 64448, + 'LatencyAvg': 23, + 'LatencyMin': 13, + 'LatencyMax': 28} } rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile.rate = 100.0 + rfc2544_profile._get_next_rate = mock.Mock(return_value=100.0) + rfc2544_profile._get_framesize = mock.Mock(return_value='64B') completed, samples = rfc2544_profile.get_drop_percentage( - samples, 0, 1, 4) + samples, 0, 1, 4, 0.1) self.assertTrue(completed) self.assertEqual(66.9, samples['TxThroughput']) self.assertEqual(66.833, samples['RxThroughput']) self.assertEqual(0.099651, samples['DropPercentage']) - self.assertEqual(21.5, samples['latency_ns_avg']) - self.assertEqual(14.0, samples['latency_ns_min']) - self.assertEqual(26.5, samples['latency_ns_max']) + self.assertEqual(21.5, samples['LatencyAvg']) + self.assertEqual(13.0, samples['LatencyMin']) + self.assertEqual(28.0, samples['LatencyMax']) + self.assertEqual(100.0, samples['Rate']) + self.assertEqual('64B', samples['PktSize']) def test_get_drop_percentage_over_drop_percentage(self): samples = {'iface_name_1': - {'in_packets': 1000, 'out_packets': 1000, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25}, + {'InPackets': 1000, 'OutPackets': 1000, + 'InBytes': 64000, 'OutBytes': 64000, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, 'iface_name_2': - {'in_packets': 1005, 'out_packets': 1007, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25} + {'InPackets': 1005, 'OutPackets': 1007, + 'InBytes': 64320, 'OutBytes': 64448, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25} } rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) rfc2544_profile.rate = 1000 + rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0) completed, samples = rfc2544_profile.get_drop_percentage( - samples, 0, 0.05, 4) + samples, 0, 0.05, 4, 0.1) self.assertFalse(completed) self.assertEqual(66.9, samples['TxThroughput']) self.assertEqual(66.833, samples['RxThroughput']) @@ -618,20 +682,23 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_under_drop_percentage(self): samples = {'iface_name_1': - {'in_packets': 1000, 'out_packets': 1000, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25}, + {'InPackets': 1000, 'OutPackets': 1000, + 'InBytes': 64000, 'OutBytes': 64000, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, 'iface_name_2': - {'in_packets': 1005, 'out_packets': 1007, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25} + {'InPackets': 1005, 'OutPackets': 1007, + 'InBytes': 64320, 'OutBytes': 64448, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25} } rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) rfc2544_profile.rate = 1000 + rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0) completed, samples = rfc2544_profile.get_drop_percentage( - samples, 0.2, 1, 4) + samples, 0.2, 1, 4, 0.1) self.assertFalse(completed) self.assertEqual(66.9, samples['TxThroughput']) self.assertEqual(66.833, samples['RxThroughput']) @@ -641,20 +708,23 @@ class TestIXIARFC2544Profile(unittest.TestCase): @mock.patch.object(ixia_rfc2544.LOG, 'info') def test_get_drop_percentage_not_flow(self, *args): samples = {'iface_name_1': - {'in_packets': 1000, 'out_packets': 0, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25}, + {'InPackets': 1000, 'OutPackets': 0, + 'InBytes': 64000, 'OutBytes': 0, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, 'iface_name_2': - {'in_packets': 1005, 'out_packets': 0, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25} + {'InPackets': 1005, 'OutPackets': 0, + 'InBytes': 64320, 'OutBytes': 0, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25} } rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) rfc2544_profile.rate = 1000 + rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0) completed, samples = rfc2544_profile.get_drop_percentage( - samples, 0.2, 1, 4) + samples, 0.2, 1, 4, 0.1) self.assertFalse(completed) self.assertEqual(0.0, samples['TxThroughput']) self.assertEqual(66.833, samples['RxThroughput']) @@ -663,25 +733,67 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_first_run(self): samples = {'iface_name_1': - {'in_packets': 1000, 'out_packets': 1000, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25}, + {'InPackets': 1000, 'OutPackets': 1000, + 'InBytes': 64000, 'OutBytes': 64000, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, 'iface_name_2': - {'in_packets': 1005, 'out_packets': 1007, - 'Store-Forward_Avg_latency_ns': 20, - 'Store-Forward_Min_latency_ns': 15, - 'Store-Forward_Max_latency_ns': 25} + {'InPackets': 1005, 'OutPackets': 1007, + 'InBytes': 64320, 'OutBytes': 64448, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25} } rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0) completed, samples = rfc2544_profile.get_drop_percentage( - samples, 0, 1, 4, first_run=True) + samples, 0, 1, 4, 0.1, first_run=True) self.assertTrue(completed) self.assertEqual(66.9, samples['TxThroughput']) self.assertEqual(66.833, samples['RxThroughput']) self.assertEqual(0.099651, samples['DropPercentage']) self.assertEqual(33.45, rfc2544_profile.rate) + def test_get_drop_percentage_resolution(self): + rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile._get_next_rate = mock.Mock(return_value=0.1) + samples = {'iface_name_1': + {'InPackets': 1000, 'OutPackets': 1000, + 'InBytes': 64000, 'OutBytes': 64000, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, + 'iface_name_2': + {'InPackets': 1005, 'OutPackets': 1007, + 'InBytes': 64320, 'OutBytes': 64448, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25} + } + rfc2544_profile.rate = 0.19 + completed, _ = rfc2544_profile.get_drop_percentage( + samples, 0, 0.05, 4, 0.1) + self.assertTrue(completed) + + samples = {'iface_name_1': + {'InPackets': 1000, 'OutPackets': 1000, + 'InBytes': 64000, 'OutBytes': 64000, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25}, + 'iface_name_2': + {'InPackets': 1005, 'OutPackets': 1007, + 'InBytes': 64320, 'OutBytes': 64448, + 'LatencyAvg': 20, + 'LatencyMin': 15, + 'LatencyMax': 25} + } + rfc2544_profile.rate = 0.5 + completed, _ = rfc2544_profile.get_drop_percentage( + samples, 0, 0.05, 4, 0.1) + self.assertFalse(completed) + class TestIXIARFC2544PppoeScenarioProfile(unittest.TestCase): @@ -701,6 +813,9 @@ class TestIXIARFC2544PppoeScenarioProfile(unittest.TestCase): def setUp(self): self.ixia_tp = ixia_rfc2544.IXIARFC2544PppoeScenarioProfile( self.TRAFFIC_PROFILE) + self.ixia_tp.rate = 100.0 + self.ixia_tp._get_next_rate = mock.Mock(return_value=50.0) + self.ixia_tp._get_framesize = mock.Mock(return_value='64B') def test___init__(self): self.assertIsInstance(self.ixia_tp.full_profile, @@ -715,3 +830,195 @@ class TestIXIARFC2544PppoeScenarioProfile(unittest.TestCase): self.ixia_tp._get_flow_groups_params() self.assertDictEqual(self.ixia_tp.full_profile, expected_tp) + + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_flow_groups_params') + def test_update_traffic_profile(self, mock_get_flow_groups_params): + networks = { + 'uplink_0': 'data1', + 'downlink_0': 'data2', + 'uplink_1': 'data3', + 'downlink_1': 'data4' + } + ports = ['xe0', 'xe1', 'xe2', 'xe3'] + mock_traffic_gen = mock.Mock() + mock_traffic_gen.networks = networks + mock_traffic_gen.vnfd_helper.port_num.side_effect = ports + self.ixia_tp.update_traffic_profile(mock_traffic_gen) + mock_get_flow_groups_params.assert_called_once() + self.assertEqual(self.ixia_tp.ports, ports) + + def test__get_prio_flows_drop_percentage(self): + + input_stats = { + '0': { + 'InPackets': 50, + 'OutPackets': 100, + 'Store-Forward_Avg_latency_ns': 10, + 'Store-Forward_Min_latency_ns': 10, + 'Store-Forward_Max_latency_ns': 10}} + + result = self.ixia_tp._get_prio_flows_drop_percentage(input_stats) + self.assertIsNotNone(result['0'].get('DropPercentage')) + self.assertEqual(result['0'].get('DropPercentage'), 50.0) + + def test__get_prio_flows_drop_percentage_traffic_not_flowing(self): + input_stats = { + '0': { + 'InPackets': 0, + 'OutPackets': 0, + 'Store-Forward_Avg_latency_ns': 0, + 'Store-Forward_Min_latency_ns': 0, + 'Store-Forward_Max_latency_ns': 0}} + + result = self.ixia_tp._get_prio_flows_drop_percentage(input_stats) + self.assertIsNotNone(result['0'].get('DropPercentage')) + self.assertEqual(result['0'].get('DropPercentage'), 100) + + def test__get_summary_pppoe_subs_counters(self): + input_stats = { + 'xe0': { + 'OutPackets': 100, + 'SessionsUp': 4, + 'SessionsDown': 0, + 'SessionsNotStarted': 0, + 'SessionsTotal': 4}, + 'xe1': { + 'OutPackets': 100, + 'SessionsUp': 4, + 'SessionsDown': 0, + 'SessionsNotStarted': 0, + 'SessionsTotal': 4} + } + + expected_stats = { + 'SessionsUp': 8, + 'SessionsDown': 0, + 'SessionsNotStarted': 0, + 'SessionsTotal': 8 + } + + res = self.ixia_tp._get_summary_pppoe_subs_counters(input_stats) + self.assertDictEqual(res, expected_stats) + + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_prio_flows_drop_percentage') + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_summary_pppoe_subs_counters') + def test_get_drop_percentage(self, mock_get_pppoe_subs, + mock_sum_prio_drop_rate): + samples = { + 'priority_stats': { + '0': { + 'InPackets': 100, + 'OutPackets': 100, + 'InBytes': 6400, + 'OutBytes': 6400, + 'LatencyAvg': 10, + 'LatencyMin': 10, + 'LatencyMax': 10}}, + 'xe0': { + 'InPackets': 100, + 'OutPackets': 100, + 'InBytes': 6400, + 'OutBytes': 6400, + 'LatencyAvg': 10, + 'LatencyMin': 10, + 'LatencyMax': 10}} + + mock_get_pppoe_subs.return_value = {'SessionsUp': 1} + mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}} + + self.ixia_tp._get_framesize = mock.Mock(return_value='64B') + status, res = self.ixia_tp.get_drop_percentage( + samples, tol_min=0.0, tolerance=0.0001, precision=0, + resolution=0.1, first_run=True) + self.assertIsNotNone(res.get('DropPercentage')) + self.assertIsNotNone(res.get('Priority')) + self.assertIsNotNone(res.get('SessionsUp')) + self.assertEqual(res['DropPercentage'], 0.0) + self.assertEqual(res['Rate'], 100.0) + self.assertEqual(res['PktSize'], '64B') + self.assertTrue(status) + mock_sum_prio_drop_rate.assert_called_once() + mock_get_pppoe_subs.assert_called_once() + + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_prio_flows_drop_percentage') + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_summary_pppoe_subs_counters') + def test_get_drop_percentage_failed_status(self, mock_get_pppoe_subs, + mock_sum_prio_drop_rate): + samples = { + 'priority_stats': { + '0': { + 'InPackets': 90, + 'OutPackets': 100, + 'InBytes': 5760, + 'OutBytes': 6400, + 'LatencyAvg': 10, + 'LatencyMin': 10, + 'LatencyMax': 10}}, + 'xe0': { + 'InPackets': 90, + 'OutPackets': 100, + 'InBytes': 5760, + 'OutBytes': 6400, + 'LatencyAvg': 10, + 'LatencyMin': 10, + 'LatencyMax': 10}} + + mock_get_pppoe_subs.return_value = {'SessionsUp': 1} + mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}} + + status, res = self.ixia_tp.get_drop_percentage( + samples, tol_min=0.0, tolerance=0.0001, precision=0, + resolution=0.1, first_run=True) + self.assertIsNotNone(res.get('DropPercentage')) + self.assertIsNotNone(res.get('Priority')) + self.assertIsNotNone(res.get('SessionsUp')) + self.assertEqual(res['DropPercentage'], 10.0) + self.assertFalse(status) + mock_sum_prio_drop_rate.assert_called_once() + mock_get_pppoe_subs.assert_called_once() + + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_prio_flows_drop_percentage') + @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile, + '_get_summary_pppoe_subs_counters') + def test_get_drop_percentage_priority_flow_check(self, mock_get_pppoe_subs, + mock_sum_prio_drop_rate): + samples = { + 'priority_stats': { + '0': { + 'InPackets': 100, + 'OutPackets': 100, + 'InBytes': 6400, + 'OutBytes': 6400, + 'LatencyAvg': 10, + 'LatencyMin': 10, + 'LatencyMax': 10}}, + 'xe0': { + 'InPackets': 90, + 'OutPackets': 100, + 'InBytes': 5760, + 'OutBytes': 6400, + 'LatencyAvg': 10, + 'LatencyMin': 10, + 'LatencyMax': 10 + }} + + mock_get_pppoe_subs.return_value = {'SessionsUp': 1} + mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}} + + tc_rfc2544_opts = {'priority': '0', + 'allowed_drop_rate': '0.0001 - 0.0001'} + status, res = self.ixia_tp.get_drop_percentage( + samples, tol_min=15.0000, tolerance=15.0001, precision=0, + resolution=0.1, first_run=True, tc_rfc2544_opts=tc_rfc2544_opts) + self.assertIsNotNone(res.get('DropPercentage')) + self.assertIsNotNone(res.get('Priority')) + self.assertIsNotNone(res.get('SessionsUp')) + self.assertTrue(status) + mock_sum_prio_drop_rate.assert_called_once() + mock_get_pppoe_subs.assert_called_once() diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py index 59f37befa..1d9eb0887 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import time import unittest import mock @@ -28,7 +29,8 @@ class TestProxIrqProfile(unittest.TestCase): def _stop_mocks(self): self._mock_log_info.stop() - def test_execute_1(self): + @mock.patch.object(time, 'sleep') + def test_execute_1(self, *args): tp_config = { 'traffic_profile': { }, diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py index 11bee03a4..1593a0835 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2017-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import time import unittest import mock @@ -78,7 +79,8 @@ class TestProxProfile(unittest.TestCase): profile.init(queue) self.assertIs(profile.queue, queue) - def test_execute_traffic(self): + @mock.patch.object(time, 'sleep') + def test_execute_traffic(self, *args): packet_sizes = [ 10, 100, diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py index b8fbc6344..febcfe5da 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py @@ -141,25 +141,25 @@ class TestRFC2544Profile(base.BaseUnitTestCase): port_pg_id, True) mock_stl_profile.assert_called_once_with(['stream1']) - def test__create_imix_data_mode_DIB(self): + def test__create_imix_data_mode_DIP(self): rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE) data = {'64B': 50, '128B': 50} self.assertEqual( {'64': 50.0, '128': 50.0}, rfc2544_profile._create_imix_data( - data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) + data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) data = {'64B': 1, '128b': 3} self.assertEqual( {'64': 25.0, '128': 75.0}, rfc2544_profile._create_imix_data( - data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) + data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) data = {} self.assertEqual( {}, rfc2544_profile._create_imix_data( - data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) + data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) - def test__create_imix_data_mode_DIP(self): + def test__create_imix_data_mode_DIB(self): rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE) data = {'64B': 25, '128B': 25, '512B': 25, '1518B': 25} byte_total = 64 * 25 + 128 * 25 + 512 * 25 + 1518 * 25 @@ -169,17 +169,17 @@ class TestRFC2544Profile(base.BaseUnitTestCase): '512': 512 * 25.0 * 100 / byte_total, '1518': 1518 * 25.0 * 100/ byte_total}, rfc2544_profile._create_imix_data( - data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) + data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) data = {} self.assertEqual( {}, rfc2544_profile._create_imix_data( - data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) + data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) data = {'64B': 100} self.assertEqual( {'64': 100.0}, rfc2544_profile._create_imix_data( - data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) + data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) def test__create_vm(self): packet = {'outer_l2': 'l2_definition'} @@ -248,41 +248,55 @@ class TestRFC2544Profile(base.BaseUnitTestCase): mock.call(percentage=float(25 * 35) / 100), mock.call(percentage=float(75 * 35) / 100)], any_order=True) - def test_get_drop_percentage(self): + @mock.patch.object(rfc2544.RFC2544Profile, '_get_framesize') + def test_get_drop_percentage(self, mock_get_framesize): rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE) + rfc2544_profile.iteration = 1 + mock_get_framesize.return_value = '64B' + samples = [ - {'xe1': {'tx_throughput_fps': 110, - 'rx_throughput_fps': 101, - 'out_packets': 2100, + {'xe1': {'out_packets': 2100, 'in_packets': 2010, + 'out_bytes': 134400, + 'in_bytes': 128640, 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)}, - 'xe2': {'tx_throughput_fps': 210, - 'rx_throughput_fps': 201, - 'out_packets': 4100, + 'xe2': {'out_packets': 4100, 'in_packets': 4010, + 'out_bytes': 262400, + 'in_bytes': 256640, 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)}}, - {'xe1': {'tx_throughput_fps': 156, - 'rx_throughput_fps': 108, - 'out_packets': 2110, + {'xe1': {'out_packets': 2110, 'in_packets': 2040, + 'out_bytes': 135040, + 'in_bytes': 130560, 'latency': 'Latency1', 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)}, - 'xe2': {'tx_throughput_fps': 253, - 'rx_throughput_fps': 215, - 'out_packets': 4150, + 'xe2': {'out_packets': 4150, 'in_packets': 4010, + 'out_bytes': 265600, + 'in_bytes': 256640, 'latency': 'Latency2', 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)}} ] completed, output = rfc2544_profile.get_drop_percentage( - samples, 0, 0, False) - expected = {'DropPercentage': 50.0, - 'Latency': {'xe1': 'Latency1', 'xe2': 'Latency2'}, + samples, 0, 0, False, 0.1) + expected = {'xe1': {'OutPackets': 10, + 'InPackets': 30, + 'OutBytes': 640, + 'InBytes': 1920}, + 'xe2': {'OutPackets': 50, + 'InPackets': 0, + 'OutBytes': 3200, + 'InBytes': 0}, + 'DropPercentage': 50.0, 'RxThroughput': 1000000.0, 'TxThroughput': 2000000.0, - 'CurrentDropPercentage': 50.0, + 'RxThroughputBps': 64000000.0, + 'TxThroughputBps': 128000000.0, 'Rate': 100.0, - 'Throughput': 1000000.0} + 'Iteration': 1, + 'PktSize': '64B', + 'Status': 'Failure'} self.assertEqual(expected, output) self.assertFalse(completed) diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_sip.py b/yardstick/tests/unit/network_services/traffic_profile/test_sip.py new file mode 100644 index 000000000..bf26ee44d --- /dev/null +++ b/yardstick/tests/unit/network_services/traffic_profile/test_sip.py @@ -0,0 +1,51 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import mock + +from yardstick.network_services.traffic_profile import sip + + +class TestSipProfile(unittest.TestCase): + + TRAFFIC_PROFILE = { + "schema": "nsb:traffic_profile:0.1", + "name": "sip", + "description": "Traffic profile to run sip", + "traffic_profile": { + "traffic_type": "SipProfile", + "frame_rate": 100, # pps + "duration": 10, + "enable_latency": False}} + + def setUp(self): + self.sip_profile = sip.SipProfile(self.TRAFFIC_PROFILE) + + def test___init__(self): + self.assertIsNone(self.sip_profile.generator) + + def test_execute_traffic(self): + self.sip_profile.generator = None + mock_traffic_generator = mock.Mock() + self.sip_profile.execute_traffic(mock_traffic_generator) + self.assertIsNotNone(self.sip_profile.generator) + + def test_is_ended_true(self): + self.sip_profile.generator = mock.Mock(return_value=True) + self.assertTrue(self.sip_profile.is_ended()) + + def test_is_ended_false(self): + self.sip_profile.generator = None + self.assertFalse(self.sip_profile.is_ended()) diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py new file mode 100644 index 000000000..8ad17b547 --- /dev/null +++ b/yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py @@ -0,0 +1,890 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mock +from trex_stl_lib import trex_stl_client +from trex_stl_lib import trex_stl_packet_builder_scapy +from trex_stl_lib import trex_stl_streams + +from yardstick.common import constants +from yardstick.network_services.helpers.vpp_helpers.multiple_loss_ratio_search import \ + MultipleLossRatioSearch +from yardstick.network_services.helpers.vpp_helpers.ndr_pdr_result import \ + NdrPdrResult +from yardstick.network_services.helpers.vpp_helpers.receive_rate_interval import \ + ReceiveRateInterval +from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \ + ReceiveRateMeasurement +from yardstick.network_services.traffic_profile import base as tp_base +from yardstick.network_services.traffic_profile import rfc2544, vpp_rfc2544 +from yardstick.network_services.traffic_profile.rfc2544 import PortPgIDMap +from yardstick.tests.unit import base + + +class TestVppRFC2544Profile(base.BaseUnitTestCase): + TRAFFIC_PROFILE = { + "schema": "isb:traffic_profile:0.1", + "name": "fixed", + "description": "Fixed traffic profile to run UDP traffic", + "traffic_profile": { + "traffic_type": "FixedTraffic", + "duration": 30, + "enable_latency": True, + "frame_rate": 100, + "intermediate_phases": 2, + "lower_bound": 1.0, + "step_interval": 0.5, + "test_precision": 0.1, + "upper_bound": 100.0}} + + TRAFFIC_PROFILE_MAX_RATE = { + "schema": "isb:traffic_profile:0.1", + "name": "fixed", + "description": "Fixed traffic profile to run UDP traffic", + "traffic_profile": { + "traffic_type": "FixedTraffic", + "duration": 30, + "enable_latency": True, + "frame_rate": 10000, + "intermediate_phases": 2, + "lower_bound": 1.0, + "step_interval": 0.5, + "test_precision": 0.1, + "upper_bound": 100.0}} + + PROFILE = { + "description": "Traffic profile to run RFC2544 latency", + "downlink_0": { + "ipv4": { + "id": 2, + "outer_l2": { + "framesize": { + "1024B": "0", + "1280B": "0", + "128B": "0", + "1400B": "0", + "1500B": "0", + "1518B": "0", + "256B": "0", + "373b": "0", + "512B": "0", + "570B": "0", + "64B": "100" + } + }, + "outer_l3v4": { + "count": "1", + "dstip4": "10.0.0.0-10.0.0.100", + "proto": 61, + "srcip4": "20.0.0.0-20.0.0.100" + } + } + }, + "name": "rfc2544", + "schema": "nsb:traffic_profile:0.1", + "traffic_profile": { + "duration": 30, + "enable_latency": True, + "frame_rate": 100, + "intermediate_phases": 2, + "lower_bound": 1.0, + "step_interval": 0.5, + "test_precision": 0.1, + "traffic_type": "VppRFC2544Profile", + "upper_bound": 100.0 + }, + "uplink": { + "ipv4": { + "id": 1, + "outer_l2": { + "framesize": { + "1024B": "0", + "1280B": "0", + "128B": "0", + "1400B": "0", + "1500B": "0", + "1518B": "0", + "256B": "0", + "373B": "0", + "512B": "0", + "570B": "0", + "64B": "100" + } + }, + "outer_l3v4": { + "count": "10", + "dstip4": "20.0.0.0-20.0.0.100", + "proto": 61, + "srcip4": "10.0.0.0-10.0.0.100" + } + } + } + } + + def test___init__(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + self.assertEqual(vpp_rfc2544_profile.max_rate, + vpp_rfc2544_profile.rate) + self.assertEqual(0, vpp_rfc2544_profile.min_rate) + self.assertEqual(2, vpp_rfc2544_profile.number_of_intermediate_phases) + self.assertEqual(30, vpp_rfc2544_profile.duration) + self.assertEqual(0.1, vpp_rfc2544_profile.precision) + self.assertEqual(1.0, vpp_rfc2544_profile.lower_bound) + self.assertEqual(100.0, vpp_rfc2544_profile.upper_bound) + self.assertEqual(0.5, vpp_rfc2544_profile.step_interval) + self.assertEqual(True, vpp_rfc2544_profile.enable_latency) + + def test_init_traffic_params(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + mock_generator = mock.MagicMock() + mock_generator.rfc2544_helper.latency = True + mock_generator.rfc2544_helper.tolerance_low = 0.0 + mock_generator.rfc2544_helper.tolerance_high = 0.005 + mock_generator.scenario_helper.all_options = { + "vpp_config": { + "max_rate": 14880000 + } + } + vpp_rfc2544_profile.init_traffic_params(mock_generator) + self.assertEqual(0.0, vpp_rfc2544_profile.tolerance_low) + self.assertEqual(0.005, vpp_rfc2544_profile.tolerance_high) + self.assertEqual(14880000, vpp_rfc2544_profile.max_rate) + self.assertEqual(True, vpp_rfc2544_profile.enable_latency) + + def test_calculate_frame_size(self): + imix = {'40B': 7, '576B': 4, '1500B': 1} + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + self.assertEqual((4084 / 12, 12), + vpp_rfc2544_profile.calculate_frame_size(imix)) + + def test_calculate_frame_size_empty(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + self.assertEqual((64, 100), + vpp_rfc2544_profile.calculate_frame_size(None)) + + def test_calculate_frame_size_error(self): + imix = {'40B': -7, '576B': 4, '1500B': 1} + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + self.assertEqual((64, 100), + vpp_rfc2544_profile.calculate_frame_size(imix)) + + def test__gen_payload(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + self.assertIsNotNone(vpp_rfc2544_profile._gen_payload(4)) + + def test_register_generator(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + mock_generator = mock.MagicMock() + mock_generator.rfc2544_helper.latency = True + mock_generator.rfc2544_helper.tolerance_low = 0.0 + mock_generator.rfc2544_helper.tolerance_high = 0.005 + mock_generator.scenario_helper.all_options = { + "vpp_config": { + "max_rate": 14880000 + } + } + vpp_rfc2544_profile.register_generator(mock_generator) + self.assertEqual(0.0, vpp_rfc2544_profile.tolerance_low) + self.assertEqual(0.005, vpp_rfc2544_profile.tolerance_high) + self.assertEqual(14880000, vpp_rfc2544_profile.max_rate) + self.assertEqual(True, vpp_rfc2544_profile.enable_latency) + + def test_stop_traffic(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + mock_generator = mock.Mock() + vpp_rfc2544_profile.stop_traffic(traffic_generator=mock_generator) + mock_generator.client.stop.assert_called_once() + mock_generator.client.reset.assert_called_once() + mock_generator.client.remove_all_streams.assert_called_once() + + def test_execute_traffic(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.init_queue(mock.MagicMock()) + vpp_rfc2544_profile.params = { + 'downlink_0': 'profile1', + 'uplink_0': 'profile2'} + mock_generator = mock.MagicMock() + mock_generator.networks = { + 'downlink_0': ['xe0', 'xe1'], + 'uplink_0': ['xe2', 'xe3'], + 'uplink_1': ['xe2', 'xe3']} + mock_generator.port_num.side_effect = [10, 20, 30, 40] + mock_generator.rfc2544_helper.correlated_traffic = False + + with mock.patch.object(vpp_rfc2544_profile, 'create_profile') as \ + mock_create_profile: + vpp_rfc2544_profile.execute_traffic( + traffic_generator=mock_generator) + mock_create_profile.assert_has_calls([ + mock.call('profile1', 10), + mock.call('profile1', 20), + mock.call('profile2', 30), + mock.call('profile2', 40)]) + mock_generator.client.add_streams.assert_has_calls([ + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[30]), + mock.call(mock.ANY, ports=[40])]) + + def test_execute_traffic_correlated_traffic(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.init_queue(mock.MagicMock()) + vpp_rfc2544_profile.params = { + 'downlink_0': 'profile1', + 'uplink_0': 'profile2'} + mock_generator = mock.MagicMock() + mock_generator.networks = { + 'downlink_0': ['xe0', 'xe1'], + 'uplink_0': ['xe2', 'xe3']} + mock_generator.port_num.side_effect = [10, 20, 30, 40] + mock_generator.rfc2544_helper.correlated_traffic = True + + with mock.patch.object(vpp_rfc2544_profile, 'create_profile') as \ + mock_create_profile: + vpp_rfc2544_profile.execute_traffic( + traffic_generator=mock_generator) + mock_create_profile.assert_has_calls([ + mock.call('profile2', 10), + mock.call('profile2', 20)]) + mock_generator.client.add_streams.assert_has_calls([ + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20])]) + + def test_execute_traffic_max_rate(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE_MAX_RATE) + vpp_rfc2544_profile.init_queue(mock.MagicMock()) + vpp_rfc2544_profile.pkt_size = 64 + vpp_rfc2544_profile.params = { + 'downlink_0': 'profile1', + 'uplink_0': 'profile2'} + mock_generator = mock.MagicMock() + mock_generator.networks = { + 'downlink_0': ['xe0', 'xe1'], + 'uplink_0': ['xe2', 'xe3']} + mock_generator.port_num.side_effect = [10, 20, 30, 40] + mock_generator.rfc2544_helper.correlated_traffic = False + + with mock.patch.object(vpp_rfc2544_profile, 'create_profile') as \ + mock_create_profile: + vpp_rfc2544_profile.execute_traffic( + traffic_generator=mock_generator) + mock_create_profile.assert_has_calls([ + mock.call('profile1', 10), + mock.call('profile1', 20), + mock.call('profile2', 30), + mock.call('profile2', 40)]) + mock_generator.client.add_streams.assert_has_calls([ + mock.call(mock.ANY, ports=[10]), + mock.call(mock.ANY, ports=[20]), + mock.call(mock.ANY, ports=[30]), + mock.call(mock.ANY, ports=[40])]) + + @mock.patch.object(trex_stl_streams, 'STLProfile') + def test_create_profile(self, mock_stl_profile): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + port = mock.ANY + profile_data = {'packetid_1': {'outer_l2': {'framesize': 'imix_info'}}} + with mock.patch.object(vpp_rfc2544_profile, 'calculate_frame_size') as \ + mock_calculate_frame_size, \ + mock.patch.object(vpp_rfc2544_profile, '_create_imix_data') as \ + mock_create_imix, \ + mock.patch.object(vpp_rfc2544_profile, '_create_vm') as \ + mock_create_vm, \ + mock.patch.object(vpp_rfc2544_profile, + '_create_single_stream') as \ + mock_create_single_stream: + mock_calculate_frame_size.return_value = 64, 100 + mock_create_imix.return_value = 'imix_data' + mock_create_single_stream.return_value = ['stream1'] + vpp_rfc2544_profile.create_profile(profile_data, port) + + mock_create_imix.assert_called_once_with('imix_info') + mock_create_vm.assert_called_once_with( + {'outer_l2': {'framesize': 'imix_info'}}) + mock_create_single_stream.assert_called_once_with(port, 'imix_data', + 100) + mock_stl_profile.assert_called_once_with(['stream1']) + + @mock.patch.object(trex_stl_streams, 'STLProfile') + def test_create_profile_max_rate(self, mock_stl_profile): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE_MAX_RATE) + port = mock.ANY + profile_data = {'packetid_1': {'outer_l2': {'framesize': 'imix_info'}}} + with mock.patch.object(vpp_rfc2544_profile, 'calculate_frame_size') as \ + mock_calculate_frame_size, \ + mock.patch.object(vpp_rfc2544_profile, '_create_imix_data') as \ + mock_create_imix, \ + mock.patch.object(vpp_rfc2544_profile, '_create_vm') as \ + mock_create_vm, \ + mock.patch.object(vpp_rfc2544_profile, + '_create_single_stream') as \ + mock_create_single_stream: + mock_calculate_frame_size.return_value = 64, 100 + mock_create_imix.return_value = 'imix_data' + mock_create_single_stream.return_value = ['stream1'] + vpp_rfc2544_profile.create_profile(profile_data, port) + + mock_create_imix.assert_called_once_with('imix_info', 'mode_DIP') + mock_create_vm.assert_called_once_with( + {'outer_l2': {'framesize': 'imix_info'}}) + mock_create_single_stream.assert_called_once_with(port, 'imix_data', + 100) + mock_stl_profile.assert_called_once_with(['stream1']) + + def test__create_imix_data_mode_DIP(self): + rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(self.TRAFFIC_PROFILE) + data = {'64B': 50, '128B': 50} + self.assertEqual( + {'64': 50.0, '128': 50.0}, + rfc2544_profile._create_imix_data( + data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) + data = {'64B': 1, '128b': 3} + self.assertEqual( + {'64': 25.0, '128': 75.0}, + rfc2544_profile._create_imix_data( + data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) + data = {} + self.assertEqual( + {}, + rfc2544_profile._create_imix_data( + data, weight_mode=constants.DISTRIBUTION_IN_PACKETS)) + + def test__create_imix_data_mode_DIB(self): + rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(self.TRAFFIC_PROFILE) + data = {'64B': 25, '128B': 25, '512B': 25, '1518B': 25} + byte_total = 64 * 25 + 128 * 25 + 512 * 25 + 1518 * 25 + self.assertEqual( + {'64': 64 * 25.0 * 100 / byte_total, + '128': 128 * 25.0 * 100 / byte_total, + '512': 512 * 25.0 * 100 / byte_total, + '1518': 1518 * 25.0 * 100 / byte_total}, + rfc2544_profile._create_imix_data( + data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) + data = {} + self.assertEqual( + {}, + rfc2544_profile._create_imix_data( + data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) + data = {'64B': 100} + self.assertEqual( + {'64': 100.0}, + rfc2544_profile._create_imix_data( + data, weight_mode=constants.DISTRIBUTION_IN_BYTES)) + + def test__create_vm(self): + packet = {'outer_l2': 'l2_definition'} + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + with mock.patch.object(vpp_rfc2544_profile, '_set_outer_l2_fields') as \ + mock_l2_fileds: + vpp_rfc2544_profile._create_vm(packet) + mock_l2_fileds.assert_called_once_with('l2_definition') + + @mock.patch.object(trex_stl_packet_builder_scapy, 'STLPktBuilder', + return_value='packet') + def test__create_single_packet(self, mock_pktbuilder): + size = 128 + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.ether_packet = mock.MagicMock() + vpp_rfc2544_profile.ip_packet = mock.MagicMock() + vpp_rfc2544_profile.udp_packet = mock.MagicMock() + vpp_rfc2544_profile.trex_vm = 'trex_vm' + # base_pkt = ( + # vpp_rfc2544_profile.ether_packet / vpp_rfc2544_profile.ip_packet / + # vpp_rfc2544_profile.udp_packet) + # pad = (size - len(base_pkt)) * 'x' + output = vpp_rfc2544_profile._create_single_packet(size=size) + self.assertEqual(mock_pktbuilder.call_count, 2) + # mock_pktbuilder.assert_called_once_with(pkt=base_pkt / pad, + # vm='trex_vm') + self.assertEqual(output, ('packet', 'packet')) + + def test__set_outer_l3v4_fields(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + outer_l3v4 = self.PROFILE[ + tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l3v4'] + outer_l3v4['proto'] = 'tcp' + self.assertIsNone( + vpp_rfc2544_profile._set_outer_l3v4_fields(outer_l3v4)) + + @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats') + @mock.patch.object(trex_stl_streams, 'STLTXCont') + @mock.patch.object(trex_stl_client, 'STLStream') + def test__create_single_stream(self, mock_stream, mock_txcont, + mock_latency): + imix_data = {'64': 25, '512': 75} + mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4'] + mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4'] + mock_latency.side_effect = ['latency1', 'latency2'] + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap() + vpp_rfc2544_profile.port_pg_id.add_port(10) + with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \ + mock_create_single_packet: + mock_create_single_packet.return_value = 64, 100 + output = vpp_rfc2544_profile._create_single_stream(10, imix_data, + 100, 0.0) + self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output) + mock_latency.assert_has_calls([ + mock.call(pg_id=1), mock.call(pg_id=2)]) + mock_txcont.assert_has_calls([ + mock.call(percentage=25 * 100 / 100), + mock.call(percentage=75 * 100 / 100)], any_order=True) + + @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats') + @mock.patch.object(trex_stl_streams, 'STLTXCont') + @mock.patch.object(trex_stl_client, 'STLStream') + def test__create_single_stream_max_rate(self, mock_stream, mock_txcont, + mock_latency): + imix_data = {'64': 25, '512': 75} + mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4'] + mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4'] + mock_latency.side_effect = ['latency1', 'latency2'] + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE_MAX_RATE) + vpp_rfc2544_profile.pkt_size = 64 + vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap() + vpp_rfc2544_profile.port_pg_id.add_port(1) + with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \ + mock_create_single_packet: + mock_create_single_packet.return_value = 64, 100 + output = vpp_rfc2544_profile._create_single_stream(1, imix_data, + 100, 0.0) + self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output) + mock_latency.assert_has_calls([ + mock.call(pg_id=1), mock.call(pg_id=2)]) + mock_txcont.assert_has_calls([ + mock.call(pps=int(25 * 100 / 100)), + mock.call(pps=int(75 * 100 / 100))], any_order=True) + + @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats') + @mock.patch.object(trex_stl_streams, 'STLTXCont') + @mock.patch.object(trex_stl_client, 'STLStream') + def test__create_single_stream_mlr_search(self, mock_stream, mock_txcont, + mock_latency): + imix_data = {'64': 25, '512': 75} + mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4'] + mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4'] + mock_latency.side_effect = ['latency1', 'latency2'] + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.max_rate = 14880000 + vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap() + vpp_rfc2544_profile.port_pg_id.add_port(10) + with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \ + mock_create_single_packet: + mock_create_single_packet.return_value = 64, 100 + output = vpp_rfc2544_profile._create_single_stream(10, imix_data, + 100, 0.0) + self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output) + mock_latency.assert_has_calls([ + mock.call(pg_id=1), mock.call(pg_id=2)]) + mock_txcont.assert_has_calls([ + mock.call(pps=25 * 100 / 100), + mock.call(pps=75 * 100 / 100)], any_order=True) + + def test_binary_search_with_optimized(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.pkt_size = 64 + vpp_rfc2544_profile.init_queue(mock.MagicMock()) + mock_generator = mock.MagicMock() + mock_generator.vnfd_helper.interfaces = [ + {"name": "xe0"}, {"name": "xe0"} + ] + + vpp_rfc2544_profile.ports = [0, 1] + vpp_rfc2544_profile.port_pg_id = PortPgIDMap() + vpp_rfc2544_profile.port_pg_id.add_port(0) + vpp_rfc2544_profile.port_pg_id.add_port(1) + vpp_rfc2544_profile.profiles = mock.MagicMock() + vpp_rfc2544_profile.test_data = mock.MagicMock() + vpp_rfc2544_profile.queue = mock.MagicMock() + + with mock.patch.object(MultipleLossRatioSearch, 'measure') as \ + mock_measure, \ + mock.patch.object(MultipleLossRatioSearch, 'ndrpdr') as \ + mock_ndrpdr: + measured_low = ReceiveRateMeasurement(1, 14880000, 14879927, 0) + measured_high = ReceiveRateMeasurement(1, 14880000, 14879927, 0) + measured_low.latency = ['1000/3081/3962', '500/3149/3730'] + measured_high.latency = ['1000/3081/3962', '500/3149/3730'] + starting_interval = ReceiveRateInterval(measured_low, + measured_high) + starting_result = NdrPdrResult(starting_interval, + starting_interval) + mock_measure.return_value = ReceiveRateMeasurement(1, 14880000, + 14879927, 0) + mock_ndrpdr.return_value = MultipleLossRatioSearch.ProgressState( + starting_result, 2, 30, 0.005, 0.0, + 4857361, 4977343) + + result_samples = vpp_rfc2544_profile.binary_search_with_optimized( + traffic_generator=mock_generator, duration=30, + timeout=720, + test_data={}) + + expected = {'Result_NDR_LOWER': {'bandwidth_total_Gbps': 9.999310944, + 'rate_total_pps': 14879927.0}, + 'Result_NDR_UPPER': {'bandwidth_total_Gbps': 9.999310944, + 'rate_total_pps': 14879927.0}, + 'Result_NDR_packets_lost': {'packet_loss_ratio': 0.0, + 'packets_lost': 0.0}, + 'Result_PDR_LOWER': {'bandwidth_total_Gbps': 9.999310944, + 'rate_total_pps': 14879927.0}, + 'Result_PDR_UPPER': {'bandwidth_total_Gbps': 9.999310944, + 'rate_total_pps': 14879927.0}, + 'Result_PDR_packets_lost': {'packet_loss_ratio': 0.0, + 'packets_lost': 0.0}, + 'Result_stream0_NDR_LOWER': {'avg_latency': 3081.0, + 'max_latency': 3962.0, + 'min_latency': 1000.0}, + 'Result_stream0_PDR_LOWER': {'avg_latency': 3081.0, + 'max_latency': 3962.0, + 'min_latency': 1000.0}, + 'Result_stream1_NDR_LOWER': {'avg_latency': 3149.0, + 'max_latency': 3730.0, + 'min_latency': 500.0}, + 'Result_stream1_PDR_LOWER': {'avg_latency': 3149.0, + 'max_latency': 3730.0, + 'min_latency': 500.0}} + self.assertEqual(expected, result_samples) + + def test_binary_search(self): + vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile( + self.TRAFFIC_PROFILE) + vpp_rfc2544_profile.pkt_size = 64 + vpp_rfc2544_profile.init_queue(mock.MagicMock()) + mock_generator = mock.MagicMock() + mock_generator.vnfd_helper.interfaces = [ + {"name": "xe0"}, {"name": "xe1"} + ] + stats = { + "0": { + "ibytes": 55549120, + "ierrors": 0, + "ipackets": 867955, + "obytes": 55549696, + "oerrors": 0, + "opackets": 867964, + "rx_bps": 104339032.0, + "rx_bps_L1": 136944984.0, + "rx_pps": 203787.2, + "rx_util": 1.36944984, + "tx_bps": 134126008.0, + "tx_bps_L1": 176040392.0, + "tx_pps": 261964.9, + "tx_util": 1.7604039200000001 + }, + "1": { + "ibytes": 55549696, + "ierrors": 0, + "ipackets": 867964, + "obytes": 55549120, + "oerrors": 0, + "opackets": 867955, + "rx_bps": 134119648.0, + "rx_bps_L1": 176032032.0, + "rx_pps": 261952.4, + "rx_util": 1.76032032, + "tx_bps": 104338192.0, + "tx_bps_L1": 136943872.0, + "tx_pps": 203785.5, + "tx_util": 1.36943872 + }, + "flow_stats": { + "1": { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 6400, + "1": 0, + "total": 6400 + }, + "rx_pkts": { + "0": 100, + "1": 0, + "total": 100 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 0, + "1": 6400, + "total": 6400 + }, + "tx_pkts": { + "0": 0, + "1": 100, + "total": 100 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + "2": { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 0, + "1": 6464, + "total": 6464 + }, + "rx_pkts": { + "0": 0, + "1": 101, + "total": 101 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 6464, + "1": 0, + "total": 6464 + }, + "tx_pkts": { + "0": 101, + "1": 0, + "total": 101 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + "global": { + "rx_err": { + "0": 0, + "1": 0 + }, + "tx_err": { + "0": 0, + "1": 0 + } + } + }, + "global": { + "bw_per_core": 45.6, + "cpu_util": 0.1494, + "queue_full": 0, + "rx_bps": 238458672.0, + "rx_cpu_util": 4.751e-05, + "rx_drop_bps": 0.0, + "rx_pps": 465739.6, + "tx_bps": 238464208.0, + "tx_pps": 465750.4 + }, + "latency": { + "1": { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 63.375, + "histogram": { + "20": 1, + "30": 18, + "40": 12, + "50": 10, + "60": 12, + "70": 11, + "80": 6, + "90": 10, + "100": 20 + }, + "jitter": 23, + "last_max": 122, + "total_max": 123, + "total_min": 20 + } + }, + "2": { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 74, + "histogram": { + "60": 20, + "70": 10, + "80": 3, + "90": 4, + "100": 64 + }, + "jitter": 6, + "last_max": 83, + "total_max": 135, + "total_min": 60 + } + }, + "global": { + "bad_hdr": 0, + "old_flow": 0 + } + }, + "total": { + "ibytes": 111098816, + "ierrors": 0, + "ipackets": 1735919, + "obytes": 111098816, + "oerrors": 0, + "opackets": 1735919, + "rx_bps": 238458680.0, + "rx_bps_L1": 312977016.0, + "rx_pps": 465739.6, + "rx_util": 3.1297701599999996, + "tx_bps": 238464200.0, + "tx_bps_L1": 312984264.0, + "tx_pps": 465750.4, + "tx_util": 3.12984264 + } + } + samples = { + "xe0": { + "in_packets": 867955, + "latency": { + "2": { + "avg_latency": 74.0, + "max_latency": 135.0, + "min_latency": 60.0 + } + }, + "out_packets": 867964, + "rx_throughput_bps": 104339032.0, + "rx_throughput_fps": 203787.2, + "tx_throughput_bps": 134126008.0, + "tx_throughput_fps": 261964.9 + }, + "xe1": { + "in_packets": 867964, + "latency": { + "1": { + "avg_latency": 63.375, + "max_latency": 123.0, + "min_latency": 20.0 + } + }, + "out_packets": 867955, + "rx_throughput_bps": 134119648.0, + "rx_throughput_fps": 261952.4, + "tx_throughput_bps": 104338192.0, + "tx_throughput_fps": 203785.5 + } + } + + mock_generator.loss = 0 + mock_generator.sent = 2169700 + mock_generator.send_traffic_on_tg = mock.Mock(return_value=stats) + mock_generator.generate_samples = mock.Mock(return_value=samples) + + result_samples = vpp_rfc2544_profile.binary_search( + traffic_generator=mock_generator, duration=30, + tolerance_value=0.005, + test_data={}) + + expected = {'Result_theor_max_throughput': 134126008.0, + 'xe0': {'Result_Actual_throughput': 104339032.0}, + 'xe1': {'Result_Actual_throughput': 134119648.0}} + self.assertEqual(expected, result_samples) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/tc_baremetal_rfc2544_ipv4_1flow_64B.yaml b/yardstick/tests/unit/network_services/vnf_generic/vnf/tc_baremetal_rfc2544_ipv4_1flow_64B.yaml index fb1be35c1..09c22ad9e 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/tc_baremetal_rfc2544_ipv4_1flow_64B.yaml +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/tc_baremetal_rfc2544_ipv4_1flow_64B.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ scenarios: traffic_profile: "../../traffic_profiles/ipv4_throughput_vpe.yaml" topology: vpe_vnf_topology.yaml nodes: - tg__1: trafficgen_1.yardstick - vnf__1: vnf.yardstick + tg__0: trafficgen_0.yardstick + vnf__0: vnf_0.yardstick tc_options: rfc2544: allowed_drop_rate: 0.8 - 1 diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py index 2d7ec195f..12bb42f20 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_agnostic_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_agnostic_vnf.py index 47e464da3..7c7fe5955 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_agnostic_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_agnostic_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_base.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_base.py index ea2f84d98..1a72e042b 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_base.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_base.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py index 635ca41a2..d0672dcfd 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_epc_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_epc_vnf.py index c5bc3f59d..b1bef2e39 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_epc_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_epc_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_ipsec_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_ipsec_vnf.py new file mode 100644 index 000000000..00dc4a5d1 --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_ipsec_vnf.py @@ -0,0 +1,2151 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from multiprocessing import Process + +import mock + +from yardstick.benchmark.contexts import base as ctx_base +from yardstick.common import utils +from yardstick.network_services.helpers import cpu +from yardstick.network_services.nfvi.resource import ResourceProfile +from yardstick.network_services.vnf_generic.vnf import ipsec_vnf, vpp_helpers +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper +from yardstick.network_services.vnf_generic.vnf.ipsec_vnf import CryptoAlg, \ + IntegAlg, VipsecApproxSetupEnvHelper +from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import \ + mock_ssh + +SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' + +NAME = 'vnf__1' + + +class TestCryptoAlg(unittest.TestCase): + + def test__init__(self): + encr_alg = CryptoAlg.AES_GCM_128 + self.assertEqual('aes-gcm-128', encr_alg.alg_name) + self.assertEqual('AES-GCM', encr_alg.scapy_name) + self.assertEqual(20, encr_alg.key_len) + + +class TestIntegAlg(unittest.TestCase): + + def test__init__(self): + auth_alg = IntegAlg.AES_GCM_128 + self.assertEqual('aes-gcm-128', auth_alg.alg_name) + self.assertEqual('AES-GCM', auth_alg.scapy_name) + self.assertEqual(20, auth_alg.key_len) + + +@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process") +class TestVipsecApproxVnf(unittest.TestCase): + VNFD = {'vnfd:vnfd-catalog': + {'vnfd': + [{ + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "VPP IPsec", + "id": "VipsecApproxVnf", + "mgmt-interface": { + "ip": "10.10.10.101", + "password": "r00t", + "user": "root", + "vdu-id": "ipsecvnf-baremetal" + }, + "name": "IpsecVnf", + "short-name": "IpsecVnf", + "vdu": [ + { + "description": "VPP Ipsec", + "external-interface": [ + { + "name": "xe0", + "virtual-interface": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:ff:06.0" + }, + "vnfd-connection-point-ref": "xe0" + }, + { + "name": "xe1", + "virtual-interface": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe1", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:ff:07.0" + }, + "vnfd-connection-point-ref": "xe1" + } + ], + "id": "ipsecvnf-baremetal", + "name": "ipsecvnf-baremetal", + "routing_table": [] + } + ] + } + ]}} + + VNFD_ERROR = {'vnfd:vnfd-catalog': + {'vnfd': + [{ + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "VPP IPsec", + "id": "VipsecApproxVnf", + "mgmt-interface": { + "ip": "10.10.10.101", + "password": "r00t", + "user": "root", + "vdu-id": "ipsecvnf-baremetal" + }, + "name": "IpsecVnf", + "short-name": "IpsecVnf", + "vdu": [ + { + "description": "VPP Ipsec", + "external-interface": [ + { + "name": "xe0", + "virtual-interface": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "peer_name": "tg__0", + "vld_id": "uplink_1", + "vpci": "0000:ff:06.0" + }, + "vnfd-connection-point-ref": "xe0" + }, + { + "name": "xe1", + "virtual-interface": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:ff:07.0" + }, + "vnfd-connection-point-ref": "xe1" + } + ], + "id": "ipsecvnf-baremetal", + "name": "ipsecvnf-baremetal", + "routing_table": [] + } + ] + } + ]}} + + scenario_cfg = { + "nodes": { + "tg__0": "trafficgen.yardstick-5486cc2f", + "vnf__0": "vnf0.yardstick-5486cc2f", + "vnf__1": "vnf1.yardstick-5486cc2f" + }, + "options": { + "flow": { + "count": 1, + "dst_ip": [ + "20.0.0.0-20.0.0.100" + ], + "src_ip": [ + "10.0.0.0-10.0.0.100" + ] + }, + "framesize": { + "downlink": { + "64B": 100 + }, + "uplink": { + "64B": 100 + } + }, + "rfc2544": { + "allowed_drop_rate": "0.0 - 0.005" + }, + "tg__0": { + "collectd": { + "interval": 1 + }, + "queues_per_port": 7 + }, + "traffic_type": 4, + "vnf__0": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vnf__1": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vpp_config": { + "crypto_algorithms": "aes-gcm", + "tunnel": 1 + } + }, + "runner": { + "duration": 500, + "interval": 10, + "object": + "yardstick.benchmark.scenarios.networking.vnf_generic.NetworkServiceTestCase", + "output_config": { + "DEFAULT": { + "debug": "False", + "dispatcher": [ + "influxdb" + ] + }, + "dispatcher_file": { + "debug": "False", + "dispatcher": "influxdb", + "file_path": "/tmp/yardstick.out" + }, + "dispatcher_http": { + "debug": "False", + "dispatcher": "influxdb", + "target": "http://127.0.0.1:8000/results", + "timeout": "20" + }, + "dispatcher_influxdb": { + "db_name": "yardstick", + "debug": "False", + "dispatcher": "influxdb", + "password": "r00t", + "target": "http://192.168.100.3:8086", + "timeout": "20", + "username": "root" + }, + "nsb": { + "bin_path": "/opt/nsb_bin", + "debug": "False", + "dispatcher": "influxdb", + "trex_client_lib": "/opt/nsb_bin/trex_client/stl", + "trex_path": "/opt/nsb_bin/trex/scripts" + } + }, + "runner_id": 1105, + "type": "Duration" + }, + "task_id": "5486cc2f-d4d3-4feb-b0df-5e0bcd584c9e", + "task_path": "samples/vnf_samples/nsut/ipsec", + "tc": "tc_baremetal_rfc2544_ipv4_1flow_sw_aesgcm_4cores_64B_trex", + "topology": "vpp-tg-topology-2.yaml", + "traffic_profile": "../../traffic_profiles/ipv4_throughput_latency_vpp.yaml", + "type": "NSPerf" + } + + context_cfg = { + "networks": {}, + "nodes": { + "tg__0": { + "VNF model": "../../vnf_descriptors/tg_vpp_tpl.yaml", + "ctx_type": "Node", + "interfaces": { + "xe0": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:00:06.0" + }, + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "xe1": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "192.168.101.2", + "dst_mac": "90:e2:ba:7c:41:a9", + "ifname": "xe1", + "local_ip": "192.168.101.1", + "local_mac": "90:e2:ba:7c:30:e9", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "192.168.101.1", + "dst_mac": "90:e2:ba:7c:30:e9", + "ifname": "xe0", + "local_ip": "192.168.101.2", + "local_mac": "90:e2:ba:7c:41:a9", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "tg__0", + "vld_id": "downlink_0", + "vpci": "0000:00:06.0" + }, + "peer_name": "vnf__1", + "vld_id": "downlink_0", + "vpci": "0000:81:00.1" + } + }, + "ip": "10.10.10.10", + "member-vnf-index": "1", + "name": "trafficgen.yardstick-5486cc2f", + "password": "r00t", + "port": 22, + "role": "TrafficGen", + "user": "root", + "username": "root", + "vnfd-id-ref": "tg__0" + }, + "vnf__0": { + "VNF model": "../../vnf_descriptors/vpp_vnfd.yaml", + "ctx_type": "Node", + "interfaces": { + "xe0": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:00:06.0" + }, + "xe1": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe1", + "peer_intf": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + } + }, + "ip": "10.10.10.101", + "member-vnf-index": "2", + "name": "vnf0.yardstick-5486cc2f", + "password": "r00t", + "port": 22, + "role": "VirtualNetworkFunction", + "user": "root", + "username": "root", + "vnfd-id-ref": "vnf__0" + }, + "vnf__1": { + "VNF model": "../../vnf_descriptors/vpp_vnfd.yaml", + "ctx_type": "Node", + "interfaces": { + "xe0": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.101.1", + "dst_mac": "90:e2:ba:7c:30:e9", + "ifname": "xe0", + "local_ip": "192.168.101.2", + "local_mac": "90:e2:ba:7c:41:a9", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_intf": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "192.168.101.2", + "dst_mac": "90:e2:ba:7c:41:a9", + "ifname": "xe1", + "local_ip": "192.168.101.1", + "local_mac": "90:e2:ba:7c:30:e9", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__1", + "vld_id": "downlink_0", + "vpci": "0000:81:00.1" + }, + "peer_name": "tg__0", + "vld_id": "downlink_0", + "vpci": "0000:00:06.0" + }, + "xe1": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_intf": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe1", + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + } + }, + "ip": "10.10.10.102", + "member-vnf-index": "3", + "name": "vnf1.yardstick-5486cc2f", + "password": "r00t", + "port": 22, + "role": "VirtualNetworkFunction", + "user": "root", + "username": "root", + "vnfd-id-ref": "vnf__1" + } + } + } + + def test___init__(self, *args): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + self.assertIsNone(vipsec_vnf._vnf_process) + + @mock.patch(SSH_HELPER) + def test__run(self, ssh, *args): + mock_ssh(ssh) + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + vipsec_vnf._build_config = mock.MagicMock() + vipsec_vnf.setup_helper.kill_vnf = mock.MagicMock() + vipsec_vnf.setup_helper.create_ipsec_tunnels = mock.MagicMock() + vipsec_vnf.queue_wrapper = mock.MagicMock() + vipsec_vnf.scenario_helper.scenario_cfg = self.scenario_cfg + vipsec_vnf.vnf_cfg = {'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': '1C/1T', + 'worker_threads': 1} + vipsec_vnf.all_options = {'traffic_type': '4', + 'topology': 'nsb_test_case.yaml'} + vipsec_vnf._run() + # vipsec_vnf.setup_helper.ssh_helper.execute.assert_called_once() + + @mock.patch(SSH_HELPER) + def test_wait_for_instantiate(self, ssh, *args): + mock_ssh(ssh) + + mock_process = mock.Mock(autospec=Process) + mock_process.is_alive.return_value = True + mock_process.exitcode = 432 + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + vipsec_vnf.resource_helper.resource = mock.MagicMock() + vipsec_vnf.setup_helper = mock.MagicMock() + vipsec_vnf.setup_helper.check_status.return_value = True + vipsec_vnf._vnf_process = mock_process + vipsec_vnf.WAIT_TIME = 0 + self.assertEqual(vipsec_vnf.wait_for_instantiate(), 432) + + @mock.patch(SSH_HELPER) + def test_wait_for_instantiate_crash(self, ssh, *args): + mock_ssh(ssh) + + mock_process = mock.Mock(autospec=Process) + mock_process.is_alive.return_value = False + mock_process.exitcode = 432 + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + vipsec_vnf.resource_helper.resource = mock.MagicMock() + vipsec_vnf.setup_helper = mock.MagicMock() + vipsec_vnf.setup_helper.check_status.return_value = False + vipsec_vnf._vnf_process = mock_process + vipsec_vnf.WAIT_TIME = 0 + vipsec_vnf.WAIT_TIME_FOR_SCRIPT = 0 + + with self.assertRaises(RuntimeError) as raised: + vipsec_vnf.wait_for_instantiate() + + self.assertIn('VNF process died', str(raised.exception)) + + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', + return_value='mock_node') + @mock.patch.object(ipsec_vnf.VipsecApproxSetupEnvHelper, + 'get_vpp_statistics', + return_value={'packets_in': 0, 'packets_fwd': 0, + 'packets_dropped': 0}) + @mock.patch(SSH_HELPER) + def test_collect_kpi(self, ssh, *args): + mock_ssh(ssh) + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + vipsec_vnf.scenario_helper.scenario_cfg = { + 'nodes': {vipsec_vnf.name: "mock"} + } + result = { + 'collect_stats': {'packets_in': 0, 'packets_fwd': 0, + 'packets_dropped': 0}, + 'physical_node': 'mock_node' + } + self.assertEqual(result, vipsec_vnf.collect_kpi()) + + @mock.patch.object(utils, 'find_relative_file') + @mock.patch( + "yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch(SSH_HELPER) + def test_instantiate(self, ssh, *args): + mock_ssh(ssh) + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + vipsec_vnf.deploy_helper = mock.MagicMock() + vipsec_vnf.resource_helper = mock.MagicMock() + vipsec_vnf._build_config = mock.MagicMock() + vipsec_vnf.WAIT_TIME = 0 + self.scenario_cfg.update({"nodes": {"vnf__1": ""}}) + self.assertIsNone(vipsec_vnf.instantiate(self.scenario_cfg, + self.context_cfg)) + + @mock.patch.object(ipsec_vnf.VipsecApproxSetupEnvHelper, 'kill_vnf', + return_value='') + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch(SSH_HELPER) + def test_terminate(self, ssh, *args): + mock_ssh(ssh) + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vipsec_vnf = ipsec_vnf.VipsecApproxVnf(NAME, vnfd) + vipsec_vnf._vnf_process = mock.MagicMock() + vipsec_vnf._vnf_process.terminate = mock.Mock() + self.assertIsNone(vipsec_vnf.terminate()) + + +class TestVipsecApproxSetupEnvHelper(unittest.TestCase): + ALL_OPTIONS = { + "flow": { + "count": 1, + "dst_ip": [ + "20.0.0.0-20.0.0.100" + ], + "src_ip": [ + "10.0.0.0-10.0.0.100" + ] + }, + "framesize": { + "downlink": { + "64B": 100 + }, + "uplink": { + "64B": 100 + } + }, + "rfc2544": { + "allowed_drop_rate": "0.0 - 0.005" + }, + "tg__0": { + "collectd": { + "interval": 1 + }, + "queues_per_port": 7 + }, + "traffic_type": 4, + "vnf__0": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vnf__1": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vpp_config": { + "crypto_algorithms": "aes-gcm", + "tunnel": 1 + } + } + + ALL_OPTIONS_CBC_ALGORITHMS = { + "flow": { + "count": 1, + "dst_ip": [ + "20.0.0.0-20.0.0.100" + ], + "src_ip": [ + "10.0.0.0-10.0.0.100" + ] + }, + "framesize": { + "downlink": { + "64B": 100 + }, + "uplink": { + "64B": 100 + } + }, + "rfc2544": { + "allowed_drop_rate": "0.0 - 0.005" + }, + "tg__0": { + "collectd": { + "interval": 1 + }, + "queues_per_port": 7 + }, + "traffic_type": 4, + "vnf__0": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vnf__1": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vpp_config": { + "crypto_algorithms": "cbc-sha1", + "tunnel": 1 + } + } + + ALL_OPTIONS_ERROR = { + "flow_error": { + "count": 1, + "dst_ip": [ + "20.0.0.0-20.0.0.100" + ], + "src_ip": [ + "10.0.0.0-10.0.0.100" + ] + }, + "framesize": { + "downlink": { + "64B": 100 + }, + "uplink": { + "64B": 100 + } + }, + "rfc2544": { + "allowed_drop_rate": "0.0 - 0.005" + }, + "tg__0": { + "collectd": { + "interval": 1 + }, + "queues_per_port": 7 + }, + "traffic_type": 4, + "vnf__0": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vnf__1": { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + }, + "vpp_config": { + "crypto_algorithms": "aes-gcm", + "tunnel": 1 + } + } + + OPTIONS = { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "SW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + } + + OPTIONS_HW = { + "collectd": { + "interval": 1 + }, + "vnf_config": { + "crypto_type": "HW_cryptodev", + "rxq": 1, + "worker_config": "1C/1T", + "worker_threads": 4 + } + } + + CPU_LAYOUT = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1, 1, 0], + [2, 1, 0, 0, 0, 2, 2, 1], + [3, 1, 0, 0, 0, 3, 3, 1], + [4, 2, 0, 0, 0, 4, 4, 2], + [5, 2, 0, 0, 0, 5, 5, 2], + [6, 3, 0, 0, 0, 6, 6, 3], + [7, 3, 0, 0, 0, 7, 7, 3], + [8, 4, 0, 0, 0, 8, 8, 4], + [9, 5, 0, 1, 0, 9, 9, 4], + [10, 6, 0, 1, 0, 10, 10, 5], + [11, 6, 0, 1, 0, 11, 11, 5], + [12, 7, 0, 1, 0, 12, 12, 6], + [13, 7, 0, 1, 0, 13, 13, 6], + [14, 8, 0, 1, 0, 14, 14, 7], + [15, 8, 0, 1, 0, 15, 15, 7], + [16, 9, 0, 1, 0, 16, 16, 8], + [17, 9, 0, 1, 0, 17, 17, 8]]} + CPU_SMT = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1, 1, 0], + [2, 1, 0, 0, 0, 2, 2, 1], + [3, 1, 0, 0, 0, 3, 3, 1], + [4, 2, 0, 0, 0, 4, 4, 2], + [5, 2, 0, 0, 0, 5, 5, 2], + [6, 3, 0, 0, 0, 6, 6, 3], + [7, 3, 0, 0, 0, 7, 7, 3], + [8, 4, 0, 0, 0, 8, 8, 4], + [9, 5, 0, 1, 0, 0, 0, 0], + [10, 6, 0, 1, 0, 1, 1, 0], + [11, 6, 0, 1, 0, 2, 2, 1], + [12, 7, 0, 1, 0, 3, 3, 1], + [13, 7, 0, 1, 0, 4, 4, 2], + [14, 8, 0, 1, 0, 5, 5, 2], + [15, 8, 0, 1, 0, 6, 6, 3], + [16, 9, 0, 1, 0, 7, 7, 3], + [17, 9, 0, 1, 0, 8, 8, 4]]} + + VPP_INTERFACES_DUMP = [ + { + "sw_if_index": 0, + "sup_sw_if_index": 0, + "l2_address_length": 0, + "l2_address": [0, 0, 0, 0, 0, 0, 0, 0], + "interface_name": "local0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 0, + "link_speed": 0, + "mtu": 0, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }, + { + "sw_if_index": 1, + "sup_sw_if_index": 1, + "l2_address_length": 6, + "l2_address": [144, 226, 186, 124, 65, 168, 0, 0], + "interface_name": "TenGigabitEthernetff/6/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9202, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }, + { + "sw_if_index": 2, + "sup_sw_if_index": 2, + "l2_address_length": 6, + "l2_address": [78, 144, 133, 211, 197, 19, 0, 0], + "interface_name": "VirtualFunctionEthernetff/7/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9206, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + } + ] + + VPP_INTERFACES_STATUS = \ + ' Name Idx State MTU (L3/IP4/IP6/MPLS)' \ + 'Counter Count \n' \ + 'TenGigabitEthernetff/6/0 1 up 9000/0/0/0 \n' \ + 'VirtualFunctionEthernetff/7/0 2 up 9000/0/0/0 \n' \ + 'ipsec0 2 up 9000/0/0/0 \n' \ + 'local0 0 down 0/0/0/0 ' + + VPP_INTERFACES_STATUS_FALSE = \ + ' Name Idx State MTU (L3/IP4/IP6/MPLS)' \ + 'Counter Count \n' \ + 'TenGigabitEthernetff/6/0 1 down 9000/0/0/0 \n' \ + 'VirtualFunctionEthernetff/7/0 2 down 9000/0/0/0 \n' \ + 'ipsec0 2 down 9000/0/0/0 \n' \ + 'local0 0 down 0/0/0/0 ' + + def test__get_crypto_type(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual('SW_cryptodev', + ipsec_approx_setup_helper._get_crypto_type()) + + def test__get_crypto_algorithms(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual('aes-gcm', + ipsec_approx_setup_helper._get_crypto_algorithms()) + + def test__get_n_tunnels(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(1, ipsec_approx_setup_helper._get_n_tunnels()) + + def test__get_n_connections(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(1, ipsec_approx_setup_helper._get_n_connections()) + + def test__get_n_connections_error(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS_ERROR + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with self.assertRaises(KeyError) as raised: + ipsec_approx_setup_helper._get_n_connections() + self.assertIn( + 'Missing flow definition in scenario section of the task definition file', + str(raised.exception)) + + def test__get_flow_src_start_ip(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual('10.0.0.0', + ipsec_approx_setup_helper._get_flow_src_start_ip()) + + def test__get_flow_src_start_ip_vnf1(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD_ERROR['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual('20.0.0.0', + ipsec_approx_setup_helper._get_flow_src_start_ip()) + + def test__get_flow_src_start_ip_error(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS_ERROR + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with self.assertRaises(KeyError) as raised: + ipsec_approx_setup_helper._get_flow_src_start_ip() + self.assertIn( + 'Missing flow definition in scenario section of the task definition file', + str(raised.exception)) + + def test__get_flow_dst_start_ip(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual('20.0.0.0', + ipsec_approx_setup_helper._get_flow_dst_start_ip()) + + def test__get_flow_dst_start_ip_vnf1(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD_ERROR['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual('10.0.0.0', + ipsec_approx_setup_helper._get_flow_dst_start_ip()) + + def test__get_flow_dst_start_ip_error(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.all_options = self.ALL_OPTIONS_ERROR + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with self.assertRaises(KeyError) as raised: + ipsec_approx_setup_helper._get_flow_dst_start_ip() + self.assertIn( + 'Missing flow definition in scenario section of the task definition file', + str(raised.exception)) + + def test_build_config(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.build_config()) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertEqual('TenGigabitEthernetff/6/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_name')) + self.assertEqual(1, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_sw_index')) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + self.assertEqual('VirtualFunctionEthernetff/7/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_name')) + self.assertEqual(2, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_sw_index')) + self.assertGreaterEqual(ssh_helper.execute.call_count, 4) + + def test_build_config_cbc_algorithms(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS_CBC_ALGORITHMS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.build_config()) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertEqual('TenGigabitEthernetff/6/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_name')) + self.assertEqual(1, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_sw_index')) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + self.assertEqual('VirtualFunctionEthernetff/7/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_name')) + self.assertEqual(2, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_sw_index')) + self.assertGreaterEqual(ssh_helper.execute.call_count, 4) + + @mock.patch.object(utils, 'setup_hugepages') + def test_setup_vnf_environment(self, *args): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.nodes = [None, None] + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + self.assertIsInstance( + ipsec_approx_setup_helper.setup_vnf_environment(), + ResourceProfile) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertEqual('TenGigabitEthernetff/6/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_name')) + self.assertEqual(1, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_sw_index')) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + self.assertEqual('VirtualFunctionEthernetff/7/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_name')) + self.assertEqual(2, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_sw_index')) + self.assertGreaterEqual(ssh_helper.execute.call_count, 4) + + @mock.patch.object(utils, 'setup_hugepages') + def test_setup_vnf_environment_hw(self, *args): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.nodes = [None, None] + scenario_helper.options = self.OPTIONS_HW + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + self.assertIsInstance( + ipsec_approx_setup_helper.setup_vnf_environment(), + ResourceProfile) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertEqual('TenGigabitEthernetff/6/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_name')) + self.assertEqual(1, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe0', 'vpp_sw_index')) + self.assertEqual(0, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + self.assertEqual('VirtualFunctionEthernetff/7/0', + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_name')) + self.assertEqual(2, + ipsec_approx_setup_helper.get_value_by_interface_key( + 'xe1', 'vpp_sw_index')) + self.assertGreaterEqual(ssh_helper.execute.call_count, 4) + + def test_calculate_frame_size(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(16984 / 48, + ipsec_approx_setup_helper.calculate_frame_size( + {'64B': 28, '570B': 16, '1518B': 4})) + + def test_calculate_frame_size_64(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(64, + ipsec_approx_setup_helper.calculate_frame_size({})) + + def test_calculate_frame_size_64_error(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(64, + ipsec_approx_setup_helper.calculate_frame_size( + {'64B': -28, '570B': 16, '1518B': 4})) + + def test_check_status(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, self.VPP_INTERFACES_STATUS, '' + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertTrue(ipsec_approx_setup_helper.check_status()) + + def test_check_status_false(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, self.VPP_INTERFACES_STATUS_FALSE, '' + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertFalse(ipsec_approx_setup_helper.check_status()) + + def test_get_vpp_statistics(self): + def execute(cmd): + if 'TenGigabitEthernetff/6/0' in cmd: + return 0, output_xe0, '' + elif 'VirtualFunctionEthernetff/7/0' in cmd: + return 0, output_xe1, '' + return 0, '0', '' + + output_xe0 = \ + ' Name Idx State MTU (L3/IP4/IP6/MPLS)' \ + ' Counter Count \n' \ + 'TenGigabitEthernetff/6/0 1 up 9200/0/0/0 ' \ + 'rx packets 23373568\n' \ + ' ' \ + 'rx bytes 1402414080\n' \ + ' ' \ + 'tx packets 20476416\n' \ + ' ' \ + 'tx bytes 1228584960\n' \ + ' ' \ + 'ip4 23373568\n' \ + ' ' \ + 'rx-miss 27789925' + output_xe1 = \ + ' Name Idx State MTU (L3/IP4/IP6/MPLS)' \ + ' Counter Count \n' \ + 'VirtualFunctionEthernetff/7/0 2 up 9200/0/0/0 ' \ + 'rx packets 23373568\n' \ + ' ' \ + 'rx bytes 1402414080\n' \ + ' ' \ + 'tx packets 20476416\n' \ + ' ' \ + 'tx bytes 1228584960\n' \ + ' ' \ + 'ip4 23373568\n' \ + ' ' \ + 'rx-miss 27789925' + + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute = execute + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertEqual({'xe0': {'packets_dropped': 27789925, + 'packets_fwd': 20476416, + 'packets_in': 23373568}, + 'xe1': {'packets_dropped': 27789925, + 'packets_fwd': 20476416, + 'packets_in': 23373568}}, + ipsec_approx_setup_helper.get_vpp_statistics()) + + def test_parser_vpp_stats(self): + output = \ + ' Name Idx State MTU (L3/IP4/IP6/MPLS)' \ + 'Counter Count \n' \ + 'TenGigabitEthernetff/6/0 1 up 9200/0/0/0 ' \ + 'rx packets 23373568\n' \ + ' ' \ + 'rx bytes 1402414080\n' \ + ' ' \ + 'tx packets 20476416\n' \ + ' ' \ + 'tx bytes 1228584960\n' \ + ' ' \ + 'ip4 23373568\n' \ + ' ' \ + 'rx-miss 27789925' + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual({'xe0': {'packets_dropped': 27789925, + 'packets_fwd': 20476416, + 'packets_in': 23373568}}, + ipsec_approx_setup_helper.parser_vpp_stats('xe0', + 'TenGigabitEthernetff/6/0', + output)) + + def test_parser_vpp_stats_no_miss(self): + output = \ + ' Name Idx State ' \ + 'Counter Count \n' \ + 'TenGigabitEthernetff/6/0 1 up ' \ + 'rx packets 23373568\n' \ + ' ' \ + 'rx bytes 1402414080\n' \ + ' ' \ + 'tx packets 20476416\n' \ + ' ' \ + 'tx bytes 1228584960\n' \ + ' ' \ + 'ip4 23373568' + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual({'xe0': {'packets_dropped': 2897152, + 'packets_fwd': 20476416, + 'packets_in': 23373568}}, + ipsec_approx_setup_helper.parser_vpp_stats('xe0', + 'TenGigabitEthernetff/6/0', + output)) + + def test_create_ipsec_tunnels(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out, \ + mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template, \ + mock.patch.object(ipsec_approx_setup_helper, + 'vpp_get_interface_data') as \ + mock_ipsec_approx_setup_helper: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + mock_vat_terminal_exec_cmd_from_template.return_value = self.VPP_INTERFACES_DUMP + mock_ipsec_approx_setup_helper.return_value = self.VPP_INTERFACES_DUMP + sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.create_ipsec_tunnels()) + self.assertGreaterEqual( + mock_vat_terminal_exec_cmd_from_template.call_count, 9) + + def test_create_ipsec_tunnels_cbc_algorithms(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS_CBC_ALGORITHMS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out, \ + mock.patch.object(ipsec_approx_setup_helper, + 'find_encrypted_data_interface') as \ + mock_find_encrypted_data_interface, \ + mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template, \ + mock.patch.object(ipsec_approx_setup_helper, + 'vpp_get_interface_data') as \ + mock_ipsec_approx_setup_helper: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + mock_find_encrypted_data_interface.return_value = { + 'dpdk_port_num': 0, + 'driver': 'igb_uio', + 'dst_ip': '192.168.100.1', + 'dst_mac': '90:e2:ba:7c:30:e8', + 'ifname': 'xe0', + 'local_ip': '192.168.100.2', + 'local_mac': '90:e2:ba:7c:41:a8', + 'netmask': '255.255.255.0', + 'network': {}, + 'node_name': 'vnf__1', + 'numa_node': 0, + 'peer_ifname': 'xe0', + 'peer_intf': {'dpdk_port_num': 0, + 'driver': 'igb_uio', + 'dst_ip': '192.168.100.2', + 'dst_mac': '90:e2:ba:7c:41:a8', + 'ifname': 'xe0', + 'local_ip': '192.168.100.1', + 'local_mac': '90:e2:ba:7c:30:e8', + 'netmask': '255.255.255.0', + 'network': {}, + 'node_name': 'tg__0', + 'peer_ifname': 'xe0', + 'peer_name': 'vnf__0', + 'vld_id': 'uplink_0', + 'vpci': '0000:81:00.0'}, + 'peer_name': 'tg__0', + 'vld_id': 'uplink_0', + 'vpci': '0000:ff:06.0', + 'vpp_name': u'TenGigabitEthernetff/6/0', + 'vpp_sw_index': 1} + mock_vat_terminal_exec_cmd_from_template.return_value = self.VPP_INTERFACES_DUMP + mock_ipsec_approx_setup_helper.return_value = self.VPP_INTERFACES_DUMP + sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.create_ipsec_tunnels()) + self.assertGreaterEqual( + mock_vat_terminal_exec_cmd_from_template.call_count, 9) + + def test_find_raw_data_interface(self): + expected = {'dpdk_port_num': 0, + 'driver': 'igb_uio', + 'dst_ip': '192.168.100.1', + 'dst_mac': '90:e2:ba:7c:30:e8', + 'ifname': 'xe0', + 'local_ip': '192.168.100.2', + 'local_mac': '90:e2:ba:7c:41:a8', + 'netmask': '255.255.255.0', + 'network': {}, + 'node_name': 'vnf__0', + 'numa_node': 0, + 'peer_ifname': 'xe0', + 'peer_intf': {'dpdk_port_num': 0, + 'driver': 'igb_uio', + 'dst_ip': '192.168.100.2', + 'dst_mac': '90:e2:ba:7c:41:a8', + 'ifname': 'xe0', + 'local_ip': '192.168.100.1', + 'local_mac': '90:e2:ba:7c:30:e8', + 'netmask': '255.255.255.0', + 'network': {}, + 'node_name': 'tg__0', + 'peer_ifname': 'xe0', + 'peer_name': 'vnf__0', + 'vld_id': 'uplink_0', + 'vpci': '0000:81:00.0'}, + 'peer_name': 'tg__0', + 'vld_id': 'uplink_0', + 'vpci': '0000:ff:06.0', + 'vpp_name': u'TenGigabitEthernetff/6/0', + 'vpp_sw_index': 1} + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(expected, + ipsec_approx_setup_helper.find_raw_data_interface()) + + def test_find_raw_data_interface_error(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD_ERROR['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + with self.assertRaises(KeyError): + ipsec_approx_setup_helper.find_raw_data_interface() + + def test_find_encrypted_data_interface(self): + expected = {'dpdk_port_num': 1, + 'driver': 'igb_uio', + 'dst_ip': '1.1.1.2', + 'dst_mac': '0a:b1:ec:fd:a2:66', + 'ifname': 'xe1', + 'local_ip': '1.1.1.1', + 'local_mac': '4e:90:85:d3:c5:13', + 'netmask': '255.255.255.0', + 'network': {}, + 'node_name': 'vnf__0', + 'numa_node': 0, + 'peer_ifname': 'xe1', + 'peer_intf': {'driver': 'igb_uio', + 'dst_ip': '1.1.1.1', + 'dst_mac': '4e:90:85:d3:c5:13', + 'ifname': 'xe1', + 'local_ip': '1.1.1.2', + 'local_mac': '0a:b1:ec:fd:a2:66', + 'netmask': '255.255.255.0', + 'network': {}, + 'node_name': 'vnf__1', + 'peer_ifname': 'xe1', + 'peer_name': 'vnf__0', + 'vld_id': 'ciphertext', + 'vpci': '0000:00:07.0'}, + 'peer_name': 'vnf__1', + 'vld_id': 'ciphertext', + 'vpci': '0000:ff:07.0', + 'vpp_name': u'VirtualFunctionEthernetff/7/0', + 'vpp_sw_index': 2} + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + self.assertEqual(expected, + ipsec_approx_setup_helper.find_encrypted_data_interface()) + + def test_create_startup_configuration_of_vpp(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsInstance( + ipsec_approx_setup_helper.create_startup_configuration_of_vpp(), + vpp_helpers.VppConfigGenerator) + + def test_add_worker_threads_and_rxqueues(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone( + ipsec_approx_setup_helper.add_worker_threads_and_rxqueues( + vpp_config_generator, 1, 1)) + self.assertEqual( + 'cpu\n{\n corelist-workers 2\n main-core 1\n}\ndpdk\n{\n ' \ + 'dev default\n {\n num-rx-queues 1\n }\n num-mbufs 32768\n}\n', + vpp_config_generator.dump_config()) + + def test_add_worker_threads_and_rxqueues_smt(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_SMT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_SMT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone( + ipsec_approx_setup_helper.add_worker_threads_and_rxqueues( + vpp_config_generator, 1)) + self.assertEqual( + 'cpu\n{\n corelist-workers 2,6\n main-core 1\n}\ndpdk\n{\n ' \ + 'dev default\n {\n num-rx-queues 1\n }\n num-mbufs 32768\n}\n', + vpp_config_generator.dump_config()) + + def test_add_worker_threads_and_rxqueues_with_numa(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone( + ipsec_approx_setup_helper.add_worker_threads_and_rxqueues( + vpp_config_generator, 1, 1)) + self.assertEqual( + 'cpu\n{\n corelist-workers 2\n main-core 1\n}\ndpdk\n{\n ' \ + 'dev default\n {\n num-rx-queues 1\n }\n num-mbufs 32768\n}\n', + vpp_config_generator.dump_config()) + + def test_add_pci_devices(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.add_pci_devices( + vpp_config_generator)) + self.assertEqual( + 'dpdk\n{\n dev 0000:ff:06.0 \n dev 0000:ff:07.0 \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_cryptodev(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.add_dpdk_cryptodev( + vpp_config_generator, 'aesni_gcm', 1)) + self.assertEqual( + 'dpdk\n{\n vdev cryptodev_aesni_gcm_pmd,socket_id=0 \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_cryptodev_hw(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS_HW + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.add_dpdk_cryptodev( + vpp_config_generator, 'aesni_gcm', 1)) + self.assertEqual( + 'dpdk\n{\n dev 0000:ff:01.0 \n uio-driver igb_uio\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_cryptodev_smt_used(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out: + mock_get_cpu_layout.return_value = self.CPU_SMT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_LAYOUT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.add_dpdk_cryptodev( + vpp_config_generator, 'aesni_gcm', 1)) + self.assertEqual( + 'dpdk\n{\n vdev cryptodev_aesni_gcm_pmd,socket_id=0 \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_cryptodev_smt_used_hw(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS_HW + scenario_helper.all_options = self.ALL_OPTIONS + vpp_config_generator = vpp_helpers.VppConfigGenerator() + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout: + mock_get_cpu_layout.return_value = self.CPU_SMT + ipsec_approx_setup_helper.sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper.sys_cores.cpuinfo = self.CPU_SMT + ipsec_approx_setup_helper._update_vnfd_helper( + ipsec_approx_setup_helper.sys_cores.get_cpu_layout()) + self.assertIsNone(ipsec_approx_setup_helper.add_dpdk_cryptodev( + vpp_config_generator, 'aesni_gcm', 1)) + self.assertEqual( + 'dpdk\n{\n dev 0000:ff:01.0 \n dev 0000:ff:01.1 \n uio-driver igb_uio\n}\n', + vpp_config_generator.dump_config()) + + def test_initialize_ipsec(self): + vnfd_helper = VnfdHelper( + TestVipsecApproxVnf.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + scenario_helper.all_options = self.ALL_OPTIONS + + ipsec_approx_setup_helper = VipsecApproxSetupEnvHelper(vnfd_helper, + ssh_helper, + scenario_helper) + + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout, \ + mock.patch.object(ipsec_approx_setup_helper, + 'execute_script_json_out') as \ + mock_execute_script_json_out, \ + mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template, \ + mock.patch.object(ipsec_approx_setup_helper, + 'vpp_get_interface_data') as \ + mock_ipsec_approx_setup_helper: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + mock_execute_script_json_out.return_value = str( + self.VPP_INTERFACES_DUMP).replace("\'", "\"") + mock_vat_terminal_exec_cmd_from_template.return_value = '' + mock_ipsec_approx_setup_helper.return_value = self.VPP_INTERFACES_DUMP + sys_cores = cpu.CpuSysCores(ssh_helper) + ipsec_approx_setup_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + ipsec_approx_setup_helper.update_vpp_interface_data() + ipsec_approx_setup_helper.iface_update_numa() + self.assertIsNone(ipsec_approx_setup_helper.initialize_ipsec()) + self.assertGreaterEqual( + mock_vat_terminal_exec_cmd_from_template.call_count, 9) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py index 9a30fb9e9..32f384027 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2018 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -2400,6 +2400,7 @@ class TestProxProfileHelper(unittest.TestCase): with helper.traffic_context(64, 1): pass + @mock.patch.object(time, 'sleep') def test_run_test(self, *args): resource_helper = mock.MagicMock() resource_helper.step_delta = 0.4 @@ -2549,6 +2550,7 @@ class TestProxBngProfileHelper(unittest.TestCase): self.assertEqual(helper.arp_task_cores, expected_arp_task) self.assertEqual(helper._cores_tuple, expected_combined) + @mock.patch.object(time, 'sleep') def test_run_test(self, *args): resource_helper = mock.MagicMock() resource_helper.step_delta = 0.4 @@ -2675,6 +2677,7 @@ class TestProxVpeProfileHelper(unittest.TestCase): self.assertEqual(helper.inet_ports, expected_inet) self.assertEqual(helper._ports_tuple, expected_combined) + @mock.patch.object(time, 'sleep') def test_run_test(self, *args): resource_helper = mock.MagicMock() resource_helper.step_delta = 0.4 @@ -2792,6 +2795,7 @@ class TestProxlwAFTRProfileHelper(unittest.TestCase): self.assertEqual(helper.inet_ports, expected_inet) self.assertEqual(helper._ports_tuple, expected_combined) + @mock.patch.object(time, 'sleep') def test_run_test(self, *args): resource_helper = mock.MagicMock() resource_helper.step_delta = 0.4 diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_irq.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_irq.py index fd6f1712c..94197c3be 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_irq.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_irq.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2018 Intel Corporation +# Copyright (c) 2017-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py index de436a46e..76fd74dfe 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py index 3e21392be..b8f3fcaca 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index 405eeceb7..8aa59ccd1 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2018 Intel Corporation +# Copyright (c) 2017-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,24 +16,22 @@ from copy import deepcopy import unittest import mock +import six +import time +import subprocess import paramiko from yardstick.common import exceptions as y_exceptions from yardstick.common import utils -from yardstick.network_services.nfvi.resource import ResourceProfile -from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper +from yardstick.network_services.nfvi import resource +from yardstick.network_services.vnf_generic.vnf import base from yardstick.network_services.vnf_generic.vnf import sample_vnf from yardstick.network_services.vnf_generic.vnf import vnf_ssh_helper -from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFDeployHelper -from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper from yardstick.network_services.vnf_generic.vnf.sample_vnf import ResourceHelper -from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper -from yardstick.network_services.vnf_generic.vnf.sample_vnf import Rfc2544ResourceHelper from yardstick.network_services.vnf_generic.vnf.sample_vnf import SetupEnvHelper from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen -from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper from yardstick.tests.unit.network_services.vnf_generic.vnf import test_base from yardstick.benchmark.contexts import base as ctx_base from yardstick import ssh @@ -363,123 +361,24 @@ class TestSetupEnvHelper(unittest.TestCase): class TestDpdkVnfSetupEnvHelper(unittest.TestCase): - VNFD_0 = { - 'short-name': 'VpeVnf', - 'vdu': [ - { - 'routing_table': [ - { - 'network': '152.16.100.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'if': 'xe0' - }, - { - 'network': '152.16.40.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'if': 'xe1' - }, - ], - 'description': 'VPE approximation using DPDK', - 'name': 'vpevnf-baremetal', - 'nd_route_tbl': [ - { - 'network': '0064:ff9b:0:0:0:0:9810:6414', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0' - }, - { - 'network': '0064:ff9b:0:0:0:0:9810:2814', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1' - }, - ], - 'id': 'vpevnf-baremetal', - 'external-interface': [ - { - 'virtual-interface': { - 'dst_mac': '00:00:00:00:00:03', - 'vpci': '0000:05:00.0', - 'dpdk_port_num': 0, - 'driver': 'i40e', - 'local_ip': '152.16.100.19', - 'type': 'PCI-PASSTHROUGH', - 'netmask': '255.255.255.0', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.100.20', - 'local_mac': '00:00:00:00:00:01', - 'vld_id': 'uplink_0', - 'ifname': 'xe0', - }, - 'vnfd-connection-point-ref': 'xe0', - 'name': 'xe0' - }, - { - 'virtual-interface': { - 'dst_mac': '00:00:00:00:00:04', - 'vpci': '0000:05:00.1', - 'dpdk_port_num': 1, - 'driver': 'ixgbe', - 'local_ip': '152.16.40.19', - 'type': 'PCI-PASSTHROUGH', - 'netmask': '255.255.255.0', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.40.20', - 'local_mac': '00:00:00:00:00:02', - 'vld_id': 'downlink_0', - 'ifname': 'xe1', - }, - 'vnfd-connection-point-ref': 'xe1', - 'name': 'xe1' - }, - ], - }, - ], - 'description': 'Vpe approximation using DPDK', - 'mgmt-interface': { - 'vdu-id': 'vpevnf-baremetal', - 'host': '1.1.1.1', - 'password': 'r00t', - 'user': 'root', - 'ip': '1.1.1.1' - }, - 'benchmark': { - 'kpi': [ - 'packets_in', - 'packets_fwd', - 'packets_dropped', - ], - }, - 'connection-point': [ - { - 'type': 'VPORT', - 'name': 'xe0', - }, - { - 'type': 'VPORT', - 'name': 'xe1', - }, - ], - 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh' - } + VNFD_0 = TestVnfSshHelper.VNFD_0 - VNFD = { - 'vnfd:vnfd-catalog': { - 'vnfd': [ - VNFD_0, - ] - } - } + VNFD = TestVnfSshHelper.VNFD + + def setUp(self): + self.vnfd_helper = base.VnfdHelper(deepcopy(self.VNFD_0)) + self.scenario_helper = mock.Mock() + self.ssh_helper = mock.Mock() + self.dpdk_setup_helper = sample_vnf.DpdkVnfSetupEnvHelper( + self.vnfd_helper, self.ssh_helper, self.scenario_helper) def test__update_packet_type(self): ip_pipeline_cfg = 'pkt_type = ipv4' pkt_type = {'pkt_type': '1'} expected = "pkt_type = 1" - result = DpdkVnfSetupEnvHelper._update_packet_type(ip_pipeline_cfg, pkt_type) + result = self.dpdk_setup_helper._update_packet_type( + ip_pipeline_cfg, pkt_type) self.assertEqual(result, expected) def test__update_packet_type_no_op(self): @@ -487,91 +386,99 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): pkt_type = {'pkt_type': '1'} expected = "pkt_type = ipv6" - result = DpdkVnfSetupEnvHelper._update_packet_type(ip_pipeline_cfg, pkt_type) + result = self.dpdk_setup_helper._update_packet_type( + ip_pipeline_cfg, pkt_type) self.assertEqual(result, expected) def test__update_packet_type_multi_op(self): ip_pipeline_cfg = 'pkt_type = ipv4\npkt_type = 1\npkt_type = ipv4' pkt_type = {'pkt_type': '1'} - expected = 'pkt_type = 1\npkt_type = 1\npkt_type = 1' - result = DpdkVnfSetupEnvHelper._update_packet_type(ip_pipeline_cfg, pkt_type) + + result = self.dpdk_setup_helper._update_packet_type( + ip_pipeline_cfg, pkt_type) self.assertEqual(result, expected) def test__update_traffic_type(self): ip_pipeline_cfg = 'pkt_type = ipv4' - - traffic_options = {"vnf_type": DpdkVnfSetupEnvHelper.APP_NAME, 'traffic_type': 4} + traffic_options = { + "vnf_type": sample_vnf.DpdkVnfSetupEnvHelper.APP_NAME, + "traffic_type": 4} expected = "pkt_type = ipv4" - result = DpdkVnfSetupEnvHelper._update_traffic_type(ip_pipeline_cfg, traffic_options) + + result = self.dpdk_setup_helper._update_traffic_type( + ip_pipeline_cfg, traffic_options) self.assertEqual(result, expected) def test__update_traffic_type_ipv6(self): ip_pipeline_cfg = 'pkt_type = ipv4' - - traffic_options = {"vnf_type": DpdkVnfSetupEnvHelper.APP_NAME, 'traffic_type': 6} + traffic_options = { + "vnf_type": sample_vnf.DpdkVnfSetupEnvHelper.APP_NAME, + "traffic_type": 6} expected = "pkt_type = ipv6" - result = DpdkVnfSetupEnvHelper._update_traffic_type(ip_pipeline_cfg, traffic_options) + + result = self.dpdk_setup_helper._update_traffic_type( + ip_pipeline_cfg, traffic_options) self.assertEqual(result, expected) def test__update_traffic_type_not_app_name(self): ip_pipeline_cfg = 'traffic_type = 4' - - vnf_type = ''.join(["Not", DpdkVnfSetupEnvHelper.APP_NAME]) + vnf_type = ''.join(["Not", sample_vnf.DpdkVnfSetupEnvHelper.APP_NAME]) traffic_options = {"vnf_type": vnf_type, 'traffic_type': 8} expected = "traffic_type = 8" - result = DpdkVnfSetupEnvHelper._update_traffic_type(ip_pipeline_cfg, traffic_options) + + result = self.dpdk_setup_helper._update_traffic_type( + ip_pipeline_cfg, traffic_options) self.assertEqual(result, expected) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open') + @mock.patch.object(six.moves.builtins, 'open') @mock.patch.object(utils, 'find_relative_file') - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig') - @mock.patch.object(utils, 'open_relative_file') - def test_build_config(self, mock_open_rf, mock_multi_port_config_class, mock_find, *args): + @mock.patch.object(sample_vnf, 'MultiPortConfig') + def test_build_config(self, mock_multi_port_config_class, + mock_find, *args): mock_multi_port_config = mock_multi_port_config_class() - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - scenario_helper.vnf_cfg = {} - scenario_helper.options = {} - scenario_helper.all_options = {} - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) + self.scenario_helper.vnf_cfg = {} + self.scenario_helper.options = {} + self.scenario_helper.all_options = {} - dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command' - result = dpdk_setup_helper.build_config() + self.dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command' + result = self.dpdk_setup_helper.build_config() self.assertEqual(result, expected) - self.assertGreaterEqual(ssh_helper.upload_config_file.call_count, 2) + self.assertGreaterEqual(self.ssh_helper.upload_config_file.call_count, 2) mock_find.assert_called() mock_multi_port_config.generate_config.assert_called() mock_multi_port_config.generate_script.assert_called() - scenario_helper.options = {'rules': 'fake_file'} - scenario_helper.vnf_cfg = {'file': 'fake_file'} - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) + @mock.patch.object(six.moves.builtins, 'open') + @mock.patch.object(utils, 'find_relative_file') + @mock.patch.object(sample_vnf, 'MultiPortConfig') + @mock.patch.object(utils, 'open_relative_file') + def test_build_config2(self, mock_open_rf, mock_multi_port_config_class, + mock_find, *args): + mock_multi_port_config = mock_multi_port_config_class() + self.scenario_helper.options = {'rules': 'fake_file'} + self.scenario_helper.vnf_cfg = {'file': 'fake_file'} + self.scenario_helper.all_options = {} mock_open_rf.side_effect = mock.mock_open(read_data='fake_data') - dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command' + self.dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command' - result = dpdk_setup_helper.build_config() + result = self.dpdk_setup_helper.build_config() mock_open_rf.assert_called() self.assertEqual(result, expected) - self.assertGreaterEqual(ssh_helper.upload_config_file.call_count, 2) + self.assertGreaterEqual(self.ssh_helper.upload_config_file.call_count, 2) mock_find.assert_called() mock_multi_port_config.generate_config.assert_called() mock_multi_port_config.generate_script.assert_called() def test__build_pipeline_kwargs(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.provision_tool.return_value = 'tool_path' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.CFG_CONFIG = 'config' - dpdk_setup_helper.CFG_SCRIPT = 'script' - dpdk_setup_helper.pipeline_kwargs = {} - dpdk_setup_helper.all_ports = [0, 1, 2] - dpdk_setup_helper.scenario_helper.vnf_cfg = {'lb_config': 'HW', - 'worker_threads': 1} + self.ssh_helper.provision_tool.return_value = 'tool_path' + self.dpdk_setup_helper.CFG_CONFIG = 'config' + self.dpdk_setup_helper.CFG_SCRIPT = 'script' + self.dpdk_setup_helper.pipeline_kwargs = {} + self.dpdk_setup_helper.all_ports = [0, 1, 2] + self.dpdk_setup_helper.scenario_helper.vnf_cfg = {'lb_config': 'HW', + 'worker_threads': 1} expected = { 'cfg_file': 'config', @@ -580,12 +487,14 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): 'tool_path': 'tool_path', 'hwlb': ' --hwlb 1', } - dpdk_setup_helper._build_pipeline_kwargs() - self.assertDictEqual(dpdk_setup_helper.pipeline_kwargs, expected) + self.dpdk_setup_helper._build_pipeline_kwargs() + self.assertDictEqual(self.dpdk_setup_helper.pipeline_kwargs, expected) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('yardstick.ssh.SSH') + @mock.patch.object(time, 'sleep') + @mock.patch.object(ssh, 'SSH') def test_setup_vnf_environment(self, *args): + self.scenario_helper.nodes = [None, None] + def execute(cmd): if cmd.startswith('which '): return exec_failure @@ -593,104 +502,82 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): exec_success = (0, 'good output', '') exec_failure = (1, 'bad output', 'error output') + self.ssh_helper.execute = execute - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute = execute + self.dpdk_setup_helper._validate_cpu_cfg = mock.Mock(return_value=[]) - scenario_helper = mock.Mock() - scenario_helper.nodes = [None, None] - dpdk_vnf_setup_env_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_vnf_setup_env_helper._validate_cpu_cfg = mock.Mock(return_value=[]) - - with mock.patch.object(dpdk_vnf_setup_env_helper, '_setup_dpdk'): + with mock.patch.object(self.dpdk_setup_helper, '_setup_dpdk'): self.assertIsInstance( - dpdk_vnf_setup_env_helper.setup_vnf_environment(), - ResourceProfile) + self.dpdk_setup_helper.setup_vnf_environment(), + resource.ResourceProfile) @mock.patch.object(utils, 'setup_hugepages') def test__setup_dpdk(self, mock_setup_hugepages): - ssh_helper = mock.Mock() - ssh_helper.execute = mock.Mock() - ssh_helper.execute.return_value = (0, 0, 0) - scenario_helper = mock.Mock() - scenario_helper.all_options = {'hugepages_gb': 8} - dpdk_setup_helper = DpdkVnfSetupEnvHelper(mock.ANY, ssh_helper, - scenario_helper) - dpdk_setup_helper._setup_dpdk() - mock_setup_hugepages.assert_called_once_with(ssh_helper, 8*1024*1024) - ssh_helper.execute.assert_has_calls([ + self.ssh_helper.execute = mock.Mock() + self.ssh_helper.execute.return_value = (0, 0, 0) + self.scenario_helper.all_options = {'hugepages_gb': 8} + self.dpdk_setup_helper._setup_dpdk() + mock_setup_hugepages.assert_called_once_with( + self.ssh_helper, 8*1024*1024) + self.ssh_helper.execute.assert_has_calls([ mock.call('sudo modprobe uio && sudo modprobe igb_uio'), mock.call('lsmod | grep -i igb_uio') ]) - @mock.patch('yardstick.ssh.SSH') + @mock.patch.object(ssh, 'SSH') def test__setup_resources(self, _): - vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._validate_cpu_cfg = mock.Mock() - - dpdk_setup_helper.bound_pci = [v['virtual-interface']["vpci"] for v in - vnfd_helper.interfaces] - result = dpdk_setup_helper._setup_resources() - self.assertIsInstance(result, ResourceProfile) - self.assertEqual(dpdk_setup_helper.socket, 0) - - @mock.patch('yardstick.ssh.SSH') + self.dpdk_setup_helper._validate_cpu_cfg = mock.Mock() + self.dpdk_setup_helper.bound_pci = [v['virtual-interface']["vpci"] for v in + self.vnfd_helper.interfaces] + result = self.dpdk_setup_helper._setup_resources() + self.assertIsInstance(result, resource.ResourceProfile) + self.assertEqual(self.dpdk_setup_helper.socket, 0) + + @mock.patch.object(ssh, 'SSH') def test__setup_resources_socket_1(self, _): - vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) - vnfd_helper.interfaces[0]['virtual-interface']['vpci'] = '0000:55:00.0' - vnfd_helper.interfaces[1]['virtual-interface']['vpci'] = '0000:35:00.0' - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._validate_cpu_cfg = mock.Mock() - - dpdk_setup_helper.bound_pci = [v['virtual-interface']["vpci"] for v in - vnfd_helper.interfaces] - result = dpdk_setup_helper._setup_resources() - self.assertIsInstance(result, ResourceProfile) - self.assertEqual(dpdk_setup_helper.socket, 1) - - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') + self.vnfd_helper.interfaces[0]['virtual-interface']['vpci'] = \ + '0000:55:00.0' + self.vnfd_helper.interfaces[1]['virtual-interface']['vpci'] = \ + '0000:35:00.0' + + self.dpdk_setup_helper._validate_cpu_cfg = mock.Mock() + self.dpdk_setup_helper.bound_pci = [v['virtual-interface']["vpci"] for v in + self.vnfd_helper.interfaces] + result = self.dpdk_setup_helper._setup_resources() + self.assertIsInstance(result, resource.ResourceProfile) + self.assertEqual(self.dpdk_setup_helper.socket, 1) + + @mock.patch.object(time, 'sleep') def test__detect_and_bind_drivers(self, *args): - vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) - ssh_helper = mock.Mock() - # ssh_helper.execute = mock.Mock(return_value = (0, 'text', '')) - # ssh_helper.execute.return_value = 0, 'output', '' - scenario_helper = mock.Mock() - scenario_helper.nodes = [None, None] + self.scenario_helper.nodes = [None, None] rv = ['0000:05:00.1', '0000:05:00.0'] - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.dpdk_bind_helper._get_bound_pci_addresses = mock.Mock(return_value=rv) - dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock() - dpdk_setup_helper.dpdk_bind_helper.read_status = mock.Mock() + self.dpdk_setup_helper.dpdk_bind_helper._get_bound_pci_addresses = \ + mock.Mock(return_value=rv) + self.dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock() + self.dpdk_setup_helper.dpdk_bind_helper.read_status = mock.Mock() - self.assertIsNone(dpdk_setup_helper._detect_and_bind_drivers()) + self.assertIsNone(self.dpdk_setup_helper._detect_and_bind_drivers()) - intf_0 = vnfd_helper.vdu[0]['external-interface'][0]['virtual-interface'] - intf_1 = vnfd_helper.vdu[0]['external-interface'][1]['virtual-interface'] + intf_0 = self.vnfd_helper.vdu[0]['external-interface'][0]['virtual-interface'] + intf_1 = self.vnfd_helper.vdu[0]['external-interface'][1]['virtual-interface'] self.assertEqual(0, intf_0['dpdk_port_num']) self.assertEqual(1, intf_1['dpdk_port_num']) def test_tear_down(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - scenario_helper.nodes = [None, None] - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock() - dpdk_setup_helper.dpdk_bind_helper.used_drivers = { + self.scenario_helper.nodes = [None, None] + + self.dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock() + self.dpdk_setup_helper.dpdk_bind_helper.used_drivers = { 'd1': ['0000:05:00.0'], 'd3': ['0000:05:01.0'], } - self.assertIsNone(dpdk_setup_helper.tear_down()) - dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call(['0000:05:00.0'], 'd1', True) - dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call(['0000:05:01.0'], 'd3', True) + self.assertIsNone(self.dpdk_setup_helper.tear_down()) + self.dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call( + ['0000:05:00.0'], 'd1', True) + self.dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call( + ['0000:05:01.0'], 'd3', True) class TestResourceHelper(unittest.TestCase): @@ -794,46 +681,33 @@ class TestResourceHelper(unittest.TestCase): 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh' } + def setUp(self): + self.vnfd_helper = base.VnfdHelper(self.VNFD_0) + self.dpdk_setup_helper = sample_vnf.DpdkVnfSetupEnvHelper( + self.vnfd_helper, mock.Mock(), mock.Mock()) + self.resource_helper = sample_vnf.ResourceHelper(self.dpdk_setup_helper) + def test_setup(self): resource = object() - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.setup_vnf_environment = mock.Mock(return_value=resource) - resource_helper = ResourceHelper(dpdk_setup_helper) + self.dpdk_setup_helper.setup_vnf_environment = ( + mock.Mock(return_value=resource)) + resource_helper = sample_vnf.ResourceHelper(self.dpdk_setup_helper) self.assertIsNone(resource_helper.setup()) self.assertIs(resource_helper.resource, resource) def test_generate_cfg(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - resource_helper = ResourceHelper(dpdk_setup_helper) - - self.assertIsNone(resource_helper.generate_cfg()) + self.assertIsNone(self.resource_helper.generate_cfg()) def test_stop_collect(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - resource_helper = ResourceHelper(dpdk_setup_helper) - resource_helper.resource = mock.Mock() + self.resource_helper.resource = mock.Mock() - self.assertIsNone(resource_helper.stop_collect()) + self.assertIsNone(self.resource_helper.stop_collect()) def test_stop_collect_none(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - resource_helper = ResourceHelper(dpdk_setup_helper) - resource_helper.resource = None + self.resource_helper.resource = None - self.assertIsNone(resource_helper.stop_collect()) + self.assertIsNone(self.resource_helper.stop_collect()) class TestClientResourceHelper(unittest.TestCase): @@ -965,102 +839,75 @@ class TestClientResourceHelper(unittest.TestCase): }, } - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG') - @mock.patch.object(sample_vnf, 'STLError', new_callable=lambda: MockError) - def test_get_stats_not_connected(self, mock_stl_error, *args): - vnfd_helper = VnfdHelper(self.VNFD_0) + def setUp(self): + vnfd_helper = base.VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper( + dpdk_setup_helper = sample_vnf.DpdkVnfSetupEnvHelper( vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) - client_resource_helper.client = mock.Mock() - client_resource_helper.client.get_stats.side_effect = mock_stl_error + self.client_resource_helper = ( + sample_vnf.ClientResourceHelper(dpdk_setup_helper)) - self.assertEqual(client_resource_helper.get_stats(), {}) - client_resource_helper.client.get_stats.assert_called_once() + @mock.patch.object(sample_vnf, 'LOG') + @mock.patch.object(sample_vnf, 'STLError', new_callable=lambda: MockError) + def test_get_stats_not_connected(self, mock_stl_error, *args): + self.client_resource_helper.client = mock.Mock() + self.client_resource_helper.client.get_stats.side_effect = \ + mock_stl_error + + self.assertEqual(self.client_resource_helper.get_stats(), {}) + self.client_resource_helper.client.get_stats.assert_called_once() def test_clear_stats(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper( - vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) - client_resource_helper.client = mock.Mock() + self.client_resource_helper.client = mock.Mock() - self.assertIsNone(client_resource_helper.clear_stats()) + self.assertIsNone(self.client_resource_helper.clear_stats()) self.assertEqual( - client_resource_helper.client.clear_stats.call_count, 1) + self.client_resource_helper.client.clear_stats.call_count, 1) def test_clear_stats_of_ports(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper( - vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) - client_resource_helper.client = mock.Mock() + self.client_resource_helper.client = mock.Mock() - self.assertIsNone(client_resource_helper.clear_stats([3, 4])) - self.assertEqual( - client_resource_helper.client.clear_stats.call_count, 1) + self.assertIsNone(self.client_resource_helper.clear_stats([3, 4])) + self.client_resource_helper.client.clear_stats.assert_called_once() def test_start(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper( - vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) - client_resource_helper.client = mock.Mock() + self.client_resource_helper.client = mock.Mock() - self.assertIsNone(client_resource_helper.start()) - client_resource_helper.client.start.assert_called_once() + self.assertIsNone(self.client_resource_helper.start()) + self.client_resource_helper.client.start.assert_called_once() def test_start_ports(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper( - vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) - client_resource_helper.client = mock.Mock() + self.client_resource_helper.client = mock.Mock() - self.assertIsNone(client_resource_helper.start([3, 4])) - client_resource_helper.client.start.assert_called_once() + self.assertIsNone(self.client_resource_helper.start([3, 4])) + self.client_resource_helper.client.start.assert_called_once() def test_collect_kpi_with_queue(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) - client_resource_helper._result = {'existing': 43, 'replaceable': 12} - client_resource_helper._queue = mock.Mock() - client_resource_helper._queue.empty.return_value = False - client_resource_helper._queue.get.return_value = {'incoming': 34, 'replaceable': 99} + self.client_resource_helper._result = { + 'existing': 43, + 'replaceable': 12} + self.client_resource_helper._queue = mock.Mock() + self.client_resource_helper._queue.empty.return_value = False + self.client_resource_helper._queue.get.return_value = { + 'incoming': 34, + 'replaceable': 99} expected = { 'existing': 43, 'incoming': 34, 'replaceable': 99, } - result = client_resource_helper.collect_kpi() - self.assertDictEqual(result, expected) + result = self.client_resource_helper.collect_kpi() + self.assertEqual(result, expected) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') + @mock.patch.object(time, 'sleep') @mock.patch.object(sample_vnf, 'STLError') def test__connect_with_failures(self, mock_stl_error, *args): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - client_resource_helper = ClientResourceHelper(dpdk_setup_helper) client = mock.MagicMock() client.connect.side_effect = mock_stl_error(msg='msg') - self.assertIs(client_resource_helper._connect(client), client) + self.assertIs(self.client_resource_helper._connect(client), client) class TestRfc2544ResourceHelper(unittest.TestCase): @@ -1107,185 +954,170 @@ class TestRfc2544ResourceHelper(unittest.TestCase): } } - def test_property_rfc2544(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + def setUp(self): + self.scenario_helper = sample_vnf.ScenarioHelper('name1') + self.rfc2544_resource_helper = \ + sample_vnf.Rfc2544ResourceHelper(self.scenario_helper) - self.assertIsNone(rfc2544_resource_helper._rfc2544) - self.assertDictEqual(rfc2544_resource_helper.rfc2544, self.RFC2544_CFG_1) - self.assertDictEqual(rfc2544_resource_helper._rfc2544, self.RFC2544_CFG_1) - scenario_helper.scenario_cfg = {} # ensure that resource_helper caches - self.assertDictEqual(rfc2544_resource_helper.rfc2544, self.RFC2544_CFG_1) + def test_property_rfc2544(self): + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 + + self.assertIsNone(self.rfc2544_resource_helper._rfc2544) + self.assertEqual(self.rfc2544_resource_helper.rfc2544, + self.RFC2544_CFG_1) + self.assertEqual(self.rfc2544_resource_helper._rfc2544, + self.RFC2544_CFG_1) + # ensure that resource_helper caches + self.scenario_helper.scenario_cfg = {} + self.assertEqual(self.rfc2544_resource_helper.rfc2544, + self.RFC2544_CFG_1) def test_property_tolerance_high(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - self.assertIsNone(rfc2544_resource_helper._tolerance_high) - self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.15) - self.assertEqual(rfc2544_resource_helper._tolerance_high, 0.15) - self.assertEqual(rfc2544_resource_helper._tolerance_precision, 2) - scenario_helper.scenario_cfg = {} # ensure that resource_helper caches - self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.15) + self.assertIsNone(self.rfc2544_resource_helper._tolerance_high) + self.assertEqual(self.rfc2544_resource_helper.tolerance_high, 0.15) + self.assertEqual(self.rfc2544_resource_helper._tolerance_high, 0.15) + self.assertEqual(self.rfc2544_resource_helper._tolerance_precision, 2) + # ensure that resource_helper caches + self.scenario_helper.scenario_cfg = {} + self.assertEqual(self.rfc2544_resource_helper.tolerance_high, 0.15) def test_property_tolerance_low(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - self.assertIsNone(rfc2544_resource_helper._tolerance_low) - self.assertEqual(rfc2544_resource_helper.tolerance_low, 0.1) - self.assertEqual(rfc2544_resource_helper._tolerance_low, 0.1) - scenario_helper.scenario_cfg = {} # ensure that resource_helper caches - self.assertEqual(rfc2544_resource_helper.tolerance_low, 0.1) + self.assertIsNone(self.rfc2544_resource_helper._tolerance_low) + self.assertEqual(self.rfc2544_resource_helper.tolerance_low, 0.1) + self.assertEqual(self.rfc2544_resource_helper._tolerance_low, 0.1) + # ensure that resource_helper caches + self.scenario_helper.scenario_cfg = {} + self.assertEqual(self.rfc2544_resource_helper.tolerance_low, 0.1) def test_property_tolerance_high_range_swap(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.25) + self.assertEqual(self.rfc2544_resource_helper.tolerance_high, 0.25) def test_property_tolerance_low_range_swap(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - self.assertEqual(rfc2544_resource_helper.tolerance_low, 0.05) + self.assertEqual(self.rfc2544_resource_helper.tolerance_low, 0.05) def test_property_tolerance_high_not_range(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_3 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_3 - self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.2) - self.assertEqual(rfc2544_resource_helper._tolerance_precision, 1) + self.assertEqual(self.rfc2544_resource_helper.tolerance_high, 0.2) + self.assertEqual(self.rfc2544_resource_helper._tolerance_precision, 1) def test_property_tolerance_low_not_range(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_3 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_3 - self.assertEqual(rfc2544_resource_helper.tolerance_low, 0.2) + self.assertEqual(self.rfc2544_resource_helper.tolerance_low, 0.2) def test_property_tolerance_high_default(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_4 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_4 - self.assertEqual(rfc2544_resource_helper.tolerance_high, 0.0001) + self.assertEqual(self.rfc2544_resource_helper.tolerance_high, 0.0001) def test_property_tolerance_low_default(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_4 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_4 - self.assertEqual(rfc2544_resource_helper.tolerance_low, 0.0001) + self.assertEqual(self.rfc2544_resource_helper.tolerance_low, 0.0001) def test_property_latency(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - self.assertIsNone(rfc2544_resource_helper._latency) - self.assertTrue(rfc2544_resource_helper.latency) - self.assertTrue(rfc2544_resource_helper._latency) - scenario_helper.scenario_cfg = {} # ensure that resource_helper caches - self.assertTrue(rfc2544_resource_helper.latency) + self.assertIsNone(self.rfc2544_resource_helper._latency) + self.assertTrue(self.rfc2544_resource_helper.latency) + self.assertTrue(self.rfc2544_resource_helper._latency) + # ensure that resource_helper caches + self.scenario_helper.scenario_cfg = {} + self.assertTrue(self.rfc2544_resource_helper.latency) def test_property_latency_default(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - self.assertFalse(rfc2544_resource_helper.latency) + self.assertFalse(self.rfc2544_resource_helper.latency) def test_property_correlated_traffic(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_1 - self.assertIsNone(rfc2544_resource_helper._correlated_traffic) - self.assertTrue(rfc2544_resource_helper.correlated_traffic) - self.assertTrue(rfc2544_resource_helper._correlated_traffic) - scenario_helper.scenario_cfg = {} # ensure that resource_helper caches - self.assertTrue(rfc2544_resource_helper.correlated_traffic) + self.assertIsNone(self.rfc2544_resource_helper._correlated_traffic) + self.assertTrue(self.rfc2544_resource_helper.correlated_traffic) + self.assertTrue(self.rfc2544_resource_helper._correlated_traffic) + # ensure that resource_helper caches + self.scenario_helper.scenario_cfg = {} + self.assertTrue(self.rfc2544_resource_helper.correlated_traffic) def test_property_correlated_traffic_default(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - rfc2544_resource_helper = Rfc2544ResourceHelper(scenario_helper) + self.scenario_helper.scenario_cfg = self.SCENARIO_CFG_2 - self.assertFalse(rfc2544_resource_helper.correlated_traffic) + self.assertFalse(self.rfc2544_resource_helper.correlated_traffic) class TestSampleVNFDeployHelper(unittest.TestCase): - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('subprocess.check_output') - def test_deploy_vnfs_disabled(self, *_): - vnfd_helper = mock.Mock() - ssh_helper = mock.Mock() - ssh_helper.join_bin_path.return_value = 'joined_path' - ssh_helper.execute.return_value = 1, 'bad output', 'error output' - ssh_helper.put.return_value = None - sample_vnf_deploy_helper = SampleVNFDeployHelper(vnfd_helper, ssh_helper) - - self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1')) - sample_vnf_deploy_helper.DISABLE_DEPLOY = True - self.assertEqual(ssh_helper.execute.call_count, 5) - ssh_helper.put.assert_called_once() - - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('subprocess.check_output') - def test_deploy_vnfs(self, *args): - vnfd_helper = mock.Mock() - ssh_helper = mock.Mock() - ssh_helper.join_bin_path.return_value = 'joined_path' - ssh_helper.execute.return_value = 1, 'bad output', 'error output' - ssh_helper.put.return_value = None - sample_vnf_deploy_helper = SampleVNFDeployHelper(vnfd_helper, ssh_helper) - sample_vnf_deploy_helper.DISABLE_DEPLOY = False - - self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1')) - self.assertEqual(ssh_helper.execute.call_count, 5) - ssh_helper.put.assert_called_once() - - @mock.patch('subprocess.check_output') - def test_deploy_vnfs_early_success(self, *args): - vnfd_helper = mock.Mock() - ssh_helper = mock.Mock() - ssh_helper.join_bin_path.return_value = 'joined_path' - ssh_helper.execute.return_value = 0, 'output', '' - ssh_helper.put.return_value = None - sample_vnf_deploy_helper = SampleVNFDeployHelper(vnfd_helper, ssh_helper) - sample_vnf_deploy_helper.DISABLE_DEPLOY = False + def setUp(self): + self._mock_time_sleep = mock.patch.object(time, 'sleep') + self.mock_time_sleep = self._mock_time_sleep.start() + self._mock_check_output = mock.patch.object(subprocess, 'check_output') + self.mock_check_output = self._mock_check_output.start() + self.addCleanup(self._stop_mocks) + + self.ssh_helper = mock.Mock() + self.sample_vnf_deploy_helper = sample_vnf.SampleVNFDeployHelper( + mock.Mock(), self.ssh_helper) + self.ssh_helper.join_bin_path.return_value = 'joined_path' + self.ssh_helper.put.return_value = None + + def _stop_mocks(self): + self._mock_time_sleep.stop() + self._mock_check_output.stop() + + def test_deploy_vnfs_disabled(self): + self.ssh_helper.execute.return_value = 1, 'bad output', 'error output' - self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1')) - ssh_helper.execute.assert_called_once() - ssh_helper.put.assert_not_called() + self.sample_vnf_deploy_helper.deploy_vnfs('name1') + self.sample_vnf_deploy_helper.DISABLE_DEPLOY = True + self.assertEqual(self.ssh_helper.execute.call_count, 5) + self.ssh_helper.put.assert_called_once() + + def test_deploy_vnfs(self): + self.ssh_helper.execute.return_value = 1, 'bad output', 'error output' + self.sample_vnf_deploy_helper.DISABLE_DEPLOY = False + + self.sample_vnf_deploy_helper.deploy_vnfs('name1') + self.assertEqual(self.ssh_helper.execute.call_count, 5) + self.ssh_helper.put.assert_called_once() + + def test_deploy_vnfs_early_success(self): + self.ssh_helper.execute.return_value = 0, 'output', '' + self.sample_vnf_deploy_helper.DISABLE_DEPLOY = False + + self.sample_vnf_deploy_helper.deploy_vnfs('name1') + self.ssh_helper.execute.assert_called_once() + self.ssh_helper.put.assert_not_called() class TestScenarioHelper(unittest.TestCase): + def setUp(self): + self.scenario_helper = sample_vnf.ScenarioHelper('name1') + def test_property_task_path(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'task_path': 'my_path', } - self.assertEqual(scenario_helper.task_path, 'my_path') + self.assertEqual(self.scenario_helper.task_path, 'my_path') def test_property_nodes(self): nodes = ['node1', 'node2'] - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'nodes': nodes, } - self.assertEqual(scenario_helper.nodes, nodes) + self.assertEqual(self.scenario_helper.nodes, nodes) def test_property_all_options(self): data = { @@ -1294,30 +1126,27 @@ class TestScenarioHelper(unittest.TestCase): }, 'name2': {} } - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'options': data, } - self.assertDictEqual(scenario_helper.all_options, data) + self.assertDictEqual(self.scenario_helper.all_options, data) def test_property_options(self): data = { 'key1': 'value1', 'key2': 'value2', } - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'options': { 'name1': data, }, } - self.assertDictEqual(scenario_helper.options, data) + self.assertDictEqual(self.scenario_helper.options, data) def test_property_vnf_cfg(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'options': { 'name1': { 'vnf_config': 'my_config', @@ -1325,25 +1154,24 @@ class TestScenarioHelper(unittest.TestCase): }, } - self.assertEqual(scenario_helper.vnf_cfg, 'my_config') + self.assertEqual(self.scenario_helper.vnf_cfg, 'my_config') def test_property_vnf_cfg_default(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'options': { 'name1': {}, }, } - self.assertDictEqual(scenario_helper.vnf_cfg, ScenarioHelper.DEFAULT_VNF_CFG) + self.assertEqual(self.scenario_helper.vnf_cfg, + sample_vnf.ScenarioHelper.DEFAULT_VNF_CFG) def test_property_topology(self): - scenario_helper = ScenarioHelper('name1') - scenario_helper.scenario_cfg = { + self.scenario_helper.scenario_cfg = { 'topology': 'my_topology', } - self.assertEqual(scenario_helper.topology, 'my_topology') + self.assertEqual(self.scenario_helper.topology, 'my_topology') class TestSampleVnf(unittest.TestCase): @@ -1627,6 +1455,39 @@ class TestSampleVnf(unittest.TestCase): self.assertEqual(sample_vnf.wait_for_instantiate(), 0) + @mock.patch.object(time, 'sleep') + @mock.patch.object(ssh, 'SSH') + def test_wait_for_initialize(self, ssh, *args): + test_base.mock_ssh(ssh, exec_result=(1, "", "")) + queue_get_list = [ + 'some output', + 'pipeline> ', + 'run non_existent_script_name', + 'Cannot open file "non_existent_script_name"' + ] + queue_size_list = [ + 0, + len(queue_get_list[0]), + 0, + len(queue_get_list[1]), + len(queue_get_list[2]), + 0, + len(queue_get_list[3]) + ] + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf.APP_NAME = 'sample1' + sample_vnf.WAIT_TIME_FOR_SCRIPT = 0 + sample_vnf._vnf_process = mock.Mock() + sample_vnf._vnf_process.exitcode = 0 + sample_vnf._vnf_process._is_alive.return_value = 1 + sample_vnf.queue_wrapper = mock.Mock() + sample_vnf.q_in = mock.Mock() + sample_vnf.q_out = mock.Mock() + sample_vnf.q_out.qsize.side_effect = iter(queue_size_list) + sample_vnf.q_out.get.side_effect = iter(queue_get_list) + sample_vnf.wait_for_initialize() + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") def test_vnf_execute_with_queue_data(self, *args): queue_size_list = [ diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_imsbench_sipp.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_imsbench_sipp.py new file mode 100644 index 000000000..698b1b03f --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_imsbench_sipp.py @@ -0,0 +1,481 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mock +import unittest +from collections import deque + +from yardstick.network_services.vnf_generic.vnf import tg_imsbench_sipp +from yardstick import ssh + + +class TestSippVnf(unittest.TestCase): + + VNFD = { + "short-name": "SippVnf", + "vdu": [ + { + "id": "sippvnf-baremetal", + "routing_table": "", + "external-interface": [ + { + "virtual-interface": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "vnfd-connection-point-ref": "xe0", + "name": "xe0" + }, + { + "virtual-interface": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "vnfd-connection-point-ref": "xe1", + "name": "xe1" + } + ], + "name": "sippvnf-baremetal", + "description": "Sipp" + } + ], + "description": "ImsbenchSipp", + "mgmt-interface": { + "vdu-id": "sipp-baremetal", + "password": "r00t", + "user": "root", + "ip": "10.80.3.11" + }, + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "id": "SippVnf", + "name": "SippVnf" + } + + SCENARIO_CFG = { + "task_id": "ba636744-898e-4783-a4aa-0a79c60953cc", + "tc": "tc_vims_baremetal_sipp", + "runner": { + "interval": 1, + "output_config": { + "DEFAULT": { + "debug": "False", + "dispatcher": [ + "influxdb" + ] + }, + "nsb": { + "debug": "False", + "trex_client_lib": "/opt/nsb_bin/trex_client/stl", + "bin_path": "/opt/nsb_bin", + "trex_path": "/opt/nsb_bin/trex/scripts", + "dispatcher": "influxdb" + }, + "dispatcher_influxdb": { + "username": "root", + "target": "http://10.80.3.11:8086", + "db_name": "yardstick", + "timeout": "5", + "debug": "False", + "password": "root", + "dispatcher": "influxdb" + }, + "dispatcher_http": { + "debug": "False", + "dispatcher": "influxdb", + "timeout": "5", + "target": "http://127.0.0.1:8000/results" + }, + "dispatcher_file": { + "debug": "False", + "backup_count": "0", + "max_bytes": "0", + "dispatcher": "influxdb", + "file_path": "/tmp/yardstick.out" + } + }, + "runner_id": 18148, + "duration": 60, + "type": "Vims" + }, + "nodes": { + "vnf__0": "pcscf.yardstick-ba636744", + "vnf__1": "hss.yardstick-ba636744", + "tg__0": "sipp.yardstick-ba636744" + }, + "topology": "vims-topology.yaml", + "type": "NSPerf", + "traffic_profile": "../../traffic_profiles/ipv4_throughput.yaml", + "task_path": "samples/vnf_samples/nsut/vims", + "options": { + "init_reg_max": 5000, + "end_user": 10000, + "reg_cps": 20, + "rereg_cps": 20, + "rereg_step": 10, + "wait_time": 5, + "start_user": 1, + "msgc_cps": 10, + "dereg_step": 10, + "call_cps": 10, + "reg_step": 10, + "init_reg_cps": 50, + "dereg_cps": 20, + "msgc_step": 5, + "call_step": 5, + "hold_time": 15, + "port": 5060, + "run_mode": "nortp" + } + } + CONTEXT_CFG = { + "nodes": { + "tg__0": { + "ip": "10.80.3.11", + "interfaces": { + "xe0": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "xe1": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + } + }, + "user": "root", + "password": "r00t", + "VNF model": "../../vnf_descriptors/tg_sipp_vnfd.yaml", + "name": "sipp.yardstick-a75a3aff", + "vnfd-id-ref": "tg__0", + "member-vnf-index": "1", + "role": "TrafficGen", + "ctx_type": "Node" + }, + "vnf__0": { + "ip": "10.80.3.7", + "interfaces": { + "xe0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "tg__0": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + } + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + } + }, + "user": "root", + "password": "r00t", + "VNF model": "../../vnf_descriptors/vims_pcscf_vnfd.yaml", + "name": "pcscf.yardstick-a75a3aff", + "vnfd-id-ref": "vnf__0", + "member-vnf-index": "2", + "role": "VirtualNetworkFunction", + "ctx_type": "Node" + }, + "vnf__1": { + "ip": "10.80.3.7", + "interfaces": { + "xe0": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "tg__0": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + } + }, + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "user": "root", + "password": "r00t", + "VNF model": "../../vnf_descriptors/vims_hss_vnfd.yaml", + "name": "hss.yardstick-a75a3aff", + "vnfd-id-ref": "vnf__1", + "member-vnf-index": "3", + "role": "VirtualNetworkFunction", + "ctx_type": "Node" + } + }, + "networks": {} + } + + FILE = "timestamp:1000 reg:100 reg_saps:0" + + QUEUE = {'reg_saps': 0.0, 'timestamp': 1000.0, 'reg': 100.0} + + TRAFFIC_PROFILE = { + "schema": "nsb:traffic_profile:0.1", + "name": "sip", + "description": "Traffic profile to run sip", + "traffic_profile": { + "traffic_type": "SipProfile", + "frame_rate": 100, # pps + "enable_latency": False + }, + } + + def setUp(self): + self._mock_ssh = mock.patch.object(ssh, 'SSH') + self.mock_ssh = self._mock_ssh.start() + + self.addCleanup(self._stop_mocks) + self.sipp_vnf = tg_imsbench_sipp.SippVnf('tg__0', self.VNFD) + + def _stop_mocks(self): + self._mock_ssh.stop() + + def test___init__(self): + self.assertIsInstance(self.sipp_vnf.resource_helper, + tg_imsbench_sipp.SippResourceHelper) + + def test_wait_for_instantiate(self): + self.assertIsNone(self.sipp_vnf.wait_for_instantiate()) + + @mock.patch('six.moves.builtins.open', new_callable=mock.mock_open, read_data=FILE) + def test_handle_result_files(self, mock_file): + result_deque = deque([self.QUEUE]) + file = "/tmp/test.txt" + test = self.sipp_vnf.handle_result_files(file) + self.assertEqual(result_deque, test) + mock_file.assert_called_with(file, 'r') + + @mock.patch.object(ssh.SSH, 'get') + def test_get_result_files(self, mock_get): + self.sipp_vnf.get_result_files() + mock_get.assert_called() + + def test_collect_kpi(self): + self.sipp_vnf.queue = deque([self.QUEUE]) + self.assertEqual(self.QUEUE, self.sipp_vnf.collect_kpi()) + + def test_collect_kpi_empty(self): + self.sipp_vnf.queue = deque([]) + self.assertEqual({}, self.sipp_vnf.collect_kpi()) + + @mock.patch('six.moves.builtins.open', new_callable=mock.mock_open, read_data=FILE) + def test_count_line_num(self, mock_file): + file = "/tmp/test.txt" + mock_file.return_value.__iter__.return_value = self.FILE.splitlines() + self.assertEqual(1, self.sipp_vnf.count_line_num(file)) + mock_file.assert_called_with(file, 'r') + + @mock.patch('six.moves.builtins.open', new_callable=mock.mock_open, read_data='') + def test_count_line_num_file_empty(self, mock_file): + file = "/tmp/test.txt" + self.assertEqual(0, self.sipp_vnf.count_line_num(file)) + mock_file.assert_called_with(file, 'r') + + @mock.patch('six.moves.builtins.open', new_callable=mock.mock_open, read_data=FILE) + def test_count_line_num_file_error(self, mock_file): + file = "/tmp/test.txt" + mock_file.side_effect = IOError() + self.assertEqual(0, self.sipp_vnf.count_line_num(file)) + + def test_is_ended_false(self): + self.sipp_vnf.count_line_num = mock.Mock(return_value=1) + not_end = self.sipp_vnf.is_ended() + self.assertFalse(not_end) + + def test_is_ended_true(self): + self.sipp_vnf.count_line_num = mock.Mock(return_value=0) + end = self.sipp_vnf.is_ended() + self.assertTrue(end) + + def test_terminate(self): + self.sipp_vnf.ssh_helper = mock.MagicMock() + self.sipp_vnf.resource_helper.ssh_helper = mock.MagicMock() + self.assertIsNone(self.sipp_vnf.terminate()) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py index 469e5113f..dd1c277c3 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_landslide.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_landslide.py index 8c017d15e..2d8c01bec 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_landslide.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_landslide.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py index 51f075e4a..a3e4384cf 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_pktgen.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_pktgen.py index 34dd640ad..1ecb6ffc9 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_pktgen.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_pktgen.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py index 49df19378..0aaf17790 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2017-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py index 494e2c298..c3f3e5f67 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -18,6 +18,7 @@ import mock import six import unittest import ipaddress +import time from collections import OrderedDict from yardstick.common import utils @@ -27,6 +28,7 @@ from yardstick.benchmark.contexts import base as ctx_base from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api from yardstick.network_services.traffic_profile import base as tp_base from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia +from yardstick.network_services.traffic_profile import ixia_rfc2544 TEST_FILE_YAML = 'nsb_test_case.yaml' @@ -108,6 +110,31 @@ class TestIxiaResourceHelper(unittest.TestCase): self.assertEqual('fake_samples', ixia_rhelper._queue.get()) mock_tprofile.update_traffic_profile.assert_called_once() + def test_run_test(self): + expected_result = {'test': 'fake_samples', 'Iteration': 1} + mock_tprofile = mock.Mock() + mock_tprofile.config.duration = 10 + mock_tprofile.get_drop_percentage.return_value = \ + True, {'test': 'fake_samples', 'Iteration': 1} + ixia_rhelper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock()) + tasks_queue = mock.Mock() + tasks_queue.get.return_value = 'RUN_TRAFFIC' + results_queue = mock.Mock() + ixia_rhelper.rfc_helper = mock.Mock() + ixia_rhelper.vnfd_helper = mock.Mock() + ixia_rhelper._ix_scenario = mock.Mock() + ixia_rhelper.vnfd_helper.port_pairs.all_ports = [] + with mock.patch.object(ixia_rhelper, 'generate_samples'), \ + mock.patch.object(ixia_rhelper, '_build_ports'), \ + mock.patch.object(ixia_rhelper, '_initialize_client'), \ + mock.patch.object(utils, 'wait_until_true'): + ixia_rhelper.run_test(mock_tprofile, tasks_queue, results_queue) + + self.assertEqual(expected_result, ixia_rhelper._queue.get()) + mock_tprofile.update_traffic_profile.assert_called_once() + tasks_queue.task_done.assert_called_once() + results_queue.put.assert_called_once_with('COMPLETE') + @mock.patch.object(tg_rfc2544_ixia, 'ixnet_api') class TestIXIATrafficGen(unittest.TestCase): @@ -426,8 +453,65 @@ class TestIXIATrafficGen(unittest.TestCase): _traffic_runner() + def test_run_traffic_once(self, *args): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd) + sut._init_traffic_process = mock.Mock() + sut._tasks_queue.put = mock.Mock() + sut.resource_helper.client_started.value = 0 + sut.run_traffic_once(self.TRAFFIC_PROFILE) + sut._tasks_queue.put.assert_called_once_with("RUN_TRAFFIC") + sut._init_traffic_process.assert_called_once_with(self.TRAFFIC_PROFILE) + + def test__test_runner(self, *args): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd) + tasks = 'tasks' + results = 'results' + sut.resource_helper = mock.Mock() + sut._test_runner(self.TRAFFIC_PROFILE, tasks, results) + sut.resource_helper.run_test.assert_called_once_with(self.TRAFFIC_PROFILE, + tasks, results) + + @mock.patch.object(time, 'sleep', return_value=0) + def test__init_traffic_process(self, *args): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd) + sut._test_runner = mock.Mock(return_value=0) + sut.resource_helper = mock.Mock() + sut.resource_helper.client_started.value = 0 + sut._init_traffic_process(self.TRAFFIC_PROFILE) + + def test_wait_on_traffic(self, *args): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd) + sut._tasks_queue.join = mock.Mock(return_value=0) + sut._result_queue.get = mock.Mock(return_value='COMPLETE') + result = sut.wait_on_traffic() + sut._tasks_queue.join.assert_called_once() + sut._result_queue.get.assert_called_once() + self.assertEqual(result, 'COMPLETE') + class TestIxiaBasicScenario(unittest.TestCase): + + STATS = {'stat_name': ['Card01/Port01', + 'Card02/Port02'], + 'port_name': ['Ethernet - 001', 'Ethernet - 002'], + 'Frames_Tx': ['150', '150'], + 'Valid_Frames_Rx': ['150', '150'], + 'Frames_Tx_Rate': ['0.0', '0.0'], + 'Valid_Frames_Rx_Rate': ['0.0', '0.0'], + 'Bytes_Rx': ['9600', '9600'], + 'Bytes_Tx': ['9600', '9600'], + 'Tx_Rate_Kbps': ['0.0', '0.0'], + 'Rx_Rate_Mbps': ['0.0', '0.0'], + 'Tx_Rate_Mbps': ['0.0', '0.0'], + 'Rx_Rate_Kbps': ['0.0', '0.0'], + 'Store-Forward_Max_latency_ns': ['100', '200'], + 'Store-Forward_Min_latency_ns': ['100', '200'], + 'Store-Forward_Avg_latency_ns': ['100', '200']} + def setUp(self): self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen') self.mock_IxNextgen = self._mock_IxNextgen.start() @@ -447,9 +531,13 @@ class TestIxiaBasicScenario(unittest.TestCase): def test_create_traffic_model(self): self.mock_IxNextgen.get_vports.return_value = [1, 2, 3, 4] - self.scenario.create_traffic_model() + yaml_data = {'traffic_profile': {} + } + traffic_profile = ixia_rfc2544.IXIARFC2544Profile(yaml_data) + self.scenario.create_traffic_model(traffic_profile) self.scenario.client.get_vports.assert_called_once() - self.scenario.client.create_traffic_model.assert_called_once_with([1, 3], [2, 4]) + self.scenario.client.create_traffic_model.assert_called_once_with( + [1, 3], [2, 4], traffic_profile) def test_apply_config(self): self.assertIsNone(self.scenario.apply_config()) @@ -460,6 +548,48 @@ class TestIxiaBasicScenario(unittest.TestCase): def test_stop_protocols(self): self.assertIsNone(self.scenario.stop_protocols()) + def test__get_stats(self): + self.scenario._get_stats() + self.scenario.client.get_statistics.assert_called_once() + + @mock.patch.object(tg_rfc2544_ixia.IxiaBasicScenario, '_get_stats') + def test_generate_samples(self, mock_get_stats): + + expected_samples = {'xe0': { + 'InPackets': 150, + 'OutPackets': 150, + 'InBytes': 9600, + 'OutBytes': 9600, + 'RxThroughput': 5.0, + 'TxThroughput': 5.0, + 'RxThroughputBps': 320.0, + 'TxThroughputBps': 320.0, + 'LatencyMax': 100, + 'LatencyMin': 100, + 'LatencyAvg': 100}, + 'xe1': { + 'InPackets': 150, + 'OutPackets': 150, + 'InBytes': 9600, + 'OutBytes': 9600, + 'RxThroughput': 5.0, + 'TxThroughput': 5.0, + 'RxThroughputBps': 320.0, + 'TxThroughputBps': 320.0, + 'LatencyMax': 200, + 'LatencyMin': 200, + 'LatencyAvg': 200}} + + res_helper = mock.Mock() + res_helper.vnfd_helper.find_interface_by_port.side_effect = \ + [{'name': 'xe0'}, {'name': 'xe1'}] + ports = [0, 1] + duration = 30 + mock_get_stats.return_value = self.STATS + samples = self.scenario.generate_samples(res_helper, ports, duration) + mock_get_stats.assert_called_once() + self.assertEqual(samples, expected_samples) + class TestIxiaL3Scenario(TestIxiaBasicScenario): IXIA_CFG = { @@ -511,11 +641,13 @@ class TestIxiaL3Scenario(TestIxiaBasicScenario): def test_create_traffic_model(self): self.mock_IxNextgen.get_vports.return_value = ['1', '2'] - self.scenario.create_traffic_model() + traffic_profile = 'fake_profile' + self.scenario.create_traffic_model(traffic_profile) self.scenario.client.get_vports.assert_called_once() self.scenario.client.create_ipv4_traffic_model.\ assert_called_once_with(['1/protocols/static'], - ['2/protocols/static']) + ['2/protocols/static'], + 'fake_profile') def test_apply_config(self): self.scenario._add_interfaces = mock.Mock() @@ -569,6 +701,9 @@ class TestIxiaPppoeClientScenario(unittest.TestCase): 'gateway_ip': ['10.1.1.1', '10.2.2.1'], 'ip': ['10.1.1.1', '10.2.2.1'], 'prefix': ['24', '24'] + }, + 'priority': { + 'tos': {'precedence': [0, 4]} } } @@ -631,7 +766,31 @@ class TestIxiaPppoeClientScenario(unittest.TestCase): mock_id_pairs.assert_called_once_with(mock_tp.full_profile) mock_obj_pairs.assert_called_once_with(['xe0', 'xe1', 'xe0', 'xe1']) self.scenario.client.create_ipv4_traffic_model.assert_called_once_with( - uplink_endpoints, downlink_endpoints) + uplink_endpoints, downlink_endpoints, mock_tp) + + @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario, + '_get_endpoints_src_dst_id_pairs') + @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario, + '_get_endpoints_src_dst_obj_pairs') + def test_create_traffic_model_topology_based_flows(self, mock_obj_pairs, + mock_id_pairs): + uplink_topologies = ['topology1', 'topology3'] + downlink_topologies = ['topology2', 'topology4'] + mock_id_pairs.return_value = [] + mock_obj_pairs.return_value = [] + mock_tp = mock.Mock() + mock_tp.full_profile = {'uplink_0': 'data', + 'downlink_0': 'data', + 'uplink_1': 'data', + 'downlink_1': 'data' + } + self.scenario._access_topologies = ['topology1', 'topology3'] + self.scenario._core_topologies = ['topology2', 'topology4'] + self.scenario.create_traffic_model(mock_tp) + mock_id_pairs.assert_called_once_with(mock_tp.full_profile) + mock_obj_pairs.assert_called_once_with([]) + self.scenario.client.create_ipv4_traffic_model.assert_called_once_with( + uplink_topologies, downlink_topologies, mock_tp) def test__get_endpoints_src_dst_id_pairs(self): full_tp = OrderedDict([ @@ -702,22 +861,10 @@ class TestIxiaPppoeClientScenario(unittest.TestCase): } } - expected_result = ['tp1_dg1', 'tp3_dg1', 'tp1_dg2', 'tp3_dg1', - 'tp1_dg3', 'tp3_dg1', 'tp1_dg4', 'tp3_dg1', - 'tp2_dg1', 'tp4_dg1', 'tp2_dg2', 'tp4_dg1', - 'tp2_dg3', 'tp4_dg1', 'tp2_dg4', 'tp4_dg1'] - self.scenario._ixia_cfg = ixia_cfg - self.scenario._access_topologies = ['topology1', 'topology2'] - self.scenario._core_topologies = ['topology3', 'topology4'] - self.mock_IxNextgen.get_topology_device_groups.side_effect = \ - [['tp1_dg1', 'tp1_dg2', 'tp1_dg3', 'tp1_dg4'], - ['tp2_dg1', 'tp2_dg2', 'tp2_dg3', 'tp2_dg4'], - ['tp3_dg1'], - ['tp4_dg1']] res = self.scenario._get_endpoints_src_dst_obj_pairs( endpoints_id_pairs) - self.assertEqual(res, expected_result) + self.assertEqual(res, []) def test_run_protocols(self): self.scenario.client.is_protocols_running.return_value = True @@ -954,3 +1101,165 @@ class TestIxiaPppoeClientScenario(unittest.TestCase): local_as=bgp_params["bgp"]["as_number"], bgp_type=bgp_params["bgp"]["bgp_type"]) ]) + + def test_update_tracking_options_raw_priority(self): + raw_priority = {'raw': 4} + self.scenario._ixia_cfg['priority'] = raw_priority + self.scenario.update_tracking_options() + self.scenario.client.set_flow_tracking.assert_called_once_with( + ['flowGroup0', 'vlanVlanId0', 'ipv4Raw0']) + + def test_update_tracking_options_tos_priority(self): + tos_priority = {'tos': {'precedence': [4, 7]}} + self.scenario._ixia_cfg['priority'] = tos_priority + self.scenario.update_tracking_options() + self.scenario.client.set_flow_tracking.assert_called_once_with( + ['flowGroup0', 'vlanVlanId0', 'ipv4Precedence0']) + + def test_update_tracking_options_dscp_priority(self): + dscp_priority = {'dscp': {'defaultPHB': [4, 7]}} + self.scenario._ixia_cfg['priority'] = dscp_priority + self.scenario.update_tracking_options() + self.scenario.client.set_flow_tracking.assert_called_once_with( + ['flowGroup0', 'vlanVlanId0', 'ipv4DefaultPhb0']) + + def test_update_tracking_options_invalid_priority_data(self): + invalid_priority = {'tos': {'inet-precedence': [4, 7]}} + self.scenario._ixia_cfg['priority'] = invalid_priority + self.scenario.update_tracking_options() + self.scenario.client.set_flow_tracking.assert_called_once_with( + ['flowGroup0', 'vlanVlanId0', 'ipv4Precedence0']) + + def test_get_tc_rfc2544_options(self): + rfc2544_tc_opts = {'allowed_drop_rate': '0.0001 - 0.0001'} + self.scenario._ixia_cfg['rfc2544'] = rfc2544_tc_opts + res = self.scenario.get_tc_rfc2544_options() + self.assertEqual(res, rfc2544_tc_opts) + + def test__get_stats(self): + self.scenario._get_stats() + self.scenario.client.get_pppoe_scenario_statistics.assert_called_once() + + def test_get_flow_id_data(self): + stats = [{'id': 1, 'in_packets': 10, 'out_packets': 20}] + key = "in_packets" + flow_id = 1 + res = self.scenario.get_flow_id_data(stats, flow_id, key) + self.assertEqual(res, 10) + + @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario, '_get_stats') + @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario, + 'get_priority_flows_stats') + def test_generate_samples(self, mock_prio_flow_statistics, + mock_get_stats): + ixia_stats = { + 'flow_statistic': [ + {'Flow_Group': 'RFC2544-1 - Flow Group 0001', + 'Frames_Delta': '0', + 'IP_Priority': '0', + 'Rx_Frames': '3000', + 'Tx_Frames': '3000', + 'VLAN-ID': '100', + 'Tx_Port': 'Ethernet - 001', + 'Store-Forward_Avg_latency_ns': '2', + 'Store-Forward_Min_latency_ns': '2', + 'Store-Forward_Max_latency_ns': '2'}, + {'Flow_Group': 'RFC2544-2 - Flow Group 0001', + 'Frames_Delta': '0', + 'IP_Priority': '0', + 'Rx_Frames': '3000', + 'Tx_Frames': '3000', + 'VLAN-ID': '101', + 'Tx_Port': 'Ethernet - 002', + 'Store-Forward_Avg_latency_ns': '2', + 'Store-Forward_Min_latency_ns': '2', + 'Store-Forward_Max_latency_ns': '2' + }], + 'port_statistics': [ + {'Frames_Tx': '3000', + 'Valid_Frames_Rx': '3000', + 'Bytes_Rx': '192000', + 'Bytes_Tx': '192000', + 'Rx_Rate_Kbps': '0.0', + 'Tx_Rate_Kbps': '0.0', + 'Rx_Rate_Mbps': '0.0', + 'Tx_Rate_Mbps': '0.0', + 'port_name': 'Ethernet - 001'}, + {'Frames_Tx': '3000', + 'Valid_Frames_Rx': '3000', + 'Bytes_Rx': '192000', + 'Bytes_Tx': '192000', + 'Rx_Rate_Kbps': '0.0', + 'Tx_Rate_Kbps': '0.0', + 'Rx_Rate_Mbps': '0.0', + 'Tx_Rate_Mbps': '0.0', + 'port_name': 'Ethernet - 002'}], + 'pppox_client_per_port': [ + {'Sessions_Down': '0', + 'Sessions_Not_Started': '0', + 'Sessions_Total': '1', + 'Sessions_Up': '1', + 'subs_port': 'Ethernet - 001'}]} + + prio_flows_stats = { + '0': { + 'InPackets': 6000, + 'OutPackets': 6000, + 'RxThroughput': 200.0, + 'TxThroughput': 200.0, + 'LatencyAvg': 2, + 'LatencyMax': 2, + 'LatencyMin': 2 + } + } + + expected_result = {'priority_stats': { + '0': {'RxThroughput': 200.0, + 'TxThroughput': 200.0, + 'LatencyAvg': 2, + 'LatencyMax': 2, + 'LatencyMin': 2, + 'InPackets': 6000, + 'OutPackets': 6000}}, + 'xe0': {'RxThroughput': 100.0, + 'LatencyAvg': 2, + 'LatencyMax': 2, + 'LatencyMin': 2, + 'TxThroughput': 100.0, + 'InPackets': 3000, + 'OutPackets': 3000, + 'InBytes': 192000, + 'OutBytes': 192000, + 'RxThroughputBps': 6400.0, + 'TxThroughputBps': 6400.0, + 'SessionsDown': 0, + 'SessionsNotStarted': 0, + 'SessionsTotal': 1, + 'SessionsUp': 1}, + 'xe1': {'RxThroughput': 100.0, + 'LatencyAvg': 2, + 'LatencyMax': 2, + 'LatencyMin': 2, + 'TxThroughput': 100.0, + 'InPackets': 3000, + 'OutPackets': 3000, + 'InBytes': 192000, + 'OutBytes': 192000, + 'RxThroughputBps': 6400.0, + 'TxThroughputBps': 6400.0}} + + mock_get_stats.return_value = ixia_stats + mock_prio_flow_statistics.return_value = prio_flows_stats + ports = [0, 1] + port_names = [{'name': 'xe0'}, {'name': 'xe1'}] + duration = 30 + res_helper = mock.Mock() + res_helper.vnfd_helper.find_interface_by_port.side_effect = \ + port_names + samples = self.scenario.generate_samples(res_helper, ports, duration) + self.assertIsNotNone(samples) + self.assertIsNotNone(samples.get('xe0')) + self.assertIsNotNone(samples.get('xe1')) + self.assertEqual(samples, expected_result) + mock_get_stats.assert_called_once() + mock_prio_flow_statistics.assert_called_once() diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py index a9fa5f3c1..51b1b0d33 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import time import mock import unittest @@ -24,7 +25,8 @@ from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex class TestTrexRfcResouceHelper(unittest.TestCase): - def test__run_traffic_once(self): + @mock.patch.object(time, 'sleep') + def test__run_traffic_once(self, *args): mock_setup_helper = mock.Mock() mock_traffic_profile = mock.Mock() mock_traffic_profile.config.duration = 3 diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py index 350ba8448..0a441c8ce 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex_vpp.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex_vpp.py new file mode 100644 index 000000000..ef1ae1182 --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex_vpp.py @@ -0,0 +1,1130 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from multiprocessing import Process + +import mock +from trex_stl_lib.trex_stl_exceptions import STLError + +from yardstick.benchmark.contexts import base as ctx_base +from yardstick.network_services.traffic_profile import base as tp_base +from yardstick.network_services.traffic_profile import rfc2544 +from yardstick.network_services.vnf_generic.vnf import base, sample_vnf, \ + tg_trex_vpp +from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import \ + mock_ssh + + +class TestTrexVppResourceHelper(unittest.TestCase): + TRAFFIC_PROFILE = { + "schema": "isb:traffic_profile:0.1", + "name": "fixed", + "description": "Fixed traffic profile to run UDP traffic", + "traffic_profile": { + "traffic_type": "FixedTraffic", + "frame_rate": 100, # pps + "flow_number": 10, + "frame_size": 64 + }, + } + + def test_fmt_latency(self): + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + self.assertEqual('10/90/489', vpp_rfc.fmt_latency(10, 90, 489)) + + def test_fmt_latency_error(self): + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + self.assertEqual('-1/-1/-1', vpp_rfc.fmt_latency('err', 'err', 'err')) + + def test_generate_samples(self): + stats = { + 0: { + "ibytes": 55549120, + "ierrors": 0, + "ipackets": 867955, + "obytes": 55549696, + "oerrors": 0, + "opackets": 867964, + "rx_bps": 104339032.0, + "rx_bps_L1": 136944984.0, + "rx_pps": 203787.2, + "rx_util": 1.36944984, + "tx_bps": 134126008.0, + "tx_bps_L1": 176040392.0, + "tx_pps": 261964.9, + "tx_util": 1.7604039200000001 + }, + 1: { + "ibytes": 55549696, + "ierrors": 0, + "ipackets": 867964, + "obytes": 55549120, + "oerrors": 0, + "opackets": 867955, + "rx_bps": 134119648.0, + "rx_bps_L1": 176032032.0, + "rx_pps": 261952.4, + "rx_util": 1.76032032, + "tx_bps": 104338192.0, + "tx_bps_L1": 136943872.0, + "tx_pps": 203785.5, + "tx_util": 1.36943872 + }, + "flow_stats": { + 1: { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 6400, + "1": 0, + "total": 6400 + }, + "rx_pkts": { + "0": 100, + "1": 0, + "total": 100 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 0, + "1": 6400, + "total": 6400 + }, + "tx_pkts": { + "0": 0, + "1": 100, + "total": 100 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + 2: { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 0, + "1": 6464, + "total": 6464 + }, + "rx_pkts": { + "0": 0, + "1": 101, + "total": 101 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 6464, + "1": 0, + "total": 6464 + }, + "tx_pkts": { + "0": 101, + "1": 0, + "total": 101 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + "global": { + "rx_err": { + "0": 0, + "1": 0 + }, + "tx_err": { + "0": 0, + "1": 0 + } + } + }, + "global": { + "bw_per_core": 45.6, + "cpu_util": 0.1494, + "queue_full": 0, + "rx_bps": 238458672.0, + "rx_cpu_util": 4.751e-05, + "rx_drop_bps": 0.0, + "rx_pps": 465739.6, + "tx_bps": 238464208.0, + "tx_pps": 465750.4 + }, + "latency": { + 1: { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 63.375, + "histogram": { + "20": 1, + "30": 18, + "40": 12, + "50": 10, + "60": 12, + "70": 11, + "80": 6, + "90": 10, + "100": 20 + }, + "jitter": 23, + "last_max": 122, + "total_max": 123, + "total_min": 20 + } + }, + 2: { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 74, + "histogram": { + "60": 20, + "70": 10, + "80": 3, + "90": 4, + "100": 64 + }, + "jitter": 6, + "last_max": 83, + "total_max": 135, + "total_min": 60 + } + }, + "global": { + "bad_hdr": 0, + "old_flow": 0 + } + }, + "total": { + "ibytes": 111098816, + "ierrors": 0, + "ipackets": 1735919, + "obytes": 111098816, + "oerrors": 0, + "opackets": 1735919, + "rx_bps": 238458680.0, + "rx_bps_L1": 312977016.0, + "rx_pps": 465739.6, + "rx_util": 3.1297701599999996, + "tx_bps": 238464200.0, + "tx_bps_L1": 312984264.0, + "tx_pps": 465750.4, + "tx_util": 3.12984264 + } + } + expected = { + "xe0": { + "in_packets": 867955, + "latency": { + 2: { + "avg_latency": 74.0, + "max_latency": 135.0, + "min_latency": 60.0 + } + }, + "out_packets": 867964, + "rx_throughput_bps": 104339032.0, + "rx_throughput_fps": 203787.2, + "tx_throughput_bps": 134126008.0, + "tx_throughput_fps": 261964.9 + }, + "xe1": { + "in_packets": 867964, + "latency": { + 1: { + "avg_latency": 63.375, + "max_latency": 123.0, + "min_latency": 20.0 + } + }, + "out_packets": 867955, + "rx_throughput_bps": 134119648.0, + "rx_throughput_fps": 261952.4, + "tx_throughput_bps": 104338192.0, + "tx_throughput_fps": 203785.5 + } + } + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0) + port_pg_id = rfc2544.PortPgIDMap() + port_pg_id.add_port(1) + port_pg_id.increase_pg_id() + port_pg_id.add_port(0) + port_pg_id.increase_pg_id() + self.assertEqual(expected, + vpp_rfc.generate_samples(stats, [0, 1], port_pg_id, + True)) + + def test_generate_samples_error(self): + stats = { + 0: { + "ibytes": 55549120, + "ierrors": 0, + "ipackets": 867955, + "obytes": 55549696, + "oerrors": 0, + "opackets": 867964, + "rx_bps": 104339032.0, + "rx_bps_L1": 136944984.0, + "rx_pps": 203787.2, + "rx_util": 1.36944984, + "tx_bps": 134126008.0, + "tx_bps_L1": 176040392.0, + "tx_pps": 261964.9, + "tx_util": 1.7604039200000001 + }, + 1: { + "ibytes": 55549696, + "ierrors": 0, + "ipackets": 867964, + "obytes": 55549120, + "oerrors": 0, + "opackets": 867955, + "rx_bps": 134119648.0, + "rx_bps_L1": 176032032.0, + "rx_pps": 261952.4, + "rx_util": 1.76032032, + "tx_bps": 104338192.0, + "tx_bps_L1": 136943872.0, + "tx_pps": 203785.5, + "tx_util": 1.36943872 + }, + "flow_stats": { + 1: { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 6400, + "1": 0, + "total": 6400 + }, + "rx_pkts": { + "0": 100, + "1": 0, + "total": 100 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 0, + "1": 6400, + "total": 6400 + }, + "tx_pkts": { + "0": 0, + "1": 100, + "total": 100 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + 2: { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 0, + "1": 6464, + "total": 6464 + }, + "rx_pkts": { + "0": 0, + "1": 101, + "total": 101 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 6464, + "1": 0, + "total": 6464 + }, + "tx_pkts": { + "0": 101, + "1": 0, + "total": 101 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + "global": { + "rx_err": { + "0": 0, + "1": 0 + }, + "tx_err": { + "0": 0, + "1": 0 + } + } + }, + "global": { + "bw_per_core": 45.6, + "cpu_util": 0.1494, + "queue_full": 0, + "rx_bps": 238458672.0, + "rx_cpu_util": 4.751e-05, + "rx_drop_bps": 0.0, + "rx_pps": 465739.6, + "tx_bps": 238464208.0, + "tx_pps": 465750.4 + }, + "latency": { + 1: { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": "err", + "histogram": { + "20": 1, + "30": 18, + "40": 12, + "50": 10, + "60": 12, + "70": 11, + "80": 6, + "90": 10, + "100": 20 + }, + "jitter": 23, + "last_max": 122, + "total_max": "err", + "total_min": "err" + } + }, + 2: { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 74, + "histogram": { + "60": 20, + "70": 10, + "80": 3, + "90": 4, + "100": 64 + }, + "jitter": 6, + "last_max": 83, + "total_max": 135, + "total_min": 60 + } + }, + "global": { + "bad_hdr": 0, + "old_flow": 0 + } + }, + "total": { + "ibytes": 111098816, + "ierrors": 0, + "ipackets": 1735919, + "obytes": 111098816, + "oerrors": 0, + "opackets": 1735919, + "rx_bps": 238458680.0, + "rx_bps_L1": 312977016.0, + "rx_pps": 465739.6, + "rx_util": 3.1297701599999996, + "tx_bps": 238464200.0, + "tx_bps_L1": 312984264.0, + "tx_pps": 465750.4, + "tx_util": 3.12984264 + } + } + expected = {'xe0': {'in_packets': 867955, + 'latency': {2: {'avg_latency': 74.0, + 'max_latency': 135.0, + 'min_latency': 60.0}}, + 'out_packets': 867964, + 'rx_throughput_bps': 104339032.0, + 'rx_throughput_fps': 203787.2, + 'tx_throughput_bps': 134126008.0, + 'tx_throughput_fps': 261964.9}, + 'xe1': {'in_packets': 867964, + 'latency': {1: {'avg_latency': -1.0, + 'max_latency': -1.0, + 'min_latency': -1.0}}, + 'out_packets': 867955, + 'rx_throughput_bps': 134119648.0, + 'rx_throughput_fps': 261952.4, + 'tx_throughput_bps': 104338192.0, + 'tx_throughput_fps': 203785.5}} + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0) + vpp_rfc.get_stats = mock.Mock() + vpp_rfc.get_stats.return_value = stats + port_pg_id = rfc2544.PortPgIDMap() + port_pg_id.add_port(1) + port_pg_id.increase_pg_id() + port_pg_id.add_port(0) + port_pg_id.increase_pg_id() + self.assertEqual(expected, + vpp_rfc.generate_samples(stats=None, ports=[0, 1], + port_pg_id=port_pg_id, + latency=True)) + + def test__run_traffic_once(self): + mock_setup_helper = mock.Mock() + mock_traffic_profile = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + vpp_rfc.TRANSIENT_PERIOD = 0 + vpp_rfc.rfc2544_helper = mock.Mock() + + self.assertTrue(vpp_rfc._run_traffic_once(mock_traffic_profile)) + mock_traffic_profile.execute_traffic.assert_called_once_with(vpp_rfc) + + def test_run_traffic(self): + mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile) + mock_traffic_profile.get_traffic_definition.return_value = "64" + mock_traffic_profile.params = self.TRAFFIC_PROFILE + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + vpp_rfc.ssh_helper = mock.Mock() + vpp_rfc.ssh_helper.run = mock.Mock() + vpp_rfc._traffic_runner = mock.Mock(return_value=0) + vpp_rfc._build_ports = mock.Mock() + vpp_rfc._connect = mock.Mock() + vpp_rfc.run_traffic(mock_traffic_profile) + + def test_send_traffic_on_tg(self): + stats = { + 0: { + "ibytes": 55549120, + "ierrors": 0, + "ipackets": 867955, + "obytes": 55549696, + "oerrors": 0, + "opackets": 867964, + "rx_bps": 104339032.0, + "rx_bps_L1": 136944984.0, + "rx_pps": 203787.2, + "rx_util": 1.36944984, + "tx_bps": 134126008.0, + "tx_bps_L1": 176040392.0, + "tx_pps": 261964.9, + "tx_util": 1.7604039200000001 + }, + 1: { + "ibytes": 55549696, + "ierrors": 0, + "ipackets": 867964, + "obytes": 55549120, + "oerrors": 0, + "opackets": 867955, + "rx_bps": 134119648.0, + "rx_bps_L1": 176032032.0, + "rx_pps": 261952.4, + "rx_util": 1.76032032, + "tx_bps": 104338192.0, + "tx_bps_L1": 136943872.0, + "tx_pps": 203785.5, + "tx_util": 1.36943872 + }, + "flow_stats": { + 1: { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 6400, + "1": 0, + "total": 6400 + }, + "rx_pkts": { + "0": 100, + "1": 0, + "total": 100 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 0, + "1": 6400, + "total": 6400 + }, + "tx_pkts": { + "0": 0, + "1": 100, + "total": 100 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + 2: { + "rx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "rx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "rx_bytes": { + "0": 0, + "1": 6464, + "total": 6464 + }, + "rx_pkts": { + "0": 0, + "1": 101, + "total": 101 + }, + "rx_pps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps": { + "0": 0, + "1": 0, + "total": 0 + }, + "tx_bps_l1": { + "0": 0.0, + "1": 0.0, + "total": 0.0 + }, + "tx_bytes": { + "0": 6464, + "1": 0, + "total": 6464 + }, + "tx_pkts": { + "0": 101, + "1": 0, + "total": 101 + }, + "tx_pps": { + "0": 0, + "1": 0, + "total": 0 + } + }, + "global": { + "rx_err": { + "0": 0, + "1": 0 + }, + "tx_err": { + "0": 0, + "1": 0 + } + } + }, + "global": { + "bw_per_core": 45.6, + "cpu_util": 0.1494, + "queue_full": 0, + "rx_bps": 238458672.0, + "rx_cpu_util": 4.751e-05, + "rx_drop_bps": 0.0, + "rx_pps": 465739.6, + "tx_bps": 238464208.0, + "tx_pps": 465750.4 + }, + "latency": { + 1: { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 63.375, + "histogram": { + "20": 1, + "30": 18, + "40": 12, + "50": 10, + "60": 12, + "70": 11, + "80": 6, + "90": 10, + "100": 20 + }, + "jitter": 23, + "last_max": 122, + "total_max": 123, + "total_min": 20 + } + }, + 2: { + "err_cntrs": { + "dropped": 0, + "dup": 0, + "out_of_order": 0, + "seq_too_high": 0, + "seq_too_low": 0 + }, + "latency": { + "average": 74, + "histogram": { + "60": 20, + "70": 10, + "80": 3, + "90": 4, + "100": 64 + }, + "jitter": 6, + "last_max": 83, + "total_max": 135, + "total_min": 60 + } + }, + "global": { + "bad_hdr": 0, + "old_flow": 0 + } + }, + "total": { + "ibytes": 111098816, + "ierrors": 0, + "ipackets": 1735919, + "obytes": 111098816, + "oerrors": 0, + "opackets": 1735919, + "rx_bps": 238458680.0, + "rx_bps_L1": 312977016.0, + "rx_pps": 465739.6, + "rx_util": 3.1297701599999996, + "tx_bps": 238464200.0, + "tx_bps_L1": 312984264.0, + "tx_pps": 465750.4, + "tx_util": 3.12984264 + } + } + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0) + vpp_rfc.client = mock.Mock() + vpp_rfc.client.get_warnings.return_value = 'get_warnings' + vpp_rfc.client.get_stats.return_value = stats + port_pg_id = rfc2544.PortPgIDMap() + port_pg_id.add_port(1) + port_pg_id.increase_pg_id() + port_pg_id.add_port(0) + port_pg_id.increase_pg_id() + self.assertEqual(stats, + vpp_rfc.send_traffic_on_tg([0, 1], port_pg_id, 30, + 10000, True)) + + def test_send_traffic_on_tg_error(self): + mock_setup_helper = mock.Mock() + vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper) + vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0) + vpp_rfc.client = mock.Mock() + vpp_rfc.client.get_warnings.return_value = 'get_warnings' + vpp_rfc.client.get_stats.side_effect = STLError('get_stats') + vpp_rfc.client.wait_on_traffic.side_effect = STLError( + 'wait_on_traffic') + port_pg_id = rfc2544.PortPgIDMap() + port_pg_id.add_port(1) + port_pg_id.increase_pg_id() + port_pg_id.add_port(0) + port_pg_id.increase_pg_id() + # with self.assertRaises(RuntimeError) as raised: + vpp_rfc.send_traffic_on_tg([0, 1], port_pg_id, 30, 10000, True) + # self.assertIn('TRex stateless runtime error', str(raised.exception)) + + +class TestTrexTrafficGenVpp(unittest.TestCase): + VNFD_0 = { + "benchmark": { + "kpi": [ + "rx_throughput_fps", + "tx_throughput_fps", + "tx_throughput_mbps", + "rx_throughput_mbps", + "in_packets", + "out_packets", + "min_latency", + "max_latency", + "avg_latency" + ] + }, + "description": "TRex stateless traffic verifier", + "id": "TrexTrafficGenVpp", + "mgmt-interface": { + "ip": "10.10.10.10", + "password": "r00t", + "user": "root", + "vdu-id": "trexgen-baremetal" + }, + "name": "trexverifier", + "short-name": "trexverifier", + "vdu": [ + { + "description": "TRex stateless traffic verifier", + "external-interface": [ + { + "name": "xe0", + "virtual-interface": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:ff:06.0" + }, + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "vnfd-connection-point-ref": "xe0" + }, + { + "name": "xe1", + "virtual-interface": { + "dpdk_port_num": 1, + "driver": "igb_uio", + "dst_ip": "192.168.101.2", + "dst_mac": "90:e2:ba:7c:41:a9", + "ifname": "xe1", + "local_ip": "192.168.101.1", + "local_mac": "90:e2:ba:7c:30:e9", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "192.168.101.1", + "dst_mac": "90:e2:ba:7c:30:e9", + "ifname": "xe0", + "local_ip": "192.168.101.2", + "local_mac": "90:e2:ba:7c:41:a9", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "tg__0", + "vld_id": "downlink_0", + "vpci": "0000:ff:06.0" + }, + "peer_name": "vnf__1", + "vld_id": "downlink_0", + "vpci": "0000:81:00.1" + }, + "vnfd-connection-point-ref": "xe1" + } + ], + "id": "trexgen-baremetal", + "name": "trexgen-baremetal" + } + ] + } + + VNFD = { + 'vnfd:vnfd-catalog': { + 'vnfd': [ + VNFD_0, + ], + }, + } + + def setUp(self): + self._mock_ssh_helper = mock.patch.object(sample_vnf, 'VnfSshHelper') + self.mock_ssh_helper = self._mock_ssh_helper.start() + self.addCleanup(self._stop_mocks) + + def _stop_mocks(self): + self._mock_ssh_helper.stop() + + def test___init__(self): + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp( + 'tg0', self.VNFD_0) + self.assertIsNotNone( + trex_traffic_gen.resource_helper._terminated.value) + + def test__check_status(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp('tg0', vnfd) + trex_traffic_gen.ssh_helper = mock.MagicMock() + trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() + trex_traffic_gen.resource_helper.ssh_helper.execute.return_value = 0, '', '' + trex_traffic_gen.scenario_helper.scenario_cfg = {} + self.assertEqual(0, trex_traffic_gen._check_status()) + + def test__start_server(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp('tg0', vnfd) + trex_traffic_gen.ssh_helper = mock.MagicMock() + trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() + trex_traffic_gen.scenario_helper.scenario_cfg = {} + self.assertIsNone(trex_traffic_gen._start_server()) + + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', + return_value='mock_node') + def test_collect_kpi(self, *args): + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp( + 'tg0', self.VNFD_0) + trex_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {trex_traffic_gen.name: "mock"} + } + expected = { + 'physical_node': 'mock_node', + 'collect_stats': {}, + } + self.assertEqual(trex_traffic_gen.collect_kpi(), expected) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate(self, *args): + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp( + 'tg0', self.VNFD_0) + trex_traffic_gen._start_server = mock.Mock(return_value=0) + trex_traffic_gen.resource_helper = mock.MagicMock() + trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() + + scenario_cfg = { + "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B", + "topology": 'nsb_test_case.yaml', + 'options': { + 'packetsize': 64, + 'traffic_type': 4, + 'rfc2544': { + 'allowed_drop_rate': '0.8 - 1', + }, + 'vnf__0': { + 'rules': 'acl_1rule.yaml', + 'vnf_config': { + 'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': '1C/1T', + 'worker_threads': 1 + }, + }, + }, + } + tg_trex_vpp.WAIT_TIME = 3 + scenario_cfg.update({"nodes": {"tg0": {}, "vnf0": {}}}) + self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {})) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate_error(self, *args): + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp( + 'tg0', self.VNFD_0) + trex_traffic_gen.resource_helper = mock.MagicMock() + trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() + scenario_cfg = { + "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B", + "nodes": { + "tg0": {}, + "vnf0": {} + }, + "topology": 'nsb_test_case.yaml', + 'options': { + 'packetsize': 64, + 'traffic_type': 4, + 'rfc2544': { + 'allowed_drop_rate': '0.8 - 1', + }, + 'vnf__0': { + 'rules': 'acl_1rule.yaml', + 'vnf_config': { + 'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': '1C/1T', + 'worker_threads': 1, + }, + }, + }, + } + trex_traffic_gen.instantiate(scenario_cfg, {}) + + @mock.patch( + 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper') + def test_wait_for_instantiate(self, ssh, *args): + mock_ssh(ssh) + + mock_process = mock.Mock(autospec=Process) + mock_process.is_alive.return_value = True + mock_process.exitcode = 432 + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + trex_traffic_gen = tg_trex_vpp.TrexTrafficGenVpp('tg0', vnfd) + trex_traffic_gen.ssh_helper = mock.MagicMock() + trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() + trex_traffic_gen.resource_helper.ssh_helper.execute.return_value = 0, '', '' + trex_traffic_gen.scenario_helper.scenario_cfg = {} + trex_traffic_gen._tg_process = mock_process + self.assertEqual(432, trex_traffic_gen.wait_for_instantiate()) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_vcmts_pktgen.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_vcmts_pktgen.py new file mode 100755 index 000000000..3b226d3f1 --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_vcmts_pktgen.py @@ -0,0 +1,652 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import mock +import socket +import threading +import time +import os +import copy + +from yardstick.benchmark.contexts import base as ctx_base +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper +from yardstick.network_services.vnf_generic.vnf import tg_vcmts_pktgen +from yardstick.common import exceptions + + +NAME = "tg__0" + + +class TestPktgenHelper(unittest.TestCase): + + def test___init__(self): + pktgen_helper = tg_vcmts_pktgen.PktgenHelper("localhost", 23000) + self.assertEqual(pktgen_helper.host, "localhost") + self.assertEqual(pktgen_helper.port, 23000) + self.assertFalse(pktgen_helper.connected) + + def _run_fake_server(self): + server_sock = socket.socket() + server_sock.bind(('localhost', 23000)) + server_sock.listen(0) + client_socket, _ = server_sock.accept() + client_socket.close() + server_sock.close() + + def test__connect(self): + pktgen_helper = tg_vcmts_pktgen.PktgenHelper("localhost", 23000) + self.assertFalse(pktgen_helper._connect()) + server_thread = threading.Thread(target=self._run_fake_server) + server_thread.start() + time.sleep(0.5) + self.assertTrue(pktgen_helper._connect()) + pktgen_helper._sock.close() + server_thread.join() + + @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_vcmts_pktgen.time') + def test_connect(self, *args): + pktgen_helper = tg_vcmts_pktgen.PktgenHelper("localhost", 23000) + pktgen_helper.connected = True + self.assertTrue(pktgen_helper.connect()) + pktgen_helper.connected = False + + pktgen_helper._connect = mock.MagicMock(return_value=True) + self.assertTrue(pktgen_helper.connect()) + self.assertTrue(pktgen_helper.connected) + + pktgen_helper = tg_vcmts_pktgen.PktgenHelper("localhost", 23000) + pktgen_helper._connect = mock.MagicMock(return_value=False) + self.assertFalse(pktgen_helper.connect()) + self.assertFalse(pktgen_helper.connected) + + def test_send_command(self): + pktgen_helper = tg_vcmts_pktgen.PktgenHelper("localhost", 23000) + self.assertFalse(pktgen_helper.send_command("")) + + pktgen_helper.connected = True + pktgen_helper._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.assertFalse(pktgen_helper.send_command("")) + + pktgen_helper._sock = mock.MagicMock() + self.assertTrue(pktgen_helper.send_command("")) + + +class TestVcmtsPktgenSetupEnvHelper(unittest.TestCase): + + PKTGEN_PARAMETERS = "export LUA_PATH=/vcmts/Pktgen.lua;"\ + "export CMK_PROC_FS=/host/proc;"\ + " /pktgen-config/setup.sh 0 4 18:02.0 "\ + "18:02.1 18:02.2 18:02.3 00:00.0 00:00.0 "\ + "00:00.0 00:00.0 imix1_100cms_1ofdm.pcap "\ + "imix1_100cms_1ofdm.pcap imix1_100cms_1ofdm.pcap "\ + "imix1_100cms_1ofdm.pcap imix1_100cms_1ofdm.pcap "\ + "imix1_100cms_1ofdm.pcap imix1_100cms_1ofdm.pcap "\ + "imix1_100cms_1ofdm.pcap" + + OPTIONS = { + "pktgen_values": "/tmp/pktgen_values.yaml", + "tg__0": { + "pktgen_id": 0 + }, + "vcmts_influxdb_ip": "10.80.5.150", + "vcmts_influxdb_port": 8086, + "vcmtsd_values": "/tmp/vcmtsd_values.yaml", + "vnf__0": { + "sg_id": 0, + "stream_dir": "us" + }, + "vnf__1": { + "sg_id": 0, + "stream_dir": "ds" + } + } + + def setUp(self): + vnfd_helper = VnfdHelper( + TestVcmtsPktgen.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + + self.setup_helper = tg_vcmts_pktgen.VcmtsPktgenSetupEnvHelper( + vnfd_helper, ssh_helper, scenario_helper) + + def test_generate_pcap_filename(self): + pcap_file_name = self.setup_helper.generate_pcap_filename(\ + TestVcmtsPktgen.PKTGEN_POD_VALUES[0]['ports'][0]) + self.assertEquals(pcap_file_name, "imix1_100cms_1ofdm.pcap") + + def test_find_port_cfg(self): + port_cfg = self.setup_helper.find_port_cfg(\ + TestVcmtsPktgen.PKTGEN_POD_VALUES[0]['ports'], "port_0") + self.assertIsNotNone(port_cfg) + + port_cfg = self.setup_helper.find_port_cfg(\ + TestVcmtsPktgen.PKTGEN_POD_VALUES[0]['ports'], "port_8") + self.assertIsNone(port_cfg) + + def test_build_pktgen_parameters(self): + parameters = self.setup_helper.build_pktgen_parameters( + TestVcmtsPktgen.PKTGEN_POD_VALUES[0]) + self.assertEquals(parameters, self.PKTGEN_PARAMETERS) + + def test_start_pktgen(self): + self.setup_helper.ssh_helper = mock.MagicMock() + self.setup_helper.start_pktgen(TestVcmtsPktgen.PKTGEN_POD_VALUES[0]) + self.setup_helper.ssh_helper.send_command.assert_called_with( + self.PKTGEN_PARAMETERS) + + def test_setup_vnf_environment(self): + self.assertIsNone(self.setup_helper.setup_vnf_environment()) + +class TestVcmtsPktgen(unittest.TestCase): + + VNFD = {'vnfd:vnfd-catalog': + {'vnfd': + [{ + "benchmark": { + "kpi": [ + "upstream/bits_per_second" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "vCMTS Pktgen Kubernetes", + "id": "VcmtsPktgen", + "mgmt-interface": { + "ip": "192.168.24.150", + "key_filename": "/tmp/yardstick_key-a3b663c2", + "user": "root", + "vdu-id": "vcmtspktgen-kubernetes" + }, + "name": "vcmtspktgen", + "short-name": "vcmtspktgen", + "vdu": [ + { + "description": "vCMTS Pktgen Kubernetes", + "external-interface": [], + "id": "vcmtspktgen-kubernetes", + "name": "vcmtspktgen-kubernetes" + } + ], + "vm-flavor": { + "memory-mb": "4096", + "vcpu-count": "4" + } + }] + }} + + PKTGEN_POD_VALUES = [ + { + "num_ports": "4", + "pktgen_id": "0", + "ports": [ + { + "net_pktgen": "18:02.0", + "num_ofdm": "1", + "num_subs": "100", + "port_0": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "18:02.1", + "num_ofdm": "1", + "num_subs": "100", + "port_1": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "18:02.2", + "num_ofdm": "1", + "num_subs": "100", + "port_2": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "18:02.3", + "num_ofdm": "1", + "num_subs": "100", + "port_3": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_4": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_5": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_6": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_7": "", + "traffic_type": "imix1" + } + ] + }, + { + "num_ports": 4, + "pktgen_id": 1, + "ports": [ + { + "net_pktgen": "18:0a.0", + "num_ofdm": "1", + "num_subs": "100", + "port_0": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "18:0a.1", + "num_ofdm": "1", + "num_subs": "100", + "port_1": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "18:0a.2", + "num_ofdm": "1", + "num_subs": "100", + "port_2": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "18:0a.3", + "num_ofdm": "1", + "num_subs": "100", + "port_3": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_4": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_5": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_6": "", + "traffic_type": "imix1" + }, + { + "net_pktgen": "00:00.0", + "num_ofdm": "1", + "num_subs": "100", + "port_7": "", + "traffic_type": "imix1" + } + ] + } + ] + + SCENARIO_CFG = { + "nodes": { + "tg__0": "pktgen0-k8syardstick-a3b663c2", + "vnf__0": "vnf0us-k8syardstick-a3b663c2", + "vnf__1": "vnf0ds-k8syardstick-a3b663c2" + }, + "options": { + "pktgen_values": "/tmp/pktgen_values.yaml", + "tg__0": { + "pktgen_id": 0 + }, + "vcmts_influxdb_ip": "10.80.5.150", + "vcmts_influxdb_port": 8086, + "vcmtsd_values": "/tmp/vcmtsd_values.yaml", + "vnf__0": { + "sg_id": 0, + "stream_dir": "us" + }, + "vnf__1": { + "sg_id": 0, + "stream_dir": "ds" + } + }, + "task_id": "a3b663c2-e616-4777-b6d0-ec2ea7a06f42", + "task_path": "samples/vnf_samples/nsut/cmts", + "tc": "tc_vcmts_k8s_pktgen", + "topology": "k8s_vcmts_topology.yaml", + "traffic_profile": "../../traffic_profiles/fixed.yaml", + "type": "NSPerf" + } + + CONTEXT_CFG = { + "networks": { + "flannel": { + "name": "flannel" + }, + "xe0": { + "name": "xe0" + }, + "xe1": { + "name": "xe1" + } + }, + "nodes": { + "tg__0": { + "VNF model": "../../vnf_descriptors/tg_vcmts_tpl.yaml", + "interfaces": { + "flannel": { + "local_ip": "192.168.24.150", + "local_mac": None, + "network_name": "flannel" + }, + "xe0": { + "local_ip": "192.168.24.150", + "local_mac": None, + "network_name": "xe0" + }, + "xe1": { + "local_ip": "192.168.24.150", + "local_mac": None, + "network_name": "xe1" + } + }, + "ip": "192.168.24.150", + "key_filename": "/tmp/yardstick_key-a3b663c2", + "member-vnf-index": "1", + "name": "pktgen0-k8syardstick-a3b663c2", + "private_ip": "192.168.24.150", + "service_ports": [ + { + "name": "ssh", + "node_port": 60270, + "port": 22, + "protocol": "TCP", + "target_port": 22 + }, + { + "name": "lua", + "node_port": 43619, + "port": 22022, + "protocol": "TCP", + "target_port": 22022 + } + ], + "ssh_port": 60270, + "user": "root", + "vnfd-id-ref": "tg__0" + }, + "vnf__0": { + "VNF model": "../../vnf_descriptors/vnf_vcmts_tpl.yaml", + "interfaces": { + "flannel": { + "local_ip": "192.168.100.132", + "local_mac": None, + "network_name": "flannel" + }, + "xe0": { + "local_ip": "192.168.100.132", + "local_mac": None, + "network_name": "xe0" + }, + "xe1": { + "local_ip": "192.168.100.132", + "local_mac": None, + "network_name": "xe1" + } + }, + "ip": "192.168.100.132", + "key_filename": "/tmp/yardstick_key-a3b663c2", + "member-vnf-index": "3", + "name": "vnf0us-k8syardstick-a3b663c2", + "private_ip": "192.168.100.132", + "service_ports": [ + { + "name": "ssh", + "node_port": 57057, + "port": 22, + "protocol": "TCP", + "target_port": 22 + }, + { + "name": "lua", + "node_port": 29700, + "port": 22022, + "protocol": "TCP", + "target_port": 22022 + } + ], + "ssh_port": 57057, + "user": "root", + "vnfd-id-ref": "vnf__0" + }, + "vnf__1": { + "VNF model": "../../vnf_descriptors/vnf_vcmts_tpl.yaml", + "interfaces": { + "flannel": { + "local_ip": "192.168.100.134", + "local_mac": None, + "network_name": "flannel" + }, + "xe0": { + "local_ip": "192.168.100.134", + "local_mac": None, + "network_name": "xe0" + }, + "xe1": { + "local_ip": "192.168.100.134", + "local_mac": None, + "network_name": "xe1" + } + }, + "ip": "192.168.100.134", + "key_filename": "/tmp/yardstick_key-a3b663c2", + "member-vnf-index": "4", + "name": "vnf0ds-k8syardstick-a3b663c2", + "private_ip": "192.168.100.134", + "service_ports": [ + { + "name": "ssh", + "node_port": 18581, + "port": 22, + "protocol": "TCP", + "target_port": 22 + }, + { + "name": "lua", + "node_port": 18469, + "port": 22022, + "protocol": "TCP", + "target_port": 22022 + } + ], + "ssh_port": 18581, + "user": "root", + "vnfd-id-ref": "vnf__1" + } + } + } + + PKTGEN_VALUES_PATH = "/tmp/pktgen_values.yaml" + + PKTGEN_VALUES = \ + "serviceAccount: cmk-serviceaccount\n" \ + "images:\n" \ + " vcmts_pktgen: vcmts-pktgen:v18.10\n" \ + "topology:\n" \ + " pktgen_replicas: 8\n" \ + " pktgen_pods:\n" \ + " - pktgen_id: 0\n" \ + " num_ports: 4\n" \ + " ports:\n" \ + " - port_0:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.0\n" \ + " - port_1:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.1\n" \ + " - port_2:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.2\n" \ + " - port_3:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.3\n" \ + " - port_4:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.4\n" \ + " - port_5:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.5\n" \ + " - port_6:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.6\n" \ + " - port_7:\n" \ + " traffic_type: 'imix2'\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " net_pktgen: 8a:02.7\n" + + def setUp(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + self.vcmts_pktgen = tg_vcmts_pktgen.VcmtsPktgen(NAME, vnfd) + self.vcmts_pktgen._start_server = mock.Mock(return_value=0) + self.vcmts_pktgen.resource_helper = mock.MagicMock() + self.vcmts_pktgen.setup_helper = mock.MagicMock() + + def test___init__(self): + self.assertFalse(self.vcmts_pktgen.traffic_finished) + self.assertIsNotNone(self.vcmts_pktgen.setup_helper) + self.assertIsNotNone(self.vcmts_pktgen.resource_helper) + + def test_extract_pod_cfg(self): + pod_cfg = self.vcmts_pktgen.extract_pod_cfg(self.PKTGEN_POD_VALUES, "0") + self.assertIsNotNone(pod_cfg) + self.assertEqual(pod_cfg["pktgen_id"], "0") + pod_cfg = self.vcmts_pktgen.extract_pod_cfg(self.PKTGEN_POD_VALUES, "4") + self.assertIsNone(pod_cfg) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate_missing_pktgen_values_key(self, *args): + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options'].pop('pktgen_values', None) + with self.assertRaises(KeyError): + self.vcmts_pktgen.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate_missing_pktgen_values_file(self, *args): + if os.path.isfile(self.PKTGEN_VALUES_PATH): + os.remove(self.PKTGEN_VALUES_PATH) + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options']['pktgen_values'] = self.PKTGEN_VALUES_PATH + with self.assertRaises(RuntimeError): + self.vcmts_pktgen.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate_empty_pktgen_values_file(self, *args): + yaml_sample = open(self.PKTGEN_VALUES_PATH, 'w') + yaml_sample.write("") + yaml_sample.close() + + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options']['pktgen_values'] = self.PKTGEN_VALUES_PATH + with self.assertRaises(RuntimeError): + self.vcmts_pktgen.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + if os.path.isfile(self.PKTGEN_VALUES_PATH): + os.remove(self.PKTGEN_VALUES_PATH) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate_invalid_pktgen_id(self, *args): + yaml_sample = open(self.PKTGEN_VALUES_PATH, 'w') + yaml_sample.write(self.PKTGEN_VALUES) + yaml_sample.close() + + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options'][NAME]['pktgen_id'] = 12 + with self.assertRaises(KeyError): + self.vcmts_pktgen.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + if os.path.isfile(self.PKTGEN_VALUES_PATH): + os.remove(self.PKTGEN_VALUES_PATH) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', + return_value='fake_context') + def test_instantiate_all_valid(self, *args): + yaml_sample = open(self.PKTGEN_VALUES_PATH, 'w') + yaml_sample.write(self.PKTGEN_VALUES) + yaml_sample.close() + + self.vcmts_pktgen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG) + self.assertIsNotNone(self.vcmts_pktgen.pod_cfg) + self.assertEqual(self.vcmts_pktgen.pod_cfg["pktgen_id"], "0") + + if os.path.isfile(self.PKTGEN_VALUES_PATH): + os.remove(self.PKTGEN_VALUES_PATH) + + def test_run_traffic_failed_connect(self): + self.vcmts_pktgen.pktgen_helper = mock.MagicMock() + self.vcmts_pktgen.pktgen_helper.connect.return_value = False + with self.assertRaises(exceptions.PktgenActionError): + self.vcmts_pktgen.run_traffic({}) + + def test_run_traffic_successful_connect(self): + self.vcmts_pktgen.pktgen_helper = mock.MagicMock() + self.vcmts_pktgen.pktgen_helper.connect.return_value = True + self.vcmts_pktgen.pktgen_rate = 8.0 + self.assertTrue(self.vcmts_pktgen.run_traffic({})) + self.vcmts_pktgen.pktgen_helper.connect.assert_called_once() + self.vcmts_pktgen.pktgen_helper.send_command.assert_called_with( + 'pktgen.start("all");') diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py index 60f739543..aabd402a6 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -329,9 +329,9 @@ class TestUdpReplayApproxVnf(unittest.TestCase): vnfd = self.VNFD_0 get_stats_ret_val = \ "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \ - "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\ - "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \ - "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>" + "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop\t\tarp_pkts \r\n"\ + "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\t\t\t0\r\n" \ + "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>" udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) udp_replay_approx_vnf.scenario_helper.scenario_cfg = { 'nodes': {udp_replay_approx_vnf.name: "mock"} diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vcmts_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vcmts_vnf.py new file mode 100755 index 000000000..11e3d6e17 --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vcmts_vnf.py @@ -0,0 +1,651 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import mock +import copy +import os + +from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper +from yardstick.network_services.vnf_generic.vnf import vcmts_vnf +from yardstick.common import exceptions + +from influxdb.resultset import ResultSet + +NAME = "vnf__0" + + +class TestInfluxDBHelper(unittest.TestCase): + + def test___init__(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + self.assertEqual(influxdb_helper._vcmts_influxdb_ip, "localhost") + self.assertEqual(influxdb_helper._vcmts_influxdb_port, 8086) + self.assertIsNotNone(influxdb_helper._last_upstream_rx) + self.assertIsNotNone(influxdb_helper._last_values_time) + + def test_start(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + influxdb_helper.start() + self.assertIsNotNone(influxdb_helper._read_client) + self.assertIsNotNone(influxdb_helper._write_client) + + def test__get_last_value_time(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + self.assertEqual(influxdb_helper._get_last_value_time('cpu_value'), + vcmts_vnf.InfluxDBHelper.INITIAL_VALUE) + + influxdb_helper._last_values_time['cpu_value'] = "RANDOM" + self.assertEqual(influxdb_helper._get_last_value_time('cpu_value'), + "RANDOM") + + def test__set_last_value_time(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + influxdb_helper._set_last_value_time('cpu_value', '00:00') + self.assertEqual(influxdb_helper._last_values_time['cpu_value'], + "'00:00'") + + def test__query_measurement(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + influxdb_helper._read_client = mock.MagicMock() + + resulted_generator = mock.MagicMock() + resulted_generator.keys.return_value = [] + influxdb_helper._read_client.query.return_value = resulted_generator + query_result = influxdb_helper._query_measurement('cpu_value') + self.assertIsNone(query_result) + + resulted_generator = mock.MagicMock() + resulted_generator.keys.return_value = ["", ""] + resulted_generator.get_points.return_value = ResultSet({"":""}) + influxdb_helper._read_client.query.return_value = resulted_generator + query_result = influxdb_helper._query_measurement('cpu_value') + self.assertIsNotNone(query_result) + + def test__rw_measurment(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + influxdb_helper._query_measurement = mock.MagicMock() + influxdb_helper._query_measurement.return_value = None + influxdb_helper._rw_measurment('cpu_value', []) + self.assertEqual(len(influxdb_helper._last_values_time), 0) + + entry = { + "type":"type", + "host":"host", + "time":"time", + "id": "1", + "value": "1.0" + } + influxdb_helper._query_measurement.return_value = [entry] + influxdb_helper._write_client = mock.MagicMock() + influxdb_helper._rw_measurment('cpu_value', ["id", "value"]) + self.assertEqual(len(influxdb_helper._last_values_time), 1) + influxdb_helper._write_client.write_points.assert_called_once() + + def test_copy_kpi(self): + influxdb_helper = vcmts_vnf.InfluxDBHelper("localhost", 8086) + influxdb_helper._rw_measurment = mock.MagicMock() + influxdb_helper.copy_kpi() + influxdb_helper._rw_measurment.assert_called() + + +class TestVcmtsdSetupEnvHelper(unittest.TestCase): + POD_CFG = { + "cm_crypto": "aes", + "cpu_socket_id": "0", + "ds_core_pool_index": "2", + "ds_core_type": "exclusive", + "net_ds": "1a:02.1", + "net_us": "1a:02.0", + "num_ofdm": "1", + "num_subs": "100", + "power_mgmt": "pm_on", + "qat": "qat_off", + "service_group_config": "", + "sg_id": "0", + "vcmtsd_image": "vcmts-d:perf" + } + + OPTIONS = { + "pktgen_values": "/tmp/pktgen_values.yaml", + "tg__0": { + "pktgen_id": 0 + }, + "vcmts_influxdb_ip": "10.80.5.150", + "vcmts_influxdb_port": 8086, + "vcmtsd_values": "/tmp/vcmtsd_values.yaml", + "vnf__0": { + "sg_id": 0, + "stream_dir": "us" + }, + "vnf__1": { + "sg_id": 0, + "stream_dir": "ds" + } + } + + def setUp(self): + vnfd_helper = VnfdHelper( + TestVcmtsVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + + self.setup_helper = vcmts_vnf.VcmtsdSetupEnvHelper( + vnfd_helper, ssh_helper, scenario_helper) + + def _build_us_parameters(self): + return vcmts_vnf.VcmtsdSetupEnvHelper.BASE_PARAMETERS + " " \ + + " /opt/bin/cmk isolate --conf-dir=/etc/cmk" \ + + " --socket-id=" + str(self.POD_CFG['cpu_socket_id']) \ + + " --pool=shared" \ + + " /vcmts-config/run_upstream.sh " + self.POD_CFG['sg_id'] \ + + " " + self.POD_CFG['ds_core_type'] \ + + " " + str(self.POD_CFG['num_ofdm']) + "ofdm" \ + + " " + str(self.POD_CFG['num_subs']) + "cm" \ + + " " + self.POD_CFG['cm_crypto'] \ + + " " + self.POD_CFG['qat'] \ + + " " + self.POD_CFG['net_us'] \ + + " " + self.POD_CFG['power_mgmt'] + + def test_build_us_parameters(self): + constructed = self._build_us_parameters() + result = self.setup_helper.build_us_parameters(self.POD_CFG) + self.assertEqual(constructed, result) + + def _build_ds_parameters(self): + return vcmts_vnf.VcmtsdSetupEnvHelper.BASE_PARAMETERS + " " \ + + " /opt/bin/cmk isolate --conf-dir=/etc/cmk" \ + + " --socket-id=" + str(self.POD_CFG['cpu_socket_id']) \ + + " --pool=" + self.POD_CFG['ds_core_type'] \ + + " /vcmts-config/run_downstream.sh " + self.POD_CFG['sg_id'] \ + + " " + self.POD_CFG['ds_core_type'] \ + + " " + str(self.POD_CFG['ds_core_pool_index']) \ + + " " + str(self.POD_CFG['num_ofdm']) + "ofdm" \ + + " " + str(self.POD_CFG['num_subs']) + "cm" \ + + " " + self.POD_CFG['cm_crypto'] \ + + " " + self.POD_CFG['qat'] \ + + " " + self.POD_CFG['net_ds'] \ + + " " + self.POD_CFG['power_mgmt'] + + def test_build_ds_parameters(self): + constructed = self._build_ds_parameters() + result = self.setup_helper.build_ds_parameters(self.POD_CFG) + self.assertEqual(constructed, result) + + def test_build_cmd(self): + us_constructed = self._build_us_parameters() + us_result = self.setup_helper.build_cmd('us', self.POD_CFG) + self.assertEqual(us_constructed, us_result) + ds_constructed = self._build_ds_parameters() + ds_result = self.setup_helper.build_cmd('ds', self.POD_CFG) + self.assertEqual(ds_constructed, ds_result) + + def test_run_vcmtsd(self): + us_constructed = self._build_us_parameters() + + vnfd_helper = VnfdHelper( + TestVcmtsVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + ssh_helper = mock.MagicMock() + scenario_helper = mock.Mock() + scenario_helper.options = self.OPTIONS + + setup_helper = vcmts_vnf.VcmtsdSetupEnvHelper( + vnfd_helper, ssh_helper, scenario_helper) + + setup_helper.run_vcmtsd('us', self.POD_CFG) + ssh_helper.send_command.assert_called_with(us_constructed) + + def test_setup_vnf_environment(self): + self.assertIsNone(self.setup_helper.setup_vnf_environment()) + +class TestVcmtsVNF(unittest.TestCase): + + VNFD = {'vnfd:vnfd-catalog': + {'vnfd': + [{ + "benchmark": { + "kpi": [ + "upstream/bits_per_second" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "vCMTS Upstream-Downstream Kubernetes", + "id": "VcmtsVNF", + "mgmt-interface": { + "ip": "192.168.100.35", + "key_filename": "/tmp/yardstick_key-81dcca91", + "user": "root", + "vdu-id": "vcmtsvnf-kubernetes" + }, + "name": "vcmtsvnf", + "short-name": "vcmtsvnf", + "vdu": [ + { + "description": "vCMTS Upstream-Downstream Kubernetes", + "external-interface": [], + "id": "vcmtsvnf-kubernetes", + "name": "vcmtsvnf-kubernetes" + } + ], + "vm-flavor": { + "memory-mb": "4096", + "vcpu-count": "4" + } + }] + } + } + + POD_CFG = [ + { + "cm_crypto": "aes", + "cpu_socket_id": "0", + "ds_core_pool_index": "2", + "ds_core_type": "exclusive", + "net_ds": "1a:02.1", + "net_us": "1a:02.0", + "num_ofdm": "1", + "num_subs": "100", + "power_mgmt": "pm_on", + "qat": "qat_off", + "service_group_config": "", + "sg_id": "0", + "vcmtsd_image": "vcmts-d:perf" + }, + ] + + SCENARIO_CFG = { + "nodes": { + "tg__0": "pktgen0-k8syardstick-afae18b2", + "vnf__0": "vnf0us-k8syardstick-afae18b2", + "vnf__1": "vnf0ds-k8syardstick-afae18b2" + }, + "options": { + "pktgen_values": "/tmp/pktgen_values.yaml", + "tg__0": { + "pktgen_id": 0 + }, + "vcmts_influxdb_ip": "10.80.5.150", + "vcmts_influxdb_port": 8086, + "vcmtsd_values": "/tmp/vcmtsd_values.yaml", + "vnf__0": { + "sg_id": 0, + "stream_dir": "us" + }, + "vnf__1": { + "sg_id": 0, + "stream_dir": "ds" + } + }, + "task_id": "afae18b2-9902-477f-8128-49afde7c3040", + "task_path": "samples/vnf_samples/nsut/cmts", + "tc": "tc_vcmts_k8s_pktgen", + "topology": "k8s_vcmts_topology.yaml", + "traffic_profile": "../../traffic_profiles/fixed.yaml", + "type": "NSPerf" + } + + CONTEXT_CFG = { + "networks": { + "flannel": { + "name": "flannel" + }, + "xe0": { + "name": "xe0" + }, + "xe1": { + "name": "xe1" + } + }, + "nodes": { + "tg__0": { + "VNF model": "../../vnf_descriptors/tg_vcmts_tpl.yaml", + "interfaces": { + "flannel": { + "local_ip": "192.168.24.110", + "local_mac": None, + "network_name": "flannel" + }, + "xe0": { + "local_ip": "192.168.24.110", + "local_mac": None, + "network_name": "xe0" + }, + "xe1": { + "local_ip": "192.168.24.110", + "local_mac": None, + "network_name": "xe1" + } + }, + "ip": "192.168.24.110", + "key_filename": "/tmp/yardstick_key-afae18b2", + "member-vnf-index": "1", + "name": "pktgen0-k8syardstick-afae18b2", + "private_ip": "192.168.24.110", + "service_ports": [ + { + "name": "ssh", + "node_port": 17153, + "port": 22, + "protocol": "TCP", + "target_port": 22 + }, + { + "name": "lua", + "node_port": 51250, + "port": 22022, + "protocol": "TCP", + "target_port": 22022 + } + ], + "ssh_port": 17153, + "user": "root", + "vnfd-id-ref": "tg__0" + }, + "vnf__0": { + "VNF model": "../../vnf_descriptors/vnf_vcmts_tpl.yaml", + "interfaces": { + "flannel": { + "local_ip": "192.168.100.53", + "local_mac": None, + "network_name": "flannel" + }, + "xe0": { + "local_ip": "192.168.100.53", + "local_mac": None, + "network_name": "xe0" + }, + "xe1": { + "local_ip": "192.168.100.53", + "local_mac": None, + "network_name": "xe1" + } + }, + "ip": "192.168.100.53", + "key_filename": "/tmp/yardstick_key-afae18b2", + "member-vnf-index": "3", + "name": "vnf0us-k8syardstick-afae18b2", + "private_ip": "192.168.100.53", + "service_ports": [ + { + "name": "ssh", + "node_port": 34027, + "port": 22, + "protocol": "TCP", + "target_port": 22 + }, + { + "name": "lua", + "node_port": 32580, + "port": 22022, + "protocol": "TCP", + "target_port": 22022 + } + ], + "ssh_port": 34027, + "user": "root", + "vnfd-id-ref": "vnf__0" + }, + "vnf__1": { + "VNF model": "../../vnf_descriptors/vnf_vcmts_tpl.yaml", + "interfaces": { + "flannel": { + "local_ip": "192.168.100.52", + "local_mac": None, + "network_name": "flannel" + }, + "xe0": { + "local_ip": "192.168.100.52", + "local_mac": None, + "network_name": "xe0" + }, + "xe1": { + "local_ip": "192.168.100.52", + "local_mac": None, + "network_name": "xe1" + } + }, + "ip": "192.168.100.52", + "key_filename": "/tmp/yardstick_key-afae18b2", + "member-vnf-index": "4", + "name": "vnf0ds-k8syardstick-afae18b2", + "private_ip": "192.168.100.52", + "service_ports": [ + { + "name": "ssh", + "node_port": 58661, + "port": 22, + "protocol": "TCP", + "target_port": 22 + }, + { + "name": "lua", + "node_port": 58233, + "port": 22022, + "protocol": "TCP", + "target_port": 22022 + } + ], + "ssh_port": 58661, + "user": "root", + "vnfd-id-ref": "vnf__1" + }, + } + } + + VCMTSD_VALUES_PATH = "/tmp/vcmtsd_values.yaml" + + VCMTSD_VALUES = \ + "serviceAccount: cmk-serviceaccount\n" \ + "topology:\n" \ + " vcmts_replicas: 16\n" \ + " vcmts_pods:\n" \ + " - service_group_config:\n" \ + " sg_id: 0\n" \ + " net_us: 18:02.0\n" \ + " net_ds: 18:02.1\n" \ + " num_ofdm: 4\n" \ + " num_subs: 300\n" \ + " cm_crypto: aes\n" \ + " qat: qat_off\n" \ + " power_mgmt: pm_on\n" \ + " cpu_socket_id: 0\n" \ + " ds_core_type: exclusive\n" \ + " ds_core_pool_index: 0\n" \ + " vcmtsd_image: vcmts-d:feat" + + VCMTSD_VALUES_INCOMPLETE = \ + "serviceAccount: cmk-serviceaccount\n" \ + "topology:\n" \ + " vcmts_replicas: 16" + + def setUp(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + self.vnf = vcmts_vnf.VcmtsVNF(NAME, vnfd) + + def test___init__(self, *args): + self.assertIsNotNone(self.vnf.setup_helper) + + def test_extract_pod_cfg(self): + pod_cfg = self.vnf.extract_pod_cfg(self.POD_CFG, "0") + self.assertIsNotNone(pod_cfg) + self.assertEqual(pod_cfg['sg_id'], '0') + pod_cfg = self.vnf.extract_pod_cfg(self.POD_CFG, "1") + self.assertIsNone(pod_cfg) + + def test_instantiate_missing_influxdb_info(self): + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options'].pop('vcmts_influxdb_ip', None) + with self.assertRaises(KeyError): + self.vnf.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + def test_instantiate_missing_vcmtsd_values_file(self): + if os.path.isfile(self.VCMTSD_VALUES_PATH): + os.remove(self.VCMTSD_VALUES_PATH) + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options']['vcmtsd_values'] = self.VCMTSD_VALUES_PATH + with self.assertRaises(RuntimeError): + self.vnf.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + def test_instantiate_empty_vcmtsd_values_file(self): + yaml_sample = open(self.VCMTSD_VALUES_PATH, 'w') + yaml_sample.write("") + yaml_sample.close() + + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options']['vcmtsd_values'] = self.VCMTSD_VALUES_PATH + with self.assertRaises(RuntimeError): + self.vnf.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + if os.path.isfile(self.VCMTSD_VALUES_PATH): + os.remove(self.VCMTSD_VALUES_PATH) + + def test_instantiate_missing_vcmtsd_values_key(self): + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options'].pop('vcmtsd_values', None) + with self.assertRaises(KeyError): + self.vnf.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + def test_instantiate_invalid_vcmtsd_values(self): + yaml_sample = open(self.VCMTSD_VALUES_PATH, 'w') + yaml_sample.write(self.VCMTSD_VALUES_INCOMPLETE) + yaml_sample.close() + + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + with self.assertRaises(KeyError): + self.vnf.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + if os.path.isfile(self.VCMTSD_VALUES_PATH): + os.remove(self.VCMTSD_VALUES_PATH) + + def test_instantiate_invalid_sg_id(self): + yaml_sample = open(self.VCMTSD_VALUES_PATH, 'w') + yaml_sample.write(self.VCMTSD_VALUES) + yaml_sample.close() + + err_scenario_cfg = copy.deepcopy(self.SCENARIO_CFG) + err_scenario_cfg['options'][NAME]['sg_id'] = 8 + with self.assertRaises(exceptions.IncorrectConfig): + self.vnf.instantiate(err_scenario_cfg, self.CONTEXT_CFG) + + if os.path.isfile(self.VCMTSD_VALUES_PATH): + os.remove(self.VCMTSD_VALUES_PATH) + + @mock.patch('yardstick.network_services.vnf_generic.vnf.vcmts_vnf.VnfSshHelper') + def test_instantiate_all_valid(self, ssh, *args): + mock_ssh(ssh) + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vnf = vcmts_vnf.VcmtsVNF(NAME, vnfd) + + yaml_sample = open(self.VCMTSD_VALUES_PATH, 'w') + yaml_sample.write(self.VCMTSD_VALUES) + yaml_sample.close() + + vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG) + self.assertEqual(vnf.vcmts_influxdb_ip, "10.80.5.150") + self.assertEqual(vnf.vcmts_influxdb_port, 8086) + + if os.path.isfile(self.VCMTSD_VALUES_PATH): + os.remove(self.VCMTSD_VALUES_PATH) + + def test__update_collectd_options(self): + scenario_cfg = {'options': + {'collectd': + {'interval': 3, + 'plugins': + {'plugin3': {'param': 3}}}, + 'vnf__0': + {'collectd': + {'interval': 2, + 'plugins': + {'plugin3': {'param': 2}, + 'plugin2': {'param': 2}}}}}} + context_cfg = {'nodes': + {'vnf__0': + {'collectd': + {'interval': 1, + 'plugins': + {'plugin3': {'param': 1}, + 'plugin2': {'param': 1}, + 'plugin1': {'param': 1}}}}}} + expected = {'interval': 1, + 'plugins': + {'plugin3': {'param': 1}, + 'plugin2': {'param': 1}, + 'plugin1': {'param': 1}}} + + self.vnf._update_collectd_options(scenario_cfg, context_cfg) + self.assertEqual(self.vnf.setup_helper.collectd_options, expected) + + def test__update_options(self): + options1 = {'interval': 1, + 'param1': 'value1', + 'plugins': + {'plugin3': {'param': 3}, + 'plugin2': {'param': 1}, + 'plugin1': {'param': 1}}} + options2 = {'interval': 2, + 'param2': 'value2', + 'plugins': + {'plugin4': {'param': 4}, + 'plugin2': {'param': 2}, + 'plugin1': {'param': 2}}} + expected = {'interval': 1, + 'param1': 'value1', + 'param2': 'value2', + 'plugins': + {'plugin4': {'param': 4}, + 'plugin3': {'param': 3}, + 'plugin2': {'param': 1}, + 'plugin1': {'param': 1}}} + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vnf = vcmts_vnf.VcmtsVNF('vnf1', vnfd) + vnf._update_options(options2, options1) + self.assertEqual(options2, expected) + + def test_wait_for_instantiate(self): + self.assertIsNone(self.vnf.wait_for_instantiate()) + + def test_terminate(self): + self.assertIsNone(self.vnf.terminate()) + + def test_scale(self): + self.assertIsNone(self.vnf.scale()) + + def test_collect_kpi(self): + self.vnf.influxdb_helper = mock.MagicMock() + self.vnf.collect_kpi() + self.vnf.influxdb_helper.copy_kpi.assert_called_once() + + def test_start_collect(self): + self.vnf.vcmts_influxdb_ip = "localhost" + self.vnf.vcmts_influxdb_port = 8800 + + self.assertIsNone(self.vnf.start_collect()) + self.assertIsNotNone(self.vnf.influxdb_helper) + + def test_stop_collect(self): + self.assertIsNone(self.vnf.stop_collect()) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py index 5911948a3..5334ce18c 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vims_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vims_vnf.py new file mode 100644 index 000000000..d86dab8ad --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vims_vnf.py @@ -0,0 +1,713 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License,Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing,software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import mock + +from yardstick.network_services.vnf_generic.vnf import vims_vnf +from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh + + +class TestVimsPcscfVnf(unittest.TestCase): + + VNFD_0 = { + "short-name": "SippVnf", + "vdu": [ + { + "id": "sippvnf-baremetal", + "routing_table": "", + "external-interface": [ + { + "virtual-interface": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vnf__0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "vnf__1": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "vnfd-connection-point-ref": "xe0", + "name": "xe0" + }, + { + "virtual-interface": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vnf__0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "vnf__1": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "vnfd-connection-point-ref": "xe1", + "name": "xe1" + } + ], + "name": "sippvnf-baremetal", + "description": "Sipp" + } + ], + "description": "ImsbenchSipp", + "mgmt-interface": { + "vdu-id": "sipp-baremetal", + "password": "r00t", + "user": "root", + "ip": "10.80.3.11" + }, + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "id": "SippVnf", + "name": "SippVnf" + } + + def setUp(self): + self.pcscf_vnf = vims_vnf.VimsPcscfVnf('vnf__0', self.VNFD_0) + + def test___init__(self): + self.assertEqual(self.pcscf_vnf.name, 'vnf__0') + self.assertIsInstance(self.pcscf_vnf.resource_helper, + vims_vnf.VimsResourceHelper) + self.assertIsNone(self.pcscf_vnf._vnf_process) + + def test_wait_for_instantiate(self): + self.assertIsNone(self.pcscf_vnf.wait_for_instantiate()) + + def test__run(self): + self.assertIsNone(self.pcscf_vnf._run()) + + def test_start_collect(self): + self.assertIsNone(self.pcscf_vnf.start_collect()) + + def test_collect_kpi(self): + self.assertIsNone(self.pcscf_vnf.collect_kpi()) + + +class TestVimsHssVnf(unittest.TestCase): + + VNFD_1 = { + "short-name": "SippVnf", + "vdu": [ + { + "id": "sippvnf-baremetal", + "routing_table": "", + "external-interface": [ + { + "virtual-interface": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vnf__0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "vnf__1": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "vnfd-connection-point-ref": "xe0", + "name": "xe0" + }, + { + "virtual-interface": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vnf__0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "vnf__1": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "vnfd-connection-point-ref": "xe1", + "name": "xe1" + } + ], + "name": "sippvnf-baremetal", + "description": "Sipp" + } + ], + "description": "ImsbenchSipp", + "mgmt-interface": { + "vdu-id": "sipp-baremetal", + "password": "r00t", + "user": "root", + "ip": "10.80.3.11" + }, + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "id": "SippVnf", + "name": "SippVnf" + } + + SCENARIO_CFG = { + "task_id": "86414e11-5ef5-4426-b175-71baaa00fbd7", + "tc": "tc_vims_baremetal_sipp", + "runner": { + "interval": 1, + "output_config": { + "DEFAULT": { + "debug": "False", + "dispatcher": [ + "influxdb" + ] + }, + "nsb": { + "debug": "False", + "trex_client_lib": "/opt/nsb_bin/trex_client/stl", + "bin_path": "/opt/nsb_bin", + "trex_path": "/opt/nsb_bin/trex/scripts", + "dispatcher": "influxdb" + }, + "dispatcher_influxdb": { + "username": "root", + "target": "http://10.80.3.11:8086", + "db_name": "yardstick", + "timeout": "5", + "debug": "False", + "password": "root", + "dispatcher": "influxdb" + }, + "dispatcher_http": { + "debug": "False", + "dispatcher": "influxdb", + "timeout": "5", + "target": "http://127.0.0.1:8000/results" + }, + "dispatcher_file": { + "debug": "False", + "backup_count": "0", + "max_bytes": "0", + "dispatcher": "influxdb", + "file_path": "/tmp/yardstick.out" + } + }, + "runner_id": 22610, + "duration": 60, + "type": "Vims" + }, + "nodes": { + "vnf__0": "pcscf.yardstick-86414e11", + "vnf__1": "hss.yardstick-86414e11", + "tg__0": "sipp.yardstick-86414e11" + }, + "topology": "vims-topology.yaml", + "type": "NSPerf", + "traffic_profile": "../../traffic_profiles/ipv4_throughput.yaml", + "task_path": "samples/vnf_samples/nsut/vims", + "options": { + "init_reg_max": 5000, + "end_user": 10000, + "reg_cps": 20, + "rereg_cps": 20, + "rereg_step": 10, + "wait_time": 5, + "start_user": 1, + "msgc_cps": 10, + "dereg_step": 10, + "call_cps": 10, + "reg_step": 10, + "init_reg_cps": 50, + "dereg_cps": 20, + "msgc_step": 5, + "call_step": 5, + "hold_time": 15, + "port": 5060, + "run_mode": "nortp" + } + } + + CONTEXT_CFG = { + "nodes": { + "tg__0": { + "ip": "10.80.3.11", + "interfaces": { + "xe0": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vnf__0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "vnf__1": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "xe1": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vnf__0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "vnf__1": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + } + }, + "user": "root", + "password": "r00t", + "VNF model": "../../vnf_descriptors/tg_sipp_vnfd.yaml", + "name": "sipp.yardstick-86414e11", + "vnfd-id-ref": "tg__0", + "member-vnf-index": "1", + "role": "TrafficGen", + "ctx_type": "Node" + }, + "vnf__0": { + "ip": "10.80.3.7", + "interfaces": { + "xe0": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "tg__0": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + } + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + } + }, + "user": "root", + "password": "r00t", + "VNF model": "../../vnf_descriptors/vims_pcscf_vnfd.yaml", + "name": "pcscf.yardstick-86414e11", + "vnfd-id-ref": "vnf__0", + "member-vnf-index": "2", + "role": "VirtualNetworkFunction", + "ctx_type": "Node" + }, + "vnf__1": { + "ip": "10.80.3.7", + "interfaces": { + "xe0": { + "vld_id": "ims_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "tg__0": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "peer_intf": { + "vld_id": "data_network", + "peer_ifname": "xe1", + "dst_mac": "90:e2:ba:7c:30:e8", + "network": {}, + "local_ip": "10.80.3.7", + "peer_intf": { + "vld_id": "ims_network", + "peer_ifname": "xe0", + "dst_mac": "90:e2:ba:7c:41:e8", + "network": {}, + "local_ip": "10.80.3.11", + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:30:e8" + }, + "node_name": "vnf__0", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:a8" + }, + "node_name": "tg__0", + "netmask": "255.255.255.0", + "peer_name": "vnf__1", + "dst_ip": "10.80.3.7", + "ifname": "xe1", + "local_mac": "90:e2:ba:7c:30:e8" + } + }, + "node_name": "vnf__1", + "netmask": "255.255.255.0", + "peer_name": "tg__0", + "dst_ip": "10.80.3.11", + "ifname": "xe0", + "local_mac": "90:e2:ba:7c:41:e8" + } + }, + "user": "root", + "password": "r00t", + "VNF model": "../../vnf_descriptors/vims_hss_vnfd.yaml", + "name": "hss.yardstick-86414e11", + "vnfd-id-ref": "vnf__1", + "member-vnf-index": "3", + "role": "VirtualNetworkFunction", + "ctx_type": "Node" + } + }, + "networks": {} + } + + def setUp(self): + self.hss_vnf = vims_vnf.VimsHssVnf('vnf__1', self.VNFD_1) + + def test___init__(self): + self.assertIsInstance(self.hss_vnf.resource_helper, + vims_vnf.VimsResourceHelper) + self.assertIsNone(self.hss_vnf._vnf_process) + + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper") + def test_instantiate(self, ssh): + mock_ssh(ssh) + hss_vnf = vims_vnf.VimsHssVnf('vnf__1', self.VNFD_1) + self.assertIsNone(hss_vnf.instantiate(self.SCENARIO_CFG, + self.CONTEXT_CFG)) + + def test_wait_for_instantiate(self): + self.assertIsNone(self.hss_vnf.wait_for_instantiate()) + + def test_start_collect(self): + self.assertIsNone(self.hss_vnf.start_collect()) + + def test_collect_kpi(self): + self.assertIsNone(self.hss_vnf.collect_kpi()) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index 7b67ecc37..8342f5faa 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpp_helpers.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpp_helpers.py new file mode 100644 index 000000000..cca604f43 --- /dev/null +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpp_helpers.py @@ -0,0 +1,1723 @@ +# Copyright (c) 2019 Viosoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import ipaddress +import unittest + +import mock + +from yardstick.common import exceptions +from yardstick.network_services.helpers import cpu +from yardstick.network_services.vnf_generic.vnf import vpp_helpers +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper +from yardstick.network_services.vnf_generic.vnf.vpp_helpers import \ + VppSetupEnvHelper, VppConfigGenerator, VatTerminal + + +class TestVppConfigGenerator(unittest.TestCase): + + def test_add_config_item(self): + test_item = {} + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_config_item(test_item, '/tmp/vpe.log', + ['unix', 'log']) + self.assertEqual({'unix': {'log': '/tmp/vpe.log'}}, test_item) + + def test_add_config_item_str(self): + test_item = {'unix': ''} + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_config_item(test_item, '/tmp/vpe.log', + ['unix', 'log']) + self.assertEqual({'unix': {'log': '/tmp/vpe.log'}}, test_item) + + def test_add_unix_log(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_unix_log() + self.assertEqual('unix\n{\n log /tmp/vpe.log\n}\n', + vpp_config_generator.dump_config()) + + def test_add_unix_cli_listen(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_unix_cli_listen() + self.assertEqual('unix\n{\n cli-listen /run/vpp/cli.sock\n}\n', + vpp_config_generator.dump_config()) + + def test_add_unix_nodaemon(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_unix_nodaemon() + self.assertEqual('unix\n{\n nodaemon \n}\n', + vpp_config_generator.dump_config()) + + def test_add_unix_coredump(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_unix_coredump() + self.assertEqual('unix\n{\n full-coredump \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_dev(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_dev('0000:00:00.0') + self.assertEqual('dpdk\n{\n dev 0000:00:00.0 \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_cryptodev(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_cryptodev(2, '0000:00:00.0') + self.assertEqual( + 'dpdk\n{\n dev 0000:00:01.0 \n dev 0000:00:01.1 \n uio-driver igb_uio\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_sw_cryptodev(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_sw_cryptodev('aesni_gcm', 0, 2) + self.assertEqual( + 'dpdk\n{\n vdev cryptodev_aesni_gcm_pmd,socket_id=0 \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_dev_default_rxq(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_dev_default_rxq(1) + self.assertEqual( + 'dpdk\n{\n dev default\n {\n num-rx-queues 1\n }\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_dev_default_rxd(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_dev_default_rxd(2048) + self.assertEqual( + 'dpdk\n{\n dev default\n {\n num-rx-desc 2048\n }\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_dev_default_txd(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_dev_default_txd(2048) + self.assertEqual( + 'dpdk\n{\n dev default\n {\n num-tx-desc 2048\n }\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_log_level(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_log_level('debug') + self.assertEqual('dpdk\n{\n log-level debug\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_socketmem(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_socketmem('1024,1024') + self.assertEqual('dpdk\n{\n socket-mem 1024,1024\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_num_mbufs(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_num_mbufs(32768) + self.assertEqual('dpdk\n{\n num-mbufs 32768\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_uio_driver(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_uio_driver('igb_uio') + self.assertEqual('dpdk\n{\n uio-driver igb_uio\n}\n', + vpp_config_generator.dump_config()) + + def test_add_cpu_main_core(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_cpu_main_core('1,2') + self.assertEqual('cpu\n{\n main-core 1,2\n}\n', + vpp_config_generator.dump_config()) + + def test_add_cpu_corelist_workers(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_cpu_corelist_workers('1,2') + self.assertEqual('cpu\n{\n corelist-workers 1,2\n}\n', + vpp_config_generator.dump_config()) + + def test_add_heapsize(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_heapsize('4G') + self.assertEqual('heapsize 4G\n', vpp_config_generator.dump_config()) + + def test_add_ip6_hash_buckets(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_ip6_hash_buckets(2000000) + self.assertEqual('ip6\n{\n hash-buckets 2000000\n}\n', + vpp_config_generator.dump_config()) + + def test_add_ip6_heap_size(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_ip6_heap_size('4G') + self.assertEqual('ip6\n{\n heap-size 4G\n}\n', + vpp_config_generator.dump_config()) + + def test_add_ip_heap_size(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_ip_heap_size('4G') + self.assertEqual('ip\n{\n heap-size 4G\n}\n', + vpp_config_generator.dump_config()) + + def test_add_statseg_size(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_statseg_size('4G') + self.assertEqual('statseg\n{\n size 4G\n}\n', + vpp_config_generator.dump_config()) + + def test_add_plugin(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_plugin('enable', ['dpdk_plugin.so']) + self.assertEqual( + 'plugins\n{\n plugin [\'dpdk_plugin.so\']\n {\n enable \n }\n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_no_multi_seg(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_no_multi_seg() + self.assertEqual('dpdk\n{\n no-multi-seg \n}\n', + vpp_config_generator.dump_config()) + + def test_add_dpdk_no_tx_checksum_offload(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_dpdk_no_tx_checksum_offload() + self.assertEqual('dpdk\n{\n no-tx-checksum-offload \n}\n', + vpp_config_generator.dump_config()) + + def test_dump_config(self): + vpp_config_generator = VppConfigGenerator() + vpp_config_generator.add_unix_log() + self.assertEqual('unix\n{\n log /tmp/vpe.log\n}\n', + vpp_config_generator.dump_config()) + + def test_pci_dev_check(self): + self.assertTrue(VppConfigGenerator.pci_dev_check('0000:00:00.0')) + + def test_pci_dev_check_error(self): + with self.assertRaises(ValueError) as raised: + VppConfigGenerator.pci_dev_check('0000:00:0.0') + self.assertIn( + 'PCI address 0000:00:0.0 is not in valid format xxxx:xx:xx.x', + str(raised.exception)) + + +class TestVppSetupEnvHelper(unittest.TestCase): + VNFD_0 = { + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "VPP IPsec", + "id": "VipsecApproxVnf", + "mgmt-interface": { + "ip": "10.10.10.101", + "password": "r00t", + "user": "root", + "vdu-id": "ipsecvnf-baremetal" + }, + "name": "IpsecVnf", + "short-name": "IpsecVnf", + "vdu": [ + { + "description": "VPP Ipsec", + "external-interface": [ + { + "name": "xe0", + "virtual-interface": { + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:ff:06.0" + }, + "vnfd-connection-point-ref": "xe0" + }, + { + "name": "xe1", + "virtual-interface": { + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe1", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:ff:07.0" + }, + "vnfd-connection-point-ref": "xe1" + } + ], + "id": "ipsecvnf-baremetal", + "name": "ipsecvnf-baremetal", + "routing_table": [] + } + ] + } + + VNFD_1 = { + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "VPP IPsec", + "id": "VipsecApproxVnf", + "mgmt-interface": { + "ip": "10.10.10.101", + "password": "r00t", + "user": "root", + "vdu-id": "ipsecvnf-baremetal" + }, + "name": "IpsecVnf", + "short-name": "IpsecVnf", + "vdu": [ + { + "description": "VPP Ipsec", + "external-interface": [ + { + "name": "xe0", + "virtual-interface": { + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:ff:06.0" + }, + "vnfd-connection-point-ref": "xe0" + }, + { + "name": "xe1", + "virtual-interface": { + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe1", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:ff:07.0" + }, + "vnfd-connection-point-ref": "xe1" + } + ], + "id": "ipsecvnf-baremetal", + "name": "ipsecvnf-baremetal", + "routing_table": [] + } + ] + } + + VNFD_2 = { + "benchmark": { + "kpi": [ + "packets_in", + "packets_fwd", + "packets_dropped" + ] + }, + "connection-point": [ + { + "name": "xe0", + "type": "VPORT" + }, + { + "name": "xe1", + "type": "VPORT" + } + ], + "description": "VPP IPsec", + "id": "VipsecApproxVnf", + "mgmt-interface": { + "ip": "10.10.10.101", + "password": "r00t", + "user": "root", + "vdu-id": "ipsecvnf-baremetal" + }, + "name": "IpsecVnf", + "short-name": "IpsecVnf", + "vdu": [ + { + "description": "VPP Ipsec", + "external-interface": [ + { + "name": "xe0", + "virtual-interface": { + "driver": "igb_uio", + "dst_ip": "192.168.100.1", + "dst_mac": "90:e2:ba:7c:30:e8", + "ifname": "xe0", + "local_ip": "192.168.100.2", + "local_mac": "90:e2:ba:7c:41:a8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe0", + "peer_intf": { + "dpdk_port_num": 0, + "driver": "igb_uio", + "dst_ip": "192.168.100.2", + "dst_mac": "90:e2:ba:7c:41:a8", + "ifname": "xe0", + "local_ip": "192.168.100.1", + "local_mac": "90:e2:ba:7c:30:e8", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "tg__0", + "peer_ifname": "xe0", + "peer_name": "vnf__0", + "vld_id": "uplink_0", + "vpci": "0000:81:00.0" + }, + "peer_name": "tg__0", + "vld_id": "uplink_0", + "vpci": "0000:ff:06.0" + }, + "vnfd-connection-point-ref": "xe0" + }, + { + "name": "xe1", + "virtual-interface": { + "driver": "igb_uio", + "dst_ip": "1.1.1.2", + "dst_mac": "0a:b1:ec:fd:a2:66", + "ifname": "xe1", + "local_ip": "1.1.1.1", + "local_mac": "4e:90:85:d3:c5:13", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__0", + "peer_ifname": "xe1", + "peer_intf": { + "driver": "igb_uio", + "dst_ip": "1.1.1.1", + "dst_mac": "4e:90:85:d3:c5:13", + "ifname": "xe1", + "local_ip": "1.1.1.2", + "local_mac": "0a:b1:ec:fd:a2:66", + "netmask": "255.255.255.0", + "network": {}, + "node_name": "vnf__1", + "peer_ifname": "xe1", + "peer_name": "vnf__0", + "vld_id": "ciphertext", + "vpci": "0000:00:07.0" + }, + "peer_name": "vnf__1", + "vld_id": "ciphertext", + "vpci": "0000:ff:07.0" + }, + "vnfd-connection-point-ref": "xe1" + } + ], + "id": "ipsecvnf-baremetal", + "name": "ipsecvnf-baremetal", + "routing_table": [] + } + ] + } + + VNFD = { + 'vnfd:vnfd-catalog': { + 'vnfd': [ + VNFD_0, + ], + }, + } + + VPP_INTERFACES_DUMP = [ + { + "sw_if_index": 0, + "sup_sw_if_index": 0, + "l2_address_length": 0, + "l2_address": [0, 0, 0, 0, 0, 0, 0, 0], + "interface_name": "local0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 0, + "link_speed": 0, + "mtu": 0, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }, + { + "sw_if_index": 1, + "sup_sw_if_index": 1, + "l2_address_length": 6, + "l2_address": [144, 226, 186, 124, 65, 168, 0, 0], + "interface_name": "TenGigabitEthernetff/6/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9202, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }, + { + "sw_if_index": 2, + "sup_sw_if_index": 2, + "l2_address_length": 6, + "l2_address": [78, 144, 133, 211, 197, 19, 0, 0], + "interface_name": "VirtualFunctionEthernetff/7/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9206, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + } + ] + + VPP_INTERFACES_DUMP_MAC_ERR = [ + { + "sw_if_index": 0, + "sup_sw_if_index": 0, + "l2_address_length": 0, + "l2_address": [0, 0, 0, 0, 0, 0, 0, 0], + "interface_name": "local0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 0, + "link_speed": 0, + "mtu": 0, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }, + { + "sw_if_index": 1, + "sup_sw_if_index": 1, + "l2_address_length": 6, + "l2_address": [144, 226, 186, 124, 65, 169, 0, 0], + "interface_name": "TenGigabitEthernetff/6/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9202, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }, + { + "sw_if_index": 2, + "sup_sw_if_index": 2, + "l2_address_length": 6, + "l2_address": [78, 144, 133, 211, 197, 20, 0, 0], + "interface_name": "VirtualFunctionEthernetff/7/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9206, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + } + ] + + CPU_LAYOUT = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1, 1, 0]]} + CPU_SMT = {'cpuinfo': [[0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 1, 1, 0], + [2, 1, 0, 0, 0, 2, 2, 1], + [3, 1, 0, 0, 0, 3, 3, 1], + [4, 2, 0, 0, 0, 4, 4, 2], + [5, 2, 0, 0, 0, 5, 5, 2], + [6, 3, 0, 0, 0, 6, 6, 3], + [7, 3, 0, 0, 0, 7, 7, 3], + [8, 4, 0, 0, 0, 8, 8, 4], + [9, 5, 0, 1, 0, 0, 0, 0], + [10, 6, 0, 1, 0, 1, 1, 0], + [11, 6, 0, 1, 0, 2, 2, 1], + [12, 7, 0, 1, 0, 3, 3, 1], + [13, 7, 0, 1, 0, 4, 4, 2], + [14, 8, 0, 1, 0, 5, 5, 2], + [15, 8, 0, 1, 0, 6, 6, 3], + [16, 9, 0, 1, 0, 7, 7, 3], + [17, 9, 0, 1, 0, 8, 8, 4]]} + + def test_kill_vnf(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, 0, 0 + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.kill_vnf() + + def test_kill_vnf_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 1, 0, 0 + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with self.assertRaises(RuntimeError) as raised: + vpp_setup_env_helper.kill_vnf() + + self.assertIn('Failed to stop service vpp', str(raised.exception)) + + def test_tear_down(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.tear_down() + + def test_start_vpp_service(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, 0, 0 + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.start_vpp_service() + + def test_start_vpp_service_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 1, 0, 0 + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with self.assertRaises(RuntimeError) as raised: + vpp_setup_env_helper.start_vpp_service() + + self.assertIn('Failed to start service vpp', str(raised.exception)) + + def test__update_vnfd_helper(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper._update_vnfd_helper( + {'vpp-data': {'vpp-key': 'vpp-value'}}) + + self.assertEqual({'vpp-key': 'vpp-value'}, + vpp_setup_env_helper.vnfd_helper.get('vpp-data', {})) + + def test__update_vnfd_helper_with_key(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper._update_vnfd_helper({'driver': 'qat'}, 'xe0') + + self.assertEqual('qat', + vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'driver')) + + def test__update_vnfd_helper_dict_without_key(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper._update_vnfd_helper( + {'mgmt-interface': {'name': 'net'}}) + + self.assertEqual({'ip': '10.10.10.101', + 'name': 'net', + 'password': 'r00t', + 'user': 'root', + 'vdu-id': 'ipsecvnf-baremetal'}, + vpp_setup_env_helper.vnfd_helper.get('mgmt-interface', + {})) + + def test_get_value_by_interface_key(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper._update_vnfd_helper( + {'vpp-data': {'vpp-key': 'vpp-value'}}, 'xe0') + + self.assertEqual({'vpp-key': 'vpp-value'}, + vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'vpp-data')) + + def test_get_value_by_interface_key_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper._update_vnfd_helper( + {'vpp-data': {'vpp-key': 'vpp-value'}}, 'xe0') + + self.assertIsNone(vpp_setup_env_helper.get_value_by_interface_key( + 'xe2', 'vpp-err')) + + def test_crypto_device_init(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.dpdk_bind_helper.load_dpdk_driver = mock.Mock() + vpp_setup_env_helper.dpdk_bind_helper.bind = mock.Mock() + + vpp_setup_env_helper.kill_vnf = mock.Mock() + vpp_setup_env_helper.pci_driver_unbind = mock.Mock() + + with mock.patch.object(vpp_setup_env_helper, 'get_pci_dev_driver') as \ + mock_get_pci_dev_driver, \ + mock.patch.object(vpp_setup_env_helper, 'set_sriov_numvfs') as \ + mock_set_sriov_numvfs: + mock_get_pci_dev_driver.return_value = 'igb_uio' + self.assertIsNone( + vpp_setup_env_helper.crypto_device_init('0000:ff:06.0', 32)) + mock_set_sriov_numvfs.assert_called() + + def test_get_sriov_numvfs(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '32', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertEqual(32, + vpp_setup_env_helper.get_sriov_numvfs('0000:ff:06.0')) + + def test_get_sriov_numvfs_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, 'err', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertEqual(0, + vpp_setup_env_helper.get_sriov_numvfs('0000:ff:06.0')) + + def test_set_sriov_numvfs(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.set_sriov_numvfs('0000:ff:06.0') + self.assertEqual(ssh_helper.execute.call_count, 1) + + def test_pci_driver_unbind(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.pci_driver_unbind('0000:ff:06.0') + self.assertEqual(ssh_helper.execute.call_count, 1) + + def test_get_pci_dev_driver(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = \ + 0, 'Slot: ff:07.0\n' \ + 'Class: Ethernet controller\n' \ + 'Vendor: Intel Corporation\n' \ + 'Device: 82599 Ethernet Controller Virtual Function\n' \ + 'SVendor: Intel Corporation\n' \ + 'SDevice: 82599 Ethernet Controller Virtual Function\n' \ + 'Rev: 01\n' \ + 'Driver: igb_uio\n' \ + 'Module: ixgbevf', '' + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertEqual('igb_uio', vpp_setup_env_helper.get_pci_dev_driver( + '0000:ff:06.0')) + + def test_get_pci_dev_driver_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 1, 'err', '' + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with self.assertRaises(RuntimeError) as raised: + vpp_setup_env_helper.get_pci_dev_driver( + '0000:ff:06.0') + + self.assertIn("'lspci -vmmks 0000:ff:06.0' failed", + str(raised.exception)) + + def test_get_pci_dev_driver_output_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = \ + 0, 'Slot: ff:07.0\n' \ + '\n\t' \ + 'Vendor: Intel Corporation\n' \ + 'Device: 82599 Ethernet Controller Virtual Function\n' \ + 'SVendor: Intel Corporation\n' \ + 'SDevice: 82599 Ethernet Controller Virtual Function\n' \ + 'Rev: 01\n' \ + 'Driver_err: igb_uio\n' \ + 'Module: ixgbevf', '' + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertIsNone( + vpp_setup_env_helper.get_pci_dev_driver('0000:ff:06.0')) + + def test_vpp_create_ipsec_tunnels(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + self.assertIsNone( + vpp_setup_env_helper.vpp_create_ipsec_tunnels('10.10.10.2', + '10.10.10.1', 'xe0', + 1, 1, mock.Mock(), + 'crypto_key', + mock.Mock(), + 'integ_key', + '20.20.20.0')) + self.assertGreaterEqual(ssh_helper.execute.call_count, 2) + + def test_vpp_create_ipsec_1000_tunnels(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + self.assertIsNone( + vpp_setup_env_helper.vpp_create_ipsec_tunnels('10.10.10.2', + '10.10.10.1', 'xe0', + 1000, 128000, + mock.Mock(), + 'crypto_key', + mock.Mock(), + 'integ_key', + '20.20.20.0')) + self.assertGreaterEqual(ssh_helper.execute.call_count, 2) + + def test_apply_config(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertIsNone(vpp_setup_env_helper.apply_config(mock.Mock())) + self.assertGreaterEqual(ssh_helper.execute.call_count, 2) + + def test_apply_config_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 1, '', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with self.assertRaises(RuntimeError) as raised: + vpp_setup_env_helper.apply_config(mock.Mock()) + + self.assertIn('Writing config file failed', str(raised.exception)) + + def test_vpp_route_add(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertIsNone( + vpp_setup_env_helper.vpp_route_add('xe0', '10.10.10.1', 24)) + + def test_vpp_route_add_without_index(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertIsNone( + vpp_setup_env_helper.vpp_route_add('xe0', '10.10.10.1', 24, + interface='xe0', + use_sw_index=False)) + + def test_add_arp_on_dut(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertEqual('', vpp_setup_env_helper.add_arp_on_dut('xe0', + '10.10.10.1', + '00:00:00:00:00:00')) + + def test_set_ip(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertEqual('', + vpp_setup_env_helper.set_ip('xe0', '10.10.10.1', + 24)) + + def test_set_interface_state(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertEqual('', + vpp_setup_env_helper.set_interface_state('xe0', + 'up')) + + def test_set_interface_state_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + with self.assertRaises(ValueError) as raised: + vpp_setup_env_helper.set_interface_state('xe0', 'error') + self.assertIn('Unexpected interface state: error', + str(raised.exception)) + + def test_set_interface_down_state(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertEqual('', + vpp_setup_env_helper.set_interface_state('xe0', + 'down')) + + def test_vpp_set_interface_mtu(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = '' + self.assertIsNone( + vpp_setup_env_helper.vpp_set_interface_mtu('xe0', 9200)) + + def test_vpp_interfaces_ready_wait(self): + json_output = [self.VPP_INTERFACES_DUMP] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + self.assertIsNone(vpp_setup_env_helper.vpp_interfaces_ready_wait()) + + def test_vpp_interfaces_ready_wait_timeout(self): + json_output = [[ + { + "sw_if_index": 0, + "sup_sw_if_index": 0, + "l2_address_length": 0, + "l2_address": [0, 0, 0, 0, 0, 0, 0, 0], + "interface_name": "xe0", + "admin_up_down": 1, + "link_up_down": 0, + "link_duplex": 0, + "link_speed": 0, + "mtu": 0, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }]] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + with self.assertRaises(RuntimeError) as raised: + vpp_setup_env_helper.vpp_interfaces_ready_wait(5) + self.assertIn('timeout, not up [\'xe0\']', str(raised.exception)) + + def test_vpp_get_interface_data(self): + json_output = [self.VPP_INTERFACES_DUMP] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + self.assertEqual(json_output[0], + vpp_setup_env_helper.vpp_get_interface_data()) + + def test_vpp_get_interface_data_ifname(self): + json_output = [self.VPP_INTERFACES_DUMP] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + self.assertEqual(json_output[0][2], + vpp_setup_env_helper.vpp_get_interface_data( + 'VirtualFunctionEthernetff/7/0')) + + def test_vpp_get_interface_data_ifname_error(self): + json_output = [self.VPP_INTERFACES_DUMP] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + self.assertEqual({}, vpp_setup_env_helper.vpp_get_interface_data( + 'error')) + + def test_vpp_get_interface_data_ifindex(self): + json_output = [self.VPP_INTERFACES_DUMP] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + self.assertEqual(json_output[0][1], + vpp_setup_env_helper.vpp_get_interface_data(1)) + + def test_vpp_get_interface_data_error(self): + json_output = [self.VPP_INTERFACES_DUMP] + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + + with mock.patch.object(vpp_helpers.VatTerminal, + 'vat_terminal_exec_cmd_from_template') as \ + mock_vat_terminal_exec_cmd_from_template: + mock_vat_terminal_exec_cmd_from_template.return_value = json_output + with self.assertRaises(TypeError) as raised: + vpp_setup_env_helper.vpp_get_interface_data(1.0) + self.assertEqual('', str(raised.exception)) + + def test_update_vpp_interface_data(self): + output = '{}\n{}'.format(self.VPP_INTERFACES_DUMP, + 'dump_interface_table:6019: JSON output ' \ + 'supported only for VPE API calls and dump_stats_table\n' \ + '/opt/nsb_bin/vpp/templates/dump_interfaces.vat(2): \n' \ + 'dump_interface_table error: Misc') + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, output.replace("\'", "\""), '' + ssh_helper.join_bin_path.return_value = '/opt/nsb_bin/vpp/templates' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertIsNone(vpp_setup_env_helper.update_vpp_interface_data()) + self.assertGreaterEqual(ssh_helper.execute.call_count, 1) + self.assertEqual('TenGigabitEthernetff/6/0', + vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'vpp_name')) + self.assertEqual(1, vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'vpp_sw_index')) + self.assertEqual('VirtualFunctionEthernetff/7/0', + vpp_setup_env_helper.get_value_by_interface_key( + 'xe1', 'vpp_name')) + self.assertEqual(2, vpp_setup_env_helper.get_value_by_interface_key( + 'xe1', 'vpp_sw_index')) + + def test_update_vpp_interface_data_error(self): + output = '{}\n{}'.format(self.VPP_INTERFACES_DUMP_MAC_ERR, + 'dump_interface_table:6019: JSON output ' \ + 'supported only for VPE API calls and dump_stats_table\n' \ + '/opt/nsb_bin/vpp/templates/dump_interfaces.vat(2): \n' \ + 'dump_interface_table error: Misc') + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, output.replace("\'", "\""), '' + ssh_helper.join_bin_path.return_value = '/opt/nsb_bin/vpp/templates' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertIsNone(vpp_setup_env_helper.update_vpp_interface_data()) + self.assertGreaterEqual(ssh_helper.execute.call_count, 1) + + def test_iface_update_numa(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '0', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertIsNone(vpp_setup_env_helper.iface_update_numa()) + self.assertGreaterEqual(ssh_helper.execute.call_count, 2) + self.assertEqual(0, vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertEqual(0, vpp_setup_env_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + + def test_iface_update_numa_error(self): + vnfd_helper = VnfdHelper(self.VNFD_1) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '-1', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout: + mock_get_cpu_layout.return_value = self.CPU_LAYOUT + sys_cores = cpu.CpuSysCores(ssh_helper) + vpp_setup_env_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + self.assertIsNone(vpp_setup_env_helper.iface_update_numa()) + self.assertGreaterEqual(ssh_helper.execute.call_count, 2) + self.assertEqual(0, vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertEqual(0, vpp_setup_env_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + + def test_iface_update_without_numa(self): + vnfd_helper = VnfdHelper(self.VNFD_2) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, '-1', '' + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with mock.patch.object(cpu.CpuSysCores, 'get_cpu_layout') as \ + mock_get_cpu_layout: + mock_get_cpu_layout.return_value = self.CPU_SMT + sys_cores = cpu.CpuSysCores(ssh_helper) + vpp_setup_env_helper._update_vnfd_helper( + sys_cores.get_cpu_layout()) + self.assertIsNone(vpp_setup_env_helper.iface_update_numa()) + self.assertGreaterEqual(ssh_helper.execute.call_count, 2) + self.assertIsNone(vpp_setup_env_helper.get_value_by_interface_key( + 'xe0', 'numa_node')) + self.assertIsNone(vpp_setup_env_helper.get_value_by_interface_key( + 'xe1', 'numa_node')) + + def test_execute_script(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + vpp_setup_env_helper.execute_script('dump_interfaces.vat', True, True) + self.assertGreaterEqual(ssh_helper.put_file.call_count, 1) + self.assertGreaterEqual(ssh_helper.execute.call_count, 1) + + def test_execute_script_error(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.side_effect = Exception + + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + with self.assertRaises(Exception) as raised: + vpp_setup_env_helper.execute_script('dump_interfaces.vat', True, + True) + self.assertIn( + 'VAT script execution failed: vpp_api_test json in dump_interfaces.vat script', + str(raised.exception)) + self.assertGreaterEqual(ssh_helper.put_file.call_count, 1) + + def test_execute_script_json_out(self): + json_output = [ + { + "sw_if_index": 0, + "sup_sw_if_index": 0 + }, + { + "l2_address_length": 6, + "l2_address": [144, 226, 186, 124, 65, 168, 0, 0] + }, + { + "interface_name": "VirtualFunctionEthernetff/7/0", + "admin_up_down": 0 + } + ] + output = '{}\n{}'.format(json_output, + 'dump_interface_table:6019: JSON output ' \ + 'supported only for VPE API calls and dump_stats_table\n' \ + '/opt/nsb_bin/vpp/templates/dump_interfaces.vat(2): \n' \ + 'dump_interface_table error: Misc') + vnfd_helper = VnfdHelper(self.VNFD_0) + ssh_helper = mock.Mock() + ssh_helper.execute.return_value = 0, output, '' + ssh_helper.join_bin_path.return_value = '/opt/nsb_bin/vpp/templates' + scenario_helper = mock.Mock() + vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper, + scenario_helper) + self.assertEqual(str(json_output), + vpp_setup_env_helper.execute_script_json_out( + 'dump_interfaces.vat')) + + def test_self_cleanup_vat_json_output(self): + json_output = [ + { + "sw_if_index": 0, + "sup_sw_if_index": 0 + }, + { + "l2_address_length": 6, + "l2_address": [144, 226, 186, 124, 65, 168, 0, 0] + }, + { + "interface_name": "VirtualFunctionEthernetff/7/0", + "admin_up_down": 0 + } + ] + + output = '{}\n{}'.format(json_output, + 'dump_interface_table:6019: JSON output ' \ + 'supported only for VPE API calls and dump_stats_table\n' \ + '/opt/nsb_bin/vpp/templates/dump_interfaces.vat(2): \n' \ + 'dump_interface_table error: Misc') + self.assertEqual(str(json_output), + VppSetupEnvHelper.cleanup_vat_json_output(output, + '/opt/nsb_bin/vpp/templates/dump_interfaces.vat')) + + def test__convert_mac_to_number_list(self): + self.assertEqual([144, 226, 186, 124, 65, 168], + VppSetupEnvHelper._convert_mac_to_number_list( + '90:e2:ba:7c:41:a8')) + + def test_get_vpp_interface_by_mac(self): + mac_address = '90:e2:ba:7c:41:a8' + self.assertEqual({'admin_up_down': 0, + 'interface_name': 'TenGigabitEthernetff/6/0', + 'l2_address': [144, 226, 186, 124, 65, 168, 0, 0], + 'l2_address_length': 6, + 'link_duplex': 2, + 'link_speed': 32, + 'link_up_down': 0, + 'mtu': 9202, + 'sub_default': 0, + 'sub_dot1ad': 0, + 'sub_exact_match': 0, + 'sub_id': 0, + 'sub_inner_vlan_id': 0, + 'sub_inner_vlan_id_any': 0, + 'sub_number_of_tags': 0, + 'sub_outer_vlan_id': 0, + 'sub_outer_vlan_id_any': 0, + 'sup_sw_if_index': 1, + 'sw_if_index': 1, + 'vtr_op': 0, + 'vtr_push_dot1q': 0, + 'vtr_tag1': 0, + 'vtr_tag2': 0}, + VppSetupEnvHelper.get_vpp_interface_by_mac( + self.VPP_INTERFACES_DUMP, mac_address)) + + def test_get_vpp_interface_by_mac_error(self): + mac_address = '90:e2:ba:7c:41:a9' + with self.assertRaises(ValueError) as raised: + VppSetupEnvHelper.get_vpp_interface_by_mac( + [{ + "sw_if_index": 1, + "sup_sw_if_index": 1, + "l2_address_length": 7, + "l2_address": [144, 226, 186, 124, 65, 169, 0, 0], + "interface_name": "TenGigabitEthernetff/6/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9202, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }], mac_address) + + self.assertIn('l2_address_length value is not 6.', + str(raised.exception)) + + def test_get_vpp_interface_by_mac_l2_error(self): + mac_address = '90:e2:ba:7c:41:a7' + with self.assertRaises(KeyError) as raised: + VppSetupEnvHelper.get_vpp_interface_by_mac( + [{ + "sw_if_index": 1, + "sup_sw_if_index": 1, + "l2_address_length": 6, + "l2_address_err": [144, 226, 186, 124, 65, 167, 0, 0], + "interface_name": "TenGigabitEthernetff/6/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9202, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }], mac_address) + + self.assertIn( + 'key l2_address not found in interface dict.Probably input list ' \ + 'is not parsed from correct VAT json output.', + str(raised.exception)) + + def test_get_vpp_interface_by_mac_l2_length_error(self): + mac_address = '90:e2:ba:7c:41:a6' + with self.assertRaises(KeyError) as raised: + VppSetupEnvHelper.get_vpp_interface_by_mac( + [{ + "sw_if_index": 1, + "sup_sw_if_index": 1, + "l2_address_length_err": 6, + "l2_address": [144, 226, 186, 124, 65, 166, 0, 0], + "interface_name": "TenGigabitEthernetff/6/0", + "admin_up_down": 0, + "link_up_down": 0, + "link_duplex": 2, + "link_speed": 32, + "mtu": 9202, + "sub_id": 0, + "sub_dot1ad": 0, + "sub_number_of_tags": 0, + "sub_outer_vlan_id": 0, + "sub_inner_vlan_id": 0, + "sub_exact_match": 0, + "sub_default": 0, + "sub_outer_vlan_id_any": 0, + "sub_inner_vlan_id_any": 0, + "vtr_op": 0, + "vtr_push_dot1q": 0, + "vtr_tag1": 0, + "vtr_tag2": 0 + }], mac_address) + + self.assertIn( + 'key l2_address_length not found in interface dict. Probably ' \ + 'input list is not parsed from correct VAT json output.', + str(raised.exception)) + + def test_get_prefix_length(self): + start_ip = '10.10.10.0' + end_ip = '10.10.10.127' + ips = [ipaddress.ip_address(ip) for ip in + [str(ipaddress.ip_address(start_ip)), str(end_ip)]] + lowest_ip, highest_ip = min(ips), max(ips) + + self.assertEqual(25, + VppSetupEnvHelper.get_prefix_length(int(lowest_ip), + int(highest_ip), + lowest_ip.max_prefixlen)) + + def test_get_prefix_length_zero_prefix(self): + start_ip = '10.0.0.0' + end_ip = '10.0.0.0' + ips = [ipaddress.ip_address(ip) for ip in + [str(ipaddress.ip_address(start_ip)), str(end_ip)]] + lowest_ip, highest_ip = min(ips), max(ips) + + self.assertEqual(0, + VppSetupEnvHelper.get_prefix_length(int(lowest_ip), + int(highest_ip), + 0)) + + +class TestVatTerminal(unittest.TestCase): + + def test___init___error(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_open.side_effect = exceptions.SSHTimeout + + with self.assertRaises(RuntimeError) as raised: + VatTerminal(ssh_helper, json_param=True) + self.assertIn('Cannot open interactive terminal', + str(raised.exception)) + + def test___init___exec_error(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.side_effect = exceptions.SSHTimeout + VatTerminal(ssh_helper, json_param=True) + + def test_vat_terminal_exec_cmd(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.return_value = str( + {'empty': 'value'}).replace("\'", "\"") + vat_terminal = VatTerminal(ssh_helper, json_param=True) + + self.assertEqual({'empty': 'value'}, + vat_terminal.vat_terminal_exec_cmd( + "hw_interface_set_mtu sw_if_index 1 mtu 9200")) + + def test_vat_terminal_exec_cmd_array(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.return_value = str( + [{'empty': 'value'}]).replace("\'", "\"") + vat_terminal = VatTerminal(ssh_helper, json_param=True) + + self.assertEqual([{'empty': 'value'}], + vat_terminal.vat_terminal_exec_cmd( + "hw_interface_set_mtu sw_if_index 1 mtu 9200")) + + def test_vat_terminal_exec_cmd_without_output(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.return_value = str( + {'empty': 'value'}).replace("\'", "\"") + vat_terminal = VatTerminal(ssh_helper, json_param=False) + + self.assertIsNone(vat_terminal.vat_terminal_exec_cmd( + "hw_interface_set_mtu sw_if_index 1 mtu 9200")) + + def test_vat_terminal_exec_cmd_error(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.return_value = str( + {'empty': 'value'}).replace("\'", "\"") + ssh_helper.interactive_terminal_exec_command.side_effect = exceptions.SSHTimeout + + vat_terminal = VatTerminal(ssh_helper, json_param=True) + + with self.assertRaises(RuntimeError) as raised: + vat_terminal.vat_terminal_exec_cmd( + "hw_interface_set_mtu sw_if_index 1 mtu 9200") + self.assertIn( + 'VPP is not running on node. VAT command hw_interface_set_mtu ' \ + 'sw_if_index 1 mtu 9200 execution failed', + str(raised.exception)) + + def test_vat_terminal_exec_cmd_output_error(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.return_value = str( + 'empty: value').replace("\'", "\"") + + vat_terminal = VatTerminal(ssh_helper, json_param=True) + + with self.assertRaises(RuntimeError) as raised: + vat_terminal.vat_terminal_exec_cmd( + "hw_interface_set_mtu sw_if_index 1 mtu 9200") + self.assertIn( + 'VAT command hw_interface_set_mtu sw_if_index 1 mtu 9200: no JSON data.', + str(raised.exception)) + + def test_vat_terminal_close(self): + ssh_helper = mock.Mock() + vat_terminal = VatTerminal(ssh_helper, json_param=False) + self.assertIsNone(vat_terminal.vat_terminal_close()) + + def test_vat_terminal_close_error(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_exec_command.side_effect = exceptions.SSHTimeout + vat_terminal = VatTerminal(ssh_helper, json_param=False) + with self.assertRaises(RuntimeError) as raised: + vat_terminal.vat_terminal_close() + self.assertIn('Failed to close VAT console', str(raised.exception)) + + def test_vat_terminal_close_vat_error(self): + ssh_helper = mock.Mock() + ssh_helper.interactive_terminal_close.side_effect = exceptions.SSHTimeout + vat_terminal = VatTerminal(ssh_helper, json_param=False) + with self.assertRaises(RuntimeError) as raised: + vat_terminal.vat_terminal_close() + self.assertIn('Cannot close interactive terminal', + str(raised.exception)) + + def test_vat_terminal_exec_cmd_from_template(self): + ssh_helper = mock.Mock() + vat_terminal = VatTerminal(ssh_helper, json_param=False) + + with mock.patch.object(vat_terminal, 'vat_terminal_exec_cmd') as \ + mock_vat_terminal_exec_cmd: + mock_vat_terminal_exec_cmd.return_value = 'empty' + self.assertEqual(['empty'], + vat_terminal.vat_terminal_exec_cmd_from_template( + "hw_interface_set_mtu.vat", sw_if_index=1, + mtu=9200)) diff --git a/yardstick/tests/unit/test_ssh.py b/yardstick/tests/unit/test_ssh.py index 71929f1a2..374fb6644 100644 --- a/yardstick/tests/unit/test_ssh.py +++ b/yardstick/tests/unit/test_ssh.py @@ -286,6 +286,48 @@ class SSHTestCase(unittest.TestCase): mock_paramiko_exec_command.assert_called_once_with('cmd', get_pty=True) + @mock.patch("yardstick.ssh.paramiko") + def test_interactive_terminal_open(self, mock_paramiko): + fake_client = mock.Mock() + fake_session = mock.Mock() + fake_session.recv.return_value = ":~# " + fake_transport = mock.Mock() + fake_transport.open_session.return_value = fake_session + fake_client.get_transport.return_value = fake_transport + mock_paramiko.SSHClient.return_value = fake_client + + test_ssh = ssh.SSH("admin", "example.net", pkey="key") + result = test_ssh.interactive_terminal_open() + self.assertEqual(fake_session, result) + + @mock.patch("yardstick.ssh.paramiko") + def test_interactive_terminal_exec_command(self, mock_paramiko): + fake_client = mock.Mock() + fake_session = mock.Mock() + fake_session.recv.return_value = "stdout fake data" + fake_transport = mock.Mock() + fake_transport.open_session.return_value = fake_session + fake_client.get_transport.return_value = fake_transport + mock_paramiko.SSHClient.return_value = fake_client + + test_ssh = ssh.SSH("admin", "example.net", pkey="key") + with mock.patch.object(fake_session, "sendall") \ + as mock_paramiko_send_command: + result = test_ssh.interactive_terminal_exec_command(fake_session, + 'cmd', "vat# ") + self.assertEqual("stdout fake data", result) + mock_paramiko_send_command.assert_called_once_with('cmd\n') + + @mock.patch("yardstick.ssh.paramiko") + def test_interactive_terminal_close(self, _): + fake_session = mock.Mock() + paramiko_sshclient = self.test_client._get_client() + paramiko_sshclient.get_transport.open_session.return_value = fake_session + with mock.patch.object(fake_session, "close") \ + as mock_paramiko_terminal_close: + self.test_client.interactive_terminal_close(fake_session) + mock_paramiko_terminal_close.assert_called_once_with() + class SSHRunTestCase(unittest.TestCase): """Test SSH.run method in different aspects. |