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