Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 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 | |
| 16 | |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 17 | import unittest |
| 18 | from twisted.internet import defer |
| 19 | from nose.tools import * |
| 20 | from IGMP import * |
| 21 | from ACL import ACLTest |
| 22 | from DHCP import DHCPTest |
| 23 | from Channels import Channels, IgmpChannel |
| 24 | from subscriberDb import SubscriberDB |
| 25 | import time, monotonic |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 26 | from CordTestUtils import get_mac, log_test |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 27 | from OltConfig import OltConfig |
A.R Karthick | be7768c | 2017-03-17 11:39:41 -0700 | [diff] [blame] | 28 | from OnosCtrl import OnosCtrl |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 29 | from OnosFlowCtrl import OnosFlowCtrl |
| 30 | from CordContainer import Container, Onos, Quagga |
| 31 | from onosclidriver import OnosCliDriver |
| 32 | from CordTestServer import CordTestServer, cord_test_onos_restart, cord_test_quagga_restart,cord_test_quagga_stop, cord_test_quagga_shell,cord_test_shell |
| 33 | from portmaps import g_subscriber_port_map |
| 34 | import time, monotonic |
| 35 | from scapy_ssl_tls.ssl_tls import * |
| 36 | from scapy_ssl_tls.ssl_tls_crypto import * |
| 37 | import os |
| 38 | import json |
| 39 | from socket import socket |
| 40 | import pexpect |
| 41 | from Stats import Stats |
A.R Karthick | 2e99c47 | 2017-03-22 19:13:51 -0700 | [diff] [blame] | 42 | import logging |
| 43 | logging.getLogger('scapy.runtime').setLevel(logging.ERROR) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 44 | from scapy.all import * |
| 45 | from OnosFlowCtrl import OnosFlowCtrl |
| 46 | from nose.twistedtools import reactor, deferred |
| 47 | import tempfile |
| 48 | import threading |
| 49 | from threading import current_thread |
| 50 | from threadPool import ThreadPool |
| 51 | import random |
| 52 | import collections |
| 53 | import requests |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 54 | log_test.setLevel('INFO') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 55 | class cluster_igmp(object): |
| 56 | V_INF1 = 'veth0' |
| 57 | V_INF2 = 'veth1' |
| 58 | MGROUP1 = '239.1.2.3' |
| 59 | MGROUP2 = '239.2.2.3' |
| 60 | MINVALIDGROUP1 = '255.255.255.255' |
| 61 | MINVALIDGROUP2 = '239.255.255.255' |
| 62 | MMACGROUP1 = "01:00:5e:01:02:03" |
| 63 | MMACGROUP2 = "01:00:5e:02:02:03" |
| 64 | IGMP_DST_MAC = "01:00:5e:00:00:16" |
| 65 | IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1" |
| 66 | IP_SRC = '1.2.3.4' |
| 67 | IP_DST = '224.0.0.22' |
| 68 | NEGATIVE_TRAFFIC_STATUS = 1 |
| 69 | igmp_eth = Ether(dst = IGMP_DST_MAC, type = ETH_P_IP) |
| 70 | igmp_ip = IP(dst = IP_DST) |
| 71 | IGMP_TEST_TIMEOUT = 5 |
| 72 | IGMP_QUERY_TIMEOUT = 60 |
| 73 | MCAST_TRAFFIC_TIMEOUT = 10 |
| 74 | PORT_TX_DEFAULT = 2 |
| 75 | PORT_RX_DEFAULT = 1 |
| 76 | max_packets = 100 |
| 77 | app = 'org.opencord.igmp' |
A.R Karthick | 5968e0d | 2017-05-16 14:50:46 -0700 | [diff] [blame] | 78 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json')) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 79 | ROVER_TEST_TIMEOUT = 300 #3600*86 |
| 80 | ROVER_TIMEOUT = (ROVER_TEST_TIMEOUT - 100) |
| 81 | ROVER_JOIN_TIMEOUT = 60 |
| 82 | |
| 83 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 84 | def setUpClass(cls,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 85 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
| 86 | cls.port_map, _ = cls.olt.olt_port_map() |
A R Karthick | 0f6b684 | 2016-12-06 17:17:44 -0800 | [diff] [blame] | 87 | OnosCtrl.cord_olt_config(cls.olt, controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 88 | |
| 89 | @classmethod |
| 90 | def tearDownClass(cls): pass |
| 91 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 92 | def setUp(self,controller=None): |
| 93 | self.setUpClass(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 94 | self.get_igmp_intf() |
| 95 | ''' Activate the igmp app''' |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 96 | self.onos_ctrl = OnosCtrl(self.app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 97 | self.onos_ctrl.activate() |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 98 | self.igmp_channel = IgmpChannel(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 99 | |
| 100 | def tearDown(self): pass |
| 101 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 102 | def onos_load_config(self, config,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 103 | log_test.info('onos load config is %s'%config) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 104 | status, code = OnosCtrl(self.app).config(config,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 105 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 106 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 107 | assert_equal(status, True) |
| 108 | time.sleep(2) |
| 109 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 110 | def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],controller=None,flag = False): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 111 | ssm_dict = {'apps' : { 'org.onosproject.igmp' : { 'ssmTranslate' : [] } } } |
| 112 | ssm_xlate_list = ssm_dict['apps']['org.onosproject.igmp']['ssmTranslate'] |
| 113 | if flag: #to maintain seperate group-source pair. |
| 114 | for i in range(len(groups)): |
| 115 | d = {} |
| 116 | d['source'] = src_list[i] or '0.0.0.0' |
| 117 | d['group'] = groups[i] |
| 118 | ssm_xlate_list.append(d) |
| 119 | else: |
| 120 | for g in groups: |
| 121 | for s in src_list: |
| 122 | d = {} |
| 123 | d['source'] = s or '0.0.0.0' |
| 124 | d['group'] = g |
| 125 | ssm_xlate_list.append(d) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 126 | self.onos_load_config(ssm_dict,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 127 | cord_port_map = {} |
| 128 | for g in groups: |
| 129 | cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT) |
| 130 | self.igmp_channel.cord_port_table_load(cord_port_map) |
| 131 | time.sleep(2) |
| 132 | |
| 133 | def mcast_ip_range(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'): |
| 134 | start = list(map(int, start_ip.split("."))) |
| 135 | end = list(map(int, end_ip.split("."))) |
| 136 | temp = start |
| 137 | ip_range = [] |
| 138 | ip_range.append(start_ip) |
| 139 | while temp != end: |
| 140 | start[3] += 1 |
| 141 | for i in (3, 2, 1): |
| 142 | if temp[i] == 255: |
| 143 | temp[i] = 0 |
| 144 | temp[i-1] += 1 |
| 145 | ip_range.append(".".join(map(str, temp))) |
| 146 | return ip_range |
| 147 | |
| 148 | def random_mcast_ip(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'): |
| 149 | start = list(map(int, start_ip.split("."))) |
| 150 | end = list(map(int, end_ip.split("."))) |
| 151 | temp = start |
| 152 | ip_range = [] |
| 153 | ip_range.append(start_ip) |
| 154 | while temp != end: |
| 155 | start[3] += 1 |
| 156 | for i in (3, 2, 1): |
| 157 | if temp[i] == 255: |
| 158 | temp[i] = 0 |
| 159 | temp[i-1] += 1 |
| 160 | ip_range.append(".".join(map(str, temp))) |
| 161 | return random.choice(ip_range) |
| 162 | |
| 163 | def source_ip_range(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'): |
| 164 | start = list(map(int, start_ip.split("."))) |
| 165 | end = list(map(int, end_ip.split("."))) |
| 166 | temp = start |
| 167 | ip_range = [] |
| 168 | ip_range.append(start_ip) |
| 169 | while temp != end: |
| 170 | start[3] += 1 |
| 171 | for i in (3, 2, 1): |
| 172 | if temp[i] == 255: |
| 173 | temp[i] = 0 |
| 174 | temp[i-1] += 1 |
| 175 | ip_range.append(".".join(map(str, temp))) |
| 176 | return ip_range |
| 177 | def iptomac(self, mcast_ip): |
| 178 | mcast_mac = '01:00:5e:' |
| 179 | octets = mcast_ip.split('.') |
| 180 | second_oct = int(octets[1]) & 127 |
| 181 | third_oct = int(octets[2]) |
| 182 | fourth_oct = int(octets[3]) |
| 183 | mcast_mac = mcast_mac + format(second_oct,'02x') + ':' + format(third_oct, '02x') + ':' + format(fourth_oct, '02x') |
| 184 | return mcast_mac |
| 185 | |
| 186 | def randomsourceip(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'): |
| 187 | start = list(map(int, start_ip.split("."))) |
| 188 | end = list(map(int, end_ip.split("."))) |
| 189 | temp = start |
| 190 | ip_range = [] |
| 191 | ip_range.append(start_ip) |
| 192 | while temp != end: |
| 193 | start[3] += 1 |
| 194 | for i in (3, 2, 1): |
| 195 | if temp[i] == 255: |
| 196 | temp[i] = 0 |
| 197 | temp[i-1] += 1 |
| 198 | ip_range.append(".".join(map(str, temp))) |
| 199 | return random.choice(ip_range) |
| 200 | |
| 201 | def get_igmp_intf(self): |
| 202 | inst = os.getenv('TEST_INSTANCE', None) |
| 203 | if not inst: |
| 204 | return 'veth0' |
| 205 | inst = int(inst) + 1 |
| 206 | if inst >= self.port_map['uplink']: |
| 207 | inst += 1 |
| 208 | if self.port_map.has_key(inst): |
| 209 | return self.port_map[inst] |
| 210 | return 'veth0' |
| 211 | |
| 212 | def igmp_verify_join(self, igmpStateList): |
| 213 | sendState, recvState = igmpStateList |
| 214 | ## check if the send is received for the groups |
| 215 | for g in sendState.groups: |
| 216 | tx_stats = sendState.group_map[g][0] |
| 217 | tx = tx_stats.count |
| 218 | assert_greater(tx, 0) |
| 219 | rx_stats = recvState.group_map[g][1] |
| 220 | rx = rx_stats.count |
| 221 | assert_greater(rx, 0) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 222 | log_test.info('Receive stats %s for group %s' %(rx_stats, g)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 223 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 224 | log_test.info('IGMP test verification success') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 225 | |
| 226 | def igmp_verify_leave(self, igmpStateList, leave_groups): |
| 227 | sendState, recvState = igmpStateList[0], igmpStateList[1] |
| 228 | ## check if the send is received for the groups |
| 229 | for g in sendState.groups: |
| 230 | tx_stats = sendState.group_map[g][0] |
| 231 | rx_stats = recvState.group_map[g][1] |
| 232 | tx = tx_stats.count |
| 233 | rx = rx_stats.count |
| 234 | assert_greater(tx, 0) |
| 235 | if g not in leave_groups: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 236 | log_test.info('Received %d packets for group %s' %(rx, g)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 237 | for g in leave_groups: |
| 238 | rx = recvState.group_map[g][1].count |
| 239 | assert_equal(rx, 0) |
| 240 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 241 | log_test.info('IGMP test verification success') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 242 | |
| 243 | def mcast_traffic_timer(self): |
| 244 | self.mcastTraffic.stopReceives() |
| 245 | |
| 246 | def send_mcast_cb(self, send_state): |
| 247 | for g in send_state.groups: |
| 248 | send_state.update(g, tx = 1) |
| 249 | return 0 |
| 250 | |
| 251 | ##Runs in the context of twisted reactor thread |
| 252 | def igmp_recv(self, igmpState, iface = 'veth0'): |
| 253 | p = self.recv_socket.recv() |
| 254 | try: |
| 255 | send_time = float(p.payload.load) |
| 256 | recv_time = monotonic.monotonic() |
| 257 | except: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 258 | log_test.info('Unexpected Payload received: %s' %p.payload.load) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 259 | return 0 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 260 | #log_test.info( 'Recv in %.6f secs' %(recv_time - send_time)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 261 | igmpState.update(p.dst, rx = 1, t = recv_time - send_time) |
| 262 | return 0 |
| 263 | |
| 264 | def send_igmp_join(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE, |
| 265 | ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1): |
| 266 | if ssm_load is True: |
| 267 | self.onos_ssm_table_load(groups, src_list) |
| 268 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, |
| 269 | gaddr=self.IP_DST) |
| 270 | for g in groups: |
| 271 | gr = IGMPv3gr(rtype= record_type, mcaddr=g) |
| 272 | gr.sources = src_list |
| 273 | igmp.grps.append(gr) |
| 274 | if ip_pkt is None: |
| 275 | ip_pkt = self.igmp_eth/self.igmp_ip |
| 276 | pkt = ip_pkt/igmp |
| 277 | IGMPv3.fixup(pkt) |
| 278 | sendp(pkt, iface=iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 279 | log_test.info('igmp join packet is %s'%pkt.show()) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 280 | if delay != 0: |
| 281 | time.sleep(delay) |
| 282 | |
| 283 | class cluster_tls(): |
| 284 | eap_app = 'org.opencord.aaa' |
| 285 | CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE----- |
| 286 | MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD |
| 287 | VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE |
| 288 | ChMKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw |
| 289 | JAYDVQQDEx1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjAzMTEx |
| 290 | ODUzMzVaFw0xNzAzMDYxODUzMzVaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECBMC |
| 291 | Q0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UEChMKQ2llbmEgSW5jLjEeMBwG |
| 292 | CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDEx1FeGFtcGxlIENl |
| 293 | cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC |
| 294 | ggEBAL9Jv54TkqycL3U2Fdd/y5NXdnPVXwAVV3m6I3eIffVCv8eS+mwlbl9dnbjo |
| 295 | qqlGEgA3sEg5HtnKoW81l3PSyV/YaqzUzbcpDlgWlbNkFQ3nVxh61gSU34Fc4h/W |
| 296 | plSvCkwGSbV5udLtEe6S9IflP2Fu/eXa9vmUtoPqDk66p9U/nWVf2H1GJy7XanWg |
| 297 | wke+HpQvbzoSfPJS0e5Rm9KErrzaIkJpqt7soW+OjVJitUax7h45RYY1HHHlbMQ0 |
| 298 | ndWW8UDsCxFQO6d7nsijCzY69Y8HarH4mbVtqhg3KJevxD9UMRy6gdtPMDZLah1c |
| 299 | LHRu14ucOK4aF8oICOgtcD06auUCAwEAAaOCASwwggEoMB0GA1UdDgQWBBQwEs0m |
| 300 | c8HARTVp21wtiwgav5biqjCBwAYDVR0jBIG4MIG1gBQwEs0mc8HARTVp21wtiwga |
| 301 | v5biqqGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQH |
| 302 | EwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW |
| 303 | D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB |
| 304 | dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap |
| 305 | oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI |
| 306 | hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp |
| 307 | jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo |
| 308 | bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L |
| 309 | opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej |
| 310 | gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM |
| 311 | 729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY= |
| 312 | -----END CERTIFICATE-----''' |
| 313 | def __init__(self): |
| 314 | pass |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 315 | def setUp(self,controller=None): |
| 316 | self.onos_ctrl = OnosCtrl(self.eap_app,controller=controller) |
| 317 | self.onos_aaa_config(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 318 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 319 | def onos_aaa_config(self,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 320 | log_test.info('controller in onos_aaa_config is %s'%controller) |
A.R Karthick | a6c88fd | 2017-03-13 09:29:41 -0700 | [diff] [blame] | 321 | aaa_dict = {'apps' : { 'org.opencord.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password', |
| 322 | 'radiusIp': '172.17.0.2' } } } } |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 323 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
A.R Karthick | a6c88fd | 2017-03-13 09:29:41 -0700 | [diff] [blame] | 324 | aaa_dict['apps']['org.opencord.aaa']['AAA']['radiusIp'] = radius_ip |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 325 | self.onos_ctrl.activate() |
| 326 | time.sleep(2) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 327 | self.onos_load_config(aaa_dict,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 328 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 329 | def onos_load_config(self, config,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 330 | log_test.info('controller in onos_load_config is %s'%controller) |
| 331 | log_test.info('onos load config is %s'%config) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 332 | status, code = OnosCtrl(self.eap_app).config(config,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 333 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 334 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 335 | assert_equal(status, True) |
| 336 | time.sleep(2) |
| 337 | |
| 338 | |
| 339 | class cluster_flows(): |
| 340 | |
| 341 | PORT_TX_DEFAULT = 2 |
| 342 | PORT_RX_DEFAULT = 1 |
| 343 | INTF_TX_DEFAULT = 'veth2' |
| 344 | INTF_RX_DEFAULT = 'veth0' |
| 345 | default_port_map = { |
| 346 | PORT_TX_DEFAULT : INTF_TX_DEFAULT, |
| 347 | PORT_RX_DEFAULT : INTF_RX_DEFAULT, |
| 348 | INTF_TX_DEFAULT : PORT_TX_DEFAULT, |
| 349 | INTF_RX_DEFAULT : PORT_RX_DEFAULT |
| 350 | } |
| 351 | app = 'org.onosproject.cli' |
| 352 | |
| 353 | def incmac(self, mac): |
| 354 | tmp = str(hex(int('0x'+mac,16)+1).split('x')[1]) |
| 355 | mac = '0'+ tmp if len(tmp) < 2 else tmp |
| 356 | return mac |
| 357 | |
| 358 | def next_mac(self, mac): |
| 359 | mac = mac.split(":") |
| 360 | mac[5] = self.incmac(mac[5]) |
| 361 | |
| 362 | if len(mac[5]) > 2: |
| 363 | mac[0] = self.incmac(mac[0]) |
| 364 | mac[5] = '01' |
| 365 | |
| 366 | if len(mac[0]) > 2: |
| 367 | mac[0] = '01' |
| 368 | mac[1] = self.incmac(mac[1]) |
| 369 | mac[5] = '01' |
| 370 | return ':'.join(mac) |
| 371 | |
| 372 | def to_egress_mac(cls, mac): |
| 373 | mac = mac.split(":") |
| 374 | mac[4] = '01' |
| 375 | |
| 376 | return ':'.join(mac) |
| 377 | |
| 378 | def inc_ip(self, ip, i): |
| 379 | |
| 380 | ip[i] =str(int(ip[i])+1) |
| 381 | return '.'.join(ip) |
| 382 | |
| 383 | |
| 384 | def next_ip(self, ip): |
| 385 | |
| 386 | lst = ip.split('.') |
| 387 | for i in (3,0,-1): |
| 388 | if int(lst[i]) < 255: |
| 389 | return self.inc_ip(lst, i) |
| 390 | elif int(lst[i]) == 255: |
| 391 | lst[i] = '0' |
| 392 | if int(lst[i-1]) < 255: |
| 393 | return self.inc_ip(lst,i-1) |
| 394 | elif int(lst[i-2]) < 255: |
| 395 | lst[i-1] = '0' |
| 396 | return self.inc_ip(lst,i-2) |
| 397 | else: |
| 398 | break |
| 399 | |
| 400 | def randomip(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'): |
| 401 | start = list(map(int, start_ip.split("."))) |
| 402 | end = list(map(int, end_ip.split("."))) |
| 403 | temp = start |
| 404 | ip_range = [] |
| 405 | ip_range.append(start_ip) |
| 406 | while temp != end: |
| 407 | start[3] += 1 |
| 408 | for i in (3, 2, 1): |
| 409 | if temp[i] == 255: |
| 410 | temp[i] = 0 |
| 411 | temp[i-1] += 1 |
| 412 | ip_range.append(".".join(map(str, temp))) |
| 413 | return random.choice(ip_range) |
| 414 | |
| 415 | def ip_range(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'): |
| 416 | start = list(map(int, start_ip.split("."))) |
| 417 | end = list(map(int, end_ip.split("."))) |
| 418 | temp = start |
| 419 | ip_range = [] |
| 420 | ip_range.append(start_ip) |
| 421 | while temp != end: |
| 422 | start[3] += 1 |
| 423 | for i in (3, 2, 1): |
| 424 | if temp[i] == 255: |
| 425 | temp[i] = 0 |
| 426 | temp[i-1] += 1 |
| 427 | ip_range.append(".".join(map(str, temp))) |
| 428 | return ip_range |
| 429 | |
| 430 | def to_egress_ip(self, ip): |
| 431 | lst=ip.split('.') |
| 432 | lst[0] = '182' |
| 433 | return '.'.join(lst) |
| 434 | |
| 435 | @classmethod |
| 436 | def setUpClass(cls): |
| 437 | cls.olt = OltConfig() |
| 438 | cls.port_map, _ = cls.olt.olt_port_map() |
| 439 | if not cls.port_map: |
| 440 | cls.port_map = cls.default_port_map |
| 441 | cls.device_id = OnosCtrl.get_device_id() |
| 442 | |
| 443 | class cluster_proxyarp(): |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 444 | #apps = ('org.onosproject.vrouter','org.onosproject.proxyarp') |
| 445 | app = 'org.onosproject.proxyarp' |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 446 | device_id = 'of:' + get_mac() |
| 447 | device_dict = { "devices" : { |
| 448 | "{}".format(device_id) : { |
| 449 | "basic" : { |
| 450 | "driver" : "softrouter" |
| 451 | } |
| 452 | } |
| 453 | }, |
| 454 | } |
| 455 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 456 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
| 457 | GATEWAY = '192.168.10.50' |
| 458 | INGRESS_PORT = 1 |
| 459 | EGRESS_PORT = 2 |
| 460 | MAX_PORTS = 100 |
| 461 | hosts_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ] |
| 462 | |
A.R Karthick | 5968e0d | 2017-05-16 14:50:46 -0700 | [diff] [blame] | 463 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json')) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 464 | |
| 465 | @classmethod |
| 466 | def setUpClass(cls): |
| 467 | cls.olt = OltConfig() |
| 468 | cls.port_map, _ = cls.olt.olt_port_map() |
| 469 | print('port map in proxyarp setUpClass is %s'%cls.port_map) |
| 470 | if not cls.port_map: |
| 471 | cls.port_map = g_subscriber_port_map |
| 472 | time.sleep(3) |
| 473 | cls.load_device_id() |
| 474 | |
| 475 | @classmethod |
| 476 | def load_device_id(cls): |
| 477 | did = OnosCtrl.get_device_id() |
| 478 | cls.device_id = did |
| 479 | cls.device_dict = { "devices" : { |
| 480 | "{}".format(did) : { |
| 481 | "basic" : { |
| 482 | "driver" : "softrouter" |
| 483 | } |
| 484 | } |
| 485 | }, |
| 486 | } |
| 487 | def cliEnter(self): |
| 488 | retries = 0 |
| 489 | while retries < 3: |
| 490 | self.cli = OnosCliDriver(connect = True) |
| 491 | if self.cli.handle: |
| 492 | break |
| 493 | else: |
| 494 | retries += 1 |
| 495 | time.sleep(2) |
| 496 | |
| 497 | def cliExit(self): |
| 498 | self.cli.disconnect() |
| 499 | |
| 500 | @classmethod |
| 501 | def interface_config_load(cls, interface_cfg = None): |
| 502 | if type(interface_cfg) is tuple: |
| 503 | res = [] |
| 504 | for v in interface_cfg: |
| 505 | if type(v) == list: |
| 506 | pass |
| 507 | else: |
| 508 | res += v.items() |
| 509 | config = dict(res) |
| 510 | else: |
| 511 | config = interface_cfg |
| 512 | cfg = json.dumps(config) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 513 | #with open('{}/network-cfg.json'.format(cls.onos_config_path), 'w') as f: |
| 514 | # f.write(cfg) |
| 515 | #return cord_test_onos_restart(config=config) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 516 | |
| 517 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 518 | def host_config_load(cls, host_config = None, controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 519 | for host in host_config: |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 520 | status, code = OnosCtrl(cls.app).host_config(host,onos_ip=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 521 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 522 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 523 | assert_equal(status, True) |
| 524 | |
| 525 | @classmethod |
| 526 | def generate_interface_config(cls, hosts = 1): |
| 527 | num = 0 |
| 528 | start_host = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0 |
| 529 | end_host = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0 |
| 530 | ports_dict = { 'ports' : {} } |
| 531 | interface_list = [] |
| 532 | hosts_list = [] |
| 533 | for n in xrange(start_host, end_host, 256): |
| 534 | port_map = ports_dict['ports'] |
| 535 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 536 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 537 | try: |
| 538 | interfaces = port_map[device_port_key]['interfaces'] |
| 539 | except: |
| 540 | port_map[device_port_key] = { 'interfaces' : [] } |
| 541 | interfaces = port_map[device_port_key]['interfaces'] |
| 542 | ip = n + 1 |
| 543 | host_ip = n + 2 |
| 544 | ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff) |
| 545 | host = '%d.%d.%d.%d' % ( (host_ip >> 24) & 0xff, ( ( host_ip >> 16) & 0xff ), ( (host_ip >> 8 ) & 0xff ), host_ip & 0xff ) |
| 546 | mac = RandMAC()._fix() |
| 547 | hosts_list.append((host, mac)) |
| 548 | if num < cls.MAX_PORTS - 1: |
| 549 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac } |
| 550 | interfaces.append(interface_dict) |
| 551 | interface_list.append(interface_dict['name']) |
| 552 | else: |
| 553 | interfaces[0]['ips'].append(ips) |
| 554 | num += 1 |
| 555 | if num == hosts: |
| 556 | break |
| 557 | cls.hosts_list = hosts_list |
| 558 | return (cls.device_dict, ports_dict, hosts_list) |
| 559 | |
| 560 | @classmethod |
| 561 | def generate_host_config(cls): |
| 562 | num = 0 |
| 563 | hosts_dict = {} |
| 564 | for host, mac in cls.hosts_list: |
| 565 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 566 | hosts_dict[host] = {'mac':mac, 'vlan':'none', 'ipAddresses':[host], 'location':{ 'elementId' : '{}'.format(cls.device_id), 'port': port}} |
| 567 | num += 1 |
| 568 | return hosts_dict.values() |
| 569 | |
| 570 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 571 | def proxyarp_activate(cls, deactivate = False,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 572 | app = 'org.onosproject.proxyarp' |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 573 | onos_ctrl = OnosCtrl(app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 574 | if deactivate is True: |
| 575 | onos_ctrl.deactivate() |
| 576 | else: |
| 577 | onos_ctrl.activate() |
| 578 | time.sleep(3) |
| 579 | |
| 580 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 581 | def proxyarp_config(cls, hosts = 1,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 582 | proxyarp_configs = cls.generate_interface_config(hosts = hosts) |
| 583 | cls.interface_config_load(interface_cfg = proxyarp_configs) |
| 584 | hostcfg = cls.generate_host_config() |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 585 | cls.host_config_load(host_config = hostcfg,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 586 | return proxyarp_configs |
| 587 | |
| 588 | def proxyarp_arpreply_verify(self, ingress, hostip, hostmac, PositiveTest=True): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 589 | #log_test.info('verifying arp reply for host ip %s host mac %s on interface %s'%(hostip ,hostmac ,self.port_map[ingress])) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 590 | self.success = False |
| 591 | def recv_task(): |
| 592 | def recv_cb(pkt): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 593 | log_test.info('Arp Reply seen with source Mac is %s' %(pkt[ARP].hwsrc)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 594 | self.success = True if PositiveTest == True else False |
| 595 | sniff(count=1, timeout=2, lfilter = lambda p: ARP in p and p[ARP].op == 2 and p[ARP].hwsrc == hostmac, |
| 596 | prn = recv_cb, iface = self.port_map[ingress]) |
| 597 | t = threading.Thread(target = recv_task) |
| 598 | t.start() |
| 599 | pkt = (Ether(dst = 'ff:ff:ff:ff:ff:ff')/ARP(op=1,pdst=hostip)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 600 | log_test.info('sending arp request for dest ip %s on interface %s' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 601 | (hostip, self.port_map[ingress])) |
| 602 | sendp( pkt, count = 10, iface = self.port_map[ingress]) |
| 603 | t.join() |
| 604 | if PositiveTest: |
| 605 | assert_equal(self.success, True) |
| 606 | else: |
| 607 | assert_equal(self.success, False) |
| 608 | |
| 609 | def proxyarp_hosts_verify(self, hosts = 1,PositiveTest = True): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 610 | log_test.info('verifying arp reply for host ip host mac on interface %s'%(self.port_map[2])) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 611 | _,_,hosts_config = self.proxyarp_config(hosts = hosts) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 612 | log_test.info('\nhosts_config %s and its type %s'%(hosts_config,type(hosts_config))) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 613 | self.cliEnter() |
| 614 | connected_hosts = json.loads(self.cli.hosts(jsonFormat = True)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 615 | log_test.info('Discovered hosts: %s' %connected_hosts) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 616 | #We read from cli if we expect less number of routes to avoid cli timeouts |
| 617 | if hosts <= 10000: |
| 618 | assert_equal(len(connected_hosts), hosts) |
| 619 | ingress = hosts+1 |
| 620 | for hostip, hostmac in hosts_config: |
| 621 | self.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = PositiveTest) |
| 622 | time.sleep(1) |
| 623 | self.cliExit() |
| 624 | return True |
| 625 | |
| 626 | class cluster_vrouter(object): |
| 627 | apps = ('org.onosproject.vrouter', 'org.onosproject.fwd') |
| 628 | device_id = 'of:' + get_mac() |
| 629 | vrouter_device_dict = { "devices" : { |
| 630 | "{}".format(device_id) : { |
| 631 | "basic" : { |
| 632 | "driver" : "softrouter" |
| 633 | } |
| 634 | } |
| 635 | }, |
| 636 | } |
| 637 | zebra_conf = ''' |
| 638 | password zebra |
| 639 | log stdout |
| 640 | service advanced-vty |
| 641 | ! |
| 642 | !debug zebra rib |
| 643 | !debug zebra kernel |
| 644 | !debug zebra fpm |
| 645 | ! |
| 646 | !interface eth1 |
| 647 | ! ip address 10.10.0.3/16 |
| 648 | line vty |
| 649 | exec-timeout 0 0 |
| 650 | ''' |
| 651 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 652 | quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config') |
| 653 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
| 654 | GATEWAY = '192.168.10.50' |
| 655 | INGRESS_PORT = 1 |
| 656 | EGRESS_PORT = 2 |
| 657 | MAX_PORTS = 100 |
| 658 | peer_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ] |
| 659 | network_list = [] |
| 660 | network_mask = 24 |
| 661 | default_routes_address = ('11.10.10.0/24',) |
| 662 | default_peer_address = peer_list |
| 663 | quagga_ip = os.getenv('QUAGGA_IP') |
| 664 | |
| 665 | @classmethod |
| 666 | def setUpClass(cls): |
| 667 | ''' Activate the vrouter apps''' |
| 668 | cls.olt = OltConfig() |
| 669 | cls.port_map, _ = cls.olt.olt_port_map() |
| 670 | if not cls.port_map: |
| 671 | cls.port_map = g_subscriber_port_map |
| 672 | time.sleep(3) |
| 673 | cls.load_device_id() |
| 674 | |
| 675 | @classmethod |
| 676 | def tearDownClass(cls): |
| 677 | '''Deactivate the vrouter apps''' |
| 678 | #cls.vrouter_host_unload() |
| 679 | cls.start_onos(network_cfg = {}) |
| 680 | #cls.vrouter_activate(cls, deactivate = True) |
| 681 | |
| 682 | |
| 683 | @classmethod |
| 684 | def load_device_id(cls): |
| 685 | did = OnosCtrl.get_device_id() |
| 686 | cls.device_id = did |
| 687 | cls.vrouter_device_dict = { "devices" : { |
| 688 | "{}".format(did) : { |
| 689 | "basic" : { |
| 690 | "driver" : "softrouter" |
| 691 | } |
| 692 | } |
| 693 | }, |
| 694 | } |
| 695 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 696 | def cliEnter(self,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 697 | retries = 0 |
| 698 | while retries < 3: |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 699 | self.cli = OnosCliDriver(connect = True,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 700 | if self.cli.handle: |
| 701 | break |
| 702 | else: |
| 703 | retries += 1 |
| 704 | time.sleep(2) |
| 705 | |
| 706 | def cliExit(self): |
| 707 | self.cli.disconnect() |
| 708 | |
| 709 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 710 | def onos_load_config(cls, config,controller=None): |
| 711 | status, code = OnosCtrl.config(config,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 712 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 713 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 714 | assert_equal(status, True) |
| 715 | |
| 716 | @classmethod |
| 717 | def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None, |
| 718 | route_update = None, router_address = None): |
| 719 | vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers, |
| 720 | peer_address = peer_address, router_address = router_address) |
| 721 | return vrouter_configs |
| 722 | |
| 723 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 724 | def vrouter_host_load(cls,peer_address = None,controller=None): |
| 725 | index = 1 |
| 726 | hosts_dict = {} |
| 727 | peer_info = peer_address if peer_address is not None else cls.peer_list |
| 728 | for host,_ in peer_info: |
| 729 | #iface = cls.port_map[index] |
| 730 | mac = RandMAC()._fix() |
| 731 | #port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 732 | log_test.info('creating host with ip %s and mac %s'%(host,mac)) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 733 | hosts_dict[host] = {'mac':mac, 'vlan':'none', 'ipAddresses':[host], 'location':{ 'elementId' : '{}'.format(cls.device_id), 'port': index}} |
| 734 | index += 1 |
| 735 | for host in hosts_dict.values(): |
| 736 | status, code = OnosCtrl.host_config(host,onos_ip=controller) |
| 737 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 738 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 739 | return False |
| 740 | return True |
| 741 | |
| 742 | """@classmethod |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 743 | def vrouter_host_load(cls, peer_address = None): |
| 744 | #cls.setUpClass() |
| 745 | index = 1 |
| 746 | peer_info = peer_address if peer_address is not None else cls.peer_list |
| 747 | |
| 748 | for host,_ in peer_info: |
| 749 | iface = cls.port_map[index] |
| 750 | index += 1 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 751 | log_test.info('Assigning ip %s to interface %s' %(host, iface)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 752 | config_cmds = ( 'ifconfig {} 0'.format(iface), |
| 753 | 'ifconfig {0} {1}'.format(iface, host), |
| 754 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 755 | ) |
| 756 | for cmd in config_cmds: |
| 757 | os.system(cmd) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 758 | """ |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 759 | @classmethod |
| 760 | def vrouter_host_unload(cls, peer_address = None): |
| 761 | index = 1 |
| 762 | peer_info = peer_address if peer_address is not None else cls.peer_list |
| 763 | |
| 764 | for host,_ in peer_info: |
| 765 | iface = cls.port_map[index] |
| 766 | index += 1 |
| 767 | config_cmds = ('ifconfig {} 0'.format(iface), ) |
| 768 | for cmd in config_cmds: |
| 769 | os.system(cmd) |
| 770 | |
| 771 | @classmethod |
| 772 | def start_onos(cls, network_cfg = None): |
| 773 | if type(network_cfg) is tuple: |
| 774 | res = [] |
| 775 | for v in network_cfg: |
| 776 | res += v.items() |
| 777 | config = dict(res) |
| 778 | else: |
| 779 | config = network_cfg |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 780 | cfg = json.dumps(config) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 781 | log_test.info('Restarting ONOS with new network configuration %s'%config) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 782 | #return cord_test_onos_restart(config = config) |
| 783 | with open('{}/network-cfg.json'.format(cls.onos_config_path), 'w') as f: |
| 784 | f.write(cfg) |
| 785 | return cord_test_onos_restart(config=config) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 786 | |
| 787 | @classmethod |
| 788 | def start_quagga(cls, networks = 4, peer_address = None, router_address = None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 789 | log_test.info('Restarting Quagga container with configuration for %d networks' %(networks)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 790 | config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address) |
| 791 | if networks <= 10000: |
| 792 | boot_delay = 25 |
| 793 | else: |
| 794 | delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200] |
| 795 | n = min(networks/100000, len(delay_map)-1) |
| 796 | boot_delay = delay_map[n] |
| 797 | cord_test_quagga_restart(config = config, boot_delay = boot_delay) |
| 798 | |
| 799 | @classmethod |
| 800 | def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None): |
| 801 | num = 0 |
| 802 | if peer_address is None: |
| 803 | start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0 |
| 804 | end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0 |
| 805 | else: |
| 806 | ip = peer_address[0][0] |
| 807 | start_ip = ip.split('.') |
| 808 | start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0 |
| 809 | end_peer = ((int(start_ip[0]) + 8) << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0 |
| 810 | local_network = end_peer + 1 |
| 811 | ports_dict = { 'ports' : {} } |
| 812 | interface_list = [] |
| 813 | peer_list = [] |
| 814 | for n in xrange(start_peer, end_peer, 256): |
| 815 | port_map = ports_dict['ports'] |
| 816 | port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1 |
| 817 | device_port_key = '{0}/{1}'.format(cls.device_id, port) |
| 818 | try: |
| 819 | interfaces = port_map[device_port_key]['interfaces'] |
| 820 | except: |
| 821 | port_map[device_port_key] = { 'interfaces' : [] } |
| 822 | interfaces = port_map[device_port_key]['interfaces'] |
| 823 | ip = n + 2 |
| 824 | peer_ip = n + 1 |
| 825 | ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff) |
| 826 | peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff ) |
| 827 | mac = RandMAC()._fix() |
| 828 | peer_list.append((peer, mac)) |
| 829 | if num < cls.MAX_PORTS - 1: |
| 830 | interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac } |
| 831 | interfaces.append(interface_dict) |
| 832 | interface_list.append(interface_dict['name']) |
| 833 | else: |
| 834 | interfaces[0]['ips'].append(ips) |
| 835 | num += 1 |
| 836 | if num == peers: |
| 837 | break |
| 838 | quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 839 | quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router'] |
| 840 | quagga_router_dict['ospfEnabled'] = True |
| 841 | quagga_router_dict['interfaces'] = interface_list |
| 842 | quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 843 | |
| 844 | #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } } |
| 845 | bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers'] |
| 846 | speaker_dict = {} |
| 847 | speaker_dict['name'] = 'bgp{}'.format(peers+1) |
| 848 | speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1) |
| 849 | speaker_dict['peers'] = peer_list |
| 850 | bgp_speakers_list.append(speaker_dict) |
| 851 | cls.peer_list = peer_list |
| 852 | return (cls.vrouter_device_dict, ports_dict, quagga_dict) |
| 853 | |
| 854 | @classmethod |
| 855 | def generate_conf(cls, networks = 4, peer_address = None, router_address = None): |
| 856 | num = 0 |
| 857 | if router_address is None: |
| 858 | start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0 |
| 859 | end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0 |
| 860 | network_mask = 24 |
| 861 | else: |
| 862 | ip = router_address |
| 863 | start_ip = ip.split('.') |
| 864 | network_mask = int(start_ip[3].split('/')[1]) |
| 865 | start_ip[3] = (start_ip[3].split('/'))[0] |
| 866 | start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0 |
| 867 | end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0 |
| 868 | net_list = [] |
| 869 | peer_list = peer_address if peer_address is not None else cls.peer_list |
| 870 | network_list = [] |
| 871 | for n in xrange(start_network, end_network, 256): |
| 872 | net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) ) |
| 873 | network_list.append(net) |
| 874 | gateway = peer_list[num % len(peer_list)][0] |
| 875 | net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway) |
| 876 | net_list.append(net_route) |
| 877 | num += 1 |
| 878 | if num == networks: |
| 879 | break |
| 880 | cls.network_list = network_list |
| 881 | cls.network_mask = network_mask |
| 882 | zebra_routes = '\n'.join(net_list) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 883 | #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 884 | return cls.zebra_conf + zebra_routes |
| 885 | |
| 886 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 887 | def vrouter_activate(cls, deactivate = False,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 888 | app = 'org.onosproject.vrouter' |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 889 | onos_ctrl = OnosCtrl(app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 890 | if deactivate is True: |
| 891 | onos_ctrl.deactivate() |
| 892 | else: |
| 893 | onos_ctrl.activate() |
| 894 | time.sleep(3) |
| 895 | |
| 896 | @classmethod |
| 897 | def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None, |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 898 | route_update = None, router_address = None, time_expire = None, adding_new_routes = None,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 899 | vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers, |
| 900 | peer_address = peer_address, route_update = route_update) |
| 901 | cls.start_onos(network_cfg = vrouter_configs) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 902 | cls.vrouter_host_load(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 903 | ##Start quagga |
| 904 | cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address) |
| 905 | return vrouter_configs |
| 906 | |
| 907 | def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True): |
| 908 | src_mac = '00:00:00:00:00:02' |
| 909 | src_ip = '1.1.1.1' |
| 910 | self.success = False if positive_test else True |
| 911 | timeout = 10 if positive_test else 1 |
| 912 | count = 2 if positive_test else 1 |
| 913 | self.start_sending = True |
| 914 | def recv_task(): |
| 915 | def recv_cb(pkt): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 916 | log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 917 | self.success = True if positive_test else False |
| 918 | sniff(count=count, timeout=timeout, |
| 919 | lfilter = lambda p: IP in p and p[IP].dst == dst_ip and p[IP].src == src_ip, |
| 920 | prn = recv_cb, iface = self.port_map[ingress]) |
| 921 | self.start_sending = False |
| 922 | |
| 923 | t = threading.Thread(target = recv_task) |
| 924 | t.start() |
| 925 | L2 = Ether(src = src_mac, dst = dst_mac) |
| 926 | L3 = IP(src = src_ip, dst = dst_ip) |
| 927 | pkt = L2/L3 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 928 | log_test.info('Sending a packet with dst ip %s, dst mac %s on port %s to verify if flows are correct' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 929 | (dst_ip, dst_mac, self.port_map[egress])) |
| 930 | while self.start_sending is True: |
| 931 | sendp(pkt, count=50, iface = self.port_map[egress]) |
| 932 | t.join() |
| 933 | assert_equal(self.success, True) |
| 934 | |
| 935 | def vrouter_traffic_verify(self, positive_test = True, peer_address = None): |
| 936 | if peer_address is None: |
| 937 | peers = len(self.peer_list) |
| 938 | peer_list = self.peer_list |
| 939 | else: |
| 940 | peers = len(peer_address) |
| 941 | peer_list = peer_address |
| 942 | egress = peers + 1 |
| 943 | num = 0 |
| 944 | num_hosts = 5 if positive_test else 1 |
| 945 | src_mac = '00:00:00:00:00:02' |
| 946 | src_ip = '1.1.1.1' |
| 947 | if self.network_mask != 24: |
| 948 | peers = 1 |
| 949 | for network in self.network_list: |
| 950 | num_ips = num_hosts |
| 951 | octets = network.split('.') |
| 952 | for i in xrange(num_ips): |
| 953 | octets[-1] = str(int(octets[-1]) + 1) |
| 954 | dst_ip = '.'.join(octets) |
| 955 | dst_mac = peer_list[ num % peers ] [1] |
| 956 | port = (num % peers) |
| 957 | ingress = port + 1 |
| 958 | #Since peers are on the same network |
| 959 | ##Verify if flows are setup by sending traffic across |
| 960 | self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test) |
| 961 | num += 1 |
| 962 | |
| 963 | def vrouter_network_verify(self, networks, peers = 1, positive_test = True, |
| 964 | start_network = None, start_peer_address = None, route_update = None, |
| 965 | invalid_peers = None, time_expire = None, unreachable_route_traffic = None, |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 966 | deactivate_activate_vrouter = None, adding_new_routes = None,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 967 | |
| 968 | _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers, |
| 969 | peer_address = start_peer_address, |
| 970 | route_update = route_update, |
| 971 | router_address = start_network, |
| 972 | time_expire = time_expire, |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 973 | adding_new_routes = adding_new_routes, |
| 974 | controller=controller) |
| 975 | self.cliEnter(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 976 | ##Now verify |
| 977 | hosts = json.loads(self.cli.hosts(jsonFormat = True)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 978 | log_test.info('Discovered hosts: %s' %hosts) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 979 | ##We read from cli if we expect less number of routes to avoid cli timeouts |
| 980 | if networks <= 10000: |
| 981 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 982 | #log_test.info('Routes: %s' %routes) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 983 | if start_network is not None: |
| 984 | if start_network.split('/')[1] is 24: |
| 985 | assert_equal(len(routes['routes4']), networks) |
| 986 | if start_network.split('/')[1] is not 24: |
| 987 | assert_equal(len(routes['routes4']), 1) |
| 988 | if start_network is None and invalid_peers is None: |
| 989 | assert_equal(len(routes['routes4']), networks) |
| 990 | if invalid_peers is not None: |
| 991 | assert_equal(len(routes['routes4']), 0) |
| 992 | flows = json.loads(self.cli.flows(jsonFormat = True)) |
| 993 | flows = filter(lambda f: f['flows'], flows) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 994 | #log_test.info('Flows: %s' %flows) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 995 | assert_not_equal(len(flows), 0) |
| 996 | if invalid_peers is None: |
| 997 | self.vrouter_traffic_verify() |
| 998 | if positive_test is False: |
| 999 | self.vrouter_network_verify_negative(networks, peers = peers) |
| 1000 | if time_expire is True: |
| 1001 | self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24') |
| 1002 | self.vrouter_traffic_verify() |
| 1003 | if unreachable_route_traffic is True: |
| 1004 | network_list_backup = self.network_list |
| 1005 | self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5'] |
| 1006 | self.vrouter_traffic_verify(positive_test = False) |
| 1007 | self.network_list = network_list_backup |
| 1008 | if deactivate_activate_vrouter is True: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1009 | log_test.info('Deactivating vrouter app in ONOS controller for negative scenario') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1010 | self.vrouter_activate(deactivate = True) |
| 1011 | #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False)) |
| 1012 | #assert_equal(len(routes['routes4']), 'Command not found') |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1013 | log_test.info('Activating vrouter app again in ONOS controller for negative scenario') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1014 | self.vrouter_activate(deactivate = False) |
| 1015 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 1016 | assert_equal(len(routes['routes4']), networks) |
| 1017 | self.vrouter_traffic_verify() |
| 1018 | self.cliExit() |
| 1019 | return True |
| 1020 | |
| 1021 | def vrouter_network_verify_negative(self, networks, peers = 1): |
| 1022 | ##Stop quagga. Test traffic again to see if flows were removed |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1023 | log_test.info('Stopping Quagga container') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1024 | cord_test_quagga_stop() |
| 1025 | if networks <= 10000: |
| 1026 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 1027 | #Verify routes have been removed |
| 1028 | if routes and routes.has_key('routes4'): |
| 1029 | assert_equal(len(routes['routes4']), 0) |
| 1030 | self.vrouter_traffic_verify(positive_test = False) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1031 | log_test.info('OVS flows have been removed successfully after Quagga was stopped') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1032 | self.start_quagga(networks = networks) |
| 1033 | ##Verify the flows again after restarting quagga back |
| 1034 | if networks <= 10000: |
| 1035 | routes = json.loads(self.cli.routes(jsonFormat = True)) |
| 1036 | assert_equal(len(routes['routes4']), networks) |
| 1037 | self.vrouter_traffic_verify() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1038 | log_test.info('OVS flows have been successfully reinstalled after Quagga was restarted') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1039 | |
| 1040 | def quagga_shell(self, cmd): |
| 1041 | shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd)) |
| 1042 | quagga_cmd = ' -c '.join(shell_cmds) |
| 1043 | |
| 1044 | return cord_test_quagga_shell(quagga_cmd) |
| 1045 | |
| 1046 | class cluster_acl(object): |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1047 | app = 'org.onosproject.acl' |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1048 | device_id = 'of:' + get_mac('ovsbr0') |
| 1049 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 1050 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
| 1051 | GATEWAY = '192.168.10.50' |
| 1052 | INGRESS_PORT = 1 |
| 1053 | EGRESS_PORT = 2 |
| 1054 | ingress_iface = 1 |
| 1055 | egress_iface = 2 |
| 1056 | MAX_PORTS = 100 |
| 1057 | CURRENT_PORT_NUM = egress_iface |
| 1058 | ACL_SRC_IP = '192.168.20.3/32' |
| 1059 | ACL_DST_IP = '192.168.30.2/32' |
| 1060 | ACL_SRC_IP_RULE_2 = '192.168.40.3/32' |
| 1061 | ACL_DST_IP_RULE_2 = '192.168.50.2/32' |
| 1062 | ACL_SRC_IP_PREFIX_24 = '192.168.20.3/24' |
| 1063 | ACL_DST_IP_PREFIX_24 = '192.168.30.2/24' |
| 1064 | HOST_DST_IP = '192.168.30.0/24' |
| 1065 | HOST_DST_IP_RULE_2 = '192.168.50.0/24' |
| 1066 | |
| 1067 | @classmethod |
| 1068 | def setUpClass(cls): |
| 1069 | cls.olt = OltConfig() |
| 1070 | cls.port_map,_ = cls.olt.olt_port_map() |
| 1071 | if not cls.port_map: |
| 1072 | cls.port_map = g_subscriber_port_map |
| 1073 | time.sleep(3) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1074 | log_test.info('port_map = %s'%cls.port_map[1] ) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1075 | |
| 1076 | @classmethod |
| 1077 | def tearDownClass(cls): |
| 1078 | '''Deactivate the acl app''' |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1079 | def setUp(self,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1080 | self.setUpClass() |
| 1081 | ''' Activate the acl app''' |
| 1082 | self.maxDiff = None ##for assert_equal compare outputs on failure |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1083 | self.onos_ctrl = OnosCtrl(self.app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1084 | status, _ = self.onos_ctrl.activate() |
| 1085 | assert_equal(status, True) |
| 1086 | time.sleep(1) |
| 1087 | #status, _ = ACLTest.remove_acl_rule() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1088 | #log_test.info('Start setup') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1089 | #assert_equal(status, True) |
| 1090 | |
| 1091 | def tearDown(self): |
| 1092 | '''Deactivate the acl app''' |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1093 | log_test.info('Tear down setup') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1094 | self.CURRENT_PORT_NUM = 4 |
| 1095 | |
| 1096 | def cliEnter(self): |
| 1097 | retries = 0 |
| 1098 | while retries < 3: |
| 1099 | self.cli = OnosCliDriver(connect = True) |
| 1100 | if self.cli.handle: |
| 1101 | break |
| 1102 | else: |
| 1103 | retries += 1 |
| 1104 | time.sleep(2) |
| 1105 | |
| 1106 | def cliExit(self): |
| 1107 | self.cli.disconnect() |
| 1108 | |
| 1109 | @classmethod |
| 1110 | def acl_hosts_add(cls, dstHostIpMac, egress_iface_count = 1, egress_iface_num = None): |
| 1111 | cls.setUpClass() |
| 1112 | index = 0 |
| 1113 | if egress_iface_num is None: |
| 1114 | egress_iface_num = cls.egress_iface |
| 1115 | for ip,_ in dstHostIpMac: |
| 1116 | egress = cls.port_map[egress_iface_num] |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1117 | log_test.info('Assigning ip %s to interface %s' %(ip, egress)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1118 | config_cmds_egress = ( 'ifconfig {} 0'.format(egress), |
| 1119 | 'ifconfig {0} up'.format(egress), |
| 1120 | 'ifconfig {0} {1}'.format(egress, ip), |
| 1121 | 'arping -I {0} {1} -c 2'.format(egress, ip.split('/')[0]), |
| 1122 | 'ifconfig {0}'.format(egress), |
| 1123 | ) |
| 1124 | for cmd in config_cmds_egress: |
| 1125 | os.system(cmd) |
| 1126 | index += 1 |
| 1127 | if index == egress_iface_count: |
| 1128 | break |
| 1129 | egress_iface_count += 1 |
| 1130 | egress_iface_num += 1 |
| 1131 | |
| 1132 | |
| 1133 | @classmethod |
| 1134 | def acl_hosts_remove(cls, egress_iface_count = 1, egress_iface_num = None): |
| 1135 | cls.setUpClass() |
| 1136 | if egress_iface_num is None: |
| 1137 | egress_iface_num = cls.egress_iface |
| 1138 | n = 0 |
| 1139 | for n in range(egress_iface_count): |
| 1140 | egress = cls.port_map[egress_iface_num] |
| 1141 | config_cmds_egress = ('ifconfig {} 0'.format(egress)) |
| 1142 | os.system(config_cmds_egress) |
| 1143 | egress_iface_num += 1 |
| 1144 | |
| 1145 | def acl_rule_traffic_send_recv(self, srcMac, dstMac, srcIp, dstIp, ingress =None, egress=None, ip_proto=None, dstPortNum = None, positive_test = True): |
| 1146 | self.setUpClass() |
| 1147 | if ingress is None: |
| 1148 | ingress = self.ingress_iface |
| 1149 | if egress is None: |
| 1150 | egress = self.egress_iface |
| 1151 | ingress = self.port_map[ingress] |
| 1152 | egress = self.port_map[egress] |
| 1153 | self.success = False if positive_test else True |
| 1154 | timeout = 10 if positive_test else 1 |
| 1155 | count = 2 if positive_test else 1 |
| 1156 | self.start_sending = True |
| 1157 | def recv_task(): |
| 1158 | def recv_cb(pkt): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1159 | log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1160 | self.success = True if positive_test else False |
| 1161 | sniff(count=count, timeout=timeout, |
| 1162 | lfilter = lambda p: IP in p and p[IP].dst == dstIp.split('/')[0] and p[IP].src == srcIp.split('/')[0], |
| 1163 | prn = recv_cb, iface = egress) |
| 1164 | self.start_sending = False |
| 1165 | |
| 1166 | t = threading.Thread(target = recv_task) |
| 1167 | t.start() |
| 1168 | L2 = Ether(src = srcMac, dst = dstMac) |
| 1169 | L3 = IP(src = srcIp.split('/')[0], dst = dstIp.split('/')[0]) |
| 1170 | pkt = L2/L3 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1171 | log_test.info('Sending a packet with dst ip %s, src ip %s , dst mac %s src mac %s on port %s to verify if flows are correct' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1172 | (dstIp.split('/')[0], srcIp.split('/')[0], dstMac, srcMac, ingress)) |
| 1173 | while self.start_sending is True: |
| 1174 | sendp(pkt, count=50, iface = ingress) |
| 1175 | t.join() |
| 1176 | assert_equal(self.success, True) |
| 1177 | |
| 1178 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1179 | def onos_load_config(cls, config,controller=None): |
| 1180 | status, code = OnosCtrl.config(config,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1181 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1182 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1183 | assert_equal(status, True) |
| 1184 | |
| 1185 | class cluster_dhcprelay(object): |
| 1186 | app = 'org.onosproject.dhcprelay' |
| 1187 | app_dhcp = 'org.onosproject.dhcp' |
| 1188 | relay_interfaces_last = () |
| 1189 | interface_to_mac_map = {} |
| 1190 | host_ip_map = {} |
| 1191 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 1192 | dhcp_data_dir = os.path.join(test_path, '..', 'setup') |
A.R Karthick | 5968e0d | 2017-05-16 14:50:46 -0700 | [diff] [blame] | 1193 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json')) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1194 | default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, } |
| 1195 | default_options = [ ('subnet-mask', '255.255.255.0'), |
| 1196 | ('broadcast-address', '192.168.1.255'), |
| 1197 | ('domain-name-servers', '192.168.1.1'), |
| 1198 | ('domain-name', '"mydomain.cord-tester"'), |
| 1199 | ] |
| 1200 | ##specify the IP for the dhcp interface matching the subnet and subnet config |
| 1201 | ##this is done for each interface dhcpd server would be listening on |
| 1202 | default_subnet_config = [ ('192.168.1.2', |
| 1203 | ''' |
| 1204 | subnet 192.168.1.0 netmask 255.255.255.0 { |
| 1205 | range 192.168.1.10 192.168.1.100; |
| 1206 | } |
| 1207 | '''), ] |
| 1208 | |
| 1209 | lock = threading.Condition() |
| 1210 | ip_count = 0 |
| 1211 | failure_count = 0 |
| 1212 | start_time = 0 |
| 1213 | diff = 0 |
| 1214 | |
| 1215 | transaction_count = 0 |
| 1216 | transactions = 0 |
| 1217 | running_time = 0 |
| 1218 | total_success = 0 |
| 1219 | total_failure = 0 |
| 1220 | onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0))) |
| 1221 | |
| 1222 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1223 | def setUpClass(cls,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1224 | log_test.info('controller ip in dhcp setup def is %s'%controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1225 | ''' Activate the dhcprelay app''' |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1226 | OnosCtrl(cls.app_dhcp,controller=controller).deactivate() |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1227 | time.sleep(3) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1228 | cls.onos_ctrl = OnosCtrl(cls.app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1229 | status, _ = cls.onos_ctrl.activate() |
| 1230 | assert_equal(status, True) |
| 1231 | time.sleep(3) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1232 | cls.dhcp_relay_setup(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1233 | ##start dhcpd initially with default config |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1234 | cls.dhcpd_start(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1235 | |
| 1236 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1237 | def tearDownClass(cls,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1238 | '''Deactivate the dhcp relay app''' |
| 1239 | try: |
| 1240 | os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir)) |
| 1241 | os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir)) |
| 1242 | except: pass |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1243 | OnosCtrl(cls.app,controller=controller).deactivate() |
| 1244 | #cls.onos_ctrl.deactivate() |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1245 | cls.dhcpd_stop() |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1246 | #cls.dhcp_relay_cleanup() |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1247 | |
| 1248 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1249 | def dhcp_relay_setup(cls,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1250 | did = OnosCtrl.get_device_id() |
| 1251 | cls.relay_device_id = did |
| 1252 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
| 1253 | cls.port_map, _ = cls.olt.olt_port_map() |
| 1254 | if cls.port_map: |
| 1255 | ##Per subscriber, we use 1 relay port |
| 1256 | try: |
| 1257 | relay_port = cls.port_map[cls.port_map['relay_ports'][0]] |
| 1258 | except: |
| 1259 | relay_port = cls.port_map['uplink'] |
| 1260 | cls.relay_interface_port = relay_port |
| 1261 | cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],) |
| 1262 | else: |
| 1263 | cls.relay_interface_port = 100 |
| 1264 | cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],) |
| 1265 | cls.relay_interfaces_last = cls.relay_interfaces |
| 1266 | if cls.port_map: |
| 1267 | ##generate a ip/mac client virtual interface config for onos |
| 1268 | interface_list = [] |
| 1269 | for port in cls.port_map['ports']: |
| 1270 | port_num = cls.port_map[port] |
| 1271 | if port_num == cls.port_map['uplink']: |
| 1272 | continue |
| 1273 | ip = cls.get_host_ip(port_num) |
| 1274 | mac = cls.get_mac(port) |
| 1275 | interface_list.append((port_num, ip, mac)) |
| 1276 | |
| 1277 | #configure dhcp server virtual interface on the same subnet as first client interface |
| 1278 | relay_ip = cls.get_host_ip(interface_list[0][0]) |
| 1279 | relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port]) |
| 1280 | interface_list.append((cls.relay_interface_port, relay_ip, relay_mac)) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1281 | cls.onos_interface_load(interface_list,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1282 | |
| 1283 | @classmethod |
| 1284 | def dhcp_relay_cleanup(cls): |
| 1285 | ##reset the ONOS port configuration back to default |
| 1286 | if cls.onos_restartable is True: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1287 | log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1288 | return cord_test_onos_restart(config = {}) |
| 1289 | |
| 1290 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1291 | def onos_load_config(cls, config,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1292 | log_test.info('loading onos config in controller %s'%controller) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1293 | status, code = OnosCtrl.config(config,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1294 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1295 | log_test.info('JSON request returned status %d' %code) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1296 | assert_equal(status, True) |
| 1297 | time.sleep(2) |
| 1298 | |
| 1299 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1300 | def onos_interface_load(cls, interface_list,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1301 | interface_dict = { 'ports': {} } |
| 1302 | for port_num, ip, mac in interface_list: |
| 1303 | port_map = interface_dict['ports'] |
| 1304 | port = '{}/{}'.format(cls.relay_device_id, port_num) |
| 1305 | port_map[port] = { 'interfaces': [] } |
| 1306 | interface_list = port_map[port]['interfaces'] |
| 1307 | interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ], |
| 1308 | 'mac' : mac, |
| 1309 | 'name': 'vir-{}'.format(port_num) |
| 1310 | } |
| 1311 | interface_list.append(interface_map) |
| 1312 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1313 | cls.onos_load_config(interface_dict,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1314 | |
| 1315 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1316 | def onos_dhcp_relay_load(cls, server_ip, server_mac,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1317 | relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port) |
| 1318 | dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay': |
| 1319 | {'dhcpserverConnectPoint':relay_device_map, |
| 1320 | 'serverip':server_ip, |
| 1321 | 'servermac':server_mac |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | } |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1326 | cls.onos_load_config(dhcp_dict,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1327 | |
| 1328 | @classmethod |
| 1329 | def get_host_ip(cls, port): |
| 1330 | if cls.host_ip_map.has_key(port): |
| 1331 | return cls.host_ip_map[port] |
| 1332 | cls.host_ip_map[port] = '192.168.1.{}'.format(port) |
| 1333 | return cls.host_ip_map[port] |
| 1334 | |
| 1335 | @classmethod |
| 1336 | def host_load(cls, iface): |
| 1337 | '''Have ONOS discover the hosts for dhcp-relay responses''' |
| 1338 | port = g_subscriber_port_map[iface] |
| 1339 | host = '173.17.1.{}'.format(port) |
| 1340 | cmds = ( 'ifconfig {} 0'.format(iface), |
| 1341 | 'ifconfig {0} {1}'.format(iface, host), |
| 1342 | 'arping -I {0} {1} -c 2'.format(iface, host), |
| 1343 | 'ifconfig {} 0'.format(iface), ) |
| 1344 | for c in cmds: |
| 1345 | os.system(c) |
| 1346 | @classmethod |
| 1347 | |
| 1348 | def dhcpd_conf_generate(cls, config = default_config, options = default_options, |
| 1349 | subnet = default_subnet_config): |
| 1350 | conf = '' |
| 1351 | for k, v in config.items(): |
| 1352 | conf += '{} {};\n'.format(k, v) |
| 1353 | |
| 1354 | opts = '' |
| 1355 | for k, v in options: |
| 1356 | opts += 'option {} {};\n'.format(k, v) |
| 1357 | |
| 1358 | subnet_config = '' |
| 1359 | for _, v in subnet: |
| 1360 | subnet_config += '{}\n'.format(v) |
| 1361 | |
| 1362 | return '{}{}{}'.format(conf, opts, subnet_config) |
| 1363 | |
| 1364 | @classmethod |
| 1365 | def dhcpd_start(cls, intf_list = None, |
| 1366 | config = default_config, options = default_options, |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1367 | subnet = default_subnet_config,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1368 | '''Start the dhcpd server by generating the conf file''' |
| 1369 | if intf_list is None: |
| 1370 | intf_list = cls.relay_interfaces |
| 1371 | ##stop dhcpd if already running |
| 1372 | cls.dhcpd_stop() |
| 1373 | dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options, |
| 1374 | subnet = subnet) |
| 1375 | ##first touch dhcpd.leases if it doesn't exist |
| 1376 | lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir) |
| 1377 | if os.access(lease_file, os.F_OK) is False: |
| 1378 | with open(lease_file, 'w') as fd: pass |
| 1379 | |
| 1380 | conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir) |
| 1381 | with open(conf_file, 'w') as fd: |
| 1382 | fd.write(dhcp_conf) |
| 1383 | |
| 1384 | #now configure the dhcpd interfaces for various subnets |
| 1385 | index = 0 |
| 1386 | intf_info = [] |
| 1387 | for ip,_ in subnet: |
| 1388 | intf = intf_list[index] |
| 1389 | mac = cls.get_mac(intf) |
| 1390 | intf_info.append((ip, mac)) |
| 1391 | index += 1 |
| 1392 | os.system('ifconfig {} {}'.format(intf, ip)) |
| 1393 | |
| 1394 | intf_str = ','.join(intf_list) |
| 1395 | dhcpd_cmd = '/usr/sbin/dhcpd -4 --no-pid -cf {0} -lf {1} {2}'.format(conf_file, lease_file, intf_str) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1396 | log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1397 | ret = os.system(dhcpd_cmd) |
| 1398 | assert_equal(ret, 0) |
| 1399 | time.sleep(3) |
| 1400 | cls.relay_interfaces_last = cls.relay_interfaces |
| 1401 | cls.relay_interfaces = intf_list |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1402 | cls.onos_dhcp_relay_load(*intf_info[0],controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1403 | |
| 1404 | @classmethod |
| 1405 | def dhcpd_stop(cls): |
| 1406 | os.system('pkill -9 dhcpd') |
| 1407 | for intf in cls.relay_interfaces: |
| 1408 | os.system('ifconfig {} 0'.format(intf)) |
| 1409 | |
| 1410 | cls.relay_interfaces = cls.relay_interfaces_last |
| 1411 | |
| 1412 | @classmethod |
| 1413 | def get_mac(cls, iface): |
| 1414 | if cls.interface_to_mac_map.has_key(iface): |
| 1415 | return cls.interface_to_mac_map[iface] |
| 1416 | mac = get_mac(iface, pad = 0) |
| 1417 | cls.interface_to_mac_map[iface] = mac |
| 1418 | return mac |
| 1419 | |
| 1420 | def stats(self,success_rate = False, only_discover = False, iface = 'veth0'): |
| 1421 | |
| 1422 | self.ip_count = 0 |
| 1423 | self.failure_count = 0 |
| 1424 | self.start_time = 0 |
| 1425 | self.diff = 0 |
| 1426 | self.transaction_count = 0 |
| 1427 | |
| 1428 | mac = self.get_mac(iface) |
| 1429 | self.host_load(iface) |
| 1430 | ##we use the defaults for this test that serves as an example for others |
| 1431 | ##You don't need to restart dhcpd server if retaining default config |
| 1432 | config = self.default_config |
| 1433 | options = self.default_options |
| 1434 | subnet = self.default_subnet_config |
| 1435 | dhcpd_interface_list = self.relay_interfaces |
| 1436 | self.dhcpd_start(intf_list = dhcpd_interface_list, |
| 1437 | config = config, |
| 1438 | options = options, |
| 1439 | subnet = subnet) |
| 1440 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
| 1441 | self.start_time = time.time() |
| 1442 | |
| 1443 | while self.diff <= 60: |
| 1444 | |
| 1445 | if only_discover: |
| 1446 | cip, sip, mac, _ = self.dhcp.only_discover(multiple = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1447 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1448 | (cip, sip, mac)) |
| 1449 | else: |
| 1450 | cip, sip = self.send_recv(mac, update_seed = True, validate = False) |
| 1451 | |
| 1452 | if cip: |
| 1453 | self.ip_count +=1 |
| 1454 | elif cip == None: |
| 1455 | self.failure_count += 1 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1456 | log_test.info('Failed to get ip') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1457 | if success_rate and self.ip_count > 0: |
| 1458 | break |
| 1459 | |
| 1460 | self.diff = round(time.time() - self.start_time, 0) |
| 1461 | |
| 1462 | self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2) |
| 1463 | self.transactions += (self.ip_count+self.failure_count) |
| 1464 | self.running_time += self.diff |
| 1465 | self.total_success += self.ip_count |
| 1466 | self.total_failure += self.failure_count |
| 1467 | |
| 1468 | def send_recv(self, mac, update_seed = False, validate = True): |
| 1469 | cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed) |
| 1470 | if validate: |
| 1471 | assert_not_equal(cip, None) |
| 1472 | assert_not_equal(sip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1473 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1474 | (cip, sip, self.dhcp.get_mac(cip)[0])) |
| 1475 | return cip,sip |
| 1476 | |
| 1477 | class Subscriber(Channels): |
| 1478 | PORT_TX_DEFAULT = 2 |
| 1479 | PORT_RX_DEFAULT = 1 |
| 1480 | INTF_TX_DEFAULT = 'veth2' |
| 1481 | INTF_RX_DEFAULT = 'veth0' |
| 1482 | STATS_RX = 0 |
| 1483 | STATS_TX = 1 |
| 1484 | STATS_JOIN = 2 |
| 1485 | STATS_LEAVE = 3 |
| 1486 | SUBSCRIBER_SERVICES = 'DHCP IGMP TLS' |
| 1487 | def __init__(self, name = 'sub', service = SUBSCRIBER_SERVICES, port_map = None, |
| 1488 | num = 1, channel_start = 0, |
| 1489 | tx_port = PORT_TX_DEFAULT, rx_port = PORT_RX_DEFAULT, |
| 1490 | iface = INTF_RX_DEFAULT, iface_mcast = INTF_TX_DEFAULT, |
| 1491 | mcast_cb = None, loginType = 'wireless'): |
| 1492 | self.tx_port = tx_port |
| 1493 | self.rx_port = rx_port |
| 1494 | self.port_map = port_map or g_subscriber_port_map |
| 1495 | try: |
| 1496 | self.tx_intf = self.port_map[tx_port] |
| 1497 | self.rx_intf = self.port_map[rx_port] |
| 1498 | except: |
| 1499 | self.tx_intf = self.port_map[self.PORT_TX_DEFAULT] |
| 1500 | self.rx_intf = self.port_map[self.PORT_RX_DEFAULT] |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1501 | log_test.info('Subscriber %s, rx interface %s, uplink interface %s' %(name, self.rx_intf, self.tx_intf)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1502 | Channels.__init__(self, num, channel_start = channel_start, |
| 1503 | iface = self.rx_intf, iface_mcast = self.tx_intf, mcast_cb = mcast_cb) |
| 1504 | self.name = name |
| 1505 | self.service = service |
| 1506 | self.service_map = {} |
| 1507 | services = self.service.strip().split(' ') |
| 1508 | for s in services: |
| 1509 | self.service_map[s] = True |
| 1510 | self.loginType = loginType |
| 1511 | ##start streaming channels |
| 1512 | self.join_map = {} |
| 1513 | ##accumulated join recv stats |
| 1514 | self.join_rx_stats = Stats() |
| 1515 | self.recv_timeout = False |
| 1516 | |
| 1517 | def has_service(self, service): |
| 1518 | if self.service_map.has_key(service): |
| 1519 | return self.service_map[service] |
| 1520 | if self.service_map.has_key(service.upper()): |
| 1521 | return self.service_map[service.upper()] |
| 1522 | return False |
| 1523 | |
| 1524 | def channel_join_update(self, chan, join_time): |
| 1525 | self.join_map[chan] = ( Stats(), Stats(), Stats(), Stats() ) |
| 1526 | self.channel_update(chan, self.STATS_JOIN, 1, t = join_time) |
| 1527 | def channel_join(self, chan = 0, delay = 2): |
| 1528 | '''Join a channel and create a send/recv stats map''' |
| 1529 | if self.join_map.has_key(chan): |
| 1530 | del self.join_map[chan] |
| 1531 | self.delay = delay |
| 1532 | chan, join_time = self.join(chan) |
| 1533 | self.channel_join_update(chan, join_time) |
| 1534 | return chan |
| 1535 | |
| 1536 | def channel_join_next(self, delay = 2): |
| 1537 | '''Joins the next channel leaving the last channel''' |
| 1538 | if self.last_chan: |
| 1539 | if self.join_map.has_key(self.last_chan): |
| 1540 | del self.join_map[self.last_chan] |
| 1541 | self.delay = delay |
| 1542 | chan, join_time = self.join_next() |
| 1543 | self.channel_join_update(chan, join_time) |
| 1544 | return chan |
| 1545 | |
| 1546 | def channel_jump(self, delay = 2): |
| 1547 | '''Jumps randomly to the next channel leaving the last channel''' |
| 1548 | if self.last_chan is not None: |
| 1549 | if self.join_map.has_key(self.last_chan): |
| 1550 | del self.join_map[self.last_chan] |
| 1551 | self.delay = delay |
| 1552 | chan, join_time = self.jump() |
| 1553 | self.channel_join_update(chan, join_time) |
| 1554 | return chan |
| 1555 | |
| 1556 | def channel_leave(self, chan = 0): |
| 1557 | if self.join_map.has_key(chan): |
| 1558 | del self.join_map[chan] |
| 1559 | self.leave(chan) |
| 1560 | |
| 1561 | def channel_update(self, chan, stats_type, packets, t=0): |
| 1562 | if type(chan) == type(0): |
| 1563 | chan_list = (chan,) |
| 1564 | else: |
| 1565 | chan_list = chan |
| 1566 | for c in chan_list: |
| 1567 | if self.join_map.has_key(c): |
| 1568 | self.join_map[c][stats_type].update(packets = packets, t = t) |
| 1569 | def channel_receive(self, chan, cb = None, count = 1, timeout = 5): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1570 | log_test.info('Subscriber %s on port %s receiving from group %s, channel %d' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1571 | (self.name, self.rx_intf, self.gaddr(chan), chan)) |
| 1572 | r = self.recv(chan, cb = cb, count = count, timeout = timeout) |
| 1573 | if len(r) == 0: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1574 | log_test.info('Subscriber %s on port %s timed out' %(self.name, self.rx_intf)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1575 | else: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1576 | log_test.info('Subscriber %s on port %s received %d packets' %(self.name, self.rx_intf, len(r))) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1577 | if self.recv_timeout: |
| 1578 | ##Negative test case is disabled for now |
| 1579 | assert_equal(len(r), 0) |
| 1580 | |
| 1581 | def recv_channel_cb(self, pkt): |
| 1582 | ##First verify that we have received the packet for the joined instance |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1583 | log_test.info('Packet received for group %s, subscriber %s, port %s' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1584 | (pkt[IP].dst, self.name, self.rx_intf)) |
| 1585 | if self.recv_timeout: |
| 1586 | return |
| 1587 | chan = self.caddr(pkt[IP].dst) |
| 1588 | assert_equal(chan in self.join_map.keys(), True) |
| 1589 | recv_time = monotonic.monotonic() * 1000000 |
| 1590 | join_time = self.join_map[chan][self.STATS_JOIN].start |
| 1591 | delta = recv_time - join_time |
| 1592 | self.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 1593 | self.channel_update(chan, self.STATS_RX, 1, t = delta) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1594 | log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1595 | |
| 1596 | class subscriber_pool: |
| 1597 | |
| 1598 | def __init__(self, subscriber, test_cbs): |
| 1599 | self.subscriber = subscriber |
| 1600 | self.test_cbs = test_cbs |
| 1601 | |
| 1602 | def pool_cb(self): |
| 1603 | for cb in self.test_cbs: |
| 1604 | if cb: |
| 1605 | self.test_status = cb(self.subscriber) |
| 1606 | if self.test_status is not True: |
| 1607 | ## This is chaning for other sub status has to check again |
| 1608 | self.test_status = True |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1609 | log_test.info('This service is failed and other services will not run for this subscriber') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1610 | break |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1611 | log_test.info('This Subscriber is tested for multiple service eligibility ') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1612 | self.test_status = True |
| 1613 | |
| 1614 | class cluster_subscriber(object): |
| 1615 | apps = ('org.opencord.aaa', 'org.onosproject.dhcp') |
| 1616 | olt_apps = () #'org.opencord.cordmcast') |
| 1617 | vtn_app = 'org.opencord.vtn' |
| 1618 | table_app = 'org.ciena.cordigmp' |
| 1619 | dhcp_server_config = { |
| 1620 | "ip": "10.1.11.50", |
| 1621 | "mac": "ca:fe:ca:fe:ca:fe", |
| 1622 | "subnet": "255.255.252.0", |
| 1623 | "broadcast": "10.1.11.255", |
| 1624 | "router": "10.1.8.1", |
| 1625 | "domain": "8.8.8.8", |
| 1626 | "ttl": "63", |
| 1627 | "delay": "2", |
| 1628 | "startip": "10.1.11.51", |
| 1629 | "endip": "10.1.11.100" |
| 1630 | } |
| 1631 | |
| 1632 | aaa_loaded = False |
| 1633 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 1634 | table_app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-multitable-2.0-SNAPSHOT.oar') |
| 1635 | app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-2.0-SNAPSHOT.oar') |
| 1636 | onos_config_path = os.path.join(test_path, '..', 'setup/onos-config') |
A.R Karthick | 5968e0d | 2017-05-16 14:50:46 -0700 | [diff] [blame] | 1637 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json')) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1638 | cpqd_path = os.path.join(test_path, '..', 'setup') |
| 1639 | ovs_path = cpqd_path |
| 1640 | test_services = ('IGMP', 'TRAFFIC') |
| 1641 | num_joins = 0 |
| 1642 | num_subscribers = 0 |
| 1643 | num_channels = 0 |
| 1644 | recv_timeout = False |
| 1645 | onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0))) |
| 1646 | |
| 1647 | INTF_TX_DEFAULT = 'veth2' |
| 1648 | INTF_RX_DEFAULT = 'veth0' |
| 1649 | SUBSCRIBER_TIMEOUT = 300 |
| 1650 | CLIENT_CERT = """-----BEGIN CERTIFICATE----- |
| 1651 | MIICuDCCAiGgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx |
| 1652 | CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h |
| 1653 | IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd |
| 1654 | RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwNjA2MjExMjI3WhcN |
| 1655 | MTcwNjAxMjExMjI3WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV |
| 1656 | BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI |
| 1657 | hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC |
| 1658 | gYEAwvXiSzb9LZ6c7uNziUfKvoHO7wu/uiFC5YUpXbmVGuGZizbVrny0xnR85Dfe |
| 1659 | +9R4diansfDhIhzOUl1XjN3YDeSS9OeF5YWNNE8XDhlz2d3rVzaN6hIhdotBkUjg |
| 1660 | rUewjTg5OFR31QEyG3v8xR3CLgiE9xQELjZbSA07pD79zuUCAwEAAaNPME0wEwYD |
| 1661 | VR0lBAwwCgYIKwYBBQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5l |
| 1662 | eGFtcGxlLmNvbS9leGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOBgQDAjkrY |
| 1663 | 6tDChmKbvr8w6Du/t8vHjTCoCIocHTN0qzWOeb1YsAGX89+TrWIuO1dFyYd+Z0KC |
| 1664 | PDKB5j/ygml9Na+AklSYAVJIjvlzXKZrOaPmhZqDufi+rXWti/utVqY4VMW2+HKC |
| 1665 | nXp37qWeuFLGyR1519Y1d6F/5XzqmvbwURuEug== |
| 1666 | -----END CERTIFICATE-----""" |
| 1667 | |
| 1668 | CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE----- |
| 1669 | MIIDvTCCAqWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx |
| 1670 | CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h |
| 1671 | IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd |
| 1672 | RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzExMTg1MzM2WhcN |
| 1673 | MTcwMzA2MTg1MzM2WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV |
| 1674 | BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI |
| 1675 | hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC |
| 1676 | AQoCggEBAOxemcBsPn9tZsCa5o2JA6sQDC7A6JgCNXXl2VFzKLNNvB9PS6D7ZBsQ |
| 1677 | 5An0zEDMNzi51q7lnrYg1XyiE4S8FzMGAFr94RlGMQJUbRD9V/oqszMX4k++iAOK |
| 1678 | tIA1gr3x7Zi+0tkjVSVzXTmgNnhChAamdMsjYUG5+CY9WAicXyy+VEV3zTphZZDR |
| 1679 | OjcjEp4m/TSXVPYPgYDXI40YZKX5BdvqykWtT/tIgZb48RS1NPyN/XkCYzl3bv21 |
| 1680 | qx7Mc0fcEbsJBIIRYTUkfxnsilcnmLxSYO+p+DZ9uBLBzcQt+4Rd5pLSfi21WM39 |
| 1681 | 2Z2oOi3vs/OYAPAqgmi2JWOv3mePa/8CAwEAAaNPME0wEwYDVR0lBAwwCgYIKwYB |
| 1682 | BQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5leGFtcGxlLmNvbS9l |
| 1683 | eGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOCAQEALBzMPDTIB6sLyPl0T6JV |
| 1684 | MjOkyldAVhXWiQsTjaGQGJUUe1cmUJyZbUZEc13MygXMPOM4x7z6VpXGuq1c/Vxn |
| 1685 | VzQ2fNnbJcIAHi/7G8W5/SQfPesIVDsHTEc4ZspPi5jlS/MVX3HOC+BDbOjdbwqP |
| 1686 | RX0JEr+uOyhjO+lRxG8ilMRACoBUbw1eDuVDoEBgErSUC44pq5ioDw2xelc+Y6hQ |
| 1687 | dmtYwfY0DbvwxHtA495frLyPcastDiT/zre7NL51MyUDPjjYjghNQEwvu66IKbQ3 |
| 1688 | T1tJBrgI7/WI+dqhKBFolKGKTDWIHsZXQvZ1snGu/FRYzg1l+R/jT8cRB9BDwhUt |
| 1689 | yg== |
| 1690 | -----END CERTIFICATE-----''' |
| 1691 | @classmethod |
| 1692 | def load_device_id(cls): |
| 1693 | '''Configure the device id''' |
| 1694 | did = OnosCtrl.get_device_id() |
| 1695 | #Set the default config |
| 1696 | cls.device_id = did |
| 1697 | cls.device_dict = { "devices" : { |
| 1698 | "{}".format(did) : { |
| 1699 | "basic" : { |
| 1700 | "driver" : "pmc-olt" |
| 1701 | } |
| 1702 | } |
| 1703 | }, |
| 1704 | } |
| 1705 | return did |
| 1706 | |
| 1707 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1708 | def setUpClass(cls,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1709 | log_test.info('controller ip in cluster.py setupclass is %s'%controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1710 | '''Load the OLT config and activate relevant apps''' |
| 1711 | did = cls.load_device_id() |
| 1712 | network_cfg = { "devices" : { |
| 1713 | "{}".format(did) : { |
| 1714 | "basic" : { |
| 1715 | "driver" : "pmc-olt" |
| 1716 | } |
| 1717 | } |
| 1718 | }, |
| 1719 | } |
| 1720 | ## Restart ONOS with cpqd driver config for OVS |
| 1721 | print('onos restart in setUpClass') |
| 1722 | cls.start_onos(network_cfg = network_cfg) |
| 1723 | #status, code = OnosCtrl.config(network_cfg) |
| 1724 | #if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1725 | # log_test.info('JSON config request for app %s returned status %d' %(app, code)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1726 | #assert_equal(status, True) |
| 1727 | #time.sleep(2) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1728 | cls.install_app_table(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1729 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
A R Karthick | 0f6b684 | 2016-12-06 17:17:44 -0800 | [diff] [blame] | 1730 | OnosCtrl.cord_olt_config(cls.olt, controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1731 | cls.port_map, cls.port_list = cls.olt.olt_port_map() |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1732 | cls.activate_apps(cls.apps + cls.olt_apps,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1733 | |
| 1734 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1735 | def tearDownClass(cls,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1736 | '''Deactivate the olt apps and restart OVS back''' |
| 1737 | apps = cls.olt_apps + ( cls.table_app,) |
| 1738 | for app in apps: |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1739 | onos_ctrl = OnosCtrl(app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1740 | onos_ctrl.deactivate() |
| 1741 | cls.uninstall_app_table() |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1742 | cls.start_onos(network_cfg = {}) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1743 | |
| 1744 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1745 | def activate_apps(cls, apps,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1746 | for app in apps: |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1747 | onos_ctrl = OnosCtrl(app,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1748 | status, _ = onos_ctrl.activate() |
| 1749 | assert_equal(status, True) |
| 1750 | time.sleep(2) |
| 1751 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1752 | def install_app_table(cls,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1753 | ##Uninstall the existing app if any |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1754 | OnosCtrl.uninstall_app(cls.table_app,onos_ip=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1755 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1756 | log_test.info('Installing the multi table app %s for subscriber test' %(cls.table_app_file)) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1757 | OnosCtrl.install_app(cls.table_app_file,onos_ip=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1758 | time.sleep(3) |
| 1759 | #onos_ctrl = OnosCtrl(cls.vtn_app) |
| 1760 | #onos_ctrl.deactivate() |
| 1761 | |
| 1762 | @classmethod |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1763 | def uninstall_app_table(cls,controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1764 | ##Uninstall the table app on class exit |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1765 | OnosCtrl.uninstall_app(cls.table_app,onos_ip=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1766 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1767 | log_test.info('Installing back the cord igmp app %s for subscriber test on exit' %(cls.app_file)) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1768 | OnosCtrl.install_app(cls.app_file,onos_ip=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1769 | #onos_ctrl = OnosCtrl(cls.vtn_app) |
| 1770 | #onos_ctrl.activate() |
| 1771 | |
| 1772 | @classmethod |
| 1773 | def start_onos(cls, network_cfg = None): |
| 1774 | if cls.onos_restartable is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1775 | log_test.info('ONOS restart is disabled. Skipping ONOS restart') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1776 | return |
| 1777 | if network_cfg is None: |
| 1778 | network_cfg = cls.device_dict |
| 1779 | |
| 1780 | if type(network_cfg) is tuple: |
| 1781 | res = [] |
| 1782 | for v in network_cfg: |
| 1783 | res += v.items() |
| 1784 | config = dict(res) |
| 1785 | else: |
| 1786 | config = network_cfg |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1787 | log_test.info('Restarting ONOS with new network configuration') |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1788 | #return cord_test_onos_restart(config = config) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1789 | |
| 1790 | @classmethod |
| 1791 | def remove_onos_config(cls): |
| 1792 | try: |
| 1793 | os.unlink('{}/network-cfg.json'.format(cls.onos_config_path)) |
| 1794 | except: pass |
| 1795 | @classmethod |
| 1796 | def start_cpqd(cls, mac = '00:11:22:33:44:55'): |
| 1797 | dpid = mac.replace(':', '') |
| 1798 | cpqd_file = os.sep.join( (cls.cpqd_path, 'cpqd.sh') ) |
| 1799 | cpqd_cmd = '{} {}'.format(cpqd_file, dpid) |
| 1800 | ret = os.system(cpqd_cmd) |
| 1801 | assert_equal(ret, 0) |
| 1802 | time.sleep(10) |
| 1803 | device_id = 'of:{}{}'.format('0'*4, dpid) |
| 1804 | return device_id |
| 1805 | |
| 1806 | @classmethod |
| 1807 | def start_ovs(cls): |
| 1808 | ovs_file = os.sep.join( (cls.ovs_path, 'of-bridge.sh') ) |
| 1809 | ret = os.system(ovs_file) |
| 1810 | assert_equal(ret, 0) |
| 1811 | time.sleep(30) |
| 1812 | |
| 1813 | @classmethod |
| 1814 | def ovs_cleanup(cls): |
| 1815 | ##For every test case, delete all the OVS groups |
| 1816 | cmd = 'ovs-ofctl del-groups br-int -OOpenFlow11 >/dev/null 2>&1' |
| 1817 | cord_test_shell(cmd) |
| 1818 | ##Since olt config is used for this test, we just fire a careless local cmd as well |
| 1819 | try: |
| 1820 | os.system(cmd) |
| 1821 | except: pass |
| 1822 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1823 | def onos_aaa_load(self,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1824 | log_test.info('controller ip in cluster.py onos_aaa_load is %s'%controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1825 | if self.aaa_loaded: |
| 1826 | return |
A.R Karthick | a6c88fd | 2017-03-13 09:29:41 -0700 | [diff] [blame] | 1827 | aaa_dict = {'apps' : { 'org.opencord.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password', |
| 1828 | 'radiusIp': '172.17.0.2' } } } } |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1829 | radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2' |
A.R Karthick | a6c88fd | 2017-03-13 09:29:41 -0700 | [diff] [blame] | 1830 | aaa_dict['apps']['org.opencord.aaa']['AAA']['radiusIp'] = radius_ip |
| 1831 | self.onos_load_config('org.opencord.aaa', aaa_dict,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1832 | self.aaa_loaded = True |
| 1833 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1834 | def onos_dhcp_table_load(self, config = None,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1835 | log_test.info('controller ip in cluster.py onos_dhcp_table_load is %s'%controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1836 | dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } } |
| 1837 | dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp'] |
| 1838 | if config: |
| 1839 | for k in config.keys(): |
| 1840 | if dhcp_config.has_key(k): |
| 1841 | dhcp_config[k] = config[k] |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1842 | self.onos_load_config('org.onosproject.dhcp', dhcp_dict,controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1843 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1844 | def onos_load_config(self, app, config,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1845 | log_test.info('controller ip in cluster.py onos_load_config is %s'%controller) |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1846 | status, code = OnosCtrl(controller=controller).config(config) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1847 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1848 | log_test.info('JSON config request for app %s returned status %d' %(app, code)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1849 | assert_equal(status, True) |
| 1850 | time.sleep(2) |
| 1851 | def dhcp_sndrcv(self, dhcp, update_seed = False): |
| 1852 | cip, sip = dhcp.discover(update_seed = update_seed) |
| 1853 | assert_not_equal(cip, None) |
| 1854 | assert_not_equal(sip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1855 | log_test.info('Got dhcp client IP %s from server %s for mac %s' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1856 | (cip, sip, dhcp.get_mac(cip)[0])) |
| 1857 | return cip,sip |
| 1858 | |
| 1859 | def dhcp_request(self, subscriber, seed_ip = '10.10.10.1', update_seed = False): |
| 1860 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.200', |
| 1861 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 1862 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 1863 | self.onos_dhcp_table_load(config) |
| 1864 | dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface) |
| 1865 | cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed) |
| 1866 | return cip, sip |
| 1867 | |
| 1868 | def recv_channel_cb(self, pkt): |
| 1869 | ##First verify that we have received the packet for the joined instance |
| 1870 | chan = self.subscriber.caddr(pkt[IP].dst) |
| 1871 | assert_equal(chan in self.subscriber.join_map.keys(), True) |
| 1872 | recv_time = monotonic.monotonic() * 1000000 |
| 1873 | join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start |
| 1874 | delta = recv_time - join_time |
| 1875 | self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True) |
| 1876 | self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1877 | log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1878 | self.test_status = True |
| 1879 | |
| 1880 | def traffic_verify(self, subscriber): |
| 1881 | if subscriber.has_service('TRAFFIC'): |
| 1882 | url = 'http://www.google.com' |
| 1883 | resp = requests.get(url) |
| 1884 | self.test_status = resp.ok |
| 1885 | if resp.ok == False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1886 | log_test.info('Subscriber %s failed get from url %s with status code %d' |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1887 | %(subscriber.name, url, resp.status_code)) |
| 1888 | else: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1889 | log_test.info('GET request from %s succeeded for subscriber %s' |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1890 | %(url, subscriber.name)) |
| 1891 | return self.test_status |
| 1892 | |
| 1893 | def tls_verify(self, subscriber): |
| 1894 | if subscriber.has_service('TLS'): |
| 1895 | time.sleep(2) |
| 1896 | tls = TLSAuthTest(intf = subscriber.rx_intf) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1897 | log_test.info('Running subscriber %s tls auth test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1898 | tls.runTest() |
| 1899 | self.test_status = True |
| 1900 | return self.test_status |
| 1901 | else: |
| 1902 | self.test_status = True |
| 1903 | return self.test_status |
| 1904 | def dhcp_verify(self, subscriber): |
| 1905 | if subscriber.has_service('DHCP'): |
| 1906 | cip, sip = self.dhcp_request(subscriber, update_seed = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1907 | log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1908 | subscriber.src_list = [cip] |
| 1909 | self.test_status = True |
| 1910 | return self.test_status |
| 1911 | else: |
| 1912 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 1913 | self.test_status = True |
| 1914 | return self.test_status |
| 1915 | |
| 1916 | def dhcp_jump_verify(self, subscriber): |
| 1917 | if subscriber.has_service('DHCP'): |
| 1918 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1') |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1919 | log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1920 | subscriber.src_list = [cip] |
| 1921 | self.test_status = True |
| 1922 | return self.test_status |
| 1923 | else: |
| 1924 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 1925 | self.test_status = True |
| 1926 | return self.test_status |
| 1927 | |
| 1928 | def dhcp_next_verify(self, subscriber): |
| 1929 | if subscriber.has_service('DHCP'): |
| 1930 | cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.150.1') |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1931 | log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1932 | subscriber.src_list = [cip] |
| 1933 | self.test_status = True |
| 1934 | return self.test_status |
| 1935 | else: |
| 1936 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 1937 | self.test_status = True |
| 1938 | return self.test_status |
| 1939 | def igmp_verify(self, subscriber): |
| 1940 | chan = 0 |
| 1941 | if subscriber.has_service('IGMP'): |
| 1942 | ##We wait for all the subscribers to join before triggering leaves |
| 1943 | if subscriber.rx_port > 1: |
| 1944 | time.sleep(5) |
| 1945 | subscriber.channel_join(chan, delay = 0) |
| 1946 | self.num_joins += 1 |
| 1947 | while self.num_joins < self.num_subscribers: |
| 1948 | time.sleep(5) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1949 | log_test.info('All subscribers have joined the channel') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1950 | for i in range(10): |
| 1951 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1952 | log_test.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1953 | subscriber.channel_leave(chan) |
| 1954 | time.sleep(5) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1955 | log_test.info('Interface %s Join RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name,subscriber.join_rx_stats)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1956 | #Should not receive packets for this subscriber |
| 1957 | self.recv_timeout = True |
| 1958 | subscriber.recv_timeout = True |
| 1959 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10) |
| 1960 | subscriber.recv_timeout = False |
| 1961 | self.recv_timeout = False |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1962 | log_test.info('Joining channel %d for subscriber %s' %(chan, subscriber.name)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1963 | subscriber.channel_join(chan, delay = 0) |
| 1964 | self.test_status = True |
| 1965 | return self.test_status |
| 1966 | |
| 1967 | def igmp_jump_verify(self, subscriber): |
| 1968 | if subscriber.has_service('IGMP'): |
| 1969 | for i in xrange(subscriber.num): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1970 | log_test.info('Subscriber %s jumping channel' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1971 | chan = subscriber.channel_jump(delay=0) |
| 1972 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1973 | log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1974 | time.sleep(3) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1975 | log_test.info('Interface %s Jump RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1976 | self.test_status = True |
| 1977 | return self.test_status |
| 1978 | def igmp_next_verify(self, subscriber): |
| 1979 | if subscriber.has_service('IGMP'): |
| 1980 | for i in xrange(subscriber.num): |
| 1981 | if i: |
| 1982 | chan = subscriber.channel_join_next(delay=0) |
| 1983 | else: |
| 1984 | chan = subscriber.channel_join(i, delay=0) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1985 | log_test.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1986 | subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1987 | log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1988 | time.sleep(3) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 1989 | log_test.info('Interface %s Join Next RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1990 | self.test_status = True |
| 1991 | return self.test_status |
| 1992 | |
| 1993 | def generate_port_list(self, subscribers, channels): |
| 1994 | return self.port_list[:subscribers] |
| 1995 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 1996 | def subscriber_load(self, create = True, num = 10, num_channels = 1, channel_start = 0, port_list = [],controller=None): |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 1997 | '''Load the subscriber from the database''' |
| 1998 | self.subscriber_db = SubscriberDB(create = create, services = self.test_services) |
| 1999 | if create is True: |
| 2000 | self.subscriber_db.generate(num) |
| 2001 | self.subscriber_info = self.subscriber_db.read(num) |
| 2002 | self.subscriber_list = [] |
| 2003 | if not port_list: |
| 2004 | port_list = self.generate_port_list(num, num_channels) |
| 2005 | |
| 2006 | index = 0 |
| 2007 | for info in self.subscriber_info: |
| 2008 | self.subscriber_list.append(Subscriber(name=info['Name'], |
| 2009 | service=info['Service'], |
| 2010 | port_map = self.port_map, |
| 2011 | num=num_channels, |
| 2012 | channel_start = channel_start, |
| 2013 | tx_port = port_list[index][0], |
| 2014 | rx_port = port_list[index][1])) |
| 2015 | if num_channels > 1: |
| 2016 | channel_start += num_channels |
| 2017 | index += 1 |
| 2018 | |
| 2019 | #load the ssm list for all subscriber channels |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 2020 | igmpChannel = IgmpChannel(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2021 | ssm_groups = map(lambda sub: sub.channels, self.subscriber_list) |
| 2022 | ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups) |
| 2023 | igmpChannel.igmp_load_ssm_config(ssm_list) |
| 2024 | def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1, |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 2025 | channel_start = 0, cbs = None, port_list = [], negative_subscriber_auth = None,controller=None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2026 | log_test.info('controller ip in cluster.py subscriber_join_verify is %s'%controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2027 | self.test_status = False |
| 2028 | self.ovs_cleanup() |
| 2029 | subscribers_count = num_subscribers |
| 2030 | sub_loop_count = num_subscribers |
| 2031 | self.subscriber_load(create = True, num = num_subscribers, |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 2032 | num_channels = num_channels, channel_start = channel_start, port_list = port_list,controller=controller) |
| 2033 | self.onos_aaa_load(controller=controller) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2034 | self.thread_pool = ThreadPool(min(100, subscribers_count), queue_size=1, wait_timeout=1) |
| 2035 | |
| 2036 | chan_leave = False #for single channel, multiple subscribers |
| 2037 | if None in (cbs, negative_subscriber_auth): |
| 2038 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify) |
| 2039 | chan_leave = True |
| 2040 | cbs_negative = cbs |
| 2041 | for subscriber in self.subscriber_list: |
| 2042 | subscriber.start() |
| 2043 | if negative_subscriber_auth is 'half' and sub_loop_count%2 is not 0: |
| 2044 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify) |
| 2045 | elif negative_subscriber_auth is 'onethird' and sub_loop_count%3 is not 0: |
| 2046 | cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify) |
| 2047 | else: |
| 2048 | cbs = cbs_negative |
| 2049 | sub_loop_count = sub_loop_count - 1 |
| 2050 | pool_object = subscriber_pool(subscriber, cbs) |
| 2051 | self.thread_pool.addTask(pool_object.pool_cb) |
| 2052 | self.thread_pool.cleanUpThreads() |
| 2053 | for subscriber in self.subscriber_list: |
| 2054 | subscriber.stop() |
| 2055 | if chan_leave is True: |
| 2056 | subscriber.channel_leave(0) |
| 2057 | subscribers_count = 0 |
| 2058 | return self.test_status |
| 2059 | def tls_invalid_cert(self, subscriber): |
| 2060 | if subscriber.has_service('TLS'): |
| 2061 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2062 | log_test.info('Running subscriber %s tls auth test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2063 | tls = TLSAuthTest(client_cert = self.CLIENT_CERT_INVALID) |
| 2064 | tls.runTest() |
| 2065 | if tls.failTest == True: |
| 2066 | self.test_status = False |
| 2067 | return self.test_status |
| 2068 | else: |
| 2069 | self.test_status = True |
| 2070 | return self.test_status |
| 2071 | |
| 2072 | def tls_no_cert(self, subscriber): |
| 2073 | if subscriber.has_service('TLS'): |
| 2074 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2075 | log_test.info('Running subscriber %s tls auth test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2076 | tls = TLSAuthTest(client_cert = '') |
| 2077 | tls.runTest() |
| 2078 | if tls.failTest == True: |
| 2079 | self.test_status = False |
| 2080 | return self.test_status |
| 2081 | else: |
| 2082 | self.test_status = True |
| 2083 | return self.test_status |
| 2084 | |
| 2085 | def tls_self_signed_cert(self, subscriber): |
| 2086 | if subscriber.has_service('TLS'): |
| 2087 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2088 | log_test.info('Running subscriber %s tls auth test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2089 | tls = TLSAuthTest(client_cert = self.CLIENT_CERT) |
| 2090 | tls.runTest() |
| 2091 | if tls.failTest == False: |
| 2092 | self.test_status = True |
| 2093 | return self.test_status |
| 2094 | else: |
| 2095 | self.test_status = True |
| 2096 | return self.test_status |
| 2097 | |
| 2098 | def tls_non_ca_authrized_cert(self, subscriber): |
| 2099 | if subscriber.has_service('TLS'): |
| 2100 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2101 | log_test.info('Running subscriber %s tls auth test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2102 | tls = TLSAuthTest(client_cert = self.CLIENT_CERT_NON_CA_AUTHORIZED) |
| 2103 | tls.runTest() |
| 2104 | if tls.failTest == False: |
| 2105 | self.test_status = True |
| 2106 | return self.test_status |
| 2107 | else: |
| 2108 | self.test_status = True |
| 2109 | return self.test_status |
| 2110 | def tls_Nsubscribers_use_same_valid_cert(self, subscriber): |
| 2111 | if subscriber.has_service('TLS'): |
| 2112 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2113 | log_test.info('Running subscriber %s tls auth test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2114 | num_users = 3 |
| 2115 | for i in xrange(num_users): |
| 2116 | tls = TLSAuthTest(intf = 'veth{}'.format(i*2)) |
| 2117 | tls.runTest() |
| 2118 | if tls.failTest == False: |
| 2119 | self.test_status = True |
| 2120 | return self.test_status |
| 2121 | else: |
| 2122 | self.test_status = True |
| 2123 | return self.test_status |
| 2124 | |
| 2125 | def dhcp_discover_scenario(self, subscriber): |
| 2126 | if subscriber.has_service('DHCP'): |
| 2127 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2128 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2129 | t1 = self.subscriber_dhcp_1release() |
| 2130 | self.test_status = True |
| 2131 | return self.test_status |
| 2132 | else: |
| 2133 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2134 | self.test_status = True |
| 2135 | return self.test_status |
| 2136 | |
| 2137 | def subscriber_dhcp_1release(self, iface = INTF_RX_DEFAULT): |
| 2138 | config = {'startip':'10.10.100.20', 'endip':'10.10.100.21', |
| 2139 | 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe", |
| 2140 | 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'} |
| 2141 | self.onos_dhcp_table_load(config) |
| 2142 | self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface) |
| 2143 | cip, sip = self.send_recv() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2144 | log_test.info('Releasing ip %s to server %s' %(cip, sip)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2145 | assert_equal(self.dhcp.release(cip), True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2146 | log_test.info('Triggering DHCP discover again after release') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2147 | cip2, sip2 = self.send_recv(update_seed = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2148 | log_test.info('Verifying released IP was given back on rediscover') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2149 | assert_equal(cip, cip2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2150 | log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2)) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2151 | assert_equal(self.dhcp.release(cip2), True) |
| 2152 | def dhcp_client_reboot_scenario(self, subscriber): |
| 2153 | if subscriber.has_service('DHCP'): |
| 2154 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2155 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2156 | tl = self.subscriber_dhcp_client_request_after_reboot() |
| 2157 | self.test_status = True |
| 2158 | return self.test_status |
| 2159 | else: |
| 2160 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2161 | self.test_status = True |
| 2162 | return self.test_status |
| 2163 | |
| 2164 | def subscriber_dhcp_client_request_after_reboot(self, iface = INTF_RX_DEFAULT): |
| 2165 | #''' Client sends DHCP Request after reboot.''' |
| 2166 | |
| 2167 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2168 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2169 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2170 | self.onos_dhcp_table_load(config) |
| 2171 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 2172 | cip, sip, mac, lval = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2173 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2174 | (cip, sip, mac) ) |
| 2175 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2176 | log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2177 | |
| 2178 | if (cip == None and mac != None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2179 | log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2180 | assert_not_equal(cip, None) |
| 2181 | |
| 2182 | else: |
| 2183 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 2184 | if new_cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2185 | log_test.info("Got DHCP server NAK.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2186 | os.system('ifconfig '+iface+' down') |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2187 | log_test.info('Client goes down.') |
| 2188 | log_test.info('Delay for 5 seconds.') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2189 | |
| 2190 | time.sleep(5) |
| 2191 | |
| 2192 | os.system('ifconfig '+iface+' up') |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2193 | log_test.info('Client is up now.') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2194 | |
| 2195 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 2196 | if new_cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2197 | log_test.info("Got DHCP server NAK.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2198 | assert_not_equal(new_cip, None) |
| 2199 | elif new_cip != None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2200 | log_test.info("Got DHCP ACK.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2201 | def dhcp_client_renew_scenario(self, subscriber): |
| 2202 | if subscriber.has_service('DHCP'): |
| 2203 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2204 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2205 | tl = self.subscriber_dhcp_client_renew_time() |
| 2206 | self.test_status = True |
| 2207 | return self.test_status |
| 2208 | else: |
| 2209 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2210 | self.test_status = True |
| 2211 | return self.test_status |
| 2212 | |
| 2213 | def subscriber_dhcp_client_renew_time(self, iface = INTF_RX_DEFAULT): |
| 2214 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2215 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2216 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2217 | self.onos_dhcp_table_load(config) |
| 2218 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 2219 | cip, sip, mac , lval = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2220 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2221 | (cip, sip, mac) ) |
| 2222 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2223 | log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2224 | if (cip == None and mac != None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2225 | log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2226 | assert_not_equal(cip, None) |
| 2227 | elif cip and sip and mac: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2228 | log_test.info("Triggering DHCP Request.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2229 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True) |
| 2230 | if new_cip and new_sip and lval: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2231 | log_test.info("Client 's Renewal time is :%s",lval) |
| 2232 | log_test.info("Generating delay till renewal time.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2233 | time.sleep(lval) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2234 | log_test.info("Client Sending Unicast DHCP request.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2235 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True) |
| 2236 | if latest_cip and latest_sip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2237 | log_test.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2238 | (latest_cip, mac, latest_sip) ) |
| 2239 | |
| 2240 | elif latest_cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2241 | log_test.info("Got DHCP NAK. Lease not renewed.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2242 | elif new_cip == None or new_sip == None or lval == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2243 | log_test.info("Got DHCP NAK.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2244 | def dhcp_server_reboot_scenario(self, subscriber): |
| 2245 | if subscriber.has_service('DHCP'): |
| 2246 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2247 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2248 | tl = self.subscriber_dhcp_server_after_reboot() |
| 2249 | self.test_status = True |
| 2250 | return self.test_status |
| 2251 | else: |
| 2252 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2253 | self.test_status = True |
| 2254 | return self.test_status |
| 2255 | def subscriber_dhcp_server_after_reboot(self, iface = INTF_RX_DEFAULT): |
| 2256 | ''' DHCP server goes down.''' |
| 2257 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2258 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2259 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2260 | self.onos_dhcp_table_load(config) |
| 2261 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 2262 | cip, sip, mac, lval = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2263 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2264 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2265 | log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2266 | if (cip == None and mac != None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2267 | log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2268 | assert_not_equal(cip, None) |
| 2269 | else: |
| 2270 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 2271 | if new_cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2272 | log_test.info("Got DHCP server NAK.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2273 | assert_not_equal(new_cip, None) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2274 | log_test.info('Getting DHCP server Down.') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2275 | onos_ctrl = OnosCtrl(self.dhcp_app) |
| 2276 | onos_ctrl.deactivate() |
| 2277 | for i in range(0,4): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2278 | log_test.info("Sending DHCP Request.") |
| 2279 | log_test.info('') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2280 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 2281 | if new_cip == None and new_sip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2282 | log_test.info('') |
| 2283 | log_test.info("DHCP Request timed out.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2284 | elif new_cip and new_sip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2285 | log_test.info("Got Reply from DHCP server.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2286 | assert_equal(new_cip,None) #Neagtive Test Case |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2287 | log_test.info('Getting DHCP server Up.') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2288 | # self.activate_apps(self.dhcp_app) |
| 2289 | onos_ctrl = OnosCtrl(self.dhcp_app) |
| 2290 | status, _ = onos_ctrl.activate() |
| 2291 | assert_equal(status, True) |
| 2292 | time.sleep(3) |
| 2293 | for i in range(0,4): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2294 | log_test.info("Sending DHCP Request after DHCP server is up.") |
| 2295 | log_test.info('') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2296 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 2297 | if new_cip == None and new_sip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2298 | log_test.info('') |
| 2299 | log_test.info("DHCP Request timed out.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2300 | elif new_cip and new_sip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2301 | log_test.info("Got Reply from DHCP server.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2302 | assert_equal(new_cip,None) #Neagtive Test Case |
| 2303 | def dhcp_client_rebind_scenario(self, subscriber): |
| 2304 | if subscriber.has_service('DHCP'): |
| 2305 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2306 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2307 | tl = self.subscriber_dhcp_client_rebind_time() |
| 2308 | self.test_status = True |
| 2309 | return self.test_status |
| 2310 | else: |
| 2311 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2312 | self.test_status = True |
| 2313 | return self.test_status |
| 2314 | |
| 2315 | def subscriber_dhcp_client_rebind_time(self, iface = INTF_RX_DEFAULT): |
| 2316 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2317 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2318 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2319 | self.onos_dhcp_table_load(config) |
| 2320 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 2321 | cip, sip, mac, lval = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2322 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2323 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2324 | log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2325 | if (cip == None and mac != None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2326 | log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2327 | assert_not_equal(cip, None) |
| 2328 | elif cip and sip and mac: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2329 | log_test.info("Triggering DHCP Request.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2330 | new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True) |
| 2331 | if new_cip and new_sip and lval: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2332 | log_test.info("Client 's Rebind time is :%s",lval) |
| 2333 | log_test.info("Generating delay till rebind time.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2334 | time.sleep(lval) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2335 | log_test.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2336 | self.dhcp.after_T2 = True |
| 2337 | for i in range(0,4): |
| 2338 | latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac) |
| 2339 | if latest_cip and latest_sip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2340 | log_test.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2341 | (latest_cip, mac, latest_sip) ) |
| 2342 | break |
| 2343 | elif latest_cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2344 | log_test.info("Got DHCP NAK. Lease not renewed.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2345 | assert_not_equal(latest_cip, None) |
| 2346 | elif new_cip == None or new_sip == None or lval == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2347 | log_test.info("Got DHCP NAK.Lease not Renewed.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2348 | def dhcp_starvation_scenario(self, subscriber): |
| 2349 | if subscriber.has_service('DHCP'): |
| 2350 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2351 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2352 | tl = self.subscriber_dhcp_starvation() |
| 2353 | self.test_status = True |
| 2354 | return self.test_status |
| 2355 | else: |
| 2356 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2357 | self.test_status = True |
| 2358 | return self.test_status |
| 2359 | |
| 2360 | def subscriber_dhcp_starvation(self, iface = INTF_RX_DEFAULT): |
| 2361 | '''DHCP starve''' |
| 2362 | config = {'startip':'182.17.0.20', 'endip':'182.17.0.69', |
| 2363 | 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe", |
| 2364 | 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'} |
| 2365 | self.onos_dhcp_table_load(config) |
| 2366 | self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2367 | log_test.info('Verifying 1 ') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2368 | for x in xrange(50): |
| 2369 | mac = RandMAC()._fix() |
| 2370 | self.send_recv(mac = mac) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2371 | log_test.info('Verifying 2 ') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2372 | cip, sip = self.send_recv(update_seed = True, validate = False) |
| 2373 | assert_equal(cip, None) |
| 2374 | assert_equal(sip, None) |
| 2375 | |
| 2376 | def dhcp_same_client_multi_discovers_scenario(self, subscriber): |
| 2377 | if subscriber.has_service('DHCP'): |
| 2378 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2379 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2380 | tl = self.subscriber_dhcp_same_client_multiple_discover() |
| 2381 | self.test_status = True |
| 2382 | return self.test_status |
| 2383 | else: |
| 2384 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2385 | self.test_status = True |
| 2386 | return self.test_status |
| 2387 | def subscriber_dhcp_same_client_multiple_discover(self, iface = INTF_RX_DEFAULT): |
| 2388 | ''' DHCP Client sending multiple discover . ''' |
| 2389 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 2390 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2391 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 2392 | self.onos_dhcp_table_load(config) |
| 2393 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
| 2394 | cip, sip, mac, lval = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2395 | log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2396 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2397 | log_test.info('Triggering DHCP discover again.') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2398 | new_cip, new_sip, new_mac , lval = self.dhcp.only_discover() |
| 2399 | if cip == new_cip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2400 | log_test.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. ' |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2401 | % (new_cip, new_sip, new_mac) ) |
| 2402 | elif cip != new_cip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2403 | log_test.info('Ip after 1st discover %s' %cip) |
| 2404 | log_test.info('Map after 2nd discover %s' %new_cip) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2405 | assert_equal(cip, new_cip) |
| 2406 | |
| 2407 | def dhcp_same_client_multi_request_scenario(self, subscriber): |
| 2408 | if subscriber.has_service('DHCP'): |
| 2409 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2410 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2411 | tl = self.subscriber_dhcp_same_client_multiple_request() |
| 2412 | self.test_status = True |
| 2413 | return self.test_status |
| 2414 | else: |
| 2415 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2416 | self.test_status = True |
| 2417 | return self.test_status |
| 2418 | def subscriber_dhcp_same_client_multiple_request(self, iface = INTF_RX_DEFAULT): |
| 2419 | ''' DHCP Client sending multiple repeat DHCP requests. ''' |
| 2420 | config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', |
| 2421 | 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2422 | 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'} |
| 2423 | self.onos_dhcp_table_load(config) |
| 2424 | self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2425 | log_test.info('Sending DHCP discover and DHCP request.') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2426 | cip, sip = self.send_recv() |
| 2427 | mac = self.dhcp.get_mac(cip)[0] |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2428 | log_test.info("Sending DHCP request again.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2429 | new_cip, new_sip = self.dhcp.only_request(cip, mac) |
| 2430 | if (new_cip,new_sip) == (cip,sip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2431 | log_test.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.' |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2432 | % (new_cip, new_sip, mac) ) |
| 2433 | elif (new_cip,new_sip): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2434 | log_test.info('No DHCP ACK') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2435 | assert_equal(new_cip, None) |
| 2436 | assert_equal(new_sip, None) |
| 2437 | else: |
| 2438 | print "Something went wrong." |
| 2439 | |
| 2440 | def dhcp_client_desired_ip_scenario(self, subscriber): |
| 2441 | if subscriber.has_service('DHCP'): |
| 2442 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2443 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2444 | tl = self.subscriber_dhcp_client_desired_address() |
| 2445 | self.test_status = True |
| 2446 | return self.test_status |
| 2447 | else: |
| 2448 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2449 | self.test_status = True |
| 2450 | return self.test_status |
| 2451 | |
| 2452 | def subscriber_dhcp_client_desired_address(self, iface = INTF_RX_DEFAULT): |
| 2453 | '''DHCP Client asking for desired IP address.''' |
| 2454 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2455 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2456 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2457 | self.onos_dhcp_table_load(config) |
| 2458 | self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface) |
| 2459 | cip, sip, mac , lval = self.dhcp.only_discover(desired = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2460 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2461 | (cip, sip, mac) ) |
| 2462 | if cip == self.dhcp.seed_ip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2463 | log_test.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2464 | (cip, sip, mac) ) |
| 2465 | elif cip != self.dhcp.seed_ip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2466 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2467 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2468 | log_test.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2469 | assert_equal(cip, self.dhcp.seed_ip) |
| 2470 | def dhcp_client_request_pkt_with_non_offered_ip_scenario(self, subscriber): |
| 2471 | if subscriber.has_service('DHCP'): |
| 2472 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2473 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2474 | tl = self.subscriber_dhcp_server_nak_packet() |
| 2475 | self.test_status = True |
| 2476 | return self.test_status |
| 2477 | else: |
| 2478 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2479 | self.test_status = True |
| 2480 | return self.test_status |
| 2481 | |
| 2482 | def subscriber_dhcp_server_nak_packet(self, iface = INTF_RX_DEFAULT): |
| 2483 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2484 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2485 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2486 | self.onos_dhcp_table_load(config) |
| 2487 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
| 2488 | cip, sip, mac, lval = self.dhcp.only_discover() |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2489 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2490 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2491 | log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2492 | if (cip == None and mac != None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2493 | log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2494 | assert_not_equal(cip, None) |
| 2495 | else: |
| 2496 | new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac) |
| 2497 | if new_cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2498 | log_test.info("Got DHCP server NAK.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2499 | assert_equal(new_cip, None) #Negative Test Case |
| 2500 | |
| 2501 | def dhcp_client_requested_out_pool_ip_scenario(self, subscriber): |
| 2502 | if subscriber.has_service('DHCP'): |
| 2503 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2504 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2505 | tl = self.subscriber_dhcp_client_desired_address_out_of_pool() |
| 2506 | self.test_status = True |
| 2507 | return self.test_status |
| 2508 | else: |
| 2509 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2510 | self.test_status = True |
| 2511 | return self.test_status |
| 2512 | def subscriber_dhcp_client_desired_address_out_of_pool(self, iface = INTF_RX_DEFAULT): |
| 2513 | '''DHCP Client asking for desired IP address from out of pool.''' |
| 2514 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2515 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2516 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2517 | self.onos_dhcp_table_load(config) |
| 2518 | self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface) |
| 2519 | cip, sip, mac, lval = self.dhcp.only_discover(desired = True) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2520 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2521 | (cip, sip, mac) ) |
| 2522 | if cip == self.dhcp.seed_ip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2523 | log_test.info('Got dhcp client IP %s from server %s for mac %s as desired .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2524 | (cip, sip, mac) ) |
| 2525 | assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case |
| 2526 | |
| 2527 | elif cip != self.dhcp.seed_ip: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2528 | log_test.info('Got dhcp client IP %s from server %s for mac %s .' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2529 | (cip, sip, mac) ) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2530 | log_test.info('The desired ip was: %s .' % self.dhcp.seed_ip) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2531 | assert_not_equal(cip, self.dhcp.seed_ip) |
| 2532 | |
| 2533 | elif cip == None: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2534 | log_test.info('Got DHCP NAK') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2535 | |
| 2536 | def dhcp_client_specific_lease_scenario(self, subscriber): |
| 2537 | if subscriber.has_service('DHCP'): |
| 2538 | time.sleep(2) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2539 | log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name) |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2540 | tl = self.subscriber_dhcp_specific_lease_packet() |
| 2541 | self.test_status = True |
| 2542 | return self.test_status |
| 2543 | else: |
| 2544 | subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)] |
| 2545 | self.test_status = True |
| 2546 | return self.test_status |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2547 | def subscriber_dhcp_specific_lease_packet(self, iface = INTF_RX_DEFAULT): |
| 2548 | ''' Client sends DHCP Discover packet for particular lease time.''' |
| 2549 | config = {'startip':'20.20.20.30', 'endip':'20.20.20.69', |
| 2550 | 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe", |
| 2551 | 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'} |
| 2552 | self.onos_dhcp_table_load(config) |
| 2553 | self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2554 | log_test.info('Sending DHCP discover with lease time of 700') |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2555 | cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True) |
| 2556 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2557 | log_test.info("Verifying Client 's IP and mac in DHCP Offer packet.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2558 | if (cip == None and mac != None): |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2559 | log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.") |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2560 | assert_not_equal(cip, None) |
| 2561 | elif lval != 700: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 2562 | log_test.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' % |
ChetanGaonker | 2099d72 | 2016-10-07 15:16:58 -0700 | [diff] [blame] | 2563 | (cip, sip, mac, lval) ) |
| 2564 | assert_not_equal(lval, 700) |