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
23 from tests.unit import STL_MOCKS
26 STLClient = mock.MagicMock()
27 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
31 from yardstick.network_services.traffic_profile.base import TrafficProfile
32 from yardstick.network_services.traffic_profile.traffic_profile import \
36 class TestTrexProfile(unittest.TestCase):
38 "schema": "isb:traffic_profile:0.1",
40 "description": "Fixed traffic profile to run UDP traffic",
42 "traffic_type": "FixedTraffic",
43 "frame_rate": 100, # pps
47 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
49 'traffic_profile': {'traffic_type': 'RFC2544Profile',
51 'public': {'ipv4': {'outer_l2': {'framesize': {'64B': '100',
58 "srcmac": "00:00:00:00:00:02",
59 "dstmac": "00:00:00:00:00:01"},
60 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
62 'srcip4': '9.9.1.1-90.1.2.2',
65 'outer_l4': {'srcport': '2001',
69 {'outer_l2': {'framesize':
70 {'64B': '100', '1518B': '0',
71 '128B': '0', '1400B': '0',
72 '256B': '0', '373b': '0',
74 "srcmac": "00:00:00:00:00:01",
75 "dstmac": "00:00:00:00:00:02"},
76 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
78 'srcip4': '1.1.1.1-1.15.255.255',
79 'dscp': 0, 'ttl': 32, 'count': 1},
80 'outer_l4': {'dstport': '2001',
83 'schema': 'isb:traffic_profile:0.1'}
84 PROFILE_v6 = {'description': 'Traffic profile to run RFC2544 latency',
86 'traffic_profile': {'traffic_type': 'RFC2544Profile',
88 'public': {'ipv6': {'outer_l2': {'framesize':
89 {'64B': '100', '1518B': '0',
90 '128B': '0', '1400B': '0',
91 '256B': '0', '373b': '0',
93 "srcmac": "00:00:00:00:00:02",
94 "dstmac": "00:00:00:00:00:01"},
95 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
97 'srcip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
100 'outer_l4': {'srcport': '2001',
104 {'ipv6': {'outer_l2': {'framesize':
105 {'64B': '100', '1518B': '0',
106 '128B': '0', '1400B': '0',
107 '256B': '0', '373b': '0',
109 "srcmac": "00:00:00:00:00:01",
110 "dstmac": "00:00:00:00:00:02"},
111 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
113 'srcip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
114 'dscp': 0, 'ttl': 32,
116 'outer_l4': {'dstport': '2001',
119 'schema': 'isb:traffic_profile:0.1'}
121 def test___init__(self):
122 TrafficProfile.params = self.PROFILE
124 TrexProfile(TrafficProfile)
125 self.assertEqual(trex_profile.pps, 100)
127 def test_execute(self):
129 TrexProfile(TrafficProfile)
130 self.assertEqual(None, trex_profile.execute({}))
132 def test_set_src_mac(self):
133 src_mac = "00:00:00:00:00:01"
135 TrexProfile(TrafficProfile)
136 self.assertEqual(None, trex_profile.set_src_mac(src_mac))
138 src_mac = "00:00:00:00:00:01-00:00:00:00:00:02"
139 self.assertEqual(None, trex_profile.set_src_mac(src_mac))
141 def test_set_dst_mac(self):
142 dst_mac = "00:00:00:00:00:03"
144 TrexProfile(TrafficProfile)
145 self.assertEqual(None, trex_profile.set_dst_mac(dst_mac))
147 dst_mac = "00:00:00:00:00:03-00:00:00:00:00:04"
148 self.assertEqual(None, trex_profile.set_dst_mac(dst_mac))
150 def test_set_src_ip4(self):
151 src_ipv4 = "152.16.100.20"
153 TrexProfile(TrafficProfile)
154 self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4))
156 src_ipv4 = "152.16.100.20-152.16.100.30"
157 self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4))
159 def test_set_dst_ip4(self):
160 dst_ipv4 = "152.16.100.20"
162 TrexProfile(TrafficProfile)
163 self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4))
165 dst_ipv4 = "152.16.100.20-152.16.100.30"
166 self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4))
168 def test_set_src_ip6(self):
169 src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414"
171 TrexProfile(TrafficProfile)
172 self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6))
174 src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420"
175 self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6))
177 def test_set_dst_ip6(self):
178 dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414"
180 TrexProfile(TrafficProfile)
181 self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6))
183 dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420"
184 self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6))
189 TrexProfile(TrafficProfile)
190 self.assertEqual(None, trex_profile.set_dscp(dscp))
193 self.assertEqual(None, trex_profile.set_dscp(dscp))
195 def test_src_port(self):
198 TrexProfile(TrafficProfile)
199 self.assertEqual(None, trex_profile.set_src_port(port))
202 self.assertEqual(None, trex_profile.set_src_port(port))
204 def test_dst_port(self):
207 TrexProfile(TrafficProfile)
208 self.assertEqual(None, trex_profile.set_dst_port(port))
211 self.assertEqual(None, trex_profile.set_dst_port(port))
214 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
215 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
218 TrexProfile(TrafficProfile)
219 self.assertEqual(None, trex_profile.set_qinq(qinq))
221 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
222 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
223 self.assertEqual(None, trex_profile.set_qinq(qinq))
225 def test_set_outer_l2_fields(self):
227 TrexProfile(TrafficProfile)
228 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
229 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
230 outer_l2 = self.PROFILE['private']['ipv4']['outer_l2']
231 outer_l2['QinQ'] = qinq
232 self.assertEqual(None, trex_profile.set_outer_l2_fields(outer_l2))
234 def test_set_outer_l3v4_fields(self):
236 TrexProfile(TrafficProfile)
237 outer_l3v4 = self.PROFILE['private']['ipv4']['outer_l3v4']
238 outer_l3v4['proto'] = 'tcp'
239 self.assertEqual(None, trex_profile.set_outer_l3v4_fields(outer_l3v4))
241 def test_set_outer_l3v6_fields(self):
243 TrexProfile(TrafficProfile)
244 outer_l3v6 = self.PROFILE_v6['private']['ipv6']['outer_l3v4']
245 outer_l3v6['proto'] = 'tcp'
247 outer_l3v6['hlim'] = 10
248 self.assertEqual(None, trex_profile.set_outer_l3v6_fields(outer_l3v6))
250 def test_set_outer_l4_fields(self):
252 TrexProfile(TrafficProfile)
253 outer_l4 = self.PROFILE['private']['ipv4']['outer_l4']
254 self.assertEqual(None, trex_profile.set_outer_l4_fields(outer_l4))
256 def test_get_streams(self):
258 TrexProfile(TrafficProfile)
259 trex_profile.params = self.PROFILE
260 profile_data = self.PROFILE["private"]
261 self.assertIsNotNone(trex_profile.get_streams(profile_data))
262 trex_profile.pg_id = 1
263 self.assertIsNotNone(trex_profile.get_streams(profile_data))
264 trex_profile.params = self.PROFILE_v6
265 trex_profile.profile_data = self.PROFILE_v6["private"]
266 self.assertIsNotNone(trex_profile.get_streams(profile_data))
267 trex_profile.pg_id = 1
268 self.assertIsNotNone(trex_profile.get_streams(profile_data))
270 def test_generate_packets(self):
272 TrexProfile(TrafficProfile)
273 trex_profile.fsize = 10
274 trex_profile.base_pkt = [10]
275 self.assertIsNone(trex_profile.generate_packets())
277 def test_generate_imix_data_error(self):
279 TrexProfile(TrafficProfile)
280 self.assertEqual({}, trex_profile.generate_imix_data(False))
282 def test__get_start_end_ipv6(self):
284 TrexProfile(TrafficProfile)
285 self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
286 "1.1.1.3", "1.1.1.1")