A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [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 | import json |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 12 | import requests |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 13 | from Stats import Stats |
| 14 | from OnosCtrl import OnosCtrl |
| 15 | from DHCP import DHCPTest |
| 16 | from EapTLS import TLSAuthTest |
| 17 | from Channels import Channels, IgmpChannel |
| 18 | from subscriberDb import SubscriberDB |
| 19 | from threadPool import ThreadPool |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 20 | from portmaps import g_subscriber_port_map |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 21 | from OltConfig import * |
| 22 | from OnosFlowCtrl import get_mac |
| 23 | from CordTestServer import cord_test_onos_restart |
| 24 | |
| 25 | log.setLevel('INFO') |
| 26 | |
| 27 | class Subscriber(Channels): |
| 28 | PORT_TX_DEFAULT = 2 |
| 29 | PORT_RX_DEFAULT = 1 |
| 30 | INTF_TX_DEFAULT = 'veth2' |
| 31 | INTF_RX_DEFAULT = 'veth0' |
| 32 | STATS_RX = 0 |
| 33 | STATS_TX = 1 |
| 34 | STATS_JOIN = 2 |
| 35 | STATS_LEAVE = 3 |
| 36 | SUBSCRIBER_SERVICES = 'DHCP IGMP TLS' |
| 37 | def __init__(self, name = 'sub', service = SUBSCRIBER_SERVICES, port_map = None, |
| 38 | num = 1, channel_start = 0, |
| 39 | tx_port = PORT_TX_DEFAULT, rx_port = PORT_RX_DEFAULT, |
| 40 | iface = INTF_RX_DEFAULT, iface_mcast = INTF_TX_DEFAULT, |
| 41 | mcast_cb = None, loginType = 'wireless'): |
| 42 | self.tx_port = tx_port |
| 43 | self.rx_port = rx_port |
| 44 | self.port_map = port_map or g_subscriber_port_map |
| 45 | try: |
| 46 | self.tx_intf = self.port_map[tx_port] |
| 47 | self.rx_intf = self.port_map[rx_port] |
| 48 | except: |
| 49 | self.tx_intf = self.port_map[self.PORT_TX_DEFAULT] |
| 50 | self.rx_intf = self.port_map[self.PORT_RX_DEFAULT] |
| 51 | |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 52 | log.info('Subscriber %s, rx interface %s, uplink interface %s' %(name, self.rx_intf, self.tx_intf)) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 53 | Channels.__init__(self, num, channel_start = channel_start, |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 54 | iface = self.rx_intf, iface_mcast = self.tx_intf, mcast_cb = mcast_cb) |
| 55 | self.name = name |
| 56 | self.service = service |
| 57 | self.service_map = {} |
| 58 | services = self.service.strip().split(' ') |
| 59 | for s in services: |
| 60 | self.service_map[s] = True |
| 61 | self.loginType = loginType |
| 62 | ##start streaming channels |
| 63 | self.join_map = {} |
| 64 | ##accumulated join recv stats |
| 65 | self.join_rx_stats = Stats() |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 66 | self.recv_timeout = False |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 67 | |
| 68 | def has_service(self, service): |
| 69 | if self.service_map.has_key(service): |
| 70 | return self.service_map[service] |
| 71 | if self.service_map.has_key(service.upper()): |
| 72 | return self.service_map[service.upper()] |
| 73 | return False |
| 74 | |
| 75 | def channel_join_update(self, chan, join_time): |
| 76 | self.join_map[chan] = ( Stats(), Stats(), Stats(), Stats() ) |
| 77 | self.channel_update(chan, self.STATS_JOIN, 1, t = join_time) |
| 78 | |
| 79 | def channel_join(self, chan = 0, delay = 2): |
| 80 | '''Join a channel and create a send/recv stats map''' |
| 81 | if self.join_map.has_key(chan): |
| 82 | del self.join_map[chan] |
| 83 | self.delay = delay |
| 84 | chan, join_time = self.join(chan) |
| 85 | self.channel_join_update(chan, join_time) |
| 86 | return chan |
| 87 | |
| 88 | def channel_join_next(self, delay = 2): |
| 89 | '''Joins the next channel leaving the last channel''' |
| 90 | if self.last_chan: |
| 91 | if self.join_map.has_key(self.last_chan): |
| 92 | del self.join_map[self.last_chan] |
| 93 | self.delay = delay |
| 94 | chan, join_time = self.join_next() |
| 95 | self.channel_join_update(chan, join_time) |
| 96 | return chan |
| 97 | |
| 98 | def channel_jump(self, delay = 2): |
| 99 | '''Jumps randomly to the next channel leaving the last channel''' |
| 100 | if self.last_chan is not None: |
| 101 | if self.join_map.has_key(self.last_chan): |
| 102 | del self.join_map[self.last_chan] |
| 103 | self.delay = delay |
| 104 | chan, join_time = self.jump() |
| 105 | self.channel_join_update(chan, join_time) |
| 106 | return chan |
| 107 | |
| 108 | def channel_leave(self, chan = 0): |
| 109 | if self.join_map.has_key(chan): |
| 110 | del self.join_map[chan] |
| 111 | self.leave(chan) |
| 112 | |
| 113 | def channel_update(self, chan, stats_type, packets, t=0): |
| 114 | if type(chan) == type(0): |
| 115 | chan_list = (chan,) |
| 116 | else: |
| 117 | chan_list = chan |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 118 | for c in chan_list: |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 119 | if self.join_map.has_key(c): |
| 120 | self.join_map[c][stats_type].update(packets = packets, t = t) |
| 121 | |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 122 | def channel_receive(self, chan, cb = None, count = 1, timeout = 5): |
| 123 | log.info('Subscriber %s on port %s receiving from group %s, channel %d' % |
| 124 | (self.name, self.rx_intf, self.gaddr(chan), chan)) |
| 125 | r = self.recv(chan, cb = cb, count = count, timeout = timeout) |
| 126 | if self.recv_timeout: |
| 127 | ##Negative test case is disabled for now |
| 128 | assert_equal(len(r), 0) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 129 | |
| 130 | def recv_channel_cb(self, pkt): |
| 131 | ##First verify that we have received the packet for the joined instance |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 132 | log.info('Packet received for group %s, subscriber %s, port %s' % |
| 133 | (pkt[IP].dst, self.name, self.rx_intf)) |
| 134 | if self.recv_timeout: |
| 135 | return |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 136 | chan = self.caddr(pkt[IP].dst) |
| 137 | assert_equal(chan in self.join_map.keys(), True) |
| 138 | recv_time = monotonic.monotonic() * 1000000 |
| 139 | join_time = self.join_map[chan][self.STATS_JOIN].start |
| 140 | delta = recv_time - join_time |
| 141 | self.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 142 | self.channel_update(chan, self.STATS_RX, 1, t = delta) |
| 143 | log.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
| 144 | |
| 145 | class subscriber_pool: |
| 146 | |
| 147 | def __init__(self, subscriber, test_cbs): |
| 148 | self.subscriber = subscriber |
| 149 | self.test_cbs = test_cbs |
| 150 | |
| 151 | def pool_cb(self): |
| 152 | for cb in self.test_cbs: |
| 153 | if cb: |
| 154 | cb(self.subscriber) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 155 | |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 156 | class subscriber_exchange(unittest.TestCase): |
| 157 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 158 | apps = ('org.opencord.aaa', 'org.onosproject.dhcp') |
| 159 | olt_apps = () #'org.opencord.cordmcast') |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 160 | table_app = 'org.ciena.cordigmp' |
| 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 | |
| 174 | aaa_loaded = False |
| 175 | test_path = os.path.dirname(os.path.realpath(__file__)) |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 176 | table_app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-multitable-2.0-SNAPSHOT.oar') |
| 177 | app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-2.0-SNAPSHOT.oar') |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 178 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
| 179 | olt_conf_file = os.path.join(test_path, '..', 'setup/olt_config_multitable.json') |
| 180 | cpqd_path = os.path.join(test_path, '..', 'setup') |
| 181 | ovs_path = cpqd_path |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 182 | test_services = ('IGMP', 'TRAFFIC') |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 183 | num_joins = 0 |
| 184 | num_subscribers = 0 |
| 185 | num_channels = 0 |
| 186 | recv_timeout = False |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 187 | |
| 188 | @classmethod |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 189 | def load_device_id(cls): |
| 190 | '''If running under olt, we get the first switch connected to onos''' |
| 191 | olt = os.getenv('OLT_CONFIG', None) |
| 192 | if olt: |
| 193 | devices = OnosCtrl.get_devices() |
| 194 | if devices: |
| 195 | dids = map(lambda d: d['id'], devices) |
| 196 | if len(dids) == 1: |
| 197 | did = dids[0] |
| 198 | else: |
| 199 | ###If we have more than 1, then check for env before using first one |
| 200 | did = os.getenv('OLT_DEVICE_ID', dids[0]) |
| 201 | else: |
| 202 | did = 'of:' + get_mac('ovsbr0') |
| 203 | |
| 204 | #Set the default config |
| 205 | cls.device_id = did |
| 206 | cls.device_dict = { "devices" : { |
| 207 | "{}".format(did) : { |
| 208 | "basic" : { |
| 209 | "driver" : "pmc-olt" |
| 210 | } |
| 211 | } |
| 212 | }, |
| 213 | } |
| 214 | return did |
| 215 | |
| 216 | @classmethod |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 217 | def setUpClass(cls): |
| 218 | '''Load the OLT config and activate relevant apps''' |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 219 | did = cls.load_device_id() |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 220 | network_cfg = { "devices" : { |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 221 | "{}".format(did) : { |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 222 | "basic" : { |
| 223 | "driver" : "pmc-olt" |
| 224 | } |
| 225 | } |
| 226 | }, |
| 227 | } |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 228 | ## Restart ONOS with cpqd driver config for OVS |
| 229 | cls.start_onos(network_cfg = network_cfg) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 230 | cls.install_app_table() |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 231 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
| 232 | OnosCtrl.cord_olt_config(cls.olt.olt_device_data()) |
| 233 | cls.port_map, cls.port_list = cls.olt.olt_port_map_multi() |
| 234 | cls.activate_apps(cls.apps + cls.olt_apps) |
| 235 | |
| 236 | @classmethod |
| 237 | def tearDownClass(cls): |
| 238 | '''Deactivate the olt apps and restart OVS back''' |
| 239 | apps = cls.olt_apps + ( cls.table_app,) |
| 240 | for app in apps: |
| 241 | onos_ctrl = OnosCtrl(app) |
| 242 | onos_ctrl.deactivate() |
| 243 | cls.uninstall_app_table() |
A R Karthick | e0f33fa | 2016-06-22 13:36:02 -0700 | [diff] [blame] | 244 | cls.start_onos(network_cfg = {}) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 245 | |
| 246 | @classmethod |
| 247 | def activate_apps(cls, apps): |
| 248 | for app in apps: |
| 249 | onos_ctrl = OnosCtrl(app) |
| 250 | status, _ = onos_ctrl.activate() |
| 251 | assert_equal(status, True) |
| 252 | time.sleep(2) |
| 253 | |
| 254 | @classmethod |
| 255 | def install_app_table(cls): |
| 256 | ##Uninstall the existing app if any |
| 257 | OnosCtrl.uninstall_app(cls.table_app) |
| 258 | time.sleep(2) |
| 259 | log.info('Installing the multi table app %s for subscriber test' %(cls.table_app_file)) |
| 260 | OnosCtrl.install_app(cls.table_app_file) |
| 261 | time.sleep(3) |
| 262 | |
| 263 | @classmethod |
| 264 | def uninstall_app_table(cls): |
| 265 | ##Uninstall the table app on class exit |
| 266 | OnosCtrl.uninstall_app(cls.table_app) |
| 267 | time.sleep(2) |
| 268 | log.info('Installing back the cord igmp app %s for subscriber test on exit' %(cls.app_file)) |
| 269 | OnosCtrl.install_app(cls.app_file) |
| 270 | |
| 271 | @classmethod |
| 272 | def start_onos(cls, network_cfg = None): |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 273 | v = bool(int(os.getenv('ONOS_RESTART_DISABLED', 0))) |
| 274 | if v: |
| 275 | log.info('ONOS restart is disabled. Skipping ONOS restart') |
| 276 | return |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 277 | if network_cfg is None: |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 278 | network_cfg = cls.device_dict |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 279 | |
| 280 | if type(network_cfg) is tuple: |
| 281 | res = [] |
| 282 | for v in network_cfg: |
| 283 | res += v.items() |
| 284 | config = dict(res) |
| 285 | else: |
| 286 | config = network_cfg |
| 287 | log.info('Restarting ONOS with new network configuration') |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 288 | return cord_test_onos_restart(config = config) |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 289 | |
| 290 | @classmethod |
| 291 | def remove_onos_config(cls): |
| 292 | try: |
| 293 | os.unlink('{}/network-cfg.json'.format(cls.onos_config_path)) |
| 294 | except: pass |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 295 | |
| 296 | @classmethod |
| 297 | def start_cpqd(cls, mac = '00:11:22:33:44:55'): |
| 298 | dpid = mac.replace(':', '') |
| 299 | cpqd_file = os.sep.join( (cls.cpqd_path, 'cpqd.sh') ) |
| 300 | cpqd_cmd = '{} {}'.format(cpqd_file, dpid) |
| 301 | ret = os.system(cpqd_cmd) |
| 302 | assert_equal(ret, 0) |
| 303 | time.sleep(10) |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 304 | device_id = 'of:{}{}'.format('0'*4, dpid) |
| 305 | return device_id |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 306 | |
| 307 | @classmethod |
| 308 | def start_ovs(cls): |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 309 | ovs_file = os.sep.join( (cls.ovs_path, 'of-bridge.sh') ) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 310 | ret = os.system(ovs_file) |
| 311 | assert_equal(ret, 0) |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 312 | time.sleep(30) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 313 | |
| 314 | def onos_aaa_load(self): |
| 315 | if self.aaa_loaded: |
| 316 | return |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 317 | aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password', |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 318 | 'radiusIp': '172.17.0.2' } } } } |
| 319 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
| 320 | aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip |
| 321 | self.onos_load_config('org.onosproject.aaa', aaa_dict) |
| 322 | self.aaa_loaded = True |
| 323 | |
| 324 | def onos_dhcp_table_load(self, config = None): |
| 325 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 326 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 327 | if config: |
| 328 | for k in config.keys(): |
| 329 | if dhcp_config.has_key(k): |
| 330 | dhcp_config[k] = config[k] |
| 331 | self.onos_load_config('org.onosproject.dhcp', dhcp_dict) |
| 332 | |
| 333 | def onos_load_config(self, app, config): |
| 334 | status, code = OnosCtrl.config(config) |
| 335 | if status is False: |
| 336 | log.info('JSON config request for app %s returned status %d' %(app, code)) |
| 337 | assert_equal(status, True) |
| 338 | time.sleep(2) |
| 339 | |
| 340 | def dhcp_sndrcv(self, dhcp, update_seed = False): |
| 341 | cip, sip = dhcp.discover(update_seed = update_seed) |
| 342 | assert_not_equal(cip, None) |
| 343 | assert_not_equal(sip, None) |
| 344 | log.info('Got dhcp client IP %s from server %s for mac %s' % |
| 345 | (cip, sip, dhcp.get_mac(cip)[0])) |
| 346 | return cip,sip |
| 347 | |
| 348 | def dhcp_request(self, subscriber, seed_ip = '10.10.10.1', update_seed = False): |
| 349 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.200', |
| 350 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 351 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 352 | self.onos_dhcp_table_load(config) |
| 353 | dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface) |
| 354 | cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed) |
| 355 | return cip, sip |
| 356 | |
| 357 | def recv_channel_cb(self, pkt): |
| 358 | ##First verify that we have received the packet for the joined instance |
| 359 | chan = self.subscriber.caddr(pkt[IP].dst) |
| 360 | assert_equal(chan in self.subscriber.join_map.keys(), True) |
| 361 | recv_time = monotonic.monotonic() * 1000000 |
| 362 | join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start |
| 363 | delta = recv_time - join_time |
| 364 | self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 365 | self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta) |
| 366 | log.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
| 367 | self.test_status = True |
| 368 | |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 369 | def traffic_verify(self, subscriber): |
| 370 | if subscriber.has_service('TRAFFIC'): |
| 371 | url = 'http://www.google.com' |
| 372 | resp = requests.get(url) |
| 373 | self.test_status = resp.ok |
| 374 | if resp.ok == False: |
| 375 | log.info('Subscriber %s failed get from url %s with status code %d' |
| 376 | %(subscriber.name, url, resp.status_code)) |
| 377 | else: |
| 378 | log.info('GET request from %s succeeded for subscriber %s' |
| 379 | %(url, subscriber.name)) |
| 380 | |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 381 | def tls_verify(self, subscriber): |
| 382 | if subscriber.has_service('TLS'): |
| 383 | time.sleep(2) |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 384 | tls = TLSAuthTest(intf = subscriber.rx_intf) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 385 | log.info('Running subscriber %s tls auth test' %subscriber.name) |
| 386 | tls.runTest() |
| 387 | self.test_status = True |
| 388 | |
| 389 | def dhcp_verify(self, subscriber): |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 390 | if subscriber.has_service('DHCP'): |
| 391 | cip, sip = self.dhcp_request(subscriber, update_seed = True) |
| 392 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 393 | subscriber.src_list = [cip] |
| 394 | self.test_status = True |
| 395 | else: |
| 396 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 397 | self.test_status = True |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 398 | |
| 399 | def dhcp_jump_verify(self, subscriber): |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 400 | if subscriber.has_service('DHCP'): |
| 401 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1') |
| 402 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 403 | subscriber.src_list = [cip] |
| 404 | self.test_status = True |
| 405 | else: |
| 406 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 407 | self.test_status = True |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 408 | |
| 409 | def dhcp_next_verify(self, subscriber): |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 410 | if subscriber.has_service('DHCP'): |
| 411 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.150.1') |
| 412 | log.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
| 413 | subscriber.src_list = [cip] |
| 414 | self.test_status = True |
| 415 | else: |
| 416 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 417 | self.test_status = True |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 418 | |
| 419 | def igmp_verify(self, subscriber): |
| 420 | chan = 0 |
| 421 | if subscriber.has_service('IGMP'): |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 422 | ##We wait for all the subscribers to join before triggering leaves |
| 423 | if subscriber.rx_port > 1: |
| 424 | time.sleep(5) |
| 425 | subscriber.channel_join(chan, delay = 0) |
| 426 | self.num_joins += 1 |
| 427 | while self.num_joins < self.num_subscribers: |
| 428 | time.sleep(5) |
| 429 | log.info('All subscribers have joined the channel') |
| 430 | for i in range(10): |
| 431 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 432 | log.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name)) |
| 433 | subscriber.channel_leave(chan) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 434 | time.sleep(5) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 435 | log.info('Interface %s Join RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name,subscriber.join_rx_stats)) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 436 | #Should not receive packets for this subscriber |
| 437 | self.recv_timeout = True |
| 438 | subscriber.recv_timeout = True |
| 439 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10) |
| 440 | subscriber.recv_timeout = False |
| 441 | self.recv_timeout = False |
| 442 | log.info('Joining channel %d for subscriber %s' %(chan, subscriber.name)) |
| 443 | subscriber.channel_join(chan, delay = 0) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 444 | self.test_status = True |
| 445 | |
| 446 | def igmp_jump_verify(self, subscriber): |
| 447 | if subscriber.has_service('IGMP'): |
| 448 | for i in xrange(subscriber.num): |
| 449 | log.info('Subscriber %s jumping channel' %subscriber.name) |
| 450 | chan = subscriber.channel_jump(delay=0) |
| 451 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
| 452 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 453 | time.sleep(3) |
| 454 | log.info('Interface %s Jump RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats)) |
| 455 | self.test_status = True |
| 456 | |
| 457 | def igmp_next_verify(self, subscriber): |
| 458 | if subscriber.has_service('IGMP'): |
| 459 | for i in xrange(subscriber.num): |
| 460 | if i: |
| 461 | chan = subscriber.channel_join_next(delay=0) |
| 462 | else: |
| 463 | chan = subscriber.channel_join(i, delay=0) |
| 464 | log.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name)) |
| 465 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1) |
| 466 | log.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
| 467 | time.sleep(3) |
| 468 | log.info('Interface %s Join Next RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats)) |
| 469 | self.test_status = True |
| 470 | |
| 471 | def generate_port_list(self, subscribers, channels): |
| 472 | return self.port_list[:subscribers] |
| 473 | |
| 474 | def subscriber_load(self, create = True, num = 10, num_channels = 1, channel_start = 0, port_list = []): |
| 475 | '''Load the subscriber from the database''' |
A R Karthick | 4b72d4b | 2016-06-15 11:09:17 -0700 | [diff] [blame] | 476 | self.subscriber_db = SubscriberDB(create = create, services = self.test_services) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 477 | if create is True: |
| 478 | self.subscriber_db.generate(num) |
| 479 | self.subscriber_info = self.subscriber_db.read(num) |
| 480 | self.subscriber_list = [] |
| 481 | if not port_list: |
| 482 | port_list = self.generate_port_list(num, num_channels) |
| 483 | |
| 484 | index = 0 |
| 485 | for info in self.subscriber_info: |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 486 | self.subscriber_list.append(Subscriber(name=info['Name'], |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 487 | service=info['Service'], |
| 488 | port_map = self.port_map, |
| 489 | num=num_channels, |
| 490 | channel_start = channel_start, |
| 491 | tx_port = port_list[index][0], |
| 492 | rx_port = port_list[index][1])) |
| 493 | if num_channels > 1: |
| 494 | channel_start += num_channels |
| 495 | index += 1 |
| 496 | |
| 497 | #load the ssm list for all subscriber channels |
| 498 | igmpChannel = IgmpChannel() |
| 499 | ssm_groups = map(lambda sub: sub.channels, self.subscriber_list) |
| 500 | ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups) |
| 501 | igmpChannel.igmp_load_ssm_config(ssm_list) |
| 502 | |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 503 | def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1, |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 504 | channel_start = 0, cbs = None, port_list = []): |
| 505 | self.test_status = False |
| 506 | self.num_subscribers = num_subscribers |
| 507 | self.subscriber_load(create = True, num = num_subscribers, |
| 508 | num_channels = num_channels, channel_start = channel_start, port_list = port_list) |
| 509 | self.onos_aaa_load() |
| 510 | self.thread_pool = ThreadPool(min(100, self.num_subscribers), queue_size=1, wait_timeout=1) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 511 | chan_leave = False #for single channel, multiple subscribers |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 512 | if cbs is None: |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 513 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 514 | chan_leave = True |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 515 | for subscriber in self.subscriber_list: |
| 516 | subscriber.start() |
| 517 | pool_object = subscriber_pool(subscriber, cbs) |
| 518 | self.thread_pool.addTask(pool_object.pool_cb) |
| 519 | self.thread_pool.cleanUpThreads() |
| 520 | for subscriber in self.subscriber_list: |
| 521 | subscriber.stop() |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 522 | if chan_leave is True: |
| 523 | subscriber.channel_leave(0) |
| 524 | self.num_subscribers = 0 |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 525 | return self.test_status |
| 526 | |
| 527 | def test_subscriber_join_recv(self): |
ChetanGaonker | f9c2f8b | 2016-07-19 15:49:41 -0700 | [diff] [blame] | 528 | """Test subscriber join and receive for channel surfing""" |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 529 | self.num_subscribers = 5 |
| 530 | self.num_channels = 1 |
| 531 | test_status = self.subscriber_join_verify(num_subscribers = self.num_subscribers, |
| 532 | num_channels = self.num_channels, |
| 533 | port_list = self.generate_port_list(self.num_subscribers, |
| 534 | self.num_channels)) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 535 | assert_equal(test_status, True) |
| 536 | |
| 537 | def test_subscriber_join_jump(self): |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 538 | """Test subscriber join and receive for channel surfing""" |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 539 | self.num_subscribers = 5 |
| 540 | self.num_channels = 10 |
| 541 | test_status = self.subscriber_join_verify(num_subscribers = self.num_subscribers, |
| 542 | num_channels = self.num_channels, |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 543 | cbs = (self.tls_verify, self.dhcp_jump_verify, |
| 544 | self.igmp_jump_verify, self.traffic_verify), |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 545 | port_list = self.generate_port_list(self.num_subscribers, |
| 546 | self.num_channels)) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 547 | assert_equal(test_status, True) |
| 548 | |
| 549 | def test_subscriber_join_next(self): |
ChetanGaonker | f9c2f8b | 2016-07-19 15:49:41 -0700 | [diff] [blame] | 550 | """Test subscriber join next for channel surfing""" |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 551 | self.num_subscribers = 5 |
| 552 | self.num_channels = 10 |
| 553 | test_status = self.subscriber_join_verify(num_subscribers = self.num_subscribers, |
| 554 | num_channels = self.num_channels, |
A R Karthick | 65c4d72 | 2016-07-18 14:20:17 -0700 | [diff] [blame] | 555 | cbs = (self.tls_verify, self.dhcp_next_verify, |
| 556 | self.igmp_next_verify, self.traffic_verify), |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 557 | port_list = self.generate_port_list(self.num_subscribers, |
| 558 | self.num_channels)) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 559 | assert_equal(test_status, True) |