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' ] |
| 145 | |
| 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 | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 170 | for app in self.apps: |
| 171 | onos_ctrl = OnosCtrl(app) |
| 172 | status, _ = onos_ctrl.activate() |
| 173 | assert_equal(status, True) |
| 174 | time.sleep(2) |
| 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 | |
| 182 | def onos_aaa_load(self): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 183 | if self.aaa_loaded: |
| 184 | return |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 185 | aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password', |
| 186 | 'radiusIp': '172.17.0.2' } } } } |
| 187 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
| 188 | aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip |
| 189 | self.onos_load_config('org.onosproject.aaa', aaa_dict) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 190 | self.aaa_loaded = True |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 191 | |
| 192 | def onos_dhcp_table_load(self, config = None): |
| 193 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 194 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 195 | if config: |
| 196 | for k in config.keys(): |
| 197 | if dhcp_config.has_key(k): |
| 198 | dhcp_config[k] = config[k] |
| 199 | self.onos_load_config('org.onosproject.dhcp', dhcp_dict) |
| 200 | |
| 201 | def onos_load_config(self, app, config): |
| 202 | onos_ctrl = OnosCtrl(app) |
| 203 | status, code = onos_ctrl.config(config) |
| 204 | if status is False: |
| 205 | log.info('JSON config request for app %s returned status %d' %(app, code)) |
| 206 | assert_equal(status, True) |
| 207 | time.sleep(2) |
| 208 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 209 | def dhcp_sndrcv(self, dhcp, update_seed = False): |
| 210 | cip, sip = dhcp.discover(update_seed = update_seed) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 211 | assert_not_equal(cip, None) |
| 212 | assert_not_equal(sip, None) |
| 213 | 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] | 214 | (cip, sip, dhcp.get_mac(cip)[0])) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 215 | return cip,sip |
| 216 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 217 | 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] | 218 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.200', |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 219 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 220 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 221 | self.onos_dhcp_table_load(config) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 222 | dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface) |
| 223 | cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 224 | return cip, sip |
| 225 | |
| 226 | def recv_channel_cb(self, pkt): |
| 227 | ##First verify that we have received the packet for the joined instance |
| 228 | chan = self.subscriber.caddr(pkt[IP].dst) |
| 229 | assert_equal(chan in self.subscriber.join_map.keys(), True) |
| 230 | recv_time = monotonic.monotonic() * 1000000 |
| 231 | join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start |
| 232 | delta = recv_time - join_time |
| 233 | self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 234 | self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 235 | 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] | 236 | self.test_status = True |
| 237 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 238 | def tls_verify(self, subscriber): |
| 239 | if subscriber.has_service('TLS'): |
| 240 | time.sleep(2) |
| 241 | tls = TLSAuthTest() |
| 242 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 243 | tls.runTest() |
| 244 | self.test_status = True |
| 245 | |
| 246 | def dhcp_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 247 | cip, sip = self.dhcp_request(subscriber, update_seed = True) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 248 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 249 | subscriber.src_list = [cip] |
| 250 | self.test_status = True |
| 251 | |
| 252 | def dhcp_jump_verify(self, subscriber): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 253 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1') |
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_next_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.150.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 igmp_verify(self, subscriber): |
| 265 | chan = 0 |
| 266 | if subscriber.has_service('IGMP'): |
| 267 | for i in range(5): |
| 268 | log.info('Joining channel %d for subscriber %s' %(chan, subscriber.name)) |
| 269 | subscriber.channel_join(chan, delay = 0) |
| 270 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 271 | log.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name)) |
| 272 | subscriber.channel_leave(chan) |
| 273 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 274 | 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] | 275 | self.test_status = True |
| 276 | |
| 277 | def igmp_jump_verify(self, subscriber): |
| 278 | if subscriber.has_service('IGMP'): |
| 279 | for i in xrange(subscriber.num): |
| 280 | log.info('Subscriber %s jumping channel' %subscriber.name) |
| 281 | chan = subscriber.channel_jump(delay=0) |
| 282 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 283 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 284 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 285 | 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] | 286 | self.test_status = True |
| 287 | |
| 288 | def igmp_next_verify(self, subscriber): |
| 289 | if subscriber.has_service('IGMP'): |
| 290 | for i in xrange(subscriber.num): |
| 291 | if i: |
| 292 | chan = subscriber.channel_join_next(delay=0) |
| 293 | else: |
| 294 | chan = subscriber.channel_join(i, delay=0) |
| 295 | log.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name)) |
| 296 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1) |
| 297 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 298 | time.sleep(3) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 299 | 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] | 300 | self.test_status = True |
| 301 | |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 302 | def generate_port_list(self, subscribers, channels): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 303 | port_list = [] |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 304 | for i in xrange(subscribers): |
| 305 | if channels > 1: |
| 306 | rx_port = 2*i+1 |
| 307 | tx_port = 2*i+2 |
| 308 | else: |
| 309 | rx_port = Subscriber.PORT_RX_DEFAULT |
| 310 | tx_port = Subscriber.PORT_TX_DEFAULT |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 311 | port_list.append((tx_port, rx_port)) |
| 312 | return port_list |
| 313 | |
| 314 | 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] | 315 | '''Load the subscriber from the database''' |
| 316 | self.subscriber_db = SubscriberDB(create = create) |
| 317 | if create is True: |
| 318 | self.subscriber_db.generate(num) |
| 319 | self.subscriber_info = self.subscriber_db.read(num) |
| 320 | self.subscriber_list = [] |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 321 | if not port_list: |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 322 | port_list = self.generate_port_list(num, num_channels) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 323 | |
| 324 | index = 0 |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 325 | for info in self.subscriber_info: |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 326 | self.subscriber_list.append(Subscriber(name=info['Name'], |
| 327 | service=info['Service'], |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 328 | port_map = self.port_map, |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 329 | num=num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 330 | channel_start = channel_start, |
| 331 | tx_port = port_list[index][0], |
| 332 | rx_port = port_list[index][1])) |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 333 | if num_channels > 1: |
| 334 | channel_start += num_channels |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 335 | index += 1 |
| 336 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 337 | #load the ssm list for all subscriber channels |
| 338 | igmpChannel = IgmpChannel() |
| 339 | ssm_groups = map(lambda sub: sub.channels, self.subscriber_list) |
| 340 | ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups) |
| 341 | igmpChannel.igmp_load_ssm_config(ssm_list) |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 342 | #load the subscriber to mcast port map for cord |
| 343 | cord_port_map = {} |
| 344 | for sub in self.subscriber_list: |
| 345 | for chan in sub.channels: |
| 346 | cord_port_map[chan] = (sub.tx_port, sub.rx_port) |
| 347 | |
| 348 | igmpChannel.cord_port_table_load(cord_port_map) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 349 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 350 | def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 351 | channel_start = 0, cbs = None, port_list = []): |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 352 | self.test_status = False |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 353 | self.num_subscribers = num_subscribers |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 354 | self.subscriber_load(create = True, num = num_subscribers, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 355 | num_channels = num_channels, channel_start = channel_start, port_list = port_list) |
Chetan Gaonker | 55fc788 | 2016-03-15 17:46:47 -0700 | [diff] [blame] | 356 | self.onos_aaa_load() |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 357 | self.thread_pool = ThreadPool(min(100, self.num_subscribers), queue_size=1, wait_timeout=1) |
| 358 | if cbs is None: |
| 359 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify) |
Chetan Gaonker | 41d2e07 | 2016-03-15 16:41:31 -0700 | [diff] [blame] | 360 | for subscriber in self.subscriber_list: |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 361 | subscriber.start() |
| 362 | pool_object = subscriber_pool(subscriber, cbs) |
| 363 | self.thread_pool.addTask(pool_object.pool_cb) |
| 364 | self.thread_pool.cleanUpThreads() |
| 365 | for subscriber in self.subscriber_list: |
| 366 | subscriber.stop() |
| 367 | return self.test_status |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 368 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 369 | def test_subscriber_join_recv(self): |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 370 | """Test subscriber join and receive""" |
| 371 | num_subscribers = 50 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 372 | num_channels = 1 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 373 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 374 | num_channels = num_channels, |
| 375 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 376 | assert_equal(test_status, True) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 377 | |
| 378 | def test_subscriber_join_jump(self): |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 379 | """Test subscriber join and receive for channel surfing""" |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 380 | num_subscribers = 5 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 381 | num_channels = 50 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 382 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 383 | num_channels = num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 384 | cbs = (self.tls_verify, self.dhcp_jump_verify, self.igmp_jump_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 385 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 386 | assert_equal(test_status, True) |
Chetan Gaonker | 4b959fc | 2016-03-09 19:20:16 -0800 | [diff] [blame] | 387 | |
| 388 | def test_subscriber_join_next(self): |
| 389 | """Test subscriber join next for channels""" |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 390 | num_subscribers = 5 |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 391 | num_channels = 50 |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 392 | test_status = self.subscriber_join_verify(num_subscribers = num_subscribers, |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 393 | num_channels = num_channels, |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 394 | cbs = (self.tls_verify, self.dhcp_next_verify, self.igmp_next_verify), |
Chetan Gaonker | 3d16385 | 2016-03-28 12:20:25 -0700 | [diff] [blame] | 395 | port_list = self.generate_port_list(num_subscribers, num_channels)) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 396 | assert_equal(test_status, True) |