blob: 4f762ea7b2a4b92b3fc3c35ad05bb9a128ca3a8a [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
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
ChetanGaonker2099d722016-10-07 15:16:58 -070017import unittest
18from twisted.internet import defer
19from nose.tools import *
20from IGMP import *
21from ACL import ACLTest
22from DHCP import DHCPTest
23from Channels import Channels, IgmpChannel
24from subscriberDb import SubscriberDB
25import time, monotonic
A R Karthick76a497a2017-04-12 10:59:39 -070026from CordTestUtils import get_mac, log_test
ChetanGaonker2099d722016-10-07 15:16:58 -070027from OltConfig import OltConfig
A.R Karthickbe7768c2017-03-17 11:39:41 -070028from OnosCtrl import OnosCtrl
ChetanGaonker2099d722016-10-07 15:16:58 -070029from OnosFlowCtrl import OnosFlowCtrl
30from CordContainer import Container, Onos, Quagga
31from onosclidriver import OnosCliDriver
32from CordTestServer import CordTestServer, cord_test_onos_restart, cord_test_quagga_restart,cord_test_quagga_stop, cord_test_quagga_shell,cord_test_shell
33from portmaps import g_subscriber_port_map
34import time, monotonic
35from scapy_ssl_tls.ssl_tls import *
36from scapy_ssl_tls.ssl_tls_crypto import *
37import os
38import json
39from socket import socket
40import pexpect
41from Stats import Stats
A.R Karthick2e99c472017-03-22 19:13:51 -070042import logging
43logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
ChetanGaonker2099d722016-10-07 15:16:58 -070044from scapy.all import *
45from OnosFlowCtrl import OnosFlowCtrl
46from nose.twistedtools import reactor, deferred
47import tempfile
48import threading
49from threading import current_thread
50from threadPool import ThreadPool
51import random
52import collections
53import requests
A R Karthick76a497a2017-04-12 10:59:39 -070054log_test.setLevel('INFO')
ChetanGaonker2099d722016-10-07 15:16:58 -070055class 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 Karthick5968e0d2017-05-16 14:50:46 -070078 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json'))
ChetanGaonker2099d722016-10-07 15:16:58 -070079 ROVER_TEST_TIMEOUT = 300 #3600*86
80 ROVER_TIMEOUT = (ROVER_TEST_TIMEOUT - 100)
81 ROVER_JOIN_TIMEOUT = 60
82
83 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -070084 def setUpClass(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -070085 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
86 cls.port_map, _ = cls.olt.olt_port_map()
A R Karthick0f6b6842016-12-06 17:17:44 -080087 OnosCtrl.cord_olt_config(cls.olt, controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070088
89 @classmethod
90 def tearDownClass(cls): pass
91
ChetanGaonker689b3862016-10-17 16:25:01 -070092 def setUp(self,controller=None):
93 self.setUpClass(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070094 self.get_igmp_intf()
95 ''' Activate the igmp app'''
ChetanGaonker689b3862016-10-17 16:25:01 -070096 self.onos_ctrl = OnosCtrl(self.app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070097 self.onos_ctrl.activate()
ChetanGaonker689b3862016-10-17 16:25:01 -070098 self.igmp_channel = IgmpChannel(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070099
100 def tearDown(self): pass
101
ChetanGaonker689b3862016-10-17 16:25:01 -0700102 def onos_load_config(self, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -0700103 log_test.info('onos load config is %s'%config)
ChetanGaonker689b3862016-10-17 16:25:01 -0700104 status, code = OnosCtrl(self.app).config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700105 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700106 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700107 assert_equal(status, True)
108 time.sleep(2)
109
ChetanGaonker689b3862016-10-17 16:25:01 -0700110 def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],controller=None,flag = False):
ChetanGaonker2099d722016-10-07 15:16:58 -0700111 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)
ChetanGaonker689b3862016-10-17 16:25:01 -0700126 self.onos_load_config(ssm_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700127 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 Karthick76a497a2017-04-12 10:59:39 -0700222 log_test.info('Receive stats %s for group %s' %(rx_stats, g))
ChetanGaonker2099d722016-10-07 15:16:58 -0700223
A R Karthick76a497a2017-04-12 10:59:39 -0700224 log_test.info('IGMP test verification success')
ChetanGaonker2099d722016-10-07 15:16:58 -0700225
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 Karthick76a497a2017-04-12 10:59:39 -0700236 log_test.info('Received %d packets for group %s' %(rx, g))
ChetanGaonker2099d722016-10-07 15:16:58 -0700237 for g in leave_groups:
238 rx = recvState.group_map[g][1].count
239 assert_equal(rx, 0)
240
A R Karthick76a497a2017-04-12 10:59:39 -0700241 log_test.info('IGMP test verification success')
ChetanGaonker2099d722016-10-07 15:16:58 -0700242
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 Karthick76a497a2017-04-12 10:59:39 -0700258 log_test.info('Unexpected Payload received: %s' %p.payload.load)
ChetanGaonker2099d722016-10-07 15:16:58 -0700259 return 0
A R Karthick76a497a2017-04-12 10:59:39 -0700260 #log_test.info( 'Recv in %.6f secs' %(recv_time - send_time))
ChetanGaonker2099d722016-10-07 15:16:58 -0700261 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 Karthick76a497a2017-04-12 10:59:39 -0700279 log_test.info('igmp join packet is %s'%pkt.show())
ChetanGaonker2099d722016-10-07 15:16:58 -0700280 if delay != 0:
281 time.sleep(delay)
282
283class cluster_tls():
284 eap_app = 'org.opencord.aaa'
285 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
286MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
287VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE
288ChMKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
289JAYDVQQDEx1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjAzMTEx
290ODUzMzVaFw0xNzAzMDYxODUzMzVaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECBMC
291Q0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UEChMKQ2llbmEgSW5jLjEeMBwG
292CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDEx1FeGFtcGxlIENl
293cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
294ggEBAL9Jv54TkqycL3U2Fdd/y5NXdnPVXwAVV3m6I3eIffVCv8eS+mwlbl9dnbjo
295qqlGEgA3sEg5HtnKoW81l3PSyV/YaqzUzbcpDlgWlbNkFQ3nVxh61gSU34Fc4h/W
296plSvCkwGSbV5udLtEe6S9IflP2Fu/eXa9vmUtoPqDk66p9U/nWVf2H1GJy7XanWg
297wke+HpQvbzoSfPJS0e5Rm9KErrzaIkJpqt7soW+OjVJitUax7h45RYY1HHHlbMQ0
298ndWW8UDsCxFQO6d7nsijCzY69Y8HarH4mbVtqhg3KJevxD9UMRy6gdtPMDZLah1c
299LHRu14ucOK4aF8oICOgtcD06auUCAwEAAaOCASwwggEoMB0GA1UdDgQWBBQwEs0m
300c8HARTVp21wtiwgav5biqjCBwAYDVR0jBIG4MIG1gBQwEs0mc8HARTVp21wtiwga
301v5biqqGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQH
302EwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
303D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
304dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
305oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
306hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp
307jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo
308bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L
309opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej
310gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM
311729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
312-----END CERTIFICATE-----'''
313 def __init__(self):
314 pass
ChetanGaonker689b3862016-10-17 16:25:01 -0700315 def setUp(self,controller=None):
316 self.onos_ctrl = OnosCtrl(self.eap_app,controller=controller)
317 self.onos_aaa_config(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700318
ChetanGaonker689b3862016-10-17 16:25:01 -0700319 def onos_aaa_config(self,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -0700320 log_test.info('controller in onos_aaa_config is %s'%controller)
A.R Karthicka6c88fd2017-03-13 09:29:41 -0700321 aaa_dict = {'apps' : { 'org.opencord.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
322 'radiusIp': '172.17.0.2' } } } }
ChetanGaonker2099d722016-10-07 15:16:58 -0700323 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A.R Karthicka6c88fd2017-03-13 09:29:41 -0700324 aaa_dict['apps']['org.opencord.aaa']['AAA']['radiusIp'] = radius_ip
ChetanGaonker2099d722016-10-07 15:16:58 -0700325 self.onos_ctrl.activate()
326 time.sleep(2)
ChetanGaonker689b3862016-10-17 16:25:01 -0700327 self.onos_load_config(aaa_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700328
ChetanGaonker689b3862016-10-17 16:25:01 -0700329 def onos_load_config(self, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -0700330 log_test.info('controller in onos_load_config is %s'%controller)
331 log_test.info('onos load config is %s'%config)
ChetanGaonker689b3862016-10-17 16:25:01 -0700332 status, code = OnosCtrl(self.eap_app).config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700333 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700334 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700335 assert_equal(status, True)
336 time.sleep(2)
337
338
339class 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
443class cluster_proxyarp():
ChetanGaonker689b3862016-10-17 16:25:01 -0700444 #apps = ('org.onosproject.vrouter','org.onosproject.proxyarp')
445 app = 'org.onosproject.proxyarp'
ChetanGaonker2099d722016-10-07 15:16:58 -0700446 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 Karthick5968e0d2017-05-16 14:50:46 -0700463 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json'))
ChetanGaonker2099d722016-10-07 15:16:58 -0700464
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)
ChetanGaonker689b3862016-10-17 16:25:01 -0700513 #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)
ChetanGaonker2099d722016-10-07 15:16:58 -0700516
517 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700518 def host_config_load(cls, host_config = None, controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700519 for host in host_config:
ChetanGaonker689b3862016-10-17 16:25:01 -0700520 status, code = OnosCtrl(cls.app).host_config(host,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700521 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700522 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700523 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
ChetanGaonker689b3862016-10-17 16:25:01 -0700571 def proxyarp_activate(cls, deactivate = False,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700572 app = 'org.onosproject.proxyarp'
ChetanGaonker689b3862016-10-17 16:25:01 -0700573 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700574 if deactivate is True:
575 onos_ctrl.deactivate()
576 else:
577 onos_ctrl.activate()
578 time.sleep(3)
579
580 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700581 def proxyarp_config(cls, hosts = 1,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700582 proxyarp_configs = cls.generate_interface_config(hosts = hosts)
583 cls.interface_config_load(interface_cfg = proxyarp_configs)
584 hostcfg = cls.generate_host_config()
ChetanGaonker689b3862016-10-17 16:25:01 -0700585 cls.host_config_load(host_config = hostcfg,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700586 return proxyarp_configs
587
588 def proxyarp_arpreply_verify(self, ingress, hostip, hostmac, PositiveTest=True):
A R Karthick76a497a2017-04-12 10:59:39 -0700589 #log_test.info('verifying arp reply for host ip %s host mac %s on interface %s'%(hostip ,hostmac ,self.port_map[ingress]))
ChetanGaonker2099d722016-10-07 15:16:58 -0700590 self.success = False
591 def recv_task():
592 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -0700593 log_test.info('Arp Reply seen with source Mac is %s' %(pkt[ARP].hwsrc))
ChetanGaonker2099d722016-10-07 15:16:58 -0700594 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 Karthick76a497a2017-04-12 10:59:39 -0700600 log_test.info('sending arp request for dest ip %s on interface %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -0700601 (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 Karthick76a497a2017-04-12 10:59:39 -0700610 log_test.info('verifying arp reply for host ip host mac on interface %s'%(self.port_map[2]))
ChetanGaonker2099d722016-10-07 15:16:58 -0700611 _,_,hosts_config = self.proxyarp_config(hosts = hosts)
A R Karthick76a497a2017-04-12 10:59:39 -0700612 log_test.info('\nhosts_config %s and its type %s'%(hosts_config,type(hosts_config)))
ChetanGaonker2099d722016-10-07 15:16:58 -0700613 self.cliEnter()
614 connected_hosts = json.loads(self.cli.hosts(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700615 log_test.info('Discovered hosts: %s' %connected_hosts)
ChetanGaonker2099d722016-10-07 15:16:58 -0700616 #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
626class 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 = '''
638password zebra
639log stdout
640service 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
648line 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
ChetanGaonker689b3862016-10-17 16:25:01 -0700696 def cliEnter(self,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700697 retries = 0
698 while retries < 3:
ChetanGaonker689b3862016-10-17 16:25:01 -0700699 self.cli = OnosCliDriver(connect = True,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700700 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
ChetanGaonker689b3862016-10-17 16:25:01 -0700710 def onos_load_config(cls, config,controller=None):
711 status, code = OnosCtrl.config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700712 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700713 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700714 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
ChetanGaonker689b3862016-10-17 16:25:01 -0700724 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 Karthick76a497a2017-04-12 10:59:39 -0700732 log_test.info('creating host with ip %s and mac %s'%(host,mac))
ChetanGaonker689b3862016-10-17 16:25:01 -0700733 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 Karthick76a497a2017-04-12 10:59:39 -0700738 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -0700739 return False
740 return True
741
742 """@classmethod
ChetanGaonker2099d722016-10-07 15:16:58 -0700743 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 Karthick76a497a2017-04-12 10:59:39 -0700751 log_test.info('Assigning ip %s to interface %s' %(host, iface))
ChetanGaonker2099d722016-10-07 15:16:58 -0700752 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)
ChetanGaonker689b3862016-10-17 16:25:01 -0700758 """
ChetanGaonker2099d722016-10-07 15:16:58 -0700759 @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
ChetanGaonker689b3862016-10-17 16:25:01 -0700780 cfg = json.dumps(config)
A R Karthick76a497a2017-04-12 10:59:39 -0700781 log_test.info('Restarting ONOS with new network configuration %s'%config)
ChetanGaonker689b3862016-10-17 16:25:01 -0700782 #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)
ChetanGaonker2099d722016-10-07 15:16:58 -0700786
787 @classmethod
788 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
A R Karthick76a497a2017-04-12 10:59:39 -0700789 log_test.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker2099d722016-10-07 15:16:58 -0700790 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 Karthick76a497a2017-04-12 10:59:39 -0700883 #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
ChetanGaonker2099d722016-10-07 15:16:58 -0700884 return cls.zebra_conf + zebra_routes
885
886 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700887 def vrouter_activate(cls, deactivate = False,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700888 app = 'org.onosproject.vrouter'
ChetanGaonker689b3862016-10-17 16:25:01 -0700889 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700890 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,
ChetanGaonker689b3862016-10-17 16:25:01 -0700898 route_update = None, router_address = None, time_expire = None, adding_new_routes = None,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700899 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)
ChetanGaonker689b3862016-10-17 16:25:01 -0700902 cls.vrouter_host_load(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700903 ##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 Karthick76a497a2017-04-12 10:59:39 -0700916 log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -0700917 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 Karthick76a497a2017-04-12 10:59:39 -0700928 log_test.info('Sending a packet with dst ip %s, dst mac %s on port %s to verify if flows are correct' %
ChetanGaonker2099d722016-10-07 15:16:58 -0700929 (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,
ChetanGaonker689b3862016-10-17 16:25:01 -0700966 deactivate_activate_vrouter = None, adding_new_routes = None,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700967
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,
ChetanGaonker689b3862016-10-17 16:25:01 -0700973 adding_new_routes = adding_new_routes,
974 controller=controller)
975 self.cliEnter(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700976 ##Now verify
977 hosts = json.loads(self.cli.hosts(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700978 log_test.info('Discovered hosts: %s' %hosts)
ChetanGaonker2099d722016-10-07 15:16:58 -0700979 ##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 Karthick76a497a2017-04-12 10:59:39 -0700982 #log_test.info('Routes: %s' %routes)
ChetanGaonker2099d722016-10-07 15:16:58 -0700983 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 Karthick76a497a2017-04-12 10:59:39 -0700994 #log_test.info('Flows: %s' %flows)
ChetanGaonker2099d722016-10-07 15:16:58 -0700995 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 Karthick76a497a2017-04-12 10:59:39 -07001009 log_test.info('Deactivating vrouter app in ONOS controller for negative scenario')
ChetanGaonker2099d722016-10-07 15:16:58 -07001010 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 Karthick76a497a2017-04-12 10:59:39 -07001013 log_test.info('Activating vrouter app again in ONOS controller for negative scenario')
ChetanGaonker2099d722016-10-07 15:16:58 -07001014 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 Karthick76a497a2017-04-12 10:59:39 -07001023 log_test.info('Stopping Quagga container')
ChetanGaonker2099d722016-10-07 15:16:58 -07001024 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 Karthick76a497a2017-04-12 10:59:39 -07001031 log_test.info('OVS flows have been removed successfully after Quagga was stopped')
ChetanGaonker2099d722016-10-07 15:16:58 -07001032 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 Karthick76a497a2017-04-12 10:59:39 -07001038 log_test.info('OVS flows have been successfully reinstalled after Quagga was restarted')
ChetanGaonker2099d722016-10-07 15:16:58 -07001039
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
1046class cluster_acl(object):
ChetanGaonker689b3862016-10-17 16:25:01 -07001047 app = 'org.onosproject.acl'
ChetanGaonker2099d722016-10-07 15:16:58 -07001048 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 Karthick76a497a2017-04-12 10:59:39 -07001074 log_test.info('port_map = %s'%cls.port_map[1] )
ChetanGaonker2099d722016-10-07 15:16:58 -07001075
1076 @classmethod
1077 def tearDownClass(cls):
1078 '''Deactivate the acl app'''
ChetanGaonker689b3862016-10-17 16:25:01 -07001079 def setUp(self,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001080 self.setUpClass()
1081 ''' Activate the acl app'''
1082 self.maxDiff = None ##for assert_equal compare outputs on failure
ChetanGaonker689b3862016-10-17 16:25:01 -07001083 self.onos_ctrl = OnosCtrl(self.app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001084 status, _ = self.onos_ctrl.activate()
1085 assert_equal(status, True)
1086 time.sleep(1)
1087 #status, _ = ACLTest.remove_acl_rule()
A R Karthick76a497a2017-04-12 10:59:39 -07001088 #log_test.info('Start setup')
ChetanGaonker2099d722016-10-07 15:16:58 -07001089 #assert_equal(status, True)
1090
1091 def tearDown(self):
1092 '''Deactivate the acl app'''
A R Karthick76a497a2017-04-12 10:59:39 -07001093 log_test.info('Tear down setup')
ChetanGaonker2099d722016-10-07 15:16:58 -07001094 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 Karthick76a497a2017-04-12 10:59:39 -07001117 log_test.info('Assigning ip %s to interface %s' %(ip, egress))
ChetanGaonker2099d722016-10-07 15:16:58 -07001118 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 Karthick76a497a2017-04-12 10:59:39 -07001159 log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -07001160 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 Karthick76a497a2017-04-12 10:59:39 -07001171 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' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001172 (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
ChetanGaonker689b3862016-10-17 16:25:01 -07001179 def onos_load_config(cls, config,controller=None):
1180 status, code = OnosCtrl.config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001181 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001182 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -07001183 assert_equal(status, True)
1184
1185class 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 Karthick5968e0d2017-05-16 14:50:46 -07001193 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
ChetanGaonker2099d722016-10-07 15:16:58 -07001194 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'''
1204subnet 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
ChetanGaonker689b3862016-10-17 16:25:01 -07001223 def setUpClass(cls,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001224 log_test.info('controller ip in dhcp setup def is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001225 ''' Activate the dhcprelay app'''
ChetanGaonker689b3862016-10-17 16:25:01 -07001226 OnosCtrl(cls.app_dhcp,controller=controller).deactivate()
ChetanGaonker2099d722016-10-07 15:16:58 -07001227 time.sleep(3)
ChetanGaonker689b3862016-10-17 16:25:01 -07001228 cls.onos_ctrl = OnosCtrl(cls.app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001229 status, _ = cls.onos_ctrl.activate()
1230 assert_equal(status, True)
1231 time.sleep(3)
ChetanGaonker689b3862016-10-17 16:25:01 -07001232 cls.dhcp_relay_setup(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001233 ##start dhcpd initially with default config
ChetanGaonker689b3862016-10-17 16:25:01 -07001234 cls.dhcpd_start(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001235
1236 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001237 def tearDownClass(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001238 '''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
ChetanGaonker689b3862016-10-17 16:25:01 -07001243 OnosCtrl(cls.app,controller=controller).deactivate()
1244 #cls.onos_ctrl.deactivate()
ChetanGaonker2099d722016-10-07 15:16:58 -07001245 cls.dhcpd_stop()
ChetanGaonker689b3862016-10-17 16:25:01 -07001246 #cls.dhcp_relay_cleanup()
ChetanGaonker2099d722016-10-07 15:16:58 -07001247
1248 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001249 def dhcp_relay_setup(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001250 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))
ChetanGaonker689b3862016-10-17 16:25:01 -07001281 cls.onos_interface_load(interface_list,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001282
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 Karthick76a497a2017-04-12 10:59:39 -07001287 log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
ChetanGaonker2099d722016-10-07 15:16:58 -07001288 return cord_test_onos_restart(config = {})
1289
1290 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001291 def onos_load_config(cls, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001292 log_test.info('loading onos config in controller %s'%controller)
ChetanGaonker689b3862016-10-17 16:25:01 -07001293 status, code = OnosCtrl.config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001294 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001295 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -07001296 assert_equal(status, True)
1297 time.sleep(2)
1298
1299 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001300 def onos_interface_load(cls, interface_list,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001301 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
ChetanGaonker689b3862016-10-17 16:25:01 -07001313 cls.onos_load_config(interface_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001314
1315 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001316 def onos_dhcp_relay_load(cls, server_ip, server_mac,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001317 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 }
ChetanGaonker689b3862016-10-17 16:25:01 -07001326 cls.onos_load_config(dhcp_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001327
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,
ChetanGaonker689b3862016-10-17 16:25:01 -07001367 subnet = default_subnet_config,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001368 '''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 Karthick76a497a2017-04-12 10:59:39 -07001396 log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
ChetanGaonker2099d722016-10-07 15:16:58 -07001397 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
ChetanGaonker689b3862016-10-17 16:25:01 -07001402 cls.onos_dhcp_relay_load(*intf_info[0],controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001403
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 Karthick76a497a2017-04-12 10:59:39 -07001447 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001448 (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 Karthick76a497a2017-04-12 10:59:39 -07001456 log_test.info('Failed to get ip')
ChetanGaonker2099d722016-10-07 15:16:58 -07001457 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 Karthick76a497a2017-04-12 10:59:39 -07001473 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001474 (cip, sip, self.dhcp.get_mac(cip)[0]))
1475 return cip,sip
1476
1477class 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 Karthick76a497a2017-04-12 10:59:39 -07001501 log_test.info('Subscriber %s, rx interface %s, uplink interface %s' %(name, self.rx_intf, self.tx_intf))
ChetanGaonker2099d722016-10-07 15:16:58 -07001502 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 Karthick76a497a2017-04-12 10:59:39 -07001570 log_test.info('Subscriber %s on port %s receiving from group %s, channel %d' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001571 (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 Karthick76a497a2017-04-12 10:59:39 -07001574 log_test.info('Subscriber %s on port %s timed out' %(self.name, self.rx_intf))
ChetanGaonker2099d722016-10-07 15:16:58 -07001575 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001576 log_test.info('Subscriber %s on port %s received %d packets' %(self.name, self.rx_intf, len(r)))
ChetanGaonker2099d722016-10-07 15:16:58 -07001577 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 Karthick76a497a2017-04-12 10:59:39 -07001583 log_test.info('Packet received for group %s, subscriber %s, port %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001584 (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 Karthick76a497a2017-04-12 10:59:39 -07001594 log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -07001595
1596class 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 Karthick76a497a2017-04-12 10:59:39 -07001609 log_test.info('This service is failed and other services will not run for this subscriber')
ChetanGaonker2099d722016-10-07 15:16:58 -07001610 break
A R Karthick76a497a2017-04-12 10:59:39 -07001611 log_test.info('This Subscriber is tested for multiple service eligibility ')
ChetanGaonker2099d722016-10-07 15:16:58 -07001612 self.test_status = True
1613
1614class 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 Karthick5968e0d2017-05-16 14:50:46 -07001637 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
ChetanGaonker2099d722016-10-07 15:16:58 -07001638 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-----
1651MIICuDCCAiGgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
1652CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h
1653IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd
1654RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwNjA2MjExMjI3WhcN
1655MTcwNjAxMjExMjI3WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV
1656BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI
1657hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
1658gYEAwvXiSzb9LZ6c7uNziUfKvoHO7wu/uiFC5YUpXbmVGuGZizbVrny0xnR85Dfe
1659+9R4diansfDhIhzOUl1XjN3YDeSS9OeF5YWNNE8XDhlz2d3rVzaN6hIhdotBkUjg
1660rUewjTg5OFR31QEyG3v8xR3CLgiE9xQELjZbSA07pD79zuUCAwEAAaNPME0wEwYD
1661VR0lBAwwCgYIKwYBBQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5l
1662eGFtcGxlLmNvbS9leGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOBgQDAjkrY
16636tDChmKbvr8w6Du/t8vHjTCoCIocHTN0qzWOeb1YsAGX89+TrWIuO1dFyYd+Z0KC
1664PDKB5j/ygml9Na+AklSYAVJIjvlzXKZrOaPmhZqDufi+rXWti/utVqY4VMW2+HKC
1665nXp37qWeuFLGyR1519Y1d6F/5XzqmvbwURuEug==
1666-----END CERTIFICATE-----"""
1667
1668 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
1669MIIDvTCCAqWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
1670CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h
1671IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd
1672RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzExMTg1MzM2WhcN
1673MTcwMzA2MTg1MzM2WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV
1674BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI
1675hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
1676AQoCggEBAOxemcBsPn9tZsCa5o2JA6sQDC7A6JgCNXXl2VFzKLNNvB9PS6D7ZBsQ
16775An0zEDMNzi51q7lnrYg1XyiE4S8FzMGAFr94RlGMQJUbRD9V/oqszMX4k++iAOK
1678tIA1gr3x7Zi+0tkjVSVzXTmgNnhChAamdMsjYUG5+CY9WAicXyy+VEV3zTphZZDR
1679OjcjEp4m/TSXVPYPgYDXI40YZKX5BdvqykWtT/tIgZb48RS1NPyN/XkCYzl3bv21
1680qx7Mc0fcEbsJBIIRYTUkfxnsilcnmLxSYO+p+DZ9uBLBzcQt+4Rd5pLSfi21WM39
16812Z2oOi3vs/OYAPAqgmi2JWOv3mePa/8CAwEAAaNPME0wEwYDVR0lBAwwCgYIKwYB
1682BQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5leGFtcGxlLmNvbS9l
1683eGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOCAQEALBzMPDTIB6sLyPl0T6JV
1684MjOkyldAVhXWiQsTjaGQGJUUe1cmUJyZbUZEc13MygXMPOM4x7z6VpXGuq1c/Vxn
1685VzQ2fNnbJcIAHi/7G8W5/SQfPesIVDsHTEc4ZspPi5jlS/MVX3HOC+BDbOjdbwqP
1686RX0JEr+uOyhjO+lRxG8ilMRACoBUbw1eDuVDoEBgErSUC44pq5ioDw2xelc+Y6hQ
1687dmtYwfY0DbvwxHtA495frLyPcastDiT/zre7NL51MyUDPjjYjghNQEwvu66IKbQ3
1688T1tJBrgI7/WI+dqhKBFolKGKTDWIHsZXQvZ1snGu/FRYzg1l+R/jT8cRB9BDwhUt
1689yg==
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" : {
Luca Prete9c0cdac2018-07-02 14:40:40 +02001700 "driver" : "voltha"
ChetanGaonker2099d722016-10-07 15:16:58 -07001701 }
1702 }
1703 },
1704 }
1705 return did
1706
1707 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001708 def setUpClass(cls,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001709 log_test.info('controller ip in cluster.py setupclass is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001710 '''Load the OLT config and activate relevant apps'''
1711 did = cls.load_device_id()
1712 network_cfg = { "devices" : {
1713 "{}".format(did) : {
1714 "basic" : {
Luca Prete9c0cdac2018-07-02 14:40:40 +02001715 "driver" : "voltha"
ChetanGaonker2099d722016-10-07 15:16:58 -07001716 }
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 Karthick76a497a2017-04-12 10:59:39 -07001725 # log_test.info('JSON config request for app %s returned status %d' %(app, code))
ChetanGaonker2099d722016-10-07 15:16:58 -07001726 #assert_equal(status, True)
1727 #time.sleep(2)
ChetanGaonker689b3862016-10-17 16:25:01 -07001728 cls.install_app_table(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001729 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
A R Karthick0f6b6842016-12-06 17:17:44 -08001730 OnosCtrl.cord_olt_config(cls.olt, controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001731 cls.port_map, cls.port_list = cls.olt.olt_port_map()
ChetanGaonker689b3862016-10-17 16:25:01 -07001732 cls.activate_apps(cls.apps + cls.olt_apps,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001733
1734 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001735 def tearDownClass(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001736 '''Deactivate the olt apps and restart OVS back'''
1737 apps = cls.olt_apps + ( cls.table_app,)
1738 for app in apps:
ChetanGaonker689b3862016-10-17 16:25:01 -07001739 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001740 onos_ctrl.deactivate()
1741 cls.uninstall_app_table()
ChetanGaonker689b3862016-10-17 16:25:01 -07001742 cls.start_onos(network_cfg = {})
ChetanGaonker2099d722016-10-07 15:16:58 -07001743
1744 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001745 def activate_apps(cls, apps,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001746 for app in apps:
ChetanGaonker689b3862016-10-17 16:25:01 -07001747 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001748 status, _ = onos_ctrl.activate()
1749 assert_equal(status, True)
1750 time.sleep(2)
1751 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001752 def install_app_table(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001753 ##Uninstall the existing app if any
ChetanGaonker689b3862016-10-17 16:25:01 -07001754 OnosCtrl.uninstall_app(cls.table_app,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001755 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07001756 log_test.info('Installing the multi table app %s for subscriber test' %(cls.table_app_file))
ChetanGaonker689b3862016-10-17 16:25:01 -07001757 OnosCtrl.install_app(cls.table_app_file,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001758 time.sleep(3)
1759 #onos_ctrl = OnosCtrl(cls.vtn_app)
1760 #onos_ctrl.deactivate()
1761
1762 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001763 def uninstall_app_table(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001764 ##Uninstall the table app on class exit
ChetanGaonker689b3862016-10-17 16:25:01 -07001765 OnosCtrl.uninstall_app(cls.table_app,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001766 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07001767 log_test.info('Installing back the cord igmp app %s for subscriber test on exit' %(cls.app_file))
ChetanGaonker689b3862016-10-17 16:25:01 -07001768 OnosCtrl.install_app(cls.app_file,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001769 #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 Karthick76a497a2017-04-12 10:59:39 -07001775 log_test.info('ONOS restart is disabled. Skipping ONOS restart')
ChetanGaonker2099d722016-10-07 15:16:58 -07001776 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 Karthick76a497a2017-04-12 10:59:39 -07001787 log_test.info('Restarting ONOS with new network configuration')
ChetanGaonker689b3862016-10-17 16:25:01 -07001788 #return cord_test_onos_restart(config = config)
ChetanGaonker2099d722016-10-07 15:16:58 -07001789
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
ChetanGaonker689b3862016-10-17 16:25:01 -07001823 def onos_aaa_load(self,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001824 log_test.info('controller ip in cluster.py onos_aaa_load is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001825 if self.aaa_loaded:
1826 return
A R Karthick1555c7c2017-09-07 14:59:41 -07001827 OnosCtrl.aaa_load_config(controller = controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001828 self.aaa_loaded = True
1829
ChetanGaonker689b3862016-10-17 16:25:01 -07001830 def onos_dhcp_table_load(self, config = None,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001831 log_test.info('controller ip in cluster.py onos_dhcp_table_load is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001832 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
1833 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
1834 if config:
1835 for k in config.keys():
1836 if dhcp_config.has_key(k):
1837 dhcp_config[k] = config[k]
ChetanGaonker689b3862016-10-17 16:25:01 -07001838 self.onos_load_config('org.onosproject.dhcp', dhcp_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001839
ChetanGaonker689b3862016-10-17 16:25:01 -07001840 def onos_load_config(self, app, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001841 log_test.info('controller ip in cluster.py onos_load_config is %s'%controller)
ChetanGaonker689b3862016-10-17 16:25:01 -07001842 status, code = OnosCtrl(controller=controller).config(config)
ChetanGaonker2099d722016-10-07 15:16:58 -07001843 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001844 log_test.info('JSON config request for app %s returned status %d' %(app, code))
ChetanGaonker2099d722016-10-07 15:16:58 -07001845 assert_equal(status, True)
1846 time.sleep(2)
1847 def dhcp_sndrcv(self, dhcp, update_seed = False):
1848 cip, sip = dhcp.discover(update_seed = update_seed)
1849 assert_not_equal(cip, None)
1850 assert_not_equal(sip, None)
A R Karthick76a497a2017-04-12 10:59:39 -07001851 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001852 (cip, sip, dhcp.get_mac(cip)[0]))
1853 return cip,sip
1854
1855 def dhcp_request(self, subscriber, seed_ip = '10.10.10.1', update_seed = False):
1856 config = {'startip':'10.10.10.20', 'endip':'10.10.10.200',
1857 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
1858 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
1859 self.onos_dhcp_table_load(config)
1860 dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface)
1861 cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed)
1862 return cip, sip
1863
1864 def recv_channel_cb(self, pkt):
1865 ##First verify that we have received the packet for the joined instance
1866 chan = self.subscriber.caddr(pkt[IP].dst)
1867 assert_equal(chan in self.subscriber.join_map.keys(), True)
1868 recv_time = monotonic.monotonic() * 1000000
1869 join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start
1870 delta = recv_time - join_time
1871 self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True)
1872 self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta)
A R Karthick76a497a2017-04-12 10:59:39 -07001873 log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -07001874 self.test_status = True
1875
1876 def traffic_verify(self, subscriber):
1877 if subscriber.has_service('TRAFFIC'):
1878 url = 'http://www.google.com'
1879 resp = requests.get(url)
1880 self.test_status = resp.ok
1881 if resp.ok == False:
A R Karthick76a497a2017-04-12 10:59:39 -07001882 log_test.info('Subscriber %s failed get from url %s with status code %d'
ChetanGaonker2099d722016-10-07 15:16:58 -07001883 %(subscriber.name, url, resp.status_code))
1884 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001885 log_test.info('GET request from %s succeeded for subscriber %s'
ChetanGaonker2099d722016-10-07 15:16:58 -07001886 %(url, subscriber.name))
1887 return self.test_status
1888
1889 def tls_verify(self, subscriber):
1890 if subscriber.has_service('TLS'):
1891 time.sleep(2)
1892 tls = TLSAuthTest(intf = subscriber.rx_intf)
A R Karthick76a497a2017-04-12 10:59:39 -07001893 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07001894 tls.runTest()
1895 self.test_status = True
1896 return self.test_status
1897 else:
1898 self.test_status = True
1899 return self.test_status
1900 def dhcp_verify(self, subscriber):
1901 if subscriber.has_service('DHCP'):
1902 cip, sip = self.dhcp_request(subscriber, update_seed = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001903 log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07001904 subscriber.src_list = [cip]
1905 self.test_status = True
1906 return self.test_status
1907 else:
1908 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
1909 self.test_status = True
1910 return self.test_status
1911
1912 def dhcp_jump_verify(self, subscriber):
1913 if subscriber.has_service('DHCP'):
1914 cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1')
A R Karthick76a497a2017-04-12 10:59:39 -07001915 log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07001916 subscriber.src_list = [cip]
1917 self.test_status = True
1918 return self.test_status
1919 else:
1920 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
1921 self.test_status = True
1922 return self.test_status
1923
1924 def dhcp_next_verify(self, subscriber):
1925 if subscriber.has_service('DHCP'):
1926 cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.150.1')
A R Karthick76a497a2017-04-12 10:59:39 -07001927 log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07001928 subscriber.src_list = [cip]
1929 self.test_status = True
1930 return self.test_status
1931 else:
1932 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
1933 self.test_status = True
1934 return self.test_status
1935 def igmp_verify(self, subscriber):
1936 chan = 0
1937 if subscriber.has_service('IGMP'):
1938 ##We wait for all the subscribers to join before triggering leaves
1939 if subscriber.rx_port > 1:
1940 time.sleep(5)
1941 subscriber.channel_join(chan, delay = 0)
1942 self.num_joins += 1
1943 while self.num_joins < self.num_subscribers:
1944 time.sleep(5)
A R Karthick76a497a2017-04-12 10:59:39 -07001945 log_test.info('All subscribers have joined the channel')
ChetanGaonker2099d722016-10-07 15:16:58 -07001946 for i in range(10):
1947 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10)
A R Karthick76a497a2017-04-12 10:59:39 -07001948 log_test.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001949 subscriber.channel_leave(chan)
1950 time.sleep(5)
A R Karthick76a497a2017-04-12 10:59:39 -07001951 log_test.info('Interface %s Join RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name,subscriber.join_rx_stats))
ChetanGaonker2099d722016-10-07 15:16:58 -07001952 #Should not receive packets for this subscriber
1953 self.recv_timeout = True
1954 subscriber.recv_timeout = True
1955 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10)
1956 subscriber.recv_timeout = False
1957 self.recv_timeout = False
A R Karthick76a497a2017-04-12 10:59:39 -07001958 log_test.info('Joining channel %d for subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001959 subscriber.channel_join(chan, delay = 0)
1960 self.test_status = True
1961 return self.test_status
1962
1963 def igmp_jump_verify(self, subscriber):
1964 if subscriber.has_service('IGMP'):
1965 for i in xrange(subscriber.num):
A R Karthick76a497a2017-04-12 10:59:39 -07001966 log_test.info('Subscriber %s jumping channel' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07001967 chan = subscriber.channel_jump(delay=0)
1968 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1)
A R Karthick76a497a2017-04-12 10:59:39 -07001969 log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001970 time.sleep(3)
A R Karthick76a497a2017-04-12 10:59:39 -07001971 log_test.info('Interface %s Jump RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats))
ChetanGaonker2099d722016-10-07 15:16:58 -07001972 self.test_status = True
1973 return self.test_status
1974 def igmp_next_verify(self, subscriber):
1975 if subscriber.has_service('IGMP'):
1976 for i in xrange(subscriber.num):
1977 if i:
1978 chan = subscriber.channel_join_next(delay=0)
1979 else:
1980 chan = subscriber.channel_join(i, delay=0)
A R Karthick76a497a2017-04-12 10:59:39 -07001981 log_test.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001982 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1)
A R Karthick76a497a2017-04-12 10:59:39 -07001983 log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001984 time.sleep(3)
A R Karthick76a497a2017-04-12 10:59:39 -07001985 log_test.info('Interface %s Join Next RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats))
ChetanGaonker2099d722016-10-07 15:16:58 -07001986 self.test_status = True
1987 return self.test_status
1988
1989 def generate_port_list(self, subscribers, channels):
1990 return self.port_list[:subscribers]
1991
ChetanGaonker689b3862016-10-17 16:25:01 -07001992 def subscriber_load(self, create = True, num = 10, num_channels = 1, channel_start = 0, port_list = [],controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001993 '''Load the subscriber from the database'''
1994 self.subscriber_db = SubscriberDB(create = create, services = self.test_services)
1995 if create is True:
1996 self.subscriber_db.generate(num)
1997 self.subscriber_info = self.subscriber_db.read(num)
1998 self.subscriber_list = []
1999 if not port_list:
2000 port_list = self.generate_port_list(num, num_channels)
2001
2002 index = 0
2003 for info in self.subscriber_info:
2004 self.subscriber_list.append(Subscriber(name=info['Name'],
2005 service=info['Service'],
2006 port_map = self.port_map,
2007 num=num_channels,
2008 channel_start = channel_start,
2009 tx_port = port_list[index][0],
2010 rx_port = port_list[index][1]))
2011 if num_channels > 1:
2012 channel_start += num_channels
2013 index += 1
2014
2015 #load the ssm list for all subscriber channels
ChetanGaonker689b3862016-10-17 16:25:01 -07002016 igmpChannel = IgmpChannel(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07002017 ssm_groups = map(lambda sub: sub.channels, self.subscriber_list)
2018 ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups)
2019 igmpChannel.igmp_load_ssm_config(ssm_list)
2020 def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1,
ChetanGaonker689b3862016-10-17 16:25:01 -07002021 channel_start = 0, cbs = None, port_list = [], negative_subscriber_auth = None,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07002022 log_test.info('controller ip in cluster.py subscriber_join_verify is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07002023 self.test_status = False
2024 self.ovs_cleanup()
2025 subscribers_count = num_subscribers
2026 sub_loop_count = num_subscribers
2027 self.subscriber_load(create = True, num = num_subscribers,
ChetanGaonker689b3862016-10-17 16:25:01 -07002028 num_channels = num_channels, channel_start = channel_start, port_list = port_list,controller=controller)
2029 self.onos_aaa_load(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07002030 self.thread_pool = ThreadPool(min(100, subscribers_count), queue_size=1, wait_timeout=1)
2031
2032 chan_leave = False #for single channel, multiple subscribers
2033 if None in (cbs, negative_subscriber_auth):
2034 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
2035 chan_leave = True
2036 cbs_negative = cbs
2037 for subscriber in self.subscriber_list:
2038 subscriber.start()
2039 if negative_subscriber_auth is 'half' and sub_loop_count%2 is not 0:
2040 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
2041 elif negative_subscriber_auth is 'onethird' and sub_loop_count%3 is not 0:
2042 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
2043 else:
2044 cbs = cbs_negative
2045 sub_loop_count = sub_loop_count - 1
2046 pool_object = subscriber_pool(subscriber, cbs)
2047 self.thread_pool.addTask(pool_object.pool_cb)
2048 self.thread_pool.cleanUpThreads()
2049 for subscriber in self.subscriber_list:
2050 subscriber.stop()
2051 if chan_leave is True:
2052 subscriber.channel_leave(0)
2053 subscribers_count = 0
2054 return self.test_status
2055 def tls_invalid_cert(self, subscriber):
2056 if subscriber.has_service('TLS'):
2057 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002058 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002059 tls = TLSAuthTest(client_cert = self.CLIENT_CERT_INVALID)
2060 tls.runTest()
2061 if tls.failTest == True:
2062 self.test_status = False
2063 return self.test_status
2064 else:
2065 self.test_status = True
2066 return self.test_status
2067
2068 def tls_no_cert(self, subscriber):
2069 if subscriber.has_service('TLS'):
2070 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002071 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002072 tls = TLSAuthTest(client_cert = '')
2073 tls.runTest()
2074 if tls.failTest == True:
2075 self.test_status = False
2076 return self.test_status
2077 else:
2078 self.test_status = True
2079 return self.test_status
2080
2081 def tls_self_signed_cert(self, subscriber):
2082 if subscriber.has_service('TLS'):
2083 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002084 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002085 tls = TLSAuthTest(client_cert = self.CLIENT_CERT)
2086 tls.runTest()
2087 if tls.failTest == False:
2088 self.test_status = True
2089 return self.test_status
2090 else:
2091 self.test_status = True
2092 return self.test_status
2093
2094 def tls_non_ca_authrized_cert(self, subscriber):
2095 if subscriber.has_service('TLS'):
2096 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002097 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002098 tls = TLSAuthTest(client_cert = self.CLIENT_CERT_NON_CA_AUTHORIZED)
2099 tls.runTest()
2100 if tls.failTest == False:
2101 self.test_status = True
2102 return self.test_status
2103 else:
2104 self.test_status = True
2105 return self.test_status
2106 def tls_Nsubscribers_use_same_valid_cert(self, subscriber):
2107 if subscriber.has_service('TLS'):
2108 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002109 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002110 num_users = 3
2111 for i in xrange(num_users):
2112 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
2113 tls.runTest()
2114 if tls.failTest == False:
2115 self.test_status = True
2116 return self.test_status
2117 else:
2118 self.test_status = True
2119 return self.test_status
2120
2121 def dhcp_discover_scenario(self, subscriber):
2122 if subscriber.has_service('DHCP'):
2123 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002124 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002125 t1 = self.subscriber_dhcp_1release()
2126 self.test_status = True
2127 return self.test_status
2128 else:
2129 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2130 self.test_status = True
2131 return self.test_status
2132
2133 def subscriber_dhcp_1release(self, iface = INTF_RX_DEFAULT):
2134 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
2135 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
2136 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
2137 self.onos_dhcp_table_load(config)
2138 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
2139 cip, sip = self.send_recv()
A R Karthick76a497a2017-04-12 10:59:39 -07002140 log_test.info('Releasing ip %s to server %s' %(cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07002141 assert_equal(self.dhcp.release(cip), True)
A R Karthick76a497a2017-04-12 10:59:39 -07002142 log_test.info('Triggering DHCP discover again after release')
ChetanGaonker2099d722016-10-07 15:16:58 -07002143 cip2, sip2 = self.send_recv(update_seed = True)
A R Karthick76a497a2017-04-12 10:59:39 -07002144 log_test.info('Verifying released IP was given back on rediscover')
ChetanGaonker2099d722016-10-07 15:16:58 -07002145 assert_equal(cip, cip2)
A R Karthick76a497a2017-04-12 10:59:39 -07002146 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
ChetanGaonker2099d722016-10-07 15:16:58 -07002147 assert_equal(self.dhcp.release(cip2), True)
2148 def dhcp_client_reboot_scenario(self, subscriber):
2149 if subscriber.has_service('DHCP'):
2150 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002151 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002152 tl = self.subscriber_dhcp_client_request_after_reboot()
2153 self.test_status = True
2154 return self.test_status
2155 else:
2156 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2157 self.test_status = True
2158 return self.test_status
2159
2160 def subscriber_dhcp_client_request_after_reboot(self, iface = INTF_RX_DEFAULT):
2161 #''' Client sends DHCP Request after reboot.'''
2162
2163 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2164 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2165 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2166 self.onos_dhcp_table_load(config)
2167 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2168 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002169 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002170 (cip, sip, mac) )
2171
A R Karthick76a497a2017-04-12 10:59:39 -07002172 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002173
2174 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002175 log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002176 assert_not_equal(cip, None)
2177
2178 else:
2179 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2180 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002181 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002182 os.system('ifconfig '+iface+' down')
A R Karthick76a497a2017-04-12 10:59:39 -07002183 log_test.info('Client goes down.')
2184 log_test.info('Delay for 5 seconds.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002185
2186 time.sleep(5)
2187
2188 os.system('ifconfig '+iface+' up')
A R Karthick76a497a2017-04-12 10:59:39 -07002189 log_test.info('Client is up now.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002190
2191 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2192 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002193 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002194 assert_not_equal(new_cip, None)
2195 elif new_cip != None:
A R Karthick76a497a2017-04-12 10:59:39 -07002196 log_test.info("Got DHCP ACK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002197 def dhcp_client_renew_scenario(self, subscriber):
2198 if subscriber.has_service('DHCP'):
2199 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002200 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002201 tl = self.subscriber_dhcp_client_renew_time()
2202 self.test_status = True
2203 return self.test_status
2204 else:
2205 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2206 self.test_status = True
2207 return self.test_status
2208
2209 def subscriber_dhcp_client_renew_time(self, iface = INTF_RX_DEFAULT):
2210 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2211 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2212 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2213 self.onos_dhcp_table_load(config)
2214 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2215 cip, sip, mac , lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002216 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002217 (cip, sip, mac) )
2218
A R Karthick76a497a2017-04-12 10:59:39 -07002219 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002220 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002221 log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002222 assert_not_equal(cip, None)
2223 elif cip and sip and mac:
A R Karthick76a497a2017-04-12 10:59:39 -07002224 log_test.info("Triggering DHCP Request.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002225 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
2226 if new_cip and new_sip and lval:
A R Karthick76a497a2017-04-12 10:59:39 -07002227 log_test.info("Client 's Renewal time is :%s",lval)
2228 log_test.info("Generating delay till renewal time.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002229 time.sleep(lval)
A R Karthick76a497a2017-04-12 10:59:39 -07002230 log_test.info("Client Sending Unicast DHCP request.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002231 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
2232 if latest_cip and latest_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002233 log_test.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
ChetanGaonker2099d722016-10-07 15:16:58 -07002234 (latest_cip, mac, latest_sip) )
2235
2236 elif latest_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002237 log_test.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002238 elif new_cip == None or new_sip == None or lval == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002239 log_test.info("Got DHCP NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002240 def dhcp_server_reboot_scenario(self, subscriber):
2241 if subscriber.has_service('DHCP'):
2242 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002243 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002244 tl = self.subscriber_dhcp_server_after_reboot()
2245 self.test_status = True
2246 return self.test_status
2247 else:
2248 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2249 self.test_status = True
2250 return self.test_status
2251 def subscriber_dhcp_server_after_reboot(self, iface = INTF_RX_DEFAULT):
2252 ''' DHCP server goes down.'''
2253 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2254 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2255 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2256 self.onos_dhcp_table_load(config)
2257 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2258 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002259 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002260 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002261 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002262 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002263 log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002264 assert_not_equal(cip, None)
2265 else:
2266 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2267 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002268 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002269 assert_not_equal(new_cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -07002270 log_test.info('Getting DHCP server Down.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002271 onos_ctrl = OnosCtrl(self.dhcp_app)
2272 onos_ctrl.deactivate()
2273 for i in range(0,4):
A R Karthick76a497a2017-04-12 10:59:39 -07002274 log_test.info("Sending DHCP Request.")
2275 log_test.info('')
ChetanGaonker2099d722016-10-07 15:16:58 -07002276 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2277 if new_cip == None and new_sip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002278 log_test.info('')
2279 log_test.info("DHCP Request timed out.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002280 elif new_cip and new_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002281 log_test.info("Got Reply from DHCP server.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002282 assert_equal(new_cip,None) #Neagtive Test Case
A R Karthick76a497a2017-04-12 10:59:39 -07002283 log_test.info('Getting DHCP server Up.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002284# self.activate_apps(self.dhcp_app)
2285 onos_ctrl = OnosCtrl(self.dhcp_app)
2286 status, _ = onos_ctrl.activate()
2287 assert_equal(status, True)
2288 time.sleep(3)
2289 for i in range(0,4):
A R Karthick76a497a2017-04-12 10:59:39 -07002290 log_test.info("Sending DHCP Request after DHCP server is up.")
2291 log_test.info('')
ChetanGaonker2099d722016-10-07 15:16:58 -07002292 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2293 if new_cip == None and new_sip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002294 log_test.info('')
2295 log_test.info("DHCP Request timed out.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002296 elif new_cip and new_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002297 log_test.info("Got Reply from DHCP server.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002298 assert_equal(new_cip,None) #Neagtive Test Case
2299 def dhcp_client_rebind_scenario(self, subscriber):
2300 if subscriber.has_service('DHCP'):
2301 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002302 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002303 tl = self.subscriber_dhcp_client_rebind_time()
2304 self.test_status = True
2305 return self.test_status
2306 else:
2307 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2308 self.test_status = True
2309 return self.test_status
2310
2311 def subscriber_dhcp_client_rebind_time(self, iface = INTF_RX_DEFAULT):
2312 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2313 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2314 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2315 self.onos_dhcp_table_load(config)
2316 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2317 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002318 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002319 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002320 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002321 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002322 log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002323 assert_not_equal(cip, None)
2324 elif cip and sip and mac:
A R Karthick76a497a2017-04-12 10:59:39 -07002325 log_test.info("Triggering DHCP Request.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002326 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
2327 if new_cip and new_sip and lval:
A R Karthick76a497a2017-04-12 10:59:39 -07002328 log_test.info("Client 's Rebind time is :%s",lval)
2329 log_test.info("Generating delay till rebind time.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002330 time.sleep(lval)
A R Karthick76a497a2017-04-12 10:59:39 -07002331 log_test.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002332 self.dhcp.after_T2 = True
2333 for i in range(0,4):
2334 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
2335 if latest_cip and latest_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002336 log_test.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
ChetanGaonker2099d722016-10-07 15:16:58 -07002337 (latest_cip, mac, latest_sip) )
2338 break
2339 elif latest_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002340 log_test.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002341 assert_not_equal(latest_cip, None)
2342 elif new_cip == None or new_sip == None or lval == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002343 log_test.info("Got DHCP NAK.Lease not Renewed.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002344 def dhcp_starvation_scenario(self, subscriber):
2345 if subscriber.has_service('DHCP'):
2346 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002347 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002348 tl = self.subscriber_dhcp_starvation()
2349 self.test_status = True
2350 return self.test_status
2351 else:
2352 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2353 self.test_status = True
2354 return self.test_status
2355
2356 def subscriber_dhcp_starvation(self, iface = INTF_RX_DEFAULT):
2357 '''DHCP starve'''
2358 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
2359 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
2360 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
2361 self.onos_dhcp_table_load(config)
2362 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07002363 log_test.info('Verifying 1 ')
ChetanGaonker2099d722016-10-07 15:16:58 -07002364 for x in xrange(50):
2365 mac = RandMAC()._fix()
2366 self.send_recv(mac = mac)
A R Karthick76a497a2017-04-12 10:59:39 -07002367 log_test.info('Verifying 2 ')
ChetanGaonker2099d722016-10-07 15:16:58 -07002368 cip, sip = self.send_recv(update_seed = True, validate = False)
2369 assert_equal(cip, None)
2370 assert_equal(sip, None)
2371
2372 def dhcp_same_client_multi_discovers_scenario(self, subscriber):
2373 if subscriber.has_service('DHCP'):
2374 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002375 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002376 tl = self.subscriber_dhcp_same_client_multiple_discover()
2377 self.test_status = True
2378 return self.test_status
2379 else:
2380 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2381 self.test_status = True
2382 return self.test_status
2383 def subscriber_dhcp_same_client_multiple_discover(self, iface = INTF_RX_DEFAULT):
2384 ''' DHCP Client sending multiple discover . '''
2385 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
2386 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
2387 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
2388 self.onos_dhcp_table_load(config)
2389 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2390 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002391 log_test.info('Got dhcp client IP %s from server %s for mac %s . Not going to send DHCPREQUEST.' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002392 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002393 log_test.info('Triggering DHCP discover again.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002394 new_cip, new_sip, new_mac , lval = self.dhcp.only_discover()
2395 if cip == new_cip:
A R Karthick76a497a2017-04-12 10:59:39 -07002396 log_test.info('Got same ip for 2nd DHCP discover for client IP %s from server %s for mac %s. Triggering DHCP Request. '
ChetanGaonker2099d722016-10-07 15:16:58 -07002397 % (new_cip, new_sip, new_mac) )
2398 elif cip != new_cip:
A R Karthick76a497a2017-04-12 10:59:39 -07002399 log_test.info('Ip after 1st discover %s' %cip)
2400 log_test.info('Map after 2nd discover %s' %new_cip)
ChetanGaonker2099d722016-10-07 15:16:58 -07002401 assert_equal(cip, new_cip)
2402
2403 def dhcp_same_client_multi_request_scenario(self, subscriber):
2404 if subscriber.has_service('DHCP'):
2405 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002406 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002407 tl = self.subscriber_dhcp_same_client_multiple_request()
2408 self.test_status = True
2409 return self.test_status
2410 else:
2411 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2412 self.test_status = True
2413 return self.test_status
2414 def subscriber_dhcp_same_client_multiple_request(self, iface = INTF_RX_DEFAULT):
2415 ''' DHCP Client sending multiple repeat DHCP requests. '''
2416 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
2417 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
2418 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
2419 self.onos_dhcp_table_load(config)
2420 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07002421 log_test.info('Sending DHCP discover and DHCP request.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002422 cip, sip = self.send_recv()
2423 mac = self.dhcp.get_mac(cip)[0]
A R Karthick76a497a2017-04-12 10:59:39 -07002424 log_test.info("Sending DHCP request again.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002425 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2426 if (new_cip,new_sip) == (cip,sip):
A R Karthick76a497a2017-04-12 10:59:39 -07002427 log_test.info('Got same ip for 2nd DHCP Request for client IP %s from server %s for mac %s.'
ChetanGaonker2099d722016-10-07 15:16:58 -07002428 % (new_cip, new_sip, mac) )
2429 elif (new_cip,new_sip):
A R Karthick76a497a2017-04-12 10:59:39 -07002430 log_test.info('No DHCP ACK')
ChetanGaonker2099d722016-10-07 15:16:58 -07002431 assert_equal(new_cip, None)
2432 assert_equal(new_sip, None)
2433 else:
2434 print "Something went wrong."
2435
2436 def dhcp_client_desired_ip_scenario(self, subscriber):
2437 if subscriber.has_service('DHCP'):
2438 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002439 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002440 tl = self.subscriber_dhcp_client_desired_address()
2441 self.test_status = True
2442 return self.test_status
2443 else:
2444 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2445 self.test_status = True
2446 return self.test_status
2447
2448 def subscriber_dhcp_client_desired_address(self, iface = INTF_RX_DEFAULT):
2449 '''DHCP Client asking for desired IP address.'''
2450 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2451 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2452 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2453 self.onos_dhcp_table_load(config)
2454 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface)
2455 cip, sip, mac , lval = self.dhcp.only_discover(desired = True)
A R Karthick76a497a2017-04-12 10:59:39 -07002456 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002457 (cip, sip, mac) )
2458 if cip == self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002459 log_test.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002460 (cip, sip, mac) )
2461 elif cip != self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002462 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002463 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002464 log_test.info('The desired ip was: %s .' % self.dhcp.seed_ip)
ChetanGaonker2099d722016-10-07 15:16:58 -07002465 assert_equal(cip, self.dhcp.seed_ip)
2466 def dhcp_client_request_pkt_with_non_offered_ip_scenario(self, subscriber):
2467 if subscriber.has_service('DHCP'):
2468 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002469 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002470 tl = self.subscriber_dhcp_server_nak_packet()
2471 self.test_status = True
2472 return self.test_status
2473 else:
2474 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2475 self.test_status = True
2476 return self.test_status
2477
2478 def subscriber_dhcp_server_nak_packet(self, iface = INTF_RX_DEFAULT):
2479 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2480 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2481 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2482 self.onos_dhcp_table_load(config)
2483 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2484 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002485 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002486 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002487 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet. Those should not be none, which is expected.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002488 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002489 log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002490 assert_not_equal(cip, None)
2491 else:
2492 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
2493 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002494 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002495 assert_equal(new_cip, None) #Negative Test Case
2496
2497 def dhcp_client_requested_out_pool_ip_scenario(self, subscriber):
2498 if subscriber.has_service('DHCP'):
2499 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002500 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002501 tl = self.subscriber_dhcp_client_desired_address_out_of_pool()
2502 self.test_status = True
2503 return self.test_status
2504 else:
2505 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2506 self.test_status = True
2507 return self.test_status
2508 def subscriber_dhcp_client_desired_address_out_of_pool(self, iface = INTF_RX_DEFAULT):
2509 '''DHCP Client asking for desired IP address from out of pool.'''
2510 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2511 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2512 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2513 self.onos_dhcp_table_load(config)
2514 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
2515 cip, sip, mac, lval = self.dhcp.only_discover(desired = True)
A R Karthick76a497a2017-04-12 10:59:39 -07002516 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002517 (cip, sip, mac) )
2518 if cip == self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002519 log_test.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002520 (cip, sip, mac) )
2521 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
2522
2523 elif cip != self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002524 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002525 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002526 log_test.info('The desired ip was: %s .' % self.dhcp.seed_ip)
ChetanGaonker2099d722016-10-07 15:16:58 -07002527 assert_not_equal(cip, self.dhcp.seed_ip)
2528
2529 elif cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002530 log_test.info('Got DHCP NAK')
ChetanGaonker2099d722016-10-07 15:16:58 -07002531
2532 def dhcp_client_specific_lease_scenario(self, subscriber):
2533 if subscriber.has_service('DHCP'):
2534 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002535 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002536 tl = self.subscriber_dhcp_specific_lease_packet()
2537 self.test_status = True
2538 return self.test_status
2539 else:
2540 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2541 self.test_status = True
2542 return self.test_status
ChetanGaonker2099d722016-10-07 15:16:58 -07002543 def subscriber_dhcp_specific_lease_packet(self, iface = INTF_RX_DEFAULT):
2544 ''' Client sends DHCP Discover packet for particular lease time.'''
2545 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2546 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2547 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2548 self.onos_dhcp_table_load(config)
2549 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07002550 log_test.info('Sending DHCP discover with lease time of 700')
ChetanGaonker2099d722016-10-07 15:16:58 -07002551 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
2552
A R Karthick76a497a2017-04-12 10:59:39 -07002553 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002554 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002555 log_test.info("Verified that Client 's IP and mac in DHCP Offer packet are none, which is not expected behavior.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002556 assert_not_equal(cip, None)
2557 elif lval != 700:
A R Karthick76a497a2017-04-12 10:59:39 -07002558 log_test.info('Getting dhcp client IP %s from server %s for mac %s with lease time %s. That is not 700.' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002559 (cip, sip, mac, lval) )
2560 assert_not_equal(lval, 700)