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
21 from yardstick.network_services.traffic_profile.base import TrafficProfile
22 from yardstick.network_services.traffic_profile.traffic_profile import \
26 class TestTrexProfile(unittest.TestCase):
28 "schema": "isb:traffic_profile:0.1",
30 "description": "Fixed traffic profile to run UDP traffic",
32 "traffic_type": "FixedTraffic",
33 "frame_rate": 100, # pps
37 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
39 'traffic_profile': {'traffic_type': 'RFC2544Profile',
41 'public': {'ipv4': {'outer_l2': {'framesize': {'64B': '100',
48 "srcmac": "00:00:00:00:00:02",
49 "dstmac": "00:00:00:00:00:01"},
50 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
52 'srcip4': '9.9.1.1-90.1.2.2',
53 'dscp': 0, 'ttl': 32},
54 'outer_l4': {'srcport': '2001',
57 {'outer_l2': {'framesize':
58 {'64B': '100', '1518B': '0',
59 '128B': '0', '1400B': '0',
60 '256B': '0', '373b': '0',
62 "srcmac": "00:00:00:00:00:01",
63 "dstmac": "00:00:00:00:00:02"},
64 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
66 'srcip4': '1.1.1.1-1.15.255.255',
67 'dscp': 0, 'ttl': 32},
68 'outer_l4': {'dstport': '2001',
70 'schema': 'isb:traffic_profile:0.1'}
71 PROFILE_v6 = {'description': 'Traffic profile to run RFC2544 latency',
73 'traffic_profile': {'traffic_type': 'RFC2544Profile',
75 'public': {'ipv6': {'outer_l2': {'framesize':
76 {'64B': '100', '1518B': '0',
77 '128B': '0', '1400B': '0',
78 '256B': '0', '373b': '0',
80 "srcmac": "00:00:00:00:00:02",
81 "dstmac": "00:00:00:00:00:01"},
82 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
84 'srcip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
85 'dscp': 0, 'ttl': 32},
86 'outer_l4': {'srcport': '2001',
89 {'ipv6': {'outer_l2': {'framesize':
90 {'64B': '100', '1518B': '0',
91 '128B': '0', '1400B': '0',
92 '256B': '0', '373b': '0',
94 "srcmac": "00:00:00:00:00:01",
95 "dstmac": "00:00:00:00:00:02"},
96 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
98 'srcip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
99 'dscp': 0, 'ttl': 32},
100 'outer_l4': {'dstport': '2001',
101 'srcport': '1234'}}},
102 'schema': 'isb:traffic_profile:0.1'}
104 def test___init__(self):
105 TrafficProfile.params = self.PROFILE
107 TrexProfile(TrafficProfile)
108 self.assertEqual(trex_profile.pps, 100)
110 def test_execute(self):
112 TrexProfile(TrafficProfile)
113 self.assertEqual(None, trex_profile.execute({}))
115 def test_set_src_mac(self):
116 src_mac = "00:00:00:00:00:01"
118 TrexProfile(TrafficProfile)
119 self.assertEqual(None, trex_profile.set_src_mac(src_mac))
121 src_mac = "00:00:00:00:00:01-00:00:00:00:00:02"
122 self.assertEqual(None, trex_profile.set_src_mac(src_mac))
124 def test_set_dst_mac(self):
125 dst_mac = "00:00:00:00:00:03"
127 TrexProfile(TrafficProfile)
128 self.assertEqual(None, trex_profile.set_dst_mac(dst_mac))
130 dst_mac = "00:00:00:00:00:03-00:00:00:00:00:04"
131 self.assertEqual(None, trex_profile.set_dst_mac(dst_mac))
133 def test_set_src_ip4(self):
134 src_ipv4 = "152.16.100.20"
136 TrexProfile(TrafficProfile)
137 self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4))
139 src_ipv4 = "152.16.100.20-152.16.100.30"
140 self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4))
142 def test_set_dst_ip4(self):
143 dst_ipv4 = "152.16.100.20"
145 TrexProfile(TrafficProfile)
146 self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4))
148 dst_ipv4 = "152.16.100.20-152.16.100.30"
149 self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4))
151 def test_set_src_ip6(self):
152 src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414"
154 TrexProfile(TrafficProfile)
155 self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6))
157 src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420"
158 self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6))
160 def test_set_dst_ip6(self):
161 dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414"
163 TrexProfile(TrafficProfile)
164 self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6))
166 dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420"
167 self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6))
172 TrexProfile(TrafficProfile)
173 self.assertEqual(None, trex_profile.set_dscp(dscp))
176 self.assertEqual(None, trex_profile.set_dscp(dscp))
178 def test_src_port(self):
181 TrexProfile(TrafficProfile)
182 self.assertEqual(None, trex_profile.set_src_port(port))
185 self.assertEqual(None, trex_profile.set_src_port(port))
187 def test_dst_port(self):
190 TrexProfile(TrafficProfile)
191 self.assertEqual(None, trex_profile.set_dst_port(port))
194 self.assertEqual(None, trex_profile.set_dst_port(port))
197 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
198 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
201 TrexProfile(TrafficProfile)
202 self.assertEqual(None, trex_profile.set_qinq(qinq))
204 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
205 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
206 self.assertEqual(None, trex_profile.set_qinq(qinq))
208 def test_set_outer_l2_fields(self):
210 TrexProfile(TrafficProfile)
211 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
212 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
213 outer_l2 = self.PROFILE['private']['ipv4']['outer_l2']
214 outer_l2['QinQ'] = qinq
215 self.assertEqual(None, trex_profile.set_outer_l2_fields(outer_l2))
217 def test_set_outer_l3v4_fields(self):
219 TrexProfile(TrafficProfile)
220 outer_l3v4 = self.PROFILE['private']['ipv4']['outer_l3v4']
221 outer_l3v4['proto'] = 'tcp'
222 self.assertEqual(None, trex_profile.set_outer_l3v4_fields(outer_l3v4))
224 def test_set_outer_l3v6_fields(self):
226 TrexProfile(TrafficProfile)
227 outer_l3v6 = self.PROFILE_v6['private']['ipv6']['outer_l3v4']
228 outer_l3v6['proto'] = 'tcp'
230 outer_l3v6['hlim'] = 10
231 self.assertEqual(None, trex_profile.set_outer_l3v6_fields(outer_l3v6))
233 def test_set_outer_l4_fields(self):
235 TrexProfile(TrafficProfile)
236 outer_l4 = self.PROFILE['private']['ipv4']['outer_l4']
237 self.assertEqual(None, trex_profile.set_outer_l4_fields(outer_l4))
239 def test_get_streams(self):
241 TrexProfile(TrafficProfile)
242 trex_profile.params = self.PROFILE
243 trex_profile.profile_data = self.PROFILE["private"]
244 self.assertIsNotNone(trex_profile.get_streams())
245 trex_profile.pg_id = 1
246 self.assertIsNotNone(trex_profile.get_streams())
247 trex_profile.params = self.PROFILE_v6
248 trex_profile.profile_data = self.PROFILE_v6["private"]
249 self.assertIsNotNone(trex_profile.get_streams())
250 trex_profile.pg_id = 1
251 self.assertIsNotNone(trex_profile.get_streams())
253 def test_generate_packets(self):
255 TrexProfile(TrafficProfile)
256 trex_profile.fsize = 10
257 trex_profile.base_pkt = [10]
258 self.assertIsNone(trex_profile.generate_packets())
260 def test_generate_imix_data_error(self):
262 TrexProfile(TrafficProfile)
263 self.assertEqual({}, trex_profile.generate_imix_data(False))
265 def test__get_start_end_ipv6(self):
267 TrexProfile(TrafficProfile)
268 self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
269 "1.1.1.3", "1.1.1.1")