blob: dc8bf7954306abae95a2fe359332ebc5d737c38c [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
ChetanGaonker720ea612016-06-21 17:54:25 -070024import os
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070025from OnosCtrl import OnosCtrl
A R Karthickb03cecd2016-07-27 10:27:55 -070026from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070027from OltConfig import OltConfig
A R Karthick9313b762016-11-07 13:14:35 -080028from CordLogger import CordLogger
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070029import random
30from threading import current_thread
ChetanGaonker720ea612016-06-21 17:54:25 -070031import collections
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070032log.setLevel('INFO')
33
A R Karthick9313b762016-11-07 13:14:35 -080034class flows_exchange(CordLogger):
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070035
36 #Use the first available device id as our device id to program flows
37 app = 'org.onosproject.cli'
38 PORT_TX_DEFAULT = 2
39 PORT_RX_DEFAULT = 1
40 INTF_TX_DEFAULT = 'veth2'
41 INTF_RX_DEFAULT = 'veth0'
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070042 default_port_map = {
Chetan Gaonker7ab338c2016-04-15 17:23:17 -070043 PORT_TX_DEFAULT : INTF_TX_DEFAULT,
44 PORT_RX_DEFAULT : INTF_RX_DEFAULT,
45 INTF_TX_DEFAULT : PORT_TX_DEFAULT,
46 INTF_RX_DEFAULT : PORT_RX_DEFAULT
47 }
48
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070049 def incmac(self, mac):
ChetanGaonker720ea612016-06-21 17:54:25 -070050 tmp = str(hex(int('0x'+mac,16)+1).split('x')[1])
51 mac = '0'+ tmp if len(tmp) < 2 else tmp
52 return mac
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070053
54 def next_mac(self, mac):
55 mac = mac.split(":")
56 mac[5] = self.incmac(mac[5])
57
58 if len(mac[5]) > 2:
ChetanGaonker720ea612016-06-21 17:54:25 -070059 mac[0] = self.incmac(mac[0])
60 mac[5] = '01'
61
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070062 if len(mac[0]) > 2:
ChetanGaonker720ea612016-06-21 17:54:25 -070063 mac[0] = '01'
64 mac[1] = self.incmac(mac[1])
65 mac[5] = '01'
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070066 return ':'.join(mac)
67
68 def to_egress_mac(cls, mac):
69 mac = mac.split(":")
70 mac[4] = '01'
ChetanGaonker720ea612016-06-21 17:54:25 -070071
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070072 return ':'.join(mac)
73
74 def inc_ip(self, ip, i):
ChetanGaonker720ea612016-06-21 17:54:25 -070075
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070076 ip[i] =str(int(ip[i])+1)
77 return '.'.join(ip)
78
79
80 def next_ip(self, ip):
ChetanGaonker720ea612016-06-21 17:54:25 -070081
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070082 lst = ip.split('.')
83 for i in (3,0,-1):
84 if int(lst[i]) < 255:
85 return self.inc_ip(lst, i)
86 elif int(lst[i]) == 255:
ChetanGaonker720ea612016-06-21 17:54:25 -070087 lst[i] = '0'
88 if int(lst[i-1]) < 255:
89 return self.inc_ip(lst,i-1)
90 elif int(lst[i-2]) < 255:
91 lst[i-1] = '0'
92 return self.inc_ip(lst,i-2)
93 else:
94 break
ChetanGaonkera6adc0b2016-06-12 12:21:14 -070095
96 def to_egress_ip(self, ip):
97 lst=ip.split('.')
98 lst[0] = '182'
99 return '.'.join(lst)
100
ChetanGaonker720ea612016-06-21 17:54:25 -0700101
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700102 @classmethod
103 def setUpClass(cls):
104 cls.olt = OltConfig()
A R Karthickb03cecd2016-07-27 10:27:55 -0700105 cls.port_map, _ = cls.olt.olt_port_map()
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700106 if not cls.port_map:
107 cls.port_map = cls.default_port_map
A R Karthickb03cecd2016-07-27 10:27:55 -0700108 cls.device_id = OnosCtrl.get_device_id()
A R Karthicke4660f52017-02-23 12:08:41 -0800109 num_ports = len(cls.port_map['ports'] + cls.port_map['relay_ports'])
110 cls.port_offset = int(os.getenv('TEST_INSTANCE', 0)) * num_ports
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700111
112 def test_flow_mac(self):
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700113 '''Test Add and verify flows with MAC selectors'''
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700114 egress = 1
115 ingress = 2
116 egress_mac = '00:00:00:00:00:01'
117 ingress_mac = '00:00:00:00:00:02'
ChetanGaonker720ea612016-06-21 17:54:25 -0700118
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700119 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800120 egressPort = egress + self.port_offset,
121 ingressPort = ingress + self.port_offset,
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700122 ethSrc = ingress_mac,
123 ethDst = egress_mac)
124 result = flow.addFlow()
125 assert_equal(result, True)
126 ##wait for flows to be added to ONOS
ChetanGaonker720ea612016-06-21 17:54:25 -0700127 time.sleep(1)
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700128 self.success = False
129 def mac_recv_task():
130 def recv_cb(pkt):
131 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
132 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700133 sniff(count=2, timeout=5, lfilter = lambda p: p.src == ingress_mac,
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700134 prn = recv_cb, iface = self.port_map[egress])
135
136 t = threading.Thread(target = mac_recv_task)
137 t.start()
138 pkt = Ether(src = ingress_mac, dst = egress_mac)/IP()
139 log.info('Sending a packet to verify if flows are correct')
140 sendp(pkt, count=50, iface = self.port_map[ingress])
141 t.join()
142 assert_equal(self.success, True)
143
144 def test_flow_ip(self):
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700145 '''Test Add and verify flows with IPv4 selectors'''
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700146 egress = 1
147 ingress = 2
148 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
149 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
150 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800151 egressPort = egress + self.port_offset,
152 ingressPort = ingress + self.port_offset,
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700153 ethType = '0x0800',
154 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
155 ipDst = ('IPV4_DST', egress_map['ip']+'/32')
156 )
157 result = flow.addFlow()
158 assert_equal(result, True)
159 ##wait for flows to be added to ONOS
ChetanGaonker720ea612016-06-21 17:54:25 -0700160 time.sleep(1)
Chetan Gaonker7ab338c2016-04-15 17:23:17 -0700161 self.success = False
162 def mac_recv_task():
163 def recv_cb(pkt):
164 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
165 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700166 sniff(count=2, timeout=5,
Chetan Gaonker3533faa2016-04-25 17:50:14 -0700167 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 -0700168 prn = recv_cb, iface = self.port_map[egress])
169
170 t = threading.Thread(target = mac_recv_task)
171 t.start()
172 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
173 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
174 pkt = L2/L3
175 log.info('Sending a packet to verify if flows are correct')
176 sendp(pkt, count=50, iface = self.port_map[ingress])
177 t.join()
178 assert_equal(self.success, True)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700179
180
181 def test_flow_tcp_port(self):
182 egress = 1
183 ingress = 2
184 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 9500 }
185 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 9000 }
186 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800187 egressPort = egress + self.port_offset,
188 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700189 tcpSrc = ingress_map['tcp_port'],
190 tcpDst = egress_map['tcp_port']
191 )
192 result = flow.addFlow()
193 assert_equal(result, True)
194 ##wait for flows to be added to ONOS
ChetanGaonker720ea612016-06-21 17:54:25 -0700195 time.sleep(1)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700196 self.success = False
197 def mac_recv_task():
198 def recv_cb(pkt):
199 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
200 self.success = True
ChetanGaonker720ea612016-06-21 17:54:25 -0700201 sniff(count=2, timeout=5, lfilter = lambda p: TCP in p and p[TCP].dport == egress_map['tcp_port']
202 and p[TCP].sport == ingress_map['tcp_port'], prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700203
204 t = threading.Thread(target = mac_recv_task)
205 t.start()
206 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
207 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
208 L4 = TCP(sport = ingress_map['tcp_port'], dport = egress_map['tcp_port'])
209 pkt = L2/L3/L4
210 log.info('Sending packets to verify if flows are correct')
211 sendp(pkt, count=50, iface = self.port_map[ingress])
212 t.join()
213 assert_equal(self.success, True)
214
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700215 def test_flow_udp_port(self):
216 egress = 1
217 ingress = 2
218 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 9500 }
219 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 9000 }
220 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800221 egressPort = egress + self.port_offset,
222 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700223 udpSrc = ingress_map['udp_port'],
224 udpDst = egress_map['udp_port']
225 )
226 result = flow.addFlow()
227 assert_equal(result, True)
228 ##wait for flows to be added to ONOS
ChetanGaonker720ea612016-06-21 17:54:25 -0700229 time.sleep(1)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700230 self.success = False
231 def mac_recv_task():
232 def recv_cb(pkt):
233 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
234 self.success = True
235 sniff(count=2, timeout=5,
ChetanGaonker720ea612016-06-21 17:54:25 -0700236 lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port']
237 and p[UDP].sport == ingress_map['udp_port'], prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -0700238
239 t = threading.Thread(target = mac_recv_task)
240 t.start()
241 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
242 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
243 L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port'])
244 pkt = L2/L3/L4
245 log.info('Sending packets to verify if flows are correct')
246 sendp(pkt, count=50, iface = self.port_map[ingress])
247 t.join()
248 assert_equal(self.success, True)
249
ChetanGaonker720ea612016-06-21 17:54:25 -0700250 @nottest
251 def test_flow_vlan(self):
252 egress = 1
253 ingress = 2
254 egress_mac = '00:00:00:00:00:01'
255 ingress_mac = '00:00:00:00:00:02'
256 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800257 egressPort = egress + self.port_offset,
258 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700259 ethSrc = ingress_mac,
260 ethDst = egress_mac,
261 vlan = 0x10)
262 result = flow.addFlow()
263 assert_equal(result, True)
264 ##wait for flows to be added to ONOS
265 time.sleep(1)
266 self.success = False
267 def mac_recv_task():
268 def recv_cb(pkt):
269 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
270 log.info('Pkt:%s', pkt.show())
271 self.success = True
272 sniff(count=2, timeout=5, lfilter = lambda p:p.src == ingress_mac,
273 prn = recv_cb, iface = self.port_map[egress])
274
275 t = threading.Thread(target = mac_recv_task)
276 t.start()
277 pkt = Ether(src = ingress_mac, dst = egress_mac)/Dot1Q(vlan = 0x10)/IP()
278 log.info("Sending Packet:%s",pkt.show())
279 log.info('Sending a packet to verify if flows are correct')
280 sendp(pkt, count=50, iface = self.port_map[ingress])
281 t.join()
282 assert_equal(self.success, True)
283
284 def test_flow_ipv6(self):
285 egress = 1
286 ingress = 2
287 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
288 ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
289 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800290 egressPort = egress + self.port_offset,
291 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700292 ethType = '0x86dd',
293 ipSrc = ('IPV6_SRC', ingress_map['ipv6'] + '/48'),
294 ipDst = ('IPV6_DST', egress_map['ipv6'] + '/48')
295 )
296
297 result = flow.addFlow()
298 assert_equal(result, True)
299 ##wait for flows to be added to ONOS
300 time.sleep(1)
301 self.success = False
302 def mac_recv_task():
303 def recv_cb(pkt):
304 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IPv6].src, pkt[IPv6].dst))
305 self.success = True
306 sniff(count=2, timeout=5,
307 lfilter = lambda p: IPv6 in p and p[IPv6].dst == egress_map['ipv6'] and p[IPv6].src == ingress_map['ipv6'],
308 prn = recv_cb, iface = self.port_map[egress])
309
310 t = threading.Thread(target = mac_recv_task)
311 t.start()
312 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
313 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'])
314 pkt = L2/L3
315 log.info('Sending a packet to verify if flows are correct')
316 sendp(pkt, count=50, iface = self.port_map[ingress])
317 t.join()
318 assert_equal(self.success, True)
319
320 def test_flow_ipv6_flow_label(self):
321 egress = 1
322 ingress = 2
323 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
324 ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
325 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800326 egressPort = egress + self.port_offset,
327 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700328 ipv6flow_label = 25
329 )
330
331 result = flow.addFlow()
332 assert_equal(result, True)
333 ##wait for flows to be added to ONOS
334 time.sleep(1)
335 self.success = False
336 def mac_recv_task():
337 def recv_cb(pkt):
338 log.info('Pkt seen with ingress ip %s, egress ip %s with flow label %s' %(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].fl))
339 self.success = True
340 sniff(count=2, timeout=5, lfilter = lambda p: IPv6 in p and p[IPv6].dst == egress_map['ipv6']
341 and p[IPv6].src == ingress_map['ipv6'] and p[IPv6].fl == 25, prn = recv_cb, iface = self.port_map[egress])
342
343 t = threading.Thread(target = mac_recv_task)
344 t.start()
345 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
346 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], fl = 25)
347 pkt = L2/L3
348 log.info('Sending a packet to verify if flows are correct')
349 sendp(pkt, count=50, iface = self.port_map[ingress])
350 t.join()
351 assert_equal(self.success, True)
352
353 def test_flow_ipv6_extension_header(self):
354 egress = 1
355 ingress = 2
356 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
357 ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
358 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800359 egressPort = egress + self.port_offset,
360 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700361 ipv6_extension = 0,
362 )
363
364 result = flow.addFlow()
365 assert_equal(result, True)
366 ##wait for flows to be added to ONOS
367 time.sleep(1)
368 self.success = False
369 def mac_recv_task():
370 def recv_cb(pkt):
371 log.info('Pkt seen with ingress ip %s, egress ip %s, Extension Header Type %s' %(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].nh))
372 self.success = True
373 sniff(count=2, timeout=5,
374 lfilter = lambda p: IPv6 in p and p[IPv6].nh == 0, prn = recv_cb, iface = self.port_map[egress])
375
376 t = threading.Thread(target = mac_recv_task)
377 t.start()
378 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
379 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], nh = 0)
380 pkt = L2/L3
381 log.info('Sending packets to verify if flows are correct')
382 sendp(pkt, count=50, iface = self.port_map[ingress])
383 t.join()
384 assert_equal(self.success, True)
385
386 def test_flow_ipv6_available_extension_headers(self):
387 egress = 1
388 ingress = 2
389 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
390 ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
391 for i in [0, 60, 43, 44, 51, 50, 135]:
392 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800393 egressPort = egress + self.port_offset,
394 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700395 ipv6_extension = i,
396 )
397
398 result = flow.addFlow()
399 assert_equal(result, True)
400 ##wait for flows to be added to ONOS
401 time.sleep(1)
402 def mac_recv_task():
403 def recv_cb(pkt):
404 log.info('Pkt seen with ingress ip %s, egress ip %s, Extension Header Type %s' %(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].nh))
405 self.success = True
406 sniff(count=2, timeout=5, lfilter = lambda p: IPv6 in p and p[IPv6].nh == i,
407 prn = recv_cb, iface = self.port_map[egress])
408
409 for i in [0, 60, 43, 44, 51, 50, 135]:
410 self.success = False
411 t = threading.Thread(target = mac_recv_task)
412 t.start()
413 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
414 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], nh = i)
415 pkt = L2/L3
416 log.info('Sending packets to verify if flows are correct')
417 sendp(pkt, count=50, iface = self.port_map[ingress])
418 t.join()
419 assert_equal(self.success, True)
420
421
422 def test_flow_dscp(self):
423 egress = 1
424 ingress = 2
425 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
426 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
427 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800428 egressPort = egress + self.port_offset,
429 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700430 dscp = 32
431 )
432 result = flow.addFlow()
433 assert_equal(result, True)
434 ##wait for flows to be added to ONOS
435 time.sleep(1)
436 self.success = False
437 def mac_recv_task():
438 def recv_cb(pkt):
439 log.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
440 self.success = True
441 sniff(count=2, timeout=5,
442 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip']
443 and p[IP].tos == 32,prn = recv_cb, iface = self.port_map[egress])
444
445 t = threading.Thread(target = mac_recv_task)
446 t.start()
447 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
448 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = 32)
449 pkt = L2/L3
450 log.info('Sending a packet to verify if flows are correct')
451 sendp(pkt, count=50, iface = self.port_map[ingress])
452 t.join()
453 assert_equal(self.success, True)
454
455 def test_flow_available_dscp(self):
456 egress = 1
457 ingress = 2
458 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
459 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
460 dscp = [184, 0, 40, 48, 56, 72, 80, 88, 104, 112, 120, 136, 144, 152, 32, 64, 96, 128, 160, 192, 224]
461 for i in dscp:
462 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800463 egressPort = egress + self.port_offset,
464 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700465 dscp = i
466 )
467 result = flow.addFlow()
468 assert_equal(result, True)
469 ##wait for flows to be added to ONOS
470 time.sleep(1)
471
472 def mac_recv_task():
473 def recv_cb(pkt):
474 log.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
475 self.success = True
476 sniff(count=2, timeout=5,
477 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip']
478 and p[IP].tos == i,prn = recv_cb, iface = self.port_map[egress])
479
480 for i in dscp:
481 self.success = False
482 t = threading.Thread(target = mac_recv_task)
483 t.start()
484 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
485 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = i)
486 pkt = L2/L3
487 log.info('Sending a packet to verify if flows are correct')
488 sendp(pkt, count=50, iface = self.port_map[ingress])
489 t.join()
490 assert_equal(self.success, True)
491
492 def test_flow_ecn(self):
493 egress = 1
494 ingress = 2
495 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
496 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
497 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800498 egressPort = egress + self.port_offset,
499 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700500 ecn = 1
501 )
502 result = flow.addFlow()
503 assert_equal(result, True)
504 ##wait for flows to be added to ONOS
505 time.sleep(1)
506 self.success = False
507 def mac_recv_task():
508 def recv_cb(pkt):
509 log.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
510 self.success = True
511 sniff(count=2, timeout=5,
512 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip']
513 and int(bin(p[IP].tos).split('b')[1][-2:],2) == 1,prn = recv_cb,
514 iface = self.port_map[egress])
515
516 t = threading.Thread(target = mac_recv_task)
517 t.start()
518 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
519 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = 1)
520 pkt = L2/L3
521 log.info('Sending a packet to verify if flows are correct')
522 sendp(pkt, count=50, iface = self.port_map[ingress])
523 t.join()
524 assert_equal(self.success, True)
525
526
527 def test_flow_available_ecn(self):
528 egress = 1
529 ingress = 2
530 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
531 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
532 for i in range(4):
533 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800534 egressPort = egress + self.port_offset,
535 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700536 ecn = i
537 )
538 result = flow.addFlow()
539 assert_equal(result, True)
540 ##wait for flows to be added to ONOS
541 time.sleep(1)
542 def mac_recv_task():
543 def recv_cb(pkt):
544 log.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
545 self.success = True
546 sniff(count=2, timeout=5,
547 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip']
548 and int(bin(p[IP].tos).split('b')[1][-2:],2) == i,prn = recv_cb,
549 iface = self.port_map[egress])
550
551 for i in range(4):
552 self.success = False
553 t = threading.Thread(target = mac_recv_task)
554 t.start()
555 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
556 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = i)
557 pkt = L2/L3
558 log.info('Sending a packet to verify if flows are correct')
559 sendp(pkt, count=50, iface = self.port_map[ingress])
560 t.join()
561 assert_equal(self.success, True)
562
563 def test_flow_available_dscp_and_ecn(self):
564 egress = 1
565 ingress = 2
566 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
567 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
568 dscp = [46, 0, 10, 12, 14, 18, 20, 22, 26, 28, 30, 34, 36, 38, 8, 16, 24, 32, 40, 48, 56]
569 for i in dscp:
570 for j in (0,1,2,3):
571 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800572 egressPort = egress + self.port_offset,
573 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700574 dscp = i,
575 ecn = j
576 )
577 result = flow.addFlow()
578 assert_equal(result, True)
579 ##wait for flows to be added to ONOS
580 time.sleep(1)
581
582 def mac_recv_task():
583 def recv_cb(pkt):
584 log.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
585 self.success = True
586 sniff(count=2, timeout=5,
587 lfilter = lambda p: IP in p and p[IP].tos == int(bin(i).split('b')[1]+ bin(j).split('b')[1],2)
588 ,prn = recv_cb, iface = self.port_map[egress])
589
590 for i in dscp:
591 for j in (0,1,2,3):
592
593 self.success = False
594 t = threading.Thread(target = mac_recv_task)
595 t.start()
596 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
597 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = int(bin(i).split('b')[1]+ bin(j).split('b')[1],2))
598 pkt = L2/L3
599 log.info('Sending packets to verify if flows are correct')
600 sendp(pkt, count=50, iface = self.port_map[ingress])
601 t.join()
602 assert_equal(self.success, True)
603
604 def test_flow_icmp(self):
605 egress = 1
606 ingress = 2
607 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
608 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
609 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800610 egressPort = egress + self.port_offset,
611 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700612 icmpv4_type = '3',
613 icmpv4_code = 8
614 )
615 result = flow.addFlow()
616 assert_equal(result, True)
617 ##wait for flows to be added to ONOS
618 time.sleep(1)
619 self.success = False
620
621 def mac_recv_task():
622 def recv_cb(pkt):
623 log.info('Pkt seen with ICMP type %s, ICMP code %s' %(pkt[ICMP].type, pkt[ICMP].code))
624 self.success = True
625 sniff(count=2, timeout=5,
626 lfilter = lambda p: ICMP in p and p[ICMP].type == 3 and p[ICMP].code == 8,
627 prn = recv_cb, iface = self.port_map[egress])
628
629 t = threading.Thread(target = mac_recv_task)
630 t.start()
631 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
632 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])/ICMP(type = 3, code = 8)
633 pkt = L2/L3
634 log.info('Sending a packet to verify if flows are correct')
635 sendp(pkt, count=50, iface = self.port_map[ingress])
636 t.join()
637 assert_equal(self.success, True)
638
639 def test_flow_icmp_different_types(self):
640 egress = 1
641 ingress = 2
642 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
643 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
644 icmp = {'11': [0, 1], '10': 0, '0': 0, '3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
645 '5': [1, 2, 3], '4': 0, '9': 0, '8': 0}
646 for type,code in icmp.items():
647 if isinstance(code, list):
648 for i in code:
649 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800650 egressPort = egress + self.port_offset,
651 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700652 icmpv4_type = type,
653 icmpv4_code = i
654 )
655 result = flow.addFlow()
656 assert_equal(result, True)
657 ##wait for flows to be added to ONOS
658 time.sleep(1)
659 else:
660 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800661 egressPort = egress + self.port_offset,
662 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700663 icmpv4_type = type,
664 icmpv4_code = code
665 )
666 result = flow.addFlow()
667 assert_equal(result, True)
668 ##wait for flows to be added to ONOS
669 time.sleep(1)
670 self.success = False
671
672 def mac_recv_task():
673 def recv_cb(pkt):
674 log.info('Pkt seen with ICMP type %s, ICMP code %s' %(pkt[ICMP].type, pkt[ICMP].code))
675 self.success = True
676 sniff(count=2, timeout=5,
677 lfilter = lambda p: ICMP in p and p[ICMP].type == 3 and p[ICMP].code == 8,
678 prn = recv_cb, iface = self.port_map[egress])
679
680 t = threading.Thread(target = mac_recv_task)
681 t.start()
682 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
683 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])/ICMP(type = 3, code = 8)
684 pkt = L2/L3
685 log.info('Sending a packet to verify if flows are correct')
686 sendp(pkt, count=50, iface = self.port_map[ingress])
687 t.join()
688 assert_equal(self.success, True)
689
690 def test_flow_icmpv6_EchoRequest(self):
691 egress = 1
692 ingress = 2
693 egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
694 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'}
695 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800696 egressPort = egress + self.port_offset,
697 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700698 icmpv6_type = '128',
699 icmpv6_code = 0
700 )
701 result = flow.addFlow()
702 assert_equal(result, True)
703 ##wait for flows to be added to ONOS
704 time.sleep(1)
705 self.success = False
706 def mac_recv_task():
707 def recv_cb(pkt):
708 log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6EchoRequest].type, pkt[ICMPv6EchoRequest].code))
709 self.success = True
710 sniff(count=2, timeout=5,
711 lfilter = lambda p: ICMPv6EchoRequest in p and p[ICMPv6EchoRequest].type == 128 and p[ICMPv6EchoRequest].code == 0,
712 prn = recv_cb, iface = self.port_map[egress])
713
714 t = threading.Thread(target = mac_recv_task)
715 t.start()
716 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
717 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6EchoRequest()
718 pkt = L2/L3
719 log.info('Sending a packet to verify if flows are correct')
720 sendp(pkt, count=50, iface = self.port_map[ingress])
721 t.join()
722 assert_equal(self.success, True)
723
724 def test_flow_icmpv6_EchoReply(self):
725 egress = 1
726 ingress = 2
727 egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
728 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
729 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800730 egressPort = egress + self.port_offset,
731 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700732 icmpv6_type = '129',
733 icmpv6_code = 0
734 )
735 result = flow.addFlow()
736 assert_equal(result, True)
737 ##wait for flows to be added to ONOS
738 time.sleep(1)
739 self.success = False
740 def mac_recv_task():
741 def recv_cb(pkt):
742 log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6EchoReply].type, pkt[ICMPv6EchoReply].code))
743 self.success = True
744 sniff(count=2, timeout=5,
745 lfilter = lambda p: ICMPv6EchoReply in p and p[ICMPv6EchoReply].type == 129 and p[ICMPv6EchoReply].code == 0,
746 prn = recv_cb, iface = self.port_map[egress])
747
748 t = threading.Thread(target = mac_recv_task)
749 t.start()
750 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
751 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6EchoReply()
752 pkt = L2/L3
753 log.info('Sending packets to verify if flows are correct')
754 sendp(pkt, count=50, iface = self.port_map[ingress])
755 t.join()
756 assert_equal(self.success, True)
757
758
759 def test_flow_icmpv6_DestUnreachable(self):
760 egress = 1
761 ingress = 2
762 egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
763 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
764 for i in range(8):
765 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800766 egressPort = egress + self.port_offset,
767 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700768 icmpv6_type = '1',
769 icmpv6_code = i
770 )
771 result = flow.addFlow()
772 assert_equal(result, True)
773 ##wait for flows to be added to ONOS
774 time.sleep(1)
775 for i in range(8):
776 self.success = False
777 def mac_recv_task():
778 def recv_cb(pkt):
779 log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6DestUnreach].type, pkt[ICMPv6DestUnreach].code))
780 self.success = True
781 sniff(count=2, timeout=5,
782 lfilter = lambda p: ICMPv6DestUnreach in p and p[ICMPv6DestUnreach].type == 1 and p[ICMPv6DestUnreach].code == i,
783 prn = recv_cb, iface = self.port_map[egress])
784
785 t = threading.Thread(target = mac_recv_task)
786 t.start()
787 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
788 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6DestUnreach(code = i)
789 pkt = L2/L3
790 log.info('Sending packets to verify if flows are correct')
791 sendp(pkt, count=50, iface = self.port_map[ingress])
792 t.join()
793 assert_equal(self.success, True)
794
795 def test_flow_icmpv6_PacketTooBig(self):
796 egress = 1
797 ingress = 2
798 egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
799 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
800 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800801 egressPort = egress + self.port_offset,
802 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700803 icmpv6_type = '2',
804 icmpv6_code = 0
805 )
806 result = flow.addFlow()
807 assert_equal(result, True)
808 ##wait for flows to be added to ONOS
809 time.sleep(1)
810 self.success = False
811 def mac_recv_task():
812 def recv_cb(pkt):
813 log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6PacketTooBig].type, pkt[ICMPv6PacketTooBig].code))
814 self.success = True
815 sniff(count=2, timeout=5,
816 lfilter = lambda p: ICMPv6PacketTooBig in p and p[ICMPv6PacketTooBig].type == 2 and p[ICMPv6PacketTooBig].code == 0,
817 prn = recv_cb, iface = self.port_map[egress])
818
819 t = threading.Thread(target = mac_recv_task)
820 t.start()
821 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
822 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6PacketTooBig()
823 pkt = L2/L3
824 log.info('Sending packets to verify if flows are correct')
825 sendp(pkt, count=50, iface = self.port_map[ingress])
826 t.join()
827 assert_equal(self.success, True)
828
829 def test_flow_icmpv6_TimeExceeded(self):
830 egress = 1
831 ingress = 2
832 egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
833 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
834 for i in range(2):
835 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800836 egressPort = egress + self.port_offset,
837 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700838 icmpv6_type = '3',
839 icmpv6_code = i
840 )
841 result = flow.addFlow()
842 assert_equal(result, True)
843 ##wait for flows to be added to ONOS
844 time.sleep(1)
845 for i in range(2):
846 self.success = False
847 def mac_recv_task():
848 def recv_cb(pkt):
849 log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6TimeExceeded].type, pkt[ICMPv6TimeExceeded].code))
850 self.success = True
851 sniff(count=2, timeout=5,
852 lfilter = lambda p: ICMPv6TimeExceeded in p and p[ICMPv6TimeExceeded].type == 3 and p[ICMPv6TimeExceeded].code == i,
853 prn = recv_cb, iface = self.port_map[egress])
854
855 t = threading.Thread(target = mac_recv_task)
856 t.start()
857 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
858 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6TimeExceeded(code = i)
859 pkt = L2/L3
860 log.info('Sending packets to verify if flows are correct')
861 sendp(pkt, count=50, iface = self.port_map[ingress])
862 t.join()
863 assert_equal(self.success, True)
864
865 def test_flow_icmpv6_ParameterProblem(self):
866 egress = 1
867 ingress = 2
868 egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
869 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
870 for i in range(3):
871 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800872 egressPort = egress + self.port_offset,
873 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700874 icmpv6_type = '4',
875 icmpv6_code = i
876 )
877 result = flow.addFlow()
878 assert_equal(result, True)
879 ##wait for flows to be added to ONOS
880 time.sleep(1)
881 for i in range(3):
882 self.success = False
883 def mac_recv_task():
884 def recv_cb(pkt):
885 log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6ParamProblem].type, pkt[ICMPv6ParamProblem].code))
886 self.success = True
887 sniff(count=2, timeout=5,
888 lfilter = lambda p: ICMPv6ParamProblem in p and p[ICMPv6ParamProblem].type == 4 and p[ICMPv6ParamProblem].code == i,
889 prn = recv_cb, iface = self.port_map[egress])
890
891 t = threading.Thread(target = mac_recv_task)
892 t.start()
893 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
894 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6ParamProblem(code = i)
895 pkt = L2/L3
896 log.info('Sending packets to verify if flows are correct')
897 sendp(pkt, count=50, iface = self.port_map[ingress])
898 t.join()
899 assert_equal(self.success, True)
900
901 def test_flow_icmpv6_ND_Target_address(self):
902 egress = 1
903 ingress = 2
904 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'}
905 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800906 egressPort = egress + self.port_offset,
907 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700908 ipv6_target = '2001:db8:a0b:12f0:1010:1010:1010:1001')
909 result = flow.addFlow()
910 assert_equal(result, True)
911 ##wait for flows to be added to ONOS
912 time.sleep(1)
913 self.success = False
914 def mac_recv_task():
915 def recv_cb(pkt):
916 log.info('Pkt seen with ICMPv6 Neighbor Discovery type %s, target address %s' %(pkt[ICMPv6ND_NS].type, pkt[ICMPv6ND_NS].tgt))
917 self.success = True
918 sniff(count=2, timeout=5,
919 lfilter = lambda p: ICMPv6ND_NS in p and p[ICMPv6ND_NS].tgt == '2001:db8:a0b:12f0:1010:1010:1010:1001',
920 prn = recv_cb, iface = self.port_map[egress])
921
922 t = threading.Thread(target = mac_recv_task)
923 t.start()
924 L2 = Ether(src = ingress_map['ether'])
925 L3 = IPv6(src = ingress_map['ipv6'])/ICMPv6ND_NS(tgt = '2001:db8:a0b:12f0:1010:1010:1010:1001')
926 pkt = L2/L3
927 log.info('Sending packets to verify if flows are correct')
928 sendp(pkt, count=50, iface = self.port_map[ingress])
929 t.join()
930 assert_equal(self.success, True)
931
932 def test_flow_icmpv6_ND_SLL(self):
933 egress = 1
934 ingress = 2
935 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
936 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'}
937 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800938 egressPort = egress + self.port_offset,
939 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700940 ipv6_sll = ingress_map['ether'])
941 result = flow.addFlow()
942 assert_equal(result, True)
943 ##wait for flows to be added to ONOS
944 time.sleep(1)
945 self.success = False
946 def mac_recv_task():
947 def recv_cb(pkt):
948 log.info('Pkt seen with ICMPv6 Neighbor Discovery type %s, Source Link Layer address %s' %(pkt[ICMPv6ND_NS].type, pkt[ICMPv6NDOptSrcLLAddr].lladdr))
949 self.success = True
950 sniff(count=2, timeout=5,
951 lfilter = lambda p: ICMPv6NDOptSrcLLAddr in p and p[ICMPv6NDOptSrcLLAddr].lladdr == ingress_map['ether'],
952 prn = recv_cb, iface = self.port_map[egress])
953
954 t = threading.Thread(target = mac_recv_task)
955 t.start()
956 L2 = Ether(src = ingress_map['ether'])#, dst = ingress_map['ether'])
957 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6ND_NS(tgt = egress_map['ipv6'])/ICMPv6NDOptSrcLLAddr(lladdr = ingress_map['ether'])
958 pkt = L2/L3
959 log.info('Sending packets to verify if flows are correct')
960 sendp(pkt, count=50, iface = self.port_map[ingress])
961 t.join()
962 assert_equal(self.success, True)
963
964 def test_flow_icmpv6_NA_TLL(self):
965 egress = 1
966 ingress = 2
967 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'}
968 ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'}
969 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -0800970 egressPort = egress + self.port_offset,
971 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -0700972 ipv6_tll = egress_map['ether'])
973 result = flow.addFlow()
974 assert_equal(result, True)
975 ##wait for flows to be added to ONOS
976 time.sleep(1)
977 self.success = False
978 def mac_recv_task():
979 def recv_cb(pkt):
980 log.info('Pkt seen with ICMPv6 Neighbor Advertisement type %s, Target Link Layer address %s' %(pkt[ICMPv6ND_NA].type, pkt[ICMPv6NDOptDstLLAddr].lladdr))
981 self.success = True
982 sniff(count=2, timeout=5,
983 lfilter = lambda p: ICMPv6NDOptDstLLAddr in p and p[ICMPv6NDOptDstLLAddr].lladdr == ingress_map['ether'],
984 prn = recv_cb, iface = self.port_map[egress])
985
986 t = threading.Thread(target = mac_recv_task)
987 t.start()
988 L2 = Ether(src = ingress_map['ether'])#, dst = ingress_map['ether'])
989 L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6ND_NA(tgt = ingress_map['ipv6'])/ICMPv6NDOptDstLLAddr(lladdr = ingress_map['ether'])
990 pkt = L2/L3
991 log.info('Sending packets to verify if flows are correct')
992 sendp(pkt, count=50, iface = self.port_map[ingress])
993 t.join()
994 assert_equal(self.success, True)
995
996 def test_flow_ipv6_and_icmpv6(self):
997 egress = 1
998 ingress = 2
999 egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
1000 ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
1001 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001002 egressPort = egress + self.port_offset,
1003 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -07001004 ethType = '0x86dd',
1005 ipSrc = ('IPV6_SRC', ingress_map['ipv6'] + '/48'),
1006 ipDst = ('IPV6_DST', egress_map['ipv6'] + '/48'),
1007 icmpv6_type = '128',
1008 icmpv6_code = 0
1009 )
1010
1011 result = flow.addFlow()
1012 assert_equal(result, True)
1013 ##wait for flows to be added to ONOS
1014 time.sleep(1)
1015 self.success = False
1016
1017 def mac_recv_task():
1018 def recv_cb(pkt):
1019 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IPv6].src, pkt[IPv6].dst))
1020 self.success = True
1021 sniff(count=2, timeout=5,
1022 lfilter = lambda p: IPv6 in p and p[IPv6].dst == egress_map['ipv6'] and p[IPv6].src == ingress_map['ipv6']
1023 and p[ICMPv6EchoRequest].type == 128 and p[ICMPv6EchoRequest].code == 0, prn = recv_cb, iface = self.port_map[egress])
1024
1025 t = threading.Thread(target = mac_recv_task)
1026 t.start()
1027 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1028 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'])/ICMPv6EchoRequest()
1029 pkt = L2/L3
1030 log.info('Sending a packet to verify if flows are correct')
1031 sendp(pkt, count=50, iface = self.port_map[ingress])
1032 t.join()
1033 assert_equal(self.success, True)
1034
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001035 def test_5_flow_constant_dst_mac(self):
1036 egress = 1
1037 ingress = 2
1038 egress_mac = '00:00:00:00:01:01'
1039 ingress_mac = '00:00:00:00:00:00'
1040
ChetanGaonker720ea612016-06-21 17:54:25 -07001041
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001042 for i in range(0,5):
1043 ingress_mac = self.next_mac(ingress_mac)
1044
1045 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001046 egressPort = egress + self.port_offset,
1047 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001048 ethSrc = ingress_mac,
1049 ethDst = egress_mac)
1050 result = flow.addFlow()
1051 assert_equal(result, True)
1052 ##wait for flows to be added to ONOS
1053 time.sleep(1)
1054 log.info("%d flow added.",i+1)
1055 self.success = False
1056
1057 def mac_recv_task():
1058 def recv_cb(pkt):
1059 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1060 self.success = True
1061 sniff(count=2, timeout=5, lfilter = lambda p: p.src == '00:00:00:00:00:02',
ChetanGaonker720ea612016-06-21 17:54:25 -07001062 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001063
1064 t = threading.Thread(target = mac_recv_task)
1065 t.start()
1066 pkt = Ether(src = '00:00:00:00:00:02', dst = egress_mac)/IP()
1067 log.info('Sending packets to verify if flows are correct')
1068 sendp(pkt, count=50, iface = self.port_map[ingress])
1069 t.join()
1070 assert_equal(self.success, True)
1071
1072
1073 def test_500_flow_constant_dst_mac(self):
1074 egress = 1
1075 ingress = 2
1076 egress_mac = '00:00:00:00:01:01'
1077 ingress_mac = '00:00:00:00:00:00'
1078 success_dir = {}
1079
1080 for i in range(0,500):
1081 ingress_mac = self.next_mac(ingress_mac)
1082
1083 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001084 egressPort = egress + self.port_offset,
1085 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001086 ethSrc = ingress_mac,
1087 ethDst = egress_mac)
1088 result = flow.addFlow()
1089 assert_equal(result, True)
1090 ##wait for flows to be added to ONOS
1091 time.sleep(1)
1092 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07001093 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001094
1095 def verify_flow(*r):
1096 random_src = ''.join(r)
1097 def mac_recv_task():
1098 def recv_cb(pkt):
1099 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1100 success_dir[current_thread().name] = True
1101 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001102 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001103
ChetanGaonker720ea612016-06-21 17:54:25 -07001104 t = threading.Thread(target = mac_recv_task)
1105 t.start()
1106 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1107 log.info('Sending packets to verify if flows are correct')
1108 sendp(pkt, count=50, iface = self.port_map[ingress])
1109 t.join()
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001110
1111 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1112 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
1113 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,100)).split('x')[1])
1114 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(101,240)).split('x')[1])
1115 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:f5')
1116 t1.start()
1117 t2.start()
1118 t3.start()
1119 t4.start()
1120 t5.start()
ChetanGaonker720ea612016-06-21 17:54:25 -07001121
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001122 t1.join()
1123 t2.join()
1124 t3.join()
1125 t4.join()
1126 t5.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001127
1128 if len(success_dir) != 5:
1129 self.success = False
1130
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001131 assert_equal(self.success, True)
1132
ChetanGaonker720ea612016-06-21 17:54:25 -07001133
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001134 def test_1k_flow_constant_dst_mac(self):
1135 egress = 1
1136 ingress = 2
1137 egress_mac = '00:00:00:00:01:01'
1138 ingress_mac = '00:00:00:00:00:00'
1139 success_dir = {}
1140
1141 for i in range(0,1000):
1142 ingress_mac = self.next_mac(ingress_mac)
ChetanGaonker720ea612016-06-21 17:54:25 -07001143
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001144 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001145 egressPort = egress + self.port_offset,
1146 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001147 ethSrc = ingress_mac,
1148 ethDst = egress_mac)
1149 result = flow.addFlow()
1150 assert_equal(result, True)
1151 ##wait for flows to be added to ONOS
1152 time.sleep(1)
1153 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07001154 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001155
1156 def verify_flow(*r):
1157 random_src = ''.join(r)
1158 def mac_recv_task():
1159 def recv_cb(pkt):
1160 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1161 success_dir[current_thread().name] = True
1162 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001163 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001164
1165 t = threading.Thread(target = mac_recv_task)
1166 t.start()
1167 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1168 log.info('Sending packets to verify if flows are correct')
1169 sendp(pkt, count=50, iface = self.port_map[ingress])
1170 t.join()
1171
1172 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1173 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
1174 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:09')
1175 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
1176 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
1177 t6 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:08')
1178 t7 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
1179 t8 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
1180 t9 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:'+ hex(random.randrange(16,175)).split('x')[1])
1181 t10 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:eb')
1182 t1.start()
1183 t2.start()
1184 t3.start()
1185 t4.start()
1186 t5.start()
1187 t6.start()
1188 t7.start()
1189 t8.start()
1190 t9.start()
1191 t10.start()
1192
1193 t1.join()
1194 t2.join()
1195 t3.join()
1196 t4.join()
1197 t5.join()
1198 t6.join()
1199 t7.join()
1200 t8.join()
1201 t9.join()
1202 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001203 if len(success_dir) != 10:
1204 self.success = False
1205
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001206 assert_equal(self.success, True)
1207
1208
1209 @nottest
1210 def test_10k_flow_constant_dst_mac(self):
1211 egress = 1
1212 ingress = 2
1213 egress_mac = '00:00:00:00:01:01'
1214 ingress_mac = '00:00:00:00:00:00'
1215 success_dir = {}
1216
ChetanGaonker720ea612016-06-21 17:54:25 -07001217
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001218 for i in range(0,10000):
1219 ingress_mac = self.next_mac(ingress_mac)
1220
1221 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001222 egressPort = egress + self.port_offset,
1223 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001224 ethSrc = ingress_mac,
1225 ethDst = egress_mac)
1226 result = flow.addFlow()
1227 assert_equal(result, True)
1228 ##wait for flows to be added to ONOS
1229 time.sleep(1)
1230 log.info("%d flow added.",i+1)
1231 self.success = True
1232
1233 def verify_flow(*r):
1234 random_src = ''.join(r)
1235 def mac_recv_task():
1236 def recv_cb(pkt):
1237 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1238 success_dir[current_thread().name] = True
1239 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001240 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001241
1242 t = threading.Thread(target = mac_recv_task)
1243 t.start()
1244 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1245 log.info('Sending packets to verify if flows are correct')
1246 sendp(pkt, count=50, iface = self.port_map[ingress])
1247 t.join()
1248
1249 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1250 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1251 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1252 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1253 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1254 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
1255 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(17,21)).split('x')[1] +':00:00:00:00:' +
ChetanGaonker720ea612016-06-21 17:54:25 -07001256 hex(random.randrange(16,254)).split('x')[1])
1257
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001258 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,30)).split('x')[1] +':00:00:00:00:' +
ChetanGaonker720ea612016-06-21 17:54:25 -07001259 hex(random.randrange(16,254)).split('x')[1])
1260
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001261 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(31,38)).split('x')[1] +':00:00:00:00:' +
ChetanGaonker720ea612016-06-21 17:54:25 -07001262 hex(random.randrange(16,254)).split('x')[1])
1263
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001264 t10 = threading.Thread(target = verify_flow, args = '27:00:00:00:00:37')
1265
1266 t1.start()
1267 t2.start()
1268 t3.start()
1269 t4.start()
1270 t5.start()
1271 t6.start()
1272 t7.start()
1273 t8.start()
1274 t9.start()
1275 t10.start()
1276
1277 t1.join()
1278 t2.join()
1279 t3.join()
1280 t4.join()
1281 t5.join()
1282 t6.join()
1283 t7.join()
1284 t8.join()
1285 t9.join()
1286 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001287 if len(success_dir) != 10:
1288 self.success = False
1289
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001290 assert_equal(self.success, True)
1291
1292 @nottest
1293 def test_100k_flow_constant_dst_mac(self):
1294 egress = 1
1295 ingress = 2
1296 egress_mac = '00:00:00:00:01:01'
1297 ingress_mac = '00:00:00:00:00:00'
1298 success_dir = {}
1299
1300
1301 for i in range(0,100000):
1302 ingress_mac = self.next_mac(ingress_mac)
1303
1304 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001305 egressPort = egress + self.port_offset,
1306 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001307 ethSrc = ingress_mac,
1308 ethDst = egress_mac)
1309 result = flow.addFlow()
1310 assert_equal(result, True)
1311 ##wait for flows to be added to ONOS
1312 time.sleep(1)
1313 log.info("%d flow added.",i+1)
1314 self.success = True
1315
1316 def verify_flow(*r):
1317 random_src = ''.join(r)
1318 def mac_recv_task():
1319 def recv_cb(pkt):
1320 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1321 success_dir[current_thread().name] = True
1322 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001323 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001324
1325 t = threading.Thread(target = mac_recv_task)
1326 t.start()
1327 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1328 log.info('Sending packets to verify if flows are correct')
1329 sendp(pkt, count=50, iface = self.port_map[ingress])
1330 t.join()
1331
1332 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1333 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1334 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1335 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1336 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1337 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,41)).split('x')[1] + ':00:00:00:00:08')
1338 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(42,72)).split('x')[1] +':00:00:00:00:' +
1339 hex(random.randrange(16,254)).split('x')[1])
1340
1341 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(73,100)).split('x')[1] +':00:00:00:00:' +
1342 hex(random.randrange(16,254)).split('x')[1])
1343
1344 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(101,136)).split('x')[1] +':00:00:00:00:' +
1345 hex(random.randrange(16,254)).split('x')[1])
1346
1347 t10 = threading.Thread(target = verify_flow, args = '89:01:00:00:00:28')
1348
1349 t1.start()
1350 t2.start()
1351 t3.start()
1352 t4.start()
1353 t5.start()
1354 t6.start()
1355 t7.start()
1356 t8.start()
1357 t9.start()
1358 t10.start()
1359
1360 t1.join()
1361 t2.join()
1362 t3.join()
1363 t4.join()
1364 t5.join()
1365 t6.join()
1366 t7.join()
1367 t8.join()
1368 t9.join()
1369 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001370 if len(success_dir) != 10:
1371 self.success = False
1372
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001373 assert_equal(self.success, True)
1374
1375
1376 @nottest
1377 def test_1000k_flow_constant_dst_mac(self):
1378 egress = 1
1379 ingress = 2
1380 egress_mac = '00:00:00:00:01:01'
1381 ingress_mac = '00:00:00:00:00:00'
1382 success_dir = {}
1383
ChetanGaonker720ea612016-06-21 17:54:25 -07001384
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001385 for i in range(0,1000000):
1386 ingress_mac = self.next_mac(ingress_mac)
1387
1388 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001389 egressPort = egress + self.port_offset,
1390 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001391 ethSrc = ingress_mac,
1392 ethDst = egress_mac)
1393 result = flow.addFlow()
1394 assert_equal(result, True)
1395 ##wait for flows to be added to ONOS
1396 time.sleep(1)
1397 log.info("%d flow added.",i+1)
1398 self.success = True
1399
1400 def verify_flow(*r):
1401 random_src = ''.join(r)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001402 def mac_recv_task():
1403 def recv_cb(pkt):
1404 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1405 success_dir[current_thread().name] = True
1406 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001407 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001408
1409 t = threading.Thread(target = mac_recv_task)
1410 t.start()
1411 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1412 log.info('Sending packets to verify if flows are correct')
1413 sendp(pkt, count=50, iface = self.port_map[ingress])
1414 t.join()
1415
1416 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1417 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1418 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1419 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1420 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1421 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
1422 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,50)).split('x')[1] +':00:00:00:00:' +
1423 hex(random.randrange(16,254)).split('x')[1])
1424
1425 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(51,75)).split('x')[1] +':00:00:00:00:' +
1426 hex(random.randrange(16,254)).split('x')[1])
1427
1428 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(76,95)).split('x')[1] +':00:00:00:00:' +
1429 hex(random.randrange(16,254)).split('x')[1])
1430
1431 t10 = threading.Thread(target = verify_flow, args = '60:0f:00:00:00:91')
1432
1433 t1.start()
1434 t2.start()
1435 t3.start()
1436 t4.start()
1437 t5.start()
1438 t6.start()
1439 t7.start()
1440 t8.start()
1441 t9.start()
1442 t10.start()
1443
1444 t1.join()
1445 t2.join()
1446 t3.join()
1447 t4.join()
1448 t5.join()
1449 t6.join()
1450 t7.join()
1451 t8.join()
1452 t9.join()
1453 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001454 if len(success_dir) != 10:
1455 self.success = False
1456
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001457 assert_equal(self.success, True)
1458
ChetanGaonker720ea612016-06-21 17:54:25 -07001459 def test_5_flow_constant_src_mac(self):
1460 egress = 1
1461 ingress = 2
1462 egress_mac = '00:00:00:00:01:00'
1463 ingress_mac = '00:00:00:00:00:01'
1464
1465
1466 for i in range(0,5):
1467 egress_mac = self.next_mac(egress_mac)
1468
1469 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001470 egressPort = egress + self.port_offset,
1471 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -07001472 ethSrc = ingress_mac,
1473 ethDst = egress_mac)
1474 result = flow.addFlow()
1475 assert_equal(result, True)
1476 ##wait for flows to be added to ONOS
1477 time.sleep(1)
1478 log.info("%d flow added.",i+1)
1479 self.success = False
1480
1481 def mac_recv_task():
1482 def recv_cb(pkt):
1483 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1484 self.success = True
1485 sniff(count=2, timeout=5, lfilter = lambda p: p.src == '00:00:00:00:00:01' and p.dst == '00:00:00:00:01:02',
1486 prn = recv_cb, iface = self.port_map[egress])
1487
1488 t = threading.Thread(target = mac_recv_task)
1489 t.start()
1490 pkt = Ether(src = ingress_mac, dst = '00:00:00:00:01:02')/IP()
1491 log.info('Sending packets to verify if flows are correct')
1492 sendp(pkt, count=50, iface = self.port_map[ingress])
1493 t.join()
1494 assert_equal(self.success, True)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001495
1496 def test_500_flow_mac(self):
1497 egress = 1
1498 ingress = 2
1499 egress_mac = '00:00:00:00:01:00'
1500 ingress_mac = '00:00:00:00:00:00'
1501 success_dir = {}
1502
1503 for i in range(0,500):
1504 ingress_mac = self.next_mac(ingress_mac)
1505 egress_mac = self.to_egress_mac(ingress_mac)
1506
1507 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001508 egressPort = egress + self.port_offset,
1509 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001510 ethSrc = ingress_mac,
1511 ethDst = egress_mac)
1512 result = flow.addFlow()
1513 assert_equal(result, True)
1514 ##wait for flows to be added to ONOS
1515 time.sleep(1)
1516 log.info("%d flow added.",i+1)
1517 self.success = True
1518 def verify_flow(*r):
1519 random_src = ''.join(r)
ChetanGaonker720ea612016-06-21 17:54:25 -07001520
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001521 def mac_recv_task():
1522 def recv_cb(pkt):
1523 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1524 success_dir[current_thread().name] = True
1525 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001526 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001527
1528 t = threading.Thread(target = mac_recv_task)
1529 t.start()
1530 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
1531 log.info('Sending packets to verify if flows are correct')
1532 sendp(pkt, count=50, iface = self.port_map[ingress])
1533 t.join()
1534
1535 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1536 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
1537 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,100)).split('x')[1])
1538 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(101,240)).split('x')[1])
1539 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:f5')
1540 t1.start()
1541 t2.start()
1542 t3.start()
1543 t4.start()
1544 t5.start()
1545 t1.join()
1546 t2.join()
1547 t3.join()
1548 t4.join()
1549 t5.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001550 if len(success_dir) != 5:
1551 self.success = False
1552
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001553 assert_equal(self.success, True)
1554
1555 def test_1k_flow_mac(self):
1556 egress = 1
1557 ingress = 2
1558 egress_mac = '00:00:00:00:01:00'
1559 ingress_mac = '00:00:00:00:00:00'
1560 success_dir = {}
1561
1562 for i in range(0,1000):
1563 ingress_mac = self.next_mac(ingress_mac)
1564 egress_mac = self.to_egress_mac(ingress_mac)
1565
1566 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001567 egressPort = egress + self.port_offset,
1568 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001569 ethSrc = ingress_mac,
1570 ethDst = egress_mac)
1571 result = flow.addFlow()
1572 assert_equal(result, True)
1573 ##wait for flows to be added to ONOS
1574 time.sleep(1)
1575 log.info("%d flow added.",i+1)
1576 self.success = True
1577 def verify_flow(*r):
1578 random_src = ''.join(r)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001579 def mac_recv_task():
1580 def recv_cb(pkt):
1581 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1582 success_dir[current_thread().name] = True
ChetanGaonker720ea612016-06-21 17:54:25 -07001583 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
1584 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001585
1586 t = threading.Thread(target = mac_recv_task)
1587 t.start()
ChetanGaonker720ea612016-06-21 17:54:25 -07001588 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
1589 log.info('Sending packets to verify if flows are correct')
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001590 sendp(pkt, count=50, iface = self.port_map[ingress])
1591 t.join()
1592
1593 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1594 t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1])
1595 t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:09')
1596 t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
1597 t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
1598 t6 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:08')
1599 t7 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1])
1600 t8 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1])
1601 t9 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:'+ hex(random.randrange(16,175)).split('x')[1])
1602 t10 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:eb')
ChetanGaonker720ea612016-06-21 17:54:25 -07001603
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001604 t1.start()
1605 t2.start()
1606 t3.start()
1607 t4.start()
1608 t5.start()
1609 t6.start()
1610 t7.start()
1611 t8.start()
1612 t9.start()
1613 t10.start()
1614
1615 t1.join()
1616 t2.join()
1617 t3.join()
1618 t4.join()
1619 t5.join()
1620 t6.join()
1621 t7.join()
1622 t8.join()
1623 t9.join()
1624 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001625 if len(success_dir) != 10:
1626 self.success = False
1627
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001628 assert_equal(self.success, True)
1629
1630 @nottest
1631 def test_10k_flow_mac(self):
1632 egress = 1
1633 ingress = 2
1634 egress_mac = '00:00:00:00:01:00'
1635 ingress_mac = '00:00:00:00:00:00'
1636 success_dir = {}
1637
1638 for i in range(0,10000):
ChetanGaonker720ea612016-06-21 17:54:25 -07001639 ingress_mac = self.next_mac(ingress_mac)
1640 egress_mac = self.to_egress_mac(ingress_mac)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001641
ChetanGaonker720ea612016-06-21 17:54:25 -07001642 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001643 egressPort = egress + self.port_offset,
1644 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -07001645 ethSrc = ingress_mac,
1646 ethDst = egress_mac)
1647 result = flow.addFlow()
1648 assert_equal(result, True)
1649 ##wait for flows to be added to ONOS
1650 time.sleep(1)
1651 log.info("%d flow added.",i+1)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001652 self.success = True
1653 def verify_flow(*r):
1654 random_src = ''.join(r)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001655 def mac_recv_task():
1656 def recv_cb(pkt):
1657 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1658 success_dir[current_thread().name] = True
1659 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001660 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001661
1662 t = threading.Thread(target = mac_recv_task)
1663 t.start()
1664 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
1665 log.info('Sending packets to verify if flows are correct')
1666 sendp(pkt, count=50, iface = self.port_map[ingress])
1667 t.join()
1668
1669 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1670 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1671 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1672 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1673 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1674 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
1675 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(17,21)).split('x')[1] +':00:00:00:00:' +
1676 hex(random.randrange(16,254)).split('x')[1])
1677
1678 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,30)).split('x')[1] +':00:00:00:00:' +
1679 hex(random.randrange(16,254)).split('x')[1])
1680
1681 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(31,38)).split('x')[1] +':00:00:00:00:' +
1682 hex(random.randrange(16,254)).split('x')[1])
1683
1684 t10 = threading.Thread(target = verify_flow, args = '27:00:00:00:00:37')
1685
1686 t1.start()
1687 t2.start()
1688 t3.start()
1689 t4.start()
1690 t5.start()
1691 t6.start()
1692 t7.start()
1693 t8.start()
1694 t9.start()
1695 t10.start()
1696
1697 t1.join()
1698 t2.join()
1699 t3.join()
1700 t4.join()
1701 t5.join()
1702 t6.join()
1703 t7.join()
1704 t8.join()
1705 t9.join()
1706 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001707 if len(success_dir) != 10:
1708 self.success = False
1709
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001710 assert_equal(self.success, True)
1711
1712 @nottest
1713 def test_100k_flow_mac(self):
1714 egress = 1
1715 ingress = 2
1716 egress_mac = '00:00:00:00:01:00'
1717 ingress_mac = '00:00:00:00:00:00'
1718 success_dir = {}
1719
1720 for i in range(0,100000):
1721 ingress_mac = self.next_mac(ingress_mac)
1722 egress_mac = self.to_egress_mac(ingress_mac)
1723
1724 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001725 egressPort = egress + self.port_offset,
1726 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001727 ethSrc = ingress_mac,
1728 ethDst = egress_mac)
1729 result = flow.addFlow()
1730 assert_equal(result, True)
1731 ##wait for flows to be added to ONOS
1732 time.sleep(1)
1733 log.info("%d flow added.",i+1)
1734 self.success = True
1735
1736 def verify_flow(*r):
1737 random_src = ''.join(r)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001738 def mac_recv_task():
1739 def recv_cb(pkt):
1740 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1741 success_dir[current_thread().name] = True
1742 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
ChetanGaonker720ea612016-06-21 17:54:25 -07001743 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001744
1745 t = threading.Thread(target = mac_recv_task)
1746 t.start()
1747 pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP()
1748 log.info('Sending packets to verify if flows are correct')
1749 sendp(pkt, count=50, iface = self.port_map[ingress])
1750 t.join()
1751
1752 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1753 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1754 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1755 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1756 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1757 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,41)).split('x')[1] + ':00:00:00:00:08')
1758 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(42,72)).split('x')[1] +':00:00:00:00:' +
1759 hex(random.randrange(16,254)).split('x')[1])
1760
1761 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(73,100)).split('x')[1] +':00:00:00:00:' +
1762 hex(random.randrange(16,254)).split('x')[1])
1763
1764 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(101,136)).split('x')[1] +':00:00:00:00:' +
1765 hex(random.randrange(16,254)).split('x')[1])
1766
1767 t10 = threading.Thread(target = verify_flow, args = '89:01:00:00:00:28')
1768
1769 t1.start()
1770 t2.start()
1771 t3.start()
1772 t4.start()
1773 t5.start()
1774 t6.start()
1775 t7.start()
1776 t8.start()
1777 t9.start()
1778 t10.start()
1779
1780 t1.join()
1781 t2.join()
1782 t3.join()
1783 t4.join()
1784 t5.join()
1785 t6.join()
1786 t7.join()
1787 t8.join()
1788 t9.join()
1789 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001790 if len(success_dir) != 10:
1791 self.success = False
1792
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001793 assert_equal(self.success, True)
1794
1795 @nottest
1796 def test_1000k_flow_mac(self):
1797 egress = 1
1798 ingress = 2
1799 egress_mac = '00:00:00:00:01:00'
1800 ingress_mac = '00:00:00:00:00:00'
1801 success_dir = {}
1802
1803 for i in range(0,1000000):
1804 ingress_mac = self.next_mac(ingress_mac)
1805 egress_mac = self.to_egress_mac(ingress_mac)
1806
1807 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001808 egressPort = egress + self.port_offset,
1809 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001810 ethSrc = ingress_mac,
1811 ethDst = egress_mac)
1812 result = flow.addFlow()
1813 assert_equal(result, True)
1814 ##wait for flows to be added to ONOS
1815 time.sleep(1)
1816 log.info("%d flow added.",i+1)
1817 self.success = True
1818
1819 def verify_flow(*r):
1820 random_src = ''.join(r)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001821 def mac_recv_task():
ChetanGaonker720ea612016-06-21 17:54:25 -07001822 def recv_cb(pkt):
1823 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1824 success_dir[current_thread().name] = True
1825 sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src,
1826 prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001827
1828 t = threading.Thread(target = mac_recv_task)
1829 t.start()
1830 pkt = Ether(src = random_src, dst = egress_mac)/IP()
1831 log.info('Sending packets to verify if flows are correct')
1832 sendp(pkt, count=50, iface = self.port_map[ingress])
1833 t.join()
1834
1835 t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01')
1836 t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1837 t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1])
1838 t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1839 t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1])
1840 t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08')
1841 t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,50)).split('x')[1] +':00:00:00:00:' +
1842 hex(random.randrange(16,254)).split('x')[1])
1843
1844 t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(51,75)).split('x')[1] +':00:00:00:00:' +
1845 hex(random.randrange(16,254)).split('x')[1])
1846
1847 t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(76,95)).split('x')[1] +':00:00:00:00:' +
1848 hex(random.randrange(16,254)).split('x')[1])
1849
1850 t10 = threading.Thread(target = verify_flow, args = '60:0f:00:00:00:91')
1851
1852 t1.start()
1853 t2.start()
1854 t3.start()
1855 t4.start()
1856 t5.start()
1857 t6.start()
1858 t7.start()
1859 t8.start()
1860 t9.start()
1861 t10.start()
1862
1863 t1.join()
1864 t2.join()
1865 t3.join()
1866 t4.join()
1867 t5.join()
1868 t6.join()
1869 t7.join()
1870 t8.join()
1871 t9.join()
1872 t10.join()
ChetanGaonker720ea612016-06-21 17:54:25 -07001873 if len(success_dir) != 10:
1874 self.success = False
1875
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07001876 assert_equal(self.success, True)
1877
ChetanGaonkerd376b902016-06-14 11:50:28 -07001878 def test_rate_100_flow_mac(self):
1879 egress = 1
1880 ingress = 2
1881 egress_mac = '00:00:00:00:01:00'
1882 ingress_mac = '00:00:00:00:00:00'
1883 flows_added = 0
1884 stats_dir = collections.OrderedDict()
1885 running_time = 0
1886
1887
1888 for i in range(1,4):
1889 start_time = time.time()
1890 for j in range(0,100):
1891 ingress_mac = self.next_mac(ingress_mac)
1892 egress_mac = self.to_egress_mac(ingress_mac)
1893
1894 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001895 egressPort = egress + self.port_offset,
1896 ingressPort = ingress + self.port_offset,
ChetanGaonkerd376b902016-06-14 11:50:28 -07001897 ethSrc = ingress_mac,
1898 ethDst = egress_mac)
1899 result = flow.addFlow()
1900 assert_equal(result, True)
1901 flows_added += 1
1902 ##wait for flows to be added to ONOS
ChetanGaonker720ea612016-06-21 17:54:25 -07001903 time.sleep(1)
ChetanGaonkerd376b902016-06-14 11:50:28 -07001904 log.info("%d flow added.",j+1)
1905 end_time = time.time()
1906 stats_dir['run '+str(i)] = round((end_time - start_time),2)
1907 for t in stats_dir.items():
ChetanGaonker720ea612016-06-21 17:54:25 -07001908 log.info("----------------------------------------------")
1909 log.info("Statics for %s",t[0])
1910 log.info("----------------------------------------------")
1911 log.info("No. of flows added Running Time ")
1912 log.info(" %d %s " %(100, t[1]))
1913 running_time += float(t[1])
ChetanGaonkerd376b902016-06-14 11:50:28 -07001914
1915 log.info("-------------------------------------------------------------------------------------------------------")
1916 log.info("Final Statics")
1917 log.info("-------------------------------------------------------------------------------------------------------")
1918 log.info("Total No. of flows added Total Running Time Average no. of flows per second ")
1919 log.info(" %d %s second %d "
1920 %(flows_added, running_time, round(flows_added/running_time,0)))
1921 log.info("-------------------------------------------------------------------------------------------------------")
1922
1923
1924
1925 def test_rate_500_flow_mac(self):
1926 egress = 1
1927 ingress = 2
1928 egress_mac = '00:00:00:00:01:00'
1929 ingress_mac = '00:00:00:00:00:00'
1930 flows_added = 0
1931 stats_dir = collections.OrderedDict()
1932 running_time = 0
1933
1934
1935 for i in range(1,4):
1936 start_time = time.time()
1937 for j in range(0,500):
1938 ingress_mac = self.next_mac(ingress_mac)
1939 egress_mac = self.to_egress_mac(ingress_mac)
1940
1941 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001942 egressPort = egress + self.port_offset,
1943 ingressPort = ingress + self.port_offset,
ChetanGaonkerd376b902016-06-14 11:50:28 -07001944 ethSrc = ingress_mac,
1945 ethDst = egress_mac)
1946 result = flow.addFlow()
1947 assert_equal(result, True)
1948 flows_added += 1
1949 ##wait for flows to be added to ONOS
ChetanGaonker720ea612016-06-21 17:54:25 -07001950 time.sleep(1)
ChetanGaonkerd376b902016-06-14 11:50:28 -07001951 log.info("%d flow added.",j+1)
1952 end_time = time.time()
1953 stats_dir['run '+str(i)] = round((end_time - start_time),2)
1954 for t in stats_dir.items():
1955 log.info("----------------------------------------------")
1956 log.info("Statics for %s",t[0])
1957 log.info("----------------------------------------------")
1958 log.info("No. of flows added Running Time ")
1959 log.info(" %d %s " %(500, t[1]))
1960 running_time += float(t[1])
1961
1962 log.info("-------------------------------------------------------------------------------------------------------")
1963 log.info("Final Statics")
1964 log.info("-------------------------------------------------------------------------------------------------------")
1965 log.info("Total No. of flows added Total Running Time Average no. of flows per second ")
1966 log.info(" %d %s second %d "
1967 %(flows_added, running_time, round(flows_added/running_time,0)))
1968 log.info("-------------------------------------------------------------------------------------------------------")
1969
1970 def test_rate_1k_flow_mac(self):
1971 egress = 1
1972 ingress = 2
1973 egress_mac = '00:00:00:00:01:00'
1974 ingress_mac = '00:00:00:00:00:00'
1975 flows_added = 0
1976 stats_dir = collections.OrderedDict()
1977 running_time = 0
1978
1979
1980 for i in range(1,4):
1981 start_time = time.time()
1982 for j in range(0,1000):
1983 ingress_mac = self.next_mac(ingress_mac)
1984 egress_mac = self.to_egress_mac(ingress_mac)
1985
1986 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08001987 egressPort = egress + self.port_offset,
1988 ingressPort = ingress + self.port_offset,
ChetanGaonkerd376b902016-06-14 11:50:28 -07001989 ethSrc = ingress_mac,
1990 ethDst = egress_mac)
1991 result = flow.addFlow()
1992 assert_equal(result, True)
1993 flows_added += 1
ChetanGaonker720ea612016-06-21 17:54:25 -07001994 ##wait for flows to be added to ONOS
1995 time.sleep(1)
ChetanGaonkerd376b902016-06-14 11:50:28 -07001996 log.info("%d flow added.",j+1)
1997 end_time = time.time()
1998 stats_dir['run '+str(i)] = round((end_time - start_time),2)
1999 for t in stats_dir.items():
2000 log.info("----------------------------------------------")
2001 log.info("Statics for %s",t[0])
2002 log.info("----------------------------------------------")
2003 log.info("No. of flows added Running Time ")
2004 log.info(" %d %s " %(1000, t[1]))
2005 running_time += float(t[1])
2006
2007 log.info("-------------------------------------------------------------------------------------------------------")
2008 log.info("Final Statics")
2009 log.info("-------------------------------------------------------------------------------------------------------")
2010 log.info("Total No. of flows added Total Running Time Average no. of flows per second ")
2011 log.info(" %d %s second %d "
2012 %(flows_added, running_time, round(flows_added/running_time,0)))
2013 log.info("-------------------------------------------------------------------------------------------------------")
2014
2015
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002016 def test_500_flow_ip(self):
2017 egress = 1
2018 ingress = 2
2019 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
2020 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
ChetanGaonker720ea612016-06-21 17:54:25 -07002021 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002022
2023 for i in range(0,500):
2024 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
2025 assert_not_equal(ingress_map['ip'], None)
2026 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
2027
2028 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002029 egressPort = egress + self.port_offset,
2030 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002031 ethType = '0x0800',
2032 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
2033 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
2034 )
2035 result = flow.addFlow()
2036 assert_equal(result, True)
2037 ##wait for flows to be added to ONOS
2038 time.sleep(1)
2039 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07002040 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002041
ChetanGaonker720ea612016-06-21 17:54:25 -07002042 def verify_flow(*r):
2043 random_src = ''.join(r)
2044 random_dst = self.to_egress_ip(random_src)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002045
ChetanGaonker720ea612016-06-21 17:54:25 -07002046 def mac_recv_task():
2047 def recv_cb(pkt):
2048 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
2049 success_dir[current_thread().name] = True
2050
2051 sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src
2052 ,prn = recv_cb, iface = self.port_map[egress])
2053
2054 t = threading.Thread(target = mac_recv_task)
2055 t.start()
2056 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2057 L3 = IP(src = random_src, dst = random_dst)
2058 pkt = L2/L3
2059 log.info('Sending packets to verify if flows are correct')
2060 sendp(pkt, count=50, iface = self.port_map[ingress])
2061 t.join()
2062
2063 t1 = threading.Thread(target = verify_flow, args = '192.0.0.1')
2064 t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(10,100,1)))
2065 t3 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(101,255,1)))
2066 t4 = threading.Thread(target = verify_flow, args = '192.0.1.' + str(random.randrange(1,235,1)))
2067 t5 = threading.Thread(target = verify_flow, args = '192.0.1.244')
2068 t1.start()
2069 t2.start()
2070 t3.start()
2071 t4.start()
2072 t5.start()
2073
2074 t1.join()
2075 t2.join()
2076 t3.join()
2077 t4.join()
2078 t5.join()
2079
2080 if len(success_dir) < 5 or len(success_dir) > 5:
2081 self.success = False
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002082 assert_equal(self.success, True)
2083
ChetanGaonker720ea612016-06-21 17:54:25 -07002084
2085 @nottest
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002086 def test_1k_flow_ip(self):
2087 egress = 1
2088 ingress = 2
2089 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
2090 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
ChetanGaonker720ea612016-06-21 17:54:25 -07002091 success_dir ={}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002092
2093 for i in range(0,1000):
2094 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
2095 assert_not_equal(ingress_map['ip'], None)
2096 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
2097
2098 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002099 egressPort = egress + self.port_offset,
2100 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002101 ethType = '0x0800',
2102 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
2103 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
2104 )
2105 result = flow.addFlow()
2106 assert_equal(result, True)
2107 ##wait for flows to be added to ONOS
2108 time.sleep(1)
2109 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07002110 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002111
ChetanGaonker720ea612016-06-21 17:54:25 -07002112 def verify_flow(*r):
2113 random_src = ''.join(r)
2114 random_dst = self.to_egress_ip(random_src)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002115
ChetanGaonker720ea612016-06-21 17:54:25 -07002116 def mac_recv_task():
2117 def recv_cb(pkt):
2118 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
2119 success_dir[current_thread().name] = True
2120
2121 sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src
2122 ,prn = recv_cb, iface = self.port_map[egress])
2123
2124 t = threading.Thread(target = mac_recv_task)
2125 t.start()
2126 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2127 L3 = IP(src = random_src, dst = random_dst)
2128 pkt = L2/L3
2129 log.info('Sending packets to verify if flows are correct')
2130 sendp(pkt, count=50, iface = self.port_map[ingress])
2131 t.join()
2132
2133 t1 = threading.Thread(target = verify_flow, args = '192.0.0.1')
2134 t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(10,255,1)))
2135 t3 = threading.Thread(target = verify_flow, args = '192.0.1.' + str(random.randrange(1,100,1)))
2136 t4 = threading.Thread(target = verify_flow, args = '192.0.1.' + str(random.randrange(101,255,1)))
2137 t5 = threading.Thread(target = verify_flow, args = '192.0.2.' + str(random.randrange(1,100,1)))
2138 t6 = threading.Thread(target = verify_flow, args = '192.0.2.' + str(random.randrange(101,255,1)))
2139 t7 = threading.Thread(target = verify_flow, args = '192.0.3.' + str(random.randrange(1,100,1)))
2140 t8 = threading.Thread(target = verify_flow, args = '192.0.3.' + str(random.randrange(101,200,1)))
2141 t9 = threading.Thread(target = verify_flow, args = '192.0.'+ str(random.randrange(0,3,1)) + '.' +
2142 str(random.randrange(1,255,1)))
2143 t10 = threading.Thread(target = verify_flow, args = '192.0.3.232')
2144
2145 t1.start()
2146 t2.start()
2147 t3.start()
2148 t4.start()
2149 t5.start()
2150 t6.start()
2151 t7.start()
2152 t8.start()
2153 t9.start()
2154 t10.start()
2155
2156 t1.join()
2157 t2.join()
2158 t3.join()
2159 t4.join()
2160 t5.join()
2161 t6.join()
2162 t7.join()
2163 t8.join()
2164 t9.join()
2165 t10.join()
2166
2167 if len(success_dir) != 10:
2168 self.success = False
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002169 assert_equal(self.success, True)
2170
2171 @nottest
2172 def test_10k_flow_ip(self):
2173 egress = 1
2174 ingress = 2
2175 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
2176 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
ChetanGaonker720ea612016-06-21 17:54:25 -07002177 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002178
2179 for i in range(0,10000):
2180 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
2181 assert_not_equal(ingress_map['ip'], None)
2182 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
2183
2184 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002185 egressPort = egress + self.port_offset,
2186 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002187 ethType = '0x0800',
2188 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
2189 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
2190 )
2191 result = flow.addFlow()
2192 assert_equal(result, True)
2193 ##wait for flows to be added to ONOS
2194 time.sleep(1)
2195 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07002196 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002197
ChetanGaonker720ea612016-06-21 17:54:25 -07002198 def verify_flow(*r):
2199 random_src = ''.join(r)
2200 random_dst = self.to_egress_ip(random_src)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002201
ChetanGaonker720ea612016-06-21 17:54:25 -07002202 def mac_recv_task():
2203 def recv_cb(pkt):
2204 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
2205 success_dir[current_thread().name] = True
2206 sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src
2207 ,prn = recv_cb, iface = self.port_map[egress])
2208
2209 t = threading.Thread(target = mac_recv_task)
2210 t.start()
2211 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2212 L3 = IP(src = random_src, dst = random_dst)
2213 pkt = L2/L3
2214 log.info('Sending packets to verify if flows are correct')
2215 sendp(pkt, count=50, iface = self.port_map[ingress])
2216 t.join()
2217
2218 t1 = threading.Thread(target = verify_flow, args = '192.0.0.1')
2219 t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(1,255,1)))
2220 t3 = threading.Thread(target = verify_flow, args = '192.0.5.' + str(random.randrange(1,255,1)))
2221 t4 = threading.Thread(target = verify_flow, args = '192.0.10.' + str(random.randrange(1,255,1)))
2222 t5 = threading.Thread(target = verify_flow, args = '192.0.15.' + str(random.randrange(1,255,1)))
2223 t6 = threading.Thread(target = verify_flow, args = '192.0.20.' + str(random.randrange(1,255,1)))
2224 t7 = threading.Thread(target = verify_flow, args = '192.0.25.' + str(random.randrange(1,255,1)))
2225 t8 = threading.Thread(target = verify_flow, args = '192.0.30.' + str(random.randrange(1,255,1)))
2226 t9 = threading.Thread(target = verify_flow, args = '192.0.'+ str(random.randrange(0,39,1)) + '.' +
2227 str(random.randrange(1,255,1)))
2228 t10 = threading.Thread(target = verify_flow, args = '192.0.39.16')
2229
2230 t1.start()
2231 t2.start()
2232 t3.start()
2233 t4.start()
2234 t5.start()
2235 t6.start()
2236 t7.start()
2237 t8.start()
2238 t9.start()
2239 t10.start()
2240
2241 t1.join()
2242 t2.join()
2243 t3.join()
2244 t4.join()
2245 t5.join()
2246 t6.join()
2247 t7.join()
2248 t8.join()
2249 t9.join()
2250 t10.join()
2251
2252 if len(success_dir) != 10:
2253 self.success = False
2254
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002255 assert_equal(self.success, True)
2256
2257 @nottest
2258 def test_100k_flow_ip(self):
2259 egress = 1
2260 ingress = 2
2261 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
2262 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
ChetanGaonker720ea612016-06-21 17:54:25 -07002263 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002264
2265 for i in range(0,100000):
2266 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
2267 assert_not_equal(ingress_map['ip'], None)
2268 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
2269
2270 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002271 egressPort = egress + self.port_offset,
2272 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002273 ethType = '0x0800',
2274 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
2275 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
2276 )
2277 result = flow.addFlow()
2278 assert_equal(result, True)
2279 ##wait for flows to be added to ONOS
2280 time.sleep(1)
2281 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07002282 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002283
ChetanGaonker720ea612016-06-21 17:54:25 -07002284 def verify_flow(*r):
2285 random_src = ''.join(r)
2286 random_dst = self.to_egress_ip(random_src)
2287 def mac_recv_task():
2288 def recv_cb(pkt):
2289 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
2290 success_dir[current_thread().name] = True
2291 sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src
2292 ,prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002293
ChetanGaonker720ea612016-06-21 17:54:25 -07002294 t = threading.Thread(target = mac_recv_task)
2295 t.start()
2296 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2297 L3 = IP(src = random_src, dst = random_dst)
2298 pkt = L2/L3
2299 log.info('Sending packets to verify if flows are correct')
2300 sendp(pkt, count=50, iface = self.port_map[ingress])
2301 t.join()
2302
2303 t1 = threading.Thread(target = verify_flow, args = '192.0.0.1')
2304 t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(1,255,1)))
2305 t3 = threading.Thread(target = verify_flow, args = '192.0.50.' + str(random.randrange(1,255,1)))
2306 t4 = threading.Thread(target = verify_flow, args = '192.0.100.' + str(random.randrange(1,255,1)))
2307 t5 = threading.Thread(target = verify_flow, args = '192.0.150.' + str(random.randrange(1,255,1)))
2308 t6 = threading.Thread(target = verify_flow, args = '192.0.200.' + str(random.randrange(1,255,1)))
2309 t7 = threading.Thread(target = verify_flow, args = '192.0.250.' + str(random.randrange(1,255,1)))
2310 t8 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(1,75,1)) + '.'
2311 + str(random.randrange(1,255,1)))
2312 t9 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(76,134,1)) + '.'
2313 + str(random.randrange(1,255,1)))
2314 t10 = threading.Thread(target = verify_flow, args = '192.1.134.160')
2315
2316 t1.start()
2317 t2.start()
2318 t3.start()
2319 t4.start()
2320 t5.start()
2321 t6.start()
2322 t7.start()
2323 t8.start()
2324 t9.start()
2325 t10.start()
2326
2327 t1.join()
2328 t2.join()
2329 t3.join()
2330 t4.join()
2331 t5.join()
2332 t6.join()
2333 t7.join()
2334 t8.join()
2335 t9.join()
2336 t10.join()
2337
2338 if len(success_dir) != 10:
2339 self.success = False
2340
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002341 assert_equal(self.success, True)
2342
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002343 @nottest
2344 def test_1000k_flow_ip(self):
2345 egress = 1
2346 ingress = 2
2347 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
2348 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
ChetanGaonker720ea612016-06-21 17:54:25 -07002349 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002350
2351 for i in range(0,1000000):
2352 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
2353 assert_not_equal(ingress_map['ip'], None)
2354 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
2355
2356 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002357 egressPort = egress + self.port_offset,
2358 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002359 ethType = '0x0800',
2360 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
2361 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
2362 )
2363 result = flow.addFlow()
2364 assert_equal(result, True)
2365 ##wait for flows to be added to ONOS
2366 time.sleep(1)
2367 log.info("%d flow added.",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07002368 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002369
ChetanGaonker720ea612016-06-21 17:54:25 -07002370 def verify_flow(*r):
2371 random_src = ''.join(r)
2372 random_dst = self.to_egress_ip(random_src)
2373 def mac_recv_task():
2374 def recv_cb(pkt):
2375 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
2376 success_dir[current_thread().name] = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002377
ChetanGaonker720ea612016-06-21 17:54:25 -07002378 sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src
2379 ,prn = recv_cb, iface = self.port_map[egress])
2380
2381 t = threading.Thread(target = mac_recv_task)
2382 t.start()
2383 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2384 L3 = IP(src = random_src, dst = random_dst)
2385 pkt = L2/L3
2386 log.info('Sending packets to verify if flows are correct')
2387 sendp(pkt, count=50, iface = self.port_map[ingress])
2388 t.join()
2389
2390 t1 = threading.Thread(target = verify_flow, args = '192.0.0.1')
2391 t2 = threading.Thread(target = verify_flow, args = '192.0.50.' + str(random.randrange(1,255,1)))
2392 t3 = threading.Thread(target = verify_flow, args = '192.0.100.' + str(random.randrange(1,255,1)))
2393 t4 = threading.Thread(target = verify_flow, args = '192.0.150.' + str(random.randrange(1,255,1)))
2394 t5 = threading.Thread(target = verify_flow, args = '192.0.200.' + str(random.randrange(1,255,1)))
2395 t6 = threading.Thread(target = verify_flow, args = '192.0.250.' + str(random.randrange(1,255,1)))
2396 t7 = threading.Thread(target = verify_flow, args = '192.0.250.' + str(random.randrange(1,255,1)))
2397 t8 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(1,150,1)) + '.'
2398 + str(random.randrange(1,255,1)))
2399 t9 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(152,255,1)) + '.'
2400 + str(random.randrange(1,255,1)))
2401 t10 = threading.Thread(target = verify_flow, args = '192.15.66.64')
2402
2403 t1.start()
2404 t2.start()
2405 t3.start()
2406 t4.start()
2407 t5.start()
2408 t6.start()
2409 t7.start()
2410 t8.start()
2411 t9.start()
2412 t10.start()
2413
2414 t1.join()
2415 t2.join()
2416 t3.join()
2417 t4.join()
2418 t5.join()
2419 t6.join()
2420 t7.join()
2421 t8.join()
2422 t9.join()
2423 t10.join()
2424
2425 if len(success_dir) != 10:
2426 self.success = False
2427
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002428 assert_equal(self.success, True)
2429
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002430 def test_500_flow_tcp_port(self):
2431 egress = 1
2432 ingress = 2
2433 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 3100 }
2434 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 1100 }
ChetanGaonker720ea612016-06-21 17:54:25 -07002435 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002436
2437 for i in range(0,500):
2438 ingress_map['tcp_port'] += 1
2439 egress_map['tcp_port'] += 1
2440
2441 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002442 egressPort = egress + self.port_offset,
2443 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002444 tcpSrc = ingress_map['tcp_port'],
2445 tcpDst = egress_map['tcp_port']
2446 )
2447
2448 result = flow.addFlow()
2449 assert_equal(result, True)
2450 ##wait for flows to be added to ONOS
2451 time.sleep(1)
2452 log.info("%d Flow added",i+1)
ChetanGaonker720ea612016-06-21 17:54:25 -07002453 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002454
ChetanGaonker720ea612016-06-21 17:54:25 -07002455 def verify_flow(*r):
2456 random_sport = int(''.join(r))
2457 random_dport = random_sport + 2000
2458 def mac_recv_task():
2459 def recv_cb(pkt):
2460 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
2461 success_dir[current_thread().name] = True
2462 sniff(count=2, timeout=5,
2463 lfilter = lambda p: TCP in p and p[TCP].dport == random_dport and p[TCP].sport == random_sport ,prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002464
ChetanGaonker720ea612016-06-21 17:54:25 -07002465 t = threading.Thread(target = mac_recv_task)
2466 t.start()
2467 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2468 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
2469 L4 = TCP(sport = random_sport, dport = random_dport)
2470 pkt = L2/L3/L4
2471 log.info('Sending packets to verify if flows are correct')
2472 sendp(pkt, count=50, iface = self.port_map[ingress])
2473 t.join()
2474 t1 = threading.Thread(target = verify_flow, args = str(1101))
2475 t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1250,1)))
2476 t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1251,1400,1)))
2477 t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1401,1590,1)))
2478 t5 = threading.Thread(target = verify_flow, args = str(1600))
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002479
ChetanGaonker720ea612016-06-21 17:54:25 -07002480 t1.start()
2481 t2.start()
2482 t3.start()
2483 t4.start()
2484 t5.start()
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002485
ChetanGaonker720ea612016-06-21 17:54:25 -07002486 t1.join()
2487 t2.join()
2488 t3.join()
2489 t4.join()
2490 t5.join()
2491
2492 if len(success_dir) != 5:
2493 self.success = False
2494
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002495 assert_equal(self.success, True)
2496
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002497 def test_1k_flow_tcp_port(self):
2498 egress = 1
2499 ingress = 2
2500 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 3100 }
2501 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 1100 }
ChetanGaonker720ea612016-06-21 17:54:25 -07002502 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002503
2504 for i in range(0,1000):
2505 ingress_map['tcp_port'] += 1
2506 egress_map['tcp_port'] += 1
2507
2508 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002509 egressPort = egress + self.port_offset,
2510 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002511 tcpSrc = ingress_map['tcp_port'],
2512 tcpDst = egress_map['tcp_port']
2513 )
2514
2515 result = flow.addFlow()
2516 assert_equal(result, True)
2517 ##wait for flows to be added to ONOS
2518 time.sleep(1)
2519 log.info("%d flow added.",i+1)
2520
ChetanGaonker720ea612016-06-21 17:54:25 -07002521 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002522
ChetanGaonker720ea612016-06-21 17:54:25 -07002523 def verify_flow(*r):
2524 random_sport = int(''.join(r))
2525 random_dport = random_sport + 2000
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002526
ChetanGaonker720ea612016-06-21 17:54:25 -07002527 def mac_recv_task():
2528 def recv_cb(pkt):
2529 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
2530 success_dir[current_thread().name] = True
2531 sniff(count=2, timeout=5,
2532 lfilter = lambda p: TCP in p and p[TCP].dport == random_dport and p[TCP].sport == random_sport ,prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002533
ChetanGaonker720ea612016-06-21 17:54:25 -07002534 t = threading.Thread(target = mac_recv_task)
2535 t.start()
2536 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2537 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
2538 L4 = TCP(sport = random_sport, dport = random_dport)
2539 pkt = L2/L3/L4
2540 log.info('Sending packets to verify if flows are correct')
2541 sendp(pkt, count=50, iface = self.port_map[ingress])
2542 t.join()
2543
2544 t1 = threading.Thread(target = verify_flow, args = str(1101))
2545 t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1350,1)))
2546 t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1351,1500,1)))
2547 t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1501,1700,1)))
2548 t5 = threading.Thread(target = verify_flow, args = str(random.randrange(1701,1900,1)))
2549 t6 = threading.Thread(target = verify_flow, args = str(random.randrange(1901,2000,1)))
2550 t7 = threading.Thread(target = verify_flow, args = str(random.randrange(2000,2050,1)))
2551 t8 = threading.Thread(target = verify_flow, args = str(random.randrange(2050,2080,1)))
2552 t9 = threading.Thread(target = verify_flow, args = str(random.randrange(1102,2100,1)))
2553 t10 = threading.Thread(target = verify_flow, args = str(2100))
2554
2555
2556 t1.start()
2557 t2.start()
2558 t3.start()
2559 t4.start()
2560 t5.start()
2561 t6.start()
2562 t7.start()
2563 t8.start()
2564 t9.start()
2565 t10.start()
2566
2567 t1.join()
2568 t2.join()
2569 t3.join()
2570 t4.join()
2571 t5.join()
2572 t6.join()
2573 t7.join()
2574 t8.join()
2575 t9.join()
2576 t10.join()
2577
2578 if len(success_dir) != 10:
2579 self.success = False
2580
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002581 assert_equal(self.success, True)
2582
2583 @nottest
2584 def test_10k_flow_tcp_port(self):
2585 egress = 1
2586 ingress = 2
2587 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 31000 }
2588 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 11000 }
ChetanGaonker720ea612016-06-21 17:54:25 -07002589 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002590
2591 for i in range(0,10000):
2592 ingress_map['tcp_port'] += 1
2593 egress_map['tcp_port'] += 1
2594
2595 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002596 egressPort = egress + self.port_offset,
2597 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002598 tcpSrc = ingress_map['tcp_port'],
2599 tcpDst = egress_map['tcp_port']
2600 )
2601
2602 result = flow.addFlow()
2603 assert_equal(result, True)
2604 ##wait for flows to be added to ONOS
2605 time.sleep(1)
2606 log.info("%d flow added.",i+1)
2607
ChetanGaonker720ea612016-06-21 17:54:25 -07002608 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002609
ChetanGaonker720ea612016-06-21 17:54:25 -07002610 def verify_flow(*r):
2611 random_sport = int(''.join(r))
2612 random_dport = random_sport + 20000
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002613
ChetanGaonker720ea612016-06-21 17:54:25 -07002614 def mac_recv_task():
2615 def recv_cb(pkt):
2616 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
2617 success_dir[current_thread().name] = True
2618 sniff(count=2, timeout=5,
2619 lfilter = lambda p: TCP in p and p[TCP].dport == random_dport
2620 and p[TCP].sport == random_sport,prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002621
ChetanGaonker720ea612016-06-21 17:54:25 -07002622 t = threading.Thread(target = mac_recv_task)
2623 t.start()
2624 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2625 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
2626 L4 = TCP(sport = random_sport, dport = random_dport)
2627 pkt = L2/L3/L4
2628 log.info('Sending packets to verify if flows are correct')
2629 sendp(pkt, count=50, iface = self.port_map[ingress])
2630 t.join()
2631
2632 t1 = threading.Thread(target = verify_flow, args = str(11001))
2633 t2 = threading.Thread(target = verify_flow, args = str(random.randrange(11110,12501,1)))
2634 t3 = threading.Thread(target = verify_flow, args = str(random.randrange(12510,14001,1)))
2635 t4 = threading.Thread(target = verify_flow, args = str(random.randrange(14010,15900,1)))
2636 t5 = threading.Thread(target = verify_flow, args = str(random.randrange(16000,17000,1)))
2637 t6 = threading.Thread(target = verify_flow, args = str(random.randrange(17001,18000,1)))
2638 t7 = threading.Thread(target = verify_flow, args = str(random.randrange(18000,19000,1)))
2639 t8 = threading.Thread(target = verify_flow, args = str(random.randrange(19000,20980,1)))
2640 t9 = threading.Thread(target = verify_flow, args = str(random.randrange(11002,21000,1)))
2641 t10 = threading.Thread(target = verify_flow, args = str(21000))
2642
2643
2644 t1.start()
2645 t2.start()
2646 t3.start()
2647 t4.start()
2648 t5.start()
2649 t6.start()
2650 t7.start()
2651 t8.start()
2652 t9.start()
2653 t10.start()
2654
2655 t1.join()
2656 t2.join()
2657 t3.join()
2658 t4.join()
2659 t5.join()
2660 t6.join()
2661 t7.join()
2662 t8.join()
2663 t9.join()
2664 t10.join()
2665
2666 if len(success_dir) != 10:
2667 self.success = False
2668
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002669 assert_equal(self.success, True)
2670
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002671 def test_500_flow_udp_port(self):
2672 egress = 1
2673 ingress = 2
2674 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 3100 }
2675 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 1100 }
ChetanGaonker720ea612016-06-21 17:54:25 -07002676 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002677
2678 for i in range(0,500):
2679 ingress_map['udp_port'] += 1
2680 egress_map['udp_port'] += 1
2681
2682 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002683 egressPort = egress + self.port_offset,
2684 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002685 udpSrc = ingress_map['udp_port'],
2686 udpDst = egress_map['udp_port']
2687 )
2688
2689 result = flow.addFlow()
2690 assert_equal(result, True)
2691 ##wait for flows to be added to ONOS
2692 time.sleep(1)
2693 log.info("%d flow added.",i+1)
2694
ChetanGaonker720ea612016-06-21 17:54:25 -07002695 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002696
ChetanGaonker720ea612016-06-21 17:54:25 -07002697 def verify_flow(*r):
2698 random_sport = int(''.join(r))
2699 random_dport = random_sport + 2000
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002700
ChetanGaonker720ea612016-06-21 17:54:25 -07002701 def mac_recv_task():
2702 def recv_cb(pkt):
2703 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
2704 success_dir[current_thread().name] = True
2705 sniff(count=2, timeout=5,
2706 lfilter = lambda p: UDP in p and p[UDP].dport == random_dport and p[UDP].sport == random_sport ,prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002707
ChetanGaonker720ea612016-06-21 17:54:25 -07002708 t = threading.Thread(target = mac_recv_task)
2709 t.start()
2710 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2711 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
2712 L4 = UDP(sport = random_sport, dport = random_dport)
2713 pkt = L2/L3/L4
2714 log.info('Sending packets to verify if flows are correct')
2715 sendp(pkt, count=50, iface = self.port_map[ingress])
2716 t.join()
2717
2718 t1 = threading.Thread(target = verify_flow, args = str(1101))
2719 t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1250,1)))
2720 t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1251,1400,1)))
2721 t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1401,1590,1)))
2722 t5 = threading.Thread(target = verify_flow, args = str(1600))
2723
2724
2725 t1.start()
2726 t2.start()
2727 t3.start()
2728 t4.start()
2729 t5.start()
2730
2731 t1.join()
2732 t2.join()
2733 t3.join()
2734 t4.join()
2735 t5.join()
2736
2737 if len(success_dir) != 5:
2738 self.success = False
2739
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002740 assert_equal(self.success, True)
2741
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002742 def test_1k_flow_udp_port(self):
2743 egress = 1
2744 ingress = 2
2745 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 3100 }
2746 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 1100 }
ChetanGaonker720ea612016-06-21 17:54:25 -07002747 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002748
ChetanGaonker720ea612016-06-21 17:54:25 -07002749 for i in range(0,100000):
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002750 ingress_map['udp_port'] += 1
2751 egress_map['udp_port'] += 1
2752
2753 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002754 egressPort = egress + self.port_offset,
2755 ingressPort = ingress + self.port_offset,
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002756 udpSrc = ingress_map['udp_port'],
2757 udpDst = egress_map['udp_port']
2758 )
2759
2760 result = flow.addFlow()
2761 assert_equal(result, True)
2762 ##wait for flows to be added to ONOS
2763 time.sleep(1)
2764 log.info("%d flow added.",i+1)
2765
ChetanGaonker720ea612016-06-21 17:54:25 -07002766 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002767
ChetanGaonker720ea612016-06-21 17:54:25 -07002768 def verify_flow(*r):
2769 random_sport = int(''.join(r))
2770 random_dport = random_sport + 2000
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002771
ChetanGaonker720ea612016-06-21 17:54:25 -07002772 def mac_recv_task():
2773 def recv_cb(pkt):
2774 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
2775 success_dir[current_thread().name] = True
2776 sniff(count=2, timeout=5,
2777 lfilter = lambda p: UDP in p and p[UDP].dport == random_dport and p[UDP].sport == random_sport ,prn = recv_cb, iface = self.port_map[egress])
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002778
ChetanGaonker720ea612016-06-21 17:54:25 -07002779 t = threading.Thread(target = mac_recv_task)
2780 t.start()
2781 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2782 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
2783 L4 = UDP(sport = random_sport, dport = random_dport)
2784 pkt = L2/L3/L4
2785 log.info('Sending packets to verify if flows are correct')
2786 sendp(pkt, count=50, iface = self.port_map[ingress])
2787 t.join()
2788
2789 t1 = threading.Thread(target = verify_flow, args = str(1101))
2790 t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1350,1)))
2791 t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1351,1500,1)))
2792 t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1501,1700,1)))
2793 t5 = threading.Thread(target = verify_flow, args = str(random.randrange(1701,1900,1)))
2794 t6 = threading.Thread(target = verify_flow, args = str(random.randrange(1901,2000,1)))
2795 t7 = threading.Thread(target = verify_flow, args = str(random.randrange(2000,2050,1)))
2796 t8 = threading.Thread(target = verify_flow, args = str(random.randrange(2050,2080,1)))
2797 t9 = threading.Thread(target = verify_flow, args = str(random.randrange(1102,2100,1)))
2798 t10 = threading.Thread(target = verify_flow, args = str(2100))
2799
2800 t1.start()
2801 t2.start()
2802 t3.start()
2803 t4.start()
2804 t5.start()
2805 t6.start()
2806 t7.start()
2807 t8.start()
2808 t9.start()
2809 t10.start()
2810
2811 t1.join()
2812 t2.join()
2813 t3.join()
2814 t4.join()
2815 t5.join()
2816 t6.join()
2817 t7.join()
2818 t8.join()
2819 t9.join()
2820 t10.join()
2821
2822 if len(success_dir) != 10:
2823 self.success = False
2824
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002825 assert_equal(self.success, True)
2826
2827 @nottest
2828 def test_10k_flow_udp_port(self):
2829 egress = 1
2830 ingress = 2
2831 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 31000 }
2832 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 11000 }
ChetanGaonker720ea612016-06-21 17:54:25 -07002833 success_dir = {}
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002834
2835 for i in range(0,10000):
ChetanGaonker720ea612016-06-21 17:54:25 -07002836 ingress_map['udp_port'] += 1
2837 egress_map['udp_port'] += 1
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002838
ChetanGaonker720ea612016-06-21 17:54:25 -07002839 flow = OnosFlowCtrl(deviceId = self.device_id,
A R Karthicke4660f52017-02-23 12:08:41 -08002840 egressPort = egress + self.port_offset,
2841 ingressPort = ingress + self.port_offset,
ChetanGaonker720ea612016-06-21 17:54:25 -07002842 udpSrc = ingress_map['udp_port'],
2843 udpDst = egress_map['udp_port']
2844 )
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002845
ChetanGaonker720ea612016-06-21 17:54:25 -07002846 result = flow.addFlow()
2847 assert_equal(result, True)
2848 ##wait for flows to be added to ONOS
2849 time.sleep(1)
2850 log.info("%d flow added.",i+1)
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002851
ChetanGaonker720ea612016-06-21 17:54:25 -07002852 self.success = True
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002853
ChetanGaonker720ea612016-06-21 17:54:25 -07002854 def verify_flow(*r):
2855 random_sport = int(''.join(r))
2856 random_dport = random_sport + 20000
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002857
ChetanGaonker720ea612016-06-21 17:54:25 -07002858 def mac_recv_task():
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002859
ChetanGaonker720ea612016-06-21 17:54:25 -07002860 def recv_cb(pkt):
2861 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
2862 success_dir[current_thread().name] = True
2863 sniff(count=2, timeout=5,
2864 lfilter = lambda p: UDP in p and p[UDP].dport == random_dport and p[UDP].sport == random_sport ,prn = recv_cb, iface = self.port_map[egress])
2865
2866 t = threading.Thread(target = mac_recv_task)
2867 t.start()
2868 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
2869 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
2870 L4 = UDP(sport = random_sport, dport = random_dport)
2871 pkt = L2/L3/L4
2872 log.info('Sending packets to verify if flows are correct')
2873 sendp(pkt, count=50, iface = self.port_map[ingress])
2874 t.join()
2875
2876 t1 = threading.Thread(target = verify_flow, args = str(11001))
2877 t2 = threading.Thread(target = verify_flow, args = str(random.randrange(11110,12501,1)))
2878 t3 = threading.Thread(target = verify_flow, args = str(random.randrange(12510,14001,1)))
2879 t4 = threading.Thread(target = verify_flow, args = str(random.randrange(14010,15900,1)))
2880 t5 = threading.Thread(target = verify_flow, args = str(random.randrange(16000,17000,1)))
2881 t6 = threading.Thread(target = verify_flow, args = str(random.randrange(17001,18000,1)))
2882 t7 = threading.Thread(target = verify_flow, args = str(random.randrange(18000,19000,1)))
2883 t8 = threading.Thread(target = verify_flow, args = str(random.randrange(19000,20980,1)))
2884 t9 = threading.Thread(target = verify_flow, args = str(random.randrange(11002,21000,1)))
2885 t10 = threading.Thread(target = verify_flow, args = str(21000))
2886
2887
2888 t1.start()
2889 t2.start()
2890 t3.start()
2891 t4.start()
2892 t5.start()
2893 t6.start()
2894 t7.start()
2895 t8.start()
2896 t9.start()
2897 t10.start()
2898
2899 t1.join()
2900 t2.join()
2901 t3.join()
2902 t4.join()
2903 t5.join()
2904 t6.join()
2905 t7.join()
2906 t8.join()
2907 t9.join()
2908 t10.join()
2909
2910 if len(success_dir) != 10:
2911 self.success = False
ChetanGaonkera6adc0b2016-06-12 12:21:14 -07002912 assert_equal(self.success, True)