blob: b1ef4c2ae0c6333358d56a7398d69cfe3fde7255 [file] [log] [blame]
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070016import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
20from scapy.all import *
21import time
22import json
23import threading
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070024from OnosCtrl import OnosCtrl
Chetan Gaonker3533faa2016-04-25 17:50:14 -070025from OnosFlowCtrl import OnosFlowCtrl, get_mac
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070026from OltConfig import OltConfig
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070027import random
28from threading import current_thread
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070029log.setLevel('INFO')
30
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070031class flows_exchange(unittest.TestCase):
32
33 #Use the first available device id as our device id to program flows
34 app = 'org.onosproject.cli'
35 PORT_TX_DEFAULT = 2
36 PORT_RX_DEFAULT = 1
37 INTF_TX_DEFAULT = 'veth2'
38 INTF_RX_DEFAULT = 'veth0'
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070039 default_port_map = {
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070040 PORT_TX_DEFAULT : INTF_TX_DEFAULT,
41 PORT_RX_DEFAULT : INTF_RX_DEFAULT,
42 INTF_TX_DEFAULT : PORT_TX_DEFAULT,
43 INTF_RX_DEFAULT : PORT_RX_DEFAULT
44 }
45
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070046 def incmac(self, mac):
47 tmp = str(hex(int('0x'+mac,16)+1).split('x')[1])
48 mac = '0'+ tmp if len(tmp) < 2 else tmp
49 return mac
50
51 def next_mac(self, mac):
52 mac = mac.split(":")
53 mac[5] = self.incmac(mac[5])
54
55 if len(mac[5]) > 2:
56 mac[0] = self.incmac(mac[0])
57 mac[5] = '01'
58 if len(mac[0]) > 2:
59 mac[0] = '01'
60 mac[1] = self.incmac(mac[1])
61 mac[5] = '01'
62 return ':'.join(mac)
63
64 def to_egress_mac(cls, mac):
65 mac = mac.split(":")
66 mac[4] = '01'
67 return ':'.join(mac)
68
69 def inc_ip(self, ip, i):
70 ip[i] =str(int(ip[i])+1)
71 return '.'.join(ip)
72
73
74 def next_ip(self, ip):
75 lst = ip.split('.')
76 for i in (3,0,-1):
77 if int(lst[i]) < 255:
78 return self.inc_ip(lst, i)
79 elif int(lst[i]) == 255:
80 lst[i] = '0'
81 if int(lst[i-1]) < 255:
82 return self.inc_ip(lst,i-1)
83 elif int(lst[i-2]) < 255:
84 lst[i-1] = '0'
85 return self.inc_ip(lst,i-2)
86 else:
87 break
88
89 def to_egress_ip(self, ip):
90 lst=ip.split('.')
91 lst[0] = '182'
92 return '.'.join(lst)
93
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070094 @classmethod
95 def setUpClass(cls):
96 cls.olt = OltConfig()
97 cls.port_map = cls.olt.olt_port_map()
98 if not cls.port_map:
99 cls.port_map = cls.default_port_map
Chetan Gaonkera9b6fcb2016-04-15 17:35:24 -0700100 cls.device_id = 'of:' + get_mac() ##match against our device id
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700101
102 def test_flow_mac(self):
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700103 '''Test Add and verify flows with MAC selectors'''
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700104 egress = 1
105 ingress = 2
106 egress_mac = '00:00:00:00:00:01'
107 ingress_mac = '00:00:00:00:00:02'
108 flow = OnosFlowCtrl(deviceId = self.device_id,
109 egressPort = egress,
110 ingressPort = ingress,
111 ethSrc = ingress_mac,
112 ethDst = egress_mac)
113 result = flow.addFlow()
114 assert_equal(result, True)
115 ##wait for flows to be added to ONOS
116 time.sleep(3)
117 self.success = False
118 def mac_recv_task():
119 def recv_cb(pkt):
120 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
121 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700122 sniff(count=2, timeout=5, lfilter = lambda p: p.src == ingress_mac,
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700123 prn = recv_cb, iface = self.port_map[egress])
124
125 t = threading.Thread(target = mac_recv_task)
126 t.start()
127 pkt = Ether(src = ingress_mac, dst = egress_mac)/IP()
128 log.info('Sending a packet to verify if flows are correct')
129 sendp(pkt, count=50, iface = self.port_map[ingress])
130 t.join()
131 assert_equal(self.success, True)
132
133 def test_flow_ip(self):
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700134 '''Test Add and verify flows with IPv4 selectors'''
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700135 egress = 1
136 ingress = 2
137 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
138 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
139 flow = OnosFlowCtrl(deviceId = self.device_id,
140 egressPort = egress,
141 ingressPort = ingress,
142 ethType = '0x0800',
143 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
144 ipDst = ('IPV4_DST', egress_map['ip']+'/32')
145 )
146 result = flow.addFlow()
147 assert_equal(result, True)
148 ##wait for flows to be added to ONOS
149 time.sleep(3)
150 self.success = False
151 def mac_recv_task():
152 def recv_cb(pkt):
153 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
154 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700155 sniff(count=2, timeout=5,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700156 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'],
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700157 prn = recv_cb, iface = self.port_map[egress])
158
159 t = threading.Thread(target = mac_recv_task)
160 t.start()
161 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
162 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
163 pkt = L2/L3
164 log.info('Sending a packet to verify if flows are correct')
165 sendp(pkt, count=50, iface = self.port_map[ingress])
166 t.join()
167 assert_equal(self.success, True)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700168
169
170 def test_flow_tcp_port(self):
171 egress = 1
172 ingress = 2
173 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 9500 }
174 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 9000 }
175 flow = OnosFlowCtrl(deviceId = self.device_id,
176 egressPort = egress,
177 ingressPort = ingress,
178 tcpSrc = ingress_map['tcp_port'],
179 tcpDst = egress_map['tcp_port']
180 )
181 result = flow.addFlow()
182 assert_equal(result, True)
183 ##wait for flows to be added to ONOS
184 time.sleep(3)
185 self.success = False
186 def mac_recv_task():
187 def recv_cb(pkt):
188 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
189 self.success = True
190 sniff(count=2, timeout=5,
191 lfilter = lambda p: TCP in p and p[TCP].dport == egress_map['tcp_port'] and p[TCP].sport == ingress_map['tcp_port'] ,prn = recv_cb, iface = self.port_map[egress])
192
193 t = threading.Thread(target = mac_recv_task)
194 t.start()
195 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
196 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
197 L4 = TCP(sport = ingress_map['tcp_port'], dport = egress_map['tcp_port'])
198 pkt = L2/L3/L4
199 log.info('Sending packets to verify if flows are correct')
200 sendp(pkt, count=50, iface = self.port_map[ingress])
201 t.join()
202 assert_equal(self.success, True)
203
204
205
206 def test_flow_udp_port(self):
207 egress = 1
208 ingress = 2
209 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 9500 }
210 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 9000 }
211 flow = OnosFlowCtrl(deviceId = self.device_id,
212 egressPort = egress,
213 ingressPort = ingress,
214 udpSrc = ingress_map['udp_port'],
215 udpDst = egress_map['udp_port']
216 )
217 result = flow.addFlow()
218 assert_equal(result, True)
219 ##wait for flows to be added to ONOS
220 time.sleep(3)
221 self.success = False
222 def mac_recv_task():
223 def recv_cb(pkt):
224 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
225 self.success = True
226 sniff(count=2, timeout=5,
227 lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port'] and p[UDP].sport == ingress_map['udp_port'] ,prn = recv_cb, iface = self.port_map[egress])
228
229 t = threading.Thread(target = mac_recv_task)
230 t.start()
231 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
232 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
233 L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port'])
234 pkt = L2/L3/L4
235 log.info('Sending packets to verify if flows are correct')
236 sendp(pkt, count=50, iface = self.port_map[ingress])
237 t.join()
238 assert_equal(self.success, True)
239
240 def test_5_flow_constant_dst_mac(self):
241 egress = 1
242 ingress = 2
243 egress_mac = '00:00:00:00:01:01'
244 ingress_mac = '00:00:00:00:00:00'
245
246 for i in range(0,5):
247 ingress_mac = self.next_mac(ingress_mac)
248
249 flow = OnosFlowCtrl(deviceId = self.device_id,
250 egressPort = egress,
251 ingressPort = ingress,
252 ethSrc = ingress_mac,
253 ethDst = egress_mac)
254 result = flow.addFlow()
255 assert_equal(result, True)
256 ##wait for flows to be added to ONOS
257 time.sleep(1)
258 log.info("%d flow added.",i+1)
259 self.success = False
260
261 def mac_recv_task():
262 def recv_cb(pkt):
263 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
264 self.success = True
265 sniff(count=2, timeout=5, lfilter = lambda p: p.src == '00:00:00:00:00:02',
266 prn = recv_cb, iface = self.port_map[egress])
267
268 t = threading.Thread(target = mac_recv_task)
269 t.start()
270 pkt = Ether(src = '00:00:00:00:00:02', dst = egress_mac)/IP()
271 log.info('Sending packets to verify if flows are correct')
272 sendp(pkt, count=50, iface = self.port_map[ingress])
273 t.join()
274 assert_equal(self.success, True)
275
276
277 def test_500_flow_constant_dst_mac(self):
278 egress = 1
279 ingress = 2
280 egress_mac = '00:00:00:00:01:01'
281 ingress_mac = '00:00:00:00:00:00'
282 success_dir = {}
283
284 for i in range(0,500):
285 ingress_mac = self.next_mac(ingress_mac)
286
287 flow = OnosFlowCtrl(deviceId = self.device_id,
288 egressPort = egress,
289 ingressPort = ingress,
290 ethSrc = ingress_mac,
291 ethDst = egress_mac)
292 result = flow.addFlow()
293 assert_equal(result, True)
294 ##wait for flows to be added to ONOS
295 time.sleep(1)
296 log.info("%d flow added.",i+1)
297 self.success = True
298
299 def verify_flow(*r):
300 random_src = ''.join(r)
301 def mac_recv_task():
302 def recv_cb(pkt):
303 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
304 success_dir[current_thread().name] = True
305 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
306 prn = recv_cb, iface = self.port_map[egress])
307
308 t = threading.Thread(target = mac_recv_task)
309 t.start()
310 pkt = Ether(src = random_src, dst = egress_mac)/IP()
311 log.info('Sending packets to verify if flows are correct')
312 sendp(pkt, count=50, iface = self.port_map[ingress])
313 t.join()
314
315 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
316 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
317 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,100)).split('x')[1])
318 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(101,240)).split('x')[1])
319 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:f5')
320 t1.start()
321 t2.start()
322 t3.start()
323 t4.start()
324 t5.start()
325 t1.join()
326 t2.join()
327 t3.join()
328 t4.join()
329 t5.join()
330 if len(success_dir) < 5 or len(success_dir) > 5:
331 self.success = False
332 else:
333 for t in success_dir.items():
334 self.success = self.success and t[1]
335 assert_equal(self.success, True)
336
337 def test_1k_flow_constant_dst_mac(self):
338 egress = 1
339 ingress = 2
340 egress_mac = '00:00:00:00:01:01'
341 ingress_mac = '00:00:00:00:00:00'
342 success_dir = {}
343
344 for i in range(0,1000):
345 ingress_mac = self.next_mac(ingress_mac)
346 flow = OnosFlowCtrl(deviceId = self.device_id,
347 egressPort = egress,
348 ingressPort = ingress,
349 ethSrc = ingress_mac,
350 ethDst = egress_mac)
351 result = flow.addFlow()
352 assert_equal(result, True)
353 ##wait for flows to be added to ONOS
354 time.sleep(1)
355 log.info("%d flow added.",i+1)
356 self.success = True
357
358 def verify_flow(*r):
359 random_src = ''.join(r)
360 def mac_recv_task():
361 def recv_cb(pkt):
362 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
363 success_dir[current_thread().name] = True
364 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
365 prn = recv_cb, iface = self.port_map[egress])
366
367 t = threading.Thread(target = mac_recv_task)
368 t.start()
369 pkt = Ether(src = random_src, dst = egress_mac)/IP()
370 log.info('Sending packets to verify if flows are correct')
371 sendp(pkt, count=50, iface = self.port_map[ingress])
372 t.join()
373
374 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
375 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
376 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:09')
377 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
378 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
379 t6 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:08')
380 t7 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
381 t8 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
382 t9 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:'+ hex(random.randrange(16,175)).split('x')[1])
383 t10 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:eb')
384 t1.start()
385 t2.start()
386 t3.start()
387 t4.start()
388 t5.start()
389 t6.start()
390 t7.start()
391 t8.start()
392 t9.start()
393 t10.start()
394
395 t1.join()
396 t2.join()
397 t3.join()
398 t4.join()
399 t5.join()
400 t6.join()
401 t7.join()
402 t8.join()
403 t9.join()
404 t10.join()
405 if len(success_dir) < 10 or len(success_dir) > 10:
406 self.success = False
407 else:
408 for t in success_dir.items():
409 self.success = self.success and t[1]
410 assert_equal(self.success, True)
411
412
413 @nottest
414 def test_10k_flow_constant_dst_mac(self):
415 egress = 1
416 ingress = 2
417 egress_mac = '00:00:00:00:01:01'
418 ingress_mac = '00:00:00:00:00:00'
419 success_dir = {}
420
421 for i in range(0,10000):
422 ingress_mac = self.next_mac(ingress_mac)
423
424 flow = OnosFlowCtrl(deviceId = self.device_id,
425 egressPort = egress,
426 ingressPort = ingress,
427 ethSrc = ingress_mac,
428 ethDst = egress_mac)
429 result = flow.addFlow()
430 assert_equal(result, True)
431 ##wait for flows to be added to ONOS
432 time.sleep(1)
433 log.info("%d flow added.",i+1)
434 self.success = True
435
436 def verify_flow(*r):
437 random_src = ''.join(r)
438 def mac_recv_task():
439 def recv_cb(pkt):
440 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
441 success_dir[current_thread().name] = True
442 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
443 prn = recv_cb, iface = self.port_map[egress])
444
445 t = threading.Thread(target = mac_recv_task)
446 t.start()
447 pkt = Ether(src = random_src, dst = egress_mac)/IP()
448 log.info('Sending packets to verify if flows are correct')
449 sendp(pkt, count=50, iface = self.port_map[ingress])
450 t.join()
451
452 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
453 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
454 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
455 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
456 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
457 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
458 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(17,21)).split('x')[1] +':00:00:00:00:' +
459 hex(random.randrange(16,254)).split('x')[1])
460 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,30)).split('x')[1] +':00:00:00:00:' +
461 hex(random.randrange(16,254)).split('x')[1])
462 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(31,38)).split('x')[1] +':00:00:00:00:' +
463 hex(random.randrange(16,254)).split('x')[1])
464 t10 = threading.Thread(target = verify_flow, args = '27:00:00:00:00:37')
465
466 t1.start()
467 t2.start()
468 t3.start()
469 t4.start()
470 t5.start()
471 t6.start()
472 t7.start()
473 t8.start()
474 t9.start()
475 t10.start()
476
477 t1.join()
478 t2.join()
479 t3.join()
480 t4.join()
481 t5.join()
482 t6.join()
483 t7.join()
484 t8.join()
485 t9.join()
486 t10.join()
487 if len(success_dir) < 10 or len(success_dir) > 10:
488 self.success = False
489 else:
490 for t in success_dir.items():
491 self.success = self.success and t[1]
492 assert_equal(self.success, True)
493
494 @nottest
495 def test_100k_flow_constant_dst_mac(self):
496 egress = 1
497 ingress = 2
498 egress_mac = '00:00:00:00:01:01'
499 ingress_mac = '00:00:00:00:00:00'
500 success_dir = {}
501
502
503 for i in range(0,100000):
504 ingress_mac = self.next_mac(ingress_mac)
505
506 flow = OnosFlowCtrl(deviceId = self.device_id,
507 egressPort = egress,
508 ingressPort = ingress,
509 ethSrc = ingress_mac,
510 ethDst = egress_mac)
511 result = flow.addFlow()
512 assert_equal(result, True)
513 ##wait for flows to be added to ONOS
514 time.sleep(1)
515 log.info("%d flow added.",i+1)
516 self.success = True
517
518 def verify_flow(*r):
519 random_src = ''.join(r)
520 def mac_recv_task():
521 def recv_cb(pkt):
522 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
523 success_dir[current_thread().name] = True
524 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
525 prn = recv_cb, iface = self.port_map[egress])
526
527 t = threading.Thread(target = mac_recv_task)
528 t.start()
529 pkt = Ether(src = random_src, dst = egress_mac)/IP()
530 log.info('Sending packets to verify if flows are correct')
531 sendp(pkt, count=50, iface = self.port_map[ingress])
532 t.join()
533
534 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
535 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
536 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
537 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
538 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
539 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,41)).split('x')[1] + ':00:00:00:00:08')
540 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(42,72)).split('x')[1] +':00:00:00:00:' +
541 hex(random.randrange(16,254)).split('x')[1])
542
543 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(73,100)).split('x')[1] +':00:00:00:00:' +
544 hex(random.randrange(16,254)).split('x')[1])
545
546 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(101,136)).split('x')[1] +':00:00:00:00:' +
547 hex(random.randrange(16,254)).split('x')[1])
548
549 t10 = threading.Thread(target = verify_flow, args = '89:01:00:00:00:28')
550
551 t1.start()
552 t2.start()
553 t3.start()
554 t4.start()
555 t5.start()
556 t6.start()
557 t7.start()
558 t8.start()
559 t9.start()
560 t10.start()
561
562 t1.join()
563 t2.join()
564 t3.join()
565 t4.join()
566 t5.join()
567 t6.join()
568 t7.join()
569 t8.join()
570 t9.join()
571 t10.join()
572 if len(success_dir) < 10 or len(success_dir) > 10:
573 self.success = False
574 else:
575 for t in success_dir.items():
576 self.success = self.success and t[1]
577 assert_equal(self.success, True)
578
579
580 @nottest
581 def test_1000k_flow_constant_dst_mac(self):
582 egress = 1
583 ingress = 2
584 egress_mac = '00:00:00:00:01:01'
585 ingress_mac = '00:00:00:00:00:00'
586 success_dir = {}
587
588 for i in range(0,1000000):
589 ingress_mac = self.next_mac(ingress_mac)
590
591 flow = OnosFlowCtrl(deviceId = self.device_id,
592 egressPort = egress,
593 ingressPort = ingress,
594 ethSrc = ingress_mac,
595 ethDst = egress_mac)
596 result = flow.addFlow()
597 assert_equal(result, True)
598 ##wait for flows to be added to ONOS
599 time.sleep(1)
600 log.info("%d flow added.",i+1)
601 self.success = True
602
603 def verify_flow(*r):
604 random_src = ''.join(r)
605
606 def mac_recv_task():
607 def recv_cb(pkt):
608 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
609 success_dir[current_thread().name] = True
610 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
611 prn = recv_cb, iface = self.port_map[egress])
612
613 t = threading.Thread(target = mac_recv_task)
614 t.start()
615 pkt = Ether(src = random_src, dst = egress_mac)/IP()
616 log.info('Sending packets to verify if flows are correct')
617 sendp(pkt, count=50, iface = self.port_map[ingress])
618 t.join()
619
620 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
621 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
622 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
623 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
624 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
625 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
626 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,50)).split('x')[1] +':00:00:00:00:' +
627 hex(random.randrange(16,254)).split('x')[1])
628
629 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(51,75)).split('x')[1] +':00:00:00:00:' +
630 hex(random.randrange(16,254)).split('x')[1])
631
632 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(76,95)).split('x')[1] +':00:00:00:00:' +
633 hex(random.randrange(16,254)).split('x')[1])
634
635 t10 = threading.Thread(target = verify_flow, args = '60:0f:00:00:00:91')
636
637 t1.start()
638 t2.start()
639 t3.start()
640 t4.start()
641 t5.start()
642 t6.start()
643 t7.start()
644 t8.start()
645 t9.start()
646 t10.start()
647
648 t1.join()
649 t2.join()
650 t3.join()
651 t4.join()
652 t5.join()
653 t6.join()
654 t7.join()
655 t8.join()
656 t9.join()
657 t10.join()
658 if len(success_dir) < 10 or len(success_dir) > 10:
659 self.success = False
660 else:
661 for t in success_dir.items():
662 self.success = self.success and t[1]
663 assert_equal(self.success, True)
664
665
666 def test_500_flow_mac(self):
667 egress = 1
668 ingress = 2
669 egress_mac = '00:00:00:00:01:00'
670 ingress_mac = '00:00:00:00:00:00'
671 success_dir = {}
672
673 for i in range(0,500):
674 ingress_mac = self.next_mac(ingress_mac)
675 egress_mac = self.to_egress_mac(ingress_mac)
676
677 flow = OnosFlowCtrl(deviceId = self.device_id,
678 egressPort = egress,
679 ingressPort = ingress,
680 ethSrc = ingress_mac,
681 ethDst = egress_mac)
682 result = flow.addFlow()
683 assert_equal(result, True)
684 ##wait for flows to be added to ONOS
685 time.sleep(1)
686 log.info("%d flow added.",i+1)
687 self.success = True
688 def verify_flow(*r):
689 random_src = ''.join(r)
690 def mac_recv_task():
691 def recv_cb(pkt):
692 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
693 success_dir[current_thread().name] = True
694 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
695 prn = recv_cb, iface = self.port_map[egress])
696
697 t = threading.Thread(target = mac_recv_task)
698 t.start()
699 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
700 log.info('Sending packets to verify if flows are correct')
701 sendp(pkt, count=50, iface = self.port_map[ingress])
702 t.join()
703
704 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
705 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
706 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,100)).split('x')[1])
707 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(101,240)).split('x')[1])
708 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:f5')
709 t1.start()
710 t2.start()
711 t3.start()
712 t4.start()
713 t5.start()
714 t1.join()
715 t2.join()
716 t3.join()
717 t4.join()
718 t5.join()
719 if len(success_dir) < 5 or len(success_dir) > 5:
720 self.success = False
721 else:
722 for t in success_dir.items():
723 self.success = self.success and t[1]
724 assert_equal(self.success, True)
725
726 def test_1k_flow_mac(self):
727 egress = 1
728 ingress = 2
729 egress_mac = '00:00:00:00:01:00'
730 ingress_mac = '00:00:00:00:00:00'
731 success_dir = {}
732
733 for i in range(0,1000):
734 ingress_mac = self.next_mac(ingress_mac)
735 egress_mac = self.to_egress_mac(ingress_mac)
736
737 flow = OnosFlowCtrl(deviceId = self.device_id,
738 egressPort = egress,
739 ingressPort = ingress,
740 ethSrc = ingress_mac,
741 ethDst = egress_mac)
742 result = flow.addFlow()
743 assert_equal(result, True)
744 ##wait for flows to be added to ONOS
745 time.sleep(1)
746 log.info("%d flow added.",i+1)
747 self.success = True
748 def verify_flow(*r):
749 random_src = ''.join(r)
750
751 def mac_recv_task():
752 def recv_cb(pkt):
753 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
754 success_dir[current_thread().name] = True
755 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
756 prn = recv_cb, iface = self.port_map[egress])
757
758 t = threading.Thread(target = mac_recv_task)
759 t.start()
760 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
761 log.info('Sending packets to verify if flows are correct')
762 sendp(pkt, count=50, iface = self.port_map[ingress])
763 t.join()
764
765 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
766 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
767 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:09')
768 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
769 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
770 t6 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:08')
771 t7 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
772 t8 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
773 t9 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:'+ hex(random.randrange(16,175)).split('x')[1])
774 t10 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:eb')
775 t1.start()
776 t2.start()
777 t3.start()
778 t4.start()
779 t5.start()
780 t6.start()
781 t7.start()
782 t8.start()
783 t9.start()
784 t10.start()
785
786 t1.join()
787 t2.join()
788 t3.join()
789 t4.join()
790 t5.join()
791 t6.join()
792 t7.join()
793 t8.join()
794 t9.join()
795 t10.join()
796 if len(success_dir) < 10 or len(success_dir) > 10:
797 self.success = False
798 else:
799 for t in success_dir.items():
800 self.success = self.success and t[1]
801 assert_equal(self.success, True)
802
803 @nottest
804 def test_10k_flow_mac(self):
805 egress = 1
806 ingress = 2
807 egress_mac = '00:00:00:00:01:00'
808 ingress_mac = '00:00:00:00:00:00'
809 success_dir = {}
810
811 for i in range(0,10000):
812 ingress_mac = self.next_mac(ingress_mac)
813 egress_mac = self.to_egress_mac(ingress_mac)
814
815 flow = OnosFlowCtrl(deviceId = self.device_id,
816 egressPort = egress,
817 ingressPort = ingress,
818 ethSrc = ingress_mac,
819 ethDst = egress_mac)
820 result = flow.addFlow()
821 assert_equal(result, True)
822 ##wait for flows to be added to ONOS
823 time.sleep(1)
824 log.info("%d flow added.",i+1)
825 self.success = True
826 def verify_flow(*r):
827 random_src = ''.join(r)
828
829 def mac_recv_task():
830 def recv_cb(pkt):
831 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
832 success_dir[current_thread().name] = True
833 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
834 prn = recv_cb, iface = self.port_map[egress])
835
836 t = threading.Thread(target = mac_recv_task)
837 t.start()
838 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
839 log.info('Sending packets to verify if flows are correct')
840 sendp(pkt, count=50, iface = self.port_map[ingress])
841 t.join()
842
843 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
844 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
845 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
846 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
847 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
848 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
849 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(17,21)).split('x')[1] +':00:00:00:00:' +
850 hex(random.randrange(16,254)).split('x')[1])
851
852 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,30)).split('x')[1] +':00:00:00:00:' +
853 hex(random.randrange(16,254)).split('x')[1])
854
855 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(31,38)).split('x')[1] +':00:00:00:00:' +
856 hex(random.randrange(16,254)).split('x')[1])
857
858 t10 = threading.Thread(target = verify_flow, args = '27:00:00:00:00:37')
859
860 t1.start()
861 t2.start()
862 t3.start()
863 t4.start()
864 t5.start()
865 t6.start()
866 t7.start()
867 t8.start()
868 t9.start()
869 t10.start()
870
871 t1.join()
872 t2.join()
873 t3.join()
874 t4.join()
875 t5.join()
876 t6.join()
877 t7.join()
878 t8.join()
879 t9.join()
880 t10.join()
881 if len(success_dir) < 10 or len(success_dir) > 10:
882 self.success = False
883 else:
884 for t in success_dir.items():
885 self.success = self.success and t[1]
886 assert_equal(self.success, True)
887
888 @nottest
889 def test_100k_flow_mac(self):
890 egress = 1
891 ingress = 2
892 egress_mac = '00:00:00:00:01:00'
893 ingress_mac = '00:00:00:00:00:00'
894 success_dir = {}
895
896 for i in range(0,100000):
897 ingress_mac = self.next_mac(ingress_mac)
898 egress_mac = self.to_egress_mac(ingress_mac)
899
900 flow = OnosFlowCtrl(deviceId = self.device_id,
901 egressPort = egress,
902 ingressPort = ingress,
903 ethSrc = ingress_mac,
904 ethDst = egress_mac)
905 result = flow.addFlow()
906 assert_equal(result, True)
907 ##wait for flows to be added to ONOS
908 time.sleep(1)
909 log.info("%d flow added.",i+1)
910 self.success = True
911
912 def verify_flow(*r):
913 random_src = ''.join(r)
914
915 def mac_recv_task():
916 def recv_cb(pkt):
917 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
918 success_dir[current_thread().name] = True
919 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
920 prn = recv_cb, iface = self.port_map[egress])
921
922 t = threading.Thread(target = mac_recv_task)
923 t.start()
924 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
925 log.info('Sending packets to verify if flows are correct')
926 sendp(pkt, count=50, iface = self.port_map[ingress])
927 t.join()
928
929 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
930 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
931 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
932 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
933 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
934 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,41)).split('x')[1] + ':00:00:00:00:08')
935 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(42,72)).split('x')[1] +':00:00:00:00:' +
936 hex(random.randrange(16,254)).split('x')[1])
937
938 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(73,100)).split('x')[1] +':00:00:00:00:' +
939 hex(random.randrange(16,254)).split('x')[1])
940
941 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(101,136)).split('x')[1] +':00:00:00:00:' +
942 hex(random.randrange(16,254)).split('x')[1])
943
944 t10 = threading.Thread(target = verify_flow, args = '89:01:00:00:00:28')
945
946 t1.start()
947 t2.start()
948 t3.start()
949 t4.start()
950 t5.start()
951 t6.start()
952 t7.start()
953 t8.start()
954 t9.start()
955 t10.start()
956
957 t1.join()
958 t2.join()
959 t3.join()
960 t4.join()
961 t5.join()
962 t6.join()
963 t7.join()
964 t8.join()
965 t9.join()
966 t10.join()
967 if len(success_dir) < 10 or len(success_dir) > 10:
968 self.success = False
969 else:
970 for t in success_dir.items():
971 self.success = self.success and t[1]
972 assert_equal(self.success, True)
973
974 @nottest
975 def test_1000k_flow_mac(self):
976 egress = 1
977 ingress = 2
978 egress_mac = '00:00:00:00:01:00'
979 ingress_mac = '00:00:00:00:00:00'
980 success_dir = {}
981
982 for i in range(0,1000000):
983 ingress_mac = self.next_mac(ingress_mac)
984 egress_mac = self.to_egress_mac(ingress_mac)
985
986 flow = OnosFlowCtrl(deviceId = self.device_id,
987 egressPort = egress,
988 ingressPort = ingress,
989 ethSrc = ingress_mac,
990 ethDst = egress_mac)
991 result = flow.addFlow()
992 assert_equal(result, True)
993 ##wait for flows to be added to ONOS
994 time.sleep(1)
995 log.info("%d flow added.",i+1)
996 self.success = True
997
998 def verify_flow(*r):
999 random_src = ''.join(r)
1000
1001 def mac_recv_task():
1002 def recv_cb(pkt):
1003 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1004 success_dir[current_thread().name] = True
1005 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
1006 prn = recv_cb, iface = self.port_map[egress])
1007
1008 t = threading.Thread(target = mac_recv_task)
1009 t.start()
1010 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1011 log.info('Sending packets to verify if flows are correct')
1012 sendp(pkt, count=50, iface = self.port_map[ingress])
1013 t.join()
1014
1015 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1016 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1017 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1018 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1019 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1020 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
1021 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,50)).split('x')[1] +':00:00:00:00:' +
1022 hex(random.randrange(16,254)).split('x')[1])
1023
1024 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(51,75)).split('x')[1] +':00:00:00:00:' +
1025 hex(random.randrange(16,254)).split('x')[1])
1026
1027 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(76,95)).split('x')[1] +':00:00:00:00:' +
1028 hex(random.randrange(16,254)).split('x')[1])
1029
1030 t10 = threading.Thread(target = verify_flow, args = '60:0f:00:00:00:91')
1031
1032 t1.start()
1033 t2.start()
1034 t3.start()
1035 t4.start()
1036 t5.start()
1037 t6.start()
1038 t7.start()
1039 t8.start()
1040 t9.start()
1041 t10.start()
1042
1043 t1.join()
1044 t2.join()
1045 t3.join()
1046 t4.join()
1047 t5.join()
1048 t6.join()
1049 t7.join()
1050 t8.join()
1051 t9.join()
1052 t10.join()
1053 if len(success_dir) < 10 or len(success_dir) > 10:
1054 self.success = False
1055 else:
1056 for t in success_dir.items():
1057 self.success = self.success and t[1]
1058 assert_equal(self.success, True)
1059
1060 def test_500_flow_ip(self):
1061 egress = 1
1062 ingress = 2
1063 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
1064 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
1065
1066 for i in range(0,500):
1067 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
1068 assert_not_equal(ingress_map['ip'], None)
1069 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
1070
1071 flow = OnosFlowCtrl(deviceId = self.device_id,
1072 egressPort = egress,
1073 ingressPort = ingress,
1074 ethType = '0x0800',
1075 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
1076 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
1077 )
1078 result = flow.addFlow()
1079 assert_equal(result, True)
1080 ##wait for flows to be added to ONOS
1081 time.sleep(1)
1082 log.info("%d flow added.",i+1)
1083 self.success = False
1084 random_src = '192.0.0.' + str(random.randrange(1,254,1))
1085 random_dst = self.to_egress_ip(random_src)
1086
1087 def mac_recv_task():
1088 def recv_cb(pkt):
1089 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1090 self.success = True
1091 sniff(count=2, timeout=5,
1092 lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src,
1093 prn = recv_cb, iface = self.port_map[egress])
1094
1095 t = threading.Thread(target = mac_recv_task)
1096 t.start()
1097 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1098 L3 = IP(src = random_src, dst = random_dst)
1099 pkt = L2/L3
1100 log.info('Sending packets to verify if flows are correct')
1101 sendp(pkt, count=50, iface = self.port_map[ingress])
1102 t.join()
1103 assert_equal(self.success, True)
1104
1105 def test_1k_flow_ip(self):
1106 egress = 1
1107 ingress = 2
1108 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
1109 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
1110
1111 for i in range(0,1000):
1112 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
1113 assert_not_equal(ingress_map['ip'], None)
1114 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
1115
1116 flow = OnosFlowCtrl(deviceId = self.device_id,
1117 egressPort = egress,
1118 ingressPort = ingress,
1119 ethType = '0x0800',
1120 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
1121 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
1122 )
1123 result = flow.addFlow()
1124 assert_equal(result, True)
1125 ##wait for flows to be added to ONOS
1126 time.sleep(1)
1127 log.info("%d flow added.",i+1)
1128 self.success = False
1129 random_src = '192.0.0.' + str(random.randrange(1,254,1))
1130 random_dst = self.to_egress_ip(random_src)
1131
1132 def mac_recv_task():
1133 def recv_cb(pkt):
1134 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1135 self.success = True
1136 sniff(count=2, timeout=5,
1137 lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src,
1138 prn = recv_cb, iface = self.port_map[egress])
1139
1140 t = threading.Thread(target = mac_recv_task)
1141 t.start()
1142 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1143 L3 = IP(src = random_src, dst = random_dst)
1144 pkt = L2/L3
1145 log.info('Sending packets to verify if flows are correct')
1146 sendp(pkt, count=50, iface = self.port_map[ingress])
1147 t.join()
1148 assert_equal(self.success, True)
1149
1150 @nottest
1151 def test_10k_flow_ip(self):
1152 egress = 1
1153 ingress = 2
1154 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
1155 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
1156
1157 for i in range(0,10000):
1158 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
1159 assert_not_equal(ingress_map['ip'], None)
1160 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
1161
1162 flow = OnosFlowCtrl(deviceId = self.device_id,
1163 egressPort = egress,
1164 ingressPort = ingress,
1165 ethType = '0x0800',
1166 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
1167 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
1168 )
1169 result = flow.addFlow()
1170 assert_equal(result, True)
1171 ##wait for flows to be added to ONOS
1172 time.sleep(1)
1173 log.info("%d flow added.",i+1)
1174 self.success = False
1175 random_src = '192.0.0.' + str(random.randrange(1,254,1))
1176 random_dst = self.to_egress_ip(random_src)
1177
1178 def mac_recv_task():
1179 def recv_cb(pkt):
1180 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1181 self.success = True
1182 sniff(count=2, timeout=5,
1183 lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src,
1184 prn = recv_cb, iface = self.port_map[egress])
1185
1186 t = threading.Thread(target = mac_recv_task)
1187 t.start()
1188 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1189 L3 = IP(src = random_src, dst = random_dst)
1190 pkt = L2/L3
1191 log.info('Sending packets to verify if flows are correct')
1192 sendp(pkt, count=50, iface = self.port_map[ingress])
1193 t.join()
1194 assert_equal(self.success, True)
1195
1196 @nottest
1197 def test_100k_flow_ip(self):
1198 egress = 1
1199 ingress = 2
1200 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
1201 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
1202
1203 for i in range(0,100000):
1204 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
1205 assert_not_equal(ingress_map['ip'], None)
1206 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
1207
1208 flow = OnosFlowCtrl(deviceId = self.device_id,
1209 egressPort = egress,
1210 ingressPort = ingress,
1211 ethType = '0x0800',
1212 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
1213 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
1214 )
1215 result = flow.addFlow()
1216 assert_equal(result, True)
1217 ##wait for flows to be added to ONOS
1218 time.sleep(1)
1219 log.info("%d flow added.",i+1)
1220 self.success = False
1221 random_src = '192.0.0.' + str(random.randrange(1,254,1))
1222 random_dst = self.to_egress_ip(random_src)
1223
1224 def mac_recv_task():
1225 def recv_cb(pkt):
1226 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1227 self.success = True
1228 sniff(count=2, timeout=5,
1229 lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src,
1230 prn = recv_cb, iface = self.port_map[egress])
1231
1232 t = threading.Thread(target = mac_recv_task)
1233 t.start()
1234 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1235 L3 = IP(src = random_src, dst = random_dst)
1236 pkt = L2/L3
1237 log.info('Sending packets to verify if flows are correct')
1238 sendp(pkt, count=50, iface = self.port_map[ingress])
1239 t.join()
1240 assert_equal(self.success, True)
1241
1242
1243 @nottest
1244 def test_1000k_flow_ip(self):
1245 egress = 1
1246 ingress = 2
1247 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
1248 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
1249
1250 for i in range(0,1000000):
1251 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
1252 assert_not_equal(ingress_map['ip'], None)
1253 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
1254
1255 flow = OnosFlowCtrl(deviceId = self.device_id,
1256 egressPort = egress,
1257 ingressPort = ingress,
1258 ethType = '0x0800',
1259 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
1260 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
1261 )
1262 result = flow.addFlow()
1263 assert_equal(result, True)
1264 ##wait for flows to be added to ONOS
1265 time.sleep(1)
1266 log.info("%d flow added.",i+1)
1267 self.success = False
1268 random_src = '192.0.0.' + str(random.randrange(1,254,1))
1269 random_dst = self.to_egress_ip(random_src)
1270
1271 def mac_recv_task():
1272 def recv_cb(pkt):
1273 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1274 self.success = True
1275 sniff(count=2, timeout=5,
1276 lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src,
1277 prn = recv_cb, iface = self.port_map[egress])
1278
1279 t = threading.Thread(target = mac_recv_task)
1280 t.start()
1281 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1282 L3 = IP(src = random_src, dst = random_dst)
1283 pkt = L2/L3
1284 log.info('Sending packets to verify if flows are correct')
1285 sendp(pkt, count=50, iface = self.port_map[ingress])
1286 t.join()
1287 assert_equal(self.success, True)
1288
1289
1290 def test_500_flow_tcp_port(self):
1291 egress = 1
1292 ingress = 2
1293 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 3100 }
1294 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 1100 }
1295
1296 for i in range(0,500):
1297 ingress_map['tcp_port'] += 1
1298 egress_map['tcp_port'] += 1
1299
1300 flow = OnosFlowCtrl(deviceId = self.device_id,
1301 egressPort = egress,
1302 ingressPort = ingress,
1303 tcpSrc = ingress_map['tcp_port'],
1304 tcpDst = egress_map['tcp_port']
1305 )
1306
1307 result = flow.addFlow()
1308 assert_equal(result, True)
1309 ##wait for flows to be added to ONOS
1310 time.sleep(1)
1311 log.info("%d Flow added",i+1)
1312
1313 self.success = False
1314 random_sport = random.randrange(1101,1600,1)
1315 random_dport = random_sport + 2000
1316
1317 def mac_recv_task():
1318
1319 def recv_cb(pkt):
1320 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
1321 self.success = True
1322 sniff(count=2, timeout=5,
1323 lfilter = lambda p: TCP in p and p[TCP].dport == random_dport and p[TCP].sport == random_sport
1324 ,prn = recv_cb, iface = self.port_map[egress])
1325
1326 t = threading.Thread(target = mac_recv_task)
1327 t.start()
1328 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1329 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1330 L4 = TCP(sport = random_sport, dport = random_dport)
1331 pkt = L2/L3/L4
1332 log.info('Sending packets to verify if flows are correct')
1333 sendp(pkt, count=50, iface = self.port_map[ingress])
1334 t.join()
1335 assert_equal(self.success, True)
1336
1337
1338 def test_1k_flow_tcp_port(self):
1339 egress = 1
1340 ingress = 2
1341 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 3100 }
1342 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 1100 }
1343
1344 for i in range(0,1000):
1345 ingress_map['tcp_port'] += 1
1346 egress_map['tcp_port'] += 1
1347
1348 flow = OnosFlowCtrl(deviceId = self.device_id,
1349 egressPort = egress,
1350 ingressPort = ingress,
1351 tcpSrc = ingress_map['tcp_port'],
1352 tcpDst = egress_map['tcp_port']
1353 )
1354
1355 result = flow.addFlow()
1356 assert_equal(result, True)
1357 ##wait for flows to be added to ONOS
1358 time.sleep(1)
1359 log.info("%d flow added.",i+1)
1360
1361 self.success = False
1362 random_sport = random.randrange(1101,2100,1)
1363 random_dport = random_sport + 2000
1364
1365 def mac_recv_task():
1366
1367 def recv_cb(pkt):
1368 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
1369 self.success = True
1370 sniff(count=2, timeout=5,
1371 lfilter = lambda p: TCP in p and p[TCP].dport == random_dport and p[TCP].sport == random_sport
1372 ,prn = recv_cb, iface = self.port_map[egress])
1373
1374 t = threading.Thread(target = mac_recv_task)
1375 t.start()
1376 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1377 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1378 L4 = TCP(sport = random_sport, dport = random_dport)
1379 pkt = L2/L3/L4
1380 log.info('Sending packets to verify if flows are correct')
1381 sendp(pkt, count=50, iface = self.port_map[ingress])
1382 t.join()
1383 assert_equal(self.success, True)
1384
1385 @nottest
1386 def test_10k_flow_tcp_port(self):
1387 egress = 1
1388 ingress = 2
1389 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 31000 }
1390 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 11000 }
1391
1392 for i in range(0,10000):
1393 ingress_map['tcp_port'] += 1
1394 egress_map['tcp_port'] += 1
1395
1396 flow = OnosFlowCtrl(deviceId = self.device_id,
1397 egressPort = egress,
1398 ingressPort = ingress,
1399 tcpSrc = ingress_map['tcp_port'],
1400 tcpDst = egress_map['tcp_port']
1401 )
1402
1403 result = flow.addFlow()
1404 assert_equal(result, True)
1405 ##wait for flows to be added to ONOS
1406 time.sleep(1)
1407 log.info("%d flow added.",i+1)
1408
1409 self.success = False
1410 random_sport = random.randrange(11001,21000,1)
1411 random_dport = random_sport + 20000
1412
1413 def mac_recv_task():
1414
1415 def recv_cb(pkt):
1416 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
1417 self.success = True
1418 sniff(count=2, timeout=5,
1419 lfilter = lambda p: TCP in p and p[TCP].dport == random_dport and p[TCP].sport == random_sport
1420 ,prn = recv_cb, iface = self.port_map[egress])
1421
1422 t = threading.Thread(target = mac_recv_task)
1423 t.start()
1424 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1425 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1426 L4 = TCP(sport = random_sport, dport = random_dport)
1427 pkt = L2/L3/L4
1428 log.info('Sending packets to verify if flows are correct')
1429 sendp(pkt, count=50, iface = self.port_map[ingress])
1430 t.join()
1431 assert_equal(self.success, True)
1432
1433
1434 def test_500_flow_udp_port(self):
1435 egress = 1
1436 ingress = 2
1437 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 3100 }
1438 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 1100 }
1439
1440 for i in range(0,500):
1441 ingress_map['udp_port'] += 1
1442 egress_map['udp_port'] += 1
1443
1444 flow = OnosFlowCtrl(deviceId = self.device_id,
1445 egressPort = egress,
1446 ingressPort = ingress,
1447 udpSrc = ingress_map['udp_port'],
1448 udpDst = egress_map['udp_port']
1449 )
1450
1451 result = flow.addFlow()
1452 assert_equal(result, True)
1453 ##wait for flows to be added to ONOS
1454 time.sleep(1)
1455 log.info("%d flow added.",i+1)
1456
1457 self.success = False
1458 random_sport = random.randrange(1101,1600,1)
1459 random_dport = random_sport + 2000
1460
1461 def mac_recv_task():
1462
1463 def recv_cb(pkt):
1464 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
1465 self.success = True
1466 sniff(count=2, timeout=5,
1467 lfilter = lambda p: UDP in p and p[UDP].dport == random_dport and p[UDP].sport == random_sport
1468 ,prn = recv_cb, iface = self.port_map[egress])
1469
1470 t = threading.Thread(target = mac_recv_task)
1471 t.start()
1472 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1473 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1474 L4 = UDP(sport = random_sport, dport = random_dport)
1475 pkt = L2/L3/L4
1476 log.info('Sending packets to verify if flows are correct')
1477 sendp(pkt, count=50, iface = self.port_map[ingress])
1478 t.join()
1479 assert_equal(self.success, True)
1480
1481
1482 def test_1k_flow_udp_port(self):
1483 egress = 1
1484 ingress = 2
1485 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 3100 }
1486 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 1100 }
1487
1488 for i in range(0,1000):
1489 ingress_map['udp_port'] += 1
1490 egress_map['udp_port'] += 1
1491
1492 flow = OnosFlowCtrl(deviceId = self.device_id,
1493 egressPort = egress,
1494 ingressPort = ingress,
1495 udpSrc = ingress_map['udp_port'],
1496 udpDst = egress_map['udp_port']
1497 )
1498
1499 result = flow.addFlow()
1500 assert_equal(result, True)
1501 ##wait for flows to be added to ONOS
1502 time.sleep(1)
1503 log.info("%d flow added.",i+1)
1504
1505 self.success = False
1506 random_sport = random.randrange(1101,2100,1)
1507 random_dport = random_sport + 2000
1508
1509 def mac_recv_task():
1510
1511 def recv_cb(pkt):
1512 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
1513 self.success = True
1514 sniff(count=2, timeout=5,
1515 lfilter = lambda p: UDP in p and p[UDP].dport == random_dport and p[UDP].sport == random_sport
1516 ,prn = recv_cb, iface = self.port_map[egress])
1517
1518 t = threading.Thread(target = mac_recv_task)
1519 t.start()
1520 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1521 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1522 L4 = UDP(sport = random_sport, dport = random_dport)
1523 pkt = L2/L3/L4
1524 log.info('Sending packets to verify if flows are correct')
1525 sendp(pkt, count=50, iface = self.port_map[ingress])
1526 t.join()
1527 assert_equal(self.success, True)
1528
1529 @nottest
1530 def test_10k_flow_udp_port(self):
1531 egress = 1
1532 ingress = 2
1533 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 31000 }
1534 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 11000 }
1535
1536 for i in range(0,10000):
1537 ingress_map['udp_port'] += 1
1538 egress_map['udp_port'] += 1
1539
1540 flow = OnosFlowCtrl(deviceId = self.device_id,
1541 egressPort = egress,
1542 ingressPort = ingress,
1543 udpSrc = ingress_map['udp_port'],
1544 udpDst = egress_map['udp_port']
1545 )
1546
1547 result = flow.addFlow()
1548 assert_equal(result, True)
1549 ##wait for flows to be added to ONOS
1550 time.sleep(1)
1551 log.info("%d flow added.",i+1)
1552
1553 self.success = False
1554 random_sport = random.randrange(11001,21000,1)
1555 random_dport = random_sport + 20000
1556
1557 def mac_recv_task():
1558
1559 def recv_cb(pkt):
1560 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
1561 self.success = True
1562 sniff(count=2, timeout=5,
1563 lfilter = lambda p: UDP in p and p[UDP].dport == random_dport and p[UDP].sport == random_sport
1564 ,prn = recv_cb, iface = self.port_map[egress])
1565
1566 t = threading.Thread(target = mac_recv_task)
1567 t.start()
1568 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1569 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1570 L4 = UDP(sport = random_sport, dport = random_dport)
1571 pkt = L2/L3/L4
1572 log.info('Sending packets to verify if flows are correct')
1573 sendp(pkt, count=50, iface = self.port_map[ingress])
1574 t.join()
1575 assert_equal(self.success, True)