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