1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 from yardstick.common import utils
23 from yardstick.common import exceptions
24 from yardstick.benchmark import contexts
25 from yardstick.benchmark.contexts import base as ctx_base
26 from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api
27 from yardstick.network_services.traffic_profile import base as tp_base
28 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia
31 TEST_FILE_YAML = 'nsb_test_case.yaml'
36 class TestIxiaResourceHelper(unittest.TestCase):
39 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
40 self.mock_IxNextgen = self._mock_IxNextgen.start()
41 self.addCleanup(self._stop_mocks)
43 def _stop_mocks(self):
44 self._mock_IxNextgen.stop()
46 def test___init___with_custom_rfc_helper(self):
47 class MyRfcHelper(tg_rfc2544_ixia.IxiaRfc2544Helper):
50 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(
51 mock.Mock(), MyRfcHelper)
52 self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper)
54 def test__init_ix_scenario(self):
55 mock_scenario = mock.Mock()
56 mock_scenario_helper = mock.Mock()
57 mock_scenario_helper.scenario_cfg = {'ixia_config': 'TestScenario',
58 'options': 'scenario_options'}
59 mock_setup_helper = mock.Mock(scenario_helper=mock_scenario_helper)
60 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock_setup_helper)
61 ixia_resource_helper._ixia_scenarios = {'TestScenario': mock_scenario}
62 ixia_resource_helper.client = 'client'
63 ixia_resource_helper.context_cfg = 'context'
64 ixia_resource_helper._init_ix_scenario()
65 mock_scenario.assert_called_once_with('client', 'context', 'scenario_options')
67 def test__init_ix_scenario_not_supported_cfg_type(self):
68 mock_scenario_helper = mock.Mock()
69 mock_scenario_helper.scenario_cfg = {'ixia_config': 'FakeScenario',
70 'options': 'scenario_options'}
71 mock_setup_helper = mock.Mock(scenario_helper=mock_scenario_helper)
72 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock_setup_helper)
73 ixia_resource_helper._ixia_scenarios = {'TestScenario': mock.Mock()}
74 with self.assertRaises(RuntimeError):
75 ixia_resource_helper._init_ix_scenario()
77 @mock.patch.object(tg_rfc2544_ixia.IxiaResourceHelper, '_init_ix_scenario')
78 def test_setup(self, mock__init_ix_scenario):
79 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
80 ixia_resource_helper.setup()
81 mock__init_ix_scenario.assert_called_once()
83 def test_stop_collect_with_client(self):
84 mock_client = mock.Mock()
85 ixia_resource_helper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
86 ixia_resource_helper.client = mock_client
87 ixia_resource_helper._ix_scenario = mock.Mock()
88 ixia_resource_helper.stop_collect()
89 self.assertEqual(1, ixia_resource_helper._terminated.value)
90 ixia_resource_helper._ix_scenario.stop_protocols.assert_called_once()
92 def test_run_traffic(self):
93 mock_tprofile = mock.Mock()
94 mock_tprofile.config.duration = 10
95 mock_tprofile.get_drop_percentage.return_value = True, 'fake_samples'
96 ixia_rhelper = tg_rfc2544_ixia.IxiaResourceHelper(mock.Mock())
97 ixia_rhelper.rfc_helper = mock.Mock()
98 ixia_rhelper.vnfd_helper = mock.Mock()
99 ixia_rhelper._ix_scenario = mock.Mock()
100 ixia_rhelper.vnfd_helper.port_pairs.all_ports = []
101 with mock.patch.object(ixia_rhelper, 'generate_samples'), \
102 mock.patch.object(ixia_rhelper, '_build_ports'), \
103 mock.patch.object(ixia_rhelper, '_initialize_client'), \
104 mock.patch.object(utils, 'wait_until_true'):
105 ixia_rhelper.run_traffic(mock_tprofile)
107 self.assertEqual('fake_samples', ixia_rhelper._queue.get())
110 @mock.patch.object(tg_rfc2544_ixia, 'ixnet_api')
111 class TestIXIATrafficGen(unittest.TestCase):
112 VNFD = {'vnfd:vnfd-catalog':
114 [{'short-name': 'VpeVnf',
117 [{'network': '152.16.100.20',
118 'netmask': '255.255.255.0',
119 'gateway': '152.16.100.20',
121 {'network': '152.16.40.20',
122 'netmask': '255.255.255.0',
123 'gateway': '152.16.40.20',
125 'description': 'VPE approximation using DPDK',
126 'name': 'vpevnf-baremetal',
128 [{'network': '0064:ff9b:0:0:0:0:9810:6414',
130 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
132 {'network': '0064:ff9b:0:0:0:0:9810:2814',
134 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
136 'id': 'vpevnf-baremetal',
137 'external-interface':
138 [{'virtual-interface':
139 {'dst_mac': '00:00:00:00:00:04',
140 'vpci': '0000:05:00.0',
141 'local_ip': '152.16.100.19',
142 'type': 'PCI-PASSTHROUGH',
143 'netmask': '255.255.255.0',
145 'bandwidth': '10 Gbps',
147 'dst_ip': '152.16.100.20',
148 'local_iface_name': 'xe0',
149 'local_mac': '00:00:00:00:00:02'},
150 'vnfd-connection-point-ref': 'xe0',
152 {'virtual-interface':
153 {'dst_mac': '00:00:00:00:00:03',
154 'vpci': '0000:05:00.1',
155 'local_ip': '152.16.40.19',
156 'type': 'PCI-PASSTHROUGH',
158 'netmask': '255.255.255.0',
160 'bandwidth': '10 Gbps',
161 'dst_ip': '152.16.40.20',
162 'local_iface_name': 'xe1',
163 'local_mac': '00:00:00:00:00:01'},
164 'vnfd-connection-point-ref': 'xe1',
166 'description': 'Vpe approximation using DPDK',
168 {'vdu-id': 'vpevnf-baremetal',
174 {'kpi': ['packets_in', 'packets_fwd',
176 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
177 {'type': 'VPORT', 'name': 'xe1'}],
178 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
181 "schema": "isb:traffic_profile:0.1",
183 "description": "Fixed traffic profile to run UDP traffic",
185 "traffic_type": "FixedTraffic",
186 "frame_rate": 100, # pps
190 TC_YAML = {'scenarios': [{'tc_options':
191 {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
192 'runner': {'duration': 400,
193 'interval': 35, 'type': 'Duration'},
195 {'flow': 'ipv4_1flow_Packets_vpe.yaml',
196 'imix': 'imix_voice.yaml'},
197 'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
198 'traffic_profile': 'ipv4_throughput_vpe.yaml',
200 'nodes': {'tg__1': 'trafficgen_1.yardstick',
201 'vnf__1': 'vnf.yardstick'},
202 'topology': 'vpe_vnf_topology.yaml'}],
203 'context': {'nfvi_type': 'baremetal',
204 'type': contexts.CONTEXT_NODE,
206 'file': '/etc/yardstick/nodes/pod.yaml'},
207 'schema': 'yardstick:task:0.1'}
209 def test___init__(self, *args):
210 with mock.patch("yardstick.ssh.SSH") as ssh:
211 ssh_mock = mock.Mock(autospec=ssh.SSH)
213 mock.Mock(return_value=(0, "", ""))
214 ssh.from_node.return_value = ssh_mock
215 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
216 # NOTE(ralonsoh): check the object returned.
217 tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd, 'task_id')
219 def test_listen_traffic(self, *args):
220 with mock.patch("yardstick.ssh.SSH") as ssh:
221 ssh_mock = mock.Mock(autospec=ssh.SSH)
223 mock.Mock(return_value=(0, "", ""))
224 ssh.from_node.return_value = ssh_mock
225 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
226 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
228 self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
230 @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
231 def test_instantiate(self, *args):
232 with mock.patch("yardstick.ssh.SSH") as ssh:
233 ssh_mock = mock.Mock(autospec=ssh.SSH)
235 mock.Mock(return_value=(0, "", ""))
237 mock.Mock(return_value=(0, "", ""))
238 ssh.from_node.return_value = ssh_mock
239 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
240 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
242 scenario_cfg = {'tc': "nsb_test_case",
250 'allowed_drop_rate': '0.8 - 1'},
252 'rules': 'acl_1rule.yaml',
256 'worker_config': '1C/1T',
257 'worker_threads': 1}}}})
258 scenario_cfg.update({
259 'nodes': {ixnet_traffic_gen.name: "mock"}
261 ixnet_traffic_gen.topology = ""
262 ixnet_traffic_gen.get_ixobj = mock.MagicMock()
263 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
264 ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
267 ixnet_traffic_gen.instantiate(scenario_cfg, {}))
269 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
270 def test_collect_kpi(self, *args):
271 with mock.patch("yardstick.ssh.SSH") as ssh:
272 ssh_mock = mock.Mock(autospec=ssh.SSH)
274 mock.Mock(return_value=(0, "", ""))
275 ssh.from_node.return_value = ssh_mock
277 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
278 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd,
280 ixnet_traffic_gen.scenario_helper.scenario_cfg = {
281 'nodes': {ixnet_traffic_gen.name: "mock"}
283 ixnet_traffic_gen.data = {}
284 restult = ixnet_traffic_gen.collect_kpi()
286 expected = {'collect_stats': {},
287 'physical_node': 'mock_node'}
289 self.assertEqual(expected, restult)
291 def test_terminate(self, *args):
292 with mock.patch("yardstick.ssh.SSH") as ssh:
293 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
294 ssh_mock = mock.Mock(autospec=ssh.SSH)
296 mock.Mock(return_value=(0, "", ""))
297 ssh.from_node.return_value = ssh_mock
298 ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(
299 NAME, vnfd, 'task_id', resource_helper_type=mock.Mock())
300 ixnet_traffic_gen._terminated = mock.MagicMock()
301 ixnet_traffic_gen._terminated.value = 0
302 ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
303 ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
304 ixnet_traffic_gen._traffic_process = mock.MagicMock()
305 ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
306 self.assertIsNone(ixnet_traffic_gen.terminate())
308 def _get_file_abspath(self, filename):
309 curr_path = os.path.dirname(os.path.abspath(__file__))
310 file_path = os.path.join(curr_path, filename)
313 def test__check_status(self, *args):
314 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
315 sut = tg_rfc2544_ixia.IxiaTrafficGen('vnf1', vnfd, 'task_id')
318 @mock.patch("yardstick.ssh.SSH")
319 def test_traffic_runner(self, mock_ssh, *args):
320 mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
321 mock_traffic_profile.get_traffic_definition.return_value = "64"
322 mock_traffic_profile.params = self.TRAFFIC_PROFILE
323 # traffic_profile.ports is standardized on port_num
324 mock_traffic_profile.ports = [0, 1]
326 mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
327 mock_ssh_instance.execute.return_value = 0, "", ""
328 mock_ssh_instance.run.return_value = 0, "", ""
330 mock_ssh.from_node.return_value = mock_ssh_instance
332 vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
333 vnfd["mgmt-interface"].update({
335 "ixchassis": "1.1.1.1",
336 "py_bin_path": "/root",
342 for ifname in range(1):
343 name = "xe{}".format(ifname)
351 "Valid_Frames_Rx": 1000,
357 samples.update({"CurrentDropPercentage": 0.0})
362 "Rx_Rate_Kbps": [20, 20],
363 "Tx_Rate_Kbps": [20, 20],
364 "Rx_Rate_Mbps": [10, 10],
365 "Tx_Rate_Mbps": [10, 10],
366 "CurrentDropPercentage": [0, 0],
367 "RxThroughput": [10, 10],
368 "TxThroughput": [10, 10],
369 "Frames_Tx": [1000, 1000],
370 "in_packets": [1000, 1000],
371 "Valid_Frames_Rx": [1000, 1000],
372 "out_packets": [1000, 1000],
376 mock_traffic_profile.execute_traffic.return_value = [
377 'Completed', samples]
378 mock_traffic_profile.get_drop_percentage.return_value = [
379 'Completed', samples]
381 sut = tg_rfc2544_ixia.IxiaTrafficGen(name, vnfd, 'task_id')
382 sut.vnf_port_pairs = [[[0], [1]]]
383 sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
386 sut.ssh_helper = mock.Mock()
387 sut._traffic_process = mock.MagicMock()
388 sut.generate_port_pairs = mock.Mock()
390 sut._ixia_traffic_gen = mock.MagicMock()
391 sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res
393 sut.resource_helper.client = mock.MagicMock()
394 sut.resource_helper.client_started = mock.MagicMock()
395 sut.resource_helper.client_started.value = 1
396 sut.resource_helper.rfc_helper.iteration.value = 11
397 sut.resource_helper._ix_scenario = mock.Mock()
399 sut.scenario_helper.scenario_cfg = {
404 'allowed_drop_rate': '0.8 - 1',
408 'rules': 'acl_1rule.yaml',
412 'worker_config': '1C/1T',
417 'task_path': '/path/to/task'
420 @mock.patch.object(six.moves.builtins, 'open', create=True)
421 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
422 mock.mock_open(), create=True)
423 @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
424 def _traffic_runner(*args):
425 sut._setup_mq_producer = mock.Mock(return_value='mq_producer')
426 result = sut._traffic_runner(mock_traffic_profile, mock.ANY)
427 self.assertIsNone(result)
432 class TestIxiaBasicScenario(unittest.TestCase):
435 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
436 self.mock_IxNextgen = self._mock_IxNextgen.start()
437 self.context_cfg = mock.Mock()
438 self.ixia_cfg = mock.Mock()
439 self.scenario = tg_rfc2544_ixia.IxiaBasicScenario(self.mock_IxNextgen,
442 self.addCleanup(self._stop_mocks)
444 def _stop_mocks(self):
445 self._mock_IxNextgen.stop()
447 def test___init___(self):
448 self.assertIsInstance(self.scenario, tg_rfc2544_ixia.IxiaBasicScenario)
449 self.assertEqual(self.scenario.client, self.mock_IxNextgen)
451 def test_apply_config(self):
452 self.assertIsNone(self.scenario.apply_config())
454 def test_create_traffic_model(self):
455 self.mock_IxNextgen.get_vports.return_value = [1, 2, 3, 4]
456 self.scenario.create_traffic_model()
457 self.scenario.client.get_vports.assert_called_once()
458 self.scenario.client.create_traffic_model.assert_called_once_with([1, 3], [2, 4])
460 def test_run_protocols(self):
461 self.assertIsNone(self.scenario.run_protocols())
463 def test_stop_protocols(self):
464 self.assertIsNone(self.scenario.stop_protocols())
467 class TestIxiaPppoeClientScenario(unittest.TestCase):
471 'sessions_per_port': 4,
472 'sessions_per_svlan': 1,
475 'ip': ['10.3.3.1', '10.4.4.1']
478 'sessions_per_port': 1,
479 'sessions_per_vlan': 1,
481 'gateway_ip': ['10.1.1.1', '10.2.2.1'],
482 'ip': ['10.1.1.1', '10.2.2.1'],
483 'prefix': ['24', '24']
489 'interfaces': {'xe0': {
490 'local_ip': '10.1.1.1',
491 'netmask': '255.255.255.0'
495 self._mock_IxNextgen = mock.patch.object(ixnet_api, 'IxNextgen')
496 self.mock_IxNextgen = self._mock_IxNextgen.start()
497 self.scenario = tg_rfc2544_ixia.IxiaPppoeClientScenario(
498 self.mock_IxNextgen, self.CONTEXT_CFG, self.IXIA_CFG)
499 tg_rfc2544_ixia.WAIT_PROTOCOLS_STARTED = 2
500 self.addCleanup(self._stop_mocks)
502 def _stop_mocks(self):
503 self._mock_IxNextgen.stop()
505 def test___init___(self):
506 self.assertIsInstance(self.scenario, tg_rfc2544_ixia.IxiaPppoeClientScenario)
507 self.assertEqual(self.scenario.client, self.mock_IxNextgen)
509 @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario,
511 @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario,
512 '_apply_access_network_config')
513 @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario,
514 '_apply_core_network_config')
515 def test_apply_config(self, mock_apply_core_net_cfg,
516 mock_apply_access_net_cfg,
517 mock_fill_ixia_config):
518 self.mock_IxNextgen.get_vports.return_value = [1, 2, 3, 4]
519 self.scenario.apply_config()
520 self.scenario.client.get_vports.assert_called_once()
521 self.assertEqual(self.scenario._uplink_vports, [1, 3])
522 self.assertEqual(self.scenario._downlink_vports, [2, 4])
523 mock_fill_ixia_config.assert_called_once()
524 mock_apply_core_net_cfg.assert_called_once()
525 mock_apply_access_net_cfg.assert_called_once()
527 def test_create_traffic_model(self):
528 self.scenario._access_topologies = 'access'
529 self.scenario._core_topologies = 'core'
530 self.scenario.create_traffic_model()
531 self.scenario.client.create_ipv4_traffic_model.assert_called_once_with(
534 def test_run_protocols(self):
535 self.scenario.client.is_protocols_running.return_value = True
536 self.scenario.run_protocols()
537 self.scenario.client.start_protocols.assert_called_once()
539 def test_run_protocols_timeout_exception(self):
540 self.scenario.client.is_protocols_running.return_value = False
541 with self.assertRaises(exceptions.WaitTimeout):
542 self.scenario.run_protocols()
543 self.scenario.client.start_protocols.assert_called_once()
545 def test_stop_protocols(self):
546 self.scenario.stop_protocols()
547 self.scenario.client.stop_protocols.assert_called_once()
549 def test__get_intf_addr_str_type_input(self):
550 intf = '192.168.10.2/24'
551 ip, mask = self.scenario._get_intf_addr(intf)
552 self.assertEqual(ip, '192.168.10.2')
553 self.assertEqual(mask, 24)
555 def test__get_intf_addr_dict_type_input(self):
556 intf = {'tg__0': 'xe0'}
557 ip, mask = self.scenario._get_intf_addr(intf)
558 self.assertEqual(ip, '10.1.1.1')
559 self.assertEqual(mask, 24)
561 @mock.patch.object(tg_rfc2544_ixia.IxiaPppoeClientScenario, '_get_intf_addr')
562 def test__fill_ixia_config(self, mock_get_intf_addr):
566 'sessions_per_port': 4,
567 'sessions_per_svlan': 1,
570 'ip': ['10.3.3.1/24', '10.4.4.1/24']
573 'sessions_per_port': 1,
574 'sessions_per_vlan': 1,
576 'gateway_ip': ['10.1.1.1/24', '10.2.2.1/24'],
577 'ip': ['10.1.1.1/24', '10.2.2.1/24']
581 mock_get_intf_addr.side_effect = [
589 self.scenario._ixia_cfg = ixia_cfg
590 self.scenario._fill_ixia_config()
591 self.assertEqual(mock_get_intf_addr.call_count, 6)
592 self.assertEqual(self.scenario._ixia_cfg['pppoe_client']['ip'],
593 ['10.3.3.1', '10.4.4.1'])
594 self.assertEqual(self.scenario._ixia_cfg['ipv4_client']['ip'],
595 ['10.1.1.1', '10.2.2.1'])
596 self.assertEqual(self.scenario._ixia_cfg['ipv4_client']['prefix'],
599 @mock.patch('yardstick.network_services.libs.ixia_libs.ixnet.ixnet_api.Vlan')
600 def test__apply_access_network_config_pap_auth(self, mock_vlan):
603 'sessions_per_port': 4,
604 'sessions_per_svlan': 1,
607 'pap_user': 'test_pap',
608 'pap_password': 'pap'
610 pap_user = _ixia_cfg['pppoe_client']['pap_user']
611 pap_passwd = _ixia_cfg['pppoe_client']['pap_password']
612 self.scenario._ixia_cfg = _ixia_cfg
613 self.scenario._uplink_vports = [0, 2]
614 self.scenario.client.add_topology.side_effect = ['Topology 1', 'Topology 2']
615 self.scenario.client.add_device_group.side_effect = ['Dg1', 'Dg2', 'Dg3',
618 self.scenario.client.add_ethernet.side_effect = ['Eth1', 'Eth2', 'Eth3',
619 'Eth4', 'Eth5', 'Eth6',
621 self.scenario._apply_access_network_config()
622 self.assertEqual(self.scenario.client.add_topology.call_count, 2)
623 self.assertEqual(self.scenario.client.add_device_group.call_count, 8)
624 self.assertEqual(self.scenario.client.add_ethernet.call_count, 8)
625 self.assertEqual(mock_vlan.call_count, 16)
626 self.assertEqual(self.scenario.client.add_vlans.call_count, 8)
627 self.assertEqual(self.scenario.client.add_pppox_client.call_count, 8)
628 self.scenario.client.add_topology.assert_has_calls([
629 mock.call('Topology access 0', 0),
630 mock.call('Topology access 1', 2)
632 self.scenario.client.add_device_group.assert_has_calls([
633 mock.call('Topology 1', 'SVLAN 10', 1),
634 mock.call('Topology 1', 'SVLAN 11', 1),
635 mock.call('Topology 1', 'SVLAN 12', 1),
636 mock.call('Topology 1', 'SVLAN 13', 1),
637 mock.call('Topology 2', 'SVLAN 14', 1),
638 mock.call('Topology 2', 'SVLAN 15', 1),
639 mock.call('Topology 2', 'SVLAN 16', 1),
640 mock.call('Topology 2', 'SVLAN 17', 1)
642 self.scenario.client.add_ethernet.assert_has_calls([
643 mock.call('Dg1', 'Ethernet'),
644 mock.call('Dg2', 'Ethernet'),
645 mock.call('Dg3', 'Ethernet'),
646 mock.call('Dg4', 'Ethernet'),
647 mock.call('Dg5', 'Ethernet'),
648 mock.call('Dg6', 'Ethernet'),
649 mock.call('Dg7', 'Ethernet'),
650 mock.call('Dg8', 'Ethernet')
652 mock_vlan.assert_has_calls([
653 mock.call(vlan_id=10),
654 mock.call(vlan_id=20, vlan_id_step=1),
655 mock.call(vlan_id=11),
656 mock.call(vlan_id=20, vlan_id_step=1),
657 mock.call(vlan_id=12),
658 mock.call(vlan_id=20, vlan_id_step=1),
659 mock.call(vlan_id=13),
660 mock.call(vlan_id=20, vlan_id_step=1),
661 mock.call(vlan_id=14),
662 mock.call(vlan_id=20, vlan_id_step=1),
663 mock.call(vlan_id=15),
664 mock.call(vlan_id=20, vlan_id_step=1),
665 mock.call(vlan_id=16),
666 mock.call(vlan_id=20, vlan_id_step=1),
667 mock.call(vlan_id=17),
668 mock.call(vlan_id=20, vlan_id_step=1)
670 self.scenario.client.add_pppox_client.assert_has_calls([
671 mock.call('Eth1', 'pap', pap_user, pap_passwd),
672 mock.call('Eth2', 'pap', pap_user, pap_passwd),
673 mock.call('Eth3', 'pap', pap_user, pap_passwd),
674 mock.call('Eth4', 'pap', pap_user, pap_passwd),
675 mock.call('Eth5', 'pap', pap_user, pap_passwd),
676 mock.call('Eth6', 'pap', pap_user, pap_passwd),
677 mock.call('Eth7', 'pap', pap_user, pap_passwd),
678 mock.call('Eth8', 'pap', pap_user, pap_passwd)
681 def test__apply_access_network_config_chap_auth(self):
684 'sessions_per_port': 4,
685 'sessions_per_svlan': 1,
688 'chap_user': 'test_chap',
689 'chap_password': 'chap'
691 chap_user = _ixia_cfg['pppoe_client']['chap_user']
692 chap_passwd = _ixia_cfg['pppoe_client']['chap_password']
693 self.scenario._ixia_cfg = _ixia_cfg
694 self.scenario._uplink_vports = [0, 2]
695 self.scenario.client.add_ethernet.side_effect = ['Eth1', 'Eth2', 'Eth3',
696 'Eth4', 'Eth5', 'Eth6',
698 self.scenario._apply_access_network_config()
699 self.assertEqual(self.scenario.client.add_pppox_client.call_count, 8)
700 self.scenario.client.add_pppox_client.assert_has_calls([
701 mock.call('Eth1', 'chap', chap_user, chap_passwd),
702 mock.call('Eth2', 'chap', chap_user, chap_passwd),
703 mock.call('Eth3', 'chap', chap_user, chap_passwd),
704 mock.call('Eth4', 'chap', chap_user, chap_passwd),
705 mock.call('Eth5', 'chap', chap_user, chap_passwd),
706 mock.call('Eth6', 'chap', chap_user, chap_passwd),
707 mock.call('Eth7', 'chap', chap_user, chap_passwd),
708 mock.call('Eth8', 'chap', chap_user, chap_passwd)
711 @mock.patch('yardstick.network_services.libs.ixia_libs.ixnet.ixnet_api.Vlan')
712 def test__apply_core_network_config_no_bgp_proto(self, mock_vlan):
713 self.scenario._downlink_vports = [1, 3]
714 self.scenario.client.add_topology.side_effect = ['Topology 1', 'Topology 2']
715 self.scenario.client.add_device_group.side_effect = ['Dg1', 'Dg2']
716 self.scenario.client.add_ethernet.side_effect = ['Eth1', 'Eth2']
717 self.scenario._apply_core_network_config()
718 self.assertEqual(self.scenario.client.add_topology.call_count, 2)
719 self.assertEqual(self.scenario.client.add_device_group.call_count, 2)
720 self.assertEqual(self.scenario.client.add_ethernet.call_count, 2)
721 self.assertEqual(mock_vlan.call_count, 2)
722 self.assertEqual(self.scenario.client.add_vlans.call_count, 2)
723 self.assertEqual(self.scenario.client.add_ipv4.call_count, 2)
724 self.scenario.client.add_topology.assert_has_calls([
725 mock.call('Topology core 0', 1),
726 mock.call('Topology core 1', 3)
728 self.scenario.client.add_device_group.assert_has_calls([
729 mock.call('Topology 1', 'Core port 0', 1),
730 mock.call('Topology 2', 'Core port 1', 1)
732 self.scenario.client.add_ethernet.assert_has_calls([
733 mock.call('Dg1', 'Ethernet'),
734 mock.call('Dg2', 'Ethernet')
736 mock_vlan.assert_has_calls([
737 mock.call(vlan_id=101),
738 mock.call(vlan_id=102)
740 self.scenario.client.add_ipv4.assert_has_calls([
741 mock.call('Eth1', name='ipv4', addr=ipaddress.IPv4Address('10.1.1.2'),
742 addr_step='0.0.0.1', prefix='24', gateway='10.1.1.1'),
743 mock.call('Eth2', name='ipv4', addr=ipaddress.IPv4Address('10.2.2.2'),
744 addr_step='0.0.0.1', prefix='24', gateway='10.2.2.1')
746 self.scenario.client.add_bgp.assert_not_called()
748 def test__apply_core_network_config_with_bgp_proto(self):
751 'bgp_type': 'external',
752 'dut_ip': '10.0.0.1',
756 self.scenario._ixia_cfg['ipv4_client'].update(bgp_params)
757 self.scenario._downlink_vports = [1, 3]
758 self.scenario.client.add_ipv4.side_effect = ['ipv4_1', 'ipv4_2']
759 self.scenario._apply_core_network_config()
760 self.assertEqual(self.scenario.client.add_bgp.call_count, 2)
761 self.scenario.client.add_bgp.assert_has_calls([
762 mock.call('ipv4_1', dut_ip=bgp_params["bgp"]["dut_ip"],
763 local_as=bgp_params["bgp"]["as_number"],
764 bgp_type=bgp_params["bgp"]["bgp_type"]),
765 mock.call('ipv4_2', dut_ip=bgp_params["bgp"]["dut_ip"],
766 local_as=bgp_params["bgp"]["as_number"],
767 bgp_type=bgp_params["bgp"]["bgp_type"])