diff options
Diffstat (limited to 'tests/unit/network_services/traffic_profile')
9 files changed, 218 insertions, 193 deletions
diff --git a/tests/unit/network_services/traffic_profile/test_base.py b/tests/unit/network_services/traffic_profile/test_base.py index 72b097b52..290610361 100644 --- a/tests/unit/network_services/traffic_profile/test_base.py +++ b/tests/unit/network_services/traffic_profile/test_base.py @@ -48,7 +48,7 @@ class TestTrafficProfile(unittest.TestCase): def test_execute(self): traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) - self.assertRaises(NotImplementedError, traffic_profile.execute, {}) + self.assertRaises(NotImplementedError, traffic_profile.execute_traffic, {}) def test_get(self): traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) diff --git a/tests/unit/network_services/traffic_profile/test_fixed.py b/tests/unit/network_services/traffic_profile/test_fixed.py index 84843178e..eb182a2fb 100644 --- a/tests/unit/network_services/traffic_profile/test_fixed.py +++ b/tests/unit/network_services/traffic_profile/test_fixed.py @@ -74,7 +74,7 @@ class TestFixedProfile(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', 'local_mac': '00:00:00:00:00:01'}, @@ -86,7 +86,7 @@ class TestFixedProfile(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_mac': '00:00:00:00:00:02'}, diff --git a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py index cd0aacba6..6fffb9ede 100644 --- a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py @@ -20,6 +20,8 @@ from __future__ import division import unittest import mock +from copy import deepcopy + from tests.unit import STL_MOCKS STLClient = mock.MagicMock() @@ -35,6 +37,7 @@ if stl_patch: class TestIXIARFC2544Profile(unittest.TestCase): + TRAFFIC_PROFILE = { "schema": "isb:traffic_profile:0.1", "name": "fixed", @@ -43,13 +46,15 @@ class TestIXIARFC2544Profile(unittest.TestCase): "traffic_type": "FixedTraffic", "frame_rate": 100, # pps "flow_number": 10, - "frame_size": 64}} + "frame_size": 64, + }, + } PROFILE = {'description': 'Traffic profile to run RFC2544 latency', 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile', 'frame_rate': 100}, - 'public': {'ipv4': + IXIARFC2544Profile.DOWNLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -61,7 +66,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): 'dscp': 0, 'ttl': 32}, 'outer_l4': {'srcport': '2001', 'dsrport': '1234'}}}, - 'private': {'ipv4': + IXIARFC2544Profile.UPLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -78,12 +83,12 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_ixia_traffic_profile_error(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [-1] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) STATIC_TRAFFIC = { - "private": { + IXIARFC2544Profile.UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -122,7 +127,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + IXIARFC2544Profile.DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -178,17 +183,16 @@ class TestIXIARFC2544Profile(unittest.TestCase): self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC) - @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open") def test_get_ixia_traffic_profile(self, mock_open): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [-1] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) STATIC_TRAFFIC = { - "private": { + IXIARFC2544Profile.UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -230,7 +234,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + IXIARFC2544Profile.DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -293,12 +297,12 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_ixia_traffic_profile_v6(self, mock_open): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [-1] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) STATIC_TRAFFIC = { - "private": { + IXIARFC2544Profile.UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -337,7 +341,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + IXIARFC2544Profile.DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -394,7 +398,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile', 'frame_rate': 100}, - 'public': + IXIARFC2544Profile.DOWNLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', @@ -411,7 +415,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): 'dscp': 0, 'ttl': 32}, 'outer_l4': {'srcport': '2001', 'dsrport': '1234'}}}, - 'private': {'ipv4': + IXIARFC2544Profile.UPLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -435,15 +439,23 @@ class TestIXIARFC2544Profile(unittest.TestCase): profile_data, mac, static_traffic=STATIC_TRAFFIC) self.assertIsNotNone(result) + def test__get_ixia_traffic_profile_default_args(self): + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + + expected = {} + result = r_f_c2544_profile._get_ixia_traffic_profile({}) + self.assertDictEqual(result, expected) + def test__ixia_traffic_generate(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) - traffic = {"public": {'iload': 10}, - "private": {'iload': 10}} + traffic = {IXIARFC2544Profile.DOWNLINK: {'iload': 10}, + IXIARFC2544Profile.UPLINK: {'iload': 10}} ixia_obj = mock.MagicMock() r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.rate = 100 @@ -453,15 +465,16 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_execute(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.first_run = True - r_f_c2544_profile.params = {"public": {'iload': 10}, - "private": {'iload': 10}} + r_f_c2544_profile.params = {IXIARFC2544Profile.DOWNLINK: {'iload': 10}, + IXIARFC2544Profile.UPLINK: {'iload': 10}} r_f_c2544_profile.get_streams = mock.Mock() r_f_c2544_profile.full_profile = {} @@ -469,14 +482,40 @@ class TestIXIARFC2544Profile(unittest.TestCase): r_f_c2544_profile.get_multiplier = mock.Mock() r_f_c2544_profile._ixia_traffic_generate = mock.Mock() ixia_obj = mock.MagicMock() - self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator, - ixia_obj)) + self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj)) + + def test_update_traffic_profile(self): + traffic_generator = mock.Mock(autospec=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 = deepcopy(self.TRAFFIC_PROFILE) + traffic_profile.update({ + "uplink_0": ["xe0"], + "downlink_0": ["xe1", "xe2"], + }) + + r_f_c2544_profile = 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(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) @@ -509,8 +548,8 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_update(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [0] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) @@ -543,8 +582,8 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_div_zero(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [0] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) @@ -583,9 +622,10 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_start_ixia_latency(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) diff --git a/tests/unit/network_services/traffic_profile/test_prox_acl.py b/tests/unit/network_services/traffic_profile/test_prox_acl.py index be172f26b..a0c60186c 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_acl.py +++ b/tests/unit/network_services/traffic_profile/test_prox_acl.py @@ -29,19 +29,38 @@ if stl_patch: from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple -class TestProxRampProfile(unittest.TestCase): +class TestProxACLProfile(unittest.TestCase): def test_run_test_with_pkt_size(self): + def target(*args, **kwargs): + 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 get_mock_samples(*args, **kwargs): + if args[2] < 0: + raise RuntimeError(' '.join([str(args), str(runs)])) + return success_tuple + tp_config = { - 'traffic_profile': { + '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() + traffic_gen.run_test = target + traffic_gen.resource_helper.run_test.side_effect = [ success_tuple, success_tuple, @@ -53,14 +72,15 @@ class TestProxRampProfile(unittest.TestCase): fail_tuple, ] - fill_values = [1, 2, 3, 4, RuntimeError] - profile = ProxACLProfile(tp_config) - profile.fill_samples = fill_samples = mock.MagicMock(side_effect=fill_values) - profile.queue = mock.MagicMock() + profile.init(mock.MagicMock()) - with self.assertRaises(RuntimeError): - profile.run_test_with_pkt_size(traffic_gen, 128, 30) + 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 - self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 5) - self.assertEqual(fill_samples.call_count, 5) + profile.run_test_with_pkt_size(traffic_gen, profile.pkt_size, profile.duration) diff --git a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py index 0edce7a14..f56a7fba9 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py +++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py @@ -56,7 +56,7 @@ class TestProxBinSearchProfile(unittest.TestCase): profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 74.69) self.assertEqual(round(profile.current_upper, 2), 75.39) self.assertEqual(len(runs), 8) @@ -87,7 +87,7 @@ class TestProxBinSearchProfile(unittest.TestCase): profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + 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), 7) diff --git a/tests/unit/network_services/traffic_profile/test_prox_mpls.py b/tests/unit/network_services/traffic_profile/test_prox_mpls.py index 77bca9cc0..642fecc35 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_mpls.py +++ b/tests/unit/network_services/traffic_profile/test_prox_mpls.py @@ -56,7 +56,7 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 74.69) self.assertEqual(round(profile.current_upper, 2), 75.39) self.assertEqual(len(runs), 8) @@ -87,7 +87,7 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + 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), 7) diff --git a/tests/unit/network_services/traffic_profile/test_prox_profile.py b/tests/unit/network_services/traffic_profile/test_prox_profile.py index 14223da0f..9899d9909 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -65,7 +65,7 @@ class TestProxProfile(unittest.TestCase): profile.init(234) self.assertEqual(profile.queue, 234) - def test_execute(self): + def test_execute_traffic(self): packet_sizes = [ 10, 100, @@ -83,9 +83,9 @@ class TestProxProfile(unittest.TestCase): self.assertFalse(profile.done) for _ in packet_sizes: with self.assertRaises(NotImplementedError): - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) - self.assertIsNone(profile.execute(traffic_generator)) + self.assertIsNone(profile.execute_traffic(traffic_generator)) def test_bounds_iterator(self): tp_config = { diff --git a/tests/unit/network_services/traffic_profile/test_rfc2544.py b/tests/unit/network_services/traffic_profile/test_rfc2544.py index aef0b93de..221233710 100644 --- a/tests/unit/network_services/traffic_profile/test_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_rfc2544.py @@ -50,7 +50,7 @@ class TestRFC2544Profile(unittest.TestCase): 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'RFC2544Profile', 'frame_rate': 100}, - 'public_1': {'ipv4': + 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -62,7 +62,7 @@ class TestRFC2544Profile(unittest.TestCase): 'dscp': 0, 'ttl': 32, 'count': 1}, 'outer_l4': {'srcport': '2001', 'dsrport': '1234', 'count': 1}}}, - 'private_1': {'ipv4': + 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -82,27 +82,29 @@ class TestRFC2544Profile(unittest.TestCase): def test_execute(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.first_run = True - self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator)) + self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator)) def test_get_drop_percentage(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.register_generator(traffic_generator) - self.assertIsNone(r_f_c2544_profile.execute(traffic_generator)) + self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator)) samples = {} for ifname in range(1): @@ -140,15 +142,16 @@ class TestRFC2544Profile(unittest.TestCase): def test_get_drop_percentage_update(self): traffic_generator = mock.Mock(autospec=RFC2544Profile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.register_generator(traffic_generator) - self.assertIsNone(r_f_c2544_profile.execute()) + self.assertIsNone(r_f_c2544_profile.execute_traffic()) samples = {} for ifname in range(1): @@ -187,14 +190,15 @@ class TestRFC2544Profile(unittest.TestCase): def test_get_drop_percentage_div_zero(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE - self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator)) + self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator)) samples = {} for ifname in range(1): name = "xe{}".format(ifname) @@ -254,9 +258,10 @@ class TestRFC2544Profile(unittest.TestCase): def test_execute_latency(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "private_0": ["xe0"], + "public_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) diff --git a/tests/unit/network_services/traffic_profile/test_traffic_profile.py b/tests/unit/network_services/traffic_profile/test_traffic_profile.py index 9a78c36a3..8355c85b6 100644 --- a/tests/unit/network_services/traffic_profile/test_traffic_profile.py +++ b/tests/unit/network_services/traffic_profile/test_traffic_profile.py @@ -29,8 +29,16 @@ stl_patch.start() if stl_patch: from yardstick.network_services.traffic_profile.base import TrafficProfile - from yardstick.network_services.traffic_profile.traffic_profile import \ - TrexProfile + from yardstick.network_services.traffic_profile.traffic_profile import TrexProfile + from yardstick.network_services.traffic_profile.traffic_profile import SRC + from yardstick.network_services.traffic_profile.traffic_profile import DST + from yardstick.network_services.traffic_profile.traffic_profile import ETHERNET + from yardstick.network_services.traffic_profile.traffic_profile import IP + from yardstick.network_services.traffic_profile.traffic_profile import IPv6 + from yardstick.network_services.traffic_profile.traffic_profile import UDP + from yardstick.network_services.traffic_profile.traffic_profile import SRC_PORT + from yardstick.network_services.traffic_profile.traffic_profile import DST_PORT + from yardstick.network_services.traffic_profile.traffic_profile import TYPE_OF_SERVICE class TestTrexProfile(unittest.TestCase): @@ -44,28 +52,32 @@ class TestTrexProfile(unittest.TestCase): "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}, - 'public': {'ipv4': {'outer_l2': {'framesize': {'64B': '100', + 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', + "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', + 'outer_l4': {'srcport': '2001', 'dsrport': '1234', 'count': 1}}}, - 'private': {'ipv4': + TrafficProfile.UPLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -85,22 +97,22 @@ class TestTrexProfile(unittest.TestCase): 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'RFC2544Profile', 'frame_rate': 100}, - 'public': {'ipv6': {'outer_l2': {'framesize': + 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', + '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', + 'outer_l4': {'srcport': '2001', 'dsrport': '1234', 'count': 1}}}, - 'private': + TrafficProfile.UPLINK: {'ipv6': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -124,92 +136,6 @@ class TestTrexProfile(unittest.TestCase): TrexProfile(TrafficProfile) self.assertEqual(trex_profile.pps, 100) - def test_execute(self): - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.execute({})) - - def test_set_src_mac(self): - src_mac = "00:00:00:00:00:01" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_mac(src_mac)) - - src_mac = "00:00:00:00:00:01-00:00:00:00:00:02" - self.assertEqual(None, trex_profile.set_src_mac(src_mac)) - - def test_set_dst_mac(self): - dst_mac = "00:00:00:00:00:03" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_mac(dst_mac)) - - dst_mac = "00:00:00:00:00:03-00:00:00:00:00:04" - self.assertEqual(None, trex_profile.set_dst_mac(dst_mac)) - - def test_set_src_ip4(self): - src_ipv4 = "152.16.100.20" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4)) - - src_ipv4 = "152.16.100.20-152.16.100.30" - self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4)) - - def test_set_dst_ip4(self): - dst_ipv4 = "152.16.100.20" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4)) - - dst_ipv4 = "152.16.100.20-152.16.100.30" - self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4)) - - def test_set_src_ip6(self): - src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6)) - - src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420" - self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6)) - - def test_set_dst_ip6(self): - dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6)) - - dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420" - self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6)) - - def test_dscp(self): - dscp = "0" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dscp(dscp)) - - dscp = "0-1" - self.assertEqual(None, trex_profile.set_dscp(dscp)) - - def test_src_port(self): - port = "1234" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_port(port)) - - port = "1234-5678" - self.assertEqual(None, trex_profile.set_src_port(port)) - - def test_dst_port(self): - port = "1234" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_port(port)) - - port = "1234-5678" - self.assertEqual(None, trex_profile.set_dst_port(port)) - def test_qinq(self): qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0}, "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}} @@ -222,47 +148,47 @@ class TestTrexProfile(unittest.TestCase): "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}} self.assertEqual(None, trex_profile.set_qinq(qinq)) - def test_set_outer_l2_fields(self): + def test__set_outer_l2_fields(self): trex_profile = \ TrexProfile(TrafficProfile) qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0}, "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}} - outer_l2 = self.PROFILE['private']['ipv4']['outer_l2'] + outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2'] outer_l2['QinQ'] = qinq - self.assertEqual(None, trex_profile.set_outer_l2_fields(outer_l2)) + self.assertEqual(None, trex_profile._set_outer_l2_fields(outer_l2)) - def test_set_outer_l3v4_fields(self): + def test__set_outer_l3v4_fields(self): trex_profile = \ TrexProfile(TrafficProfile) - outer_l3v4 = self.PROFILE['private']['ipv4']['outer_l3v4'] + outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4'] outer_l3v4['proto'] = 'tcp' - self.assertEqual(None, trex_profile.set_outer_l3v4_fields(outer_l3v4)) + self.assertEqual(None, trex_profile._set_outer_l3v4_fields(outer_l3v4)) - def test_set_outer_l3v6_fields(self): + def test__set_outer_l3v6_fields(self): trex_profile = \ TrexProfile(TrafficProfile) - outer_l3v6 = self.PROFILE_v6['private']['ipv6']['outer_l3v4'] + outer_l3v6 = self.PROFILE_v6[TrafficProfile.UPLINK]['ipv6']['outer_l3v4'] outer_l3v6['proto'] = 'tcp' outer_l3v6['tc'] = 1 outer_l3v6['hlim'] = 10 - self.assertEqual(None, trex_profile.set_outer_l3v6_fields(outer_l3v6)) + self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6)) - def test_set_outer_l4_fields(self): + def test__set_outer_l4_fields(self): trex_profile = \ TrexProfile(TrafficProfile) - outer_l4 = self.PROFILE['private']['ipv4']['outer_l4'] - self.assertEqual(None, trex_profile.set_outer_l4_fields(outer_l4)) + outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4'] + self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4)) def test_get_streams(self): trex_profile = \ TrexProfile(TrafficProfile) trex_profile.params = self.PROFILE - profile_data = self.PROFILE["private"] + profile_data = self.PROFILE[TrafficProfile.UPLINK] self.assertIsNotNone(trex_profile.get_streams(profile_data)) trex_profile.pg_id = 1 self.assertIsNotNone(trex_profile.get_streams(profile_data)) trex_profile.params = self.PROFILE_v6 - trex_profile.profile_data = self.PROFILE_v6["private"] + trex_profile.profile_data = self.PROFILE_v6[TrafficProfile.UPLINK] self.assertIsNotNone(trex_profile.get_streams(profile_data)) trex_profile.pg_id = 1 self.assertIsNotNone(trex_profile.get_streams(profile_data)) @@ -284,3 +210,37 @@ class TestTrexProfile(unittest.TestCase): TrexProfile(TrafficProfile) self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6, "1.1.1.3", "1.1.1.1") + + def test__general_single_action_partial(self): + trex_profile = TrexProfile(TrafficProfile) + + trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR) + self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src) + + trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR) + self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst) + + trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR) + self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst) + + trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060) + self.assertEqual(5060, trex_profile.udp_packet.sport) + + trex_profile._general_single_action_partial(IP)(TYPE_OF_SERVICE)(0) + self.assertEqual(0, trex_profile.ip_packet.tos) + + def test__set_proto_addr(self): + trex_profile = TrexProfile(TrafficProfile) + + 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(ETHERNET, SRC, ether_range) + trex_profile._set_proto_addr(ETHERNET, DST, ether_range) + trex_profile._set_proto_addr(IP, SRC, ip_range) + trex_profile._set_proto_addr(IP, DST, ip_range) + trex_profile._set_proto_addr(IPv6, SRC, ipv6_range) + trex_profile._set_proto_addr(IPv6, DST, ipv6_range) + trex_profile._set_proto_addr(UDP, SRC_PORT, "5060-5090") + trex_profile._set_proto_addr(UDP, DST_PORT, "5060") |