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