3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
22 from yardstick.network_services.traffic_profile.traffic_profile \
24 from yardstick.network_services.traffic_profile.rfc2544 import \
28 class TestRFC2544Profile(unittest.TestCase):
30 "schema": "isb:traffic_profile:0.1",
32 "description": "Fixed traffic profile to run UDP traffic",
34 "traffic_type": "FixedTraffic",
35 "frame_rate": 100, # pps
39 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
41 'traffic_profile': {'traffic_type': 'RFC2544Profile',
44 {'outer_l2': {'framesize':
45 {'64B': '100', '1518B': '0',
46 '128B': '0', '1400B': '0',
47 '256B': '0', '373b': '0',
49 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
51 'srcip4': '90.90.1.1-90.105.255.255',
52 'dscp': 0, 'ttl': 32},
53 'outer_l4': {'srcport': '2001',
56 {'outer_l2': {'framesize':
57 {'64B': '100', '1518B': '0',
58 '128B': '0', '1400B': '0',
59 '256B': '0', '373b': '0',
61 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
63 'srcip4': '1.1.1.1-1.15.255.255',
64 'dscp': 0, 'ttl': 32},
65 'outer_l4': {'dstport': '2001',
67 'schema': 'isb:traffic_profile:0.1'}
69 def test___init__(self):
70 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
71 assert r_f_c2544_profile.rate
73 def test_execute(self):
74 traffic_generator = mock.Mock(autospec=TrexProfile)
75 traffic_generator.my_ports = [0, 1]
76 traffic_generator.client = \
77 mock.Mock(return_value=True)
78 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
79 r_f_c2544_profile.params = self.PROFILE
80 r_f_c2544_profile.first_run = True
81 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator))
83 def test_get_drop_percentage(self):
84 traffic_generator = mock.Mock(autospec=TrexProfile)
85 traffic_generator.my_ports = [0, 1]
86 traffic_generator.client = \
87 mock.Mock(return_value=True)
88 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
89 r_f_c2544_profile.params = self.PROFILE
90 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator))
92 for ifname in range(1):
93 name = "xe{}".format(ifname)
94 samples[name] = {"rx_throughput_fps": 20,
95 "tx_throughput_fps": 20,
96 "rx_throughput_mbps": 10,
97 "tx_throughput_mbps": 10,
102 expected = {'DropPercentage': 0.0, 'RxThroughput': 33,
103 'TxThroughput': 33, 'CurrentDropPercentage': 0.0,
105 'xe0': {'tx_throughput_fps': 20, 'in_packets': 1000,
106 'out_packets': 1000, 'rx_throughput_mbps': 10,
107 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20}}
108 self.assertDictEqual(expected,
109 r_f_c2544_profile.get_drop_percentage(
110 traffic_generator, samples,
113 def test_get_drop_percentage_update(self):
114 traffic_generator = mock.Mock(autospec=TrexProfile)
115 traffic_generator.my_ports = [0, 1]
116 traffic_generator.client = \
117 mock.Mock(return_value=True)
118 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
119 r_f_c2544_profile.params = self.PROFILE
120 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator))
122 for ifname in range(1):
123 name = "xe{}".format(ifname)
124 samples[name] = {"rx_throughput_fps": 20,
125 "tx_throughput_fps": 20,
126 "rx_throughput_mbps": 10,
127 "tx_throughput_mbps": 10,
132 expected = {'DropPercentage': 0.2, 'RxThroughput': 33,
133 'TxThroughput': 33, 'CurrentDropPercentage': 0.2,
135 'xe0': {'tx_throughput_fps': 20, 'in_packets': 1000,
136 'out_packets': 1002, 'rx_throughput_mbps': 10,
137 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20}}
138 self.assertDictEqual(expected,
139 r_f_c2544_profile.get_drop_percentage(
140 traffic_generator, samples,
143 def test_get_drop_percentage_div_zero(self):
144 traffic_generator = mock.Mock(autospec=TrexProfile)
145 traffic_generator.my_ports = [0, 1]
146 traffic_generator.client = \
147 mock.Mock(return_value=True)
148 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
149 r_f_c2544_profile.params = self.PROFILE
150 self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator))
152 for ifname in range(1):
153 name = "xe{}".format(ifname)
154 samples[name] = {"rx_throughput_fps": 20,
155 "tx_throughput_fps": 20,
156 "rx_throughput_mbps": 10,
157 "tx_throughput_mbps": 10,
162 r_f_c2544_profile.tmp_throughput = 0
163 expected = {'DropPercentage': 100.0, 'RxThroughput': 33,
164 'TxThroughput': 0, 'CurrentDropPercentage': 100.0,
166 'xe0': {'tx_throughput_fps': 20, 'in_packets': 1000,
167 'out_packets': 0, 'rx_throughput_mbps': 10,
168 'tx_throughput_mbps': 10, 'rx_throughput_fps': 20}}
169 self.assertDictEqual(expected,
170 r_f_c2544_profile.get_drop_percentage(
171 traffic_generator, samples,
174 def test_get_multiplier(self):
175 r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
176 r_f_c2544_profile.max_rate = 100
177 r_f_c2544_profile.min_rate = 100
178 self.assertEqual("1.0", r_f_c2544_profile.get_multiplier())
180 if __name__ == '__main__':