aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/network_services/traffic_profile
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests/unit/network_services/traffic_profile')
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/__init__.py0
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_base.py112
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_fixed.py117
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_http.py47
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py452
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py1024
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_landslide_profile.py136
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_pktgen.py63
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_prox_acl.py74
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py302
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py57
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py130
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_prox_ramp.py95
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py341
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_sip.py51
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py277
-rw-r--r--yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py890
17 files changed, 4168 insertions, 0 deletions
diff --git a/yardstick/tests/unit/network_services/traffic_profile/__init__.py b/yardstick/tests/unit/network_services/traffic_profile/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/__init__.py
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_base.py b/yardstick/tests/unit/network_services/traffic_profile/test_base.py
new file mode 100644
index 000000000..d9244e31b
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_base.py
@@ -0,0 +1,112 @@
+# 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.
+
+import sys
+
+import mock
+import unittest
+
+from yardstick.common import exceptions
+from yardstick.network_services import traffic_profile as tprofile_package
+from yardstick.network_services.traffic_profile import base
+from yardstick import tests as y_tests
+
+
+class TestTrafficProfile(unittest.TestCase):
+ TRAFFIC_PROFILE = {
+ "schema": "isb:traffic_profile:0.1",
+ "name": "fixed",
+ "description": "Fixed traffic profile to run UDP traffic",
+ "traffic_profile": {
+ "traffic_type": "FixedTraffic",
+ "frame_rate": 100, # pps
+ "flow_number": 10,
+ "frame_size": 64}}
+
+ def _get_res_mock(self, **kw):
+ _mock = mock.MagicMock()
+ for k, v in kw.items():
+ setattr(_mock, k, v)
+ return _mock
+
+ def test___init__(self):
+ traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE)
+ self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params)
+
+ def test_execute_traffic(self):
+ traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE)
+ self.assertRaises(NotImplementedError,
+ traffic_profile.execute_traffic, {})
+
+ def test_get_existing_traffic_profile(self):
+ traffic_profile_list = [
+ 'RFC2544Profile', 'FixedProfile', 'TrafficProfileGenericHTTP',
+ 'IXIARFC2544Profile', 'ProxACLProfile', 'ProxBinSearchProfile',
+ 'ProxProfile', 'ProxRampProfile']
+ with mock.patch.dict(sys.modules, y_tests.STL_MOCKS):
+ tprofile_package.register_modules()
+
+ for tp in traffic_profile_list:
+ traffic_profile = base.TrafficProfile.get(
+ {'traffic_profile': {'traffic_type': tp}})
+ self.assertEqual(tp, traffic_profile.__class__.__name__)
+
+ def test_get_non_existing_traffic_profile(self):
+ self.assertRaises(exceptions.TrafficProfileNotImplemented,
+ base.TrafficProfile.get, self.TRAFFIC_PROFILE)
+
+
+class TestDummyProfile(unittest.TestCase):
+ def test_execute(self):
+ tp_config = {'traffic_profile': {'duration': 15}}
+ dummy_profile = base.DummyProfile(tp_config)
+ self.assertIsNone(dummy_profile.execute({}))
+
+
+class TrafficProfileConfigTestCase(unittest.TestCase):
+
+ def test__init(self):
+ tp_config = {'traffic_profile': {'packet_sizes': {'64B': 100}}}
+ tp_config_obj = base.TrafficProfileConfig(tp_config)
+ self.assertEqual({'64B': 100}, tp_config_obj.packet_sizes)
+ self.assertEqual(base.TrafficProfileConfig.DEFAULT_DURATION,
+ tp_config_obj.duration)
+
+ def test__init_set_duration(self):
+ tp_config = {'traffic_profile': {'duration': 15}}
+ tp_config_obj = base.TrafficProfileConfig(tp_config)
+ self.assertEqual(base.TrafficProfileConfig.DEFAULT_SCHEMA,
+ tp_config_obj.schema)
+ self.assertEqual(float(base.TrafficProfileConfig.DEFAULT_FRAME_RATE),
+ tp_config_obj.frame_rate)
+ self.assertEqual(15, tp_config_obj.duration)
+
+ def test__parse_rate(self):
+ tp_config = {'traffic_profile': {'packet_sizes': {'64B': 100}}}
+ tp_config_obj = base.TrafficProfileConfig(tp_config)
+ self.assertEqual((100.0, 'fps'), tp_config_obj.parse_rate('100 '))
+ self.assertEqual((200.5, 'fps'), tp_config_obj.parse_rate('200.5'))
+ self.assertEqual((300.8, 'fps'), tp_config_obj.parse_rate('300.8fps'))
+ self.assertEqual((400.2, 'fps'),
+ tp_config_obj.parse_rate('400.2 fps'))
+ self.assertEqual((500.3, '%'), tp_config_obj.parse_rate('500.3%'))
+ self.assertEqual((600.1, '%'), tp_config_obj.parse_rate('600.1 %'))
+
+ def test__parse_rate_exception(self):
+ tp_config = {'traffic_profile': {'packet_sizes': {'64B': 100}}}
+ tp_config_obj = base.TrafficProfileConfig(tp_config)
+ with self.assertRaises(exceptions.TrafficProfileRate):
+ tp_config_obj.parse_rate('100Fps')
+ with self.assertRaises(exceptions.TrafficProfileRate):
+ tp_config_obj.parse_rate('100 kbps')
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_fixed.py b/yardstick/tests/unit/network_services/traffic_profile/test_fixed.py
new file mode 100644
index 000000000..2f6713760
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_fixed.py
@@ -0,0 +1,117 @@
+# 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.
+#
+
+import mock
+import unittest
+
+from yardstick.tests import STL_MOCKS
+
+STLClient = mock.MagicMock()
+stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
+stl_patch.start()
+
+if stl_patch:
+ from yardstick.network_services.traffic_profile.base import TrafficProfile
+ from yardstick.network_services.traffic_profile.fixed import FixedProfile
+
+
+class TestFixedProfile(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}}
+
+ 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',
+ 'dst_ip': '152.16.100.20',
+ 'local_mac': '00:00:00:00:00:01'},
+ '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',
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 1,
+ 'bandwidth': '10 Gbps',
+ 'dst_ip': '152.16.40.20',
+ 'local_mac': '00:00:00:00:00:02'},
+ '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'}]}}
+
+ def test___init__(self):
+ fixed_profile = FixedProfile(self.TRAFFIC_PROFILE)
+ self.assertIsNotNone(fixed_profile)
+
+ def test_execute(self):
+ traffic_generator = mock.Mock(autospec=TrafficProfile)
+ traffic_generator.my_ports = [0, 1]
+ traffic_generator.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ traffic_generator.client = \
+ mock.Mock(return_value=True)
+ fixed_profile = FixedProfile(self.TRAFFIC_PROFILE)
+ fixed_profile.params = self.TRAFFIC_PROFILE
+ fixed_profile.first_run = True
+ self.assertIsNone(fixed_profile.execute(traffic_generator))
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_http.py b/yardstick/tests/unit/network_services/traffic_profile/test_http.py
new file mode 100644
index 000000000..874ec37d4
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_http.py
@@ -0,0 +1,47 @@
+# 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.
+
+import unittest
+
+from yardstick.network_services.traffic_profile import http
+
+
+class TestTrafficProfileGenericHTTP(unittest.TestCase):
+
+ TP_CONFIG = {'traffic_profile': {'duration': 10},
+ "uplink_0": {}, "downlink_0": {}}
+
+ def test___init__(self):
+ tp_generic_http = http.TrafficProfileGenericHTTP(
+ self.TP_CONFIG)
+ self.assertIsNotNone(tp_generic_http)
+
+ def test_get_links_param(self):
+ tp_generic_http = http.TrafficProfileGenericHTTP(
+ self.TP_CONFIG)
+
+ links = tp_generic_http.get_links_param()
+ self.assertEqual({"uplink_0": {}, "downlink_0": {}}, links)
+
+ def test_execute(self):
+ tp_generic_http = http.TrafficProfileGenericHTTP(
+ self.TP_CONFIG)
+ traffic_generator = {}
+ self.assertIsNone(tp_generic_http.execute(traffic_generator))
+
+ def test__send_http_request(self):
+ tp_generic_http = http.TrafficProfileGenericHTTP(
+ self.TP_CONFIG)
+ self.assertIsNone(tp_generic_http._send_http_request(
+ '10.1.1.1', '250', '/req'))
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py b/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py
new file mode 100644
index 000000000..996360c2e
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_http_ixload.py
@@ -0,0 +1,452 @@
+# Copyright (c) 2017-2019 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import mock
+
+from oslo_serialization import jsonutils
+
+from yardstick.network_services.traffic_profile import http_ixload
+from yardstick.network_services.traffic_profile.http_ixload import \
+ join_non_strings, validate_non_string_sequence
+
+
+class TestJoinNonStrings(unittest.TestCase):
+
+ def test_validate_non_string_sequence(self):
+ self.assertEqual(validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
+ self.assertIsNone(validate_non_string_sequence('123'))
+ self.assertIsNone(validate_non_string_sequence(1))
+
+ self.assertEqual(validate_non_string_sequence(1, 2), 2)
+ self.assertEqual(validate_non_string_sequence(1, default=2), 2)
+
+ with self.assertRaises(RuntimeError):
+ validate_non_string_sequence(1, raise_exc=RuntimeError)
+
+ def test_join_non_strings(self):
+ self.assertEqual(join_non_strings(':'), '')
+ self.assertEqual(join_non_strings(':', 'a'), 'a')
+ self.assertEqual(join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
+ self.assertEqual(join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
+ self.assertEqual(join_non_strings(':', 'abc'), 'abc')
+
+
+class TestIxLoadTrafficGen(unittest.TestCase):
+
+ def setUp(self):
+ ports = [1, 2, 3]
+ self.test_input = {
+ "remote_server": "REMOTE_SERVER",
+ "ixload_cfg": "IXLOAD_CFG",
+ "result_dir": "RESULT_DIR",
+ "ixia_chassis": "IXIA_CHASSIS",
+ "IXIA": {
+ "card": "CARD",
+ "ports": ports,
+ },
+ 'links_param': {
+ "uplink_0": {
+ "ip": {"address": "address",
+ "gateway": "gateway",
+ "subnet_prefix": "subnet_prefix",
+ "mac": "mac"
+ }}}
+ }
+
+ 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,
+ },
+ 'links_param': {}
+ }
+ 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],
+ ])
+ self.assertEqual({}, ixload.links_param)
+
+ 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,
+ },
+ 'links_param': {}
+ }
+ 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,
+ },
+ 'links_param': {}
+ }
+ 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,
+ },
+ 'links_param': {}
+ }
+ 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,
+ },
+ 'links_param': {}
+ }
+ 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.StatCollectorUtils')
+ @mock.patch('yardstick.network_services.traffic_profile.http_ixload.IxLoad')
+ def test_start_http_test_connect_error(self, mock_ixload_type, *args):
+ 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,
+ },
+ 'links_param': {}
+ }
+
+ j = jsonutils.dump_as_bytes(test_input)
+
+ mock_ixload_type.return_value.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()
+
+ def test_update_config(self):
+ net_taraffic_0 = mock.Mock()
+ net_taraffic_0.name = "HTTP client@uplink_0"
+ net_taraffic_1 = mock.Mock()
+ net_taraffic_1.name = "HTTP client@uplink_1"
+
+ community_list = [net_taraffic_0, net_taraffic_1, Exception]
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ ixload.links_param = {"uplink_0": {"ip": {},
+ "http_client": {}}}
+
+ ixload.test = mock.Mock()
+ ixload.test.communityList = community_list
+
+ ixload.update_network_param = mock.Mock()
+ ixload.update_http_client_param = mock.Mock()
+
+ ixload.update_config()
+
+ ixload.update_network_param.assert_called_once_with(net_taraffic_0, {})
+ ixload.update_http_client_param.assert_called_once_with(net_taraffic_0,
+ {})
+
+ def test_update_network_mac_address(self):
+ ethernet = mock.MagicMock()
+ net_traffic = mock.Mock()
+ net_traffic.network.getL1Plugin.return_value = ethernet
+
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ ix_net_l2_ethernet_plugin = ethernet.childrenList[0]
+ ix_net_ip_v4_v6_plugin = ix_net_l2_ethernet_plugin.childrenList[0]
+ ix_net_ip_v4_v6_range = ix_net_ip_v4_v6_plugin.rangeList[0]
+
+ ixload.update_network_mac_address(net_traffic, "auto")
+ ix_net_ip_v4_v6_range.config.assert_called_once_with(
+ autoMacGeneration=True)
+
+ ixload.update_network_mac_address(net_traffic, "00:00:00:00:00:01")
+ ix_net_ip_v4_v6_range.config.assert_called_with(
+ autoMacGeneration=False)
+ mac_range = ix_net_ip_v4_v6_range.getLowerRelatedRange("MacRange")
+ mac_range.config.assert_called_once_with(mac="00:00:00:00:00:01")
+
+ net_traffic.network.getL1Plugin.return_value = Exception
+
+ with self.assertRaises(http_ixload.InvalidRxfFile):
+ ixload.update_network_mac_address(net_traffic, "auto")
+
+ def test_update_network_address(self):
+ ethernet = mock.MagicMock()
+ net_traffic = mock.Mock()
+ net_traffic.network.getL1Plugin.return_value = ethernet
+
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ ix_net_l2_ethernet_plugin = ethernet.childrenList[0]
+ ix_net_ip_v4_v6_plugin = ix_net_l2_ethernet_plugin.childrenList[0]
+ ix_net_ip_v4_v6_range = ix_net_ip_v4_v6_plugin.rangeList[0]
+
+ ixload.update_network_address(net_traffic, "address", "gateway",
+ "prefix")
+ ix_net_ip_v4_v6_range.config.assert_called_once_with(
+ prefix="prefix",
+ ipAddress="address",
+ gatewayAddress="gateway")
+
+ net_traffic.network.getL1Plugin.return_value = Exception
+
+ with self.assertRaises(http_ixload.InvalidRxfFile):
+ ixload.update_network_address(net_traffic, "address", "gateway",
+ "prefix")
+
+ def test_update_network_param(self):
+ net_traffic = mock.Mock()
+
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ ixload.update_network_address = mock.Mock()
+ ixload.update_network_mac_address = mock.Mock()
+
+ param = {"address": "address",
+ "gateway": "gateway",
+ "subnet_prefix": "subnet_prefix",
+ "mac": "mac"
+ }
+
+ ixload.update_network_param(net_traffic, param)
+
+ ixload.update_network_address.assert_called_once_with(net_traffic,
+ "address",
+ "gateway",
+ "subnet_prefix")
+
+ ixload.update_network_mac_address.assert_called_once_with(
+ net_traffic,
+ "mac")
+
+ def test_update_http_client_param(self):
+ net_traffic = mock.Mock()
+
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ ixload.update_page_size = mock.Mock()
+ ixload.update_user_count = mock.Mock()
+
+ param = {"page_object": "page_object",
+ "simulated_users": "simulated_users"}
+
+ ixload.update_http_client_param(net_traffic, param)
+
+ ixload.update_page_size.assert_called_once_with(net_traffic,
+ "page_object")
+ ixload.update_user_count.assert_called_once_with(net_traffic,
+ "simulated_users")
+
+ def test_update_page_size(self):
+ activity = mock.MagicMock()
+ net_traffic = mock.Mock()
+
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ net_traffic.activityList = [activity]
+ ix_http_command = activity.agent.actionList[0]
+ ixload.update_page_size(net_traffic, "page_object")
+ ix_http_command.config.assert_called_once_with(
+ pageObject="page_object")
+
+ net_traffic.activityList = []
+ with self.assertRaises(http_ixload.InvalidRxfFile):
+ ixload.update_page_size(net_traffic, "page_object")
+
+ def test_update_user_count(self):
+ activity = mock.MagicMock()
+ net_traffic = mock.Mock()
+
+ ixload = http_ixload.IXLOADHttpTest(
+ jsonutils.dump_as_bytes(self.test_input))
+
+ net_traffic.activityList = [activity]
+ ixload.update_user_count(net_traffic, 123)
+ activity.config.assert_called_once_with(userObjectiveValue=123)
+
+ net_traffic.activityList = []
+ with self.assertRaises(http_ixload.InvalidRxfFile):
+ ixload.update_user_count(net_traffic, 123)
+
+ @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, *args):
+ 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,
+ },
+ 'links_param': {}
+ }
+
+ 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, *args):
+ 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,
+ },
+ 'links_param': {}
+ }
+
+ 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()
+ reassign_ports.assert_called_once()
+
+ @mock.patch("yardstick.network_services.traffic_profile.http_ixload.IXLOADHttpTest")
+ def test_main(self, *args):
+ args = ["1", "2", "3"]
+ http_ixload.main(args)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py
new file mode 100644
index 000000000..ddd1828ae
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py
@@ -0,0 +1,1024 @@
+# Copyright (c) 2016-2019 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import copy
+
+import mock
+import unittest
+import collections
+
+from yardstick.network_services.traffic_profile import ixia_rfc2544
+from yardstick.network_services.traffic_profile import trex_traffic_profile
+
+
+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},
+ ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
+ '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',
+ 'count': '1',
+ 'srcip4': '90.90.1.1-90.105.255.255',
+ 'dscp': 0,
+ 'ttl': 32},
+ 'outer_l4': {
+ 'srcport': '2001',
+ 'dsrport': '1234'}}},
+ ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
+ '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',
+ 'count': '1',
+ '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=trex_traffic_profile.TrexProfile)
+ traffic_generator.my_ports = [0, 1]
+ traffic_generator.uplink_ports = [-1]
+ traffic_generator.downlink_ports = [1]
+ traffic_generator.client = \
+ mock.Mock(return_value=True)
+ STATIC_TRAFFIC = {
+ ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
+ "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"
+ },
+ ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
+ "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 = ixia_rfc2544.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)
+ self.assertIsNotNone(result)
+
+ def test_get_ixia_traffic_profile(self):
+ traffic_generator = mock.Mock(
+ autospec=trex_traffic_profile.TrexProfile)
+ traffic_generator.my_ports = [0, 1]
+ traffic_generator.uplink_ports = [-1]
+ traffic_generator.downlink_ports = [1]
+ traffic_generator.client = \
+ mock.Mock(return_value=True)
+ STATIC_TRAFFIC = {
+ ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
+ "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,
+ "count": "1"
+ },
+ "outer_l3v6": {
+ "dscp": 0,
+ "dstip4": "152.16.100.20",
+ "proto": "udp",
+ "srcip4": "152.16.40.20",
+ "ttl": 32,
+ },
+ "outer_l4": {
+ "dstport": "2001",
+ "srcport": "1234",
+ "count": "1"
+ },
+ "traffic_type": "continuous"
+ },
+ ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
+ "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": {
+ "dscp": 0,
+ "dstip4": "152.16.100.20",
+ "proto": "udp",
+ "srcip4": "152.16.40.20",
+ "ttl": 32,
+ },
+ "outer_l3v6": {
+ "dscp": 0,
+ "dstip4": "152.16.100.20",
+ "proto": "udp",
+ "srcip4": "152.16.40.20",
+ "ttl": 32,
+ },
+ "outer_l4": {
+ "dstport": "1234",
+ "srcport": "2001",
+ "count": "1"
+ },
+ "traffic_type": "continuous"
+ }
+ }
+ ixia_rfc2544.STATIC_TRAFFIC = STATIC_TRAFFIC
+
+ r_f_c2544_profile = ixia_rfc2544.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)
+ self.assertIsNotNone(result)
+
+ @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open")
+ def test_get_ixia_traffic_profile_v6(self, *args):
+ traffic_generator = mock.Mock(
+ autospec=trex_traffic_profile.TrexProfile)
+ traffic_generator.my_ports = [0, 1]
+ traffic_generator.uplink_ports = [-1]
+ traffic_generator.downlink_ports = [1]
+ traffic_generator.client = \
+ mock.Mock(return_value=True)
+ STATIC_TRAFFIC = {
+ ixia_rfc2544.IXIARFC2544Profile.UPLINK: {
+ "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"
+ },
+ ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {
+ "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 = ixia_rfc2544.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},
+ ixia_rfc2544.IXIARFC2544Profile.DOWNLINK:
+ {'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', 'count': '1',
+ 'srcip4': '90.90.1.1-90.105.255.255',
+ 'dscp': 0, 'ttl': 32},
+ 'outer_l3v6': {'dstip6': '1.1.1.1-1.15.255.255',
+ 'proto': 'udp', 'count': '1',
+ 'srcip6': '90.90.1.1-90.105.255.255',
+ 'dscp': 0, 'ttl': 32},
+ 'outer_l4': {'srcport': '2001',
+ 'dsrport': '1234'}}},
+ ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'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', 'count': '1',
+ 'srcip4': '1.1.1.1-1.15.255.255',
+ 'dscp': 0, 'ttl': 32},
+ 'outer_l3v6':
+ {'dstip6': '9.9.1.1-90.105.255.255',
+ 'proto': 'udp', 'count': '1',
+ '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)
+ self.assertIsNotNone(result)
+
+ def test__init__(self):
+ t_profile_data = copy.deepcopy(self.TRAFFIC_PROFILE)
+ t_profile_data['traffic_profile']['frame_rate'] = 12345678
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(t_profile_data)
+ self.assertEqual(12345678, r_f_c2544_profile.rate)
+
+ def test__get_ip_and_mask_range(self):
+ ip_range = '1.2.0.2-1.2.255.254'
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ ip, mask = r_f_c2544_profile._get_ip_and_mask(ip_range)
+ self.assertEqual('1.2.0.2', ip)
+ self.assertEqual(16, mask)
+
+ def test__get_ip_and_mask_single(self):
+ ip_range = '192.168.1.10'
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ ip, mask = r_f_c2544_profile._get_ip_and_mask(ip_range)
+ self.assertEqual('192.168.1.10', ip)
+ self.assertIsNone(mask)
+
+ def test__get_fixed_and_mask_range(self):
+ fixed_mask = '8-48'
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ fixed, mask = r_f_c2544_profile._get_fixed_and_mask(fixed_mask)
+ self.assertEqual(8, fixed)
+ self.assertEqual(48, mask)
+
+ def test__get_fixed_and_mask_single(self):
+ fixed_mask = 1234
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ fixed, mask = r_f_c2544_profile._get_fixed_and_mask(fixed_mask)
+ self.assertEqual(1234, fixed)
+ self.assertEqual(0, mask)
+
+ def test__get_ixia_traffic_profile_default_args(self):
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
+ self.TRAFFIC_PROFILE)
+
+ expected = {}
+ result = r_f_c2544_profile._get_ixia_traffic_profile({})
+ self.assertDictEqual(result, expected)
+
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544Profile,
+ '_update_traffic_tracking_options')
+ def test__ixia_traffic_generate(self, mock_upd_tracking_opts):
+ traffic_generator = mock.Mock(
+ autospec=trex_traffic_profile.TrexProfile)
+ traffic_generator.networks = {
+ "uplink_0": ["xe0"],
+ "downlink_0": ["xe1"],
+ }
+ traffic_generator.client = \
+ mock.Mock(return_value=True)
+ traffic = {ixia_rfc2544.IXIARFC2544Profile.DOWNLINK: {'iload': 10},
+ ixia_rfc2544.IXIARFC2544Profile.UPLINK: {'iload': 10}}
+ ixia_obj = mock.MagicMock()
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ r_f_c2544_profile.rate = 100
+ result = r_f_c2544_profile._ixia_traffic_generate(traffic, ixia_obj,
+ traffic_generator)
+ self.assertIsNone(result)
+ mock_upd_tracking_opts.assert_called_once_with(traffic_generator)
+
+ def test__update_traffic_tracking_options(self):
+ mock_traffic_gen = mock.Mock()
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile._update_traffic_tracking_options(mock_traffic_gen)
+ mock_traffic_gen.update_tracking_options.assert_called_once()
+
+ def test__get_framesize(self):
+ traffic_profile = {
+ 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}},
+ 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}},
+ 'uplink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}},
+ 'downlink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 100}}}}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.params = traffic_profile
+ result = rfc2544_profile._get_framesize()
+ self.assertEqual(result, '64B')
+
+ def test__get_framesize_IMIX_traffic(self):
+ traffic_profile = {
+ 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 50,
+ '128B': 50}}}},
+ 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 50,
+ '128B': 50}}}},
+ 'uplink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 50,
+ '128B': 50}}}},
+ 'downlink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 50,
+ '128B': 50}}}}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.params = traffic_profile
+ result = rfc2544_profile._get_framesize()
+ self.assertEqual(result, 'IMIX')
+
+ def test__get_framesize_zero_pkt_size_weight(self):
+ traffic_profile = {
+ 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}},
+ 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}},
+ 'uplink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}},
+ 'downlink_1': {'ipv4': {'outer_l2': {'framesize': {'64B': 0}}}}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.params = traffic_profile
+ result = rfc2544_profile._get_framesize()
+ self.assertEqual(result, '')
+
+ def test_execute_traffic_first_run(self):
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.first_run = True
+ rfc2544_profile.rate = 50
+ traffic_gen = mock.Mock()
+ traffic_gen.rfc_helper.iteration.value = 0
+ with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
+ as mock_get_tp, \
+ mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
+ as mock_tgenerate:
+ mock_get_tp.return_value = 'fake_tprofile'
+ output = rfc2544_profile.execute_traffic(traffic_gen,
+ ixia_obj=mock.ANY)
+
+ self.assertTrue(output)
+ self.assertFalse(rfc2544_profile.first_run)
+ self.assertEqual(50, rfc2544_profile.max_rate)
+ self.assertEqual(0, rfc2544_profile.min_rate)
+ mock_get_tp.assert_called_once()
+ mock_tgenerate.assert_called_once()
+
+ def test_execute_traffic_not_first_run(self):
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.first_run = False
+ rfc2544_profile.max_rate = 70
+ rfc2544_profile.min_rate = 0
+ traffic_gen = mock.Mock()
+ traffic_gen.rfc_helper.iteration.value = 0
+ with mock.patch.object(rfc2544_profile, '_get_ixia_traffic_profile') \
+ as mock_get_tp, \
+ mock.patch.object(rfc2544_profile, '_ixia_traffic_generate') \
+ as mock_tgenerate:
+ mock_get_tp.return_value = 'fake_tprofile'
+ rfc2544_profile.full_profile = mock.ANY
+ output = rfc2544_profile.execute_traffic(traffic_gen,
+ ixia_obj=mock.ANY)
+
+ self.assertFalse(output)
+ self.assertEqual(35.0, rfc2544_profile.rate)
+ mock_get_tp.assert_called_once()
+ mock_tgenerate.assert_called_once()
+
+ def test_update_traffic_profile(self):
+ traffic_generator = mock.Mock(
+ autospec=trex_traffic_profile.TrexProfile)
+ traffic_generator.networks = {
+ "uplink_0": ["xe0"], # private, one value for intfs
+ "downlink_0": ["xe1", "xe2"], # public, two values for intfs
+ "downlink_1": ["xe3"], # not in TRAFFIC PROFILE
+ "tenant_0": ["xe4"], # not public or private
+ }
+
+ ports_expected = [8, 3, 5]
+ traffic_generator.vnfd_helper.port_num.side_effect = ports_expected
+ traffic_generator.client.return_value = True
+
+ traffic_profile = copy.deepcopy(self.TRAFFIC_PROFILE)
+ traffic_profile.update({
+ "uplink_0": ["xe0"],
+ "downlink_0": ["xe1", "xe2"],
+ })
+
+ r_f_c2544_profile = ixia_rfc2544.IXIARFC2544Profile(traffic_profile)
+ r_f_c2544_profile.full_profile = {}
+ r_f_c2544_profile.get_streams = mock.Mock()
+
+ self.assertIsNone(
+ r_f_c2544_profile.update_traffic_profile(traffic_generator))
+ self.assertEqual(r_f_c2544_profile.ports, ports_expected)
+
+ def test_get_drop_percentage_completed(self):
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 1000,
+ 'InBytes': 64000, 'OutBytes': 64000,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 1007,
+ 'InBytes': 64320, 'OutBytes': 64448,
+ 'LatencyAvg': 23,
+ 'LatencyMin': 13,
+ 'LatencyMax': 28}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.rate = 100.0
+ rfc2544_profile._get_next_rate = mock.Mock(return_value=100.0)
+ rfc2544_profile._get_framesize = mock.Mock(return_value='64B')
+ completed, samples = rfc2544_profile.get_drop_percentage(
+ samples, 0, 1, 4, 0.1)
+ self.assertTrue(completed)
+ self.assertEqual(66.9, samples['TxThroughput'])
+ self.assertEqual(66.833, samples['RxThroughput'])
+ self.assertEqual(0.099651, samples['DropPercentage'])
+ self.assertEqual(21.5, samples['LatencyAvg'])
+ self.assertEqual(13.0, samples['LatencyMin'])
+ self.assertEqual(28.0, samples['LatencyMax'])
+ self.assertEqual(100.0, samples['Rate'])
+ self.assertEqual('64B', samples['PktSize'])
+
+ def test_get_drop_percentage_over_drop_percentage(self):
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 1000,
+ 'InBytes': 64000, 'OutBytes': 64000,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 1007,
+ 'InBytes': 64320, 'OutBytes': 64448,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.rate = 1000
+ rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
+ completed, samples = rfc2544_profile.get_drop_percentage(
+ samples, 0, 0.05, 4, 0.1)
+ self.assertFalse(completed)
+ self.assertEqual(66.9, samples['TxThroughput'])
+ self.assertEqual(66.833, samples['RxThroughput'])
+ self.assertEqual(0.099651, samples['DropPercentage'])
+ self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
+
+ def test_get_drop_percentage_under_drop_percentage(self):
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 1000,
+ 'InBytes': 64000, 'OutBytes': 64000,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 1007,
+ 'InBytes': 64320, 'OutBytes': 64448,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.rate = 1000
+ rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
+ completed, samples = rfc2544_profile.get_drop_percentage(
+ samples, 0.2, 1, 4, 0.1)
+ self.assertFalse(completed)
+ self.assertEqual(66.9, samples['TxThroughput'])
+ self.assertEqual(66.833, samples['RxThroughput'])
+ self.assertEqual(0.099651, samples['DropPercentage'])
+ self.assertEqual(rfc2544_profile.rate, rfc2544_profile.min_rate)
+
+ @mock.patch.object(ixia_rfc2544.LOG, 'info')
+ def test_get_drop_percentage_not_flow(self, *args):
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 0,
+ 'InBytes': 64000, 'OutBytes': 0,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 0,
+ 'InBytes': 64320, 'OutBytes': 0,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.rate = 1000
+ rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
+ completed, samples = rfc2544_profile.get_drop_percentage(
+ samples, 0.2, 1, 4, 0.1)
+ self.assertFalse(completed)
+ self.assertEqual(0.0, samples['TxThroughput'])
+ self.assertEqual(66.833, samples['RxThroughput'])
+ self.assertEqual(100, samples['DropPercentage'])
+ self.assertEqual(rfc2544_profile.rate, rfc2544_profile.max_rate)
+
+ def test_get_drop_percentage_first_run(self):
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 1000,
+ 'InBytes': 64000, 'OutBytes': 64000,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 1007,
+ 'InBytes': 64320, 'OutBytes': 64448,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25}
+ }
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile._get_next_rate = mock.Mock(return_value=50.0)
+ completed, samples = rfc2544_profile.get_drop_percentage(
+ samples, 0, 1, 4, 0.1, first_run=True)
+ self.assertTrue(completed)
+ self.assertEqual(66.9, samples['TxThroughput'])
+ self.assertEqual(66.833, samples['RxThroughput'])
+ self.assertEqual(0.099651, samples['DropPercentage'])
+ self.assertEqual(33.45, rfc2544_profile.rate)
+
+ def test_get_drop_percentage_resolution(self):
+ rfc2544_profile = ixia_rfc2544.IXIARFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile._get_next_rate = mock.Mock(return_value=0.1)
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 1000,
+ 'InBytes': 64000, 'OutBytes': 64000,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 1007,
+ 'InBytes': 64320, 'OutBytes': 64448,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25}
+ }
+ rfc2544_profile.rate = 0.19
+ completed, _ = rfc2544_profile.get_drop_percentage(
+ samples, 0, 0.05, 4, 0.1)
+ self.assertTrue(completed)
+
+ samples = {'iface_name_1':
+ {'InPackets': 1000, 'OutPackets': 1000,
+ 'InBytes': 64000, 'OutBytes': 64000,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25},
+ 'iface_name_2':
+ {'InPackets': 1005, 'OutPackets': 1007,
+ 'InBytes': 64320, 'OutBytes': 64448,
+ 'LatencyAvg': 20,
+ 'LatencyMin': 15,
+ 'LatencyMax': 25}
+ }
+ rfc2544_profile.rate = 0.5
+ completed, _ = rfc2544_profile.get_drop_percentage(
+ samples, 0, 0.05, 4, 0.1)
+ self.assertFalse(completed)
+
+
+class TestIXIARFC2544PppoeScenarioProfile(unittest.TestCase):
+
+ TRAFFIC_PROFILE = {
+ "schema": "nsb:traffic_profile:0.1",
+ "name": "fixed",
+ "description": "Fixed traffic profile to run UDP traffic",
+ "traffic_profile": {
+ "traffic_type": "FixedTraffic",
+ "frame_rate": 100},
+ 'uplink_0': {'ipv4': {'port': 'xe0', 'id': 1}},
+ 'downlink_0': {'ipv4': {'port': 'xe2', 'id': 2}},
+ 'uplink_1': {'ipv4': {'port': 'xe1', 'id': 3}},
+ 'downlink_1': {'ipv4': {'port': 'xe2', 'id': 4}}
+ }
+
+ def setUp(self):
+ self.ixia_tp = ixia_rfc2544.IXIARFC2544PppoeScenarioProfile(
+ self.TRAFFIC_PROFILE)
+ self.ixia_tp.rate = 100.0
+ self.ixia_tp._get_next_rate = mock.Mock(return_value=50.0)
+ self.ixia_tp._get_framesize = mock.Mock(return_value='64B')
+
+ def test___init__(self):
+ self.assertIsInstance(self.ixia_tp.full_profile,
+ collections.OrderedDict)
+
+ def test__get_flow_groups_params(self):
+ expected_tp = collections.OrderedDict([
+ ('uplink_0', {'ipv4': {'id': 1, 'port': 'xe0'}}),
+ ('downlink_0', {'ipv4': {'id': 2, 'port': 'xe2'}}),
+ ('uplink_1', {'ipv4': {'id': 3, 'port': 'xe1'}}),
+ ('downlink_1', {'ipv4': {'id': 4, 'port': 'xe2'}})])
+
+ self.ixia_tp._get_flow_groups_params()
+ self.assertDictEqual(self.ixia_tp.full_profile, expected_tp)
+
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_flow_groups_params')
+ def test_update_traffic_profile(self, mock_get_flow_groups_params):
+ networks = {
+ 'uplink_0': 'data1',
+ 'downlink_0': 'data2',
+ 'uplink_1': 'data3',
+ 'downlink_1': 'data4'
+ }
+ ports = ['xe0', 'xe1', 'xe2', 'xe3']
+ mock_traffic_gen = mock.Mock()
+ mock_traffic_gen.networks = networks
+ mock_traffic_gen.vnfd_helper.port_num.side_effect = ports
+ self.ixia_tp.update_traffic_profile(mock_traffic_gen)
+ mock_get_flow_groups_params.assert_called_once()
+ self.assertEqual(self.ixia_tp.ports, ports)
+
+ def test__get_prio_flows_drop_percentage(self):
+
+ input_stats = {
+ '0': {
+ 'InPackets': 50,
+ 'OutPackets': 100,
+ 'Store-Forward_Avg_latency_ns': 10,
+ 'Store-Forward_Min_latency_ns': 10,
+ 'Store-Forward_Max_latency_ns': 10}}
+
+ result = self.ixia_tp._get_prio_flows_drop_percentage(input_stats)
+ self.assertIsNotNone(result['0'].get('DropPercentage'))
+ self.assertEqual(result['0'].get('DropPercentage'), 50.0)
+
+ def test__get_prio_flows_drop_percentage_traffic_not_flowing(self):
+ input_stats = {
+ '0': {
+ 'InPackets': 0,
+ 'OutPackets': 0,
+ 'Store-Forward_Avg_latency_ns': 0,
+ 'Store-Forward_Min_latency_ns': 0,
+ 'Store-Forward_Max_latency_ns': 0}}
+
+ result = self.ixia_tp._get_prio_flows_drop_percentage(input_stats)
+ self.assertIsNotNone(result['0'].get('DropPercentage'))
+ self.assertEqual(result['0'].get('DropPercentage'), 100)
+
+ def test__get_summary_pppoe_subs_counters(self):
+ input_stats = {
+ 'xe0': {
+ 'OutPackets': 100,
+ 'SessionsUp': 4,
+ 'SessionsDown': 0,
+ 'SessionsNotStarted': 0,
+ 'SessionsTotal': 4},
+ 'xe1': {
+ 'OutPackets': 100,
+ 'SessionsUp': 4,
+ 'SessionsDown': 0,
+ 'SessionsNotStarted': 0,
+ 'SessionsTotal': 4}
+ }
+
+ expected_stats = {
+ 'SessionsUp': 8,
+ 'SessionsDown': 0,
+ 'SessionsNotStarted': 0,
+ 'SessionsTotal': 8
+ }
+
+ res = self.ixia_tp._get_summary_pppoe_subs_counters(input_stats)
+ self.assertDictEqual(res, expected_stats)
+
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_prio_flows_drop_percentage')
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_summary_pppoe_subs_counters')
+ def test_get_drop_percentage(self, mock_get_pppoe_subs,
+ mock_sum_prio_drop_rate):
+ samples = {
+ 'priority_stats': {
+ '0': {
+ 'InPackets': 100,
+ 'OutPackets': 100,
+ 'InBytes': 6400,
+ 'OutBytes': 6400,
+ 'LatencyAvg': 10,
+ 'LatencyMin': 10,
+ 'LatencyMax': 10}},
+ 'xe0': {
+ 'InPackets': 100,
+ 'OutPackets': 100,
+ 'InBytes': 6400,
+ 'OutBytes': 6400,
+ 'LatencyAvg': 10,
+ 'LatencyMin': 10,
+ 'LatencyMax': 10}}
+
+ mock_get_pppoe_subs.return_value = {'SessionsUp': 1}
+ mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}}
+
+ self.ixia_tp._get_framesize = mock.Mock(return_value='64B')
+ status, res = self.ixia_tp.get_drop_percentage(
+ samples, tol_min=0.0, tolerance=0.0001, precision=0,
+ resolution=0.1, first_run=True)
+ self.assertIsNotNone(res.get('DropPercentage'))
+ self.assertIsNotNone(res.get('Priority'))
+ self.assertIsNotNone(res.get('SessionsUp'))
+ self.assertEqual(res['DropPercentage'], 0.0)
+ self.assertEqual(res['Rate'], 100.0)
+ self.assertEqual(res['PktSize'], '64B')
+ self.assertTrue(status)
+ mock_sum_prio_drop_rate.assert_called_once()
+ mock_get_pppoe_subs.assert_called_once()
+
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_prio_flows_drop_percentage')
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_summary_pppoe_subs_counters')
+ def test_get_drop_percentage_failed_status(self, mock_get_pppoe_subs,
+ mock_sum_prio_drop_rate):
+ samples = {
+ 'priority_stats': {
+ '0': {
+ 'InPackets': 90,
+ 'OutPackets': 100,
+ 'InBytes': 5760,
+ 'OutBytes': 6400,
+ 'LatencyAvg': 10,
+ 'LatencyMin': 10,
+ 'LatencyMax': 10}},
+ 'xe0': {
+ 'InPackets': 90,
+ 'OutPackets': 100,
+ 'InBytes': 5760,
+ 'OutBytes': 6400,
+ 'LatencyAvg': 10,
+ 'LatencyMin': 10,
+ 'LatencyMax': 10}}
+
+ mock_get_pppoe_subs.return_value = {'SessionsUp': 1}
+ mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}}
+
+ status, res = self.ixia_tp.get_drop_percentage(
+ samples, tol_min=0.0, tolerance=0.0001, precision=0,
+ resolution=0.1, first_run=True)
+ self.assertIsNotNone(res.get('DropPercentage'))
+ self.assertIsNotNone(res.get('Priority'))
+ self.assertIsNotNone(res.get('SessionsUp'))
+ self.assertEqual(res['DropPercentage'], 10.0)
+ self.assertFalse(status)
+ mock_sum_prio_drop_rate.assert_called_once()
+ mock_get_pppoe_subs.assert_called_once()
+
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_prio_flows_drop_percentage')
+ @mock.patch.object(ixia_rfc2544.IXIARFC2544PppoeScenarioProfile,
+ '_get_summary_pppoe_subs_counters')
+ def test_get_drop_percentage_priority_flow_check(self, mock_get_pppoe_subs,
+ mock_sum_prio_drop_rate):
+ samples = {
+ 'priority_stats': {
+ '0': {
+ 'InPackets': 100,
+ 'OutPackets': 100,
+ 'InBytes': 6400,
+ 'OutBytes': 6400,
+ 'LatencyAvg': 10,
+ 'LatencyMin': 10,
+ 'LatencyMax': 10}},
+ 'xe0': {
+ 'InPackets': 90,
+ 'OutPackets': 100,
+ 'InBytes': 5760,
+ 'OutBytes': 6400,
+ 'LatencyAvg': 10,
+ 'LatencyMin': 10,
+ 'LatencyMax': 10
+ }}
+
+ mock_get_pppoe_subs.return_value = {'SessionsUp': 1}
+ mock_sum_prio_drop_rate.return_value = {'0': {'DropPercentage': 0.0}}
+
+ tc_rfc2544_opts = {'priority': '0',
+ 'allowed_drop_rate': '0.0001 - 0.0001'}
+ status, res = self.ixia_tp.get_drop_percentage(
+ samples, tol_min=15.0000, tolerance=15.0001, precision=0,
+ resolution=0.1, first_run=True, tc_rfc2544_opts=tc_rfc2544_opts)
+ self.assertIsNotNone(res.get('DropPercentage'))
+ self.assertIsNotNone(res.get('Priority'))
+ self.assertIsNotNone(res.get('SessionsUp'))
+ self.assertTrue(status)
+ mock_sum_prio_drop_rate.assert_called_once()
+ mock_get_pppoe_subs.assert_called_once()
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_landslide_profile.py b/yardstick/tests/unit/network_services/traffic_profile/test_landslide_profile.py
new file mode 100644
index 000000000..afd550029
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_landslide_profile.py
@@ -0,0 +1,136 @@
+# Copyright (c) 2018 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.
+
+import copy
+import unittest
+
+from yardstick.network_services.traffic_profile import landslide_profile
+
+TP_CONFIG = {
+ 'schema': "nsb:traffic_profile:0.1",
+ 'name': 'LandslideProfile',
+ 'description': 'Spirent Landslide traffic profile (Data Message Flow)',
+ 'traffic_profile': {
+ 'traffic_type': 'LandslideProfile'
+ },
+ 'dmf_config': {
+ 'dmf': {
+ 'library': 'test',
+ 'name': 'Fireball UDP',
+ 'description': "Basic data flow using UDP/IP (Fireball DMF)",
+ 'keywords': 'UDP ',
+ 'dataProtocol': 'fb_udp',
+ 'burstCount': 1,
+ 'clientPort': {
+ 'clientPort': 2002,
+ 'isClientPortRange': 'false'
+ },
+ 'serverPort': 2003,
+ 'connection': {
+ 'initiatingSide': 'Client',
+ 'disconnectSide': 'Client',
+ 'underlyingProtocol': 'none',
+ 'persistentConnection': 'false'
+ },
+ 'protocolId': 0,
+ 'persistentConnection': 'false',
+ 'transactionRate': 8.0,
+ 'transactions': {
+ 'totalTransactions': 0,
+ 'retries': 0,
+ 'dataResponseTime': 60000,
+ 'packetSize': 64
+ },
+ 'segment': {
+ 'segmentSize': 64000,
+ 'maxSegmentSize': 0
+ },
+ 'size': {
+ 'sizeDistribution': 'Fixed',
+ 'sizeDeviation': 10
+ },
+ 'interval': {
+ 'intervalDistribution': 'Fixed',
+ 'intervalDeviation': 10
+ },
+ 'ipHeader': {
+ 'typeOfService': 0,
+ 'timeToLive': 64
+ },
+ 'tcpConnection': {
+ 'force3Way': 'false',
+ 'fixedRetryTime': 0,
+ 'maxPacketsToForceAck': 0
+ },
+ 'tcp': {
+ 'windowSize': 32768,
+ 'windowScaling': -1,
+ 'disableFinAckWait': 'false'
+ },
+ 'disconnectType': 'FIN',
+ 'slowStart': 'false',
+ 'connectOnly': 'false',
+ 'vtag': {
+ 'VTagMask': '0x0',
+ 'VTagValue': '0x0'
+ },
+ 'sctpPayloadProtocolId': 0,
+ 'billingIncludeSyn': 'true',
+ 'billingIncludeSubflow': 'true',
+ 'billingRecordPerTransaction': 'false',
+ 'tcpPush': 'false',
+ 'hostDataExpansionRatio': 1
+ }
+ }
+}
+DMF_OPTIONS = {
+ 'dmf': {
+ 'transactionRate': 5,
+ 'packetSize': 512,
+ 'burstCount': 1
+ }
+}
+
+
+class TestLandslideProfile(unittest.TestCase):
+
+ def test___init__(self):
+ ls_traffic_profile = landslide_profile.LandslideProfile(TP_CONFIG)
+ self.assertListEqual([TP_CONFIG["dmf_config"]],
+ ls_traffic_profile.dmf_config)
+
+ def test___init__config_not_a_dict(self):
+ _tp_config = copy.deepcopy(TP_CONFIG)
+ _tp_config['dmf_config'] = [_tp_config['dmf_config']]
+ ls_traffic_profile = landslide_profile.LandslideProfile(_tp_config)
+ self.assertListEqual(_tp_config['dmf_config'],
+ ls_traffic_profile.dmf_config)
+
+ def test_execute(self):
+ ls_traffic_profile = landslide_profile.LandslideProfile(TP_CONFIG)
+ self.assertIsNone(ls_traffic_profile.execute(None))
+
+ def test_update_dmf_options_dict(self):
+ ls_traffic_profile = landslide_profile.LandslideProfile(TP_CONFIG)
+ ls_traffic_profile.update_dmf(DMF_OPTIONS)
+ self.assertDictContainsSubset(DMF_OPTIONS['dmf'],
+ ls_traffic_profile.dmf_config[0])
+
+ def test_update_dmf_options_list(self):
+ ls_traffic_profile = landslide_profile.LandslideProfile(TP_CONFIG)
+ _dmf_options = copy.deepcopy(DMF_OPTIONS)
+ _dmf_options['dmf'] = [_dmf_options['dmf']]
+ ls_traffic_profile.update_dmf(_dmf_options)
+ self.assertTrue(all([x in ls_traffic_profile.dmf_config[0]
+ for x in DMF_OPTIONS['dmf']]))
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_pktgen.py b/yardstick/tests/unit/network_services/traffic_profile/test_pktgen.py
new file mode 100644
index 000000000..08542b4f1
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_pktgen.py
@@ -0,0 +1,63 @@
+# Copyright (c) 2018 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.
+
+import mock
+
+from yardstick.common import utils
+from yardstick.network_services.traffic_profile import pktgen
+from yardstick.tests.unit import base as ut_base
+
+
+class TestIXIARFC2544Profile(ut_base.BaseUnitTestCase):
+
+ def setUp(self):
+ self._tp_config = {'traffic_profile': {}}
+ self._host = 'localhost'
+ self._port = '12345'
+ self.tp = pktgen.PktgenTrafficProfile(self._tp_config)
+ self.tp.init(self._host, self._port)
+ self._mock_send_socket_command = mock.patch.object(
+ utils, 'send_socket_command', return_value=0)
+ self.mock_send_socket_command = self._mock_send_socket_command.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_send_socket_command.stop()
+
+ def test_start(self):
+ self.tp.start()
+ self.mock_send_socket_command.assert_called_once_with(
+ self._host, self._port, 'pktgen.start("0")')
+
+ def test_stop(self):
+ self.tp.stop()
+ self.mock_send_socket_command.assert_called_once_with(
+ self._host, self._port, 'pktgen.stop("0")')
+
+ def test_rate(self):
+ rate = 75
+ self.tp.rate(rate)
+ command = 'pktgen.set("0", "rate", 75)'
+ self.mock_send_socket_command.assert_called_once_with(
+ self._host, self._port, command)
+
+ def test_clear_all_stats(self):
+ self.tp.clear_all_stats()
+ self.mock_send_socket_command.assert_called_once_with(
+ self._host, self._port, 'clr')
+
+ def test_help(self):
+ self.tp.help()
+ self.mock_send_socket_command.assert_called_once_with(
+ self._host, self._port, 'help')
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_acl.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_acl.py
new file mode 100644
index 000000000..48c449b20
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_acl.py
@@ -0,0 +1,74 @@
+# 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.
+#
+
+import unittest
+import mock
+
+from yardstick.tests import STL_MOCKS
+
+STLClient = mock.MagicMock()
+stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
+stl_patch.start()
+
+if stl_patch:
+ from yardstick.network_services.traffic_profile.prox_ACL import ProxACLProfile
+ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
+
+
+class TestProxACLProfile(unittest.TestCase):
+
+ def test_run_test_with_pkt_size(self):
+ def target(*args):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'upper_bound': 100.0,
+ 'lower_bound': 0.0,
+ 'tolerated_loss': 50.0,
+ 'attempts': 20
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(
+ 10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(
+ 10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_gen = mock.MagicMock()
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = ProxACLProfile(tp_config)
+ profile.init(mock.MagicMock())
+
+ profile.prox_config["attempts"] = 20
+ profile.queue = mock.MagicMock()
+ profile.tolerated_loss = 50.0
+ profile.pkt_size = 128
+ profile.duration = 30
+ profile.test_value = 100.0
+ profile.tolerated_loss = 100.0
+ profile._profile_helper = profile_helper
+
+ profile.run_test_with_pkt_size(
+ traffic_gen, profile.pkt_size, profile.duration)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
new file mode 100644
index 000000000..f17656328
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
@@ -0,0 +1,302 @@
+# 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.
+
+import unittest
+import mock
+
+from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
+from yardstick.network_services.traffic_profile import prox_binsearch
+
+
+class TestProxBinSearchProfile(unittest.TestCase):
+
+ THEOR_MAX_THROUGHPUT = 0.00012340000000000002
+
+ def setUp(self):
+ self._mock_log_info = mock.patch.object(prox_binsearch.LOG, 'info')
+ self.mock_log_info = self._mock_log_info.start()
+ self.addCleanup(self._stop_mocks)
+
+ def _stop_mocks(self):
+ self._mock_log_info.stop()
+
+ def test_execute_1(self):
+ def target(*args, **_):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ def side_effect_func(arg1, arg2):
+ if arg1 == "confirmation":
+ return arg2
+ else:
+ return {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+ attrs1 = {'get.return_value': 10}
+ traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
+
+ attrs2 = {'__getitem__.return_value': 10, 'get.return_value': 10}
+ attrs3 = {'get.side_effect': side_effect_func}
+ traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
+ traffic_generator.scenario_helper.scenario_cfg["options"].configure_mock(**attrs3)
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = prox_binsearch.ProxBinSearchProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.execute_traffic(traffic_generator)
+
+ self.assertEqual(round(profile.current_lower, 2), 74.69)
+ self.assertEqual(round(profile.current_upper, 2), 76.09)
+ self.assertEqual(len(runs), 7)
+
+ # Result Samples inc theor_max
+ result_tuple = {'Actual_throughput': 5e-07,
+ 'theor_max_throughput': self.THEOR_MAX_THROUGHPUT,
+ 'PktSize': 200,
+ 'Status': 'Result'}
+
+ test_results = profile.queue.put.call_args[0]
+ for k in result_tuple:
+ self.assertEqual(result_tuple[k], test_results[0][k])
+
+ success_result_tuple = {"CurrentDropPackets": 0.5,
+ "DropPackets": 0.5,
+ "LatencyAvg": 5.3,
+ "LatencyMax": 5.2,
+ "LatencyMin": 5.1,
+ "PktSize": 200,
+ "RxThroughput": 7.5e-07,
+ "Throughput": 7.5e-07,
+ "TxThroughput": self.THEOR_MAX_THROUGHPUT,
+ "Status": 'Success'}
+
+ calls = profile.queue.put(success_result_tuple)
+ profile.queue.put.assert_has_calls(calls)
+
+ success_result_tuple2 = {"CurrentDropPackets": 0.5,
+ "DropPackets": 0.5,
+ "LatencyAvg": 5.3,
+ "LatencyMax": 5.2,
+ "LatencyMin": 5.1,
+ "PktSize": 200,
+ "RxThroughput": 7.5e-07,
+ "Throughput": 7.5e-07,
+ "TxThroughput": 123.4,
+ "can_be_lost": 409600,
+ "drop_total": 20480,
+ "rx_total": 4075520,
+ "tx_total": 4096000,
+ "Status": 'Success'}
+
+ calls = profile.queue.put(success_result_tuple2)
+ profile.queue.put.assert_has_calls(calls)
+
+ def test_execute_2(self):
+ def target(*args, **_):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 25.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ def side_effect_func(arg1, _):
+ if arg1 == "confirmation":
+ return 2
+ else:
+ return {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+ attrs1 = {'get.return_value': 10}
+ traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
+
+ attrs2 = {'__getitem__.return_value': 0, 'get.return_value': 0}
+ attrs3 = {'get.side_effect': side_effect_func}
+
+ traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
+ traffic_generator.scenario_helper.scenario_cfg["options"].configure_mock(**attrs3)
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = prox_binsearch.ProxBinSearchProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.execute_traffic(traffic_generator)
+ self.assertEqual(round(profile.current_lower, 2), 24.06)
+ self.assertEqual(round(profile.current_upper, 2), 25.47)
+ self.assertEqual(len(runs), 21)
+
+ def test_execute_3(self):
+ def target(*args, **_):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = prox_binsearch.ProxBinSearchProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.upper_bound = 100.0
+ profile.lower_bound = 99.0
+ profile.execute_traffic(traffic_generator)
+
+ result_tuple = {'Actual_throughput': 0, 'theor_max_throughput': 0,
+ "Status": 'Result', "Next_Step": ''}
+ profile.queue.put.assert_called_with(result_tuple)
+
+ # Check for success_ tuple (None expected)
+ calls = profile.queue.put.mock_calls
+ for call in calls:
+ for call_detail in call[1]:
+ if call_detail["Status"] == 'Success':
+ self.assertRaises(AttributeError)
+
+ def test_execute_4(self):
+
+ def target(*args, **_):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+ attrs1 = {'get.return_value': 100000}
+ traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
+
+ attrs2 = {'__getitem__.return_value': 0, 'get.return_value': 0}
+
+ traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = prox_binsearch.ProxBinSearchProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.execute_traffic(traffic_generator)
+ self.assertEqual(round(profile.current_lower, 2), 74.69)
+ self.assertEqual(round(profile.current_upper, 2), 76.09)
+ self.assertEqual(len(runs), 7)
+
+ # Result Samples inc theor_max
+ result_tuple = {'Actual_throughput': 5e-07,
+ 'theor_max_throughput': self.THEOR_MAX_THROUGHPUT,
+ 'PktSize': 200,
+ "Status": 'Result'}
+
+ test_results = profile.queue.put.call_args[0]
+ for k in result_tuple:
+ self.assertEqual(result_tuple[k], test_results[0][k])
+
+ success_result_tuple = {"CurrentDropPackets": 0.5,
+ "DropPackets": 0.5,
+ "LatencyAvg": 5.3,
+ "LatencyMax": 5.2,
+ "LatencyMin": 5.1,
+ "PktSize": 200,
+ "RxThroughput": 7.5e-07,
+ "Throughput": 7.5e-07,
+ "TxThroughput": self.THEOR_MAX_THROUGHPUT,
+ "Status": 'Success'}
+
+ calls = profile.queue.put(success_result_tuple)
+ profile.queue.put.assert_has_calls(calls)
+
+ success_result_tuple2 = {"CurrentDropPackets": 0.5,
+ "DropPackets": 0.5,
+ "LatencyAvg": 5.3,
+ "LatencyMax": 5.2,
+ "LatencyMin": 5.1,
+ "PktSize": 200,
+ "RxThroughput": 7.5e-07,
+ "Throughput": 7.5e-07,
+ "TxThroughput": 123.4,
+ "can_be_lost": 409600,
+ "drop_total": 20480,
+ "rx_total": 4075520,
+ "tx_total": 4096000,
+ "Status": 'Success'}
+
+ calls = profile.queue.put(success_result_tuple2)
+ profile.queue.put.assert_has_calls(calls)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py
new file mode 100644
index 000000000..1d9eb0887
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_irq.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2018-2019 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import time
+
+import unittest
+import mock
+
+from yardstick.network_services.traffic_profile import prox_irq
+
+
+class TestProxIrqProfile(unittest.TestCase):
+
+ def setUp(self):
+ self._mock_log_info = mock.patch.object(prox_irq.LOG, 'info')
+ self.mock_log_info = self._mock_log_info.start()
+ self.addCleanup(self._stop_mocks)
+
+ def _stop_mocks(self):
+ self._mock_log_info.stop()
+
+ @mock.patch.object(time, 'sleep')
+ def test_execute_1(self, *args):
+ tp_config = {
+ 'traffic_profile': {
+ },
+ }
+
+ traffic_generator = mock.MagicMock()
+ attrs1 = {'get.return_value' : 10}
+ traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
+
+ attrs2 = {'__getitem__.return_value' : 10, 'get.return_value': 10}
+ traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
+
+ profile_helper = mock.MagicMock()
+
+ profile = prox_irq.ProxIrqProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.execute_traffic(traffic_generator)
+ profile.run_test()
+ is_ended_flag = profile.is_ended()
+
+ self.assertFalse(is_ended_flag)
+ self.assertEqual(profile.lower_bound, 10.0)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py
new file mode 100644
index 000000000..1593a0835
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py
@@ -0,0 +1,130 @@
+# Copyright (c) 2017-2019 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import time
+
+import unittest
+import mock
+
+from yardstick.tests import STL_MOCKS
+
+STLClient = mock.MagicMock()
+stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
+stl_patch.start()
+
+if stl_patch:
+ from yardstick.network_services.traffic_profile.prox_profile import ProxProfile
+ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
+
+
+class TestProxProfile(unittest.TestCase):
+
+ def test_sort_vpci(self):
+ traffic_generator = mock.Mock()
+ interface_1 = {'virtual-interface': {'vpci': 'id1'}, 'name': 'name1'}
+ interface_2 = {'virtual-interface': {'vpci': 'id2'}, 'name': 'name2'}
+ interface_3 = {'virtual-interface': {'vpci': 'id3'}, 'name': 'name3'}
+ interfaces = [interface_2, interface_3, interface_1]
+ traffic_generator.vnfd_helper = {
+ 'vdu': [{'external-interface': interfaces}]}
+ output = ProxProfile.sort_vpci(traffic_generator)
+ self.assertEqual([interface_1, interface_2, interface_3], output)
+
+ def test_fill_samples(self):
+ samples = {}
+
+ traffic_generator = mock.MagicMock()
+ interfaces = [
+ ['id1', 'name1'],
+ ['id2', 'name2']
+ ]
+ traffic_generator.resource_helper.sut.port_stats.side_effect = [
+ list(range(12)),
+ list(range(10, 22)),
+ ]
+
+ expected = {
+ 'name1': {
+ 'in_packets': 6,
+ 'out_packets': 7,
+ },
+ 'name2': {
+ 'in_packets': 16,
+ 'out_packets': 17,
+ },
+ }
+ with mock.patch.object(ProxProfile, 'sort_vpci', return_value=interfaces):
+ ProxProfile.fill_samples(samples, traffic_generator)
+
+ self.assertDictEqual(samples, expected)
+
+ def test_init(self):
+ tp_config = {
+ 'traffic_profile': {},
+ }
+
+ profile = ProxProfile(tp_config)
+ queue = mock.Mock()
+ profile.init(queue)
+ self.assertIs(profile.queue, queue)
+
+ @mock.patch.object(time, 'sleep')
+ def test_execute_traffic(self, *args):
+ packet_sizes = [
+ 10,
+ 100,
+ 1000,
+ ]
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': packet_sizes,
+ },
+ }
+
+ traffic_generator = mock.MagicMock()
+
+ setup_helper = traffic_generator.setup_helper
+ setup_helper.find_in_section.return_value = None
+
+ prox_resource_helper = ProxResourceHelper(setup_helper)
+ traffic_generator.resource_helper = prox_resource_helper
+
+ profile = ProxProfile(tp_config)
+
+ self.assertFalse(profile.done.is_set())
+ for _ in packet_sizes:
+ with self.assertRaises(NotImplementedError):
+ profile.execute_traffic(traffic_generator)
+
+ self.assertIsNone(profile.execute_traffic(traffic_generator))
+ self.assertTrue(profile.done.is_set())
+
+ def test_bounds_iterator(self):
+ tp_config = {
+ 'traffic_profile': {},
+ }
+
+ profile = ProxProfile(tp_config)
+ value = 0.0
+ for value in profile.bounds_iterator():
+ pass
+
+ self.assertEqual(value, 100.0)
+
+ mock_logger = mock.MagicMock()
+ for _ in profile.bounds_iterator(mock_logger):
+ pass
+
+ mock_logger.debug.assert_called_once()
+ self.assertEqual(mock_logger.info.call_count, 10)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_ramp.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_ramp.py
new file mode 100644
index 000000000..7a77e3295
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_ramp.py
@@ -0,0 +1,95 @@
+# 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.
+#
+
+import unittest
+import mock
+
+from yardstick.tests import STL_MOCKS
+
+STLClient = mock.MagicMock()
+stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
+stl_patch.start()
+
+if stl_patch:
+ from yardstick.network_services.traffic_profile.prox_ramp import ProxRampProfile
+ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxProfileHelper
+ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
+
+
+class TestProxRampProfile(unittest.TestCase):
+
+ def test_run_test_with_pkt_size(self):
+ tp_config = {
+ 'traffic_profile': {
+ 'lower_bound': 10.0,
+ 'upper_bound': 100.0,
+ 'step_value': 10.0,
+ },
+ }
+
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+
+ traffic_gen = mock.MagicMock()
+ traffic_gen._test_type = 'Generic'
+
+ profile_helper = ProxProfileHelper(traffic_gen.resource_helper)
+ profile_helper.run_test = run_test = mock.MagicMock(return_value=success_tuple)
+
+ profile = ProxRampProfile(tp_config)
+ profile.fill_samples = fill_samples = mock.MagicMock()
+ profile.queue = mock.MagicMock()
+ profile._profile_helper = profile_helper
+
+ profile.run_test_with_pkt_size(traffic_gen, 128, 30)
+ self.assertEqual(run_test.call_count, 10)
+ self.assertEqual(fill_samples.call_count, 10)
+
+ def test_run_test_with_pkt_size_with_fail(self):
+ tp_config = {
+ 'traffic_profile': {
+ 'lower_bound': 10.0,
+ 'upper_bound': 100.0,
+ 'step_value': 10.0,
+ },
+ }
+
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ result_list = [
+ success_tuple,
+ success_tuple,
+ success_tuple,
+ fail_tuple,
+ success_tuple,
+ fail_tuple,
+ fail_tuple,
+ fail_tuple,
+ ]
+
+ traffic_gen = mock.MagicMock()
+ traffic_gen._test_type = 'Generic'
+
+ profile_helper = ProxProfileHelper(traffic_gen.resource_helper)
+ profile_helper.run_test = run_test = mock.MagicMock(side_effect=result_list)
+
+ profile = ProxRampProfile(tp_config)
+ profile.fill_samples = fill_samples = mock.MagicMock()
+ profile.queue = mock.MagicMock()
+ profile._profile_helper = profile_helper
+
+ profile.run_test_with_pkt_size(traffic_gen, 128, 30)
+ self.assertEqual(run_test.call_count, 4)
+ self.assertEqual(fill_samples.call_count, 3)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py
new file mode 100644
index 000000000..febcfe5da
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py
@@ -0,0 +1,341 @@
+# 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.
+
+import datetime
+
+import mock
+from trex_stl_lib import api as Pkt
+from trex_stl_lib import trex_stl_client
+from trex_stl_lib import trex_stl_packet_builder_scapy
+from trex_stl_lib import trex_stl_streams
+
+from yardstick.common import constants
+from yardstick.network_services.traffic_profile import rfc2544
+from yardstick.tests.unit import base
+
+
+class TestRFC2544Profile(base.BaseUnitTestCase):
+ TRAFFIC_PROFILE = {
+ "schema": "isb:traffic_profile:0.1",
+ "name": "fixed",
+ "description": "Fixed traffic profile to run UDP traffic",
+ "traffic_profile": {
+ "traffic_type": "FixedTraffic",
+ "frame_rate": 100,
+ "flow_number": 10,
+ "frame_size": 64}}
+
+ PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
+ 'name': 'rfc2544',
+ 'traffic_profile': {'traffic_type': 'RFC2544Profile',
+ 'frame_rate': 100},
+ 'downlink_0':
+ {'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, 'count': 1},
+ 'outer_l4':
+ {'srcport': '2001',
+ 'dsrport': '1234', 'count': 1}}},
+ 'uplink_0':
+ {'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, 'count': 1},
+ 'outer_l4':
+ {'dstport': '2001',
+ 'srcport': '1234', 'count': 1}}},
+ 'schema': 'isb:traffic_profile:0.1'}
+
+ def test___init__(self):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ self.assertEqual(rfc2544_profile.max_rate, rfc2544_profile.rate)
+ self.assertEqual(0, rfc2544_profile.min_rate)
+
+ def test_stop_traffic(self):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ mock_generator = mock.Mock()
+ rfc2544_profile.stop_traffic(traffic_generator=mock_generator)
+ mock_generator.client.stop.assert_called_once()
+ mock_generator.client.reset.assert_called_once()
+ mock_generator.client.remove_all_streams.assert_called_once()
+
+ def test_execute_traffic(self):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ mock_generator = mock.Mock()
+ mock_generator.networks = {
+ 'downlink_0': ['xe0', 'xe1'],
+ 'uplink_0': ['xe2', 'xe3'],
+ 'downlink_1': []}
+ mock_generator.port_num.side_effect = [10, 20, 30, 40]
+ mock_generator.rfc2544_helper.correlated_traffic = False
+ rfc2544_profile.params = {
+ 'downlink_0': 'profile1',
+ 'uplink_0': 'profile2'}
+
+ with mock.patch.object(rfc2544_profile, '_create_profile') as \
+ mock_create_profile:
+ rfc2544_profile.execute_traffic(traffic_generator=mock_generator)
+ mock_create_profile.assert_has_calls([
+ mock.call('profile1', rfc2544_profile.rate, mock.ANY, False),
+ mock.call('profile1', rfc2544_profile.rate, mock.ANY, False),
+ mock.call('profile2', rfc2544_profile.rate, mock.ANY, False),
+ mock.call('profile2', rfc2544_profile.rate, mock.ANY, False)])
+ mock_generator.client.add_streams.assert_has_calls([
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[30]),
+ mock.call(mock.ANY, ports=[40])])
+ mock_generator.client.start(ports=[10, 20, 30, 40],
+ duration=rfc2544_profile.config.duration,
+ force=True)
+
+ @mock.patch.object(trex_stl_streams, 'STLProfile')
+ def test__create_profile(self, mock_stl_profile):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ port_pg_id = mock.ANY
+ profile_data = {'packetid_1': {'outer_l2': {'framesize': 'imix_info'}}}
+ rate = 100
+ with mock.patch.object(rfc2544_profile, '_create_imix_data') as \
+ mock_create_imix, \
+ mock.patch.object(rfc2544_profile, '_create_vm') as \
+ mock_create_vm, \
+ mock.patch.object(rfc2544_profile, '_create_streams') as \
+ mock_create_streams:
+ mock_create_imix.return_value = 'imix_data'
+ mock_create_streams.return_value = ['stream1']
+ rfc2544_profile._create_profile(profile_data, rate, port_pg_id,
+ True)
+
+ mock_create_imix.assert_called_once_with('imix_info')
+ mock_create_vm.assert_called_once_with(
+ {'outer_l2': {'framesize': 'imix_info'}})
+ mock_create_streams.assert_called_once_with('imix_data', 100,
+ port_pg_id, True)
+ mock_stl_profile.assert_called_once_with(['stream1'])
+
+ def test__create_imix_data_mode_DIP(self):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ data = {'64B': 50, '128B': 50}
+ self.assertEqual(
+ {'64': 50.0, '128': 50.0},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_PACKETS))
+ data = {'64B': 1, '128b': 3}
+ self.assertEqual(
+ {'64': 25.0, '128': 75.0},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_PACKETS))
+ data = {}
+ self.assertEqual(
+ {},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_PACKETS))
+
+ def test__create_imix_data_mode_DIB(self):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ data = {'64B': 25, '128B': 25, '512B': 25, '1518B': 25}
+ byte_total = 64 * 25 + 128 * 25 + 512 * 25 + 1518 * 25
+ self.assertEqual(
+ {'64': 64 * 25.0 * 100 / byte_total,
+ '128': 128 * 25.0 * 100 / byte_total,
+ '512': 512 * 25.0 * 100 / byte_total,
+ '1518': 1518 * 25.0 * 100/ byte_total},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_BYTES))
+ data = {}
+ self.assertEqual(
+ {},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_BYTES))
+ data = {'64B': 100}
+ self.assertEqual(
+ {'64': 100.0},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_BYTES))
+
+ def test__create_vm(self):
+ packet = {'outer_l2': 'l2_definition'}
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ with mock.patch.object(rfc2544_profile, '_set_outer_l2_fields') as \
+ mock_l2_fileds:
+ rfc2544_profile._create_vm(packet)
+ mock_l2_fileds.assert_called_once_with('l2_definition')
+
+ @mock.patch.object(trex_stl_packet_builder_scapy, 'STLPktBuilder',
+ return_value='packet')
+ def test__create_single_packet(self, mock_pktbuilder):
+ size = 128
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.ether_packet = Pkt.Eth()
+ rfc2544_profile.ip_packet = Pkt.IP()
+ rfc2544_profile.udp_packet = Pkt.UDP()
+ rfc2544_profile.trex_vm = 'trex_vm'
+ base_pkt = (rfc2544_profile.ether_packet / rfc2544_profile.ip_packet /
+ rfc2544_profile.udp_packet)
+ pad = (size - len(base_pkt)) * 'x'
+ output = rfc2544_profile._create_single_packet(size=size)
+ mock_pktbuilder.assert_called_once_with(pkt=base_pkt / pad,
+ vm='trex_vm')
+ self.assertEqual(output, 'packet')
+
+ @mock.patch.object(trex_stl_packet_builder_scapy, 'STLPktBuilder',
+ return_value='packet')
+ def test__create_single_packet_qinq(self, mock_pktbuilder):
+ size = 128
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.ether_packet = Pkt.Eth()
+ rfc2544_profile.ip_packet = Pkt.IP()
+ rfc2544_profile.udp_packet = Pkt.UDP()
+ rfc2544_profile.trex_vm = 'trex_vm'
+ rfc2544_profile.qinq = True
+ rfc2544_profile.qinq_packet = Pkt.Dot1Q(vlan=1) / Pkt.Dot1Q(vlan=2)
+ base_pkt = (rfc2544_profile.ether_packet /
+ rfc2544_profile.qinq_packet / rfc2544_profile.ip_packet /
+ rfc2544_profile.udp_packet)
+ pad = (size - len(base_pkt)) * 'x'
+ output = rfc2544_profile._create_single_packet(size=size)
+ mock_pktbuilder.assert_called_once_with(pkt=base_pkt / pad,
+ vm='trex_vm')
+ self.assertEqual(output, 'packet')
+
+ @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats')
+ @mock.patch.object(trex_stl_streams, 'STLTXCont')
+ @mock.patch.object(trex_stl_client, 'STLStream')
+ def test__create_streams(self, mock_stream, mock_txcont, mock_latency):
+ imix_data = {'64': 25, '512': 75}
+ rate = 35
+ port_pg_id = rfc2544.PortPgIDMap()
+ port_pg_id.add_port(10)
+ mock_stream.side_effect = ['stream1', 'stream2']
+ mock_txcont.side_effect = ['txcont1', 'txcont2']
+ mock_latency.side_effect = ['latency1', 'latency2']
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ with mock.patch.object(rfc2544_profile, '_create_single_packet'):
+ output = rfc2544_profile._create_streams(imix_data, rate,
+ port_pg_id, True)
+ self.assertEqual(['stream1', 'stream2'], output)
+ mock_latency.assert_has_calls([
+ mock.call(pg_id=1), mock.call(pg_id=2)])
+ mock_txcont.assert_has_calls([
+ mock.call(percentage=float(25 * 35) / 100),
+ mock.call(percentage=float(75 * 35) / 100)], any_order=True)
+
+ @mock.patch.object(rfc2544.RFC2544Profile, '_get_framesize')
+ def test_get_drop_percentage(self, mock_get_framesize):
+ rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
+ rfc2544_profile.iteration = 1
+ mock_get_framesize.return_value = '64B'
+
+ samples = [
+ {'xe1': {'out_packets': 2100,
+ 'in_packets': 2010,
+ 'out_bytes': 134400,
+ 'in_bytes': 128640,
+ 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)},
+ 'xe2': {'out_packets': 4100,
+ 'in_packets': 4010,
+ 'out_bytes': 262400,
+ 'in_bytes': 256640,
+ 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)}},
+ {'xe1': {'out_packets': 2110,
+ 'in_packets': 2040,
+ 'out_bytes': 135040,
+ 'in_bytes': 130560,
+ 'latency': 'Latency1',
+ 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)},
+ 'xe2': {'out_packets': 4150,
+ 'in_packets': 4010,
+ 'out_bytes': 265600,
+ 'in_bytes': 256640,
+ 'latency': 'Latency2',
+ 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)}}
+ ]
+ completed, output = rfc2544_profile.get_drop_percentage(
+ samples, 0, 0, False, 0.1)
+ expected = {'xe1': {'OutPackets': 10,
+ 'InPackets': 30,
+ 'OutBytes': 640,
+ 'InBytes': 1920},
+ 'xe2': {'OutPackets': 50,
+ 'InPackets': 0,
+ 'OutBytes': 3200,
+ 'InBytes': 0},
+ 'DropPercentage': 50.0,
+ 'RxThroughput': 1000000.0,
+ 'TxThroughput': 2000000.0,
+ 'RxThroughputBps': 64000000.0,
+ 'TxThroughputBps': 128000000.0,
+ 'Rate': 100.0,
+ 'Iteration': 1,
+ 'PktSize': '64B',
+ 'Status': 'Failure'}
+ self.assertEqual(expected, output)
+ self.assertFalse(completed)
+
+
+class PortPgIDMapTestCase(base.BaseUnitTestCase):
+
+ def test_add_port(self):
+ port_pg_id_map = rfc2544.PortPgIDMap()
+ port_pg_id_map.add_port(10)
+ self.assertEqual(10, port_pg_id_map._last_port)
+ self.assertEqual([], port_pg_id_map._port_pg_id_map[10])
+
+ def test_get_pg_ids(self):
+ port_pg_id_map = rfc2544.PortPgIDMap()
+ port_pg_id_map.add_port(10)
+ port_pg_id_map.increase_pg_id()
+ port_pg_id_map.increase_pg_id()
+ port_pg_id_map.add_port(20)
+ port_pg_id_map.increase_pg_id()
+ self.assertEqual([1, 2], port_pg_id_map.get_pg_ids(10))
+ self.assertEqual([3], port_pg_id_map.get_pg_ids(20))
+ self.assertEqual([], port_pg_id_map.get_pg_ids(30))
+
+ def test_increase_pg_id_no_port(self):
+ port_pg_id_map = rfc2544.PortPgIDMap()
+ self.assertIsNone(port_pg_id_map.increase_pg_id())
+
+ def test_increase_pg_id_last_port(self):
+ port_pg_id_map = rfc2544.PortPgIDMap()
+ port_pg_id_map.add_port(10)
+ self.assertEqual(1, port_pg_id_map.increase_pg_id())
+ self.assertEqual([1], port_pg_id_map.get_pg_ids(10))
+ self.assertEqual(10, port_pg_id_map._last_port)
+
+ def test_increase_pg_id(self):
+ port_pg_id_map = rfc2544.PortPgIDMap()
+ port_pg_id_map.add_port(10)
+ port_pg_id_map.increase_pg_id()
+ self.assertEqual(2, port_pg_id_map.increase_pg_id(port=20))
+ self.assertEqual([1], port_pg_id_map.get_pg_ids(10))
+ self.assertEqual([2], port_pg_id_map.get_pg_ids(20))
+ self.assertEqual(20, port_pg_id_map._last_port)
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_sip.py b/yardstick/tests/unit/network_services/traffic_profile/test_sip.py
new file mode 100644
index 000000000..bf26ee44d
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_sip.py
@@ -0,0 +1,51 @@
+# Copyright (c) 2019 Viosoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import mock
+
+from yardstick.network_services.traffic_profile import sip
+
+
+class TestSipProfile(unittest.TestCase):
+
+ TRAFFIC_PROFILE = {
+ "schema": "nsb:traffic_profile:0.1",
+ "name": "sip",
+ "description": "Traffic profile to run sip",
+ "traffic_profile": {
+ "traffic_type": "SipProfile",
+ "frame_rate": 100, # pps
+ "duration": 10,
+ "enable_latency": False}}
+
+ def setUp(self):
+ self.sip_profile = sip.SipProfile(self.TRAFFIC_PROFILE)
+
+ def test___init__(self):
+ self.assertIsNone(self.sip_profile.generator)
+
+ def test_execute_traffic(self):
+ self.sip_profile.generator = None
+ mock_traffic_generator = mock.Mock()
+ self.sip_profile.execute_traffic(mock_traffic_generator)
+ self.assertIsNotNone(self.sip_profile.generator)
+
+ def test_is_ended_true(self):
+ self.sip_profile.generator = mock.Mock(return_value=True)
+ self.assertTrue(self.sip_profile.is_ended())
+
+ def test_is_ended_false(self):
+ self.sip_profile.generator = None
+ self.assertFalse(self.sip_profile.is_ended())
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py b/yardstick/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py
new file mode 100644
index 000000000..628e85459
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py
@@ -0,0 +1,277 @@
+# 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.
+
+import ipaddress
+
+import six
+import unittest
+
+from yardstick.common import exceptions as y_exc
+from yardstick.network_services.traffic_profile import base as tp_base
+from yardstick.network_services.traffic_profile import trex_traffic_profile
+
+
+class TestTrexProfile(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}}
+
+ EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01"
+ EXAMPLE_IP_ADDR = "10.0.0.1"
+ EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
+
+ PROFILE = {
+ 'description': 'Traffic profile to run RFC2544 latency',
+ 'name': 'rfc2544',
+ 'traffic_profile': {'traffic_type': 'RFC2544Profile',
+ 'frame_rate': 100},
+ tp_base.TrafficProfile.DOWNLINK: {
+ 'ipv4': {'outer_l2': {'framesize': {'64B': '100',
+ '1518B': '0',
+ '128B': '0',
+ '1400B': '0',
+ '256B': '0',
+ '373b': '0',
+ '570B': '0'},
+ "srcmac": "00:00:00:00:00:02",
+ "dstmac": "00:00:00:00:00:01"},
+ 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
+ 'proto': 'udp',
+ 'srcip4': '9.9.1.1-90.1.2.2',
+ 'dscp': 0, 'ttl': 32,
+ 'count': 1},
+ 'outer_l4': {'srcport': '2001',
+ 'dsrport': '1234',
+ 'count': 1}}},
+ tp_base.TrafficProfile.UPLINK: {
+ 'ipv4':
+ {'outer_l2': {'framesize':
+ {'64B': '100', '1518B': '0',
+ '128B': '0', '1400B': '0',
+ '256B': '0', '373b': '0',
+ '570B': '0'},
+ "srcmac": "00:00:00:00:00:01",
+ "dstmac": "00:00:00:00:00:02"},
+ '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, 'count': 1},
+ 'outer_l4': {'dstport': '2001',
+ 'srcport': '1234',
+ 'count': 1}}},
+ 'schema': 'isb:traffic_profile:0.1'}
+ PROFILE_v6 = {
+ 'description': 'Traffic profile to run RFC2544 latency',
+ 'name': 'rfc2544',
+ 'traffic_profile': {'traffic_type': 'RFC2544Profile',
+ 'frame_rate': 100},
+ tp_base.TrafficProfile.DOWNLINK: {
+ 'ipv6': {'outer_l2': {'framesize':
+ {'64B': '100', '1518B': '0',
+ '128B': '0', '1400B': '0',
+ '256B': '0', '373b': '0',
+ '570B': '0'},
+ "srcmac": "00:00:00:00:00:02",
+ "dstmac": "00:00:00:00:00:01"},
+ 'outer_l3v4': {
+ 'dstip6':
+ '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
+ 'proto': 'udp',
+ 'srcip6':
+ '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
+ 'dscp': 0, 'ttl': 32,
+ 'count': 1},
+ 'outer_l4': {'srcport': '2001',
+ 'dsrport': '1234',
+ 'count': 1}}},
+ tp_base.TrafficProfile.UPLINK: {
+ 'ipv6': {'outer_l2': {'framesize':
+ {'64B': '100', '1518B': '0',
+ '128B': '0', '1400B': '0',
+ '256B': '0', '373b': '0',
+ '570B': '0'},
+ "srcmac": "00:00:00:00:00:01",
+ "dstmac": "00:00:00:00:00:02"},
+ 'outer_l3v4': {
+ 'dstip6':
+ '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
+ 'proto': 'udp',
+ 'srcip6':
+ '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
+ 'dscp': 0, 'ttl': 32,
+ 'count': 1},
+ 'outer_l4': {'dstport': '2001',
+ 'srcport': '1234',
+ 'count': 1}}},
+ 'schema': 'isb:traffic_profile:0.1'}
+
+ def test___init__(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ self.assertEqual(trex_profile.pps, 100)
+
+ def test_qinq(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
+ "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
+
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ self.assertIsNone(trex_profile.set_qinq(qinq))
+
+ qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
+ "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
+ self.assertIsNone(trex_profile.set_qinq(qinq))
+
+ def test__set_outer_l2_fields(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
+ "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
+ outer_l2 = self.PROFILE[
+ tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l2']
+ outer_l2['QinQ'] = qinq
+ self.assertIsNone(trex_profile._set_outer_l2_fields(outer_l2))
+
+ def test__set_outer_l3v4_fields(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ outer_l3v4 = self.PROFILE[
+ tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
+ outer_l3v4['proto'] = 'tcp'
+ self.assertIsNone(trex_profile._set_outer_l3v4_fields(outer_l3v4))
+
+ def test__set_outer_l3v6_fields(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ outer_l3v6 = self.PROFILE_v6[
+ tp_base.TrafficProfile.UPLINK]['ipv6']['outer_l3v4']
+ outer_l3v6['proto'] = 'tcp'
+ outer_l3v6['tc'] = 1
+ outer_l3v6['hlim'] = 10
+ self.assertIsNone(trex_profile._set_outer_l3v6_fields(outer_l3v6))
+
+ def test__set_outer_l4_fields(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ outer_l4 = self.PROFILE[
+ tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l4']
+ self.assertIsNone(trex_profile._set_outer_l4_fields(outer_l4))
+
+ def test__count_ip_ipv4(self):
+ start, end, count = trex_traffic_profile.TrexProfile._count_ip(
+ '1.1.1.1', '1.2.3.4')
+ self.assertEqual('1.1.1.1', str(start))
+ self.assertEqual('1.2.3.4', str(end))
+ diff = (int(ipaddress.IPv4Address(six.u('1.2.3.4'))) -
+ int(ipaddress.IPv4Address(six.u('1.1.1.1'))))
+ self.assertEqual(diff, count)
+
+ def test__count_ip_ipv6(self):
+ start_ip = '0064:ff9b:0:0:0:0:9810:6414'
+ end_ip = '0064:ff9b:0:0:0:0:9810:6420'
+ start, end, count = trex_traffic_profile.TrexProfile._count_ip(
+ start_ip, end_ip)
+ self.assertEqual(0x98106414, start)
+ self.assertEqual(0x98106420, end)
+ self.assertEqual(0x98106420 - 0x98106414, count)
+
+ def test__count_ip_ipv6_exception(self):
+ start_ip = '0064:ff9b:0:0:0:0:9810:6420'
+ end_ip = '0064:ff9b:0:0:0:0:9810:6414'
+ with self.assertRaises(y_exc.IPv6RangeError):
+ trex_traffic_profile.TrexProfile._count_ip(start_ip, end_ip)
+
+ def test__dscp_range_action_partial_actual_count_zero(self):
+ traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ dscp_partial = traffic_profile._dscp_range_action_partial()
+
+ flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+ dscp_partial('1', '1', 'unneeded')
+ self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+ def test__dscp_range_action_partial_count_greater_than_actual(self):
+ traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ dscp_partial = traffic_profile._dscp_range_action_partial()
+
+ flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+ dscp_partial('1', '10', '100')
+ self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+ def test__udp_range_action_partial_actual_count_zero(self):
+ traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ traffic_profile.udp['field1'] = 'value1'
+ udp_partial = traffic_profile._udp_range_action_partial('field1')
+
+ flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+ udp_partial('1', '1', 'unneeded')
+ self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+ def test__udp_range_action_partial_count_greater_than_actual(self):
+ traffic_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ traffic_profile.udp['field1'] = 'value1'
+ udp_partial = traffic_profile._udp_range_action_partial(
+ 'field1', 'not_used_count')
+ flow_vars_initial_length = len(traffic_profile.vm_flow_vars)
+ udp_partial('1', '10', '100')
+ self.assertEqual(len(traffic_profile.vm_flow_vars), flow_vars_initial_length + 2)
+
+ def test__general_single_action_partial(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+ trex_profile._general_single_action_partial(
+ trex_traffic_profile.ETHERNET)(trex_traffic_profile.SRC)(
+ self.EXAMPLE_ETHERNET_ADDR)
+ self.assertEqual(self.EXAMPLE_ETHERNET_ADDR,
+ trex_profile.ether_packet.src)
+
+ trex_profile._general_single_action_partial(trex_traffic_profile.IP)(
+ trex_traffic_profile.DST)(self.EXAMPLE_IP_ADDR)
+ self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
+
+ trex_profile._general_single_action_partial(trex_traffic_profile.IPv6)(
+ trex_traffic_profile.DST)(self.EXAMPLE_IPv6_ADDR)
+ self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
+
+ trex_profile._general_single_action_partial(trex_traffic_profile.UDP)(
+ trex_traffic_profile.SRC_PORT)(5060)
+ self.assertEqual(5060, trex_profile.udp_packet.sport)
+
+ trex_profile._general_single_action_partial(trex_traffic_profile.IP)(
+ trex_traffic_profile.TYPE_OF_SERVICE)(0)
+ self.assertEqual(0, trex_profile.ip_packet.tos)
+
+ def test__set_proto_addr(self):
+ trex_profile = trex_traffic_profile.TrexProfile(self.PROFILE)
+
+ ether_range = "00:00:00:00:00:01-00:00:00:00:00:02"
+ ip_range = "1.1.1.2-1.1.1.10"
+ ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420'
+
+ trex_profile._set_proto_addr(trex_traffic_profile.ETHERNET,
+ trex_traffic_profile.SRC, ether_range)
+ trex_profile._set_proto_addr(trex_traffic_profile.ETHERNET,
+ trex_traffic_profile.DST, ether_range)
+ trex_profile._set_proto_addr(trex_traffic_profile.IP,
+ trex_traffic_profile.SRC, ip_range)
+ trex_profile._set_proto_addr(trex_traffic_profile.IP,
+ trex_traffic_profile.DST, ip_range)
+ trex_profile._set_proto_addr(trex_traffic_profile.IPv6,
+ trex_traffic_profile.SRC, ipv6_range)
+ trex_profile._set_proto_addr(trex_traffic_profile.IPv6,
+ trex_traffic_profile.DST, ipv6_range)
+ trex_profile._set_proto_addr(trex_traffic_profile.UDP,
+ trex_traffic_profile.SRC_PORT,
+ '5060-5090')
+ trex_profile._set_proto_addr(trex_traffic_profile.UDP,
+ trex_traffic_profile.DST_PORT, '5060')
diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py
new file mode 100644
index 000000000..8ad17b547
--- /dev/null
+++ b/yardstick/tests/unit/network_services/traffic_profile/test_vpp_rfc2544.py
@@ -0,0 +1,890 @@
+# Copyright (c) 2019 Viosoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import mock
+from trex_stl_lib import trex_stl_client
+from trex_stl_lib import trex_stl_packet_builder_scapy
+from trex_stl_lib import trex_stl_streams
+
+from yardstick.common import constants
+from yardstick.network_services.helpers.vpp_helpers.multiple_loss_ratio_search import \
+ MultipleLossRatioSearch
+from yardstick.network_services.helpers.vpp_helpers.ndr_pdr_result import \
+ NdrPdrResult
+from yardstick.network_services.helpers.vpp_helpers.receive_rate_interval import \
+ ReceiveRateInterval
+from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \
+ ReceiveRateMeasurement
+from yardstick.network_services.traffic_profile import base as tp_base
+from yardstick.network_services.traffic_profile import rfc2544, vpp_rfc2544
+from yardstick.network_services.traffic_profile.rfc2544 import PortPgIDMap
+from yardstick.tests.unit import base
+
+
+class TestVppRFC2544Profile(base.BaseUnitTestCase):
+ TRAFFIC_PROFILE = {
+ "schema": "isb:traffic_profile:0.1",
+ "name": "fixed",
+ "description": "Fixed traffic profile to run UDP traffic",
+ "traffic_profile": {
+ "traffic_type": "FixedTraffic",
+ "duration": 30,
+ "enable_latency": True,
+ "frame_rate": 100,
+ "intermediate_phases": 2,
+ "lower_bound": 1.0,
+ "step_interval": 0.5,
+ "test_precision": 0.1,
+ "upper_bound": 100.0}}
+
+ TRAFFIC_PROFILE_MAX_RATE = {
+ "schema": "isb:traffic_profile:0.1",
+ "name": "fixed",
+ "description": "Fixed traffic profile to run UDP traffic",
+ "traffic_profile": {
+ "traffic_type": "FixedTraffic",
+ "duration": 30,
+ "enable_latency": True,
+ "frame_rate": 10000,
+ "intermediate_phases": 2,
+ "lower_bound": 1.0,
+ "step_interval": 0.5,
+ "test_precision": 0.1,
+ "upper_bound": 100.0}}
+
+ PROFILE = {
+ "description": "Traffic profile to run RFC2544 latency",
+ "downlink_0": {
+ "ipv4": {
+ "id": 2,
+ "outer_l2": {
+ "framesize": {
+ "1024B": "0",
+ "1280B": "0",
+ "128B": "0",
+ "1400B": "0",
+ "1500B": "0",
+ "1518B": "0",
+ "256B": "0",
+ "373b": "0",
+ "512B": "0",
+ "570B": "0",
+ "64B": "100"
+ }
+ },
+ "outer_l3v4": {
+ "count": "1",
+ "dstip4": "10.0.0.0-10.0.0.100",
+ "proto": 61,
+ "srcip4": "20.0.0.0-20.0.0.100"
+ }
+ }
+ },
+ "name": "rfc2544",
+ "schema": "nsb:traffic_profile:0.1",
+ "traffic_profile": {
+ "duration": 30,
+ "enable_latency": True,
+ "frame_rate": 100,
+ "intermediate_phases": 2,
+ "lower_bound": 1.0,
+ "step_interval": 0.5,
+ "test_precision": 0.1,
+ "traffic_type": "VppRFC2544Profile",
+ "upper_bound": 100.0
+ },
+ "uplink": {
+ "ipv4": {
+ "id": 1,
+ "outer_l2": {
+ "framesize": {
+ "1024B": "0",
+ "1280B": "0",
+ "128B": "0",
+ "1400B": "0",
+ "1500B": "0",
+ "1518B": "0",
+ "256B": "0",
+ "373B": "0",
+ "512B": "0",
+ "570B": "0",
+ "64B": "100"
+ }
+ },
+ "outer_l3v4": {
+ "count": "10",
+ "dstip4": "20.0.0.0-20.0.0.100",
+ "proto": 61,
+ "srcip4": "10.0.0.0-10.0.0.100"
+ }
+ }
+ }
+ }
+
+ def test___init__(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ self.assertEqual(vpp_rfc2544_profile.max_rate,
+ vpp_rfc2544_profile.rate)
+ self.assertEqual(0, vpp_rfc2544_profile.min_rate)
+ self.assertEqual(2, vpp_rfc2544_profile.number_of_intermediate_phases)
+ self.assertEqual(30, vpp_rfc2544_profile.duration)
+ self.assertEqual(0.1, vpp_rfc2544_profile.precision)
+ self.assertEqual(1.0, vpp_rfc2544_profile.lower_bound)
+ self.assertEqual(100.0, vpp_rfc2544_profile.upper_bound)
+ self.assertEqual(0.5, vpp_rfc2544_profile.step_interval)
+ self.assertEqual(True, vpp_rfc2544_profile.enable_latency)
+
+ def test_init_traffic_params(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ mock_generator = mock.MagicMock()
+ mock_generator.rfc2544_helper.latency = True
+ mock_generator.rfc2544_helper.tolerance_low = 0.0
+ mock_generator.rfc2544_helper.tolerance_high = 0.005
+ mock_generator.scenario_helper.all_options = {
+ "vpp_config": {
+ "max_rate": 14880000
+ }
+ }
+ vpp_rfc2544_profile.init_traffic_params(mock_generator)
+ self.assertEqual(0.0, vpp_rfc2544_profile.tolerance_low)
+ self.assertEqual(0.005, vpp_rfc2544_profile.tolerance_high)
+ self.assertEqual(14880000, vpp_rfc2544_profile.max_rate)
+ self.assertEqual(True, vpp_rfc2544_profile.enable_latency)
+
+ def test_calculate_frame_size(self):
+ imix = {'40B': 7, '576B': 4, '1500B': 1}
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ self.assertEqual((4084 / 12, 12),
+ vpp_rfc2544_profile.calculate_frame_size(imix))
+
+ def test_calculate_frame_size_empty(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ self.assertEqual((64, 100),
+ vpp_rfc2544_profile.calculate_frame_size(None))
+
+ def test_calculate_frame_size_error(self):
+ imix = {'40B': -7, '576B': 4, '1500B': 1}
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ self.assertEqual((64, 100),
+ vpp_rfc2544_profile.calculate_frame_size(imix))
+
+ def test__gen_payload(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ self.assertIsNotNone(vpp_rfc2544_profile._gen_payload(4))
+
+ def test_register_generator(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ mock_generator = mock.MagicMock()
+ mock_generator.rfc2544_helper.latency = True
+ mock_generator.rfc2544_helper.tolerance_low = 0.0
+ mock_generator.rfc2544_helper.tolerance_high = 0.005
+ mock_generator.scenario_helper.all_options = {
+ "vpp_config": {
+ "max_rate": 14880000
+ }
+ }
+ vpp_rfc2544_profile.register_generator(mock_generator)
+ self.assertEqual(0.0, vpp_rfc2544_profile.tolerance_low)
+ self.assertEqual(0.005, vpp_rfc2544_profile.tolerance_high)
+ self.assertEqual(14880000, vpp_rfc2544_profile.max_rate)
+ self.assertEqual(True, vpp_rfc2544_profile.enable_latency)
+
+ def test_stop_traffic(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ mock_generator = mock.Mock()
+ vpp_rfc2544_profile.stop_traffic(traffic_generator=mock_generator)
+ mock_generator.client.stop.assert_called_once()
+ mock_generator.client.reset.assert_called_once()
+ mock_generator.client.remove_all_streams.assert_called_once()
+
+ def test_execute_traffic(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.init_queue(mock.MagicMock())
+ vpp_rfc2544_profile.params = {
+ 'downlink_0': 'profile1',
+ 'uplink_0': 'profile2'}
+ mock_generator = mock.MagicMock()
+ mock_generator.networks = {
+ 'downlink_0': ['xe0', 'xe1'],
+ 'uplink_0': ['xe2', 'xe3'],
+ 'uplink_1': ['xe2', 'xe3']}
+ mock_generator.port_num.side_effect = [10, 20, 30, 40]
+ mock_generator.rfc2544_helper.correlated_traffic = False
+
+ with mock.patch.object(vpp_rfc2544_profile, 'create_profile') as \
+ mock_create_profile:
+ vpp_rfc2544_profile.execute_traffic(
+ traffic_generator=mock_generator)
+ mock_create_profile.assert_has_calls([
+ mock.call('profile1', 10),
+ mock.call('profile1', 20),
+ mock.call('profile2', 30),
+ mock.call('profile2', 40)])
+ mock_generator.client.add_streams.assert_has_calls([
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[30]),
+ mock.call(mock.ANY, ports=[40])])
+
+ def test_execute_traffic_correlated_traffic(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.init_queue(mock.MagicMock())
+ vpp_rfc2544_profile.params = {
+ 'downlink_0': 'profile1',
+ 'uplink_0': 'profile2'}
+ mock_generator = mock.MagicMock()
+ mock_generator.networks = {
+ 'downlink_0': ['xe0', 'xe1'],
+ 'uplink_0': ['xe2', 'xe3']}
+ mock_generator.port_num.side_effect = [10, 20, 30, 40]
+ mock_generator.rfc2544_helper.correlated_traffic = True
+
+ with mock.patch.object(vpp_rfc2544_profile, 'create_profile') as \
+ mock_create_profile:
+ vpp_rfc2544_profile.execute_traffic(
+ traffic_generator=mock_generator)
+ mock_create_profile.assert_has_calls([
+ mock.call('profile2', 10),
+ mock.call('profile2', 20)])
+ mock_generator.client.add_streams.assert_has_calls([
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20])])
+
+ def test_execute_traffic_max_rate(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE_MAX_RATE)
+ vpp_rfc2544_profile.init_queue(mock.MagicMock())
+ vpp_rfc2544_profile.pkt_size = 64
+ vpp_rfc2544_profile.params = {
+ 'downlink_0': 'profile1',
+ 'uplink_0': 'profile2'}
+ mock_generator = mock.MagicMock()
+ mock_generator.networks = {
+ 'downlink_0': ['xe0', 'xe1'],
+ 'uplink_0': ['xe2', 'xe3']}
+ mock_generator.port_num.side_effect = [10, 20, 30, 40]
+ mock_generator.rfc2544_helper.correlated_traffic = False
+
+ with mock.patch.object(vpp_rfc2544_profile, 'create_profile') as \
+ mock_create_profile:
+ vpp_rfc2544_profile.execute_traffic(
+ traffic_generator=mock_generator)
+ mock_create_profile.assert_has_calls([
+ mock.call('profile1', 10),
+ mock.call('profile1', 20),
+ mock.call('profile2', 30),
+ mock.call('profile2', 40)])
+ mock_generator.client.add_streams.assert_has_calls([
+ mock.call(mock.ANY, ports=[10]),
+ mock.call(mock.ANY, ports=[20]),
+ mock.call(mock.ANY, ports=[30]),
+ mock.call(mock.ANY, ports=[40])])
+
+ @mock.patch.object(trex_stl_streams, 'STLProfile')
+ def test_create_profile(self, mock_stl_profile):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ port = mock.ANY
+ profile_data = {'packetid_1': {'outer_l2': {'framesize': 'imix_info'}}}
+ with mock.patch.object(vpp_rfc2544_profile, 'calculate_frame_size') as \
+ mock_calculate_frame_size, \
+ mock.patch.object(vpp_rfc2544_profile, '_create_imix_data') as \
+ mock_create_imix, \
+ mock.patch.object(vpp_rfc2544_profile, '_create_vm') as \
+ mock_create_vm, \
+ mock.patch.object(vpp_rfc2544_profile,
+ '_create_single_stream') as \
+ mock_create_single_stream:
+ mock_calculate_frame_size.return_value = 64, 100
+ mock_create_imix.return_value = 'imix_data'
+ mock_create_single_stream.return_value = ['stream1']
+ vpp_rfc2544_profile.create_profile(profile_data, port)
+
+ mock_create_imix.assert_called_once_with('imix_info')
+ mock_create_vm.assert_called_once_with(
+ {'outer_l2': {'framesize': 'imix_info'}})
+ mock_create_single_stream.assert_called_once_with(port, 'imix_data',
+ 100)
+ mock_stl_profile.assert_called_once_with(['stream1'])
+
+ @mock.patch.object(trex_stl_streams, 'STLProfile')
+ def test_create_profile_max_rate(self, mock_stl_profile):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE_MAX_RATE)
+ port = mock.ANY
+ profile_data = {'packetid_1': {'outer_l2': {'framesize': 'imix_info'}}}
+ with mock.patch.object(vpp_rfc2544_profile, 'calculate_frame_size') as \
+ mock_calculate_frame_size, \
+ mock.patch.object(vpp_rfc2544_profile, '_create_imix_data') as \
+ mock_create_imix, \
+ mock.patch.object(vpp_rfc2544_profile, '_create_vm') as \
+ mock_create_vm, \
+ mock.patch.object(vpp_rfc2544_profile,
+ '_create_single_stream') as \
+ mock_create_single_stream:
+ mock_calculate_frame_size.return_value = 64, 100
+ mock_create_imix.return_value = 'imix_data'
+ mock_create_single_stream.return_value = ['stream1']
+ vpp_rfc2544_profile.create_profile(profile_data, port)
+
+ mock_create_imix.assert_called_once_with('imix_info', 'mode_DIP')
+ mock_create_vm.assert_called_once_with(
+ {'outer_l2': {'framesize': 'imix_info'}})
+ mock_create_single_stream.assert_called_once_with(port, 'imix_data',
+ 100)
+ mock_stl_profile.assert_called_once_with(['stream1'])
+
+ def test__create_imix_data_mode_DIP(self):
+ rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(self.TRAFFIC_PROFILE)
+ data = {'64B': 50, '128B': 50}
+ self.assertEqual(
+ {'64': 50.0, '128': 50.0},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_PACKETS))
+ data = {'64B': 1, '128b': 3}
+ self.assertEqual(
+ {'64': 25.0, '128': 75.0},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_PACKETS))
+ data = {}
+ self.assertEqual(
+ {},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_PACKETS))
+
+ def test__create_imix_data_mode_DIB(self):
+ rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(self.TRAFFIC_PROFILE)
+ data = {'64B': 25, '128B': 25, '512B': 25, '1518B': 25}
+ byte_total = 64 * 25 + 128 * 25 + 512 * 25 + 1518 * 25
+ self.assertEqual(
+ {'64': 64 * 25.0 * 100 / byte_total,
+ '128': 128 * 25.0 * 100 / byte_total,
+ '512': 512 * 25.0 * 100 / byte_total,
+ '1518': 1518 * 25.0 * 100 / byte_total},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_BYTES))
+ data = {}
+ self.assertEqual(
+ {},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_BYTES))
+ data = {'64B': 100}
+ self.assertEqual(
+ {'64': 100.0},
+ rfc2544_profile._create_imix_data(
+ data, weight_mode=constants.DISTRIBUTION_IN_BYTES))
+
+ def test__create_vm(self):
+ packet = {'outer_l2': 'l2_definition'}
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ with mock.patch.object(vpp_rfc2544_profile, '_set_outer_l2_fields') as \
+ mock_l2_fileds:
+ vpp_rfc2544_profile._create_vm(packet)
+ mock_l2_fileds.assert_called_once_with('l2_definition')
+
+ @mock.patch.object(trex_stl_packet_builder_scapy, 'STLPktBuilder',
+ return_value='packet')
+ def test__create_single_packet(self, mock_pktbuilder):
+ size = 128
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.ether_packet = mock.MagicMock()
+ vpp_rfc2544_profile.ip_packet = mock.MagicMock()
+ vpp_rfc2544_profile.udp_packet = mock.MagicMock()
+ vpp_rfc2544_profile.trex_vm = 'trex_vm'
+ # base_pkt = (
+ # vpp_rfc2544_profile.ether_packet / vpp_rfc2544_profile.ip_packet /
+ # vpp_rfc2544_profile.udp_packet)
+ # pad = (size - len(base_pkt)) * 'x'
+ output = vpp_rfc2544_profile._create_single_packet(size=size)
+ self.assertEqual(mock_pktbuilder.call_count, 2)
+ # mock_pktbuilder.assert_called_once_with(pkt=base_pkt / pad,
+ # vm='trex_vm')
+ self.assertEqual(output, ('packet', 'packet'))
+
+ def test__set_outer_l3v4_fields(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ outer_l3v4 = self.PROFILE[
+ tp_base.TrafficProfile.UPLINK]['ipv4']['outer_l3v4']
+ outer_l3v4['proto'] = 'tcp'
+ self.assertIsNone(
+ vpp_rfc2544_profile._set_outer_l3v4_fields(outer_l3v4))
+
+ @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats')
+ @mock.patch.object(trex_stl_streams, 'STLTXCont')
+ @mock.patch.object(trex_stl_client, 'STLStream')
+ def test__create_single_stream(self, mock_stream, mock_txcont,
+ mock_latency):
+ imix_data = {'64': 25, '512': 75}
+ mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4']
+ mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4']
+ mock_latency.side_effect = ['latency1', 'latency2']
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap()
+ vpp_rfc2544_profile.port_pg_id.add_port(10)
+ with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \
+ mock_create_single_packet:
+ mock_create_single_packet.return_value = 64, 100
+ output = vpp_rfc2544_profile._create_single_stream(10, imix_data,
+ 100, 0.0)
+ self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output)
+ mock_latency.assert_has_calls([
+ mock.call(pg_id=1), mock.call(pg_id=2)])
+ mock_txcont.assert_has_calls([
+ mock.call(percentage=25 * 100 / 100),
+ mock.call(percentage=75 * 100 / 100)], any_order=True)
+
+ @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats')
+ @mock.patch.object(trex_stl_streams, 'STLTXCont')
+ @mock.patch.object(trex_stl_client, 'STLStream')
+ def test__create_single_stream_max_rate(self, mock_stream, mock_txcont,
+ mock_latency):
+ imix_data = {'64': 25, '512': 75}
+ mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4']
+ mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4']
+ mock_latency.side_effect = ['latency1', 'latency2']
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE_MAX_RATE)
+ vpp_rfc2544_profile.pkt_size = 64
+ vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap()
+ vpp_rfc2544_profile.port_pg_id.add_port(1)
+ with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \
+ mock_create_single_packet:
+ mock_create_single_packet.return_value = 64, 100
+ output = vpp_rfc2544_profile._create_single_stream(1, imix_data,
+ 100, 0.0)
+ self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output)
+ mock_latency.assert_has_calls([
+ mock.call(pg_id=1), mock.call(pg_id=2)])
+ mock_txcont.assert_has_calls([
+ mock.call(pps=int(25 * 100 / 100)),
+ mock.call(pps=int(75 * 100 / 100))], any_order=True)
+
+ @mock.patch.object(trex_stl_streams, 'STLFlowLatencyStats')
+ @mock.patch.object(trex_stl_streams, 'STLTXCont')
+ @mock.patch.object(trex_stl_client, 'STLStream')
+ def test__create_single_stream_mlr_search(self, mock_stream, mock_txcont,
+ mock_latency):
+ imix_data = {'64': 25, '512': 75}
+ mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4']
+ mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4']
+ mock_latency.side_effect = ['latency1', 'latency2']
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.max_rate = 14880000
+ vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap()
+ vpp_rfc2544_profile.port_pg_id.add_port(10)
+ with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \
+ mock_create_single_packet:
+ mock_create_single_packet.return_value = 64, 100
+ output = vpp_rfc2544_profile._create_single_stream(10, imix_data,
+ 100, 0.0)
+ self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output)
+ mock_latency.assert_has_calls([
+ mock.call(pg_id=1), mock.call(pg_id=2)])
+ mock_txcont.assert_has_calls([
+ mock.call(pps=25 * 100 / 100),
+ mock.call(pps=75 * 100 / 100)], any_order=True)
+
+ def test_binary_search_with_optimized(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.pkt_size = 64
+ vpp_rfc2544_profile.init_queue(mock.MagicMock())
+ mock_generator = mock.MagicMock()
+ mock_generator.vnfd_helper.interfaces = [
+ {"name": "xe0"}, {"name": "xe0"}
+ ]
+
+ vpp_rfc2544_profile.ports = [0, 1]
+ vpp_rfc2544_profile.port_pg_id = PortPgIDMap()
+ vpp_rfc2544_profile.port_pg_id.add_port(0)
+ vpp_rfc2544_profile.port_pg_id.add_port(1)
+ vpp_rfc2544_profile.profiles = mock.MagicMock()
+ vpp_rfc2544_profile.test_data = mock.MagicMock()
+ vpp_rfc2544_profile.queue = mock.MagicMock()
+
+ with mock.patch.object(MultipleLossRatioSearch, 'measure') as \
+ mock_measure, \
+ mock.patch.object(MultipleLossRatioSearch, 'ndrpdr') as \
+ mock_ndrpdr:
+ measured_low = ReceiveRateMeasurement(1, 14880000, 14879927, 0)
+ measured_high = ReceiveRateMeasurement(1, 14880000, 14879927, 0)
+ measured_low.latency = ['1000/3081/3962', '500/3149/3730']
+ measured_high.latency = ['1000/3081/3962', '500/3149/3730']
+ starting_interval = ReceiveRateInterval(measured_low,
+ measured_high)
+ starting_result = NdrPdrResult(starting_interval,
+ starting_interval)
+ mock_measure.return_value = ReceiveRateMeasurement(1, 14880000,
+ 14879927, 0)
+ mock_ndrpdr.return_value = MultipleLossRatioSearch.ProgressState(
+ starting_result, 2, 30, 0.005, 0.0,
+ 4857361, 4977343)
+
+ result_samples = vpp_rfc2544_profile.binary_search_with_optimized(
+ traffic_generator=mock_generator, duration=30,
+ timeout=720,
+ test_data={})
+
+ expected = {'Result_NDR_LOWER': {'bandwidth_total_Gbps': 9.999310944,
+ 'rate_total_pps': 14879927.0},
+ 'Result_NDR_UPPER': {'bandwidth_total_Gbps': 9.999310944,
+ 'rate_total_pps': 14879927.0},
+ 'Result_NDR_packets_lost': {'packet_loss_ratio': 0.0,
+ 'packets_lost': 0.0},
+ 'Result_PDR_LOWER': {'bandwidth_total_Gbps': 9.999310944,
+ 'rate_total_pps': 14879927.0},
+ 'Result_PDR_UPPER': {'bandwidth_total_Gbps': 9.999310944,
+ 'rate_total_pps': 14879927.0},
+ 'Result_PDR_packets_lost': {'packet_loss_ratio': 0.0,
+ 'packets_lost': 0.0},
+ 'Result_stream0_NDR_LOWER': {'avg_latency': 3081.0,
+ 'max_latency': 3962.0,
+ 'min_latency': 1000.0},
+ 'Result_stream0_PDR_LOWER': {'avg_latency': 3081.0,
+ 'max_latency': 3962.0,
+ 'min_latency': 1000.0},
+ 'Result_stream1_NDR_LOWER': {'avg_latency': 3149.0,
+ 'max_latency': 3730.0,
+ 'min_latency': 500.0},
+ 'Result_stream1_PDR_LOWER': {'avg_latency': 3149.0,
+ 'max_latency': 3730.0,
+ 'min_latency': 500.0}}
+ self.assertEqual(expected, result_samples)
+
+ def test_binary_search(self):
+ vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
+ self.TRAFFIC_PROFILE)
+ vpp_rfc2544_profile.pkt_size = 64
+ vpp_rfc2544_profile.init_queue(mock.MagicMock())
+ mock_generator = mock.MagicMock()
+ mock_generator.vnfd_helper.interfaces = [
+ {"name": "xe0"}, {"name": "xe1"}
+ ]
+ stats = {
+ "0": {
+ "ibytes": 55549120,
+ "ierrors": 0,
+ "ipackets": 867955,
+ "obytes": 55549696,
+ "oerrors": 0,
+ "opackets": 867964,
+ "rx_bps": 104339032.0,
+ "rx_bps_L1": 136944984.0,
+ "rx_pps": 203787.2,
+ "rx_util": 1.36944984,
+ "tx_bps": 134126008.0,
+ "tx_bps_L1": 176040392.0,
+ "tx_pps": 261964.9,
+ "tx_util": 1.7604039200000001
+ },
+ "1": {
+ "ibytes": 55549696,
+ "ierrors": 0,
+ "ipackets": 867964,
+ "obytes": 55549120,
+ "oerrors": 0,
+ "opackets": 867955,
+ "rx_bps": 134119648.0,
+ "rx_bps_L1": 176032032.0,
+ "rx_pps": 261952.4,
+ "rx_util": 1.76032032,
+ "tx_bps": 104338192.0,
+ "tx_bps_L1": 136943872.0,
+ "tx_pps": 203785.5,
+ "tx_util": 1.36943872
+ },
+ "flow_stats": {
+ "1": {
+ "rx_bps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ },
+ "rx_bps_l1": {
+ "0": 0.0,
+ "1": 0.0,
+ "total": 0.0
+ },
+ "rx_bytes": {
+ "0": 6400,
+ "1": 0,
+ "total": 6400
+ },
+ "rx_pkts": {
+ "0": 100,
+ "1": 0,
+ "total": 100
+ },
+ "rx_pps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ },
+ "tx_bps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ },
+ "tx_bps_l1": {
+ "0": 0.0,
+ "1": 0.0,
+ "total": 0.0
+ },
+ "tx_bytes": {
+ "0": 0,
+ "1": 6400,
+ "total": 6400
+ },
+ "tx_pkts": {
+ "0": 0,
+ "1": 100,
+ "total": 100
+ },
+ "tx_pps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ }
+ },
+ "2": {
+ "rx_bps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ },
+ "rx_bps_l1": {
+ "0": 0.0,
+ "1": 0.0,
+ "total": 0.0
+ },
+ "rx_bytes": {
+ "0": 0,
+ "1": 6464,
+ "total": 6464
+ },
+ "rx_pkts": {
+ "0": 0,
+ "1": 101,
+ "total": 101
+ },
+ "rx_pps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ },
+ "tx_bps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ },
+ "tx_bps_l1": {
+ "0": 0.0,
+ "1": 0.0,
+ "total": 0.0
+ },
+ "tx_bytes": {
+ "0": 6464,
+ "1": 0,
+ "total": 6464
+ },
+ "tx_pkts": {
+ "0": 101,
+ "1": 0,
+ "total": 101
+ },
+ "tx_pps": {
+ "0": 0,
+ "1": 0,
+ "total": 0
+ }
+ },
+ "global": {
+ "rx_err": {
+ "0": 0,
+ "1": 0
+ },
+ "tx_err": {
+ "0": 0,
+ "1": 0
+ }
+ }
+ },
+ "global": {
+ "bw_per_core": 45.6,
+ "cpu_util": 0.1494,
+ "queue_full": 0,
+ "rx_bps": 238458672.0,
+ "rx_cpu_util": 4.751e-05,
+ "rx_drop_bps": 0.0,
+ "rx_pps": 465739.6,
+ "tx_bps": 238464208.0,
+ "tx_pps": 465750.4
+ },
+ "latency": {
+ "1": {
+ "err_cntrs": {
+ "dropped": 0,
+ "dup": 0,
+ "out_of_order": 0,
+ "seq_too_high": 0,
+ "seq_too_low": 0
+ },
+ "latency": {
+ "average": 63.375,
+ "histogram": {
+ "20": 1,
+ "30": 18,
+ "40": 12,
+ "50": 10,
+ "60": 12,
+ "70": 11,
+ "80": 6,
+ "90": 10,
+ "100": 20
+ },
+ "jitter": 23,
+ "last_max": 122,
+ "total_max": 123,
+ "total_min": 20
+ }
+ },
+ "2": {
+ "err_cntrs": {
+ "dropped": 0,
+ "dup": 0,
+ "out_of_order": 0,
+ "seq_too_high": 0,
+ "seq_too_low": 0
+ },
+ "latency": {
+ "average": 74,
+ "histogram": {
+ "60": 20,
+ "70": 10,
+ "80": 3,
+ "90": 4,
+ "100": 64
+ },
+ "jitter": 6,
+ "last_max": 83,
+ "total_max": 135,
+ "total_min": 60
+ }
+ },
+ "global": {
+ "bad_hdr": 0,
+ "old_flow": 0
+ }
+ },
+ "total": {
+ "ibytes": 111098816,
+ "ierrors": 0,
+ "ipackets": 1735919,
+ "obytes": 111098816,
+ "oerrors": 0,
+ "opackets": 1735919,
+ "rx_bps": 238458680.0,
+ "rx_bps_L1": 312977016.0,
+ "rx_pps": 465739.6,
+ "rx_util": 3.1297701599999996,
+ "tx_bps": 238464200.0,
+ "tx_bps_L1": 312984264.0,
+ "tx_pps": 465750.4,
+ "tx_util": 3.12984264
+ }
+ }
+ samples = {
+ "xe0": {
+ "in_packets": 867955,
+ "latency": {
+ "2": {
+ "avg_latency": 74.0,
+ "max_latency": 135.0,
+ "min_latency": 60.0
+ }
+ },
+ "out_packets": 867964,
+ "rx_throughput_bps": 104339032.0,
+ "rx_throughput_fps": 203787.2,
+ "tx_throughput_bps": 134126008.0,
+ "tx_throughput_fps": 261964.9
+ },
+ "xe1": {
+ "in_packets": 867964,
+ "latency": {
+ "1": {
+ "avg_latency": 63.375,
+ "max_latency": 123.0,
+ "min_latency": 20.0
+ }
+ },
+ "out_packets": 867955,
+ "rx_throughput_bps": 134119648.0,
+ "rx_throughput_fps": 261952.4,
+ "tx_throughput_bps": 104338192.0,
+ "tx_throughput_fps": 203785.5
+ }
+ }
+
+ mock_generator.loss = 0
+ mock_generator.sent = 2169700
+ mock_generator.send_traffic_on_tg = mock.Mock(return_value=stats)
+ mock_generator.generate_samples = mock.Mock(return_value=samples)
+
+ result_samples = vpp_rfc2544_profile.binary_search(
+ traffic_generator=mock_generator, duration=30,
+ tolerance_value=0.005,
+ test_data={})
+
+ expected = {'Result_theor_max_throughput': 134126008.0,
+ 'xe0': {'Result_Actual_throughput': 104339032.0},
+ 'xe1': {'Result_Actual_throughput': 134119648.0}}
+ self.assertEqual(expected, result_samples)