ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -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 | eff07bc | 2016-06-09 16:39:23 -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 | eff07bc | 2016-06-09 16:39:23 -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 | cbe7964 | 2016-03-09 17:45:58 -0800 | [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, monotonic |
| 22 | import os, sys |
| 23 | import tempfile |
| 24 | import random |
| 25 | import threading |
| 26 | from Stats import Stats |
| 27 | from OnosCtrl import OnosCtrl |
| 28 | from DHCP import DHCPTest |
| 29 | from EapTLS import TLSAuthTest |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 30 | from Channels import Channels, IgmpChannel |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 31 | from subscriberDb import SubscriberDB |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 32 | from threadPool import ThreadPool |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 33 | from portmaps import g_subscriber_port_map |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 34 | from OltConfig import * |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 35 | from CordContainer import * |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 36 | from CordTestServer import cord_test_radius_restart |
| 37 | from CordLogger import CordLogger |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 38 | import copy |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 39 | log.setLevel('INFO') |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 40 | DEFAULT_NO_CHANNELS = 1 |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 41 | |
| 42 | class Subscriber(Channels): |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 43 | PORT_TX_DEFAULT = 2 |
| 44 | PORT_RX_DEFAULT = 1 |
| 45 | INTF_TX_DEFAULT = 'veth2' |
| 46 | INTF_RX_DEFAULT = 'veth0' |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 47 | STATS_RX = 0 |
| 48 | STATS_TX = 1 |
| 49 | STATS_JOIN = 2 |
| 50 | STATS_LEAVE = 3 |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 51 | SUBSCRIBER_SERVICES = 'DHCP IGMP TLS' |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 52 | |
| 53 | |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 54 | def __init__(self, name = 'sub', service = SUBSCRIBER_SERVICES, port_map = None, |
| 55 | num = 1, channel_start = 0, |
| 56 | tx_port = PORT_TX_DEFAULT, rx_port = PORT_RX_DEFAULT, |
| 57 | iface = INTF_RX_DEFAULT, iface_mcast = INTF_TX_DEFAULT, |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 58 | mcast_cb = None, loginType = 'wireless'): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 59 | self.tx_port = tx_port |
| 60 | self.rx_port = rx_port |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 61 | self.port_map = port_map or g_subscriber_port_map |
| 62 | try: |
| 63 | self.tx_intf = self.port_map[tx_port] |
| 64 | self.rx_intf = self.port_map[rx_port] |
| 65 | except: |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 66 | self.tx_intf = self.port_map[self.PORT_TX_DEFAULT] |
| 67 | self.rx_intf = self.port_map[self.PORT_RX_DEFAULT] |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 68 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 69 | Channels.__init__(self, num, channel_start = channel_start, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 70 | iface = self.rx_intf, iface_mcast = self.tx_intf, mcast_cb = mcast_cb) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 71 | self.name = name |
| 72 | self.service = service |
| 73 | self.service_map = {} |
| 74 | services = self.service.strip().split(' ') |
| 75 | for s in services: |
| 76 | self.service_map[s] = True |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 77 | self.loginType = loginType |
| 78 | ##start streaming channels |
| 79 | self.join_map = {} |
| 80 | ##accumulated join recv stats |
| 81 | self.join_rx_stats = Stats() |
| 82 | |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 83 | def has_service(self, service): |
| 84 | if self.service_map.has_key(service): |
| 85 | return self.service_map[service] |
| 86 | if self.service_map.has_key(service.upper()): |
| 87 | return self.service_map[service.upper()] |
| 88 | return False |
| 89 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 90 | def channel_join_update(self, chan, join_time): |
| 91 | self.join_map[chan] = ( Stats(), Stats(), Stats(), Stats() ) |
| 92 | self.channel_update(chan, self.STATS_JOIN, 1, t = join_time) |
| 93 | |
| 94 | def channel_join(self, chan = 0, delay = 2): |
| 95 | '''Join a channel and create a send/recv stats map''' |
| 96 | if self.join_map.has_key(chan): |
| 97 | del self.join_map[chan] |
| 98 | self.delay = delay |
| 99 | chan, join_time = self.join(chan) |
| 100 | self.channel_join_update(chan, join_time) |
| 101 | return chan |
| 102 | |
| 103 | def channel_join_next(self, delay = 2): |
| 104 | '''Joins the next channel leaving the last channel''' |
| 105 | if self.last_chan: |
| 106 | if self.join_map.has_key(self.last_chan): |
| 107 | del self.join_map[self.last_chan] |
| 108 | self.delay = delay |
| 109 | chan, join_time = self.join_next() |
| 110 | self.channel_join_update(chan, join_time) |
| 111 | return chan |
| 112 | |
| 113 | def channel_jump(self, delay = 2): |
| 114 | '''Jumps randomly to the next channel leaving the last channel''' |
Chetan Gaonker | 4a82bae | 2016-05-19 17:35:30 -0700 | [diff] [blame] | 115 | log.info("Jumps randomly to the next channel leaving the last channel") |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 116 | if self.last_chan is not None: |
| 117 | if self.join_map.has_key(self.last_chan): |
| 118 | del self.join_map[self.last_chan] |
| 119 | self.delay = delay |
| 120 | chan, join_time = self.jump() |
| 121 | self.channel_join_update(chan, join_time) |
| 122 | return chan |
| 123 | |
| 124 | def channel_leave(self, chan = 0): |
| 125 | if self.join_map.has_key(chan): |
| 126 | del self.join_map[chan] |
| 127 | self.leave(chan) |
| 128 | |
| 129 | def channel_update(self, chan, stats_type, packets, t=0): |
| 130 | if type(chan) == type(0): |
| 131 | chan_list = (chan,) |
| 132 | else: |
| 133 | chan_list = chan |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 134 | for c in chan_list: |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 135 | if self.join_map.has_key(c): |
| 136 | self.join_map[c][stats_type].update(packets = packets, t = t) |
| 137 | |
| 138 | def channel_receive(self, chan, cb = None, count = 1): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 139 | log.info('Subscriber %s receiving from group %s, channel %d' %(self.name, self.gaddr(chan), chan)) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 140 | self.recv(chan, cb = cb, count = count) |
| 141 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 142 | def recv_channel_cb(self, pkt): |
| 143 | ##First verify that we have received the packet for the joined instance |
| 144 | log.debug('Packet received for group %s, subscriber %s' %(pkt[IP].dst, self.name)) |
| 145 | chan = self.caddr(pkt[IP].dst) |
| 146 | assert_equal(chan in self.join_map.keys(), True) |
| 147 | recv_time = monotonic.monotonic() * 1000000 |
| 148 | join_time = self.join_map[chan][self.STATS_JOIN].start |
| 149 | delta = recv_time - join_time |
| 150 | self.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 151 | self.channel_update(chan, self.STATS_RX, 1, t = delta) |
| 152 | log.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
| 153 | |
| 154 | class subscriber_pool: |
| 155 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 156 | def __init__(self, subscriber, test_cbs, test_status): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 157 | self.subscriber = subscriber |
| 158 | self.test_cbs = test_cbs |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 159 | self.test_status = test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 160 | |
| 161 | def pool_cb(self): |
| 162 | for cb in self.test_cbs: |
| 163 | if cb: |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 164 | self.test_status = cb(self.subscriber) |
| 165 | # cb(self.subscriber) |
| 166 | if self.test_status is not True: |
| 167 | log.info('This service is failed and other services will not run for this subscriber') |
| 168 | break |
| 169 | log.info('This Subscriber is tested for multiple service elgibility ') |
| 170 | self.test_status = True |
| 171 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 172 | class subscriber_exchange(CordLogger): |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 173 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 174 | apps = [ 'org.opencord.aaa', 'org.onosproject.dhcp' ] |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 175 | |
| 176 | dhcp_app = 'org.onosproject.dhcp' |
| 177 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 178 | olt_apps = [ 'org.opencord.igmp', 'org.opencord.cordmcast' ] |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 179 | dhcp_server_config = { |
| 180 | "ip": "10.1.11.50", |
| 181 | "mac": "ca:fe:ca:fe:ca:fe", |
| 182 | "subnet": "255.255.252.0", |
| 183 | "broadcast": "10.1.11.255", |
| 184 | "router": "10.1.8.1", |
| 185 | "domain": "8.8.8.8", |
| 186 | "ttl": "63", |
| 187 | "delay": "2", |
| 188 | "startip": "10.1.11.51", |
| 189 | "endip": "10.1.11.100" |
| 190 | } |
| 191 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 192 | aaa_loaded = False |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 193 | INTF_TX_DEFAULT = 'veth2' |
| 194 | INTF_RX_DEFAULT = 'veth0' |
| 195 | SUBSCRIBER_TIMEOUT = 20 |
| 196 | |
| 197 | CLIENT_CERT = """-----BEGIN CERTIFICATE----- |
| 198 | MIICuDCCAiGgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx |
| 199 | CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h |
| 200 | IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd |
| 201 | RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwNjA2MjExMjI3WhcN |
| 202 | MTcwNjAxMjExMjI3WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV |
| 203 | BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI |
| 204 | hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC |
| 205 | gYEAwvXiSzb9LZ6c7uNziUfKvoHO7wu/uiFC5YUpXbmVGuGZizbVrny0xnR85Dfe |
| 206 | +9R4diansfDhIhzOUl1XjN3YDeSS9OeF5YWNNE8XDhlz2d3rVzaN6hIhdotBkUjg |
| 207 | rUewjTg5OFR31QEyG3v8xR3CLgiE9xQELjZbSA07pD79zuUCAwEAAaNPME0wEwYD |
| 208 | VR0lBAwwCgYIKwYBBQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5l |
| 209 | eGFtcGxlLmNvbS9leGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOBgQDAjkrY |
| 210 | 6tDChmKbvr8w6Du/t8vHjTCoCIocHTN0qzWOeb1YsAGX89+TrWIuO1dFyYd+Z0KC |
| 211 | PDKB5j/ygml9Na+AklSYAVJIjvlzXKZrOaPmhZqDufi+rXWti/utVqY4VMW2+HKC |
| 212 | nXp37qWeuFLGyR1519Y1d6F/5XzqmvbwURuEug== |
| 213 | -----END CERTIFICATE-----""" |
| 214 | |
| 215 | CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE----- |
| 216 | MIIDvTCCAqWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx |
| 217 | CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h |
| 218 | IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd |
| 219 | RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzExMTg1MzM2WhcN |
| 220 | MTcwMzA2MTg1MzM2WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV |
| 221 | BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI |
| 222 | hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC |
| 223 | AQoCggEBAOxemcBsPn9tZsCa5o2JA6sQDC7A6JgCNXXl2VFzKLNNvB9PS6D7ZBsQ |
| 224 | 5An0zEDMNzi51q7lnrYg1XyiE4S8FzMGAFr94RlGMQJUbRD9V/oqszMX4k++iAOK |
| 225 | tIA1gr3x7Zi+0tkjVSVzXTmgNnhChAamdMsjYUG5+CY9WAicXyy+VEV3zTphZZDR |
| 226 | OjcjEp4m/TSXVPYPgYDXI40YZKX5BdvqykWtT/tIgZb48RS1NPyN/XkCYzl3bv21 |
| 227 | qx7Mc0fcEbsJBIIRYTUkfxnsilcnmLxSYO+p+DZ9uBLBzcQt+4Rd5pLSfi21WM39 |
| 228 | 2Z2oOi3vs/OYAPAqgmi2JWOv3mePa/8CAwEAAaNPME0wEwYDVR0lBAwwCgYIKwYB |
| 229 | BQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5leGFtcGxlLmNvbS9l |
| 230 | eGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOCAQEALBzMPDTIB6sLyPl0T6JV |
| 231 | MjOkyldAVhXWiQsTjaGQGJUUe1cmUJyZbUZEc13MygXMPOM4x7z6VpXGuq1c/Vxn |
| 232 | VzQ2fNnbJcIAHi/7G8W5/SQfPesIVDsHTEc4ZspPi5jlS/MVX3HOC+BDbOjdbwqP |
| 233 | RX0JEr+uOyhjO+lRxG8ilMRACoBUbw1eDuVDoEBgErSUC44pq5ioDw2xelc+Y6hQ |
| 234 | dmtYwfY0DbvwxHtA495frLyPcastDiT/zre7NL51MyUDPjjYjghNQEwvu66IKbQ3 |
| 235 | T1tJBrgI7/WI+dqhKBFolKGKTDWIHsZXQvZ1snGu/FRYzg1l+R/jT8cRB9BDwhUt |
| 236 | yg== |
| 237 | -----END CERTIFICATE-----''' |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 238 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 239 | def setUp(self): |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 240 | '''Load the OLT config and activate relevant apps''' |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 241 | super(subscriber_exchange, self).setUp() |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 242 | self.olt = OltConfig() |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 243 | self.port_map, _ = self.olt.olt_port_map() |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 244 | ##if no olt config, fall back to ovs port map |
| 245 | if not self.port_map: |
| 246 | self.port_map = g_subscriber_port_map |
| 247 | else: |
| 248 | log.info('Using OLT Port configuration for test setup') |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 249 | log.info('Configuring CORD OLT access device information') |
| 250 | OnosCtrl.cord_olt_config(self.olt.olt_device_data()) |
| 251 | self.activate_apps(self.olt_apps) |
| 252 | |
| 253 | self.activate_apps(self.apps) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 254 | |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 255 | def tearDown(self): |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 256 | '''Deactivate the dhcp app''' |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 257 | super(subscriber_exchange, self).tearDown() |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 258 | for app in self.apps: |
| 259 | onos_ctrl = OnosCtrl(app) |
| 260 | onos_ctrl.deactivate() |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 261 | log.info('Restarting the Radius container in the setup after running every subscriber test cases by default') |
A R Karthick | 9313b76 | 2016-11-07 13:14:35 -0800 | [diff] [blame] | 262 | cord_test_radius_restart() |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 263 | #os.system('ifconfig '+INTF_RX_DEFAULT+' up') |
| 264 | |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 265 | def activate_apps(self, apps): |
Chetan Gaonker | 735495f | 2016-05-10 14:51:16 -0700 | [diff] [blame] | 266 | for app in apps: |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 267 | onos_ctrl = OnosCtrl(app) |
| 268 | status, _ = onos_ctrl.activate() |
| 269 | assert_equal(status, True) |
| 270 | time.sleep(2) |
| 271 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 272 | def onos_aaa_load(self): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 273 | if self.aaa_loaded: |
| 274 | return |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 275 | aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password', |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 276 | 'radiusIp': '172.17.0.2' } } } } |
| 277 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
| 278 | aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip |
| 279 | self.onos_load_config('org.onosproject.aaa', aaa_dict) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 280 | self.aaa_loaded = True |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 281 | |
| 282 | def onos_dhcp_table_load(self, config = None): |
| 283 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 284 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 285 | if config: |
| 286 | for k in config.keys(): |
| 287 | if dhcp_config.has_key(k): |
| 288 | dhcp_config[k] = config[k] |
| 289 | self.onos_load_config('org.onosproject.dhcp', dhcp_dict) |
| 290 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 291 | def send_recv(self, mac = None, update_seed = False, validate = True): |
| 292 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 293 | if validate: |
| 294 | assert_not_equal(cip, None) |
| 295 | assert_not_equal(sip, None) |
| 296 | log.info('Got dhcp client IP %s from server %s for mac %s' % |
| 297 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
| 298 | return cip,sip |
| 299 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 300 | def onos_load_config(self, app, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 301 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 302 | if status is False: |
| 303 | log.info('JSON config request for app %s returned status %d' %(app, code)) |
| 304 | assert_equal(status, True) |
| 305 | time.sleep(2) |
| 306 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 307 | def dhcp_sndrcv(self, dhcp, update_seed = False): |
| 308 | cip, sip = dhcp.discover(update_seed = update_seed) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 309 | assert_not_equal(cip, None) |
| 310 | assert_not_equal(sip, None) |
| 311 | log.info('Got dhcp client IP %s from server %s for mac %s' % |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 312 | (cip, sip, dhcp.get_mac(cip)[0])) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 313 | return cip,sip |
| 314 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 315 | def dhcp_request(self, subscriber, seed_ip = '10.10.10.1', update_seed = False): |
Chetan Gaonker | 0097120 | 2016-03-23 15:11:12 -0700 | [diff] [blame] | 316 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.200', |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 317 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 318 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 319 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 320 | dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface) |
| 321 | cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 322 | return cip, sip |
| 323 | |
| 324 | def recv_channel_cb(self, pkt): |
| 325 | ##First verify that we have received the packet for the joined instance |
| 326 | chan = self.subscriber.caddr(pkt[IP].dst) |
| 327 | assert_equal(chan in self.subscriber.join_map.keys(), True) |
| 328 | recv_time = monotonic.monotonic() * 1000000 |
| 329 | join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start |
| 330 | delta = recv_time - join_time |
| 331 | self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 332 | self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 333 | log.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 334 | self.test_status = True |
| 335 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 336 | def tls_verify(self, subscriber): |
| 337 | if subscriber.has_service('TLS'): |
| 338 | time.sleep(2) |
| 339 | tls = TLSAuthTest() |
| 340 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 341 | tls.runTest() |
| 342 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 343 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 344 | |
| 345 | def dhcp_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 346 | cip, sip = self.dhcp_request(subscriber, update_seed = True) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 347 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 348 | subscriber.src_list = [cip] |
| 349 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 350 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 351 | |
| 352 | def dhcp_jump_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 353 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1') |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 354 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 355 | subscriber.src_list = [cip] |
| 356 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 357 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 358 | |
| 359 | def dhcp_next_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 360 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.150.1') |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 361 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 362 | subscriber.src_list = [cip] |
| 363 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 364 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 365 | |
| 366 | def igmp_verify(self, subscriber): |
| 367 | chan = 0 |
| 368 | if subscriber.has_service('IGMP'): |
| 369 | for i in range(5): |
| 370 | log.info('Joining channel %d for subscriber %s' %(chan, subscriber.name)) |
| 371 | subscriber.channel_join(chan, delay = 0) |
| 372 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 373 | log.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name)) |
| 374 | subscriber.channel_leave(chan) |
| 375 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 376 | log.info('Interface %s Join RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name,subscriber.join_rx_stats)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 377 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 378 | return self.test_status |
| 379 | |
| 380 | def igmp_verify_multiChannel(self, subscriber): |
| 381 | if subscriber.has_service('IGMP'): |
| 382 | for chan in range(DEFAULT_NO_CHANNELS): |
| 383 | log.info('Joining channel %d for subscriber %s' %(chan, subscriber.name)) |
| 384 | subscriber.channel_join(chan, delay = 0) |
| 385 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 386 | log.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name)) |
| 387 | subscriber.channel_leave(chan) |
| 388 | time.sleep(3) |
| 389 | log.info('Interface %s Join RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name,subscriber.join_rx_stats)) |
| 390 | self.test_status = True |
| 391 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 392 | |
| 393 | def igmp_jump_verify(self, subscriber): |
| 394 | if subscriber.has_service('IGMP'): |
| 395 | for i in xrange(subscriber.num): |
| 396 | log.info('Subscriber %s jumping channel' %subscriber.name) |
| 397 | chan = subscriber.channel_jump(delay=0) |
| 398 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 399 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 400 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 401 | log.info('Interface %s Jump RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 402 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 403 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 404 | |
| 405 | def igmp_next_verify(self, subscriber): |
| 406 | if subscriber.has_service('IGMP'): |
| 407 | for i in xrange(subscriber.num): |
| 408 | if i: |
| 409 | chan = subscriber.channel_join_next(delay=0) |
| 410 | else: |
| 411 | chan = subscriber.channel_join(i, delay=0) |
| 412 | log.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name)) |
| 413 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1) |
| 414 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 415 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 416 | log.info('Interface %s Join Next RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 417 | self.test_status = True |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 418 | return self.test_status |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 419 | |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 420 | def generate_port_list(self, subscribers, channels): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 421 | port_list = [] |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 422 | for i in xrange(subscribers): |
| 423 | if channels > 1: |
| 424 | rx_port = 2*i+1 |
| 425 | tx_port = 2*i+2 |
| 426 | else: |
| 427 | rx_port = Subscriber.PORT_RX_DEFAULT |
| 428 | tx_port = Subscriber.PORT_TX_DEFAULT |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 429 | port_list.append((tx_port, rx_port)) |
| 430 | return port_list |
| 431 | |
| 432 | def subscriber_load(self, create = True, num = 10, num_channels = 1, channel_start = 0, port_list = []): |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 433 | '''Load the subscriber from the database''' |
| 434 | self.subscriber_db = SubscriberDB(create = create) |
| 435 | if create is True: |
| 436 | self.subscriber_db.generate(num) |
| 437 | self.subscriber_info = self.subscriber_db.read(num) |
| 438 | self.subscriber_list = [] |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 439 | if not port_list: |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 440 | port_list = self.generate_port_list(num, num_channels) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 441 | |
| 442 | index = 0 |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 443 | for info in self.subscriber_info: |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 444 | self.subscriber_list.append(Subscriber(name=info['Name'], |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 445 | service=info['Service'], |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 446 | port_map = self.port_map, |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 447 | num=num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 448 | channel_start = channel_start, |
| 449 | tx_port = port_list[index][0], |
| 450 | rx_port = port_list[index][1])) |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 451 | if num_channels > 1: |
| 452 | channel_start += num_channels |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 453 | index += 1 |
| 454 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 455 | #load the ssm list for all subscriber channels |
| 456 | igmpChannel = IgmpChannel() |
| 457 | ssm_groups = map(lambda sub: sub.channels, self.subscriber_list) |
| 458 | ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups) |
| 459 | igmpChannel.igmp_load_ssm_config(ssm_list) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 460 | #load the subscriber to mcast port map for cord |
| 461 | cord_port_map = {} |
| 462 | for sub in self.subscriber_list: |
| 463 | for chan in sub.channels: |
| 464 | cord_port_map[chan] = (sub.tx_port, sub.rx_port) |
| 465 | |
| 466 | igmpChannel.cord_port_table_load(cord_port_map) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 467 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 468 | def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1, |
| 469 | channel_start = 0, cbs = None, port_list = [], negative_subscriber_auth = None): |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 470 | self.test_status = False |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 471 | self.num_subscribers = num_subscribers |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 472 | self.sub_loop_count = num_subscribers |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 473 | self.subscriber_load(create = True, num = num_subscribers, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 474 | num_channels = num_channels, channel_start = channel_start, port_list = port_list) |
Chetan Gaonker | 55fc788 | 2016-03-15 17:46:47 -0700 | [diff] [blame] | 475 | self.onos_aaa_load() |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 476 | self.thread_pool = ThreadPool(min(100, self.num_subscribers), queue_size=1, wait_timeout=1) |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 477 | |
| 478 | if cbs and negative_subscriber_auth is None: |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 479 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify) |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 480 | cbs_negative = cbs |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 481 | for subscriber in self.subscriber_list: |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 482 | subscriber.start() |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 483 | if negative_subscriber_auth is 'half' and self.sub_loop_count%2 is not 0: |
| 484 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify) |
| 485 | elif negative_subscriber_auth is 'onethird' and self.sub_loop_count%3 is not 0: |
| 486 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify) |
| 487 | else: |
| 488 | cbs = cbs_negative |
| 489 | self.sub_loop_count = self.sub_loop_count - 1 |
| 490 | pool_object = subscriber_pool(subscriber, cbs, self.test_status) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 491 | self.thread_pool.addTask(pool_object.pool_cb) |
| 492 | self.thread_pool.cleanUpThreads() |
| 493 | for subscriber in self.subscriber_list: |
| 494 | subscriber.stop() |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 495 | print "self.test_status %s\n"%(self.test_status) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 496 | return self.test_status |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 497 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 498 | def tls_invalid_cert(self, subscriber): |
| 499 | if subscriber.has_service('TLS'): |
| 500 | time.sleep(2) |
| 501 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 502 | tls = TLSAuthTest(client_cert = self.CLIENT_CERT_INVALID) |
| 503 | tls.runTest() |
| 504 | if tls.failTest == True: |
| 505 | self.test_status = False |
| 506 | return self.test_status |
| 507 | |
| 508 | def tls_no_cert(self, subscriber): |
| 509 | if subscriber.has_service('TLS'): |
| 510 | time.sleep(2) |
| 511 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 512 | tls = TLSAuthTest(client_cert = '') |
| 513 | tls.runTest() |
| 514 | if tls.failTest == True: |
| 515 | self.test_status = False |
| 516 | return self.test_status |
| 517 | |
| 518 | def tls_self_signed_cert(self, subscriber): |
| 519 | if subscriber.has_service('TLS'): |
| 520 | time.sleep(2) |
| 521 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 522 | tls = TLSAuthTest(client_cert = self.CLIENT_CERT) |
| 523 | tls.runTest() |
| 524 | if tls.failTest == False: |
| 525 | self.test_status = True |
| 526 | return self.test_status |
| 527 | |
| 528 | def tls_Nsubscribers_use_same_valid_cert(self, subscriber): |
| 529 | if subscriber.has_service('TLS'): |
| 530 | time.sleep(2) |
| 531 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 532 | num_users = 3 |
| 533 | for i in xrange(num_users): |
| 534 | tls = TLSAuthTest(intf = 'veth{}'.format(i*2)) |
| 535 | tls.runTest() |
| 536 | if tls.failTest == False: |
| 537 | self.test_status = True |
| 538 | return self.test_status |
| 539 | |
| 540 | def dhcp_discover_scenario(self, subscriber): |
| 541 | if subscriber.has_service('DHCP'): |
| 542 | time.sleep(2) |
| 543 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 544 | t1 = self.subscriber_dhcp_1release() |
| 545 | self.test_status = True |
| 546 | return self.test_status |
| 547 | |
| 548 | def subscriber_dhcp_1release(self, iface = INTF_RX_DEFAULT): |
| 549 | config = {'startip':'10.10.100.20', 'endip':'10.10.100.21', |
| 550 | 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe", |
| 551 | 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'} |
| 552 | self.onos_dhcp_table_load(config) |
| 553 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
| 554 | cip, sip = self.send_recv() |
| 555 | log.info('Releasing ip %s to server %s' %(cip, sip)) |
| 556 | assert_equal(self.dhcp.release(cip), True) |
| 557 | log.info('Triggering DHCP discover again after release') |
| 558 | cip2, sip2 = self.send_recv(update_seed = True) |
| 559 | log.info('Verifying released IP was given back on rediscover') |
| 560 | assert_equal(cip, cip2) |
| 561 | log.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
| 562 | assert_equal(self.dhcp.release(cip2), True) |
| 563 | |
| 564 | |
| 565 | def dhcp_client_reboot_scenario(self, subscriber): |
| 566 | if subscriber.has_service('DHCP'): |
| 567 | time.sleep(2) |
| 568 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 569 | tl = self.subscriber_dhcp_client_request_after_reboot() |
| 570 | self.test_status = True |
| 571 | return self.test_status |
| 572 | |
| 573 | def subscriber_dhcp_client_request_after_reboot(self, iface = INTF_RX_DEFAULT): |
| 574 | #''' Client sends DHCP Request after reboot.''' |
| 575 | |
| 576 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 577 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 578 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 579 | self.onos_dhcp_table_load(config) |
| 580 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 581 | cip, sip, mac, lval = self.dhcp.only_discover() |
| 582 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 583 | (cip, sip, mac) ) |
| 584 | |
| 585 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 586 | |
| 587 | if (cip == None and mac != None): |
| 588 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 589 | assert_not_equal(cip, None) |
| 590 | |
| 591 | else: |
| 592 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 593 | if new_cip == None: |
| 594 | log.info("Got DHCP server NAK.") |
| 595 | os.system('ifconfig '+iface+' down') |
| 596 | log.info('Client goes down.') |
| 597 | log.info('Delay for 5 seconds.') |
| 598 | |
| 599 | time.sleep(5) |
| 600 | |
| 601 | os.system('ifconfig '+iface+' up') |
| 602 | log.info('Client is up now.') |
| 603 | |
| 604 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 605 | if new_cip == None: |
| 606 | log.info("Got DHCP server NAK.") |
| 607 | assert_not_equal(new_cip, None) |
| 608 | elif new_cip != None: |
| 609 | log.info("Got DHCP ACK.") |
| 610 | |
| 611 | |
| 612 | def dhcp_client_renew_scenario(self, subscriber): |
| 613 | if subscriber.has_service('DHCP'): |
| 614 | time.sleep(2) |
| 615 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 616 | tl = self.subscriber_dhcp_client_renew_time() |
| 617 | self.test_status = True |
| 618 | return self.test_status |
| 619 | |
| 620 | def subscriber_dhcp_client_renew_time(self, iface = INTF_RX_DEFAULT): |
| 621 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 622 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 623 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 624 | self.onos_dhcp_table_load(config) |
| 625 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 626 | cip, sip, mac , lval = self.dhcp.only_discover() |
| 627 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 628 | (cip, sip, mac) ) |
| 629 | |
| 630 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 631 | if (cip == None and mac != None): |
| 632 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 633 | assert_not_equal(cip, None) |
| 634 | elif cip and sip and mac: |
| 635 | log.info("Triggering DHCP Request.") |
| 636 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 637 | if new_cip and new_sip and lval: |
| 638 | log.info("Client 's Renewal time is :%s",lval) |
| 639 | log.info("Generating delay till renewal time.") |
| 640 | time.sleep(lval) |
| 641 | log.info("Client Sending Unicast DHCP request.") |
| 642 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 643 | if latest_cip and latest_sip: |
| 644 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 645 | (latest_cip, mac, latest_sip) ) |
| 646 | |
| 647 | elif latest_cip == None: |
| 648 | log.info("Got DHCP NAK. Lease not renewed.") |
| 649 | elif new_cip == None or new_sip == None or lval == None: |
| 650 | log.info("Got DHCP NAK.") |
| 651 | |
| 652 | |
| 653 | def dhcp_server_reboot_scenario(self, subscriber): |
| 654 | if subscriber.has_service('DHCP'): |
| 655 | time.sleep(2) |
| 656 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 657 | tl = self.subscriber_dhcp_server_after_reboot() |
| 658 | self.test_status = True |
| 659 | return self.test_status |
| 660 | |
| 661 | def subscriber_dhcp_server_after_reboot(self, iface = INTF_RX_DEFAULT): |
| 662 | ''' DHCP server goes down.''' |
| 663 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 664 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 665 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 666 | self.onos_dhcp_table_load(config) |
| 667 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 668 | cip, sip, mac, lval = self.dhcp.only_discover() |
| 669 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 670 | (cip, sip, mac) ) |
| 671 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 672 | if (cip == None and mac != None): |
| 673 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 674 | assert_not_equal(cip, None) |
| 675 | else: |
| 676 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 677 | if new_cip == None: |
| 678 | log.info("Got DHCP server NAK.") |
| 679 | assert_not_equal(new_cip, None) |
| 680 | log.info('Getting DHCP server Down.') |
| 681 | onos_ctrl = OnosCtrl(self.dhcp_app) |
| 682 | onos_ctrl.deactivate() |
| 683 | for i in range(0,4): |
| 684 | log.info("Sending DHCP Request.") |
| 685 | log.info('') |
| 686 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 687 | if new_cip == None and new_sip == None: |
| 688 | log.info('') |
| 689 | log.info("DHCP Request timed out.") |
| 690 | elif new_cip and new_sip: |
| 691 | log.info("Got Reply from DHCP server.") |
| 692 | assert_equal(new_cip,None) #Neagtive Test Case |
| 693 | log.info('Getting DHCP server Up.') |
| 694 | # self.activate_apps(self.dhcp_app) |
| 695 | onos_ctrl = OnosCtrl(self.dhcp_app) |
| 696 | status, _ = onos_ctrl.activate() |
| 697 | assert_equal(status, True) |
| 698 | time.sleep(3) |
| 699 | for i in range(0,4): |
| 700 | log.info("Sending DHCP Request after DHCP server is up.") |
| 701 | log.info('') |
| 702 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 703 | if new_cip == None and new_sip == None: |
| 704 | log.info('') |
| 705 | log.info("DHCP Request timed out.") |
| 706 | elif new_cip and new_sip: |
| 707 | log.info("Got Reply from DHCP server.") |
| 708 | assert_equal(new_cip,None) #Neagtive Test Case |
| 709 | |
| 710 | def dhcp_client_rebind_scenario(self, subscriber): |
| 711 | if subscriber.has_service('DHCP'): |
| 712 | time.sleep(2) |
| 713 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 714 | tl = self.subscriber_dhcp_client_rebind_time() |
| 715 | self.test_status = True |
| 716 | return self.test_status |
| 717 | |
| 718 | def subscriber_dhcp_client_rebind_time(self, iface = INTF_RX_DEFAULT): |
| 719 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 720 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 721 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 722 | self.onos_dhcp_table_load(config) |
| 723 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 724 | cip, sip, mac, lval = self.dhcp.only_discover() |
| 725 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 726 | (cip, sip, mac) ) |
| 727 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 728 | if (cip == None and mac != None): |
| 729 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 730 | assert_not_equal(cip, None) |
| 731 | elif cip and sip and mac: |
| 732 | log.info("Triggering DHCP Request.") |
| 733 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
| 734 | if new_cip and new_sip and lval: |
| 735 | log.info("Client 's Rebind time is :%s",lval) |
| 736 | log.info("Generating delay till rebind time.") |
| 737 | time.sleep(lval) |
| 738 | log.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.") |
| 739 | self.dhcp.after_T2 = True |
| 740 | for i in range(0,4): |
| 741 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 742 | if latest_cip and latest_sip: |
| 743 | log.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
| 744 | (latest_cip, mac, latest_sip) ) |
| 745 | break |
| 746 | elif latest_cip == None: |
| 747 | log.info("Got DHCP NAK. Lease not renewed.") |
| 748 | assert_not_equal(latest_cip, None) |
| 749 | elif new_cip == None or new_sip == None or lval == None: |
| 750 | log.info("Got DHCP NAK.Lease not Renewed.") |
| 751 | |
| 752 | def dhcp_starvation_scenario(self, subscriber): |
| 753 | if subscriber.has_service('DHCP'): |
| 754 | time.sleep(2) |
| 755 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 756 | tl = self.subscriber_dhcp_starvation() |
| 757 | self.test_status = True |
| 758 | return self.test_status |
| 759 | |
| 760 | |
| 761 | def subscriber_dhcp_starvation(self, iface = INTF_RX_DEFAULT): |
| 762 | '''DHCP starve''' |
| 763 | config = {'startip':'182.17.0.20', 'endip':'182.17.0.69', |
| 764 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 765 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'} |
| 766 | self.onos_dhcp_table_load(config) |
| 767 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 768 | log.info('Verifying 1 ') |
| 769 | for x in xrange(50): |
| 770 | mac = RandMAC()._fix() |
| 771 | self.send_recv(mac = mac) |
| 772 | log.info('Verifying 2 ') |
| 773 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 774 | assert_equal(cip, None) |
| 775 | assert_equal(sip, None) |
| 776 | |
| 777 | def dhcp_same_client_multi_discovers_scenario(self, subscriber): |
| 778 | if subscriber.has_service('DHCP'): |
| 779 | time.sleep(2) |
| 780 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 781 | tl = self.subscriber_dhcp_same_client_multiple_discover() |
| 782 | self.test_status = True |
| 783 | return self.test_status |
| 784 | |
| 785 | |
| 786 | def subscriber_dhcp_same_client_multiple_discover(self, iface = INTF_RX_DEFAULT): |
| 787 | ''' DHCP Client sending multiple discover . ''' |
| 788 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 789 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 790 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 791 | self.onos_dhcp_table_load(config) |
| 792 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 793 | cip, sip, mac, lval = self.dhcp.only_discover() |
| 794 | log.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
| 795 | (cip, sip, mac) ) |
| 796 | log.info('Triggering DHCP discover again.') |
| 797 | new_cip, new_sip, new_mac , lval = self.dhcp.only_discover() |
| 798 | if cip == new_cip: |
| 799 | log.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. ' |
| 800 | % (new_cip, new_sip, new_mac) ) |
| 801 | elif cip != new_cip: |
| 802 | log.info('Ip after 1st discover %s' %cip) |
| 803 | log.info('Map after 2nd discover %s' %new_cip) |
| 804 | assert_equal(cip, new_cip) |
| 805 | |
| 806 | def dhcp_same_client_multi_request_scenario(self, subscriber): |
| 807 | if subscriber.has_service('DHCP'): |
| 808 | time.sleep(2) |
| 809 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 810 | tl = self.subscriber_dhcp_same_client_multiple_request() |
| 811 | self.test_status = True |
| 812 | return self.test_status |
| 813 | |
| 814 | def subscriber_dhcp_same_client_multiple_request(self, iface = INTF_RX_DEFAULT): |
| 815 | ''' DHCP Client sending multiple repeat DHCP requests. ''' |
| 816 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 817 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 818 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 819 | self.onos_dhcp_table_load(config) |
| 820 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 821 | log.info('Sending DHCP discover and DHCP request.') |
| 822 | cip, sip = self.send_recv() |
| 823 | mac = self.dhcp.get_mac(cip)[0] |
| 824 | log.info("Sending DHCP request again.") |
| 825 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 826 | if (new_cip,new_sip) == (cip,sip): |
| 827 | log.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.' |
| 828 | % (new_cip, new_sip, mac) ) |
| 829 | elif (new_cip,new_sip): |
| 830 | log.info('No DHCP ACK') |
| 831 | assert_equal(new_cip, None) |
| 832 | assert_equal(new_sip, None) |
| 833 | else: |
| 834 | print "Something went wrong." |
| 835 | |
| 836 | |
| 837 | def dhcp_client_desired_ip_scenario(self, subscriber): |
| 838 | if subscriber.has_service('DHCP'): |
| 839 | time.sleep(2) |
| 840 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 841 | tl = self.subscriber_dhcp_client_desired_address() |
| 842 | self.test_status = True |
| 843 | return self.test_status |
| 844 | |
| 845 | def subscriber_dhcp_client_desired_address(self, iface = INTF_RX_DEFAULT): |
| 846 | '''DHCP Client asking for desired IP address.''' |
| 847 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 848 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 849 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 850 | self.onos_dhcp_table_load(config) |
| 851 | self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface) |
| 852 | cip, sip, mac , lval = self.dhcp.only_discover(desired = True) |
| 853 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 854 | (cip, sip, mac) ) |
| 855 | if cip == self.dhcp.seed_ip: |
| 856 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
| 857 | (cip, sip, mac) ) |
| 858 | elif cip != self.dhcp.seed_ip: |
| 859 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 860 | (cip, sip, mac) ) |
| 861 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 862 | assert_equal(cip, self.dhcp.seed_ip) |
| 863 | |
| 864 | def dhcp_client_request_pkt_with_non_offered_ip_scenario(self, subscriber): |
| 865 | if subscriber.has_service('DHCP'): |
| 866 | time.sleep(2) |
| 867 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 868 | tl = self.subscriber_dhcp_server_nak_packet() |
| 869 | self.test_status = True |
| 870 | return self.test_status |
| 871 | |
| 872 | def subscriber_dhcp_server_nak_packet(self, iface = INTF_RX_DEFAULT): |
| 873 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 874 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 875 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 876 | self.onos_dhcp_table_load(config) |
| 877 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 878 | cip, sip, mac, lval = self.dhcp.only_discover() |
| 879 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 880 | (cip, sip, mac) ) |
| 881 | log.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
| 882 | if (cip == None and mac != None): |
| 883 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 884 | assert_not_equal(cip, None) |
| 885 | else: |
| 886 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 887 | if new_cip == None: |
| 888 | log.info("Got DHCP server NAK.") |
| 889 | assert_equal(new_cip, None) #Negative Test Case |
| 890 | |
| 891 | def dhcp_client_requested_out_pool_ip_scenario(self, subscriber): |
| 892 | if subscriber.has_service('DHCP'): |
| 893 | time.sleep(2) |
| 894 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 895 | tl = self.subscriber_dhcp_client_desired_address_out_of_pool() |
| 896 | self.test_status = True |
| 897 | return self.test_status |
| 898 | |
| 899 | |
| 900 | def subscriber_dhcp_client_desired_address_out_of_pool(self, iface = INTF_RX_DEFAULT): |
| 901 | '''DHCP Client asking for desired IP address from out of pool.''' |
| 902 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 903 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 904 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 905 | self.onos_dhcp_table_load(config) |
| 906 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
| 907 | cip, sip, mac, lval = self.dhcp.only_discover(desired = True) |
| 908 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 909 | (cip, sip, mac) ) |
| 910 | if cip == self.dhcp.seed_ip: |
| 911 | log.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
| 912 | (cip, sip, mac) ) |
| 913 | assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case |
| 914 | |
| 915 | elif cip != self.dhcp.seed_ip: |
| 916 | log.info('Got dhcp client IP %s from server %s for mac %s .' % |
| 917 | (cip, sip, mac) ) |
| 918 | log.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
| 919 | assert_not_equal(cip, self.dhcp.seed_ip) |
| 920 | |
| 921 | elif cip == None: |
| 922 | log.info('Got DHCP NAK') |
| 923 | |
| 924 | |
| 925 | def dhcp_client_specific_lease_scenario(self, subscriber): |
| 926 | if subscriber.has_service('DHCP'): |
| 927 | time.sleep(2) |
| 928 | log.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
| 929 | tl = self.subscriber_dhcp_specific_lease_packet() |
| 930 | self.test_status = True |
| 931 | return self.test_status |
| 932 | |
| 933 | def subscriber_dhcp_specific_lease_packet(self, iface = INTF_RX_DEFAULT): |
| 934 | ''' Client sends DHCP Discover packet for particular lease time.''' |
| 935 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 936 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 937 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 938 | self.onos_dhcp_table_load(config) |
| 939 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 940 | log.info('Sending DHCP discover with lease time of 700') |
| 941 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True) |
| 942 | |
| 943 | log.info("Verifying Client 's IP and mac in DHCP Offer packet.") |
| 944 | if (cip == None and mac != None): |
| 945 | log.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
| 946 | assert_not_equal(cip, None) |
| 947 | elif lval != 700: |
| 948 | log.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
| 949 | (cip, sip, mac, lval) ) |
| 950 | assert_not_equal(lval, 700) |
| 951 | |
| 952 | def test_subscriber_join_recv_channel(self): |
| 953 | ###"""Test subscriber join and receive""" |
| 954 | num_subscribers = 1 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 955 | num_channels = 1 |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 956 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 957 | num_channels = num_channels, |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 958 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 959 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 960 | assert_equal(test_status, True) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 961 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 962 | def test_subscriber_join_jump_channel(self): |
| 963 | ###"""Test subscriber join and receive for channel surfing""" |
| 964 | num_subscribers = 1 |
| 965 | num_channels = 1 |
| 966 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 967 | num_channels = num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 968 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 969 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 970 | assert_equal(test_status, True) |
Chetan Gaonker | 4b959fc | 2016-03-09 19:20:16 -0800 | [diff] [blame] | 971 | |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 972 | def test_subscriber_join_next_channel(self): |
| 973 | ###"""Test subscriber join next for channels""" |
| 974 | num_subscribers = 1 |
| 975 | num_channels = 1 |
| 976 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 977 | num_channels = num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 978 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 979 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 980 | assert_equal(test_status, True) |
ChetanGaonker | eff07bc | 2016-06-09 16:39:23 -0700 | [diff] [blame] | 981 | |
| 982 | #@deferred(SUBSCRIBER_TIMEOUT) |
| 983 | def test_subscriber_authentication_with_invalid_certificate_and_channel_surfing(self): |
| 984 | ### """Test subscriber to auth with invalidCertification and join channel""" |
| 985 | num_subscribers = 1 |
| 986 | num_channels = 1 |
| 987 | df = defer.Deferred() |
| 988 | def sub_auth_invalid_cert(df): |
| 989 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 990 | num_channels = num_channels, |
| 991 | cbs = (self.tls_invalid_cert, self.dhcp_verify, self.igmp_verify), |
| 992 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 993 | assert_equal(test_status, False) |
| 994 | df.callback(0) |
| 995 | reactor.callLater(0, sub_auth_invalid_cert, df) |
| 996 | return df |
| 997 | |
| 998 | |
| 999 | #@deferred(SUBSCRIBER_TIMEOUT) |
| 1000 | def test_subscriber_authentication_with_no_certificate_and_channel_surfing(self): |
| 1001 | ### """Test subscriber to auth with No Certification and join channel""" |
| 1002 | num_subscribers = 1 |
| 1003 | num_channels = 1 |
| 1004 | df = defer.Deferred() |
| 1005 | def sub_auth_no_cert(df): |
| 1006 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1007 | num_channels = num_channels, |
| 1008 | cbs = (self.tls_no_cert, self.dhcp_verify, self.igmp_verify), |
| 1009 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1010 | negative_subscriber_auth = 'all') |
| 1011 | assert_equal(test_status, False) |
| 1012 | df.callback(0) |
| 1013 | reactor.callLater(0, sub_auth_no_cert, df) |
| 1014 | return df |
| 1015 | |
| 1016 | def test_subscriber_authentication_with_self_signed_certificate_and_channel_surfing(self): |
| 1017 | ### """Test subscriber to auth with Self Signed Certification and join channel""" |
| 1018 | num_subscribers = 1 |
| 1019 | num_channels = 1 |
| 1020 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1021 | num_channels = num_channels, |
| 1022 | cbs = (self.tls_self_signed_cert, self.dhcp_verify, self.igmp_verify), |
| 1023 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1024 | negative_subscriber_auth = 'all') |
| 1025 | assert_equal(test_status, True) |
| 1026 | |
| 1027 | def test_subscriber_authentication_with_dhcp_discover_and_channel_surfing(self): |
| 1028 | ### """Test subscriber auth success, DHCP re-discover with DHCP server and join channel""" |
| 1029 | num_subscribers = 1 |
| 1030 | num_channels = 1 |
| 1031 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1032 | num_channels = num_channels, |
| 1033 | cbs = (self.tls_verify, self.dhcp_discover_scenario, self.igmp_verify), |
| 1034 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1035 | assert_equal(test_status, True) |
| 1036 | |
| 1037 | def test_subscriber_authentication_with_dhcp_client_reboot_scenario_and_channel_surfing(self): |
| 1038 | ### """Test subscriber auth success, DHCP client got re-booted and join channel""" |
| 1039 | num_subscribers = 1 |
| 1040 | num_channels = 1 |
| 1041 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1042 | num_channels = num_channels, |
| 1043 | cbs = (self.tls_verify, self.dhcp_client_reboot_scenario, self.igmp_verify), |
| 1044 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1045 | assert_equal(test_status, True) |
| 1046 | |
| 1047 | def test_subscriber_authentication_with_dhcp_server_reboot_scenario_and_channel_surfing(self): |
| 1048 | ### """Test subscriber auth , DHCP server re-boot during DHCP process and join channel""" |
| 1049 | num_subscribers = 1 |
| 1050 | num_channels = 1 |
| 1051 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1052 | num_channels = num_channels, |
| 1053 | cbs = (self.tls_verify, self.dhcp_server_reboot_scenario, self.igmp_verify), |
| 1054 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1055 | assert_equal(test_status, True) |
| 1056 | |
| 1057 | def test_subscriber_authentication_with_dhcp_client_rebind_and_channel_surfing(self): |
| 1058 | ### """Test subscriber auth , DHCP client rebind IP and join channel""" |
| 1059 | num_subscribers = 1 |
| 1060 | num_channels = 1 |
| 1061 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1062 | num_channels = num_channels, |
| 1063 | cbs = (self.tls_verify, self.dhcp_client_rebind_scenario, self.igmp_verify), |
| 1064 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1065 | assert_equal(test_status, True) |
| 1066 | |
| 1067 | |
| 1068 | def test_subscriber_authentication_with_dhcp_starvation_scenario_and_channel_surfing(self): |
| 1069 | ### """Test subscriber auth , DHCP starvation and join channel""" |
| 1070 | num_subscribers = 1 |
| 1071 | num_channels = 1 |
| 1072 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1073 | num_channels = num_channels, |
| 1074 | cbs = (self.tls_verify, self.dhcp_starvation_scenario, self.igmp_verify), |
| 1075 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1076 | assert_equal(test_status, True) |
| 1077 | |
| 1078 | def test_subscriber_authentication_with_multiple_dhcp_discover_for_same_subscriber_and_channel_surfing(self): |
| 1079 | ### """Test subscriber auth , sending same DHCP client discover multiple times and join channel""" |
| 1080 | num_subscribers = 1 |
| 1081 | num_channels = 1 |
| 1082 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1083 | num_channels = num_channels, |
| 1084 | cbs = (self.tls_verify, self.dhcp_same_client_multi_discovers_scenario, self.igmp_verify), |
| 1085 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1086 | assert_equal(test_status, True) |
| 1087 | |
| 1088 | def test_subscriber_authentication_with_multiple_dhcp_request_for_same_subscriber_and_channel_surfing(self): |
| 1089 | ### """Test subscriber auth , same DHCP client multiple requerts times and join channel""" |
| 1090 | num_subscribers = 1 |
| 1091 | num_channels = 1 |
| 1092 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1093 | num_channels = num_channels, |
| 1094 | cbs = (self.tls_verify, self.dhcp_same_client_multi_request_scenario, self.igmp_verify), |
| 1095 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1096 | assert_equal(test_status, True) |
| 1097 | |
| 1098 | def test_subscriber_authentication_with_dhcp_client_requested_ip_and_channel_surfing(self): |
| 1099 | ### """Test subscriber auth with DHCP client requesting ip and join channel""" |
| 1100 | num_subscribers = 1 |
| 1101 | num_channels = 1 |
| 1102 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1103 | num_channels = num_channels, |
| 1104 | cbs = (self.tls_verify, self.dhcp_client_desired_ip_scenario, self.igmp_verify), |
| 1105 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1106 | assert_equal(test_status, True) |
| 1107 | |
| 1108 | def test_subscriber_authentication_with_dhcp_non_offered_ip_and_channel_surfing(self): |
| 1109 | ### """Test subscriber auth with DHCP client request for non-offered ip and join channel""" |
| 1110 | num_subscribers = 1 |
| 1111 | num_channels = 1 |
| 1112 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1113 | num_channels = num_channels, |
| 1114 | cbs = (self.tls_verify, self.dhcp_client_request_pkt_with_non_offered_ip_scenario, self.igmp_verify), |
| 1115 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1116 | assert_equal(test_status, True) |
| 1117 | |
| 1118 | def test_subscriber_authentication_with_dhcp_request_out_of_pool_ip_by_client_and_channel_surfing(self): |
| 1119 | ### """Test subscriber auth with DHCP client requesting out of pool ip and join channel""" |
| 1120 | num_subscribers = 1 |
| 1121 | num_channels = 1 |
| 1122 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1123 | num_channels = num_channels, |
| 1124 | cbs = (self.tls_verify, self.dhcp_client_requested_out_pool_ip_scenario, self.igmp_verify), |
| 1125 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1126 | assert_equal(test_status, True) |
| 1127 | |
| 1128 | def test_subscriber_authentication_with_dhcp_specified_lease_time_functionality_and_channel_surfing(self): |
| 1129 | ### """Test subscriber auth with DHCP client specifying lease time and join channel""" |
| 1130 | num_subscribers = 1 |
| 1131 | num_channels = 1 |
| 1132 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1133 | num_channels = num_channels, |
| 1134 | cbs = (self.tls_verify, self.dhcp_client_specific_lease_scenario, self.igmp_verify), |
| 1135 | port_list = self.generate_port_list(num_subscribers, num_channels), negative_subscriber_auth = 'all') |
| 1136 | assert_equal(test_status, True) |
ChetanGaonker | 5b984cb | 2016-07-12 15:50:49 -0700 | [diff] [blame] | 1137 | |
| 1138 | |
| 1139 | def test_subscriber_join_recv_100channels(self): |
| 1140 | num_subscribers = 1 |
| 1141 | num_channels = 100 |
| 1142 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1143 | num_channels = num_channels, |
| 1144 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify), |
| 1145 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1146 | negative_subscriber_auth = 'all') |
| 1147 | assert_equal(test_status, True) |
| 1148 | |
| 1149 | def test_subscriber_join_recv_400channels(self): |
| 1150 | num_subscribers = 1 |
| 1151 | num_channels = 400 |
| 1152 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1153 | num_channels = num_channels, |
| 1154 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify), |
| 1155 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1156 | negative_subscriber_auth = 'all') |
| 1157 | assert_equal(test_status, True) |
| 1158 | |
| 1159 | def test_subscriber_join_recv_800channels(self): |
| 1160 | num_subscribers = 1 |
| 1161 | num_channels = 800 |
| 1162 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1163 | num_channels = num_channels, |
| 1164 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify), |
| 1165 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1166 | negative_subscriber_auth = 'all') |
| 1167 | assert_equal(test_status, True) |
| 1168 | |
| 1169 | def test_subscriber_join_recv_1200channels(self): |
| 1170 | num_subscribers = 1 |
| 1171 | num_channels = 1200 |
| 1172 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1173 | num_channels = num_channels, |
| 1174 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify), |
| 1175 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1176 | negative_subscriber_auth = 'all') |
| 1177 | assert_equal(test_status, True) |
| 1178 | |
| 1179 | def test_subscriber_join_recv_1500channels(self): |
| 1180 | num_subscribers = 1 |
| 1181 | num_channels = 1500 |
| 1182 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1183 | num_channels = num_channels, |
| 1184 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify), |
| 1185 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1186 | negative_subscriber_auth = 'all') |
| 1187 | assert_equal(test_status, True) |
| 1188 | |
| 1189 | def test_subscriber_join_jump_100channels(self): |
| 1190 | num_subscribers = 1 |
| 1191 | num_channels = 100 |
| 1192 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1193 | num_channels = num_channels, |
| 1194 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
| 1195 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1196 | negative_subscriber_auth = 'all') |
| 1197 | assert_equal(test_status, True) |
| 1198 | def test_subscriber_join_jump_400channels(self): |
| 1199 | num_subscribers = 1 |
| 1200 | num_channels = 400 |
| 1201 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1202 | num_channels = num_channels, |
| 1203 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
| 1204 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1205 | negative_subscriber_auth = 'all') |
| 1206 | assert_equal(test_status, True) |
| 1207 | def test_subscriber_join_jump_800channels(self): |
| 1208 | num_subscribers = 1 |
| 1209 | num_channels = 800 |
| 1210 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1211 | num_channels = num_channels, |
| 1212 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
| 1213 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1214 | negative_subscriber_auth = 'all') |
| 1215 | assert_equal(test_status, True) |
| 1216 | def test_subscriber_join_jump_1200channel(sself): |
| 1217 | num_subscribers = 1 |
| 1218 | num_channels = 1200 |
| 1219 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1220 | num_channels = num_channels, |
| 1221 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
| 1222 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1223 | negative_subscriber_auth = 'all') |
| 1224 | assert_equal(test_status, True) |
| 1225 | def test_subscriber_join_jump_1500channels(self): |
| 1226 | num_subscribers = 1 |
| 1227 | num_channels = 1500 |
| 1228 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1229 | num_channels = num_channels, |
| 1230 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
| 1231 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1232 | negative_subscriber_auth = 'all') |
| 1233 | assert_equal(test_status, True) |
| 1234 | |
| 1235 | def test_subscriber_join_next_100channels(self): |
| 1236 | num_subscribers = 1 |
| 1237 | num_channels = 100 |
| 1238 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1239 | num_channels = num_channels, |
| 1240 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
| 1241 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1242 | negative_subscriber_auth = 'all') |
| 1243 | assert_equal(test_status, True) |
| 1244 | |
| 1245 | def test_subscriber_join_next_400channels(self): |
| 1246 | num_subscribers = 1 |
| 1247 | num_channels = 400 |
| 1248 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1249 | num_channels = num_channels, |
| 1250 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
| 1251 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1252 | negative_subscriber_auth = 'all') |
| 1253 | assert_equal(test_status, True) |
| 1254 | |
| 1255 | def test_subscriber_join_next_800channels(self): |
| 1256 | num_subscribers = 1 |
| 1257 | num_channels = 800 |
| 1258 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1259 | num_channels = num_channels, |
| 1260 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
| 1261 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1262 | negative_subscriber_auth = 'all') |
| 1263 | assert_equal(test_status, True) |
| 1264 | |
| 1265 | |
| 1266 | def test_subscriber_join_next_1200channels(self): |
| 1267 | num_subscribers = 1 |
| 1268 | num_channels = 1200 |
| 1269 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1270 | num_channels = num_channels, |
| 1271 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
| 1272 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1273 | negative_subscriber_auth = 'all') |
| 1274 | assert_equal(test_status, True) |
| 1275 | |
| 1276 | def test_subscriber_join_next_1500channels(self): |
| 1277 | num_subscribers = 1 |
| 1278 | num_channels = 1500 |
| 1279 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
| 1280 | num_channels = num_channels, |
| 1281 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
| 1282 | port_list = self.generate_port_list(num_subscribers, num_channels), |
| 1283 | negative_subscriber_auth = 'all') |
| 1284 | assert_equal(test_status, True) |