1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from __future__ import absolute_import
21 from tests.unit import STL_MOCKS
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
28 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
29 from yardstick.network_services.traffic_profile.prox_mpls_tag_untag import ProxMplsTagUntagProfile
32 class TestProxMplsTagUntagProfile(unittest.TestCase):
34 def test_mpls_1(self):
35 def target(*args, **kwargs):
37 if args[2] < 0 or args[2] > 100:
38 raise RuntimeError(' '.join([str(args), str(runs)]))
41 return success_tuple, {}
45 'packet_sizes': [200],
50 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
51 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
53 traffic_generator = mock.MagicMock()
55 profile = ProxMplsTagUntagProfile(tp_config)
56 profile.init(mock.MagicMock())
57 profile._profile_helper = profile_helper = mock.MagicMock()
58 profile_helper.run_test = target
60 profile.execute_traffic(traffic_generator)
61 self.assertEqual(round(profile.current_lower, 2), 74.69)
62 self.assertEqual(round(profile.current_upper, 2), 75.39)
63 self.assertEqual(len(runs), 8)
65 def test_mpls_2(self):
66 def target(*args, **kwargs):
68 if args[2] < 0 or args[2] > 100:
69 raise RuntimeError(' '.join([str(args), str(runs)]))
72 return success_tuple, {}
76 'packet_sizes': [200],
77 'test_precision': 2.0,
82 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
83 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
85 traffic_generator = mock.MagicMock()
87 profile = ProxMplsTagUntagProfile(tp_config)
88 profile.init(mock.MagicMock())
89 profile._profile_helper = profile_helper = mock.MagicMock()
90 profile_helper.run_test = target
92 profile.execute_traffic(traffic_generator)
93 self.assertEqual(round(profile.current_lower, 2), 24.06)
94 self.assertEqual(round(profile.current_upper, 2), 25.47)
95 self.assertEqual(len(runs), 7)