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