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