Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 1 | # |
| 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
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 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -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 * |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 35 | log.setLevel('INFO') |
| 36 | |
| 37 | class Subscriber(Channels): |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 38 | PORT_TX_DEFAULT = 2 |
| 39 | PORT_RX_DEFAULT = 1 |
| 40 | INTF_TX_DEFAULT = 'veth2' |
| 41 | INTF_RX_DEFAULT = 'veth0' |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 42 | STATS_RX = 0 |
| 43 | STATS_TX = 1 |
| 44 | STATS_JOIN = 2 |
| 45 | STATS_LEAVE = 3 |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 46 | SUBSCRIBER_SERVICES = 'DHCP IGMP TLS' |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 47 | def __init__(self, name = 'sub', service = SUBSCRIBER_SERVICES, port_map = None, |
| 48 | num = 1, channel_start = 0, |
| 49 | tx_port = PORT_TX_DEFAULT, rx_port = PORT_RX_DEFAULT, |
| 50 | iface = INTF_RX_DEFAULT, iface_mcast = INTF_TX_DEFAULT, |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 51 | mcast_cb = None, loginType = 'wireless'): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 52 | self.tx_port = tx_port |
| 53 | self.rx_port = rx_port |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 54 | self.port_map = port_map or g_subscriber_port_map |
| 55 | try: |
| 56 | self.tx_intf = self.port_map[tx_port] |
| 57 | self.rx_intf = self.port_map[rx_port] |
| 58 | except: |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 59 | self.tx_intf = self.port_map[self.PORT_TX_DEFAULT] |
| 60 | self.rx_intf = self.port_map[self.PORT_RX_DEFAULT] |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 61 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 62 | Channels.__init__(self, num, channel_start = channel_start, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 63 | 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] | 64 | self.name = name |
| 65 | self.service = service |
| 66 | self.service_map = {} |
| 67 | services = self.service.strip().split(' ') |
| 68 | for s in services: |
| 69 | self.service_map[s] = True |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 70 | self.loginType = loginType |
| 71 | ##start streaming channels |
| 72 | self.join_map = {} |
| 73 | ##accumulated join recv stats |
| 74 | self.join_rx_stats = Stats() |
| 75 | |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 76 | def has_service(self, service): |
| 77 | if self.service_map.has_key(service): |
| 78 | return self.service_map[service] |
| 79 | if self.service_map.has_key(service.upper()): |
| 80 | return self.service_map[service.upper()] |
| 81 | return False |
| 82 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 83 | def channel_join_update(self, chan, join_time): |
| 84 | self.join_map[chan] = ( Stats(), Stats(), Stats(), Stats() ) |
| 85 | self.channel_update(chan, self.STATS_JOIN, 1, t = join_time) |
| 86 | |
| 87 | def channel_join(self, chan = 0, delay = 2): |
| 88 | '''Join a channel and create a send/recv stats map''' |
| 89 | if self.join_map.has_key(chan): |
| 90 | del self.join_map[chan] |
| 91 | self.delay = delay |
| 92 | chan, join_time = self.join(chan) |
| 93 | self.channel_join_update(chan, join_time) |
| 94 | return chan |
| 95 | |
| 96 | def channel_join_next(self, delay = 2): |
| 97 | '''Joins the next channel leaving the last channel''' |
| 98 | if self.last_chan: |
| 99 | if self.join_map.has_key(self.last_chan): |
| 100 | del self.join_map[self.last_chan] |
| 101 | self.delay = delay |
| 102 | chan, join_time = self.join_next() |
| 103 | self.channel_join_update(chan, join_time) |
| 104 | return chan |
| 105 | |
| 106 | def channel_jump(self, delay = 2): |
| 107 | '''Jumps randomly to the next channel leaving the last channel''' |
| 108 | if self.last_chan is not None: |
| 109 | if self.join_map.has_key(self.last_chan): |
| 110 | del self.join_map[self.last_chan] |
| 111 | self.delay = delay |
| 112 | chan, join_time = self.jump() |
| 113 | self.channel_join_update(chan, join_time) |
| 114 | return chan |
| 115 | |
| 116 | def channel_leave(self, chan = 0): |
| 117 | if self.join_map.has_key(chan): |
| 118 | del self.join_map[chan] |
| 119 | self.leave(chan) |
| 120 | |
| 121 | def channel_update(self, chan, stats_type, packets, t=0): |
| 122 | if type(chan) == type(0): |
| 123 | chan_list = (chan,) |
| 124 | else: |
| 125 | chan_list = chan |
| 126 | for c in chan_list: |
| 127 | if self.join_map.has_key(c): |
| 128 | self.join_map[c][stats_type].update(packets = packets, t = t) |
| 129 | |
| 130 | def channel_receive(self, chan, cb = None, count = 1): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 131 | 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] | 132 | self.recv(chan, cb = cb, count = count) |
| 133 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 134 | def recv_channel_cb(self, pkt): |
| 135 | ##First verify that we have received the packet for the joined instance |
| 136 | log.debug('Packet received for group %s, subscriber %s' %(pkt[IP].dst, self.name)) |
| 137 | chan = self.caddr(pkt[IP].dst) |
| 138 | assert_equal(chan in self.join_map.keys(), True) |
| 139 | recv_time = monotonic.monotonic() * 1000000 |
| 140 | join_time = self.join_map[chan][self.STATS_JOIN].start |
| 141 | delta = recv_time - join_time |
| 142 | self.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 143 | self.channel_update(chan, self.STATS_RX, 1, t = delta) |
| 144 | log.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
| 145 | |
| 146 | class subscriber_pool: |
| 147 | |
| 148 | def __init__(self, subscriber, test_cbs): |
| 149 | self.subscriber = subscriber |
| 150 | self.test_cbs = test_cbs |
| 151 | |
| 152 | def pool_cb(self): |
| 153 | for cb in self.test_cbs: |
| 154 | if cb: |
| 155 | cb(self.subscriber) |
| 156 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 157 | class subscriber_exchange(unittest.TestCase): |
| 158 | |
| 159 | apps = [ 'org.onosproject.aaa', 'org.onosproject.dhcp' ] |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 160 | olt_apps = [ 'org.onosproject.igmp', 'org.onosproject.cordmcast' ] |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 161 | dhcp_server_config = { |
| 162 | "ip": "10.1.11.50", |
| 163 | "mac": "ca:fe:ca:fe:ca:fe", |
| 164 | "subnet": "255.255.252.0", |
| 165 | "broadcast": "10.1.11.255", |
| 166 | "router": "10.1.8.1", |
| 167 | "domain": "8.8.8.8", |
| 168 | "ttl": "63", |
| 169 | "delay": "2", |
| 170 | "startip": "10.1.11.51", |
| 171 | "endip": "10.1.11.100" |
| 172 | } |
| 173 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 174 | aaa_loaded = False |
| 175 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 176 | def setUp(self): |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 177 | '''Load the OLT config and activate relevant apps''' |
| 178 | self.olt = OltConfig() |
| 179 | self.port_map = self.olt.olt_port_map() |
| 180 | ##if no olt config, fall back to ovs port map |
| 181 | if not self.port_map: |
| 182 | self.port_map = g_subscriber_port_map |
| 183 | else: |
| 184 | log.info('Using OLT Port configuration for test setup') |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 185 | log.info('Configuring CORD OLT access device information') |
| 186 | OnosCtrl.cord_olt_config(self.olt.olt_device_data()) |
| 187 | self.activate_apps(self.olt_apps) |
| 188 | |
| 189 | self.activate_apps(self.apps) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 190 | |
| 191 | def teardown(self): |
| 192 | '''Deactivate the dhcp app''' |
| 193 | for app in self.apps: |
| 194 | onos_ctrl = OnosCtrl(app) |
| 195 | onos_ctrl.deactivate() |
| 196 | |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 197 | def activate_apps(self, apps): |
Chetan Gaonker | 735495f | 2016-05-10 14:51:16 -0700 | [diff] [blame] | 198 | for app in apps: |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 199 | onos_ctrl = OnosCtrl(app) |
| 200 | status, _ = onos_ctrl.activate() |
| 201 | assert_equal(status, True) |
| 202 | time.sleep(2) |
| 203 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 204 | def onos_aaa_load(self): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 205 | if self.aaa_loaded: |
| 206 | return |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 207 | aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password', |
| 208 | 'radiusIp': '172.17.0.2' } } } } |
| 209 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
| 210 | aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip |
| 211 | self.onos_load_config('org.onosproject.aaa', aaa_dict) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 212 | self.aaa_loaded = True |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 213 | |
| 214 | def onos_dhcp_table_load(self, config = None): |
| 215 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 216 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 217 | if config: |
| 218 | for k in config.keys(): |
| 219 | if dhcp_config.has_key(k): |
| 220 | dhcp_config[k] = config[k] |
| 221 | self.onos_load_config('org.onosproject.dhcp', dhcp_dict) |
| 222 | |
| 223 | def onos_load_config(self, app, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 224 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 225 | if status is False: |
| 226 | log.info('JSON config request for app %s returned status %d' %(app, code)) |
| 227 | assert_equal(status, True) |
| 228 | time.sleep(2) |
| 229 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 230 | def dhcp_sndrcv(self, dhcp, update_seed = False): |
| 231 | cip, sip = dhcp.discover(update_seed = update_seed) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 232 | assert_not_equal(cip, None) |
| 233 | assert_not_equal(sip, None) |
| 234 | 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] | 235 | (cip, sip, dhcp.get_mac(cip)[0])) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 236 | return cip,sip |
| 237 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 238 | 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] | 239 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.200', |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 240 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 241 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 242 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 243 | dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface) |
| 244 | cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 245 | return cip, sip |
| 246 | |
| 247 | def recv_channel_cb(self, pkt): |
| 248 | ##First verify that we have received the packet for the joined instance |
| 249 | chan = self.subscriber.caddr(pkt[IP].dst) |
| 250 | assert_equal(chan in self.subscriber.join_map.keys(), True) |
| 251 | recv_time = monotonic.monotonic() * 1000000 |
| 252 | join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start |
| 253 | delta = recv_time - join_time |
| 254 | self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 255 | self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 256 | 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] | 257 | self.test_status = True |
| 258 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 259 | def tls_verify(self, subscriber): |
| 260 | if subscriber.has_service('TLS'): |
| 261 | time.sleep(2) |
| 262 | tls = TLSAuthTest() |
| 263 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 264 | tls.runTest() |
| 265 | self.test_status = True |
| 266 | |
| 267 | def dhcp_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 268 | cip, sip = self.dhcp_request(subscriber, update_seed = True) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 269 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 270 | subscriber.src_list = [cip] |
| 271 | self.test_status = True |
| 272 | |
| 273 | def dhcp_jump_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 274 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1') |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 275 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 276 | subscriber.src_list = [cip] |
| 277 | self.test_status = True |
| 278 | |
| 279 | def dhcp_next_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 280 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.150.1') |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 281 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 282 | subscriber.src_list = [cip] |
| 283 | self.test_status = True |
| 284 | |
| 285 | def igmp_verify(self, subscriber): |
| 286 | chan = 0 |
| 287 | if subscriber.has_service('IGMP'): |
| 288 | for i in range(5): |
| 289 | log.info('Joining channel %d for subscriber %s' %(chan, subscriber.name)) |
| 290 | subscriber.channel_join(chan, delay = 0) |
| 291 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 292 | log.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name)) |
| 293 | subscriber.channel_leave(chan) |
| 294 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 295 | 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] | 296 | self.test_status = True |
| 297 | |
| 298 | def igmp_jump_verify(self, subscriber): |
| 299 | if subscriber.has_service('IGMP'): |
| 300 | for i in xrange(subscriber.num): |
| 301 | log.info('Subscriber %s jumping channel' %subscriber.name) |
| 302 | chan = subscriber.channel_jump(delay=0) |
| 303 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 304 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 305 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 306 | 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] | 307 | self.test_status = True |
| 308 | |
| 309 | def igmp_next_verify(self, subscriber): |
| 310 | if subscriber.has_service('IGMP'): |
| 311 | for i in xrange(subscriber.num): |
| 312 | if i: |
| 313 | chan = subscriber.channel_join_next(delay=0) |
| 314 | else: |
| 315 | chan = subscriber.channel_join(i, delay=0) |
| 316 | log.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name)) |
| 317 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1) |
| 318 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 319 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 320 | 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] | 321 | self.test_status = True |
| 322 | |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 323 | def generate_port_list(self, subscribers, channels): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 324 | port_list = [] |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 325 | for i in xrange(subscribers): |
| 326 | if channels > 1: |
| 327 | rx_port = 2*i+1 |
| 328 | tx_port = 2*i+2 |
| 329 | else: |
| 330 | rx_port = Subscriber.PORT_RX_DEFAULT |
| 331 | tx_port = Subscriber.PORT_TX_DEFAULT |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 332 | port_list.append((tx_port, rx_port)) |
| 333 | return port_list |
| 334 | |
| 335 | 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] | 336 | '''Load the subscriber from the database''' |
| 337 | self.subscriber_db = SubscriberDB(create = create) |
| 338 | if create is True: |
| 339 | self.subscriber_db.generate(num) |
| 340 | self.subscriber_info = self.subscriber_db.read(num) |
| 341 | self.subscriber_list = [] |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 342 | if not port_list: |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 343 | port_list = self.generate_port_list(num, num_channels) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 344 | |
| 345 | index = 0 |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 346 | for info in self.subscriber_info: |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 347 | self.subscriber_list.append(Subscriber(name=info['Name'], |
| 348 | service=info['Service'], |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 349 | port_map = self.port_map, |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 350 | num=num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 351 | channel_start = channel_start, |
| 352 | tx_port = port_list[index][0], |
| 353 | rx_port = port_list[index][1])) |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 354 | if num_channels > 1: |
| 355 | channel_start += num_channels |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 356 | index += 1 |
| 357 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 358 | #load the ssm list for all subscriber channels |
| 359 | igmpChannel = IgmpChannel() |
| 360 | ssm_groups = map(lambda sub: sub.channels, self.subscriber_list) |
| 361 | ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups) |
| 362 | igmpChannel.igmp_load_ssm_config(ssm_list) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 363 | #load the subscriber to mcast port map for cord |
| 364 | cord_port_map = {} |
| 365 | for sub in self.subscriber_list: |
| 366 | for chan in sub.channels: |
| 367 | cord_port_map[chan] = (sub.tx_port, sub.rx_port) |
| 368 | |
| 369 | igmpChannel.cord_port_table_load(cord_port_map) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 370 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 371 | def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 372 | channel_start = 0, cbs = None, port_list = []): |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 373 | self.test_status = False |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 374 | self.num_subscribers = num_subscribers |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 375 | self.subscriber_load(create = True, num = num_subscribers, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 376 | num_channels = num_channels, channel_start = channel_start, port_list = port_list) |
Chetan Gaonker | 55fc788 | 2016-03-15 17:46:47 -0700 | [diff] [blame] | 377 | self.onos_aaa_load() |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 378 | self.thread_pool = ThreadPool(min(100, self.num_subscribers), queue_size=1, wait_timeout=1) |
| 379 | if cbs is None: |
| 380 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 381 | for subscriber in self.subscriber_list: |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 382 | subscriber.start() |
| 383 | pool_object = subscriber_pool(subscriber, cbs) |
| 384 | self.thread_pool.addTask(pool_object.pool_cb) |
| 385 | self.thread_pool.cleanUpThreads() |
| 386 | for subscriber in self.subscriber_list: |
| 387 | subscriber.stop() |
| 388 | return self.test_status |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 389 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 390 | def test_subscriber_join_recv(self): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 391 | """Test subscriber join and receive""" |
| 392 | num_subscribers = 50 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 393 | num_channels = 1 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 394 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 395 | num_channels = num_channels, |
| 396 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 397 | assert_equal(test_status, True) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 398 | |
| 399 | def test_subscriber_join_jump(self): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 400 | """Test subscriber join and receive for channel surfing""" |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 401 | num_subscribers = 5 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 402 | num_channels = 50 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 403 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 404 | num_channels = num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 405 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 406 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 407 | assert_equal(test_status, True) |
Chetan Gaonker | 4b959fc | 2016-03-09 19:20:16 -0800 | [diff] [blame] | 408 | |
| 409 | def test_subscriber_join_next(self): |
| 410 | """Test subscriber join next for channels""" |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 411 | num_subscribers = 5 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 412 | num_channels = 50 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 413 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 414 | num_channels = num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 415 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 416 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 417 | assert_equal(test_status, True) |