From 4545b967760ca795a3c67f043eaca60798a90570 Mon Sep 17 00:00:00 2001 From: Deepak S Date: Tue, 20 Jun 2017 14:18:57 -0700 Subject: IXIA traffic generator Change-Id: I09bcb3f2c4b945283070d442589d3bf00468abbc Signed-off-by: Deepak S Signed-off-by: Edward MacGillivray Signed-off-by: Ross Brattain --- tests/unit/network_services/libs/__init__.py | 0 .../network_services/libs/ixia_libs/__init__.py | 0 .../network_services/libs/ixia_libs/test_IxNet.py | 882 +++++++++++++++++++++ .../traffic_profile/test_http_ixload.py | 250 ++++++ .../traffic_profile/test_ixia_rfc2544.py | 648 +++++++++++++++ .../vnf_generic/vnf/test_tg_ixload.py | 374 +++++++++ .../vnf_generic/vnf/test_tg_rfc2544_ixia.py | 405 ++++++++++ 7 files changed, 2559 insertions(+) create mode 100644 tests/unit/network_services/libs/__init__.py create mode 100644 tests/unit/network_services/libs/ixia_libs/__init__.py create mode 100644 tests/unit/network_services/libs/ixia_libs/test_IxNet.py create mode 100644 tests/unit/network_services/traffic_profile/test_http_ixload.py create mode 100644 tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py create mode 100644 tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py create mode 100644 tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py (limited to 'tests/unit/network_services') diff --git a/tests/unit/network_services/libs/__init__.py b/tests/unit/network_services/libs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/network_services/libs/ixia_libs/__init__.py b/tests/unit/network_services/libs/ixia_libs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py new file mode 100644 index 000000000..9114b5163 --- /dev/null +++ b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py @@ -0,0 +1,882 @@ +#!/usr/bin/env python + +# Copyright (c) 2016-2017 Intel 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. +# + +# Unittest for yardstick.network_services.libs.ixia_libs.IxNet + +from __future__ import absolute_import +import unittest +import mock + +from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IxNextgen +from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IP_VERSION_4 +from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IP_VERSION_6 + + +class TestIxNextgen(unittest.TestCase): + + def test___init__(self): + ixnet_gen = IxNextgen() + self.assertIsNone(ixnet_gen._bidir) + + @mock.patch("yardstick.network_services.libs.ixia_libs.IxNet.IxNet.IxNetwork") + @mock.patch("yardstick.network_services.libs.ixia_libs.IxNet.IxNet.sys") + def test_connect(self, mock_sys, mock_ix_network): + mock_ix_network.IxNet.return_value = mock_ixnet = mock.Mock() + + ixnet_gen = IxNextgen() + ixnet_gen.get_config = mock.MagicMock() + ixnet_gen.get_ixnet = mock.MagicMock() + + result = ixnet_gen._connect({"py_lib_path": "/tmp"}) + self.assertIsNotNone(result) + self.assertEqual(mock_ix_network.IxNet.call_count, 1) + self.assertEqual(mock_ixnet.connect.call_count, 1) + + def test_clear_ixia_config(self): + ixnet = mock.MagicMock() + ixnet.execute = mock.Mock() + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.clear_ixia_config() + self.assertIsNone(result) + self.assertEqual(ixnet.execute.call_count, 1) + + def test_load_ixia_profile(self): + ixnet = mock.MagicMock() + ixnet.execute = mock.Mock() + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.load_ixia_profile({}) + self.assertIsNone(result) + self.assertEqual(ixnet.execute.call_count, 1) + + def test_load_ixia_config(self): + ixnet = mock.MagicMock() + ixnet.execute = mock.Mock() + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_load_config({}) + self.assertIsNone(result) + self.assertEqual(ixnet.execute.call_count, 2) + + @mock.patch('yardstick.network_services.libs.ixia_libs.IxNet.IxNet.log') + def test_ix_assign_ports(self, mock_logger): + ixnet = mock.MagicMock() + ixnet.getList.return_value = [0, 1] + ixnet.getAttribute.side_effect = ['up', 'down'] + + config = { + 'chassis': '1.1.1.1', + 'card1': '1', + 'card2': '2', + 'port1': '2', + 'port2': '2', + } + + ixnet_gen = IxNextgen(ixnet) + ixnet_gen._cfg = config + + result = ixnet_gen.ix_assign_ports() + self.assertIsNone(result) + self.assertEqual(ixnet.execute.call_count, 1) + self.assertEqual(ixnet.commit.call_count, 1) + self.assertEqual(ixnet.getAttribute.call_count, 2) + self.assertEqual(mock_logger.error.call_count, 1) + + def test_ix_update_frame(self): + static_traffic_params = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": { + "64B": "100", + "1KB": "0", + }, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": False, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.remapIds.return_value = ["0"] + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + ixnet.getList.side_effect = [ + [1], + [1], + [1], + [ + "ethernet.header.destinationAddress", + "ethernet.header.sourceAddress", + ], + ] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_update_frame(static_traffic_params) + self.assertIsNone(result) + self.assertEqual(ixnet.setMultiAttribute.call_count, 7) + self.assertEqual(ixnet.commit.call_count, 2) + + def test_ix_update_udp(self): + ixnet = mock.MagicMock() + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_update_udp({}) + self.assertIsNone(result) + + def test_ix_update_tcp(self): + ixnet = mock.MagicMock() + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_update_tcp({}) + self.assertIsNone(result) + + def test_ix_start_traffic(self): + ixnet = mock.MagicMock() + ixnet.getList.return_value = [0] + ixnet.getAttribute.return_value = 'down' + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_start_traffic() + self.assertIsNone(result) + self.assertEqual(ixnet.getList.call_count, 1) + self.assertEqual(ixnet.execute.call_count, 3) + + def test_ix_stop_traffic(self): + ixnet = mock.MagicMock() + ixnet.getList.return_value = [0] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_stop_traffic() + self.assertIsNone(result) + self.assertEqual(ixnet.getList.call_count, 1) + self.assertEqual(ixnet.execute.call_count, 1) + + def test_ix_get_statistics(self): + ixnet = mock.MagicMock() + ixnet.execute.return_value = "" + ixnet.getList.side_effect = [ + [ + '::ixNet::OBJ-/statistics/view:"Traffic Item Statistics"', + '::ixNet::OBJ-/statistics/view:"Port Statistics"', + ], + [ + '::ixNet::OBJ-/statistics/view:"Flow Statistics"', + ], + ] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_get_statistics() + self.assertIsNotNone(result) + self.assertEqual(ixnet.getList.call_count, 2) + self.assertEqual(ixnet.execute.call_count, 20) + + def test_find_view_obj_no_where(self): + views = ['here', 'there', 'everywhere'] + result = IxNextgen.find_view_obj('no_where', views) + self.assertEqual(result, '') + + def test_add_ip_header_v4(self): + static_traffic_params = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "count": 1024, + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.remapIds.return_value = ["0"] + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + ixnet.getList.side_effect = [[1], [0], [0], ["srcIp", "dstIp"]] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.add_ip_header(static_traffic_params, IP_VERSION_4) + self.assertIsNone(result) + self.assertGreater(ixnet.setMultiAttribute.call_count, 0) + self.assertEqual(ixnet.commit.call_count, 1) + + def test_add_ip_header_v4_nothing_to_do(self): + static_traffic_params = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "count": 1024, + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.remapIds.return_value=["0"] + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + ixnet.getList.side_effect = [[1], [0, 1], [0], ["srcIp", "dstIp"]] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.add_ip_header(static_traffic_params, IP_VERSION_4) + self.assertIsNone(result) + self.assertGreater(ixnet.setMultiAttribute.call_count, 0) + self.assertEqual(ixnet.commit.call_count, 1) + + def test_add_ip_header_v6(self): + static_traffic_profile = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.getList.side_effect = [[1], [1], [1], ["srcIp", "dstIp"]] + ixnet.remapIds.return_value = ["0"] + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.add_ip_header(static_traffic_profile, IP_VERSION_6) + self.assertIsNone(result) + self.assertGreater(ixnet.setMultiAttribute.call_count, 0) + self.assertEqual(ixnet.commit.call_count, 1) + + def test_add_ip_header_v6_nothing_to_do(self): + static_traffic_params = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "count": 1024, + "ttl": 32 + }, + "outer_l3v6": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": {"64B": "100"}, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.getList.side_effect = [[1], [0, 1], [1], ["srcIP", "dstIP"]] + ixnet.remapIds.return_value = ["0"] + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.add_ip_header(static_traffic_params, IP_VERSION_6) + self.assertIsNone(result) + self.assertEqual(ixnet.setMultiAttribute.call_count, 0) + + def test_set_random_ip_multi_attributes_bad_ip_version(self): + bad_ip_version = object() + ixnet_gen = IxNextgen(mock.Mock()) + mock1 = mock.Mock() + mock2 = mock.Mock() + mock3 = mock.Mock() + with self.assertRaises(ValueError): + ixnet_gen.set_random_ip_multi_attributes(mock1, bad_ip_version, mock2, mock3) + + def test_get_config(self): + tg_cfg = { + "vdu": [ + { + "external-interface": [ + { + "virtual-interface": { + "vpci": "0000:07:00.1", + }, + }, + { + "virtual-interface": { + "vpci": "0001:08:01.2", + }, + }, + ], + }, + ], + "mgmt-interface": { + "ip": "test1", + "tg-config": { + "dut_result_dir": "test2", + "version": "test3", + "ixchassis": "test4", + "tcl_port": "test5", + "py_lib_path": "test6", + }, + } + } + + expected = { + 'py_lib_path': 'test6', + 'machine': 'test1', + 'port': 'test5', + 'chassis': 'test4', + 'card1': '0000', + 'port1': '07', + 'card2': '0001', + 'port2': '08', + 'output_dir': 'test2', + 'version': 'test3', + 'bidir': True, + } + + result = IxNextgen.get_config(tg_cfg) + self.assertDictEqual(result, expected) + + def test_ix_update_ether(self): + static_traffic_params = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + ixnet.getList.side_effect = [ + [1], + [1], + [1], + [ + "ethernet.header.destinationAddress", + "ethernet.header.sourceAddress", + ], + ] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_update_ether(static_traffic_params) + self.assertIsNone(result) + self.assertGreater(ixnet.setMultiAttribute.call_count, 0) + + def test_ix_update_ether_nothing_to_do(self): + static_traffic_params = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + + ixnet = mock.MagicMock() + ixnet.setMultiAttribute.return_value = [1] + ixnet.commit.return_value = [1] + ixnet.getList.side_effect=[ + [1], + [1], + [1], + [ + "ethernet.header.destinationAddress", + "ethernet.header.sourceAddress", + ], + ] + + ixnet_gen = IxNextgen(ixnet) + + result = ixnet_gen.ix_update_ether(static_traffic_params) + self.assertIsNone(result) + self.assertEqual(ixnet.setMultiAttribute.call_count, 0) diff --git a/tests/unit/network_services/traffic_profile/test_http_ixload.py b/tests/unit/network_services/traffic_profile/test_http_ixload.py new file mode 100644 index 000000000..2e1b6f4ff --- /dev/null +++ b/tests/unit/network_services/traffic_profile/test_http_ixload.py @@ -0,0 +1,250 @@ +# Copyright (c) 2017 Intel 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. + + +from __future__ import absolute_import +import unittest +import mock +import runpy + +from oslo_serialization import jsonutils + +from yardstick.network_services.traffic_profile import http_ixload + + +class TestIxLoadTrafficGen(unittest.TestCase): + + def test_parse_run_test(self): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + j = jsonutils.dump_as_bytes(test_input) + ixload = http_ixload.IXLOADHttpTest(j) + self.assertDictEqual(ixload.test_input, test_input) + self.assertIsNone(ixload.parse_run_test()) + self.assertEqual(ixload.ports_to_reassign, [ + ["IXIA_CHASSIS", "CARD", 1], + ["IXIA_CHASSIS", "CARD", 2], + ["IXIA_CHASSIS", "CARD", 3], + ]) + + def test_format_ports_for_reassignment(self): + ports = [ + ["IXIA_CHASSIS", "CARD", 1], + ["IXIA_CHASSIS", "CARD", 2], + ["IXIA_CHASSIS", "CARD", 3], + ] + formatted = http_ixload.IXLOADHttpTest.format_ports_for_reassignment(ports) + self.assertEqual(formatted, [ + "IXIA_CHASSIS;CARD;1", + "IXIA_CHASSIS;CARD;2", + "IXIA_CHASSIS;CARD;3", + ]) + + def test_reassign_ports(self): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + j = jsonutils.dump_as_bytes(test_input) + ixload = http_ixload.IXLOADHttpTest(j) + repository = mock.Mock() + test = mock.MagicMock() + test.setPorts = mock.Mock() + ports_to_reassign = [(1, 2, 3), (1, 2, 4)] + ixload.format_ports_for_reassignment = mock.Mock(return_value=["1;2;3"]) + self.assertIsNone(ixload.reassign_ports(test, repository, ports_to_reassign)) + + def test_reassign_ports_error(self): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + j = jsonutils.dump_as_bytes(test_input) + ixload = http_ixload.IXLOADHttpTest(j) + repository = mock.Mock() + test = "test" + ports_to_reassign = [(1, 2, 3), (1, 2, 4)] + ixload.format_ports_for_reassignment = mock.Mock(return_value=["1;2;3"]) + ixload.ix_load = mock.MagicMock() + ixload.ix_load.delete = mock.Mock() + ixload.ix_load.disconnect = mock.Mock() + with self.assertRaises(Exception): + ixload.reassign_ports(test, repository, ports_to_reassign) + + def test_stat_collector(self): + args = [0, 1] + self.assertIsNone( + http_ixload.IXLOADHttpTest.stat_collector(*args)) + + def test_IxL_StatCollectorCommand(self): + args = [[0, 1, 2, 3], [0, 1, 2, 3]] + self.assertIsNone( + http_ixload.IXLOADHttpTest.IxL_StatCollectorCommand(*args)) + + def test_set_results_dir(self): + test_stat_collector = mock.MagicMock() + test_stat_collector.setResultDir = mock.Mock() + results_on_windows = "c:/Results" + self.assertIsNone( + http_ixload.IXLOADHttpTest.set_results_dir(test_stat_collector, + results_on_windows)) + + def test_set_results_dir_error(self): + test_stat_collector = "" + results_on_windows = "c:/Results" + with self.assertRaises(Exception): + http_ixload.IXLOADHttpTest.set_results_dir(test_stat_collector, results_on_windows) + + def test_load_config_file(self): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + j = jsonutils.dump_as_bytes(test_input) + ixload = http_ixload.IXLOADHttpTest(j) + ixload.ix_load = mock.MagicMock() + ixload.ix_load.new = mock.Mock(return_value="") + self.assertIsNotNone(ixload.load_config_file("ixload.cfg")) + + def test_load_config_file_error(self): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + j = jsonutils.dump_as_bytes(test_input) + ixload = http_ixload.IXLOADHttpTest(j) + ixload.ix_load = "test" + with self.assertRaises(Exception): + ixload.load_config_file("ixload.cfg") + + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.IxLoad') + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.StatCollectorUtils') + def test_start_http_test_connect_error(self, mock_collector_type, mock_ixload_type): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + + j = jsonutils.dump_as_bytes(test_input) + + mock_ixload = mock_ixload_type() + mock_ixload.connect.side_effect = RuntimeError + + ixload = http_ixload.IXLOADHttpTest(j) + ixload.results_on_windows = 'windows_result_dir' + ixload.result_dir = 'my_result_dir' + + with self.assertRaises(RuntimeError): + ixload.start_http_test() + + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.IxLoad') + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.StatCollectorUtils') + def test_start_http_test(self, mock_collector_type, mock_ixload_type): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + + j = jsonutils.dump_as_bytes(test_input) + + ixload = http_ixload.IXLOADHttpTest(j) + ixload.results_on_windows = 'windows_result_dir' + ixload.result_dir = 'my_result_dir' + ixload.load_config_file = mock.MagicMock() + + self.assertIsNone(ixload.start_http_test()) + + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.IxLoad') + @mock.patch('yardstick.network_services.traffic_profile.http_ixload.StatCollectorUtils') + def test_start_http_test_reassign_error(self, mock_collector_type, mock_ixload_type): + ports = [1, 2, 3] + test_input = { + "remote_server": "REMOTE_SERVER", + "ixload_cfg": "IXLOAD_CFG", + "result_dir": "RESULT_DIR", + "ixia_chassis": "IXIA_CHASSIS", + "IXIA": { + "card": "CARD", + "ports": ports, + }, + } + + j = jsonutils.dump_as_bytes(test_input) + + ixload = http_ixload.IXLOADHttpTest(j) + ixload.load_config_file = mock.MagicMock() + + reassign_ports = mock.Mock(side_effect=RuntimeError) + ixload.reassign_ports = reassign_ports + ixload.results_on_windows = 'windows_result_dir' + ixload.result_dir = 'my_result_dir' + + ixload.start_http_test() + self.assertEqual(reassign_ports.call_count, 1) + + @mock.patch("yardstick.network_services.traffic_profile.http_ixload.IXLOADHttpTest") + def test_main(self, IXLOADHttpTest): + args = ["1", "2", "3"] + http_ixload.main(args) diff --git a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py new file mode 100644 index 000000000..6dba64af9 --- /dev/null +++ b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py @@ -0,0 +1,648 @@ +#!/usr/bin/env python + +# Copyright (c) 2016-2017 Intel 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. +# + +from __future__ import absolute_import +from __future__ import division +import unittest +import mock + +STL_MOCKS = { + 'stl': mock.MagicMock(), + 'stl.trex_stl_lib': mock.MagicMock(), + 'stl.trex_stl_lib.base64': mock.MagicMock(), + 'stl.trex_stl_lib.binascii': mock.MagicMock(), + 'stl.trex_stl_lib.collections': mock.MagicMock(), + 'stl.trex_stl_lib.copy': mock.MagicMock(), + 'stl.trex_stl_lib.datetime': mock.MagicMock(), + 'stl.trex_stl_lib.functools': mock.MagicMock(), + 'stl.trex_stl_lib.imp': mock.MagicMock(), + 'stl.trex_stl_lib.inspect': mock.MagicMock(), + 'stl.trex_stl_lib.json': mock.MagicMock(), + 'stl.trex_stl_lib.linecache': mock.MagicMock(), + 'stl.trex_stl_lib.math': mock.MagicMock(), + 'stl.trex_stl_lib.os': mock.MagicMock(), + 'stl.trex_stl_lib.platform': mock.MagicMock(), + 'stl.trex_stl_lib.pprint': mock.MagicMock(), + 'stl.trex_stl_lib.random': mock.MagicMock(), + 'stl.trex_stl_lib.re': mock.MagicMock(), + 'stl.trex_stl_lib.scapy': mock.MagicMock(), + 'stl.trex_stl_lib.socket': mock.MagicMock(), + 'stl.trex_stl_lib.string': mock.MagicMock(), + 'stl.trex_stl_lib.struct': mock.MagicMock(), + 'stl.trex_stl_lib.sys': mock.MagicMock(), + 'stl.trex_stl_lib.threading': mock.MagicMock(), + 'stl.trex_stl_lib.time': mock.MagicMock(), + 'stl.trex_stl_lib.traceback': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(), + 'stl.trex_stl_lib.types': mock.MagicMock(), + 'stl.trex_stl_lib.utils': mock.MagicMock(), + 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(), + 'stl.trex_stl_lib.utils.collections': mock.MagicMock(), + 'stl.trex_stl_lib.utils.common': mock.MagicMock(), + 'stl.trex_stl_lib.utils.json': mock.MagicMock(), + 'stl.trex_stl_lib.utils.os': mock.MagicMock(), + 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(), + 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(), + 'stl.trex_stl_lib.utils.random': mock.MagicMock(), + 'stl.trex_stl_lib.utils.re': mock.MagicMock(), + 'stl.trex_stl_lib.utils.string': mock.MagicMock(), + 'stl.trex_stl_lib.utils.sys': mock.MagicMock(), + 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(), + 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(), + 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(), + 'stl.trex_stl_lib.warnings': mock.MagicMock(), + 'stl.trex_stl_lib.yaml': mock.MagicMock(), + 'stl.trex_stl_lib.zlib': mock.MagicMock(), + 'stl.trex_stl_lib.zmq': mock.MagicMock(), +} + +STLClient = mock.MagicMock() +stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) +stl_patch.start() + +if stl_patch: + from yardstick.network_services.traffic_profile.traffic_profile \ + import TrexProfile + from yardstick.network_services.traffic_profile.ixia_rfc2544 import \ + IXIARFC2544Profile + from yardstick.network_services.traffic_profile import ixia_rfc2544 + + +class TestIXIARFC2544Profile(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}} + + PROFILE = {'description': 'Traffic profile to run RFC2544 latency', + 'name': 'rfc2544', + 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile', + 'frame_rate': 100}, + 'public': {'ipv4': + {'outer_l2': {'framesize': + {'64B': '100', '1518B': '0', + '128B': '0', '1400B': '0', + '256B': '0', '373b': '0', + '570B': '0'}}, + 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255', + 'proto': 'udp', + 'srcip4': '90.90.1.1-90.105.255.255', + 'dscp': 0, 'ttl': 32}, + 'outer_l4': {'srcport': '2001', + 'dsrport': '1234'}}}, + 'private': {'ipv4': + {'outer_l2': {'framesize': + {'64B': '100', '1518B': '0', + '128B': '0', '1400B': '0', + '256B': '0', '373b': '0', + '570B': '0'}}, + 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255', + 'proto': 'udp', + 'srcip4': '1.1.1.1-1.15.255.255', + 'dscp': 0, 'ttl': 32}, + 'outer_l4': {'dstport': '2001', + 'srcport': '1234'}}}, + 'schema': 'isb:traffic_profile:0.1'} + + def test_get_ixia_traffic_profile_error(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [-1] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + STATIC_TRAFFIC = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC + + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.rate = 100 + mac = {"src_mac_0": "00:00:00:00:00:01", + "src_mac_1": "00:00:00:00:00:02", + "src_mac_2": "00:00:00:00:00:02", + "dst_mac_0": "00:00:00:00:00:03", + "dst_mac_1": "00:00:00:00:00:04", + "dst_mac_2": "00:00:00:00:00:04"} + self.assertRaises(IOError, r_f_c2544_profile._get_ixia_traffic_profile, + self.PROFILE, mac, xfile="tmp", + static_traffic=STATIC_TRAFFIC) + + + @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open") + def test_get_ixia_traffic_profile(self, mock_open): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [-1] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + STATIC_TRAFFIC = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC + + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.rate = 100 + mac = {"src_mac_0": "00:00:00:00:00:01", + "src_mac_1": "00:00:00:00:00:02", + "src_mac_2": "00:00:00:00:00:02", + "dst_mac_0": "00:00:00:00:00:03", + "dst_mac_1": "00:00:00:00:00:04", + "dst_mac_2": "00:00:00:00:00:04"} + result = r_f_c2544_profile._get_ixia_traffic_profile( + self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC) + self.assertIsNotNone(result) + + @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open") + def test_get_ixia_traffic_profile_v6(self, mock_open): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [-1] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + STATIC_TRAFFIC = { + "private": { + "id": 1, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:03", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v4": { + "dscp": 0, + "dstip4": "152.16.40.20", + "proto": "udp", + "srcip4": "152.16.100.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "2001", + "srcport": "1234" + }, + "traffic_type": "continuous" + }, + "public": { + "id": 2, + "bidir": "False", + "duration": 60, + "iload": "100", + "outer_l2": { + "dstmac": "00:00:00:00:00:04", + "framesPerSecond": True, + "framesize": 64, + "srcmac": "00:00:00:00:00:01" + }, + "outer_l3": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v4": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l3v6": { + "count": 1024, + "dscp": 0, + "dstip4": "152.16.100.20", + "proto": "udp", + "srcip4": "152.16.40.20", + "ttl": 32 + }, + "outer_l4": { + "dstport": "1234", + "srcport": "2001" + }, + "traffic_type": "continuous" + } + } + ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC + + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.rate = 100 + mac = {"src_mac_0": "00:00:00:00:00:01", + "src_mac_1": "00:00:00:00:00:02", + "src_mac_2": "00:00:00:00:00:02", + "dst_mac_0": "00:00:00:00:00:03", + "dst_mac_1": "00:00:00:00:00:04", + "dst_mac_2": "00:00:00:00:00:04"} + profile_data = {'description': 'Traffic profile to run RFC2544', + 'name': 'rfc2544', + 'traffic_profile': + {'traffic_type': 'IXIARFC2544Profile', + 'frame_rate': 100}, + 'public': + {'ipv4': + {'outer_l2': {'framesize': + {'64B': '100', '1518B': '0', + '128B': '0', '1400B': '0', + '256B': '0', '373b': '0', + '570B': '0'}}, + 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255', + 'proto': 'udp', + 'srcip6': '90.90.1.1-90.105.255.255', + 'dscp': 0, 'ttl': 32}, + 'outer_l4': {'srcport': '2001', + 'dsrport': '1234'}}}, + 'private': {'ipv4': + {'outer_l2': {'framesize': + {'64B': '100', '1518B': '0', + '128B': '0', '1400B': '0', + '256B': '0', '373b': '0', + '570B': '0'}}, + 'outer_l3v6': + {'dstip6': '9.9.1.1-90.105.255.255', + 'proto': 'udp', + 'srcip6': '1.1.1.1-1.15.255.255', + 'dscp': 0, 'ttl': 32}, + 'outer_l4': {'dstport': '2001', + 'srcport': '1234'}}}, + 'schema': 'isb:traffic_profile:0.1'} + result = r_f_c2544_profile._get_ixia_traffic_profile( + profile_data, mac, static_traffic=STATIC_TRAFFIC) + self.assertIsNotNone(result) + + def test__ixia_traffic_generate(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [-1] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + traffic = {"public": {'iload': 10}, + "private": {'iload': 10}} + ixia_obj = mock.MagicMock() + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.rate = 100 + result = r_f_c2544_profile._ixia_traffic_generate(traffic_generator, + traffic, ixia_obj) + self.assertIsNone(result) + + def test_execute(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [-1] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.first_run = True + r_f_c2544_profile.params = {"public": {'iload': 10}, + "private": {'iload': 10}} + + r_f_c2544_profile.get_streams = mock.Mock() + r_f_c2544_profile.full_profile = {} + r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock() + r_f_c2544_profile.get_multiplier = mock.Mock() + r_f_c2544_profile._ixia_traffic_generate = mock.Mock() + ixia_obj = mock.MagicMock() + self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator, + ixia_obj)) + + def test_get_drop_percentage(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [0] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.params = self.PROFILE + ixia_obj = mock.MagicMock() + r_f_c2544_profile.execute = mock.Mock() + r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock() + r_f_c2544_profile._ixia_traffic_generate = mock.Mock() + r_f_c2544_profile.get_multiplier = mock.Mock() + r_f_c2544_profile.tmp_throughput = 0 + r_f_c2544_profile.tmp_drop = 0 + r_f_c2544_profile.full_profile = {} + samples = {} + for ifname in range(1): + name = "xe{}".format(ifname) + samples[name] = {"rx_throughput_fps": 20, + "tx_throughput_fps": 20, + "rx_throughput_mbps": 10, + "tx_throughput_mbps": 10, + "RxThroughput": 10, + "TxThroughput": 10, + "in_packets": 1000, + "out_packets": 1000} + tol_min = 100.0 + tolerance = 0.0 + self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage( + traffic_generator, samples, + tol_min, tolerance, ixia_obj)) + + def test_get_drop_percentage_update(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [0] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.params = self.PROFILE + ixia_obj = mock.MagicMock() + r_f_c2544_profile.execute = mock.Mock() + r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock() + r_f_c2544_profile._ixia_traffic_generate = mock.Mock() + r_f_c2544_profile.get_multiplier = mock.Mock() + r_f_c2544_profile.tmp_throughput = 0 + r_f_c2544_profile.tmp_drop = 0 + r_f_c2544_profile.full_profile = {} + samples = {} + for ifname in range(1): + name = "xe{}".format(ifname) + samples[name] = {"rx_throughput_fps": 20, + "tx_throughput_fps": 20, + "rx_throughput_mbps": 10, + "tx_throughput_mbps": 10, + "RxThroughput": 10, + "TxThroughput": 10, + "in_packets": 1000, + "out_packets": 1002} + tol_min = 0.0 + tolerance = 1.0 + self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage( + traffic_generator, samples, + tol_min, tolerance, ixia_obj)) + + def test_get_drop_percentage_div_zero(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [0] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.params = self.PROFILE + ixia_obj = mock.MagicMock() + r_f_c2544_profile.execute = mock.Mock() + r_f_c2544_profile._get_ixia_traffic_profile = mock.Mock() + r_f_c2544_profile._ixia_traffic_generate = mock.Mock() + r_f_c2544_profile.get_multiplier = mock.Mock() + r_f_c2544_profile.tmp_throughput = 0 + r_f_c2544_profile.tmp_drop = 0 + r_f_c2544_profile.full_profile = {} + samples = {} + for ifname in range(1): + name = "xe{}".format(ifname) + samples[name] = {"rx_throughput_fps": 20, + "tx_throughput_fps": 20, + "rx_throughput_mbps": 10, + "tx_throughput_mbps": 10, + "RxThroughput": 10, + "TxThroughput": 10, + "in_packets": 1000, + "out_packets": 0} + tol_min = 0.0 + tolerance = 0.0 + r_f_c2544_profile.tmp_throughput = 0 + self.assertIsNotNone(r_f_c2544_profile.get_drop_percentage( + traffic_generator, samples, + tol_min, tolerance, ixia_obj)) + + def test_get_multiplier(self): + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.max_rate = 100 + r_f_c2544_profile.min_rate = 100 + self.assertEqual("1.0", r_f_c2544_profile.get_multiplier()) + + def test_start_ixia_latency(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.my_ports = [0, 1] + traffic_generator.priv_ports = [0] + traffic_generator.pub_ports = [1] + traffic_generator.client = \ + mock.Mock(return_value=True) + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + r_f_c2544_profile.max_rate = 100 + r_f_c2544_profile.min_rate = 100 + ixia_obj = mock.MagicMock() + r_f_c2544_profile._get_ixia_traffic_profile = \ + mock.Mock(return_value={}) + r_f_c2544_profile.full_profile = {} + r_f_c2544_profile._ixia_traffic_generate = mock.Mock() + self.assertEqual( + None, + r_f_c2544_profile.start_ixia_latency(traffic_generator, + ixia_obj)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py new file mode 100644 index 000000000..cda44127e --- /dev/null +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py @@ -0,0 +1,374 @@ +#!/usr/bin/env python + +# Copyright (c) 2016-2017 Intel 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. +# + +from __future__ import absolute_import +import unittest +import mock +import subprocess + +STL_MOCKS = { + 'stl': mock.MagicMock(), + 'stl.trex_stl_lib': mock.MagicMock(), + 'stl.trex_stl_lib.base64': mock.MagicMock(), + 'stl.trex_stl_lib.binascii': mock.MagicMock(), + 'stl.trex_stl_lib.collections': mock.MagicMock(), + 'stl.trex_stl_lib.copy': mock.MagicMock(), + 'stl.trex_stl_lib.datetime': mock.MagicMock(), + 'stl.trex_stl_lib.functools': mock.MagicMock(), + 'stl.trex_stl_lib.imp': mock.MagicMock(), + 'stl.trex_stl_lib.inspect': mock.MagicMock(), + 'stl.trex_stl_lib.json': mock.MagicMock(), + 'stl.trex_stl_lib.linecache': mock.MagicMock(), + 'stl.trex_stl_lib.math': mock.MagicMock(), + 'stl.trex_stl_lib.os': mock.MagicMock(), + 'stl.trex_stl_lib.platform': mock.MagicMock(), + 'stl.trex_stl_lib.pprint': mock.MagicMock(), + 'stl.trex_stl_lib.random': mock.MagicMock(), + 'stl.trex_stl_lib.re': mock.MagicMock(), + 'stl.trex_stl_lib.scapy': mock.MagicMock(), + 'stl.trex_stl_lib.socket': mock.MagicMock(), + 'stl.trex_stl_lib.string': mock.MagicMock(), + 'stl.trex_stl_lib.struct': mock.MagicMock(), + 'stl.trex_stl_lib.sys': mock.MagicMock(), + 'stl.trex_stl_lib.threading': mock.MagicMock(), + 'stl.trex_stl_lib.time': mock.MagicMock(), + 'stl.trex_stl_lib.traceback': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(), + 'stl.trex_stl_lib.types': mock.MagicMock(), + 'stl.trex_stl_lib.utils': mock.MagicMock(), + 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(), + 'stl.trex_stl_lib.utils.collections': mock.MagicMock(), + 'stl.trex_stl_lib.utils.common': mock.MagicMock(), + 'stl.trex_stl_lib.utils.json': mock.MagicMock(), + 'stl.trex_stl_lib.utils.os': mock.MagicMock(), + 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(), + 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(), + 'stl.trex_stl_lib.utils.random': mock.MagicMock(), + 'stl.trex_stl_lib.utils.re': mock.MagicMock(), + 'stl.trex_stl_lib.utils.string': mock.MagicMock(), + 'stl.trex_stl_lib.utils.sys': mock.MagicMock(), + 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(), + 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(), + 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(), + 'stl.trex_stl_lib.warnings': mock.MagicMock(), + 'stl.trex_stl_lib.yaml': mock.MagicMock(), + 'stl.trex_stl_lib.zlib': mock.MagicMock(), + 'stl.trex_stl_lib.zmq': mock.MagicMock(), +} + +STLClient = mock.MagicMock() +stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) +stl_patch.start() + +if stl_patch: + from yardstick.network_services.vnf_generic.vnf.tg_ixload import IxLoadTrafficGen + from yardstick.network_services.vnf_generic.vnf.tg_ixload import IxLoadResourceHelper + from yardstick.network_services.traffic_profile.base import TrafficProfile + + +NAME = "tg__1" + + +class TestIxLoadTrafficGen(unittest.TestCase): + VNFD = {'vnfd:vnfd-catalog': + {'vnfd': + [{'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:04', + 'vpci': '0000:05:00.0', + 'local_ip': '152.16.100.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': '0', + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'local_iface_name': 'xe0', + 'local_mac': '00:00:00:00:00:02'}, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0'}, + {'virtual-interface': + {'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': '1', + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'local_mac': '00:00:00:00:00:01'}, + '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'}]}} + + 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___init__(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + self.assertIsNone(ixload_traffic_gen.data) + + def test_collect_kpi(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + ixload_traffic_gen.data = {} + restult = ixload_traffic_gen.collect_kpi() + self.assertEqual({}, restult) + + def test_listen_traffic(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + self.assertEqual(None, ixload_traffic_gen.listen_traffic({})) + + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.makedirs") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") + def test_instantiate(self, call, shutil, mock_makedirs): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh_mock.run = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + scenario_cfg = {'tc': "nsb_test_case", + 'ixia_profile': "ixload.cfg"} + ixload_traffic_gen.RESULTS_MOUNT = "/tmp/result" + shutil.copy = mock.Mock() + scenario_cfg.update({'options': {'packetsize': 64, 'traffic_type': 4, + 'rfc2544': {'allowed_drop_rate': '0.8 - 1'}, + 'vnf__1': {'rules': 'acl_1rule.yaml', + 'vnf_config': {'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': + '1C/1T', + 'worker_threads': 1}} + }}) + self.assertRaises(IOError, + ixload_traffic_gen.instantiate(scenario_cfg, {})) + + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len") + def test_run_traffic(self, call, shutil, main_open, min, max, len): + mock_traffic_profile = mock.Mock(autospec=TrafficProfile) + mock_traffic_profile.get_traffic_definition.return_value = "64" + mock_traffic_profile.params = self.TRAFFIC_PROFILE + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh_mock.run = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vnfd["mgmt-interface"].update({"tg-config": {}}) + vnfd["mgmt-interface"]["tg-config"].update({"ixchassis": + "1.1.1.1"}) + vnfd["mgmt-interface"]["tg-config"].update({"py_bin_path": + "/root"}) + sut = IxLoadTrafficGen(NAME, vnfd) + sut.connection = mock.Mock() + sut.connection.run = mock.Mock() + sut._traffic_runner = mock.Mock(return_value=0) + shutil.copy = mock.Mock() + result = sut.run_traffic(mock_traffic_profile) + self.assertIsNone(result) + + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len") + def test_run_traffic_csv(self, call, shutil, main_open, min, max, len): + mock_traffic_profile = mock.Mock(autospec=TrafficProfile) + mock_traffic_profile.get_traffic_definition.return_value = "64" + mock_traffic_profile.params = self.TRAFFIC_PROFILE + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh_mock.run = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vnfd["mgmt-interface"].update({"tg-config": {}}) + vnfd["mgmt-interface"]["tg-config"].update({"ixchassis": + "1.1.1.1"}) + vnfd["mgmt-interface"]["tg-config"].update({"py_bin_path": + "/root"}) + sut = IxLoadTrafficGen(NAME, vnfd) + sut.connection = mock.Mock() + sut.connection.run = mock.Mock() + sut._traffic_runner = mock.Mock(return_value=0) + shutil.copy = mock.Mock() + subprocess.call(["touch", "/tmp/1.csv"]) + sut.rel_bin_path = mock.Mock(return_value="/tmp/*.csv") + result = sut.run_traffic(mock_traffic_profile) + self.assertIsNone(result) + + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + def test_terminate(self, call): + with mock.patch("yardstick.ssh.SSH") as ssh: + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + self.assertEqual(None, ixload_traffic_gen.terminate()) + + @mock.patch("yardstick.ssh.SSH") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + def test_parse_csv_read(self, mock_call, mock_ssh): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + kpi_data = { + 'HTTP Total Throughput (Kbps)': 1, + 'HTTP Simulated Users': 2, + 'HTTP Concurrent Connections': '3', + 'HTTP Connection Rate': 4.3, + 'HTTP Transaction Rate': True, + } + http_reader = [kpi_data] + + mock_ssh_type = mock.Mock(autospec=mock_ssh.SSH) + mock_ssh_type.execute.return_value = 0, "", "" + mock_ssh.from_node.return_value = mock_ssh_type + + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + result = ixload_traffic_gen.resource_helper.result + + ixload_traffic_gen.resource_helper.parse_csv_read(http_reader) + for key_left, key_right in IxLoadResourceHelper.KPI_LIST.items(): + self.assertEqual(result[key_left][-1], int(kpi_data[key_right])) + + @mock.patch("yardstick.ssh.SSH") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + def test_parse_csv_read_value_error(self, mock_call, mock_ssh): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + http_reader = [{ + 'HTTP Total Throughput (Kbps)': 1, + 'HTTP Simulated Users': 2, + 'HTTP Concurrent Connections': "not a number", + 'HTTP Connection Rate': 4, + 'HTTP Transaction Rate': 5, + }] + + mock_ssh_type = mock.Mock(autospec=mock_ssh.SSH) + mock_ssh_type.execute.return_value = 0, "", "" + mock_ssh.from_node.return_value = mock_ssh_type + + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + init_value = ixload_traffic_gen.resource_helper.result + + ixload_traffic_gen.resource_helper.parse_csv_read(http_reader) + self.assertDictEqual(ixload_traffic_gen.resource_helper.result, init_value) + + @mock.patch("yardstick.ssh.SSH") + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + def test_parse_csv_read_error(self, mock_call, mock_ssh): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + http_reader = [{ + 'HTTP Total Throughput (Kbps)': 1, + 'HTTP Simulated Users': 2, + 'HTTP Concurrent Connections': 3, + 'HTTP Transaction Rate': 5, + }] + + mock_ssh_type = mock.Mock(autospec=mock_ssh.SSH) + mock_ssh_type.execute.return_value = 0, "", "" + mock_ssh.from_node.return_value = mock_ssh_type + + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + + with self.assertRaises(KeyError): + ixload_traffic_gen.resource_helper.parse_csv_read(http_reader) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py new file mode 100644 index 000000000..8f7f05772 --- /dev/null +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -0,0 +1,405 @@ +#!/usr/bin/env python + +# Copyright (c) 2016-2017 Intel 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. +# + +from __future__ import absolute_import +import os +import unittest +import mock +STL_MOCKS = { + 'stl': mock.MagicMock(), + 'stl.trex_stl_lib': mock.MagicMock(), + 'stl.trex_stl_lib.base64': mock.MagicMock(), + 'stl.trex_stl_lib.binascii': mock.MagicMock(), + 'stl.trex_stl_lib.collections': mock.MagicMock(), + 'stl.trex_stl_lib.copy': mock.MagicMock(), + 'stl.trex_stl_lib.datetime': mock.MagicMock(), + 'stl.trex_stl_lib.functools': mock.MagicMock(), + 'stl.trex_stl_lib.imp': mock.MagicMock(), + 'stl.trex_stl_lib.inspect': mock.MagicMock(), + 'stl.trex_stl_lib.json': mock.MagicMock(), + 'stl.trex_stl_lib.linecache': mock.MagicMock(), + 'stl.trex_stl_lib.math': mock.MagicMock(), + 'stl.trex_stl_lib.os': mock.MagicMock(), + 'stl.trex_stl_lib.platform': mock.MagicMock(), + 'stl.trex_stl_lib.pprint': mock.MagicMock(), + 'stl.trex_stl_lib.random': mock.MagicMock(), + 'stl.trex_stl_lib.re': mock.MagicMock(), + 'stl.trex_stl_lib.scapy': mock.MagicMock(), + 'stl.trex_stl_lib.socket': mock.MagicMock(), + 'stl.trex_stl_lib.string': mock.MagicMock(), + 'stl.trex_stl_lib.struct': mock.MagicMock(), + 'stl.trex_stl_lib.sys': mock.MagicMock(), + 'stl.trex_stl_lib.threading': mock.MagicMock(), + 'stl.trex_stl_lib.time': mock.MagicMock(), + 'stl.trex_stl_lib.traceback': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(), + 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(), + 'stl.trex_stl_lib.types': mock.MagicMock(), + 'stl.trex_stl_lib.utils': mock.MagicMock(), + 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(), + 'stl.trex_stl_lib.utils.collections': mock.MagicMock(), + 'stl.trex_stl_lib.utils.common': mock.MagicMock(), + 'stl.trex_stl_lib.utils.json': mock.MagicMock(), + 'stl.trex_stl_lib.utils.os': mock.MagicMock(), + 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(), + 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(), + 'stl.trex_stl_lib.utils.random': mock.MagicMock(), + 'stl.trex_stl_lib.utils.re': mock.MagicMock(), + 'stl.trex_stl_lib.utils.string': mock.MagicMock(), + 'stl.trex_stl_lib.utils.sys': mock.MagicMock(), + 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(), + 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(), + 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(), + 'stl.trex_stl_lib.warnings': mock.MagicMock(), + 'stl.trex_stl_lib.yaml': mock.MagicMock(), + 'stl.trex_stl_lib.zlib': mock.MagicMock(), + 'stl.trex_stl_lib.zmq': mock.MagicMock(), +} + +STLClient = mock.MagicMock() +stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) +stl_patch.start() + +if stl_patch: + from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaTrafficGen + from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaRfc2544Helper + from yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia import IxiaResourceHelper + from yardstick.network_services.traffic_profile.base import TrafficProfile + +TEST_FILE_YAML = 'nsb_test_case.yaml' + + +NAME = "tg__1" + + +@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen") +class TestIxiaResourceHelper(unittest.TestCase): + + def test___init___with_custom_rfc_helper(self, mock_ix_nextgen): + class MyRfcHelper(IxiaRfc2544Helper): + pass + + ixia_resource_helper = IxiaResourceHelper(mock.Mock(), MyRfcHelper) + self.assertIsInstance(ixia_resource_helper.rfc_helper, MyRfcHelper) + + def test_stop_collect_with_client(self, mock_ix_nextgen): + mock_client = mock.Mock() + + ixia_resource_helper = IxiaResourceHelper(mock.Mock()) + + ixia_resource_helper.client = mock_client + ixia_resource_helper.stop_collect() + self.assertEqual(mock_client.ix_stop_traffic.call_count, 1) + + +@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen") +class TestIXIATrafficGen(unittest.TestCase): + VNFD = {'vnfd:vnfd-catalog': + {'vnfd': + [{'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:04', + 'vpci': '0000:05:00.0', + 'local_ip': '152.16.100.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': '0', + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'local_iface_name': 'xe0', + 'local_mac': '00:00:00:00:00:02'}, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0'}, + {'virtual-interface': + {'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': '1', + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'local_mac': '00:00:00:00:00:01'}, + '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'}]}} + + 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}} + + TC_YAML = {'scenarios': [{'tc_options': + {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}}, + 'runner': {'duration': 400, + 'interval': 35, 'type': 'Duration'}, + 'traffic_options': + {'flow': 'ipv4_1flow_Packets_vpe.yaml', + 'imix': 'imix_voice.yaml'}, + 'vnf_options': {'vpe': {'cfg': 'vpe_config'}}, + 'traffic_profile': 'ipv4_throughput_vpe.yaml', + 'type': 'NSPerf', + 'nodes': {'tg__1': 'trafficgen_1.yardstick', + 'vnf__1': 'vnf.yardstick'}, + 'topology': 'vpe_vnf_topology.yaml'}], + 'context': {'nfvi_type': 'baremetal', 'type': 'Node', + 'name': 'yardstick', + 'file': '/etc/yardstick/nodes/pod.yaml'}, + 'schema': 'yardstick:task:0.1'} + + def test___init__(self, mock_ixnextgen): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd) + + def test_listen_traffic(self, mock_ixnextgen): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd) + self.assertEqual(None, ixnet_traffic_gen.listen_traffic({})) + + def test_instantiate(self, mock_ixnextgen): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh_mock.run = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd) + scenario_cfg = {'tc': "nsb_test_case", "topology": "", + 'ixia_profile': "ixload.cfg"} + scenario_cfg.update({'options': {'packetsize': 64, + 'traffic_type': 4, + 'rfc2544': {'allowed_drop_rate': '0.8 - 1'}, + 'vnf__1': {'rules': 'acl_1rule.yaml', + 'vnf_config': {'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': + '1C/1T', + 'worker_threads': 1}} + }}) + ixnet_traffic_gen.topology = "" + ixnet_traffic_gen.get_ixobj = mock.MagicMock() + ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock() + ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock() + self.assertRaises( + IOError, + ixnet_traffic_gen.instantiate(scenario_cfg, {})) + + def test_collect_kpi(self, mock_ixnextgen): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd) + ixnet_traffic_gen.data = {} + restult = ixnet_traffic_gen.collect_kpi() + self.assertEqual({}, restult) + + def test_terminate(self, mock_ixnextgen): + with mock.patch("yardstick.ssh.SSH") as ssh: + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "", "")) + ssh.from_node.return_value = ssh_mock + ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd) + ixnet_traffic_gen._terminated = mock.MagicMock() + ixnet_traffic_gen._terminated.value = 0 + ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock() + ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock() + ixnet_traffic_gen._traffic_process = mock.MagicMock() + ixnet_traffic_gen._traffic_process.terminate = mock.Mock() + self.assertEqual(None, ixnet_traffic_gen.terminate()) + + def _get_file_abspath(self, filename): + curr_path = os.path.dirname(os.path.abspath(__file__)) + file_path = os.path.join(curr_path, filename) + return file_path + + def test_scale(self, mock_ix_nextgen): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sut = IxiaTrafficGen('vnf1', vnfd) + sut.scale() + + def test__check_status(self, mock_ix_nextgen): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sut = IxiaTrafficGen('vnf1', vnfd) + sut._check_status() + + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.time") + @mock.patch("yardstick.ssh.SSH") + def test_traffic_runner(self, mock_ixnextgen, mock_ssh, mock_time): + mock_traffic_profile = mock.Mock(autospec=TrafficProfile) + mock_traffic_profile.get_traffic_definition.return_value = "64" + mock_traffic_profile.params = self.TRAFFIC_PROFILE + + mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH) + mock_ssh_instance.execute.return_value = 0, "", "" + mock_ssh_instance.run.return_value = 0, "", "" + + mock_ssh.from_node.return_value = mock_ssh_instance + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vnfd["mgmt-interface"].update({ + 'tg-config': { + "ixchassis": "1.1.1.1", + "py_bin_path": "/root", + } + }) + + samples = {} + name = '' + for ifname in range(1): + name = "xe{}".format(ifname) + samples[name] = { + "Rx_Rate_Kbps": 20, + "Tx_Rate_Kbps": 20, + "Rx_Rate_Mbps": 10, + "Tx_Rate_Mbps": 10, + "RxThroughput": 10, + "TxThroughput": 10, + "Valid_Frames_Rx": 1000, + "Frames_Tx": 1000, + "in_packets": 1000, + "out_packets": 1000, + } + + samples.update({"CurrentDropPercentage": 0.0}) + + last_res = [ + 0, + { + "Rx_Rate_Kbps": [20, 20], + "Tx_Rate_Kbps": [20, 20], + "Rx_Rate_Mbps": [10, 10], + "Tx_Rate_Mbps": [10, 10], + "CurrentDropPercentage": [0, 0], + "RxThroughput": [10, 10], + "TxThroughput": [10, 10], + "Frames_Tx": [1000, 1000], + "in_packets": [1000, 1000], + "Valid_Frames_Rx": [1000, 1000], + "out_packets": [1000, 1000], + }, + ] + + mock_traffic_profile.execute.return_value = ['Completed', samples] + mock_traffic_profile.get_drop_percentage.return_value = ['Completed', samples] + + sut = IxiaTrafficGen(name, vnfd) + sut.tg_port_pairs = [[[0], [1]]] + sut.vnf_port_pairs = [[[0], [1]]] + sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML) + sut.topology = "" + + sut.ssh_helper = mock.Mock() + sut._traffic_process = mock.MagicMock() + sut.generate_port_pairs = mock.Mock() + + sut._ixia_traffic_gen = mock.MagicMock() + sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res + + sut.resource_helper.client = mock.MagicMock() + sut.resource_helper.client_started = mock.MagicMock() + sut.resource_helper.client_started.value = 1 + + sut.scenario_helper.scenario_cfg = { + 'options': { + 'packetsize': 64, + 'traffic_type': 4, + 'rfc2544': { + 'allowed_drop_rate': '0.8 - 1' + }, + 'vnf__1': { + 'rules': 'acl_1rule.yaml', + 'vnf_config': { + 'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': '1C/1T', + 'worker_threads': 1, + }, + }, + }, + 'ixia_profile': {} + } + + result = sut._traffic_runner(mock_traffic_profile) + self.assertIsNone(result) -- cgit 1.2.3-korg