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 TrexProfile
33 from yardstick.network_services.traffic_profile.traffic_profile import SRC
34 from yardstick.network_services.traffic_profile.traffic_profile import DST
35 from yardstick.network_services.traffic_profile.traffic_profile import ETHERNET
36 from yardstick.network_services.traffic_profile.traffic_profile import IP
37 from yardstick.network_services.traffic_profile.traffic_profile import IPv6
38 from yardstick.network_services.traffic_profile.traffic_profile import UDP
39 from yardstick.network_services.traffic_profile.traffic_profile import SRC_PORT
40 from yardstick.network_services.traffic_profile.traffic_profile import DST_PORT
41 from yardstick.network_services.traffic_profile.traffic_profile import TYPE_OF_SERVICE
44 class TestTrexProfile(unittest.TestCase):
46 "schema": "isb:traffic_profile:0.1",
48 "description": "Fixed traffic profile to run UDP traffic",
50 "traffic_type": "FixedTraffic",
51 "frame_rate": 100, # pps
55 EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01"
56 EXAMPLE_IP_ADDR = "10.0.0.1"
57 EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414"
59 PROFILE = {'description': 'Traffic profile to run RFC2544 latency',
61 'traffic_profile': {'traffic_type': 'RFC2544Profile',
63 'public': {'ipv4': {'outer_l2': {'framesize': {'64B': '100',
70 "srcmac": "00:00:00:00:00:02",
71 "dstmac": "00:00:00:00:00:01"},
72 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2',
74 'srcip4': '9.9.1.1-90.1.2.2',
77 'outer_l4': {'srcport': '2001',
81 {'outer_l2': {'framesize':
82 {'64B': '100', '1518B': '0',
83 '128B': '0', '1400B': '0',
84 '256B': '0', '373b': '0',
86 "srcmac": "00:00:00:00:00:01",
87 "dstmac": "00:00:00:00:00:02"},
88 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
90 'srcip4': '1.1.1.1-1.15.255.255',
91 'dscp': 0, 'ttl': 32, 'count': 1},
92 'outer_l4': {'dstport': '2001',
95 'schema': 'isb:traffic_profile:0.1'}
96 PROFILE_v6 = {'description': 'Traffic profile to run RFC2544 latency',
98 'traffic_profile': {'traffic_type': 'RFC2544Profile',
100 'public': {'ipv6': {'outer_l2': {'framesize':
101 {'64B': '100', '1518B': '0',
102 '128B': '0', '1400B': '0',
103 '256B': '0', '373b': '0',
105 "srcmac": "00:00:00:00:00:02",
106 "dstmac": "00:00:00:00:00:01"},
107 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
109 'srcip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
110 'dscp': 0, 'ttl': 32,
112 'outer_l4': {'srcport': '2001',
116 {'ipv6': {'outer_l2': {'framesize':
117 {'64B': '100', '1518B': '0',
118 '128B': '0', '1400B': '0',
119 '256B': '0', '373b': '0',
121 "srcmac": "00:00:00:00:00:01",
122 "dstmac": "00:00:00:00:00:02"},
123 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820',
125 'srcip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420',
126 'dscp': 0, 'ttl': 32,
128 'outer_l4': {'dstport': '2001',
131 'schema': 'isb:traffic_profile:0.1'}
133 def test___init__(self):
134 TrafficProfile.params = self.PROFILE
136 TrexProfile(TrafficProfile)
137 self.assertEqual(trex_profile.pps, 100)
140 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
141 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
144 TrexProfile(TrafficProfile)
145 self.assertEqual(None, trex_profile.set_qinq(qinq))
147 qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
148 "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
149 self.assertEqual(None, trex_profile.set_qinq(qinq))
151 def test__set_outer_l2_fields(self):
153 TrexProfile(TrafficProfile)
154 qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0},
155 "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
156 outer_l2 = self.PROFILE['private']['ipv4']['outer_l2']
157 outer_l2['QinQ'] = qinq
158 self.assertEqual(None, trex_profile._set_outer_l2_fields(outer_l2))
160 def test__set_outer_l3v4_fields(self):
162 TrexProfile(TrafficProfile)
163 outer_l3v4 = self.PROFILE['private']['ipv4']['outer_l3v4']
164 outer_l3v4['proto'] = 'tcp'
165 self.assertEqual(None, trex_profile._set_outer_l3v4_fields(outer_l3v4))
167 def test__set_outer_l3v6_fields(self):
169 TrexProfile(TrafficProfile)
170 outer_l3v6 = self.PROFILE_v6['private']['ipv6']['outer_l3v4']
171 outer_l3v6['proto'] = 'tcp'
173 outer_l3v6['hlim'] = 10
174 self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6))
176 def test__set_outer_l4_fields(self):
178 TrexProfile(TrafficProfile)
179 outer_l4 = self.PROFILE['private']['ipv4']['outer_l4']
180 self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4))
182 def test_get_streams(self):
184 TrexProfile(TrafficProfile)
185 trex_profile.params = self.PROFILE
186 profile_data = self.PROFILE["private"]
187 self.assertIsNotNone(trex_profile.get_streams(profile_data))
188 trex_profile.pg_id = 1
189 self.assertIsNotNone(trex_profile.get_streams(profile_data))
190 trex_profile.params = self.PROFILE_v6
191 trex_profile.profile_data = self.PROFILE_v6["private"]
192 self.assertIsNotNone(trex_profile.get_streams(profile_data))
193 trex_profile.pg_id = 1
194 self.assertIsNotNone(trex_profile.get_streams(profile_data))
196 def test_generate_packets(self):
198 TrexProfile(TrafficProfile)
199 trex_profile.fsize = 10
200 trex_profile.base_pkt = [10]
201 self.assertIsNone(trex_profile.generate_packets())
203 def test_generate_imix_data_error(self):
205 TrexProfile(TrafficProfile)
206 self.assertEqual({}, trex_profile.generate_imix_data(False))
208 def test__get_start_end_ipv6(self):
210 TrexProfile(TrafficProfile)
211 self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6,
212 "1.1.1.3", "1.1.1.1")
214 def test__general_single_action_partial(self):
215 trex_profile = TrexProfile(TrafficProfile)
217 trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR)
218 self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src)
220 trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR)
221 self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst)
223 trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR)
224 self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst)
226 trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060)
227 self.assertEqual(5060, trex_profile.udp_packet.sport)
229 trex_profile._general_single_action_partial(IP)(TYPE_OF_SERVICE)(0)
230 self.assertEqual(0, trex_profile.ip_packet.tos)
232 def test__set_proto_addr(self):
233 trex_profile = TrexProfile(TrafficProfile)
235 ether_range = "00:00:00:00:00:01-00:00:00:00:00:02"
236 ip_range = "1.1.1.2-1.1.1.10"
237 ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420'
239 trex_profile._set_proto_addr(ETHERNET, SRC, ether_range)
240 trex_profile._set_proto_addr(ETHERNET, DST, ether_range)
241 trex_profile._set_proto_addr(IP, SRC, ip_range)
242 trex_profile._set_proto_addr(IP, DST, ip_range)
243 trex_profile._set_proto_addr(IPv6, SRC, ipv6_range)
244 trex_profile._set_proto_addr(IPv6, DST, ipv6_range)
245 trex_profile._set_proto_addr(UDP, SRC_PORT, "5060-5090")
246 trex_profile._set_proto_addr(UDP, DST_PORT, "5060")