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 |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 24 | import os |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 25 | from OnosCtrl import OnosCtrl |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 26 | from OnosFlowCtrl import OnosFlowCtrl, get_mac |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 27 | from OltConfig import OltConfig |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 28 | import random |
| 29 | from threading import current_thread |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 30 | import collections |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 31 | log.setLevel('INFO') |
| 32 | |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 33 | class flows_exchange(unittest.TestCase): |
| 34 | |
| 35 | #Use the first available device id as our device id to program flows |
| 36 | app = 'org.onosproject.cli' |
| 37 | PORT_TX_DEFAULT = 2 |
| 38 | PORT_RX_DEFAULT = 1 |
| 39 | INTF_TX_DEFAULT = 'veth2' |
| 40 | INTF_RX_DEFAULT = 'veth0' |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 41 | default_port_map = { |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 42 | PORT_TX_DEFAULT : INTF_TX_DEFAULT, |
| 43 | PORT_RX_DEFAULT : INTF_RX_DEFAULT, |
| 44 | INTF_TX_DEFAULT : PORT_TX_DEFAULT, |
| 45 | INTF_RX_DEFAULT : PORT_RX_DEFAULT |
| 46 | } |
| 47 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 48 | def incmac(self, mac): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 49 | tmp = str(hex(int('0x'+mac,16)+1).split('x')[1]) |
| 50 | mac = '0'+ tmp if len(tmp) < 2 else tmp |
| 51 | return mac |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 52 | |
| 53 | def next_mac(self, mac): |
| 54 | mac = mac.split(":") |
| 55 | mac[5] = self.incmac(mac[5]) |
| 56 | |
| 57 | if len(mac[5]) > 2: |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 58 | mac[0] = self.incmac(mac[0]) |
| 59 | mac[5] = '01' |
| 60 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 61 | if len(mac[0]) > 2: |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 62 | mac[0] = '01' |
| 63 | mac[1] = self.incmac(mac[1]) |
| 64 | mac[5] = '01' |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 65 | return ':'.join(mac) |
| 66 | |
| 67 | def to_egress_mac(cls, mac): |
| 68 | mac = mac.split(":") |
| 69 | mac[4] = '01' |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 70 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 71 | return ':'.join(mac) |
| 72 | |
| 73 | def inc_ip(self, ip, i): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 74 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 75 | ip[i] =str(int(ip[i])+1) |
| 76 | return '.'.join(ip) |
| 77 | |
| 78 | |
| 79 | def next_ip(self, ip): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 80 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 81 | lst = ip.split('.') |
| 82 | for i in (3,0,-1): |
| 83 | if int(lst[i]) < 255: |
| 84 | return self.inc_ip(lst, i) |
| 85 | elif int(lst[i]) == 255: |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 86 | lst[i] = '0' |
| 87 | if int(lst[i-1]) < 255: |
| 88 | return self.inc_ip(lst,i-1) |
| 89 | elif int(lst[i-2]) < 255: |
| 90 | lst[i-1] = '0' |
| 91 | return self.inc_ip(lst,i-2) |
| 92 | else: |
| 93 | break |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 94 | |
| 95 | def to_egress_ip(self, ip): |
| 96 | lst=ip.split('.') |
| 97 | lst[0] = '182' |
| 98 | return '.'.join(lst) |
| 99 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 100 | |
| 101 | |
| 102 | |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 103 | @classmethod |
| 104 | def setUpClass(cls): |
| 105 | cls.olt = OltConfig() |
| 106 | cls.port_map = cls.olt.olt_port_map() |
| 107 | if not cls.port_map: |
| 108 | cls.port_map = cls.default_port_map |
Chetan Gaonker | a9b6fcb | 2016-04-15 17:35:24 -0700 | [diff] [blame] | 109 | cls.device_id = 'of:' + get_mac() ##match against our device id |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 110 | |
| 111 | def test_flow_mac(self): |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 112 | '''Test Add and verify flows with MAC selectors''' |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 113 | egress = 1 |
| 114 | ingress = 2 |
| 115 | egress_mac = '00:00:00:00:00:01' |
| 116 | ingress_mac = '00:00:00:00:00:02' |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 117 | |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 118 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 119 | egressPort = egress, |
| 120 | ingressPort = ingress, |
| 121 | ethSrc = ingress_mac, |
| 122 | ethDst = egress_mac) |
| 123 | result = flow.addFlow() |
| 124 | assert_equal(result, True) |
| 125 | ##wait for flows to be added to ONOS |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 126 | time.sleep(1) |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 127 | self.success = False |
| 128 | def mac_recv_task(): |
| 129 | def recv_cb(pkt): |
| 130 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 131 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 132 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == ingress_mac, |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 133 | prn = recv_cb, iface = self.port_map[egress]) |
| 134 | |
| 135 | t = threading.Thread(target = mac_recv_task) |
| 136 | t.start() |
| 137 | pkt = Ether(src = ingress_mac, dst = egress_mac)/IP() |
| 138 | log.info('Sending a packet to verify if flows are correct') |
| 139 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 140 | t.join() |
| 141 | assert_equal(self.success, True) |
| 142 | |
| 143 | def test_flow_ip(self): |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 144 | '''Test Add and verify flows with IPv4 selectors''' |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 145 | egress = 1 |
| 146 | ingress = 2 |
| 147 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 148 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 149 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 150 | egressPort = egress, |
| 151 | ingressPort = ingress, |
| 152 | ethType = '0x0800', |
| 153 | ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'), |
| 154 | ipDst = ('IPV4_DST', egress_map['ip']+'/32') |
| 155 | ) |
| 156 | result = flow.addFlow() |
| 157 | assert_equal(result, True) |
| 158 | ##wait for flows to be added to ONOS |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 159 | time.sleep(1) |
Chetan Gaonker | 7ab338c | 2016-04-15 17:23:17 -0700 | [diff] [blame] | 160 | self.success = False |
| 161 | def mac_recv_task(): |
| 162 | def recv_cb(pkt): |
| 163 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
| 164 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 165 | sniff(count=2, timeout=5, |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 166 | 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] | 167 | prn = recv_cb, iface = self.port_map[egress]) |
| 168 | |
| 169 | t = threading.Thread(target = mac_recv_task) |
| 170 | t.start() |
| 171 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 172 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 173 | pkt = L2/L3 |
| 174 | log.info('Sending a packet to verify if flows are correct') |
| 175 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 176 | t.join() |
| 177 | assert_equal(self.success, True) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 178 | |
| 179 | |
| 180 | def test_flow_tcp_port(self): |
| 181 | egress = 1 |
| 182 | ingress = 2 |
| 183 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 9500 } |
| 184 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 9000 } |
| 185 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 186 | egressPort = egress, |
| 187 | ingressPort = ingress, |
| 188 | tcpSrc = ingress_map['tcp_port'], |
| 189 | tcpDst = egress_map['tcp_port'] |
| 190 | ) |
| 191 | result = flow.addFlow() |
| 192 | assert_equal(result, True) |
| 193 | ##wait for flows to be added to ONOS |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 194 | time.sleep(1) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 195 | self.success = False |
| 196 | def mac_recv_task(): |
| 197 | def recv_cb(pkt): |
| 198 | log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport)) |
| 199 | self.success = True |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 200 | sniff(count=2, timeout=5, lfilter = lambda p: TCP in p and p[TCP].dport == egress_map['tcp_port'] |
| 201 | and p[TCP].sport == ingress_map['tcp_port'], prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 202 | |
| 203 | t = threading.Thread(target = mac_recv_task) |
| 204 | t.start() |
| 205 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 206 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 207 | L4 = TCP(sport = ingress_map['tcp_port'], dport = egress_map['tcp_port']) |
| 208 | pkt = L2/L3/L4 |
| 209 | log.info('Sending packets to verify if flows are correct') |
| 210 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 211 | t.join() |
| 212 | assert_equal(self.success, True) |
| 213 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 214 | def test_flow_udp_port(self): |
| 215 | egress = 1 |
| 216 | ingress = 2 |
| 217 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 9500 } |
| 218 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 9000 } |
| 219 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 220 | egressPort = egress, |
| 221 | ingressPort = ingress, |
| 222 | udpSrc = ingress_map['udp_port'], |
| 223 | udpDst = egress_map['udp_port'] |
| 224 | ) |
| 225 | result = flow.addFlow() |
| 226 | assert_equal(result, True) |
| 227 | ##wait for flows to be added to ONOS |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 228 | time.sleep(1) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 229 | self.success = False |
| 230 | def mac_recv_task(): |
| 231 | def recv_cb(pkt): |
| 232 | log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport)) |
| 233 | self.success = True |
| 234 | sniff(count=2, timeout=5, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 235 | lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port'] |
| 236 | and p[UDP].sport == ingress_map['udp_port'], prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 237 | |
| 238 | t = threading.Thread(target = mac_recv_task) |
| 239 | t.start() |
| 240 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 241 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 242 | L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port']) |
| 243 | pkt = L2/L3/L4 |
| 244 | log.info('Sending packets to verify if flows are correct') |
| 245 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 246 | t.join() |
| 247 | assert_equal(self.success, True) |
| 248 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 249 | @nottest |
| 250 | def test_flow_vlan(self): |
| 251 | egress = 1 |
| 252 | ingress = 2 |
| 253 | egress_mac = '00:00:00:00:00:01' |
| 254 | ingress_mac = '00:00:00:00:00:02' |
| 255 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 256 | egressPort = egress, |
| 257 | ingressPort = ingress, |
| 258 | ethSrc = ingress_mac, |
| 259 | ethDst = egress_mac, |
| 260 | vlan = 0x10) |
| 261 | result = flow.addFlow() |
| 262 | assert_equal(result, True) |
| 263 | ##wait for flows to be added to ONOS |
| 264 | time.sleep(1) |
| 265 | self.success = False |
| 266 | def mac_recv_task(): |
| 267 | def recv_cb(pkt): |
| 268 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 269 | log.info('Pkt:%s', pkt.show()) |
| 270 | self.success = True |
| 271 | sniff(count=2, timeout=5, lfilter = lambda p:p.src == ingress_mac, |
| 272 | prn = recv_cb, iface = self.port_map[egress]) |
| 273 | |
| 274 | t = threading.Thread(target = mac_recv_task) |
| 275 | t.start() |
| 276 | pkt = Ether(src = ingress_mac, dst = egress_mac)/Dot1Q(vlan = 0x10)/IP() |
| 277 | log.info("Sending Packet:%s",pkt.show()) |
| 278 | log.info('Sending a packet to verify if flows are correct') |
| 279 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 280 | t.join() |
| 281 | assert_equal(self.success, True) |
| 282 | |
| 283 | def test_flow_ipv6(self): |
| 284 | egress = 1 |
| 285 | ingress = 2 |
| 286 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' } |
| 287 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 288 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 289 | egressPort = egress, |
| 290 | ingressPort = ingress, |
| 291 | ethType = '0x86dd', |
| 292 | ipSrc = ('IPV6_SRC', ingress_map['ipv6'] + '/48'), |
| 293 | ipDst = ('IPV6_DST', egress_map['ipv6'] + '/48') |
| 294 | ) |
| 295 | |
| 296 | result = flow.addFlow() |
| 297 | assert_equal(result, True) |
| 298 | ##wait for flows to be added to ONOS |
| 299 | time.sleep(1) |
| 300 | self.success = False |
| 301 | def mac_recv_task(): |
| 302 | def recv_cb(pkt): |
| 303 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IPv6].src, pkt[IPv6].dst)) |
| 304 | self.success = True |
| 305 | sniff(count=2, timeout=5, |
| 306 | lfilter = lambda p: IPv6 in p and p[IPv6].dst == egress_map['ipv6'] and p[IPv6].src == ingress_map['ipv6'], |
| 307 | prn = recv_cb, iface = self.port_map[egress]) |
| 308 | |
| 309 | t = threading.Thread(target = mac_recv_task) |
| 310 | t.start() |
| 311 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 312 | L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6']) |
| 313 | pkt = L2/L3 |
| 314 | log.info('Sending a packet to verify if flows are correct') |
| 315 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 316 | t.join() |
| 317 | assert_equal(self.success, True) |
| 318 | |
| 319 | def test_flow_ipv6_flow_label(self): |
| 320 | egress = 1 |
| 321 | ingress = 2 |
| 322 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' } |
| 323 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 324 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 325 | egressPort = egress, |
| 326 | ingressPort = ingress, |
| 327 | ipv6flow_label = 25 |
| 328 | ) |
| 329 | |
| 330 | result = flow.addFlow() |
| 331 | assert_equal(result, True) |
| 332 | ##wait for flows to be added to ONOS |
| 333 | time.sleep(1) |
| 334 | self.success = False |
| 335 | def mac_recv_task(): |
| 336 | def recv_cb(pkt): |
| 337 | log.info('Pkt seen with ingress ip %s, egress ip %s with flow label %s' %(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].fl)) |
| 338 | self.success = True |
| 339 | sniff(count=2, timeout=5, lfilter = lambda p: IPv6 in p and p[IPv6].dst == egress_map['ipv6'] |
| 340 | and p[IPv6].src == ingress_map['ipv6'] and p[IPv6].fl == 25, prn = recv_cb, iface = self.port_map[egress]) |
| 341 | |
| 342 | t = threading.Thread(target = mac_recv_task) |
| 343 | t.start() |
| 344 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 345 | L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], fl = 25) |
| 346 | pkt = L2/L3 |
| 347 | log.info('Sending a packet to verify if flows are correct') |
| 348 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 349 | t.join() |
| 350 | assert_equal(self.success, True) |
| 351 | |
| 352 | def test_flow_ipv6_extension_header(self): |
| 353 | egress = 1 |
| 354 | ingress = 2 |
| 355 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' } |
| 356 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 357 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 358 | egressPort = egress, |
| 359 | ingressPort = ingress, |
| 360 | ipv6_extension = 0, |
| 361 | ) |
| 362 | |
| 363 | result = flow.addFlow() |
| 364 | assert_equal(result, True) |
| 365 | ##wait for flows to be added to ONOS |
| 366 | time.sleep(1) |
| 367 | self.success = False |
| 368 | def mac_recv_task(): |
| 369 | def recv_cb(pkt): |
| 370 | log.info('Pkt seen with ingress ip %s, egress ip %s, Extension Header Type %s' %(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].nh)) |
| 371 | self.success = True |
| 372 | sniff(count=2, timeout=5, |
| 373 | lfilter = lambda p: IPv6 in p and p[IPv6].nh == 0, prn = recv_cb, iface = self.port_map[egress]) |
| 374 | |
| 375 | t = threading.Thread(target = mac_recv_task) |
| 376 | t.start() |
| 377 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 378 | L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], nh = 0) |
| 379 | pkt = L2/L3 |
| 380 | log.info('Sending packets to verify if flows are correct') |
| 381 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 382 | t.join() |
| 383 | assert_equal(self.success, True) |
| 384 | |
| 385 | def test_flow_ipv6_available_extension_headers(self): |
| 386 | egress = 1 |
| 387 | ingress = 2 |
| 388 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' } |
| 389 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 390 | for i in [0, 60, 43, 44, 51, 50, 135]: |
| 391 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 392 | egressPort = egress, |
| 393 | ingressPort = ingress, |
| 394 | ipv6_extension = i, |
| 395 | ) |
| 396 | |
| 397 | result = flow.addFlow() |
| 398 | assert_equal(result, True) |
| 399 | ##wait for flows to be added to ONOS |
| 400 | time.sleep(1) |
| 401 | def mac_recv_task(): |
| 402 | def recv_cb(pkt): |
| 403 | log.info('Pkt seen with ingress ip %s, egress ip %s, Extension Header Type %s' %(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].nh)) |
| 404 | self.success = True |
| 405 | sniff(count=2, timeout=5, lfilter = lambda p: IPv6 in p and p[IPv6].nh == i, |
| 406 | prn = recv_cb, iface = self.port_map[egress]) |
| 407 | |
| 408 | for i in [0, 60, 43, 44, 51, 50, 135]: |
| 409 | self.success = False |
| 410 | t = threading.Thread(target = mac_recv_task) |
| 411 | t.start() |
| 412 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 413 | L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], nh = i) |
| 414 | pkt = L2/L3 |
| 415 | log.info('Sending packets to verify if flows are correct') |
| 416 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 417 | t.join() |
| 418 | assert_equal(self.success, True) |
| 419 | |
| 420 | |
| 421 | def test_flow_dscp(self): |
| 422 | egress = 1 |
| 423 | ingress = 2 |
| 424 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 425 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 426 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 427 | egressPort = egress, |
| 428 | ingressPort = ingress, |
| 429 | dscp = 32 |
| 430 | ) |
| 431 | result = flow.addFlow() |
| 432 | assert_equal(result, True) |
| 433 | ##wait for flows to be added to ONOS |
| 434 | time.sleep(1) |
| 435 | self.success = False |
| 436 | def mac_recv_task(): |
| 437 | def recv_cb(pkt): |
| 438 | 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)) |
| 439 | self.success = True |
| 440 | sniff(count=2, timeout=5, |
| 441 | lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'] |
| 442 | and p[IP].tos == 32,prn = recv_cb, iface = self.port_map[egress]) |
| 443 | |
| 444 | t = threading.Thread(target = mac_recv_task) |
| 445 | t.start() |
| 446 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 447 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = 32) |
| 448 | pkt = L2/L3 |
| 449 | log.info('Sending a packet to verify if flows are correct') |
| 450 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 451 | t.join() |
| 452 | assert_equal(self.success, True) |
| 453 | |
| 454 | def test_flow_available_dscp(self): |
| 455 | egress = 1 |
| 456 | ingress = 2 |
| 457 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 458 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 459 | dscp = [184, 0, 40, 48, 56, 72, 80, 88, 104, 112, 120, 136, 144, 152, 32, 64, 96, 128, 160, 192, 224] |
| 460 | for i in dscp: |
| 461 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 462 | egressPort = egress, |
| 463 | ingressPort = ingress, |
| 464 | dscp = i |
| 465 | ) |
| 466 | result = flow.addFlow() |
| 467 | assert_equal(result, True) |
| 468 | ##wait for flows to be added to ONOS |
| 469 | time.sleep(1) |
| 470 | |
| 471 | def mac_recv_task(): |
| 472 | def recv_cb(pkt): |
| 473 | 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)) |
| 474 | self.success = True |
| 475 | sniff(count=2, timeout=5, |
| 476 | lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'] |
| 477 | and p[IP].tos == i,prn = recv_cb, iface = self.port_map[egress]) |
| 478 | |
| 479 | for i in dscp: |
| 480 | self.success = False |
| 481 | t = threading.Thread(target = mac_recv_task) |
| 482 | t.start() |
| 483 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 484 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = i) |
| 485 | pkt = L2/L3 |
| 486 | log.info('Sending a packet to verify if flows are correct') |
| 487 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 488 | t.join() |
| 489 | assert_equal(self.success, True) |
| 490 | |
| 491 | def test_flow_ecn(self): |
| 492 | egress = 1 |
| 493 | ingress = 2 |
| 494 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 495 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 496 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 497 | egressPort = egress, |
| 498 | ingressPort = ingress, |
| 499 | ecn = 1 |
| 500 | ) |
| 501 | result = flow.addFlow() |
| 502 | assert_equal(result, True) |
| 503 | ##wait for flows to be added to ONOS |
| 504 | time.sleep(1) |
| 505 | self.success = False |
| 506 | def mac_recv_task(): |
| 507 | def recv_cb(pkt): |
| 508 | 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)) |
| 509 | self.success = True |
| 510 | sniff(count=2, timeout=5, |
| 511 | lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'] |
| 512 | and int(bin(p[IP].tos).split('b')[1][-2:],2) == 1,prn = recv_cb, |
| 513 | iface = self.port_map[egress]) |
| 514 | |
| 515 | t = threading.Thread(target = mac_recv_task) |
| 516 | t.start() |
| 517 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 518 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = 1) |
| 519 | pkt = L2/L3 |
| 520 | log.info('Sending a packet to verify if flows are correct') |
| 521 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 522 | t.join() |
| 523 | assert_equal(self.success, True) |
| 524 | |
| 525 | |
| 526 | def test_flow_available_ecn(self): |
| 527 | egress = 1 |
| 528 | ingress = 2 |
| 529 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 530 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 531 | for i in range(4): |
| 532 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 533 | egressPort = egress, |
| 534 | ingressPort = ingress, |
| 535 | ecn = i |
| 536 | ) |
| 537 | result = flow.addFlow() |
| 538 | assert_equal(result, True) |
| 539 | ##wait for flows to be added to ONOS |
| 540 | time.sleep(1) |
| 541 | def mac_recv_task(): |
| 542 | def recv_cb(pkt): |
| 543 | 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)) |
| 544 | self.success = True |
| 545 | sniff(count=2, timeout=5, |
| 546 | lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'] |
| 547 | and int(bin(p[IP].tos).split('b')[1][-2:],2) == i,prn = recv_cb, |
| 548 | iface = self.port_map[egress]) |
| 549 | |
| 550 | for i in range(4): |
| 551 | self.success = False |
| 552 | t = threading.Thread(target = mac_recv_task) |
| 553 | t.start() |
| 554 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 555 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = i) |
| 556 | pkt = L2/L3 |
| 557 | log.info('Sending a packet to verify if flows are correct') |
| 558 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 559 | t.join() |
| 560 | assert_equal(self.success, True) |
| 561 | |
| 562 | def test_flow_available_dscp_and_ecn(self): |
| 563 | egress = 1 |
| 564 | ingress = 2 |
| 565 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 566 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 567 | dscp = [46, 0, 10, 12, 14, 18, 20, 22, 26, 28, 30, 34, 36, 38, 8, 16, 24, 32, 40, 48, 56] |
| 568 | for i in dscp: |
| 569 | for j in (0,1,2,3): |
| 570 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 571 | egressPort = egress, |
| 572 | ingressPort = ingress, |
| 573 | dscp = i, |
| 574 | ecn = j |
| 575 | ) |
| 576 | result = flow.addFlow() |
| 577 | assert_equal(result, True) |
| 578 | ##wait for flows to be added to ONOS |
| 579 | time.sleep(1) |
| 580 | |
| 581 | def mac_recv_task(): |
| 582 | def recv_cb(pkt): |
| 583 | 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)) |
| 584 | self.success = True |
| 585 | sniff(count=2, timeout=5, |
| 586 | lfilter = lambda p: IP in p and p[IP].tos == int(bin(i).split('b')[1]+ bin(j).split('b')[1],2) |
| 587 | ,prn = recv_cb, iface = self.port_map[egress]) |
| 588 | |
| 589 | for i in dscp: |
| 590 | for j in (0,1,2,3): |
| 591 | |
| 592 | self.success = False |
| 593 | t = threading.Thread(target = mac_recv_task) |
| 594 | t.start() |
| 595 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 596 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = int(bin(i).split('b')[1]+ bin(j).split('b')[1],2)) |
| 597 | pkt = L2/L3 |
| 598 | log.info('Sending packets to verify if flows are correct') |
| 599 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 600 | t.join() |
| 601 | assert_equal(self.success, True) |
| 602 | |
| 603 | def test_flow_icmp(self): |
| 604 | egress = 1 |
| 605 | ingress = 2 |
| 606 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 607 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 608 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 609 | egressPort = egress, |
| 610 | ingressPort = ingress, |
| 611 | icmpv4_type = '3', |
| 612 | icmpv4_code = 8 |
| 613 | ) |
| 614 | result = flow.addFlow() |
| 615 | assert_equal(result, True) |
| 616 | ##wait for flows to be added to ONOS |
| 617 | time.sleep(1) |
| 618 | self.success = False |
| 619 | |
| 620 | def mac_recv_task(): |
| 621 | def recv_cb(pkt): |
| 622 | log.info('Pkt seen with ICMP type %s, ICMP code %s' %(pkt[ICMP].type, pkt[ICMP].code)) |
| 623 | self.success = True |
| 624 | sniff(count=2, timeout=5, |
| 625 | lfilter = lambda p: ICMP in p and p[ICMP].type == 3 and p[ICMP].code == 8, |
| 626 | prn = recv_cb, iface = self.port_map[egress]) |
| 627 | |
| 628 | t = threading.Thread(target = mac_recv_task) |
| 629 | t.start() |
| 630 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 631 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])/ICMP(type = 3, code = 8) |
| 632 | pkt = L2/L3 |
| 633 | log.info('Sending a packet to verify if flows are correct') |
| 634 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 635 | t.join() |
| 636 | assert_equal(self.success, True) |
| 637 | |
| 638 | def test_flow_icmp_different_types(self): |
| 639 | egress = 1 |
| 640 | ingress = 2 |
| 641 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 642 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 643 | 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], |
| 644 | '5': [1, 2, 3], '4': 0, '9': 0, '8': 0} |
| 645 | for type,code in icmp.items(): |
| 646 | if isinstance(code, list): |
| 647 | for i in code: |
| 648 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 649 | egressPort = egress, |
| 650 | ingressPort = ingress, |
| 651 | icmpv4_type = type, |
| 652 | icmpv4_code = i |
| 653 | ) |
| 654 | result = flow.addFlow() |
| 655 | assert_equal(result, True) |
| 656 | ##wait for flows to be added to ONOS |
| 657 | time.sleep(1) |
| 658 | else: |
| 659 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 660 | egressPort = egress, |
| 661 | ingressPort = ingress, |
| 662 | icmpv4_type = type, |
| 663 | icmpv4_code = code |
| 664 | ) |
| 665 | result = flow.addFlow() |
| 666 | assert_equal(result, True) |
| 667 | ##wait for flows to be added to ONOS |
| 668 | time.sleep(1) |
| 669 | self.success = False |
| 670 | |
| 671 | def mac_recv_task(): |
| 672 | def recv_cb(pkt): |
| 673 | log.info('Pkt seen with ICMP type %s, ICMP code %s' %(pkt[ICMP].type, pkt[ICMP].code)) |
| 674 | self.success = True |
| 675 | sniff(count=2, timeout=5, |
| 676 | lfilter = lambda p: ICMP in p and p[ICMP].type == 3 and p[ICMP].code == 8, |
| 677 | prn = recv_cb, iface = self.port_map[egress]) |
| 678 | |
| 679 | t = threading.Thread(target = mac_recv_task) |
| 680 | t.start() |
| 681 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 682 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])/ICMP(type = 3, code = 8) |
| 683 | pkt = L2/L3 |
| 684 | log.info('Sending a packet to verify if flows are correct') |
| 685 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 686 | t.join() |
| 687 | assert_equal(self.success, True) |
| 688 | |
| 689 | def test_flow_icmpv6_EchoRequest(self): |
| 690 | egress = 1 |
| 691 | ingress = 2 |
| 692 | egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 693 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'} |
| 694 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 695 | egressPort = egress, |
| 696 | ingressPort = ingress, |
| 697 | icmpv6_type = '128', |
| 698 | icmpv6_code = 0 |
| 699 | ) |
| 700 | result = flow.addFlow() |
| 701 | assert_equal(result, True) |
| 702 | ##wait for flows to be added to ONOS |
| 703 | time.sleep(1) |
| 704 | self.success = False |
| 705 | def mac_recv_task(): |
| 706 | def recv_cb(pkt): |
| 707 | log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6EchoRequest].type, pkt[ICMPv6EchoRequest].code)) |
| 708 | self.success = True |
| 709 | sniff(count=2, timeout=5, |
| 710 | lfilter = lambda p: ICMPv6EchoRequest in p and p[ICMPv6EchoRequest].type == 128 and p[ICMPv6EchoRequest].code == 0, |
| 711 | prn = recv_cb, iface = self.port_map[egress]) |
| 712 | |
| 713 | t = threading.Thread(target = mac_recv_task) |
| 714 | t.start() |
| 715 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 716 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6EchoRequest() |
| 717 | pkt = L2/L3 |
| 718 | log.info('Sending a packet to verify if flows are correct') |
| 719 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 720 | t.join() |
| 721 | assert_equal(self.success, True) |
| 722 | |
| 723 | def test_flow_icmpv6_EchoReply(self): |
| 724 | egress = 1 |
| 725 | ingress = 2 |
| 726 | egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 727 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 728 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 729 | egressPort = egress, |
| 730 | ingressPort = ingress, |
| 731 | icmpv6_type = '129', |
| 732 | icmpv6_code = 0 |
| 733 | ) |
| 734 | result = flow.addFlow() |
| 735 | assert_equal(result, True) |
| 736 | ##wait for flows to be added to ONOS |
| 737 | time.sleep(1) |
| 738 | self.success = False |
| 739 | def mac_recv_task(): |
| 740 | def recv_cb(pkt): |
| 741 | log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6EchoReply].type, pkt[ICMPv6EchoReply].code)) |
| 742 | self.success = True |
| 743 | sniff(count=2, timeout=5, |
| 744 | lfilter = lambda p: ICMPv6EchoReply in p and p[ICMPv6EchoReply].type == 129 and p[ICMPv6EchoReply].code == 0, |
| 745 | prn = recv_cb, iface = self.port_map[egress]) |
| 746 | |
| 747 | t = threading.Thread(target = mac_recv_task) |
| 748 | t.start() |
| 749 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 750 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6EchoReply() |
| 751 | pkt = L2/L3 |
| 752 | log.info('Sending packets to verify if flows are correct') |
| 753 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 754 | t.join() |
| 755 | assert_equal(self.success, True) |
| 756 | |
| 757 | |
| 758 | def test_flow_icmpv6_DestUnreachable(self): |
| 759 | egress = 1 |
| 760 | ingress = 2 |
| 761 | egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 762 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 763 | for i in range(8): |
| 764 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 765 | egressPort = egress, |
| 766 | ingressPort = ingress, |
| 767 | icmpv6_type = '1', |
| 768 | icmpv6_code = i |
| 769 | ) |
| 770 | result = flow.addFlow() |
| 771 | assert_equal(result, True) |
| 772 | ##wait for flows to be added to ONOS |
| 773 | time.sleep(1) |
| 774 | for i in range(8): |
| 775 | self.success = False |
| 776 | def mac_recv_task(): |
| 777 | def recv_cb(pkt): |
| 778 | log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6DestUnreach].type, pkt[ICMPv6DestUnreach].code)) |
| 779 | self.success = True |
| 780 | sniff(count=2, timeout=5, |
| 781 | lfilter = lambda p: ICMPv6DestUnreach in p and p[ICMPv6DestUnreach].type == 1 and p[ICMPv6DestUnreach].code == i, |
| 782 | prn = recv_cb, iface = self.port_map[egress]) |
| 783 | |
| 784 | t = threading.Thread(target = mac_recv_task) |
| 785 | t.start() |
| 786 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 787 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6DestUnreach(code = i) |
| 788 | pkt = L2/L3 |
| 789 | log.info('Sending packets to verify if flows are correct') |
| 790 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 791 | t.join() |
| 792 | assert_equal(self.success, True) |
| 793 | |
| 794 | def test_flow_icmpv6_PacketTooBig(self): |
| 795 | egress = 1 |
| 796 | ingress = 2 |
| 797 | egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 798 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 799 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 800 | egressPort = egress, |
| 801 | ingressPort = ingress, |
| 802 | icmpv6_type = '2', |
| 803 | icmpv6_code = 0 |
| 804 | ) |
| 805 | result = flow.addFlow() |
| 806 | assert_equal(result, True) |
| 807 | ##wait for flows to be added to ONOS |
| 808 | time.sleep(1) |
| 809 | self.success = False |
| 810 | def mac_recv_task(): |
| 811 | def recv_cb(pkt): |
| 812 | log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6PacketTooBig].type, pkt[ICMPv6PacketTooBig].code)) |
| 813 | self.success = True |
| 814 | sniff(count=2, timeout=5, |
| 815 | lfilter = lambda p: ICMPv6PacketTooBig in p and p[ICMPv6PacketTooBig].type == 2 and p[ICMPv6PacketTooBig].code == 0, |
| 816 | prn = recv_cb, iface = self.port_map[egress]) |
| 817 | |
| 818 | t = threading.Thread(target = mac_recv_task) |
| 819 | t.start() |
| 820 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 821 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6PacketTooBig() |
| 822 | pkt = L2/L3 |
| 823 | log.info('Sending packets to verify if flows are correct') |
| 824 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 825 | t.join() |
| 826 | assert_equal(self.success, True) |
| 827 | |
| 828 | def test_flow_icmpv6_TimeExceeded(self): |
| 829 | egress = 1 |
| 830 | ingress = 2 |
| 831 | egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 832 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 833 | for i in range(2): |
| 834 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 835 | egressPort = egress, |
| 836 | ingressPort = ingress, |
| 837 | icmpv6_type = '3', |
| 838 | icmpv6_code = i |
| 839 | ) |
| 840 | result = flow.addFlow() |
| 841 | assert_equal(result, True) |
| 842 | ##wait for flows to be added to ONOS |
| 843 | time.sleep(1) |
| 844 | for i in range(2): |
| 845 | self.success = False |
| 846 | def mac_recv_task(): |
| 847 | def recv_cb(pkt): |
| 848 | log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6TimeExceeded].type, pkt[ICMPv6TimeExceeded].code)) |
| 849 | self.success = True |
| 850 | sniff(count=2, timeout=5, |
| 851 | lfilter = lambda p: ICMPv6TimeExceeded in p and p[ICMPv6TimeExceeded].type == 3 and p[ICMPv6TimeExceeded].code == i, |
| 852 | prn = recv_cb, iface = self.port_map[egress]) |
| 853 | |
| 854 | t = threading.Thread(target = mac_recv_task) |
| 855 | t.start() |
| 856 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 857 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6TimeExceeded(code = i) |
| 858 | pkt = L2/L3 |
| 859 | log.info('Sending packets to verify if flows are correct') |
| 860 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 861 | t.join() |
| 862 | assert_equal(self.success, True) |
| 863 | |
| 864 | def test_flow_icmpv6_ParameterProblem(self): |
| 865 | egress = 1 |
| 866 | ingress = 2 |
| 867 | egress_map = { 'ether': '00:00:00:00:00:03','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 868 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 869 | for i in range(3): |
| 870 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 871 | egressPort = egress, |
| 872 | ingressPort = ingress, |
| 873 | icmpv6_type = '4', |
| 874 | icmpv6_code = i |
| 875 | ) |
| 876 | result = flow.addFlow() |
| 877 | assert_equal(result, True) |
| 878 | ##wait for flows to be added to ONOS |
| 879 | time.sleep(1) |
| 880 | for i in range(3): |
| 881 | self.success = False |
| 882 | def mac_recv_task(): |
| 883 | def recv_cb(pkt): |
| 884 | log.info('Pkt seen with ICMPv6 type %s, ICMPv6 code %s' %(pkt[ICMPv6ParamProblem].type, pkt[ICMPv6ParamProblem].code)) |
| 885 | self.success = True |
| 886 | sniff(count=2, timeout=5, |
| 887 | lfilter = lambda p: ICMPv6ParamProblem in p and p[ICMPv6ParamProblem].type == 4 and p[ICMPv6ParamProblem].code == i, |
| 888 | prn = recv_cb, iface = self.port_map[egress]) |
| 889 | |
| 890 | t = threading.Thread(target = mac_recv_task) |
| 891 | t.start() |
| 892 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 893 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6ParamProblem(code = i) |
| 894 | pkt = L2/L3 |
| 895 | log.info('Sending packets to verify if flows are correct') |
| 896 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 897 | t.join() |
| 898 | assert_equal(self.success, True) |
| 899 | |
| 900 | def test_flow_icmpv6_ND_Target_address(self): |
| 901 | egress = 1 |
| 902 | ingress = 2 |
| 903 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'} |
| 904 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 905 | egressPort = egress, |
| 906 | ingressPort = ingress, |
| 907 | ipv6_target = '2001:db8:a0b:12f0:1010:1010:1010:1001') |
| 908 | result = flow.addFlow() |
| 909 | assert_equal(result, True) |
| 910 | ##wait for flows to be added to ONOS |
| 911 | time.sleep(1) |
| 912 | self.success = False |
| 913 | def mac_recv_task(): |
| 914 | def recv_cb(pkt): |
| 915 | log.info('Pkt seen with ICMPv6 Neighbor Discovery type %s, target address %s' %(pkt[ICMPv6ND_NS].type, pkt[ICMPv6ND_NS].tgt)) |
| 916 | self.success = True |
| 917 | sniff(count=2, timeout=5, |
| 918 | lfilter = lambda p: ICMPv6ND_NS in p and p[ICMPv6ND_NS].tgt == '2001:db8:a0b:12f0:1010:1010:1010:1001', |
| 919 | prn = recv_cb, iface = self.port_map[egress]) |
| 920 | |
| 921 | t = threading.Thread(target = mac_recv_task) |
| 922 | t.start() |
| 923 | L2 = Ether(src = ingress_map['ether']) |
| 924 | L3 = IPv6(src = ingress_map['ipv6'])/ICMPv6ND_NS(tgt = '2001:db8:a0b:12f0:1010:1010:1010:1001') |
| 925 | pkt = L2/L3 |
| 926 | log.info('Sending packets to verify if flows are correct') |
| 927 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 928 | t.join() |
| 929 | assert_equal(self.success, True) |
| 930 | |
| 931 | def test_flow_icmpv6_ND_SLL(self): |
| 932 | egress = 1 |
| 933 | ingress = 2 |
| 934 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 935 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'} |
| 936 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 937 | egressPort = egress, |
| 938 | ingressPort = ingress, |
| 939 | ipv6_sll = ingress_map['ether']) |
| 940 | result = flow.addFlow() |
| 941 | assert_equal(result, True) |
| 942 | ##wait for flows to be added to ONOS |
| 943 | time.sleep(1) |
| 944 | self.success = False |
| 945 | def mac_recv_task(): |
| 946 | def recv_cb(pkt): |
| 947 | log.info('Pkt seen with ICMPv6 Neighbor Discovery type %s, Source Link Layer address %s' %(pkt[ICMPv6ND_NS].type, pkt[ICMPv6NDOptSrcLLAddr].lladdr)) |
| 948 | self.success = True |
| 949 | sniff(count=2, timeout=5, |
| 950 | lfilter = lambda p: ICMPv6NDOptSrcLLAddr in p and p[ICMPv6NDOptSrcLLAddr].lladdr == ingress_map['ether'], |
| 951 | prn = recv_cb, iface = self.port_map[egress]) |
| 952 | |
| 953 | t = threading.Thread(target = mac_recv_task) |
| 954 | t.start() |
| 955 | L2 = Ether(src = ingress_map['ether'])#, dst = ingress_map['ether']) |
| 956 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6ND_NS(tgt = egress_map['ipv6'])/ICMPv6NDOptSrcLLAddr(lladdr = ingress_map['ether']) |
| 957 | pkt = L2/L3 |
| 958 | log.info('Sending packets to verify if flows are correct') |
| 959 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 960 | t.join() |
| 961 | assert_equal(self.success, True) |
| 962 | |
| 963 | def test_flow_icmpv6_NA_TLL(self): |
| 964 | egress = 1 |
| 965 | ingress = 2 |
| 966 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001'} |
| 967 | ingress_map = { 'ether': '00:00:00:00:00:04','ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002'} |
| 968 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 969 | egressPort = egress, |
| 970 | ingressPort = ingress, |
| 971 | ipv6_tll = egress_map['ether']) |
| 972 | result = flow.addFlow() |
| 973 | assert_equal(result, True) |
| 974 | ##wait for flows to be added to ONOS |
| 975 | time.sleep(1) |
| 976 | self.success = False |
| 977 | def mac_recv_task(): |
| 978 | def recv_cb(pkt): |
| 979 | log.info('Pkt seen with ICMPv6 Neighbor Advertisement type %s, Target Link Layer address %s' %(pkt[ICMPv6ND_NA].type, pkt[ICMPv6NDOptDstLLAddr].lladdr)) |
| 980 | self.success = True |
| 981 | sniff(count=2, timeout=5, |
| 982 | lfilter = lambda p: ICMPv6NDOptDstLLAddr in p and p[ICMPv6NDOptDstLLAddr].lladdr == ingress_map['ether'], |
| 983 | prn = recv_cb, iface = self.port_map[egress]) |
| 984 | |
| 985 | t = threading.Thread(target = mac_recv_task) |
| 986 | t.start() |
| 987 | L2 = Ether(src = ingress_map['ether'])#, dst = ingress_map['ether']) |
| 988 | L3 = IPv6(src = ingress_map['ipv6'], dst = egress_map['ipv6'])/ICMPv6ND_NA(tgt = ingress_map['ipv6'])/ICMPv6NDOptDstLLAddr(lladdr = ingress_map['ether']) |
| 989 | pkt = L2/L3 |
| 990 | log.info('Sending packets to verify if flows are correct') |
| 991 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 992 | t.join() |
| 993 | assert_equal(self.success, True) |
| 994 | |
| 995 | def test_flow_ipv6_and_icmpv6(self): |
| 996 | egress = 1 |
| 997 | ingress = 2 |
| 998 | egress_map = { 'ether': '00:00:00:00:00:03', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' } |
| 999 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' } |
| 1000 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1001 | egressPort = egress, |
| 1002 | ingressPort = ingress, |
| 1003 | ethType = '0x86dd', |
| 1004 | ipSrc = ('IPV6_SRC', ingress_map['ipv6'] + '/48'), |
| 1005 | ipDst = ('IPV6_DST', egress_map['ipv6'] + '/48'), |
| 1006 | icmpv6_type = '128', |
| 1007 | icmpv6_code = 0 |
| 1008 | ) |
| 1009 | |
| 1010 | result = flow.addFlow() |
| 1011 | assert_equal(result, True) |
| 1012 | ##wait for flows to be added to ONOS |
| 1013 | time.sleep(1) |
| 1014 | self.success = False |
| 1015 | |
| 1016 | def mac_recv_task(): |
| 1017 | def recv_cb(pkt): |
| 1018 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IPv6].src, pkt[IPv6].dst)) |
| 1019 | self.success = True |
| 1020 | sniff(count=2, timeout=5, |
| 1021 | lfilter = lambda p: IPv6 in p and p[IPv6].dst == egress_map['ipv6'] and p[IPv6].src == ingress_map['ipv6'] |
| 1022 | and p[ICMPv6EchoRequest].type == 128 and p[ICMPv6EchoRequest].code == 0, prn = recv_cb, iface = self.port_map[egress]) |
| 1023 | |
| 1024 | t = threading.Thread(target = mac_recv_task) |
| 1025 | t.start() |
| 1026 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 1027 | L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'])/ICMPv6EchoRequest() |
| 1028 | pkt = L2/L3 |
| 1029 | log.info('Sending a packet to verify if flows are correct') |
| 1030 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1031 | t.join() |
| 1032 | assert_equal(self.success, True) |
| 1033 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1034 | def test_5_flow_constant_dst_mac(self): |
| 1035 | egress = 1 |
| 1036 | ingress = 2 |
| 1037 | egress_mac = '00:00:00:00:01:01' |
| 1038 | ingress_mac = '00:00:00:00:00:00' |
| 1039 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1040 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1041 | for i in range(0,5): |
| 1042 | ingress_mac = self.next_mac(ingress_mac) |
| 1043 | |
| 1044 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1045 | egressPort = egress, |
| 1046 | ingressPort = ingress, |
| 1047 | ethSrc = ingress_mac, |
| 1048 | ethDst = egress_mac) |
| 1049 | result = flow.addFlow() |
| 1050 | assert_equal(result, True) |
| 1051 | ##wait for flows to be added to ONOS |
| 1052 | time.sleep(1) |
| 1053 | log.info("%d flow added.",i+1) |
| 1054 | self.success = False |
| 1055 | |
| 1056 | def mac_recv_task(): |
| 1057 | def recv_cb(pkt): |
| 1058 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1059 | self.success = True |
| 1060 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == '00:00:00:00:00:02', |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1061 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1062 | |
| 1063 | t = threading.Thread(target = mac_recv_task) |
| 1064 | t.start() |
| 1065 | pkt = Ether(src = '00:00:00:00:00:02', dst = egress_mac)/IP() |
| 1066 | log.info('Sending packets to verify if flows are correct') |
| 1067 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1068 | t.join() |
| 1069 | assert_equal(self.success, True) |
| 1070 | |
| 1071 | |
| 1072 | def test_500_flow_constant_dst_mac(self): |
| 1073 | egress = 1 |
| 1074 | ingress = 2 |
| 1075 | egress_mac = '00:00:00:00:01:01' |
| 1076 | ingress_mac = '00:00:00:00:00:00' |
| 1077 | success_dir = {} |
| 1078 | |
| 1079 | for i in range(0,500): |
| 1080 | ingress_mac = self.next_mac(ingress_mac) |
| 1081 | |
| 1082 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1083 | egressPort = egress, |
| 1084 | ingressPort = ingress, |
| 1085 | ethSrc = ingress_mac, |
| 1086 | ethDst = egress_mac) |
| 1087 | result = flow.addFlow() |
| 1088 | assert_equal(result, True) |
| 1089 | ##wait for flows to be added to ONOS |
| 1090 | time.sleep(1) |
| 1091 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1092 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1093 | |
| 1094 | def verify_flow(*r): |
| 1095 | random_src = ''.join(r) |
| 1096 | def mac_recv_task(): |
| 1097 | def recv_cb(pkt): |
| 1098 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1099 | success_dir[current_thread().name] = True |
| 1100 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1101 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1102 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1103 | t = threading.Thread(target = mac_recv_task) |
| 1104 | t.start() |
| 1105 | pkt = Ether(src = random_src, dst = egress_mac)/IP() |
| 1106 | log.info('Sending packets to verify if flows are correct') |
| 1107 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1108 | t.join() |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1109 | |
| 1110 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1111 | t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1]) |
| 1112 | t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,100)).split('x')[1]) |
| 1113 | t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(101,240)).split('x')[1]) |
| 1114 | t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:f5') |
| 1115 | t1.start() |
| 1116 | t2.start() |
| 1117 | t3.start() |
| 1118 | t4.start() |
| 1119 | t5.start() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1120 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1121 | t1.join() |
| 1122 | t2.join() |
| 1123 | t3.join() |
| 1124 | t4.join() |
| 1125 | t5.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1126 | |
| 1127 | if len(success_dir) != 5: |
| 1128 | self.success = False |
| 1129 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1130 | assert_equal(self.success, True) |
| 1131 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1132 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1133 | def test_1k_flow_constant_dst_mac(self): |
| 1134 | egress = 1 |
| 1135 | ingress = 2 |
| 1136 | egress_mac = '00:00:00:00:01:01' |
| 1137 | ingress_mac = '00:00:00:00:00:00' |
| 1138 | success_dir = {} |
| 1139 | |
| 1140 | for i in range(0,1000): |
| 1141 | ingress_mac = self.next_mac(ingress_mac) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1142 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1143 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1144 | egressPort = egress, |
| 1145 | ingressPort = ingress, |
| 1146 | ethSrc = ingress_mac, |
| 1147 | ethDst = egress_mac) |
| 1148 | result = flow.addFlow() |
| 1149 | assert_equal(result, True) |
| 1150 | ##wait for flows to be added to ONOS |
| 1151 | time.sleep(1) |
| 1152 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1153 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1154 | |
| 1155 | def verify_flow(*r): |
| 1156 | random_src = ''.join(r) |
| 1157 | def mac_recv_task(): |
| 1158 | def recv_cb(pkt): |
| 1159 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1160 | success_dir[current_thread().name] = True |
| 1161 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1162 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1163 | |
| 1164 | t = threading.Thread(target = mac_recv_task) |
| 1165 | t.start() |
| 1166 | pkt = Ether(src = random_src, dst = egress_mac)/IP() |
| 1167 | log.info('Sending packets to verify if flows are correct') |
| 1168 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1169 | t.join() |
| 1170 | |
| 1171 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1172 | t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1]) |
| 1173 | t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:09') |
| 1174 | t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1]) |
| 1175 | t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1]) |
| 1176 | t6 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:08') |
| 1177 | t7 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1]) |
| 1178 | t8 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1]) |
| 1179 | t9 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:'+ hex(random.randrange(16,175)).split('x')[1]) |
| 1180 | t10 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:eb') |
| 1181 | t1.start() |
| 1182 | t2.start() |
| 1183 | t3.start() |
| 1184 | t4.start() |
| 1185 | t5.start() |
| 1186 | t6.start() |
| 1187 | t7.start() |
| 1188 | t8.start() |
| 1189 | t9.start() |
| 1190 | t10.start() |
| 1191 | |
| 1192 | t1.join() |
| 1193 | t2.join() |
| 1194 | t3.join() |
| 1195 | t4.join() |
| 1196 | t5.join() |
| 1197 | t6.join() |
| 1198 | t7.join() |
| 1199 | t8.join() |
| 1200 | t9.join() |
| 1201 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1202 | if len(success_dir) != 10: |
| 1203 | self.success = False |
| 1204 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1205 | assert_equal(self.success, True) |
| 1206 | |
| 1207 | |
| 1208 | @nottest |
| 1209 | def test_10k_flow_constant_dst_mac(self): |
| 1210 | egress = 1 |
| 1211 | ingress = 2 |
| 1212 | egress_mac = '00:00:00:00:01:01' |
| 1213 | ingress_mac = '00:00:00:00:00:00' |
| 1214 | success_dir = {} |
| 1215 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1216 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1217 | for i in range(0,10000): |
| 1218 | ingress_mac = self.next_mac(ingress_mac) |
| 1219 | |
| 1220 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1221 | egressPort = egress, |
| 1222 | ingressPort = ingress, |
| 1223 | ethSrc = ingress_mac, |
| 1224 | ethDst = egress_mac) |
| 1225 | result = flow.addFlow() |
| 1226 | assert_equal(result, True) |
| 1227 | ##wait for flows to be added to ONOS |
| 1228 | time.sleep(1) |
| 1229 | log.info("%d flow added.",i+1) |
| 1230 | self.success = True |
| 1231 | |
| 1232 | def verify_flow(*r): |
| 1233 | random_src = ''.join(r) |
| 1234 | def mac_recv_task(): |
| 1235 | def recv_cb(pkt): |
| 1236 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1237 | success_dir[current_thread().name] = True |
| 1238 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1239 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1240 | |
| 1241 | t = threading.Thread(target = mac_recv_task) |
| 1242 | t.start() |
| 1243 | pkt = Ether(src = random_src, dst = egress_mac)/IP() |
| 1244 | log.info('Sending packets to verify if flows are correct') |
| 1245 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1246 | t.join() |
| 1247 | |
| 1248 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1249 | t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1250 | t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1]) |
| 1251 | t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1252 | t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1253 | t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08') |
| 1254 | t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(17,21)).split('x')[1] +':00:00:00:00:' + |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1255 | hex(random.randrange(16,254)).split('x')[1]) |
| 1256 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1257 | t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,30)).split('x')[1] +':00:00:00:00:' + |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1258 | hex(random.randrange(16,254)).split('x')[1]) |
| 1259 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1260 | t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(31,38)).split('x')[1] +':00:00:00:00:' + |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1261 | hex(random.randrange(16,254)).split('x')[1]) |
| 1262 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1263 | t10 = threading.Thread(target = verify_flow, args = '27:00:00:00:00:37') |
| 1264 | |
| 1265 | t1.start() |
| 1266 | t2.start() |
| 1267 | t3.start() |
| 1268 | t4.start() |
| 1269 | t5.start() |
| 1270 | t6.start() |
| 1271 | t7.start() |
| 1272 | t8.start() |
| 1273 | t9.start() |
| 1274 | t10.start() |
| 1275 | |
| 1276 | t1.join() |
| 1277 | t2.join() |
| 1278 | t3.join() |
| 1279 | t4.join() |
| 1280 | t5.join() |
| 1281 | t6.join() |
| 1282 | t7.join() |
| 1283 | t8.join() |
| 1284 | t9.join() |
| 1285 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1286 | if len(success_dir) != 10: |
| 1287 | self.success = False |
| 1288 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1289 | assert_equal(self.success, True) |
| 1290 | |
| 1291 | @nottest |
| 1292 | def test_100k_flow_constant_dst_mac(self): |
| 1293 | egress = 1 |
| 1294 | ingress = 2 |
| 1295 | egress_mac = '00:00:00:00:01:01' |
| 1296 | ingress_mac = '00:00:00:00:00:00' |
| 1297 | success_dir = {} |
| 1298 | |
| 1299 | |
| 1300 | for i in range(0,100000): |
| 1301 | ingress_mac = self.next_mac(ingress_mac) |
| 1302 | |
| 1303 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1304 | egressPort = egress, |
| 1305 | ingressPort = ingress, |
| 1306 | ethSrc = ingress_mac, |
| 1307 | ethDst = egress_mac) |
| 1308 | result = flow.addFlow() |
| 1309 | assert_equal(result, True) |
| 1310 | ##wait for flows to be added to ONOS |
| 1311 | time.sleep(1) |
| 1312 | log.info("%d flow added.",i+1) |
| 1313 | self.success = True |
| 1314 | |
| 1315 | def verify_flow(*r): |
| 1316 | random_src = ''.join(r) |
| 1317 | def mac_recv_task(): |
| 1318 | def recv_cb(pkt): |
| 1319 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1320 | success_dir[current_thread().name] = True |
| 1321 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1322 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1323 | |
| 1324 | t = threading.Thread(target = mac_recv_task) |
| 1325 | t.start() |
| 1326 | pkt = Ether(src = random_src, dst = egress_mac)/IP() |
| 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 | |
| 1331 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1332 | t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1333 | t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1]) |
| 1334 | t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1335 | t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1336 | t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,41)).split('x')[1] + ':00:00:00:00:08') |
| 1337 | t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(42,72)).split('x')[1] +':00:00:00:00:' + |
| 1338 | hex(random.randrange(16,254)).split('x')[1]) |
| 1339 | |
| 1340 | t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(73,100)).split('x')[1] +':00:00:00:00:' + |
| 1341 | hex(random.randrange(16,254)).split('x')[1]) |
| 1342 | |
| 1343 | t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(101,136)).split('x')[1] +':00:00:00:00:' + |
| 1344 | hex(random.randrange(16,254)).split('x')[1]) |
| 1345 | |
| 1346 | t10 = threading.Thread(target = verify_flow, args = '89:01:00:00:00:28') |
| 1347 | |
| 1348 | t1.start() |
| 1349 | t2.start() |
| 1350 | t3.start() |
| 1351 | t4.start() |
| 1352 | t5.start() |
| 1353 | t6.start() |
| 1354 | t7.start() |
| 1355 | t8.start() |
| 1356 | t9.start() |
| 1357 | t10.start() |
| 1358 | |
| 1359 | t1.join() |
| 1360 | t2.join() |
| 1361 | t3.join() |
| 1362 | t4.join() |
| 1363 | t5.join() |
| 1364 | t6.join() |
| 1365 | t7.join() |
| 1366 | t8.join() |
| 1367 | t9.join() |
| 1368 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1369 | if len(success_dir) != 10: |
| 1370 | self.success = False |
| 1371 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1372 | assert_equal(self.success, True) |
| 1373 | |
| 1374 | |
| 1375 | @nottest |
| 1376 | def test_1000k_flow_constant_dst_mac(self): |
| 1377 | egress = 1 |
| 1378 | ingress = 2 |
| 1379 | egress_mac = '00:00:00:00:01:01' |
| 1380 | ingress_mac = '00:00:00:00:00:00' |
| 1381 | success_dir = {} |
| 1382 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1383 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1384 | for i in range(0,1000000): |
| 1385 | ingress_mac = self.next_mac(ingress_mac) |
| 1386 | |
| 1387 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1388 | egressPort = egress, |
| 1389 | ingressPort = ingress, |
| 1390 | ethSrc = ingress_mac, |
| 1391 | ethDst = egress_mac) |
| 1392 | result = flow.addFlow() |
| 1393 | assert_equal(result, True) |
| 1394 | ##wait for flows to be added to ONOS |
| 1395 | time.sleep(1) |
| 1396 | log.info("%d flow added.",i+1) |
| 1397 | self.success = True |
| 1398 | |
| 1399 | def verify_flow(*r): |
| 1400 | random_src = ''.join(r) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1401 | def mac_recv_task(): |
| 1402 | def recv_cb(pkt): |
| 1403 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1404 | success_dir[current_thread().name] = True |
| 1405 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1406 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1407 | |
| 1408 | t = threading.Thread(target = mac_recv_task) |
| 1409 | t.start() |
| 1410 | pkt = Ether(src = random_src, dst = egress_mac)/IP() |
| 1411 | log.info('Sending packets to verify if flows are correct') |
| 1412 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1413 | t.join() |
| 1414 | |
| 1415 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1416 | t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1417 | t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1]) |
| 1418 | t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1419 | t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1420 | t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08') |
| 1421 | t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,50)).split('x')[1] +':00:00:00:00:' + |
| 1422 | hex(random.randrange(16,254)).split('x')[1]) |
| 1423 | |
| 1424 | t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(51,75)).split('x')[1] +':00:00:00:00:' + |
| 1425 | hex(random.randrange(16,254)).split('x')[1]) |
| 1426 | |
| 1427 | t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(76,95)).split('x')[1] +':00:00:00:00:' + |
| 1428 | hex(random.randrange(16,254)).split('x')[1]) |
| 1429 | |
| 1430 | t10 = threading.Thread(target = verify_flow, args = '60:0f:00:00:00:91') |
| 1431 | |
| 1432 | t1.start() |
| 1433 | t2.start() |
| 1434 | t3.start() |
| 1435 | t4.start() |
| 1436 | t5.start() |
| 1437 | t6.start() |
| 1438 | t7.start() |
| 1439 | t8.start() |
| 1440 | t9.start() |
| 1441 | t10.start() |
| 1442 | |
| 1443 | t1.join() |
| 1444 | t2.join() |
| 1445 | t3.join() |
| 1446 | t4.join() |
| 1447 | t5.join() |
| 1448 | t6.join() |
| 1449 | t7.join() |
| 1450 | t8.join() |
| 1451 | t9.join() |
| 1452 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1453 | if len(success_dir) != 10: |
| 1454 | self.success = False |
| 1455 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1456 | assert_equal(self.success, True) |
| 1457 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1458 | def test_5_flow_constant_src_mac(self): |
| 1459 | egress = 1 |
| 1460 | ingress = 2 |
| 1461 | egress_mac = '00:00:00:00:01:00' |
| 1462 | ingress_mac = '00:00:00:00:00:01' |
| 1463 | |
| 1464 | |
| 1465 | for i in range(0,5): |
| 1466 | egress_mac = self.next_mac(egress_mac) |
| 1467 | |
| 1468 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1469 | egressPort = egress, |
| 1470 | ingressPort = ingress, |
| 1471 | ethSrc = ingress_mac, |
| 1472 | ethDst = egress_mac) |
| 1473 | result = flow.addFlow() |
| 1474 | assert_equal(result, True) |
| 1475 | ##wait for flows to be added to ONOS |
| 1476 | time.sleep(1) |
| 1477 | log.info("%d flow added.",i+1) |
| 1478 | self.success = False |
| 1479 | |
| 1480 | def mac_recv_task(): |
| 1481 | def recv_cb(pkt): |
| 1482 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1483 | self.success = True |
| 1484 | 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', |
| 1485 | prn = recv_cb, iface = self.port_map[egress]) |
| 1486 | |
| 1487 | t = threading.Thread(target = mac_recv_task) |
| 1488 | t.start() |
| 1489 | pkt = Ether(src = ingress_mac, dst = '00:00:00:00:01:02')/IP() |
| 1490 | log.info('Sending packets to verify if flows are correct') |
| 1491 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1492 | t.join() |
| 1493 | assert_equal(self.success, True) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1494 | |
| 1495 | def test_500_flow_mac(self): |
| 1496 | egress = 1 |
| 1497 | ingress = 2 |
| 1498 | egress_mac = '00:00:00:00:01:00' |
| 1499 | ingress_mac = '00:00:00:00:00:00' |
| 1500 | success_dir = {} |
| 1501 | |
| 1502 | for i in range(0,500): |
| 1503 | ingress_mac = self.next_mac(ingress_mac) |
| 1504 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1505 | |
| 1506 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1507 | egressPort = egress, |
| 1508 | ingressPort = ingress, |
| 1509 | ethSrc = ingress_mac, |
| 1510 | ethDst = egress_mac) |
| 1511 | result = flow.addFlow() |
| 1512 | assert_equal(result, True) |
| 1513 | ##wait for flows to be added to ONOS |
| 1514 | time.sleep(1) |
| 1515 | log.info("%d flow added.",i+1) |
| 1516 | self.success = True |
| 1517 | def verify_flow(*r): |
| 1518 | random_src = ''.join(r) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1519 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1520 | def mac_recv_task(): |
| 1521 | def recv_cb(pkt): |
| 1522 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1523 | success_dir[current_thread().name] = True |
| 1524 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1525 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1526 | |
| 1527 | t = threading.Thread(target = mac_recv_task) |
| 1528 | t.start() |
| 1529 | pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP() |
| 1530 | log.info('Sending packets to verify if flows are correct') |
| 1531 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1532 | t.join() |
| 1533 | |
| 1534 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1535 | t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1]) |
| 1536 | t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,100)).split('x')[1]) |
| 1537 | t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(101,240)).split('x')[1]) |
| 1538 | t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:f5') |
| 1539 | t1.start() |
| 1540 | t2.start() |
| 1541 | t3.start() |
| 1542 | t4.start() |
| 1543 | t5.start() |
| 1544 | t1.join() |
| 1545 | t2.join() |
| 1546 | t3.join() |
| 1547 | t4.join() |
| 1548 | t5.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1549 | if len(success_dir) != 5: |
| 1550 | self.success = False |
| 1551 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1552 | assert_equal(self.success, True) |
| 1553 | |
| 1554 | def test_1k_flow_mac(self): |
| 1555 | egress = 1 |
| 1556 | ingress = 2 |
| 1557 | egress_mac = '00:00:00:00:01:00' |
| 1558 | ingress_mac = '00:00:00:00:00:00' |
| 1559 | success_dir = {} |
| 1560 | |
| 1561 | for i in range(0,1000): |
| 1562 | ingress_mac = self.next_mac(ingress_mac) |
| 1563 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1564 | |
| 1565 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1566 | egressPort = egress, |
| 1567 | ingressPort = ingress, |
| 1568 | ethSrc = ingress_mac, |
| 1569 | ethDst = egress_mac) |
| 1570 | result = flow.addFlow() |
| 1571 | assert_equal(result, True) |
| 1572 | ##wait for flows to be added to ONOS |
| 1573 | time.sleep(1) |
| 1574 | log.info("%d flow added.",i+1) |
| 1575 | self.success = True |
| 1576 | def verify_flow(*r): |
| 1577 | random_src = ''.join(r) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1578 | def mac_recv_task(): |
| 1579 | def recv_cb(pkt): |
| 1580 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1581 | success_dir[current_thread().name] = True |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1582 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
| 1583 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1584 | |
| 1585 | t = threading.Thread(target = mac_recv_task) |
| 1586 | t.start() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1587 | pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP() |
| 1588 | log.info('Sending packets to verify if flows are correct') |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1589 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1590 | t.join() |
| 1591 | |
| 1592 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1593 | t2 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:' + hex(random.randrange(50,254)).split('x')[1]) |
| 1594 | t3 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:09') |
| 1595 | t4 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1]) |
| 1596 | t5 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1]) |
| 1597 | t6 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:08') |
| 1598 | t7 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(16,150)).split('x')[1]) |
| 1599 | t8 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:' + hex(random.randrange(151,250)).split('x')[1]) |
| 1600 | t9 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:'+ hex(random.randrange(16,175)).split('x')[1]) |
| 1601 | t10 = threading.Thread(target = verify_flow, args = '03:00:00:00:00:eb') |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1602 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1603 | t1.start() |
| 1604 | t2.start() |
| 1605 | t3.start() |
| 1606 | t4.start() |
| 1607 | t5.start() |
| 1608 | t6.start() |
| 1609 | t7.start() |
| 1610 | t8.start() |
| 1611 | t9.start() |
| 1612 | t10.start() |
| 1613 | |
| 1614 | t1.join() |
| 1615 | t2.join() |
| 1616 | t3.join() |
| 1617 | t4.join() |
| 1618 | t5.join() |
| 1619 | t6.join() |
| 1620 | t7.join() |
| 1621 | t8.join() |
| 1622 | t9.join() |
| 1623 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1624 | if len(success_dir) != 10: |
| 1625 | self.success = False |
| 1626 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1627 | assert_equal(self.success, True) |
| 1628 | |
| 1629 | @nottest |
| 1630 | def test_10k_flow_mac(self): |
| 1631 | egress = 1 |
| 1632 | ingress = 2 |
| 1633 | egress_mac = '00:00:00:00:01:00' |
| 1634 | ingress_mac = '00:00:00:00:00:00' |
| 1635 | success_dir = {} |
| 1636 | |
| 1637 | for i in range(0,10000): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1638 | ingress_mac = self.next_mac(ingress_mac) |
| 1639 | egress_mac = self.to_egress_mac(ingress_mac) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1640 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1641 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1642 | egressPort = egress, |
| 1643 | ingressPort = ingress, |
| 1644 | ethSrc = ingress_mac, |
| 1645 | ethDst = egress_mac) |
| 1646 | result = flow.addFlow() |
| 1647 | assert_equal(result, True) |
| 1648 | ##wait for flows to be added to ONOS |
| 1649 | time.sleep(1) |
| 1650 | log.info("%d flow added.",i+1) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1651 | self.success = True |
| 1652 | def verify_flow(*r): |
| 1653 | random_src = ''.join(r) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1654 | def mac_recv_task(): |
| 1655 | def recv_cb(pkt): |
| 1656 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1657 | success_dir[current_thread().name] = True |
| 1658 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1659 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1660 | |
| 1661 | t = threading.Thread(target = mac_recv_task) |
| 1662 | t.start() |
| 1663 | pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP() |
| 1664 | log.info('Sending packets to verify if flows are correct') |
| 1665 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1666 | t.join() |
| 1667 | |
| 1668 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1669 | t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1670 | t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1]) |
| 1671 | t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1672 | t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1673 | t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08') |
| 1674 | t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(17,21)).split('x')[1] +':00:00:00:00:' + |
| 1675 | hex(random.randrange(16,254)).split('x')[1]) |
| 1676 | |
| 1677 | t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,30)).split('x')[1] +':00:00:00:00:' + |
| 1678 | hex(random.randrange(16,254)).split('x')[1]) |
| 1679 | |
| 1680 | t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(31,38)).split('x')[1] +':00:00:00:00:' + |
| 1681 | hex(random.randrange(16,254)).split('x')[1]) |
| 1682 | |
| 1683 | t10 = threading.Thread(target = verify_flow, args = '27:00:00:00:00:37') |
| 1684 | |
| 1685 | t1.start() |
| 1686 | t2.start() |
| 1687 | t3.start() |
| 1688 | t4.start() |
| 1689 | t5.start() |
| 1690 | t6.start() |
| 1691 | t7.start() |
| 1692 | t8.start() |
| 1693 | t9.start() |
| 1694 | t10.start() |
| 1695 | |
| 1696 | t1.join() |
| 1697 | t2.join() |
| 1698 | t3.join() |
| 1699 | t4.join() |
| 1700 | t5.join() |
| 1701 | t6.join() |
| 1702 | t7.join() |
| 1703 | t8.join() |
| 1704 | t9.join() |
| 1705 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1706 | if len(success_dir) != 10: |
| 1707 | self.success = False |
| 1708 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1709 | assert_equal(self.success, True) |
| 1710 | |
| 1711 | @nottest |
| 1712 | def test_100k_flow_mac(self): |
| 1713 | egress = 1 |
| 1714 | ingress = 2 |
| 1715 | egress_mac = '00:00:00:00:01:00' |
| 1716 | ingress_mac = '00:00:00:00:00:00' |
| 1717 | success_dir = {} |
| 1718 | |
| 1719 | for i in range(0,100000): |
| 1720 | ingress_mac = self.next_mac(ingress_mac) |
| 1721 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1722 | |
| 1723 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1724 | egressPort = egress, |
| 1725 | ingressPort = ingress, |
| 1726 | ethSrc = ingress_mac, |
| 1727 | ethDst = egress_mac) |
| 1728 | result = flow.addFlow() |
| 1729 | assert_equal(result, True) |
| 1730 | ##wait for flows to be added to ONOS |
| 1731 | time.sleep(1) |
| 1732 | log.info("%d flow added.",i+1) |
| 1733 | self.success = True |
| 1734 | |
| 1735 | def verify_flow(*r): |
| 1736 | random_src = ''.join(r) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1737 | def mac_recv_task(): |
| 1738 | def recv_cb(pkt): |
| 1739 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1740 | success_dir[current_thread().name] = True |
| 1741 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1742 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1743 | |
| 1744 | t = threading.Thread(target = mac_recv_task) |
| 1745 | t.start() |
| 1746 | pkt = Ether(src = random_src, dst = self.to_egress_mac(random_src))/IP() |
| 1747 | log.info('Sending packets to verify if flows are correct') |
| 1748 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1749 | t.join() |
| 1750 | |
| 1751 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1752 | t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1753 | t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1]) |
| 1754 | t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1755 | t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1756 | t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,41)).split('x')[1] + ':00:00:00:00:08') |
| 1757 | t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(42,72)).split('x')[1] +':00:00:00:00:' + |
| 1758 | hex(random.randrange(16,254)).split('x')[1]) |
| 1759 | |
| 1760 | t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(73,100)).split('x')[1] +':00:00:00:00:' + |
| 1761 | hex(random.randrange(16,254)).split('x')[1]) |
| 1762 | |
| 1763 | t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(101,136)).split('x')[1] +':00:00:00:00:' + |
| 1764 | hex(random.randrange(16,254)).split('x')[1]) |
| 1765 | |
| 1766 | t10 = threading.Thread(target = verify_flow, args = '89:01:00:00:00:28') |
| 1767 | |
| 1768 | t1.start() |
| 1769 | t2.start() |
| 1770 | t3.start() |
| 1771 | t4.start() |
| 1772 | t5.start() |
| 1773 | t6.start() |
| 1774 | t7.start() |
| 1775 | t8.start() |
| 1776 | t9.start() |
| 1777 | t10.start() |
| 1778 | |
| 1779 | t1.join() |
| 1780 | t2.join() |
| 1781 | t3.join() |
| 1782 | t4.join() |
| 1783 | t5.join() |
| 1784 | t6.join() |
| 1785 | t7.join() |
| 1786 | t8.join() |
| 1787 | t9.join() |
| 1788 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1789 | if len(success_dir) != 10: |
| 1790 | self.success = False |
| 1791 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1792 | assert_equal(self.success, True) |
| 1793 | |
| 1794 | @nottest |
| 1795 | def test_1000k_flow_mac(self): |
| 1796 | egress = 1 |
| 1797 | ingress = 2 |
| 1798 | egress_mac = '00:00:00:00:01:00' |
| 1799 | ingress_mac = '00:00:00:00:00:00' |
| 1800 | success_dir = {} |
| 1801 | |
| 1802 | for i in range(0,1000000): |
| 1803 | ingress_mac = self.next_mac(ingress_mac) |
| 1804 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1805 | |
| 1806 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1807 | egressPort = egress, |
| 1808 | ingressPort = ingress, |
| 1809 | ethSrc = ingress_mac, |
| 1810 | ethDst = egress_mac) |
| 1811 | result = flow.addFlow() |
| 1812 | assert_equal(result, True) |
| 1813 | ##wait for flows to be added to ONOS |
| 1814 | time.sleep(1) |
| 1815 | log.info("%d flow added.",i+1) |
| 1816 | self.success = True |
| 1817 | |
| 1818 | def verify_flow(*r): |
| 1819 | random_src = ''.join(r) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1820 | def mac_recv_task(): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1821 | def recv_cb(pkt): |
| 1822 | log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst)) |
| 1823 | success_dir[current_thread().name] = True |
| 1824 | sniff(count=2, timeout=5, lfilter = lambda p: p.src == random_src, |
| 1825 | prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1826 | |
| 1827 | t = threading.Thread(target = mac_recv_task) |
| 1828 | t.start() |
| 1829 | pkt = Ether(src = random_src, dst = egress_mac)/IP() |
| 1830 | log.info('Sending packets to verify if flows are correct') |
| 1831 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 1832 | t.join() |
| 1833 | |
| 1834 | t1 = threading.Thread(target = verify_flow, args = '00:00:00:00:00:01') |
| 1835 | t2 = threading.Thread(target = verify_flow, args = '01:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1836 | t3 = threading.Thread(target = verify_flow, args = '02:00:00:00:00:'+ hex(random.randrange(16,254)).split('x')[1]) |
| 1837 | t4 = threading.Thread(target = verify_flow, args = '05:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1838 | t5 = threading.Thread(target = verify_flow, args = '07:00:00:00:00:' + hex(random.randrange(16,254)).split('x')[1]) |
| 1839 | t6 = threading.Thread(target = verify_flow, args = hex(random.randrange(16,21)).split('x')[1] + ':00:00:00:00:08') |
| 1840 | t7 = threading.Thread(target = verify_flow, args = hex(random.randrange(22,50)).split('x')[1] +':00:00:00:00:' + |
| 1841 | hex(random.randrange(16,254)).split('x')[1]) |
| 1842 | |
| 1843 | t8 = threading.Thread(target = verify_flow, args = hex(random.randrange(51,75)).split('x')[1] +':00:00:00:00:' + |
| 1844 | hex(random.randrange(16,254)).split('x')[1]) |
| 1845 | |
| 1846 | t9 = threading.Thread(target = verify_flow, args = hex(random.randrange(76,95)).split('x')[1] +':00:00:00:00:' + |
| 1847 | hex(random.randrange(16,254)).split('x')[1]) |
| 1848 | |
| 1849 | t10 = threading.Thread(target = verify_flow, args = '60:0f:00:00:00:91') |
| 1850 | |
| 1851 | t1.start() |
| 1852 | t2.start() |
| 1853 | t3.start() |
| 1854 | t4.start() |
| 1855 | t5.start() |
| 1856 | t6.start() |
| 1857 | t7.start() |
| 1858 | t8.start() |
| 1859 | t9.start() |
| 1860 | t10.start() |
| 1861 | |
| 1862 | t1.join() |
| 1863 | t2.join() |
| 1864 | t3.join() |
| 1865 | t4.join() |
| 1866 | t5.join() |
| 1867 | t6.join() |
| 1868 | t7.join() |
| 1869 | t8.join() |
| 1870 | t9.join() |
| 1871 | t10.join() |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1872 | if len(success_dir) != 10: |
| 1873 | self.success = False |
| 1874 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 1875 | assert_equal(self.success, True) |
| 1876 | |
ChetanGaonker | d376b90 | 2016-06-14 11:50:28 -0700 | [diff] [blame] | 1877 | def test_rate_100_flow_mac(self): |
| 1878 | egress = 1 |
| 1879 | ingress = 2 |
| 1880 | egress_mac = '00:00:00:00:01:00' |
| 1881 | ingress_mac = '00:00:00:00:00:00' |
| 1882 | flows_added = 0 |
| 1883 | stats_dir = collections.OrderedDict() |
| 1884 | running_time = 0 |
| 1885 | |
| 1886 | |
| 1887 | for i in range(1,4): |
| 1888 | start_time = time.time() |
| 1889 | for j in range(0,100): |
| 1890 | ingress_mac = self.next_mac(ingress_mac) |
| 1891 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1892 | |
| 1893 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1894 | egressPort = egress, |
| 1895 | ingressPort = ingress, |
| 1896 | ethSrc = ingress_mac, |
| 1897 | ethDst = egress_mac) |
| 1898 | result = flow.addFlow() |
| 1899 | assert_equal(result, True) |
| 1900 | flows_added += 1 |
| 1901 | ##wait for flows to be added to ONOS |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1902 | time.sleep(1) |
ChetanGaonker | d376b90 | 2016-06-14 11:50:28 -0700 | [diff] [blame] | 1903 | log.info("%d flow added.",j+1) |
| 1904 | end_time = time.time() |
| 1905 | stats_dir['run '+str(i)] = round((end_time - start_time),2) |
| 1906 | for t in stats_dir.items(): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1907 | log.info("----------------------------------------------") |
| 1908 | log.info("Statics for %s",t[0]) |
| 1909 | log.info("----------------------------------------------") |
| 1910 | log.info("No. of flows added Running Time ") |
| 1911 | log.info(" %d %s " %(100, t[1])) |
| 1912 | running_time += float(t[1]) |
ChetanGaonker | d376b90 | 2016-06-14 11:50:28 -0700 | [diff] [blame] | 1913 | |
| 1914 | log.info("-------------------------------------------------------------------------------------------------------") |
| 1915 | log.info("Final Statics") |
| 1916 | log.info("-------------------------------------------------------------------------------------------------------") |
| 1917 | log.info("Total No. of flows added Total Running Time Average no. of flows per second ") |
| 1918 | log.info(" %d %s second %d " |
| 1919 | %(flows_added, running_time, round(flows_added/running_time,0))) |
| 1920 | log.info("-------------------------------------------------------------------------------------------------------") |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | def test_rate_500_flow_mac(self): |
| 1925 | egress = 1 |
| 1926 | ingress = 2 |
| 1927 | egress_mac = '00:00:00:00:01:00' |
| 1928 | ingress_mac = '00:00:00:00:00:00' |
| 1929 | flows_added = 0 |
| 1930 | stats_dir = collections.OrderedDict() |
| 1931 | running_time = 0 |
| 1932 | |
| 1933 | |
| 1934 | for i in range(1,4): |
| 1935 | start_time = time.time() |
| 1936 | for j in range(0,500): |
| 1937 | ingress_mac = self.next_mac(ingress_mac) |
| 1938 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1939 | |
| 1940 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1941 | egressPort = egress, |
| 1942 | ingressPort = ingress, |
| 1943 | ethSrc = ingress_mac, |
| 1944 | ethDst = egress_mac) |
| 1945 | result = flow.addFlow() |
| 1946 | assert_equal(result, True) |
| 1947 | flows_added += 1 |
| 1948 | ##wait for flows to be added to ONOS |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1949 | time.sleep(1) |
ChetanGaonker | d376b90 | 2016-06-14 11:50:28 -0700 | [diff] [blame] | 1950 | log.info("%d flow added.",j+1) |
| 1951 | end_time = time.time() |
| 1952 | stats_dir['run '+str(i)] = round((end_time - start_time),2) |
| 1953 | for t in stats_dir.items(): |
| 1954 | log.info("----------------------------------------------") |
| 1955 | log.info("Statics for %s",t[0]) |
| 1956 | log.info("----------------------------------------------") |
| 1957 | log.info("No. of flows added Running Time ") |
| 1958 | log.info(" %d %s " %(500, t[1])) |
| 1959 | running_time += float(t[1]) |
| 1960 | |
| 1961 | log.info("-------------------------------------------------------------------------------------------------------") |
| 1962 | log.info("Final Statics") |
| 1963 | log.info("-------------------------------------------------------------------------------------------------------") |
| 1964 | log.info("Total No. of flows added Total Running Time Average no. of flows per second ") |
| 1965 | log.info(" %d %s second %d " |
| 1966 | %(flows_added, running_time, round(flows_added/running_time,0))) |
| 1967 | log.info("-------------------------------------------------------------------------------------------------------") |
| 1968 | |
| 1969 | def test_rate_1k_flow_mac(self): |
| 1970 | egress = 1 |
| 1971 | ingress = 2 |
| 1972 | egress_mac = '00:00:00:00:01:00' |
| 1973 | ingress_mac = '00:00:00:00:00:00' |
| 1974 | flows_added = 0 |
| 1975 | stats_dir = collections.OrderedDict() |
| 1976 | running_time = 0 |
| 1977 | |
| 1978 | |
| 1979 | for i in range(1,4): |
| 1980 | start_time = time.time() |
| 1981 | for j in range(0,1000): |
| 1982 | ingress_mac = self.next_mac(ingress_mac) |
| 1983 | egress_mac = self.to_egress_mac(ingress_mac) |
| 1984 | |
| 1985 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 1986 | egressPort = egress, |
| 1987 | ingressPort = ingress, |
| 1988 | ethSrc = ingress_mac, |
| 1989 | ethDst = egress_mac) |
| 1990 | result = flow.addFlow() |
| 1991 | assert_equal(result, True) |
| 1992 | flows_added += 1 |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 1993 | ##wait for flows to be added to ONOS |
| 1994 | time.sleep(1) |
ChetanGaonker | d376b90 | 2016-06-14 11:50:28 -0700 | [diff] [blame] | 1995 | log.info("%d flow added.",j+1) |
| 1996 | end_time = time.time() |
| 1997 | stats_dir['run '+str(i)] = round((end_time - start_time),2) |
| 1998 | for t in stats_dir.items(): |
| 1999 | log.info("----------------------------------------------") |
| 2000 | log.info("Statics for %s",t[0]) |
| 2001 | log.info("----------------------------------------------") |
| 2002 | log.info("No. of flows added Running Time ") |
| 2003 | log.info(" %d %s " %(1000, t[1])) |
| 2004 | running_time += float(t[1]) |
| 2005 | |
| 2006 | log.info("-------------------------------------------------------------------------------------------------------") |
| 2007 | log.info("Final Statics") |
| 2008 | log.info("-------------------------------------------------------------------------------------------------------") |
| 2009 | log.info("Total No. of flows added Total Running Time Average no. of flows per second ") |
| 2010 | log.info(" %d %s second %d " |
| 2011 | %(flows_added, running_time, round(flows_added/running_time,0))) |
| 2012 | log.info("-------------------------------------------------------------------------------------------------------") |
| 2013 | |
| 2014 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2015 | def test_500_flow_ip(self): |
| 2016 | egress = 1 |
| 2017 | ingress = 2 |
| 2018 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' } |
| 2019 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2020 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2021 | |
| 2022 | for i in range(0,500): |
| 2023 | ingress_map['ip'] = self.next_ip(ingress_map['ip']) |
| 2024 | assert_not_equal(ingress_map['ip'], None) |
| 2025 | egress_map['ip'] = self.to_egress_ip(ingress_map['ip']) |
| 2026 | |
| 2027 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2028 | egressPort = egress, |
| 2029 | ingressPort = ingress, |
| 2030 | ethType = '0x0800', |
| 2031 | ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'), |
| 2032 | ipDst = ('IPV4_DST', egress_map['ip']+'/8') |
| 2033 | ) |
| 2034 | result = flow.addFlow() |
| 2035 | assert_equal(result, True) |
| 2036 | ##wait for flows to be added to ONOS |
| 2037 | time.sleep(1) |
| 2038 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2039 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2040 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2041 | def verify_flow(*r): |
| 2042 | random_src = ''.join(r) |
| 2043 | random_dst = self.to_egress_ip(random_src) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2044 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2045 | def mac_recv_task(): |
| 2046 | def recv_cb(pkt): |
| 2047 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
| 2048 | success_dir[current_thread().name] = True |
| 2049 | |
| 2050 | sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src |
| 2051 | ,prn = recv_cb, iface = self.port_map[egress]) |
| 2052 | |
| 2053 | t = threading.Thread(target = mac_recv_task) |
| 2054 | t.start() |
| 2055 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2056 | L3 = IP(src = random_src, dst = random_dst) |
| 2057 | pkt = L2/L3 |
| 2058 | log.info('Sending packets to verify if flows are correct') |
| 2059 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2060 | t.join() |
| 2061 | |
| 2062 | t1 = threading.Thread(target = verify_flow, args = '192.0.0.1') |
| 2063 | t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(10,100,1))) |
| 2064 | t3 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(101,255,1))) |
| 2065 | t4 = threading.Thread(target = verify_flow, args = '192.0.1.' + str(random.randrange(1,235,1))) |
| 2066 | t5 = threading.Thread(target = verify_flow, args = '192.0.1.244') |
| 2067 | t1.start() |
| 2068 | t2.start() |
| 2069 | t3.start() |
| 2070 | t4.start() |
| 2071 | t5.start() |
| 2072 | |
| 2073 | t1.join() |
| 2074 | t2.join() |
| 2075 | t3.join() |
| 2076 | t4.join() |
| 2077 | t5.join() |
| 2078 | |
| 2079 | if len(success_dir) < 5 or len(success_dir) > 5: |
| 2080 | self.success = False |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2081 | assert_equal(self.success, True) |
| 2082 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2083 | |
| 2084 | @nottest |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2085 | def test_1k_flow_ip(self): |
| 2086 | egress = 1 |
| 2087 | ingress = 2 |
| 2088 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' } |
| 2089 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2090 | success_dir ={} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2091 | |
| 2092 | for i in range(0,1000): |
| 2093 | ingress_map['ip'] = self.next_ip(ingress_map['ip']) |
| 2094 | assert_not_equal(ingress_map['ip'], None) |
| 2095 | egress_map['ip'] = self.to_egress_ip(ingress_map['ip']) |
| 2096 | |
| 2097 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2098 | egressPort = egress, |
| 2099 | ingressPort = ingress, |
| 2100 | ethType = '0x0800', |
| 2101 | ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'), |
| 2102 | ipDst = ('IPV4_DST', egress_map['ip']+'/8') |
| 2103 | ) |
| 2104 | result = flow.addFlow() |
| 2105 | assert_equal(result, True) |
| 2106 | ##wait for flows to be added to ONOS |
| 2107 | time.sleep(1) |
| 2108 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2109 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2110 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2111 | def verify_flow(*r): |
| 2112 | random_src = ''.join(r) |
| 2113 | random_dst = self.to_egress_ip(random_src) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2114 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2115 | def mac_recv_task(): |
| 2116 | def recv_cb(pkt): |
| 2117 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
| 2118 | success_dir[current_thread().name] = True |
| 2119 | |
| 2120 | sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src |
| 2121 | ,prn = recv_cb, iface = self.port_map[egress]) |
| 2122 | |
| 2123 | t = threading.Thread(target = mac_recv_task) |
| 2124 | t.start() |
| 2125 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2126 | L3 = IP(src = random_src, dst = random_dst) |
| 2127 | pkt = L2/L3 |
| 2128 | log.info('Sending packets to verify if flows are correct') |
| 2129 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2130 | t.join() |
| 2131 | |
| 2132 | t1 = threading.Thread(target = verify_flow, args = '192.0.0.1') |
| 2133 | t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(10,255,1))) |
| 2134 | t3 = threading.Thread(target = verify_flow, args = '192.0.1.' + str(random.randrange(1,100,1))) |
| 2135 | t4 = threading.Thread(target = verify_flow, args = '192.0.1.' + str(random.randrange(101,255,1))) |
| 2136 | t5 = threading.Thread(target = verify_flow, args = '192.0.2.' + str(random.randrange(1,100,1))) |
| 2137 | t6 = threading.Thread(target = verify_flow, args = '192.0.2.' + str(random.randrange(101,255,1))) |
| 2138 | t7 = threading.Thread(target = verify_flow, args = '192.0.3.' + str(random.randrange(1,100,1))) |
| 2139 | t8 = threading.Thread(target = verify_flow, args = '192.0.3.' + str(random.randrange(101,200,1))) |
| 2140 | t9 = threading.Thread(target = verify_flow, args = '192.0.'+ str(random.randrange(0,3,1)) + '.' + |
| 2141 | str(random.randrange(1,255,1))) |
| 2142 | t10 = threading.Thread(target = verify_flow, args = '192.0.3.232') |
| 2143 | |
| 2144 | t1.start() |
| 2145 | t2.start() |
| 2146 | t3.start() |
| 2147 | t4.start() |
| 2148 | t5.start() |
| 2149 | t6.start() |
| 2150 | t7.start() |
| 2151 | t8.start() |
| 2152 | t9.start() |
| 2153 | t10.start() |
| 2154 | |
| 2155 | t1.join() |
| 2156 | t2.join() |
| 2157 | t3.join() |
| 2158 | t4.join() |
| 2159 | t5.join() |
| 2160 | t6.join() |
| 2161 | t7.join() |
| 2162 | t8.join() |
| 2163 | t9.join() |
| 2164 | t10.join() |
| 2165 | |
| 2166 | if len(success_dir) != 10: |
| 2167 | self.success = False |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2168 | assert_equal(self.success, True) |
| 2169 | |
| 2170 | @nottest |
| 2171 | def test_10k_flow_ip(self): |
| 2172 | egress = 1 |
| 2173 | ingress = 2 |
| 2174 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' } |
| 2175 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2176 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2177 | |
| 2178 | for i in range(0,10000): |
| 2179 | ingress_map['ip'] = self.next_ip(ingress_map['ip']) |
| 2180 | assert_not_equal(ingress_map['ip'], None) |
| 2181 | egress_map['ip'] = self.to_egress_ip(ingress_map['ip']) |
| 2182 | |
| 2183 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2184 | egressPort = egress, |
| 2185 | ingressPort = ingress, |
| 2186 | ethType = '0x0800', |
| 2187 | ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'), |
| 2188 | ipDst = ('IPV4_DST', egress_map['ip']+'/8') |
| 2189 | ) |
| 2190 | result = flow.addFlow() |
| 2191 | assert_equal(result, True) |
| 2192 | ##wait for flows to be added to ONOS |
| 2193 | time.sleep(1) |
| 2194 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2195 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2196 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2197 | def verify_flow(*r): |
| 2198 | random_src = ''.join(r) |
| 2199 | random_dst = self.to_egress_ip(random_src) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2200 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2201 | def mac_recv_task(): |
| 2202 | def recv_cb(pkt): |
| 2203 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
| 2204 | success_dir[current_thread().name] = True |
| 2205 | sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src |
| 2206 | ,prn = recv_cb, iface = self.port_map[egress]) |
| 2207 | |
| 2208 | t = threading.Thread(target = mac_recv_task) |
| 2209 | t.start() |
| 2210 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2211 | L3 = IP(src = random_src, dst = random_dst) |
| 2212 | pkt = L2/L3 |
| 2213 | log.info('Sending packets to verify if flows are correct') |
| 2214 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2215 | t.join() |
| 2216 | |
| 2217 | t1 = threading.Thread(target = verify_flow, args = '192.0.0.1') |
| 2218 | t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(1,255,1))) |
| 2219 | t3 = threading.Thread(target = verify_flow, args = '192.0.5.' + str(random.randrange(1,255,1))) |
| 2220 | t4 = threading.Thread(target = verify_flow, args = '192.0.10.' + str(random.randrange(1,255,1))) |
| 2221 | t5 = threading.Thread(target = verify_flow, args = '192.0.15.' + str(random.randrange(1,255,1))) |
| 2222 | t6 = threading.Thread(target = verify_flow, args = '192.0.20.' + str(random.randrange(1,255,1))) |
| 2223 | t7 = threading.Thread(target = verify_flow, args = '192.0.25.' + str(random.randrange(1,255,1))) |
| 2224 | t8 = threading.Thread(target = verify_flow, args = '192.0.30.' + str(random.randrange(1,255,1))) |
| 2225 | t9 = threading.Thread(target = verify_flow, args = '192.0.'+ str(random.randrange(0,39,1)) + '.' + |
| 2226 | str(random.randrange(1,255,1))) |
| 2227 | t10 = threading.Thread(target = verify_flow, args = '192.0.39.16') |
| 2228 | |
| 2229 | t1.start() |
| 2230 | t2.start() |
| 2231 | t3.start() |
| 2232 | t4.start() |
| 2233 | t5.start() |
| 2234 | t6.start() |
| 2235 | t7.start() |
| 2236 | t8.start() |
| 2237 | t9.start() |
| 2238 | t10.start() |
| 2239 | |
| 2240 | t1.join() |
| 2241 | t2.join() |
| 2242 | t3.join() |
| 2243 | t4.join() |
| 2244 | t5.join() |
| 2245 | t6.join() |
| 2246 | t7.join() |
| 2247 | t8.join() |
| 2248 | t9.join() |
| 2249 | t10.join() |
| 2250 | |
| 2251 | if len(success_dir) != 10: |
| 2252 | self.success = False |
| 2253 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2254 | assert_equal(self.success, True) |
| 2255 | |
| 2256 | @nottest |
| 2257 | def test_100k_flow_ip(self): |
| 2258 | egress = 1 |
| 2259 | ingress = 2 |
| 2260 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' } |
| 2261 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2262 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2263 | |
| 2264 | for i in range(0,100000): |
| 2265 | ingress_map['ip'] = self.next_ip(ingress_map['ip']) |
| 2266 | assert_not_equal(ingress_map['ip'], None) |
| 2267 | egress_map['ip'] = self.to_egress_ip(ingress_map['ip']) |
| 2268 | |
| 2269 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2270 | egressPort = egress, |
| 2271 | ingressPort = ingress, |
| 2272 | ethType = '0x0800', |
| 2273 | ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'), |
| 2274 | ipDst = ('IPV4_DST', egress_map['ip']+'/8') |
| 2275 | ) |
| 2276 | result = flow.addFlow() |
| 2277 | assert_equal(result, True) |
| 2278 | ##wait for flows to be added to ONOS |
| 2279 | time.sleep(1) |
| 2280 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2281 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2282 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2283 | def verify_flow(*r): |
| 2284 | random_src = ''.join(r) |
| 2285 | random_dst = self.to_egress_ip(random_src) |
| 2286 | def mac_recv_task(): |
| 2287 | def recv_cb(pkt): |
| 2288 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
| 2289 | success_dir[current_thread().name] = True |
| 2290 | sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src |
| 2291 | ,prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2292 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2293 | t = threading.Thread(target = mac_recv_task) |
| 2294 | t.start() |
| 2295 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2296 | L3 = IP(src = random_src, dst = random_dst) |
| 2297 | pkt = L2/L3 |
| 2298 | log.info('Sending packets to verify if flows are correct') |
| 2299 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2300 | t.join() |
| 2301 | |
| 2302 | t1 = threading.Thread(target = verify_flow, args = '192.0.0.1') |
| 2303 | t2 = threading.Thread(target = verify_flow, args = '192.0.0.' + str(random.randrange(1,255,1))) |
| 2304 | t3 = threading.Thread(target = verify_flow, args = '192.0.50.' + str(random.randrange(1,255,1))) |
| 2305 | t4 = threading.Thread(target = verify_flow, args = '192.0.100.' + str(random.randrange(1,255,1))) |
| 2306 | t5 = threading.Thread(target = verify_flow, args = '192.0.150.' + str(random.randrange(1,255,1))) |
| 2307 | t6 = threading.Thread(target = verify_flow, args = '192.0.200.' + str(random.randrange(1,255,1))) |
| 2308 | t7 = threading.Thread(target = verify_flow, args = '192.0.250.' + str(random.randrange(1,255,1))) |
| 2309 | t8 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(1,75,1)) + '.' |
| 2310 | + str(random.randrange(1,255,1))) |
| 2311 | t9 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(76,134,1)) + '.' |
| 2312 | + str(random.randrange(1,255,1))) |
| 2313 | t10 = threading.Thread(target = verify_flow, args = '192.1.134.160') |
| 2314 | |
| 2315 | t1.start() |
| 2316 | t2.start() |
| 2317 | t3.start() |
| 2318 | t4.start() |
| 2319 | t5.start() |
| 2320 | t6.start() |
| 2321 | t7.start() |
| 2322 | t8.start() |
| 2323 | t9.start() |
| 2324 | t10.start() |
| 2325 | |
| 2326 | t1.join() |
| 2327 | t2.join() |
| 2328 | t3.join() |
| 2329 | t4.join() |
| 2330 | t5.join() |
| 2331 | t6.join() |
| 2332 | t7.join() |
| 2333 | t8.join() |
| 2334 | t9.join() |
| 2335 | t10.join() |
| 2336 | |
| 2337 | if len(success_dir) != 10: |
| 2338 | self.success = False |
| 2339 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2340 | assert_equal(self.success, True) |
| 2341 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2342 | @nottest |
| 2343 | def test_1000k_flow_ip(self): |
| 2344 | egress = 1 |
| 2345 | ingress = 2 |
| 2346 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' } |
| 2347 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2348 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2349 | |
| 2350 | for i in range(0,1000000): |
| 2351 | ingress_map['ip'] = self.next_ip(ingress_map['ip']) |
| 2352 | assert_not_equal(ingress_map['ip'], None) |
| 2353 | egress_map['ip'] = self.to_egress_ip(ingress_map['ip']) |
| 2354 | |
| 2355 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2356 | egressPort = egress, |
| 2357 | ingressPort = ingress, |
| 2358 | ethType = '0x0800', |
| 2359 | ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'), |
| 2360 | ipDst = ('IPV4_DST', egress_map['ip']+'/8') |
| 2361 | ) |
| 2362 | result = flow.addFlow() |
| 2363 | assert_equal(result, True) |
| 2364 | ##wait for flows to be added to ONOS |
| 2365 | time.sleep(1) |
| 2366 | log.info("%d flow added.",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2367 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2368 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2369 | def verify_flow(*r): |
| 2370 | random_src = ''.join(r) |
| 2371 | random_dst = self.to_egress_ip(random_src) |
| 2372 | def mac_recv_task(): |
| 2373 | def recv_cb(pkt): |
| 2374 | log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
| 2375 | success_dir[current_thread().name] = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2376 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2377 | sniff(count=2, timeout=5, lfilter = lambda p: IP in p and p[IP].dst == random_dst and p[IP].src == random_src |
| 2378 | ,prn = recv_cb, iface = self.port_map[egress]) |
| 2379 | |
| 2380 | t = threading.Thread(target = mac_recv_task) |
| 2381 | t.start() |
| 2382 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2383 | L3 = IP(src = random_src, dst = random_dst) |
| 2384 | pkt = L2/L3 |
| 2385 | log.info('Sending packets to verify if flows are correct') |
| 2386 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2387 | t.join() |
| 2388 | |
| 2389 | t1 = threading.Thread(target = verify_flow, args = '192.0.0.1') |
| 2390 | t2 = threading.Thread(target = verify_flow, args = '192.0.50.' + str(random.randrange(1,255,1))) |
| 2391 | t3 = threading.Thread(target = verify_flow, args = '192.0.100.' + str(random.randrange(1,255,1))) |
| 2392 | t4 = threading.Thread(target = verify_flow, args = '192.0.150.' + str(random.randrange(1,255,1))) |
| 2393 | t5 = threading.Thread(target = verify_flow, args = '192.0.200.' + str(random.randrange(1,255,1))) |
| 2394 | t6 = threading.Thread(target = verify_flow, args = '192.0.250.' + str(random.randrange(1,255,1))) |
| 2395 | t7 = threading.Thread(target = verify_flow, args = '192.0.250.' + str(random.randrange(1,255,1))) |
| 2396 | t8 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(1,150,1)) + '.' |
| 2397 | + str(random.randrange(1,255,1))) |
| 2398 | t9 = threading.Thread(target = verify_flow, args = '192.1.'+str(random.randrange(152,255,1)) + '.' |
| 2399 | + str(random.randrange(1,255,1))) |
| 2400 | t10 = threading.Thread(target = verify_flow, args = '192.15.66.64') |
| 2401 | |
| 2402 | t1.start() |
| 2403 | t2.start() |
| 2404 | t3.start() |
| 2405 | t4.start() |
| 2406 | t5.start() |
| 2407 | t6.start() |
| 2408 | t7.start() |
| 2409 | t8.start() |
| 2410 | t9.start() |
| 2411 | t10.start() |
| 2412 | |
| 2413 | t1.join() |
| 2414 | t2.join() |
| 2415 | t3.join() |
| 2416 | t4.join() |
| 2417 | t5.join() |
| 2418 | t6.join() |
| 2419 | t7.join() |
| 2420 | t8.join() |
| 2421 | t9.join() |
| 2422 | t10.join() |
| 2423 | |
| 2424 | if len(success_dir) != 10: |
| 2425 | self.success = False |
| 2426 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2427 | assert_equal(self.success, True) |
| 2428 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2429 | def test_500_flow_tcp_port(self): |
| 2430 | egress = 1 |
| 2431 | ingress = 2 |
| 2432 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 3100 } |
| 2433 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 1100 } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2434 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2435 | |
| 2436 | for i in range(0,500): |
| 2437 | ingress_map['tcp_port'] += 1 |
| 2438 | egress_map['tcp_port'] += 1 |
| 2439 | |
| 2440 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2441 | egressPort = egress, |
| 2442 | ingressPort = ingress, |
| 2443 | tcpSrc = ingress_map['tcp_port'], |
| 2444 | tcpDst = egress_map['tcp_port'] |
| 2445 | ) |
| 2446 | |
| 2447 | result = flow.addFlow() |
| 2448 | assert_equal(result, True) |
| 2449 | ##wait for flows to be added to ONOS |
| 2450 | time.sleep(1) |
| 2451 | log.info("%d Flow added",i+1) |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2452 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2453 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2454 | def verify_flow(*r): |
| 2455 | random_sport = int(''.join(r)) |
| 2456 | random_dport = random_sport + 2000 |
| 2457 | def mac_recv_task(): |
| 2458 | def recv_cb(pkt): |
| 2459 | log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport)) |
| 2460 | success_dir[current_thread().name] = True |
| 2461 | sniff(count=2, timeout=5, |
| 2462 | 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]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2463 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2464 | t = threading.Thread(target = mac_recv_task) |
| 2465 | t.start() |
| 2466 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2467 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 2468 | L4 = TCP(sport = random_sport, dport = random_dport) |
| 2469 | pkt = L2/L3/L4 |
| 2470 | log.info('Sending packets to verify if flows are correct') |
| 2471 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2472 | t.join() |
| 2473 | t1 = threading.Thread(target = verify_flow, args = str(1101)) |
| 2474 | t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1250,1))) |
| 2475 | t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1251,1400,1))) |
| 2476 | t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1401,1590,1))) |
| 2477 | t5 = threading.Thread(target = verify_flow, args = str(1600)) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2478 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2479 | t1.start() |
| 2480 | t2.start() |
| 2481 | t3.start() |
| 2482 | t4.start() |
| 2483 | t5.start() |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2484 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2485 | t1.join() |
| 2486 | t2.join() |
| 2487 | t3.join() |
| 2488 | t4.join() |
| 2489 | t5.join() |
| 2490 | |
| 2491 | if len(success_dir) != 5: |
| 2492 | self.success = False |
| 2493 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2494 | assert_equal(self.success, True) |
| 2495 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2496 | def test_1k_flow_tcp_port(self): |
| 2497 | egress = 1 |
| 2498 | ingress = 2 |
| 2499 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 3100 } |
| 2500 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 1100 } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2501 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2502 | |
| 2503 | for i in range(0,1000): |
| 2504 | ingress_map['tcp_port'] += 1 |
| 2505 | egress_map['tcp_port'] += 1 |
| 2506 | |
| 2507 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2508 | egressPort = egress, |
| 2509 | ingressPort = ingress, |
| 2510 | tcpSrc = ingress_map['tcp_port'], |
| 2511 | tcpDst = egress_map['tcp_port'] |
| 2512 | ) |
| 2513 | |
| 2514 | result = flow.addFlow() |
| 2515 | assert_equal(result, True) |
| 2516 | ##wait for flows to be added to ONOS |
| 2517 | time.sleep(1) |
| 2518 | log.info("%d flow added.",i+1) |
| 2519 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2520 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2521 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2522 | def verify_flow(*r): |
| 2523 | random_sport = int(''.join(r)) |
| 2524 | random_dport = random_sport + 2000 |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2525 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2526 | def mac_recv_task(): |
| 2527 | def recv_cb(pkt): |
| 2528 | log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport)) |
| 2529 | success_dir[current_thread().name] = True |
| 2530 | sniff(count=2, timeout=5, |
| 2531 | 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]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2532 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2533 | t = threading.Thread(target = mac_recv_task) |
| 2534 | t.start() |
| 2535 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2536 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 2537 | L4 = TCP(sport = random_sport, dport = random_dport) |
| 2538 | pkt = L2/L3/L4 |
| 2539 | log.info('Sending packets to verify if flows are correct') |
| 2540 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2541 | t.join() |
| 2542 | |
| 2543 | t1 = threading.Thread(target = verify_flow, args = str(1101)) |
| 2544 | t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1350,1))) |
| 2545 | t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1351,1500,1))) |
| 2546 | t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1501,1700,1))) |
| 2547 | t5 = threading.Thread(target = verify_flow, args = str(random.randrange(1701,1900,1))) |
| 2548 | t6 = threading.Thread(target = verify_flow, args = str(random.randrange(1901,2000,1))) |
| 2549 | t7 = threading.Thread(target = verify_flow, args = str(random.randrange(2000,2050,1))) |
| 2550 | t8 = threading.Thread(target = verify_flow, args = str(random.randrange(2050,2080,1))) |
| 2551 | t9 = threading.Thread(target = verify_flow, args = str(random.randrange(1102,2100,1))) |
| 2552 | t10 = threading.Thread(target = verify_flow, args = str(2100)) |
| 2553 | |
| 2554 | |
| 2555 | t1.start() |
| 2556 | t2.start() |
| 2557 | t3.start() |
| 2558 | t4.start() |
| 2559 | t5.start() |
| 2560 | t6.start() |
| 2561 | t7.start() |
| 2562 | t8.start() |
| 2563 | t9.start() |
| 2564 | t10.start() |
| 2565 | |
| 2566 | t1.join() |
| 2567 | t2.join() |
| 2568 | t3.join() |
| 2569 | t4.join() |
| 2570 | t5.join() |
| 2571 | t6.join() |
| 2572 | t7.join() |
| 2573 | t8.join() |
| 2574 | t9.join() |
| 2575 | t10.join() |
| 2576 | |
| 2577 | if len(success_dir) != 10: |
| 2578 | self.success = False |
| 2579 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2580 | assert_equal(self.success, True) |
| 2581 | |
| 2582 | @nottest |
| 2583 | def test_10k_flow_tcp_port(self): |
| 2584 | egress = 1 |
| 2585 | ingress = 2 |
| 2586 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 31000 } |
| 2587 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 11000 } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2588 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2589 | |
| 2590 | for i in range(0,10000): |
| 2591 | ingress_map['tcp_port'] += 1 |
| 2592 | egress_map['tcp_port'] += 1 |
| 2593 | |
| 2594 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2595 | egressPort = egress, |
| 2596 | ingressPort = ingress, |
| 2597 | tcpSrc = ingress_map['tcp_port'], |
| 2598 | tcpDst = egress_map['tcp_port'] |
| 2599 | ) |
| 2600 | |
| 2601 | result = flow.addFlow() |
| 2602 | assert_equal(result, True) |
| 2603 | ##wait for flows to be added to ONOS |
| 2604 | time.sleep(1) |
| 2605 | log.info("%d flow added.",i+1) |
| 2606 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2607 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2608 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2609 | def verify_flow(*r): |
| 2610 | random_sport = int(''.join(r)) |
| 2611 | random_dport = random_sport + 20000 |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2612 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2613 | def mac_recv_task(): |
| 2614 | def recv_cb(pkt): |
| 2615 | log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport)) |
| 2616 | success_dir[current_thread().name] = True |
| 2617 | sniff(count=2, timeout=5, |
| 2618 | lfilter = lambda p: TCP in p and p[TCP].dport == random_dport |
| 2619 | and p[TCP].sport == random_sport,prn = recv_cb, iface = self.port_map[egress]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2620 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2621 | t = threading.Thread(target = mac_recv_task) |
| 2622 | t.start() |
| 2623 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2624 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 2625 | L4 = TCP(sport = random_sport, dport = random_dport) |
| 2626 | pkt = L2/L3/L4 |
| 2627 | log.info('Sending packets to verify if flows are correct') |
| 2628 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2629 | t.join() |
| 2630 | |
| 2631 | t1 = threading.Thread(target = verify_flow, args = str(11001)) |
| 2632 | t2 = threading.Thread(target = verify_flow, args = str(random.randrange(11110,12501,1))) |
| 2633 | t3 = threading.Thread(target = verify_flow, args = str(random.randrange(12510,14001,1))) |
| 2634 | t4 = threading.Thread(target = verify_flow, args = str(random.randrange(14010,15900,1))) |
| 2635 | t5 = threading.Thread(target = verify_flow, args = str(random.randrange(16000,17000,1))) |
| 2636 | t6 = threading.Thread(target = verify_flow, args = str(random.randrange(17001,18000,1))) |
| 2637 | t7 = threading.Thread(target = verify_flow, args = str(random.randrange(18000,19000,1))) |
| 2638 | t8 = threading.Thread(target = verify_flow, args = str(random.randrange(19000,20980,1))) |
| 2639 | t9 = threading.Thread(target = verify_flow, args = str(random.randrange(11002,21000,1))) |
| 2640 | t10 = threading.Thread(target = verify_flow, args = str(21000)) |
| 2641 | |
| 2642 | |
| 2643 | t1.start() |
| 2644 | t2.start() |
| 2645 | t3.start() |
| 2646 | t4.start() |
| 2647 | t5.start() |
| 2648 | t6.start() |
| 2649 | t7.start() |
| 2650 | t8.start() |
| 2651 | t9.start() |
| 2652 | t10.start() |
| 2653 | |
| 2654 | t1.join() |
| 2655 | t2.join() |
| 2656 | t3.join() |
| 2657 | t4.join() |
| 2658 | t5.join() |
| 2659 | t6.join() |
| 2660 | t7.join() |
| 2661 | t8.join() |
| 2662 | t9.join() |
| 2663 | t10.join() |
| 2664 | |
| 2665 | if len(success_dir) != 10: |
| 2666 | self.success = False |
| 2667 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2668 | assert_equal(self.success, True) |
| 2669 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2670 | def test_500_flow_udp_port(self): |
| 2671 | egress = 1 |
| 2672 | ingress = 2 |
| 2673 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 3100 } |
| 2674 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 1100 } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2675 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2676 | |
| 2677 | for i in range(0,500): |
| 2678 | ingress_map['udp_port'] += 1 |
| 2679 | egress_map['udp_port'] += 1 |
| 2680 | |
| 2681 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2682 | egressPort = egress, |
| 2683 | ingressPort = ingress, |
| 2684 | udpSrc = ingress_map['udp_port'], |
| 2685 | udpDst = egress_map['udp_port'] |
| 2686 | ) |
| 2687 | |
| 2688 | result = flow.addFlow() |
| 2689 | assert_equal(result, True) |
| 2690 | ##wait for flows to be added to ONOS |
| 2691 | time.sleep(1) |
| 2692 | log.info("%d flow added.",i+1) |
| 2693 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2694 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2695 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2696 | def verify_flow(*r): |
| 2697 | random_sport = int(''.join(r)) |
| 2698 | random_dport = random_sport + 2000 |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2699 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2700 | def mac_recv_task(): |
| 2701 | def recv_cb(pkt): |
| 2702 | log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport)) |
| 2703 | success_dir[current_thread().name] = True |
| 2704 | sniff(count=2, timeout=5, |
| 2705 | 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]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2706 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2707 | t = threading.Thread(target = mac_recv_task) |
| 2708 | t.start() |
| 2709 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2710 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 2711 | L4 = UDP(sport = random_sport, dport = random_dport) |
| 2712 | pkt = L2/L3/L4 |
| 2713 | log.info('Sending packets to verify if flows are correct') |
| 2714 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2715 | t.join() |
| 2716 | |
| 2717 | t1 = threading.Thread(target = verify_flow, args = str(1101)) |
| 2718 | t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1250,1))) |
| 2719 | t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1251,1400,1))) |
| 2720 | t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1401,1590,1))) |
| 2721 | t5 = threading.Thread(target = verify_flow, args = str(1600)) |
| 2722 | |
| 2723 | |
| 2724 | t1.start() |
| 2725 | t2.start() |
| 2726 | t3.start() |
| 2727 | t4.start() |
| 2728 | t5.start() |
| 2729 | |
| 2730 | t1.join() |
| 2731 | t2.join() |
| 2732 | t3.join() |
| 2733 | t4.join() |
| 2734 | t5.join() |
| 2735 | |
| 2736 | if len(success_dir) != 5: |
| 2737 | self.success = False |
| 2738 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2739 | assert_equal(self.success, True) |
| 2740 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2741 | def test_1k_flow_udp_port(self): |
| 2742 | egress = 1 |
| 2743 | ingress = 2 |
| 2744 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 3100 } |
| 2745 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 1100 } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2746 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2747 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2748 | for i in range(0,100000): |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2749 | ingress_map['udp_port'] += 1 |
| 2750 | egress_map['udp_port'] += 1 |
| 2751 | |
| 2752 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2753 | egressPort = egress, |
| 2754 | ingressPort = ingress, |
| 2755 | udpSrc = ingress_map['udp_port'], |
| 2756 | udpDst = egress_map['udp_port'] |
| 2757 | ) |
| 2758 | |
| 2759 | result = flow.addFlow() |
| 2760 | assert_equal(result, True) |
| 2761 | ##wait for flows to be added to ONOS |
| 2762 | time.sleep(1) |
| 2763 | log.info("%d flow added.",i+1) |
| 2764 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2765 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2766 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2767 | def verify_flow(*r): |
| 2768 | random_sport = int(''.join(r)) |
| 2769 | random_dport = random_sport + 2000 |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2770 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2771 | def mac_recv_task(): |
| 2772 | def recv_cb(pkt): |
| 2773 | log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport)) |
| 2774 | success_dir[current_thread().name] = True |
| 2775 | sniff(count=2, timeout=5, |
| 2776 | 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]) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2777 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2778 | t = threading.Thread(target = mac_recv_task) |
| 2779 | t.start() |
| 2780 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2781 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 2782 | L4 = UDP(sport = random_sport, dport = random_dport) |
| 2783 | pkt = L2/L3/L4 |
| 2784 | log.info('Sending packets to verify if flows are correct') |
| 2785 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2786 | t.join() |
| 2787 | |
| 2788 | t1 = threading.Thread(target = verify_flow, args = str(1101)) |
| 2789 | t2 = threading.Thread(target = verify_flow, args = str(random.randrange(1110,1350,1))) |
| 2790 | t3 = threading.Thread(target = verify_flow, args = str(random.randrange(1351,1500,1))) |
| 2791 | t4 = threading.Thread(target = verify_flow, args = str(random.randrange(1501,1700,1))) |
| 2792 | t5 = threading.Thread(target = verify_flow, args = str(random.randrange(1701,1900,1))) |
| 2793 | t6 = threading.Thread(target = verify_flow, args = str(random.randrange(1901,2000,1))) |
| 2794 | t7 = threading.Thread(target = verify_flow, args = str(random.randrange(2000,2050,1))) |
| 2795 | t8 = threading.Thread(target = verify_flow, args = str(random.randrange(2050,2080,1))) |
| 2796 | t9 = threading.Thread(target = verify_flow, args = str(random.randrange(1102,2100,1))) |
| 2797 | t10 = threading.Thread(target = verify_flow, args = str(2100)) |
| 2798 | |
| 2799 | t1.start() |
| 2800 | t2.start() |
| 2801 | t3.start() |
| 2802 | t4.start() |
| 2803 | t5.start() |
| 2804 | t6.start() |
| 2805 | t7.start() |
| 2806 | t8.start() |
| 2807 | t9.start() |
| 2808 | t10.start() |
| 2809 | |
| 2810 | t1.join() |
| 2811 | t2.join() |
| 2812 | t3.join() |
| 2813 | t4.join() |
| 2814 | t5.join() |
| 2815 | t6.join() |
| 2816 | t7.join() |
| 2817 | t8.join() |
| 2818 | t9.join() |
| 2819 | t10.join() |
| 2820 | |
| 2821 | if len(success_dir) != 10: |
| 2822 | self.success = False |
| 2823 | |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2824 | assert_equal(self.success, True) |
| 2825 | |
| 2826 | @nottest |
| 2827 | def test_10k_flow_udp_port(self): |
| 2828 | egress = 1 |
| 2829 | ingress = 2 |
| 2830 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 31000 } |
| 2831 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 11000 } |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2832 | success_dir = {} |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2833 | |
| 2834 | for i in range(0,10000): |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2835 | ingress_map['udp_port'] += 1 |
| 2836 | egress_map['udp_port'] += 1 |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2837 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2838 | flow = OnosFlowCtrl(deviceId = self.device_id, |
| 2839 | egressPort = egress, |
| 2840 | ingressPort = ingress, |
| 2841 | udpSrc = ingress_map['udp_port'], |
| 2842 | udpDst = egress_map['udp_port'] |
| 2843 | ) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2844 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2845 | result = flow.addFlow() |
| 2846 | assert_equal(result, True) |
| 2847 | ##wait for flows to be added to ONOS |
| 2848 | time.sleep(1) |
| 2849 | log.info("%d flow added.",i+1) |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2850 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2851 | self.success = True |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2852 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2853 | def verify_flow(*r): |
| 2854 | random_sport = int(''.join(r)) |
| 2855 | random_dport = random_sport + 20000 |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2856 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2857 | def mac_recv_task(): |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2858 | |
ChetanGaonker | 720ea61 | 2016-06-21 17:54:25 -0700 | [diff] [blame] | 2859 | def recv_cb(pkt): |
| 2860 | log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport)) |
| 2861 | success_dir[current_thread().name] = True |
| 2862 | sniff(count=2, timeout=5, |
| 2863 | 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]) |
| 2864 | |
| 2865 | t = threading.Thread(target = mac_recv_task) |
| 2866 | t.start() |
| 2867 | L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether']) |
| 2868 | L3 = IP(src = ingress_map['ip'], dst = egress_map['ip']) |
| 2869 | L4 = UDP(sport = random_sport, dport = random_dport) |
| 2870 | pkt = L2/L3/L4 |
| 2871 | log.info('Sending packets to verify if flows are correct') |
| 2872 | sendp(pkt, count=50, iface = self.port_map[ingress]) |
| 2873 | t.join() |
| 2874 | |
| 2875 | t1 = threading.Thread(target = verify_flow, args = str(11001)) |
| 2876 | t2 = threading.Thread(target = verify_flow, args = str(random.randrange(11110,12501,1))) |
| 2877 | t3 = threading.Thread(target = verify_flow, args = str(random.randrange(12510,14001,1))) |
| 2878 | t4 = threading.Thread(target = verify_flow, args = str(random.randrange(14010,15900,1))) |
| 2879 | t5 = threading.Thread(target = verify_flow, args = str(random.randrange(16000,17000,1))) |
| 2880 | t6 = threading.Thread(target = verify_flow, args = str(random.randrange(17001,18000,1))) |
| 2881 | t7 = threading.Thread(target = verify_flow, args = str(random.randrange(18000,19000,1))) |
| 2882 | t8 = threading.Thread(target = verify_flow, args = str(random.randrange(19000,20980,1))) |
| 2883 | t9 = threading.Thread(target = verify_flow, args = str(random.randrange(11002,21000,1))) |
| 2884 | t10 = threading.Thread(target = verify_flow, args = str(21000)) |
| 2885 | |
| 2886 | |
| 2887 | t1.start() |
| 2888 | t2.start() |
| 2889 | t3.start() |
| 2890 | t4.start() |
| 2891 | t5.start() |
| 2892 | t6.start() |
| 2893 | t7.start() |
| 2894 | t8.start() |
| 2895 | t9.start() |
| 2896 | t10.start() |
| 2897 | |
| 2898 | t1.join() |
| 2899 | t2.join() |
| 2900 | t3.join() |
| 2901 | t4.join() |
| 2902 | t5.join() |
| 2903 | t6.join() |
| 2904 | t7.join() |
| 2905 | t8.join() |
| 2906 | t9.join() |
| 2907 | t10.join() |
| 2908 | |
| 2909 | if len(success_dir) != 10: |
| 2910 | self.success = False |
ChetanGaonker | a6adc0b | 2016-06-12 12:21:14 -0700 | [diff] [blame] | 2911 | assert_equal(self.success, True) |