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