blob: 5e248ec1ff1fe8a7af1e2d9ab76613bc5de72381 [file] [log] [blame]
ChetanGaonker2099d722016-10-07 15:16:58 -07001import unittest
2from twisted.internet import defer
3from nose.tools import *
4from IGMP import *
5from ACL import ACLTest
6from DHCP import DHCPTest
7from Channels import Channels, IgmpChannel
8from subscriberDb import SubscriberDB
9import time, monotonic
A R Karthick76a497a2017-04-12 10:59:39 -070010from CordTestUtils import get_mac, log_test
ChetanGaonker2099d722016-10-07 15:16:58 -070011from OltConfig import OltConfig
A.R Karthickbe7768c2017-03-17 11:39:41 -070012from OnosCtrl import OnosCtrl
ChetanGaonker2099d722016-10-07 15:16:58 -070013from OnosFlowCtrl import OnosFlowCtrl
14from CordContainer import Container, Onos, Quagga
15from onosclidriver import OnosCliDriver
16from CordTestServer import CordTestServer, cord_test_onos_restart, cord_test_quagga_restart,cord_test_quagga_stop, cord_test_quagga_shell,cord_test_shell
17from portmaps import g_subscriber_port_map
18import time, monotonic
19from scapy_ssl_tls.ssl_tls import *
20from scapy_ssl_tls.ssl_tls_crypto import *
21import os
22import json
23from socket import socket
24import pexpect
25from Stats import Stats
A.R Karthick2e99c472017-03-22 19:13:51 -070026import logging
27logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
ChetanGaonker2099d722016-10-07 15:16:58 -070028from scapy.all import *
29from OnosFlowCtrl import OnosFlowCtrl
30from nose.twistedtools import reactor, deferred
31import tempfile
32import threading
33from threading import current_thread
34from threadPool import ThreadPool
35import random
36import collections
37import requests
A R Karthick76a497a2017-04-12 10:59:39 -070038log_test.setLevel('INFO')
ChetanGaonker2099d722016-10-07 15:16:58 -070039class cluster_igmp(object):
40 V_INF1 = 'veth0'
41 V_INF2 = 'veth1'
42 MGROUP1 = '239.1.2.3'
43 MGROUP2 = '239.2.2.3'
44 MINVALIDGROUP1 = '255.255.255.255'
45 MINVALIDGROUP2 = '239.255.255.255'
46 MMACGROUP1 = "01:00:5e:01:02:03"
47 MMACGROUP2 = "01:00:5e:02:02:03"
48 IGMP_DST_MAC = "01:00:5e:00:00:16"
49 IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1"
50 IP_SRC = '1.2.3.4'
51 IP_DST = '224.0.0.22'
52 NEGATIVE_TRAFFIC_STATUS = 1
53 igmp_eth = Ether(dst = IGMP_DST_MAC, type = ETH_P_IP)
54 igmp_ip = IP(dst = IP_DST)
55 IGMP_TEST_TIMEOUT = 5
56 IGMP_QUERY_TIMEOUT = 60
57 MCAST_TRAFFIC_TIMEOUT = 10
58 PORT_TX_DEFAULT = 2
59 PORT_RX_DEFAULT = 1
60 max_packets = 100
61 app = 'org.opencord.igmp'
62 olt_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json')
63 ROVER_TEST_TIMEOUT = 300 #3600*86
64 ROVER_TIMEOUT = (ROVER_TEST_TIMEOUT - 100)
65 ROVER_JOIN_TIMEOUT = 60
66
67 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -070068 def setUpClass(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -070069 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
70 cls.port_map, _ = cls.olt.olt_port_map()
A R Karthick0f6b6842016-12-06 17:17:44 -080071 OnosCtrl.cord_olt_config(cls.olt, controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070072
73 @classmethod
74 def tearDownClass(cls): pass
75
ChetanGaonker689b3862016-10-17 16:25:01 -070076 def setUp(self,controller=None):
77 self.setUpClass(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070078 self.get_igmp_intf()
79 ''' Activate the igmp app'''
ChetanGaonker689b3862016-10-17 16:25:01 -070080 self.onos_ctrl = OnosCtrl(self.app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070081 self.onos_ctrl.activate()
ChetanGaonker689b3862016-10-17 16:25:01 -070082 self.igmp_channel = IgmpChannel(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070083
84 def tearDown(self): pass
85
ChetanGaonker689b3862016-10-17 16:25:01 -070086 def onos_load_config(self, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -070087 log_test.info('onos load config is %s'%config)
ChetanGaonker689b3862016-10-17 16:25:01 -070088 status, code = OnosCtrl(self.app).config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -070089 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -070090 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -070091 assert_equal(status, True)
92 time.sleep(2)
93
ChetanGaonker689b3862016-10-17 16:25:01 -070094 def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],controller=None,flag = False):
ChetanGaonker2099d722016-10-07 15:16:58 -070095 ssm_dict = {'apps' : { 'org.onosproject.igmp' : { 'ssmTranslate' : [] } } }
96 ssm_xlate_list = ssm_dict['apps']['org.onosproject.igmp']['ssmTranslate']
97 if flag: #to maintain seperate group-source pair.
98 for i in range(len(groups)):
99 d = {}
100 d['source'] = src_list[i] or '0.0.0.0'
101 d['group'] = groups[i]
102 ssm_xlate_list.append(d)
103 else:
104 for g in groups:
105 for s in src_list:
106 d = {}
107 d['source'] = s or '0.0.0.0'
108 d['group'] = g
109 ssm_xlate_list.append(d)
ChetanGaonker689b3862016-10-17 16:25:01 -0700110 self.onos_load_config(ssm_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700111 cord_port_map = {}
112 for g in groups:
113 cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT)
114 self.igmp_channel.cord_port_table_load(cord_port_map)
115 time.sleep(2)
116
117 def mcast_ip_range(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'):
118 start = list(map(int, start_ip.split(".")))
119 end = list(map(int, end_ip.split(".")))
120 temp = start
121 ip_range = []
122 ip_range.append(start_ip)
123 while temp != end:
124 start[3] += 1
125 for i in (3, 2, 1):
126 if temp[i] == 255:
127 temp[i] = 0
128 temp[i-1] += 1
129 ip_range.append(".".join(map(str, temp)))
130 return ip_range
131
132 def random_mcast_ip(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'):
133 start = list(map(int, start_ip.split(".")))
134 end = list(map(int, end_ip.split(".")))
135 temp = start
136 ip_range = []
137 ip_range.append(start_ip)
138 while temp != end:
139 start[3] += 1
140 for i in (3, 2, 1):
141 if temp[i] == 255:
142 temp[i] = 0
143 temp[i-1] += 1
144 ip_range.append(".".join(map(str, temp)))
145 return random.choice(ip_range)
146
147 def source_ip_range(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
148 start = list(map(int, start_ip.split(".")))
149 end = list(map(int, end_ip.split(".")))
150 temp = start
151 ip_range = []
152 ip_range.append(start_ip)
153 while temp != end:
154 start[3] += 1
155 for i in (3, 2, 1):
156 if temp[i] == 255:
157 temp[i] = 0
158 temp[i-1] += 1
159 ip_range.append(".".join(map(str, temp)))
160 return ip_range
161 def iptomac(self, mcast_ip):
162 mcast_mac = '01:00:5e:'
163 octets = mcast_ip.split('.')
164 second_oct = int(octets[1]) & 127
165 third_oct = int(octets[2])
166 fourth_oct = int(octets[3])
167 mcast_mac = mcast_mac + format(second_oct,'02x') + ':' + format(third_oct, '02x') + ':' + format(fourth_oct, '02x')
168 return mcast_mac
169
170 def randomsourceip(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
171 start = list(map(int, start_ip.split(".")))
172 end = list(map(int, end_ip.split(".")))
173 temp = start
174 ip_range = []
175 ip_range.append(start_ip)
176 while temp != end:
177 start[3] += 1
178 for i in (3, 2, 1):
179 if temp[i] == 255:
180 temp[i] = 0
181 temp[i-1] += 1
182 ip_range.append(".".join(map(str, temp)))
183 return random.choice(ip_range)
184
185 def get_igmp_intf(self):
186 inst = os.getenv('TEST_INSTANCE', None)
187 if not inst:
188 return 'veth0'
189 inst = int(inst) + 1
190 if inst >= self.port_map['uplink']:
191 inst += 1
192 if self.port_map.has_key(inst):
193 return self.port_map[inst]
194 return 'veth0'
195
196 def igmp_verify_join(self, igmpStateList):
197 sendState, recvState = igmpStateList
198 ## check if the send is received for the groups
199 for g in sendState.groups:
200 tx_stats = sendState.group_map[g][0]
201 tx = tx_stats.count
202 assert_greater(tx, 0)
203 rx_stats = recvState.group_map[g][1]
204 rx = rx_stats.count
205 assert_greater(rx, 0)
A R Karthick76a497a2017-04-12 10:59:39 -0700206 log_test.info('Receive stats %s for group %s' %(rx_stats, g))
ChetanGaonker2099d722016-10-07 15:16:58 -0700207
A R Karthick76a497a2017-04-12 10:59:39 -0700208 log_test.info('IGMP test verification success')
ChetanGaonker2099d722016-10-07 15:16:58 -0700209
210 def igmp_verify_leave(self, igmpStateList, leave_groups):
211 sendState, recvState = igmpStateList[0], igmpStateList[1]
212 ## check if the send is received for the groups
213 for g in sendState.groups:
214 tx_stats = sendState.group_map[g][0]
215 rx_stats = recvState.group_map[g][1]
216 tx = tx_stats.count
217 rx = rx_stats.count
218 assert_greater(tx, 0)
219 if g not in leave_groups:
A R Karthick76a497a2017-04-12 10:59:39 -0700220 log_test.info('Received %d packets for group %s' %(rx, g))
ChetanGaonker2099d722016-10-07 15:16:58 -0700221 for g in leave_groups:
222 rx = recvState.group_map[g][1].count
223 assert_equal(rx, 0)
224
A R Karthick76a497a2017-04-12 10:59:39 -0700225 log_test.info('IGMP test verification success')
ChetanGaonker2099d722016-10-07 15:16:58 -0700226
227 def mcast_traffic_timer(self):
228 self.mcastTraffic.stopReceives()
229
230 def send_mcast_cb(self, send_state):
231 for g in send_state.groups:
232 send_state.update(g, tx = 1)
233 return 0
234
235 ##Runs in the context of twisted reactor thread
236 def igmp_recv(self, igmpState, iface = 'veth0'):
237 p = self.recv_socket.recv()
238 try:
239 send_time = float(p.payload.load)
240 recv_time = monotonic.monotonic()
241 except:
A R Karthick76a497a2017-04-12 10:59:39 -0700242 log_test.info('Unexpected Payload received: %s' %p.payload.load)
ChetanGaonker2099d722016-10-07 15:16:58 -0700243 return 0
A R Karthick76a497a2017-04-12 10:59:39 -0700244 #log_test.info( 'Recv in %.6f secs' %(recv_time - send_time))
ChetanGaonker2099d722016-10-07 15:16:58 -0700245 igmpState.update(p.dst, rx = 1, t = recv_time - send_time)
246 return 0
247
248 def send_igmp_join(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE,
249 ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1):
250 if ssm_load is True:
251 self.onos_ssm_table_load(groups, src_list)
252 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
253 gaddr=self.IP_DST)
254 for g in groups:
255 gr = IGMPv3gr(rtype= record_type, mcaddr=g)
256 gr.sources = src_list
257 igmp.grps.append(gr)
258 if ip_pkt is None:
259 ip_pkt = self.igmp_eth/self.igmp_ip
260 pkt = ip_pkt/igmp
261 IGMPv3.fixup(pkt)
262 sendp(pkt, iface=iface)
A R Karthick76a497a2017-04-12 10:59:39 -0700263 log_test.info('igmp join packet is %s'%pkt.show())
ChetanGaonker2099d722016-10-07 15:16:58 -0700264 if delay != 0:
265 time.sleep(delay)
266
267class cluster_tls():
268 eap_app = 'org.opencord.aaa'
269 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
270MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
271VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE
272ChMKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
273JAYDVQQDEx1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjAzMTEx
274ODUzMzVaFw0xNzAzMDYxODUzMzVaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECBMC
275Q0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UEChMKQ2llbmEgSW5jLjEeMBwG
276CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDEx1FeGFtcGxlIENl
277cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
278ggEBAL9Jv54TkqycL3U2Fdd/y5NXdnPVXwAVV3m6I3eIffVCv8eS+mwlbl9dnbjo
279qqlGEgA3sEg5HtnKoW81l3PSyV/YaqzUzbcpDlgWlbNkFQ3nVxh61gSU34Fc4h/W
280plSvCkwGSbV5udLtEe6S9IflP2Fu/eXa9vmUtoPqDk66p9U/nWVf2H1GJy7XanWg
281wke+HpQvbzoSfPJS0e5Rm9KErrzaIkJpqt7soW+OjVJitUax7h45RYY1HHHlbMQ0
282ndWW8UDsCxFQO6d7nsijCzY69Y8HarH4mbVtqhg3KJevxD9UMRy6gdtPMDZLah1c
283LHRu14ucOK4aF8oICOgtcD06auUCAwEAAaOCASwwggEoMB0GA1UdDgQWBBQwEs0m
284c8HARTVp21wtiwgav5biqjCBwAYDVR0jBIG4MIG1gBQwEs0mc8HARTVp21wtiwga
285v5biqqGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQH
286EwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
287D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
288dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
289oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
290hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp
291jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo
292bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L
293opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej
294gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM
295729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
296-----END CERTIFICATE-----'''
297 def __init__(self):
298 pass
ChetanGaonker689b3862016-10-17 16:25:01 -0700299 def setUp(self,controller=None):
300 self.onos_ctrl = OnosCtrl(self.eap_app,controller=controller)
301 self.onos_aaa_config(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700302
ChetanGaonker689b3862016-10-17 16:25:01 -0700303 def onos_aaa_config(self,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -0700304 log_test.info('controller in onos_aaa_config is %s'%controller)
A.R Karthicka6c88fd2017-03-13 09:29:41 -0700305 aaa_dict = {'apps' : { 'org.opencord.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
306 'radiusIp': '172.17.0.2' } } } }
ChetanGaonker2099d722016-10-07 15:16:58 -0700307 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A.R Karthicka6c88fd2017-03-13 09:29:41 -0700308 aaa_dict['apps']['org.opencord.aaa']['AAA']['radiusIp'] = radius_ip
ChetanGaonker2099d722016-10-07 15:16:58 -0700309 self.onos_ctrl.activate()
310 time.sleep(2)
ChetanGaonker689b3862016-10-17 16:25:01 -0700311 self.onos_load_config(aaa_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700312
ChetanGaonker689b3862016-10-17 16:25:01 -0700313 def onos_load_config(self, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -0700314 log_test.info('controller in onos_load_config is %s'%controller)
315 log_test.info('onos load config is %s'%config)
ChetanGaonker689b3862016-10-17 16:25:01 -0700316 status, code = OnosCtrl(self.eap_app).config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700317 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700318 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700319 assert_equal(status, True)
320 time.sleep(2)
321
322
323class cluster_flows():
324
325 PORT_TX_DEFAULT = 2
326 PORT_RX_DEFAULT = 1
327 INTF_TX_DEFAULT = 'veth2'
328 INTF_RX_DEFAULT = 'veth0'
329 default_port_map = {
330 PORT_TX_DEFAULT : INTF_TX_DEFAULT,
331 PORT_RX_DEFAULT : INTF_RX_DEFAULT,
332 INTF_TX_DEFAULT : PORT_TX_DEFAULT,
333 INTF_RX_DEFAULT : PORT_RX_DEFAULT
334 }
335 app = 'org.onosproject.cli'
336
337 def incmac(self, mac):
338 tmp = str(hex(int('0x'+mac,16)+1).split('x')[1])
339 mac = '0'+ tmp if len(tmp) < 2 else tmp
340 return mac
341
342 def next_mac(self, mac):
343 mac = mac.split(":")
344 mac[5] = self.incmac(mac[5])
345
346 if len(mac[5]) > 2:
347 mac[0] = self.incmac(mac[0])
348 mac[5] = '01'
349
350 if len(mac[0]) > 2:
351 mac[0] = '01'
352 mac[1] = self.incmac(mac[1])
353 mac[5] = '01'
354 return ':'.join(mac)
355
356 def to_egress_mac(cls, mac):
357 mac = mac.split(":")
358 mac[4] = '01'
359
360 return ':'.join(mac)
361
362 def inc_ip(self, ip, i):
363
364 ip[i] =str(int(ip[i])+1)
365 return '.'.join(ip)
366
367
368 def next_ip(self, ip):
369
370 lst = ip.split('.')
371 for i in (3,0,-1):
372 if int(lst[i]) < 255:
373 return self.inc_ip(lst, i)
374 elif int(lst[i]) == 255:
375 lst[i] = '0'
376 if int(lst[i-1]) < 255:
377 return self.inc_ip(lst,i-1)
378 elif int(lst[i-2]) < 255:
379 lst[i-1] = '0'
380 return self.inc_ip(lst,i-2)
381 else:
382 break
383
384 def randomip(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
385 start = list(map(int, start_ip.split(".")))
386 end = list(map(int, end_ip.split(".")))
387 temp = start
388 ip_range = []
389 ip_range.append(start_ip)
390 while temp != end:
391 start[3] += 1
392 for i in (3, 2, 1):
393 if temp[i] == 255:
394 temp[i] = 0
395 temp[i-1] += 1
396 ip_range.append(".".join(map(str, temp)))
397 return random.choice(ip_range)
398
399 def ip_range(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
400 start = list(map(int, start_ip.split(".")))
401 end = list(map(int, end_ip.split(".")))
402 temp = start
403 ip_range = []
404 ip_range.append(start_ip)
405 while temp != end:
406 start[3] += 1
407 for i in (3, 2, 1):
408 if temp[i] == 255:
409 temp[i] = 0
410 temp[i-1] += 1
411 ip_range.append(".".join(map(str, temp)))
412 return ip_range
413
414 def to_egress_ip(self, ip):
415 lst=ip.split('.')
416 lst[0] = '182'
417 return '.'.join(lst)
418
419 @classmethod
420 def setUpClass(cls):
421 cls.olt = OltConfig()
422 cls.port_map, _ = cls.olt.olt_port_map()
423 if not cls.port_map:
424 cls.port_map = cls.default_port_map
425 cls.device_id = OnosCtrl.get_device_id()
426
427class cluster_proxyarp():
ChetanGaonker689b3862016-10-17 16:25:01 -0700428 #apps = ('org.onosproject.vrouter','org.onosproject.proxyarp')
429 app = 'org.onosproject.proxyarp'
ChetanGaonker2099d722016-10-07 15:16:58 -0700430 device_id = 'of:' + get_mac()
431 device_dict = { "devices" : {
432 "{}".format(device_id) : {
433 "basic" : {
434 "driver" : "softrouter"
435 }
436 }
437 },
438 }
439 test_path = os.path.dirname(os.path.realpath(__file__))
440 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
441 GATEWAY = '192.168.10.50'
442 INGRESS_PORT = 1
443 EGRESS_PORT = 2
444 MAX_PORTS = 100
445 hosts_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ]
446
447 olt_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json')
448
449 @classmethod
450 def setUpClass(cls):
451 cls.olt = OltConfig()
452 cls.port_map, _ = cls.olt.olt_port_map()
453 print('port map in proxyarp setUpClass is %s'%cls.port_map)
454 if not cls.port_map:
455 cls.port_map = g_subscriber_port_map
456 time.sleep(3)
457 cls.load_device_id()
458
459 @classmethod
460 def load_device_id(cls):
461 did = OnosCtrl.get_device_id()
462 cls.device_id = did
463 cls.device_dict = { "devices" : {
464 "{}".format(did) : {
465 "basic" : {
466 "driver" : "softrouter"
467 }
468 }
469 },
470 }
471 def cliEnter(self):
472 retries = 0
473 while retries < 3:
474 self.cli = OnosCliDriver(connect = True)
475 if self.cli.handle:
476 break
477 else:
478 retries += 1
479 time.sleep(2)
480
481 def cliExit(self):
482 self.cli.disconnect()
483
484 @classmethod
485 def interface_config_load(cls, interface_cfg = None):
486 if type(interface_cfg) is tuple:
487 res = []
488 for v in interface_cfg:
489 if type(v) == list:
490 pass
491 else:
492 res += v.items()
493 config = dict(res)
494 else:
495 config = interface_cfg
496 cfg = json.dumps(config)
ChetanGaonker689b3862016-10-17 16:25:01 -0700497 #with open('{}/network-cfg.json'.format(cls.onos_config_path), 'w') as f:
498 # f.write(cfg)
499 #return cord_test_onos_restart(config=config)
ChetanGaonker2099d722016-10-07 15:16:58 -0700500
501 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700502 def host_config_load(cls, host_config = None, controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700503 for host in host_config:
ChetanGaonker689b3862016-10-17 16:25:01 -0700504 status, code = OnosCtrl(cls.app).host_config(host,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700505 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700506 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700507 assert_equal(status, True)
508
509 @classmethod
510 def generate_interface_config(cls, hosts = 1):
511 num = 0
512 start_host = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
513 end_host = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
514 ports_dict = { 'ports' : {} }
515 interface_list = []
516 hosts_list = []
517 for n in xrange(start_host, end_host, 256):
518 port_map = ports_dict['ports']
519 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
520 device_port_key = '{0}/{1}'.format(cls.device_id, port)
521 try:
522 interfaces = port_map[device_port_key]['interfaces']
523 except:
524 port_map[device_port_key] = { 'interfaces' : [] }
525 interfaces = port_map[device_port_key]['interfaces']
526 ip = n + 1
527 host_ip = n + 2
528 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
529 host = '%d.%d.%d.%d' % ( (host_ip >> 24) & 0xff, ( ( host_ip >> 16) & 0xff ), ( (host_ip >> 8 ) & 0xff ), host_ip & 0xff )
530 mac = RandMAC()._fix()
531 hosts_list.append((host, mac))
532 if num < cls.MAX_PORTS - 1:
533 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
534 interfaces.append(interface_dict)
535 interface_list.append(interface_dict['name'])
536 else:
537 interfaces[0]['ips'].append(ips)
538 num += 1
539 if num == hosts:
540 break
541 cls.hosts_list = hosts_list
542 return (cls.device_dict, ports_dict, hosts_list)
543
544 @classmethod
545 def generate_host_config(cls):
546 num = 0
547 hosts_dict = {}
548 for host, mac in cls.hosts_list:
549 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
550 hosts_dict[host] = {'mac':mac, 'vlan':'none', 'ipAddresses':[host], 'location':{ 'elementId' : '{}'.format(cls.device_id), 'port': port}}
551 num += 1
552 return hosts_dict.values()
553
554 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700555 def proxyarp_activate(cls, deactivate = False,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700556 app = 'org.onosproject.proxyarp'
ChetanGaonker689b3862016-10-17 16:25:01 -0700557 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700558 if deactivate is True:
559 onos_ctrl.deactivate()
560 else:
561 onos_ctrl.activate()
562 time.sleep(3)
563
564 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700565 def proxyarp_config(cls, hosts = 1,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700566 proxyarp_configs = cls.generate_interface_config(hosts = hosts)
567 cls.interface_config_load(interface_cfg = proxyarp_configs)
568 hostcfg = cls.generate_host_config()
ChetanGaonker689b3862016-10-17 16:25:01 -0700569 cls.host_config_load(host_config = hostcfg,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700570 return proxyarp_configs
571
572 def proxyarp_arpreply_verify(self, ingress, hostip, hostmac, PositiveTest=True):
A R Karthick76a497a2017-04-12 10:59:39 -0700573 #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 -0700574 self.success = False
575 def recv_task():
576 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -0700577 log_test.info('Arp Reply seen with source Mac is %s' %(pkt[ARP].hwsrc))
ChetanGaonker2099d722016-10-07 15:16:58 -0700578 self.success = True if PositiveTest == True else False
579 sniff(count=1, timeout=2, lfilter = lambda p: ARP in p and p[ARP].op == 2 and p[ARP].hwsrc == hostmac,
580 prn = recv_cb, iface = self.port_map[ingress])
581 t = threading.Thread(target = recv_task)
582 t.start()
583 pkt = (Ether(dst = 'ff:ff:ff:ff:ff:ff')/ARP(op=1,pdst=hostip))
A R Karthick76a497a2017-04-12 10:59:39 -0700584 log_test.info('sending arp request for dest ip %s on interface %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -0700585 (hostip, self.port_map[ingress]))
586 sendp( pkt, count = 10, iface = self.port_map[ingress])
587 t.join()
588 if PositiveTest:
589 assert_equal(self.success, True)
590 else:
591 assert_equal(self.success, False)
592
593 def proxyarp_hosts_verify(self, hosts = 1,PositiveTest = True):
A R Karthick76a497a2017-04-12 10:59:39 -0700594 log_test.info('verifying arp reply for host ip host mac on interface %s'%(self.port_map[2]))
ChetanGaonker2099d722016-10-07 15:16:58 -0700595 _,_,hosts_config = self.proxyarp_config(hosts = hosts)
A R Karthick76a497a2017-04-12 10:59:39 -0700596 log_test.info('\nhosts_config %s and its type %s'%(hosts_config,type(hosts_config)))
ChetanGaonker2099d722016-10-07 15:16:58 -0700597 self.cliEnter()
598 connected_hosts = json.loads(self.cli.hosts(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700599 log_test.info('Discovered hosts: %s' %connected_hosts)
ChetanGaonker2099d722016-10-07 15:16:58 -0700600 #We read from cli if we expect less number of routes to avoid cli timeouts
601 if hosts <= 10000:
602 assert_equal(len(connected_hosts), hosts)
603 ingress = hosts+1
604 for hostip, hostmac in hosts_config:
605 self.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = PositiveTest)
606 time.sleep(1)
607 self.cliExit()
608 return True
609
610class cluster_vrouter(object):
611 apps = ('org.onosproject.vrouter', 'org.onosproject.fwd')
612 device_id = 'of:' + get_mac()
613 vrouter_device_dict = { "devices" : {
614 "{}".format(device_id) : {
615 "basic" : {
616 "driver" : "softrouter"
617 }
618 }
619 },
620 }
621 zebra_conf = '''
622password zebra
623log stdout
624service advanced-vty
625!
626!debug zebra rib
627!debug zebra kernel
628!debug zebra fpm
629!
630!interface eth1
631! ip address 10.10.0.3/16
632line vty
633 exec-timeout 0 0
634'''
635 test_path = os.path.dirname(os.path.realpath(__file__))
636 quagga_config_path = os.path.join(test_path, '..', 'setup/quagga-config')
637 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
638 GATEWAY = '192.168.10.50'
639 INGRESS_PORT = 1
640 EGRESS_PORT = 2
641 MAX_PORTS = 100
642 peer_list = [ ('192.168.10.1', '00:00:00:00:00:01'), ('192.168.11.1', '00:00:00:00:02:01'), ]
643 network_list = []
644 network_mask = 24
645 default_routes_address = ('11.10.10.0/24',)
646 default_peer_address = peer_list
647 quagga_ip = os.getenv('QUAGGA_IP')
648
649 @classmethod
650 def setUpClass(cls):
651 ''' Activate the vrouter apps'''
652 cls.olt = OltConfig()
653 cls.port_map, _ = cls.olt.olt_port_map()
654 if not cls.port_map:
655 cls.port_map = g_subscriber_port_map
656 time.sleep(3)
657 cls.load_device_id()
658
659 @classmethod
660 def tearDownClass(cls):
661 '''Deactivate the vrouter apps'''
662 #cls.vrouter_host_unload()
663 cls.start_onos(network_cfg = {})
664 #cls.vrouter_activate(cls, deactivate = True)
665
666
667 @classmethod
668 def load_device_id(cls):
669 did = OnosCtrl.get_device_id()
670 cls.device_id = did
671 cls.vrouter_device_dict = { "devices" : {
672 "{}".format(did) : {
673 "basic" : {
674 "driver" : "softrouter"
675 }
676 }
677 },
678 }
679
ChetanGaonker689b3862016-10-17 16:25:01 -0700680 def cliEnter(self,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700681 retries = 0
682 while retries < 3:
ChetanGaonker689b3862016-10-17 16:25:01 -0700683 self.cli = OnosCliDriver(connect = True,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700684 if self.cli.handle:
685 break
686 else:
687 retries += 1
688 time.sleep(2)
689
690 def cliExit(self):
691 self.cli.disconnect()
692
693 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700694 def onos_load_config(cls, config,controller=None):
695 status, code = OnosCtrl.config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700696 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700697 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -0700698 assert_equal(status, True)
699
700 @classmethod
701 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
702 route_update = None, router_address = None):
703 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
704 peer_address = peer_address, router_address = router_address)
705 return vrouter_configs
706
707 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700708 def vrouter_host_load(cls,peer_address = None,controller=None):
709 index = 1
710 hosts_dict = {}
711 peer_info = peer_address if peer_address is not None else cls.peer_list
712 for host,_ in peer_info:
713 #iface = cls.port_map[index]
714 mac = RandMAC()._fix()
715 #port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
A R Karthick76a497a2017-04-12 10:59:39 -0700716 log_test.info('creating host with ip %s and mac %s'%(host,mac))
ChetanGaonker689b3862016-10-17 16:25:01 -0700717 hosts_dict[host] = {'mac':mac, 'vlan':'none', 'ipAddresses':[host], 'location':{ 'elementId' : '{}'.format(cls.device_id), 'port': index}}
718 index += 1
719 for host in hosts_dict.values():
720 status, code = OnosCtrl.host_config(host,onos_ip=controller)
721 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700722 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -0700723 return False
724 return True
725
726 """@classmethod
ChetanGaonker2099d722016-10-07 15:16:58 -0700727 def vrouter_host_load(cls, peer_address = None):
728 #cls.setUpClass()
729 index = 1
730 peer_info = peer_address if peer_address is not None else cls.peer_list
731
732 for host,_ in peer_info:
733 iface = cls.port_map[index]
734 index += 1
A R Karthick76a497a2017-04-12 10:59:39 -0700735 log_test.info('Assigning ip %s to interface %s' %(host, iface))
ChetanGaonker2099d722016-10-07 15:16:58 -0700736 config_cmds = ( 'ifconfig {} 0'.format(iface),
737 'ifconfig {0} {1}'.format(iface, host),
738 'arping -I {0} {1} -c 2'.format(iface, host),
739 )
740 for cmd in config_cmds:
741 os.system(cmd)
ChetanGaonker689b3862016-10-17 16:25:01 -0700742 """
ChetanGaonker2099d722016-10-07 15:16:58 -0700743 @classmethod
744 def vrouter_host_unload(cls, peer_address = None):
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
751 config_cmds = ('ifconfig {} 0'.format(iface), )
752 for cmd in config_cmds:
753 os.system(cmd)
754
755 @classmethod
756 def start_onos(cls, network_cfg = None):
757 if type(network_cfg) is tuple:
758 res = []
759 for v in network_cfg:
760 res += v.items()
761 config = dict(res)
762 else:
763 config = network_cfg
ChetanGaonker689b3862016-10-17 16:25:01 -0700764 cfg = json.dumps(config)
A R Karthick76a497a2017-04-12 10:59:39 -0700765 log_test.info('Restarting ONOS with new network configuration %s'%config)
ChetanGaonker689b3862016-10-17 16:25:01 -0700766 #return cord_test_onos_restart(config = config)
767 with open('{}/network-cfg.json'.format(cls.onos_config_path), 'w') as f:
768 f.write(cfg)
769 return cord_test_onos_restart(config=config)
ChetanGaonker2099d722016-10-07 15:16:58 -0700770
771 @classmethod
772 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
A R Karthick76a497a2017-04-12 10:59:39 -0700773 log_test.info('Restarting Quagga container with configuration for %d networks' %(networks))
ChetanGaonker2099d722016-10-07 15:16:58 -0700774 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
775 if networks <= 10000:
776 boot_delay = 25
777 else:
778 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
779 n = min(networks/100000, len(delay_map)-1)
780 boot_delay = delay_map[n]
781 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
782
783 @classmethod
784 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
785 num = 0
786 if peer_address is None:
787 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
788 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
789 else:
790 ip = peer_address[0][0]
791 start_ip = ip.split('.')
792 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
793 end_peer = ((int(start_ip[0]) + 8) << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
794 local_network = end_peer + 1
795 ports_dict = { 'ports' : {} }
796 interface_list = []
797 peer_list = []
798 for n in xrange(start_peer, end_peer, 256):
799 port_map = ports_dict['ports']
800 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
801 device_port_key = '{0}/{1}'.format(cls.device_id, port)
802 try:
803 interfaces = port_map[device_port_key]['interfaces']
804 except:
805 port_map[device_port_key] = { 'interfaces' : [] }
806 interfaces = port_map[device_port_key]['interfaces']
807 ip = n + 2
808 peer_ip = n + 1
809 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
810 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
811 mac = RandMAC()._fix()
812 peer_list.append((peer, mac))
813 if num < cls.MAX_PORTS - 1:
814 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
815 interfaces.append(interface_dict)
816 interface_list.append(interface_dict['name'])
817 else:
818 interfaces[0]['ips'].append(ips)
819 num += 1
820 if num == peers:
821 break
822 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
823 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
824 quagga_router_dict['ospfEnabled'] = True
825 quagga_router_dict['interfaces'] = interface_list
826 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
827
828 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
829 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
830 speaker_dict = {}
831 speaker_dict['name'] = 'bgp{}'.format(peers+1)
832 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
833 speaker_dict['peers'] = peer_list
834 bgp_speakers_list.append(speaker_dict)
835 cls.peer_list = peer_list
836 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
837
838 @classmethod
839 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
840 num = 0
841 if router_address is None:
842 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
843 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
844 network_mask = 24
845 else:
846 ip = router_address
847 start_ip = ip.split('.')
848 network_mask = int(start_ip[3].split('/')[1])
849 start_ip[3] = (start_ip[3].split('/'))[0]
850 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
851 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
852 net_list = []
853 peer_list = peer_address if peer_address is not None else cls.peer_list
854 network_list = []
855 for n in xrange(start_network, end_network, 256):
856 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
857 network_list.append(net)
858 gateway = peer_list[num % len(peer_list)][0]
859 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
860 net_list.append(net_route)
861 num += 1
862 if num == networks:
863 break
864 cls.network_list = network_list
865 cls.network_mask = network_mask
866 zebra_routes = '\n'.join(net_list)
A R Karthick76a497a2017-04-12 10:59:39 -0700867 #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
ChetanGaonker2099d722016-10-07 15:16:58 -0700868 return cls.zebra_conf + zebra_routes
869
870 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -0700871 def vrouter_activate(cls, deactivate = False,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700872 app = 'org.onosproject.vrouter'
ChetanGaonker689b3862016-10-17 16:25:01 -0700873 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700874 if deactivate is True:
875 onos_ctrl.deactivate()
876 else:
877 onos_ctrl.activate()
878 time.sleep(3)
879
880 @classmethod
881 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
ChetanGaonker689b3862016-10-17 16:25:01 -0700882 route_update = None, router_address = None, time_expire = None, adding_new_routes = None,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700883 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
884 peer_address = peer_address, route_update = route_update)
885 cls.start_onos(network_cfg = vrouter_configs)
ChetanGaonker689b3862016-10-17 16:25:01 -0700886 cls.vrouter_host_load(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700887 ##Start quagga
888 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
889 return vrouter_configs
890
891 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
892 src_mac = '00:00:00:00:00:02'
893 src_ip = '1.1.1.1'
894 self.success = False if positive_test else True
895 timeout = 10 if positive_test else 1
896 count = 2 if positive_test else 1
897 self.start_sending = True
898 def recv_task():
899 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -0700900 log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -0700901 self.success = True if positive_test else False
902 sniff(count=count, timeout=timeout,
903 lfilter = lambda p: IP in p and p[IP].dst == dst_ip and p[IP].src == src_ip,
904 prn = recv_cb, iface = self.port_map[ingress])
905 self.start_sending = False
906
907 t = threading.Thread(target = recv_task)
908 t.start()
909 L2 = Ether(src = src_mac, dst = dst_mac)
910 L3 = IP(src = src_ip, dst = dst_ip)
911 pkt = L2/L3
A R Karthick76a497a2017-04-12 10:59:39 -0700912 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 -0700913 (dst_ip, dst_mac, self.port_map[egress]))
914 while self.start_sending is True:
915 sendp(pkt, count=50, iface = self.port_map[egress])
916 t.join()
917 assert_equal(self.success, True)
918
919 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
920 if peer_address is None:
921 peers = len(self.peer_list)
922 peer_list = self.peer_list
923 else:
924 peers = len(peer_address)
925 peer_list = peer_address
926 egress = peers + 1
927 num = 0
928 num_hosts = 5 if positive_test else 1
929 src_mac = '00:00:00:00:00:02'
930 src_ip = '1.1.1.1'
931 if self.network_mask != 24:
932 peers = 1
933 for network in self.network_list:
934 num_ips = num_hosts
935 octets = network.split('.')
936 for i in xrange(num_ips):
937 octets[-1] = str(int(octets[-1]) + 1)
938 dst_ip = '.'.join(octets)
939 dst_mac = peer_list[ num % peers ] [1]
940 port = (num % peers)
941 ingress = port + 1
942 #Since peers are on the same network
943 ##Verify if flows are setup by sending traffic across
944 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
945 num += 1
946
947 def vrouter_network_verify(self, networks, peers = 1, positive_test = True,
948 start_network = None, start_peer_address = None, route_update = None,
949 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
ChetanGaonker689b3862016-10-17 16:25:01 -0700950 deactivate_activate_vrouter = None, adding_new_routes = None,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700951
952 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
953 peer_address = start_peer_address,
954 route_update = route_update,
955 router_address = start_network,
956 time_expire = time_expire,
ChetanGaonker689b3862016-10-17 16:25:01 -0700957 adding_new_routes = adding_new_routes,
958 controller=controller)
959 self.cliEnter(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700960 ##Now verify
961 hosts = json.loads(self.cli.hosts(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700962 log_test.info('Discovered hosts: %s' %hosts)
ChetanGaonker2099d722016-10-07 15:16:58 -0700963 ##We read from cli if we expect less number of routes to avoid cli timeouts
964 if networks <= 10000:
965 routes = json.loads(self.cli.routes(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700966 #log_test.info('Routes: %s' %routes)
ChetanGaonker2099d722016-10-07 15:16:58 -0700967 if start_network is not None:
968 if start_network.split('/')[1] is 24:
969 assert_equal(len(routes['routes4']), networks)
970 if start_network.split('/')[1] is not 24:
971 assert_equal(len(routes['routes4']), 1)
972 if start_network is None and invalid_peers is None:
973 assert_equal(len(routes['routes4']), networks)
974 if invalid_peers is not None:
975 assert_equal(len(routes['routes4']), 0)
976 flows = json.loads(self.cli.flows(jsonFormat = True))
977 flows = filter(lambda f: f['flows'], flows)
A R Karthick76a497a2017-04-12 10:59:39 -0700978 #log_test.info('Flows: %s' %flows)
ChetanGaonker2099d722016-10-07 15:16:58 -0700979 assert_not_equal(len(flows), 0)
980 if invalid_peers is None:
981 self.vrouter_traffic_verify()
982 if positive_test is False:
983 self.vrouter_network_verify_negative(networks, peers = peers)
984 if time_expire is True:
985 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
986 self.vrouter_traffic_verify()
987 if unreachable_route_traffic is True:
988 network_list_backup = self.network_list
989 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
990 self.vrouter_traffic_verify(positive_test = False)
991 self.network_list = network_list_backup
992 if deactivate_activate_vrouter is True:
A R Karthick76a497a2017-04-12 10:59:39 -0700993 log_test.info('Deactivating vrouter app in ONOS controller for negative scenario')
ChetanGaonker2099d722016-10-07 15:16:58 -0700994 self.vrouter_activate(deactivate = True)
995 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
996 #assert_equal(len(routes['routes4']), 'Command not found')
A R Karthick76a497a2017-04-12 10:59:39 -0700997 log_test.info('Activating vrouter app again in ONOS controller for negative scenario')
ChetanGaonker2099d722016-10-07 15:16:58 -0700998 self.vrouter_activate(deactivate = False)
999 routes = json.loads(self.cli.routes(jsonFormat = True))
1000 assert_equal(len(routes['routes4']), networks)
1001 self.vrouter_traffic_verify()
1002 self.cliExit()
1003 return True
1004
1005 def vrouter_network_verify_negative(self, networks, peers = 1):
1006 ##Stop quagga. Test traffic again to see if flows were removed
A R Karthick76a497a2017-04-12 10:59:39 -07001007 log_test.info('Stopping Quagga container')
ChetanGaonker2099d722016-10-07 15:16:58 -07001008 cord_test_quagga_stop()
1009 if networks <= 10000:
1010 routes = json.loads(self.cli.routes(jsonFormat = True))
1011 #Verify routes have been removed
1012 if routes and routes.has_key('routes4'):
1013 assert_equal(len(routes['routes4']), 0)
1014 self.vrouter_traffic_verify(positive_test = False)
A R Karthick76a497a2017-04-12 10:59:39 -07001015 log_test.info('OVS flows have been removed successfully after Quagga was stopped')
ChetanGaonker2099d722016-10-07 15:16:58 -07001016 self.start_quagga(networks = networks)
1017 ##Verify the flows again after restarting quagga back
1018 if networks <= 10000:
1019 routes = json.loads(self.cli.routes(jsonFormat = True))
1020 assert_equal(len(routes['routes4']), networks)
1021 self.vrouter_traffic_verify()
A R Karthick76a497a2017-04-12 10:59:39 -07001022 log_test.info('OVS flows have been successfully reinstalled after Quagga was restarted')
ChetanGaonker2099d722016-10-07 15:16:58 -07001023
1024 def quagga_shell(self, cmd):
1025 shell_cmds = ('vtysh', '"conf t"', '"{}"'.format(cmd))
1026 quagga_cmd = ' -c '.join(shell_cmds)
1027
1028 return cord_test_quagga_shell(quagga_cmd)
1029
1030class cluster_acl(object):
ChetanGaonker689b3862016-10-17 16:25:01 -07001031 app = 'org.onosproject.acl'
ChetanGaonker2099d722016-10-07 15:16:58 -07001032 device_id = 'of:' + get_mac('ovsbr0')
1033 test_path = os.path.dirname(os.path.realpath(__file__))
1034 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
1035 GATEWAY = '192.168.10.50'
1036 INGRESS_PORT = 1
1037 EGRESS_PORT = 2
1038 ingress_iface = 1
1039 egress_iface = 2
1040 MAX_PORTS = 100
1041 CURRENT_PORT_NUM = egress_iface
1042 ACL_SRC_IP = '192.168.20.3/32'
1043 ACL_DST_IP = '192.168.30.2/32'
1044 ACL_SRC_IP_RULE_2 = '192.168.40.3/32'
1045 ACL_DST_IP_RULE_2 = '192.168.50.2/32'
1046 ACL_SRC_IP_PREFIX_24 = '192.168.20.3/24'
1047 ACL_DST_IP_PREFIX_24 = '192.168.30.2/24'
1048 HOST_DST_IP = '192.168.30.0/24'
1049 HOST_DST_IP_RULE_2 = '192.168.50.0/24'
1050
1051 @classmethod
1052 def setUpClass(cls):
1053 cls.olt = OltConfig()
1054 cls.port_map,_ = cls.olt.olt_port_map()
1055 if not cls.port_map:
1056 cls.port_map = g_subscriber_port_map
1057 time.sleep(3)
A R Karthick76a497a2017-04-12 10:59:39 -07001058 log_test.info('port_map = %s'%cls.port_map[1] )
ChetanGaonker2099d722016-10-07 15:16:58 -07001059
1060 @classmethod
1061 def tearDownClass(cls):
1062 '''Deactivate the acl app'''
ChetanGaonker689b3862016-10-17 16:25:01 -07001063 def setUp(self,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001064 self.setUpClass()
1065 ''' Activate the acl app'''
1066 self.maxDiff = None ##for assert_equal compare outputs on failure
ChetanGaonker689b3862016-10-17 16:25:01 -07001067 self.onos_ctrl = OnosCtrl(self.app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001068 status, _ = self.onos_ctrl.activate()
1069 assert_equal(status, True)
1070 time.sleep(1)
1071 #status, _ = ACLTest.remove_acl_rule()
A R Karthick76a497a2017-04-12 10:59:39 -07001072 #log_test.info('Start setup')
ChetanGaonker2099d722016-10-07 15:16:58 -07001073 #assert_equal(status, True)
1074
1075 def tearDown(self):
1076 '''Deactivate the acl app'''
A R Karthick76a497a2017-04-12 10:59:39 -07001077 log_test.info('Tear down setup')
ChetanGaonker2099d722016-10-07 15:16:58 -07001078 self.CURRENT_PORT_NUM = 4
1079
1080 def cliEnter(self):
1081 retries = 0
1082 while retries < 3:
1083 self.cli = OnosCliDriver(connect = True)
1084 if self.cli.handle:
1085 break
1086 else:
1087 retries += 1
1088 time.sleep(2)
1089
1090 def cliExit(self):
1091 self.cli.disconnect()
1092
1093 @classmethod
1094 def acl_hosts_add(cls, dstHostIpMac, egress_iface_count = 1, egress_iface_num = None):
1095 cls.setUpClass()
1096 index = 0
1097 if egress_iface_num is None:
1098 egress_iface_num = cls.egress_iface
1099 for ip,_ in dstHostIpMac:
1100 egress = cls.port_map[egress_iface_num]
A R Karthick76a497a2017-04-12 10:59:39 -07001101 log_test.info('Assigning ip %s to interface %s' %(ip, egress))
ChetanGaonker2099d722016-10-07 15:16:58 -07001102 config_cmds_egress = ( 'ifconfig {} 0'.format(egress),
1103 'ifconfig {0} up'.format(egress),
1104 'ifconfig {0} {1}'.format(egress, ip),
1105 'arping -I {0} {1} -c 2'.format(egress, ip.split('/')[0]),
1106 'ifconfig {0}'.format(egress),
1107 )
1108 for cmd in config_cmds_egress:
1109 os.system(cmd)
1110 index += 1
1111 if index == egress_iface_count:
1112 break
1113 egress_iface_count += 1
1114 egress_iface_num += 1
1115
1116
1117 @classmethod
1118 def acl_hosts_remove(cls, egress_iface_count = 1, egress_iface_num = None):
1119 cls.setUpClass()
1120 if egress_iface_num is None:
1121 egress_iface_num = cls.egress_iface
1122 n = 0
1123 for n in range(egress_iface_count):
1124 egress = cls.port_map[egress_iface_num]
1125 config_cmds_egress = ('ifconfig {} 0'.format(egress))
1126 os.system(config_cmds_egress)
1127 egress_iface_num += 1
1128
1129 def acl_rule_traffic_send_recv(self, srcMac, dstMac, srcIp, dstIp, ingress =None, egress=None, ip_proto=None, dstPortNum = None, positive_test = True):
1130 self.setUpClass()
1131 if ingress is None:
1132 ingress = self.ingress_iface
1133 if egress is None:
1134 egress = self.egress_iface
1135 ingress = self.port_map[ingress]
1136 egress = self.port_map[egress]
1137 self.success = False if positive_test else True
1138 timeout = 10 if positive_test else 1
1139 count = 2 if positive_test else 1
1140 self.start_sending = True
1141 def recv_task():
1142 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -07001143 log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -07001144 self.success = True if positive_test else False
1145 sniff(count=count, timeout=timeout,
1146 lfilter = lambda p: IP in p and p[IP].dst == dstIp.split('/')[0] and p[IP].src == srcIp.split('/')[0],
1147 prn = recv_cb, iface = egress)
1148 self.start_sending = False
1149
1150 t = threading.Thread(target = recv_task)
1151 t.start()
1152 L2 = Ether(src = srcMac, dst = dstMac)
1153 L3 = IP(src = srcIp.split('/')[0], dst = dstIp.split('/')[0])
1154 pkt = L2/L3
A R Karthick76a497a2017-04-12 10:59:39 -07001155 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 -07001156 (dstIp.split('/')[0], srcIp.split('/')[0], dstMac, srcMac, ingress))
1157 while self.start_sending is True:
1158 sendp(pkt, count=50, iface = ingress)
1159 t.join()
1160 assert_equal(self.success, True)
1161
1162 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001163 def onos_load_config(cls, config,controller=None):
1164 status, code = OnosCtrl.config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001165 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001166 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -07001167 assert_equal(status, True)
1168
1169class cluster_dhcprelay(object):
1170 app = 'org.onosproject.dhcprelay'
1171 app_dhcp = 'org.onosproject.dhcp'
1172 relay_interfaces_last = ()
1173 interface_to_mac_map = {}
1174 host_ip_map = {}
1175 test_path = os.path.dirname(os.path.realpath(__file__))
1176 dhcp_data_dir = os.path.join(test_path, '..', 'setup')
1177 olt_conf_file = os.path.join(test_path, '..', 'setup/olt_config.json')
1178 default_config = { 'default-lease-time' : 600, 'max-lease-time' : 7200, }
1179 default_options = [ ('subnet-mask', '255.255.255.0'),
1180 ('broadcast-address', '192.168.1.255'),
1181 ('domain-name-servers', '192.168.1.1'),
1182 ('domain-name', '"mydomain.cord-tester"'),
1183 ]
1184 ##specify the IP for the dhcp interface matching the subnet and subnet config
1185 ##this is done for each interface dhcpd server would be listening on
1186 default_subnet_config = [ ('192.168.1.2',
1187'''
1188subnet 192.168.1.0 netmask 255.255.255.0 {
1189 range 192.168.1.10 192.168.1.100;
1190}
1191'''), ]
1192
1193 lock = threading.Condition()
1194 ip_count = 0
1195 failure_count = 0
1196 start_time = 0
1197 diff = 0
1198
1199 transaction_count = 0
1200 transactions = 0
1201 running_time = 0
1202 total_success = 0
1203 total_failure = 0
1204 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
1205
1206 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001207 def setUpClass(cls,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001208 log_test.info('controller ip in dhcp setup def is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001209 ''' Activate the dhcprelay app'''
ChetanGaonker689b3862016-10-17 16:25:01 -07001210 OnosCtrl(cls.app_dhcp,controller=controller).deactivate()
ChetanGaonker2099d722016-10-07 15:16:58 -07001211 time.sleep(3)
ChetanGaonker689b3862016-10-17 16:25:01 -07001212 cls.onos_ctrl = OnosCtrl(cls.app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001213 status, _ = cls.onos_ctrl.activate()
1214 assert_equal(status, True)
1215 time.sleep(3)
ChetanGaonker689b3862016-10-17 16:25:01 -07001216 cls.dhcp_relay_setup(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001217 ##start dhcpd initially with default config
ChetanGaonker689b3862016-10-17 16:25:01 -07001218 cls.dhcpd_start(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001219
1220 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001221 def tearDownClass(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001222 '''Deactivate the dhcp relay app'''
1223 try:
1224 os.unlink('{}/dhcpd.conf'.format(cls.dhcp_data_dir))
1225 os.unlink('{}/dhcpd.leases'.format(cls.dhcp_data_dir))
1226 except: pass
ChetanGaonker689b3862016-10-17 16:25:01 -07001227 OnosCtrl(cls.app,controller=controller).deactivate()
1228 #cls.onos_ctrl.deactivate()
ChetanGaonker2099d722016-10-07 15:16:58 -07001229 cls.dhcpd_stop()
ChetanGaonker689b3862016-10-17 16:25:01 -07001230 #cls.dhcp_relay_cleanup()
ChetanGaonker2099d722016-10-07 15:16:58 -07001231
1232 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001233 def dhcp_relay_setup(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001234 did = OnosCtrl.get_device_id()
1235 cls.relay_device_id = did
1236 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
1237 cls.port_map, _ = cls.olt.olt_port_map()
1238 if cls.port_map:
1239 ##Per subscriber, we use 1 relay port
1240 try:
1241 relay_port = cls.port_map[cls.port_map['relay_ports'][0]]
1242 except:
1243 relay_port = cls.port_map['uplink']
1244 cls.relay_interface_port = relay_port
1245 cls.relay_interfaces = (cls.port_map[cls.relay_interface_port],)
1246 else:
1247 cls.relay_interface_port = 100
1248 cls.relay_interfaces = (g_subscriber_port_map[cls.relay_interface_port],)
1249 cls.relay_interfaces_last = cls.relay_interfaces
1250 if cls.port_map:
1251 ##generate a ip/mac client virtual interface config for onos
1252 interface_list = []
1253 for port in cls.port_map['ports']:
1254 port_num = cls.port_map[port]
1255 if port_num == cls.port_map['uplink']:
1256 continue
1257 ip = cls.get_host_ip(port_num)
1258 mac = cls.get_mac(port)
1259 interface_list.append((port_num, ip, mac))
1260
1261 #configure dhcp server virtual interface on the same subnet as first client interface
1262 relay_ip = cls.get_host_ip(interface_list[0][0])
1263 relay_mac = cls.get_mac(cls.port_map[cls.relay_interface_port])
1264 interface_list.append((cls.relay_interface_port, relay_ip, relay_mac))
ChetanGaonker689b3862016-10-17 16:25:01 -07001265 cls.onos_interface_load(interface_list,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001266
1267 @classmethod
1268 def dhcp_relay_cleanup(cls):
1269 ##reset the ONOS port configuration back to default
1270 if cls.onos_restartable is True:
A R Karthick76a497a2017-04-12 10:59:39 -07001271 log_test.info('Cleaning up dhcp relay config by restarting ONOS with default network cfg')
ChetanGaonker2099d722016-10-07 15:16:58 -07001272 return cord_test_onos_restart(config = {})
1273
1274 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001275 def onos_load_config(cls, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001276 log_test.info('loading onos config in controller %s'%controller)
ChetanGaonker689b3862016-10-17 16:25:01 -07001277 status, code = OnosCtrl.config(config,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001278 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001279 log_test.info('JSON request returned status %d' %code)
ChetanGaonker2099d722016-10-07 15:16:58 -07001280 assert_equal(status, True)
1281 time.sleep(2)
1282
1283 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001284 def onos_interface_load(cls, interface_list,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001285 interface_dict = { 'ports': {} }
1286 for port_num, ip, mac in interface_list:
1287 port_map = interface_dict['ports']
1288 port = '{}/{}'.format(cls.relay_device_id, port_num)
1289 port_map[port] = { 'interfaces': [] }
1290 interface_list = port_map[port]['interfaces']
1291 interface_map = { 'ips' : [ '{}/{}'.format(ip, 24) ],
1292 'mac' : mac,
1293 'name': 'vir-{}'.format(port_num)
1294 }
1295 interface_list.append(interface_map)
1296
ChetanGaonker689b3862016-10-17 16:25:01 -07001297 cls.onos_load_config(interface_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001298
1299 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001300 def onos_dhcp_relay_load(cls, server_ip, server_mac,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001301 relay_device_map = '{}/{}'.format(cls.relay_device_id, cls.relay_interface_port)
1302 dhcp_dict = {'apps':{'org.onosproject.dhcp-relay':{'dhcprelay':
1303 {'dhcpserverConnectPoint':relay_device_map,
1304 'serverip':server_ip,
1305 'servermac':server_mac
1306 }
1307 }
1308 }
1309 }
ChetanGaonker689b3862016-10-17 16:25:01 -07001310 cls.onos_load_config(dhcp_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001311
1312 @classmethod
1313 def get_host_ip(cls, port):
1314 if cls.host_ip_map.has_key(port):
1315 return cls.host_ip_map[port]
1316 cls.host_ip_map[port] = '192.168.1.{}'.format(port)
1317 return cls.host_ip_map[port]
1318
1319 @classmethod
1320 def host_load(cls, iface):
1321 '''Have ONOS discover the hosts for dhcp-relay responses'''
1322 port = g_subscriber_port_map[iface]
1323 host = '173.17.1.{}'.format(port)
1324 cmds = ( 'ifconfig {} 0'.format(iface),
1325 'ifconfig {0} {1}'.format(iface, host),
1326 'arping -I {0} {1} -c 2'.format(iface, host),
1327 'ifconfig {} 0'.format(iface), )
1328 for c in cmds:
1329 os.system(c)
1330 @classmethod
1331
1332 def dhcpd_conf_generate(cls, config = default_config, options = default_options,
1333 subnet = default_subnet_config):
1334 conf = ''
1335 for k, v in config.items():
1336 conf += '{} {};\n'.format(k, v)
1337
1338 opts = ''
1339 for k, v in options:
1340 opts += 'option {} {};\n'.format(k, v)
1341
1342 subnet_config = ''
1343 for _, v in subnet:
1344 subnet_config += '{}\n'.format(v)
1345
1346 return '{}{}{}'.format(conf, opts, subnet_config)
1347
1348 @classmethod
1349 def dhcpd_start(cls, intf_list = None,
1350 config = default_config, options = default_options,
ChetanGaonker689b3862016-10-17 16:25:01 -07001351 subnet = default_subnet_config,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001352 '''Start the dhcpd server by generating the conf file'''
1353 if intf_list is None:
1354 intf_list = cls.relay_interfaces
1355 ##stop dhcpd if already running
1356 cls.dhcpd_stop()
1357 dhcp_conf = cls.dhcpd_conf_generate(config = config, options = options,
1358 subnet = subnet)
1359 ##first touch dhcpd.leases if it doesn't exist
1360 lease_file = '{}/dhcpd.leases'.format(cls.dhcp_data_dir)
1361 if os.access(lease_file, os.F_OK) is False:
1362 with open(lease_file, 'w') as fd: pass
1363
1364 conf_file = '{}/dhcpd.conf'.format(cls.dhcp_data_dir)
1365 with open(conf_file, 'w') as fd:
1366 fd.write(dhcp_conf)
1367
1368 #now configure the dhcpd interfaces for various subnets
1369 index = 0
1370 intf_info = []
1371 for ip,_ in subnet:
1372 intf = intf_list[index]
1373 mac = cls.get_mac(intf)
1374 intf_info.append((ip, mac))
1375 index += 1
1376 os.system('ifconfig {} {}'.format(intf, ip))
1377
1378 intf_str = ','.join(intf_list)
1379 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 -07001380 log_test.info('Starting DHCPD server with command: %s' %dhcpd_cmd)
ChetanGaonker2099d722016-10-07 15:16:58 -07001381 ret = os.system(dhcpd_cmd)
1382 assert_equal(ret, 0)
1383 time.sleep(3)
1384 cls.relay_interfaces_last = cls.relay_interfaces
1385 cls.relay_interfaces = intf_list
ChetanGaonker689b3862016-10-17 16:25:01 -07001386 cls.onos_dhcp_relay_load(*intf_info[0],controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001387
1388 @classmethod
1389 def dhcpd_stop(cls):
1390 os.system('pkill -9 dhcpd')
1391 for intf in cls.relay_interfaces:
1392 os.system('ifconfig {} 0'.format(intf))
1393
1394 cls.relay_interfaces = cls.relay_interfaces_last
1395
1396 @classmethod
1397 def get_mac(cls, iface):
1398 if cls.interface_to_mac_map.has_key(iface):
1399 return cls.interface_to_mac_map[iface]
1400 mac = get_mac(iface, pad = 0)
1401 cls.interface_to_mac_map[iface] = mac
1402 return mac
1403
1404 def stats(self,success_rate = False, only_discover = False, iface = 'veth0'):
1405
1406 self.ip_count = 0
1407 self.failure_count = 0
1408 self.start_time = 0
1409 self.diff = 0
1410 self.transaction_count = 0
1411
1412 mac = self.get_mac(iface)
1413 self.host_load(iface)
1414 ##we use the defaults for this test that serves as an example for others
1415 ##You don't need to restart dhcpd server if retaining default config
1416 config = self.default_config
1417 options = self.default_options
1418 subnet = self.default_subnet_config
1419 dhcpd_interface_list = self.relay_interfaces
1420 self.dhcpd_start(intf_list = dhcpd_interface_list,
1421 config = config,
1422 options = options,
1423 subnet = subnet)
1424 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
1425 self.start_time = time.time()
1426
1427 while self.diff <= 60:
1428
1429 if only_discover:
1430 cip, sip, mac, _ = self.dhcp.only_discover(multiple = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001431 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001432 (cip, sip, mac))
1433 else:
1434 cip, sip = self.send_recv(mac, update_seed = True, validate = False)
1435
1436 if cip:
1437 self.ip_count +=1
1438 elif cip == None:
1439 self.failure_count += 1
A R Karthick76a497a2017-04-12 10:59:39 -07001440 log_test.info('Failed to get ip')
ChetanGaonker2099d722016-10-07 15:16:58 -07001441 if success_rate and self.ip_count > 0:
1442 break
1443
1444 self.diff = round(time.time() - self.start_time, 0)
1445
1446 self.transaction_count = round((self.ip_count+self.failure_count)/self.diff, 2)
1447 self.transactions += (self.ip_count+self.failure_count)
1448 self.running_time += self.diff
1449 self.total_success += self.ip_count
1450 self.total_failure += self.failure_count
1451
1452 def send_recv(self, mac, update_seed = False, validate = True):
1453 cip, sip = self.dhcp.discover(mac = mac, update_seed = update_seed)
1454 if validate:
1455 assert_not_equal(cip, None)
1456 assert_not_equal(sip, None)
A R Karthick76a497a2017-04-12 10:59:39 -07001457 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001458 (cip, sip, self.dhcp.get_mac(cip)[0]))
1459 return cip,sip
1460
1461class Subscriber(Channels):
1462 PORT_TX_DEFAULT = 2
1463 PORT_RX_DEFAULT = 1
1464 INTF_TX_DEFAULT = 'veth2'
1465 INTF_RX_DEFAULT = 'veth0'
1466 STATS_RX = 0
1467 STATS_TX = 1
1468 STATS_JOIN = 2
1469 STATS_LEAVE = 3
1470 SUBSCRIBER_SERVICES = 'DHCP IGMP TLS'
1471 def __init__(self, name = 'sub', service = SUBSCRIBER_SERVICES, port_map = None,
1472 num = 1, channel_start = 0,
1473 tx_port = PORT_TX_DEFAULT, rx_port = PORT_RX_DEFAULT,
1474 iface = INTF_RX_DEFAULT, iface_mcast = INTF_TX_DEFAULT,
1475 mcast_cb = None, loginType = 'wireless'):
1476 self.tx_port = tx_port
1477 self.rx_port = rx_port
1478 self.port_map = port_map or g_subscriber_port_map
1479 try:
1480 self.tx_intf = self.port_map[tx_port]
1481 self.rx_intf = self.port_map[rx_port]
1482 except:
1483 self.tx_intf = self.port_map[self.PORT_TX_DEFAULT]
1484 self.rx_intf = self.port_map[self.PORT_RX_DEFAULT]
A R Karthick76a497a2017-04-12 10:59:39 -07001485 log_test.info('Subscriber %s, rx interface %s, uplink interface %s' %(name, self.rx_intf, self.tx_intf))
ChetanGaonker2099d722016-10-07 15:16:58 -07001486 Channels.__init__(self, num, channel_start = channel_start,
1487 iface = self.rx_intf, iface_mcast = self.tx_intf, mcast_cb = mcast_cb)
1488 self.name = name
1489 self.service = service
1490 self.service_map = {}
1491 services = self.service.strip().split(' ')
1492 for s in services:
1493 self.service_map[s] = True
1494 self.loginType = loginType
1495 ##start streaming channels
1496 self.join_map = {}
1497 ##accumulated join recv stats
1498 self.join_rx_stats = Stats()
1499 self.recv_timeout = False
1500
1501 def has_service(self, service):
1502 if self.service_map.has_key(service):
1503 return self.service_map[service]
1504 if self.service_map.has_key(service.upper()):
1505 return self.service_map[service.upper()]
1506 return False
1507
1508 def channel_join_update(self, chan, join_time):
1509 self.join_map[chan] = ( Stats(), Stats(), Stats(), Stats() )
1510 self.channel_update(chan, self.STATS_JOIN, 1, t = join_time)
1511 def channel_join(self, chan = 0, delay = 2):
1512 '''Join a channel and create a send/recv stats map'''
1513 if self.join_map.has_key(chan):
1514 del self.join_map[chan]
1515 self.delay = delay
1516 chan, join_time = self.join(chan)
1517 self.channel_join_update(chan, join_time)
1518 return chan
1519
1520 def channel_join_next(self, delay = 2):
1521 '''Joins the next channel leaving the last channel'''
1522 if self.last_chan:
1523 if self.join_map.has_key(self.last_chan):
1524 del self.join_map[self.last_chan]
1525 self.delay = delay
1526 chan, join_time = self.join_next()
1527 self.channel_join_update(chan, join_time)
1528 return chan
1529
1530 def channel_jump(self, delay = 2):
1531 '''Jumps randomly to the next channel leaving the last channel'''
1532 if self.last_chan is not None:
1533 if self.join_map.has_key(self.last_chan):
1534 del self.join_map[self.last_chan]
1535 self.delay = delay
1536 chan, join_time = self.jump()
1537 self.channel_join_update(chan, join_time)
1538 return chan
1539
1540 def channel_leave(self, chan = 0):
1541 if self.join_map.has_key(chan):
1542 del self.join_map[chan]
1543 self.leave(chan)
1544
1545 def channel_update(self, chan, stats_type, packets, t=0):
1546 if type(chan) == type(0):
1547 chan_list = (chan,)
1548 else:
1549 chan_list = chan
1550 for c in chan_list:
1551 if self.join_map.has_key(c):
1552 self.join_map[c][stats_type].update(packets = packets, t = t)
1553 def channel_receive(self, chan, cb = None, count = 1, timeout = 5):
A R Karthick76a497a2017-04-12 10:59:39 -07001554 log_test.info('Subscriber %s on port %s receiving from group %s, channel %d' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001555 (self.name, self.rx_intf, self.gaddr(chan), chan))
1556 r = self.recv(chan, cb = cb, count = count, timeout = timeout)
1557 if len(r) == 0:
A R Karthick76a497a2017-04-12 10:59:39 -07001558 log_test.info('Subscriber %s on port %s timed out' %(self.name, self.rx_intf))
ChetanGaonker2099d722016-10-07 15:16:58 -07001559 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001560 log_test.info('Subscriber %s on port %s received %d packets' %(self.name, self.rx_intf, len(r)))
ChetanGaonker2099d722016-10-07 15:16:58 -07001561 if self.recv_timeout:
1562 ##Negative test case is disabled for now
1563 assert_equal(len(r), 0)
1564
1565 def recv_channel_cb(self, pkt):
1566 ##First verify that we have received the packet for the joined instance
A R Karthick76a497a2017-04-12 10:59:39 -07001567 log_test.info('Packet received for group %s, subscriber %s, port %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001568 (pkt[IP].dst, self.name, self.rx_intf))
1569 if self.recv_timeout:
1570 return
1571 chan = self.caddr(pkt[IP].dst)
1572 assert_equal(chan in self.join_map.keys(), True)
1573 recv_time = monotonic.monotonic() * 1000000
1574 join_time = self.join_map[chan][self.STATS_JOIN].start
1575 delta = recv_time - join_time
1576 self.join_rx_stats.update(packets=1, t = delta, usecs = True)
1577 self.channel_update(chan, self.STATS_RX, 1, t = delta)
A R Karthick76a497a2017-04-12 10:59:39 -07001578 log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -07001579
1580class subscriber_pool:
1581
1582 def __init__(self, subscriber, test_cbs):
1583 self.subscriber = subscriber
1584 self.test_cbs = test_cbs
1585
1586 def pool_cb(self):
1587 for cb in self.test_cbs:
1588 if cb:
1589 self.test_status = cb(self.subscriber)
1590 if self.test_status is not True:
1591 ## This is chaning for other sub status has to check again
1592 self.test_status = True
A R Karthick76a497a2017-04-12 10:59:39 -07001593 log_test.info('This service is failed and other services will not run for this subscriber')
ChetanGaonker2099d722016-10-07 15:16:58 -07001594 break
A R Karthick76a497a2017-04-12 10:59:39 -07001595 log_test.info('This Subscriber is tested for multiple service eligibility ')
ChetanGaonker2099d722016-10-07 15:16:58 -07001596 self.test_status = True
1597
1598class cluster_subscriber(object):
1599 apps = ('org.opencord.aaa', 'org.onosproject.dhcp')
1600 olt_apps = () #'org.opencord.cordmcast')
1601 vtn_app = 'org.opencord.vtn'
1602 table_app = 'org.ciena.cordigmp'
1603 dhcp_server_config = {
1604 "ip": "10.1.11.50",
1605 "mac": "ca:fe:ca:fe:ca:fe",
1606 "subnet": "255.255.252.0",
1607 "broadcast": "10.1.11.255",
1608 "router": "10.1.8.1",
1609 "domain": "8.8.8.8",
1610 "ttl": "63",
1611 "delay": "2",
1612 "startip": "10.1.11.51",
1613 "endip": "10.1.11.100"
1614 }
1615
1616 aaa_loaded = False
1617 test_path = os.path.dirname(os.path.realpath(__file__))
1618 table_app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-multitable-2.0-SNAPSHOT.oar')
1619 app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-2.0-SNAPSHOT.oar')
1620 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
1621 olt_conf_file = os.path.join(test_path, '..', 'setup/olt_config.json')
1622 cpqd_path = os.path.join(test_path, '..', 'setup')
1623 ovs_path = cpqd_path
1624 test_services = ('IGMP', 'TRAFFIC')
1625 num_joins = 0
1626 num_subscribers = 0
1627 num_channels = 0
1628 recv_timeout = False
1629 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
1630
1631 INTF_TX_DEFAULT = 'veth2'
1632 INTF_RX_DEFAULT = 'veth0'
1633 SUBSCRIBER_TIMEOUT = 300
1634 CLIENT_CERT = """-----BEGIN CERTIFICATE-----
1635MIICuDCCAiGgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
1636CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h
1637IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd
1638RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwNjA2MjExMjI3WhcN
1639MTcwNjAxMjExMjI3WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV
1640BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI
1641hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
1642gYEAwvXiSzb9LZ6c7uNziUfKvoHO7wu/uiFC5YUpXbmVGuGZizbVrny0xnR85Dfe
1643+9R4diansfDhIhzOUl1XjN3YDeSS9OeF5YWNNE8XDhlz2d3rVzaN6hIhdotBkUjg
1644rUewjTg5OFR31QEyG3v8xR3CLgiE9xQELjZbSA07pD79zuUCAwEAAaNPME0wEwYD
1645VR0lBAwwCgYIKwYBBQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5l
1646eGFtcGxlLmNvbS9leGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOBgQDAjkrY
16476tDChmKbvr8w6Du/t8vHjTCoCIocHTN0qzWOeb1YsAGX89+TrWIuO1dFyYd+Z0KC
1648PDKB5j/ygml9Na+AklSYAVJIjvlzXKZrOaPmhZqDufi+rXWti/utVqY4VMW2+HKC
1649nXp37qWeuFLGyR1519Y1d6F/5XzqmvbwURuEug==
1650-----END CERTIFICATE-----"""
1651
1652 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
1653MIIDvTCCAqWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
1654CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h
1655IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd
1656RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzExMTg1MzM2WhcN
1657MTcwMzA2MTg1MzM2WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV
1658BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI
1659hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
1660AQoCggEBAOxemcBsPn9tZsCa5o2JA6sQDC7A6JgCNXXl2VFzKLNNvB9PS6D7ZBsQ
16615An0zEDMNzi51q7lnrYg1XyiE4S8FzMGAFr94RlGMQJUbRD9V/oqszMX4k++iAOK
1662tIA1gr3x7Zi+0tkjVSVzXTmgNnhChAamdMsjYUG5+CY9WAicXyy+VEV3zTphZZDR
1663OjcjEp4m/TSXVPYPgYDXI40YZKX5BdvqykWtT/tIgZb48RS1NPyN/XkCYzl3bv21
1664qx7Mc0fcEbsJBIIRYTUkfxnsilcnmLxSYO+p+DZ9uBLBzcQt+4Rd5pLSfi21WM39
16652Z2oOi3vs/OYAPAqgmi2JWOv3mePa/8CAwEAAaNPME0wEwYDVR0lBAwwCgYIKwYB
1666BQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5leGFtcGxlLmNvbS9l
1667eGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOCAQEALBzMPDTIB6sLyPl0T6JV
1668MjOkyldAVhXWiQsTjaGQGJUUe1cmUJyZbUZEc13MygXMPOM4x7z6VpXGuq1c/Vxn
1669VzQ2fNnbJcIAHi/7G8W5/SQfPesIVDsHTEc4ZspPi5jlS/MVX3HOC+BDbOjdbwqP
1670RX0JEr+uOyhjO+lRxG8ilMRACoBUbw1eDuVDoEBgErSUC44pq5ioDw2xelc+Y6hQ
1671dmtYwfY0DbvwxHtA495frLyPcastDiT/zre7NL51MyUDPjjYjghNQEwvu66IKbQ3
1672T1tJBrgI7/WI+dqhKBFolKGKTDWIHsZXQvZ1snGu/FRYzg1l+R/jT8cRB9BDwhUt
1673yg==
1674-----END CERTIFICATE-----'''
1675 @classmethod
1676 def load_device_id(cls):
1677 '''Configure the device id'''
1678 did = OnosCtrl.get_device_id()
1679 #Set the default config
1680 cls.device_id = did
1681 cls.device_dict = { "devices" : {
1682 "{}".format(did) : {
1683 "basic" : {
1684 "driver" : "pmc-olt"
1685 }
1686 }
1687 },
1688 }
1689 return did
1690
1691 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001692 def setUpClass(cls,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001693 log_test.info('controller ip in cluster.py setupclass is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001694 '''Load the OLT config and activate relevant apps'''
1695 did = cls.load_device_id()
1696 network_cfg = { "devices" : {
1697 "{}".format(did) : {
1698 "basic" : {
1699 "driver" : "pmc-olt"
1700 }
1701 }
1702 },
1703 }
1704 ## Restart ONOS with cpqd driver config for OVS
1705 print('onos restart in setUpClass')
1706 cls.start_onos(network_cfg = network_cfg)
1707 #status, code = OnosCtrl.config(network_cfg)
1708 #if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001709 # log_test.info('JSON config request for app %s returned status %d' %(app, code))
ChetanGaonker2099d722016-10-07 15:16:58 -07001710 #assert_equal(status, True)
1711 #time.sleep(2)
ChetanGaonker689b3862016-10-17 16:25:01 -07001712 cls.install_app_table(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001713 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
A R Karthick0f6b6842016-12-06 17:17:44 -08001714 OnosCtrl.cord_olt_config(cls.olt, controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001715 cls.port_map, cls.port_list = cls.olt.olt_port_map()
ChetanGaonker689b3862016-10-17 16:25:01 -07001716 cls.activate_apps(cls.apps + cls.olt_apps,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001717
1718 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001719 def tearDownClass(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001720 '''Deactivate the olt apps and restart OVS back'''
1721 apps = cls.olt_apps + ( cls.table_app,)
1722 for app in apps:
ChetanGaonker689b3862016-10-17 16:25:01 -07001723 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001724 onos_ctrl.deactivate()
1725 cls.uninstall_app_table()
ChetanGaonker689b3862016-10-17 16:25:01 -07001726 cls.start_onos(network_cfg = {})
ChetanGaonker2099d722016-10-07 15:16:58 -07001727
1728 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001729 def activate_apps(cls, apps,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001730 for app in apps:
ChetanGaonker689b3862016-10-17 16:25:01 -07001731 onos_ctrl = OnosCtrl(app,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001732 status, _ = onos_ctrl.activate()
1733 assert_equal(status, True)
1734 time.sleep(2)
1735 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001736 def install_app_table(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001737 ##Uninstall the existing app if any
ChetanGaonker689b3862016-10-17 16:25:01 -07001738 OnosCtrl.uninstall_app(cls.table_app,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001739 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07001740 log_test.info('Installing the multi table app %s for subscriber test' %(cls.table_app_file))
ChetanGaonker689b3862016-10-17 16:25:01 -07001741 OnosCtrl.install_app(cls.table_app_file,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001742 time.sleep(3)
1743 #onos_ctrl = OnosCtrl(cls.vtn_app)
1744 #onos_ctrl.deactivate()
1745
1746 @classmethod
ChetanGaonker689b3862016-10-17 16:25:01 -07001747 def uninstall_app_table(cls,controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001748 ##Uninstall the table app on class exit
ChetanGaonker689b3862016-10-17 16:25:01 -07001749 OnosCtrl.uninstall_app(cls.table_app,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001750 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07001751 log_test.info('Installing back the cord igmp app %s for subscriber test on exit' %(cls.app_file))
ChetanGaonker689b3862016-10-17 16:25:01 -07001752 OnosCtrl.install_app(cls.app_file,onos_ip=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001753 #onos_ctrl = OnosCtrl(cls.vtn_app)
1754 #onos_ctrl.activate()
1755
1756 @classmethod
1757 def start_onos(cls, network_cfg = None):
1758 if cls.onos_restartable is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001759 log_test.info('ONOS restart is disabled. Skipping ONOS restart')
ChetanGaonker2099d722016-10-07 15:16:58 -07001760 return
1761 if network_cfg is None:
1762 network_cfg = cls.device_dict
1763
1764 if type(network_cfg) is tuple:
1765 res = []
1766 for v in network_cfg:
1767 res += v.items()
1768 config = dict(res)
1769 else:
1770 config = network_cfg
A R Karthick76a497a2017-04-12 10:59:39 -07001771 log_test.info('Restarting ONOS with new network configuration')
ChetanGaonker689b3862016-10-17 16:25:01 -07001772 #return cord_test_onos_restart(config = config)
ChetanGaonker2099d722016-10-07 15:16:58 -07001773
1774 @classmethod
1775 def remove_onos_config(cls):
1776 try:
1777 os.unlink('{}/network-cfg.json'.format(cls.onos_config_path))
1778 except: pass
1779 @classmethod
1780 def start_cpqd(cls, mac = '00:11:22:33:44:55'):
1781 dpid = mac.replace(':', '')
1782 cpqd_file = os.sep.join( (cls.cpqd_path, 'cpqd.sh') )
1783 cpqd_cmd = '{} {}'.format(cpqd_file, dpid)
1784 ret = os.system(cpqd_cmd)
1785 assert_equal(ret, 0)
1786 time.sleep(10)
1787 device_id = 'of:{}{}'.format('0'*4, dpid)
1788 return device_id
1789
1790 @classmethod
1791 def start_ovs(cls):
1792 ovs_file = os.sep.join( (cls.ovs_path, 'of-bridge.sh') )
1793 ret = os.system(ovs_file)
1794 assert_equal(ret, 0)
1795 time.sleep(30)
1796
1797 @classmethod
1798 def ovs_cleanup(cls):
1799 ##For every test case, delete all the OVS groups
1800 cmd = 'ovs-ofctl del-groups br-int -OOpenFlow11 >/dev/null 2>&1'
1801 cord_test_shell(cmd)
1802 ##Since olt config is used for this test, we just fire a careless local cmd as well
1803 try:
1804 os.system(cmd)
1805 except: pass
1806
ChetanGaonker689b3862016-10-17 16:25:01 -07001807 def onos_aaa_load(self,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001808 log_test.info('controller ip in cluster.py onos_aaa_load is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001809 if self.aaa_loaded:
1810 return
A.R Karthicka6c88fd2017-03-13 09:29:41 -07001811 aaa_dict = {'apps' : { 'org.opencord.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
1812 'radiusIp': '172.17.0.2' } } } }
ChetanGaonker2099d722016-10-07 15:16:58 -07001813 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
A.R Karthicka6c88fd2017-03-13 09:29:41 -07001814 aaa_dict['apps']['org.opencord.aaa']['AAA']['radiusIp'] = radius_ip
1815 self.onos_load_config('org.opencord.aaa', aaa_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001816 self.aaa_loaded = True
1817
ChetanGaonker689b3862016-10-17 16:25:01 -07001818 def onos_dhcp_table_load(self, config = None,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001819 log_test.info('controller ip in cluster.py onos_dhcp_table_load is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001820 dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
1821 dhcp_config = dhcp_dict['apps']['org.onosproject.dhcp']['dhcp']
1822 if config:
1823 for k in config.keys():
1824 if dhcp_config.has_key(k):
1825 dhcp_config[k] = config[k]
ChetanGaonker689b3862016-10-17 16:25:01 -07001826 self.onos_load_config('org.onosproject.dhcp', dhcp_dict,controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07001827
ChetanGaonker689b3862016-10-17 16:25:01 -07001828 def onos_load_config(self, app, config,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07001829 log_test.info('controller ip in cluster.py onos_load_config is %s'%controller)
ChetanGaonker689b3862016-10-17 16:25:01 -07001830 status, code = OnosCtrl(controller=controller).config(config)
ChetanGaonker2099d722016-10-07 15:16:58 -07001831 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001832 log_test.info('JSON config request for app %s returned status %d' %(app, code))
ChetanGaonker2099d722016-10-07 15:16:58 -07001833 assert_equal(status, True)
1834 time.sleep(2)
1835 def dhcp_sndrcv(self, dhcp, update_seed = False):
1836 cip, sip = dhcp.discover(update_seed = update_seed)
1837 assert_not_equal(cip, None)
1838 assert_not_equal(sip, None)
A R Karthick76a497a2017-04-12 10:59:39 -07001839 log_test.info('Got dhcp client IP %s from server %s for mac %s' %
ChetanGaonker2099d722016-10-07 15:16:58 -07001840 (cip, sip, dhcp.get_mac(cip)[0]))
1841 return cip,sip
1842
1843 def dhcp_request(self, subscriber, seed_ip = '10.10.10.1', update_seed = False):
1844 config = {'startip':'10.10.10.20', 'endip':'10.10.10.200',
1845 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
1846 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
1847 self.onos_dhcp_table_load(config)
1848 dhcp = DHCPTest(seed_ip = seed_ip, iface = subscriber.iface)
1849 cip, sip = self.dhcp_sndrcv(dhcp, update_seed = update_seed)
1850 return cip, sip
1851
1852 def recv_channel_cb(self, pkt):
1853 ##First verify that we have received the packet for the joined instance
1854 chan = self.subscriber.caddr(pkt[IP].dst)
1855 assert_equal(chan in self.subscriber.join_map.keys(), True)
1856 recv_time = monotonic.monotonic() * 1000000
1857 join_time = self.subscriber.join_map[chan][self.subscriber.STATS_JOIN].start
1858 delta = recv_time - join_time
1859 self.subscriber.join_rx_stats.update(packets=1, t = delta, usecs = True)
1860 self.subscriber.channel_update(chan, self.subscriber.STATS_RX, 1, t = delta)
A R Karthick76a497a2017-04-12 10:59:39 -07001861 log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst))
ChetanGaonker2099d722016-10-07 15:16:58 -07001862 self.test_status = True
1863
1864 def traffic_verify(self, subscriber):
1865 if subscriber.has_service('TRAFFIC'):
1866 url = 'http://www.google.com'
1867 resp = requests.get(url)
1868 self.test_status = resp.ok
1869 if resp.ok == False:
A R Karthick76a497a2017-04-12 10:59:39 -07001870 log_test.info('Subscriber %s failed get from url %s with status code %d'
ChetanGaonker2099d722016-10-07 15:16:58 -07001871 %(subscriber.name, url, resp.status_code))
1872 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001873 log_test.info('GET request from %s succeeded for subscriber %s'
ChetanGaonker2099d722016-10-07 15:16:58 -07001874 %(url, subscriber.name))
1875 return self.test_status
1876
1877 def tls_verify(self, subscriber):
1878 if subscriber.has_service('TLS'):
1879 time.sleep(2)
1880 tls = TLSAuthTest(intf = subscriber.rx_intf)
A R Karthick76a497a2017-04-12 10:59:39 -07001881 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07001882 tls.runTest()
1883 self.test_status = True
1884 return self.test_status
1885 else:
1886 self.test_status = True
1887 return self.test_status
1888 def dhcp_verify(self, subscriber):
1889 if subscriber.has_service('DHCP'):
1890 cip, sip = self.dhcp_request(subscriber, update_seed = True)
A R Karthick76a497a2017-04-12 10:59:39 -07001891 log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07001892 subscriber.src_list = [cip]
1893 self.test_status = True
1894 return self.test_status
1895 else:
1896 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
1897 self.test_status = True
1898 return self.test_status
1899
1900 def dhcp_jump_verify(self, subscriber):
1901 if subscriber.has_service('DHCP'):
1902 cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1')
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_next_verify(self, subscriber):
1913 if subscriber.has_service('DHCP'):
1914 cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.150.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 def igmp_verify(self, subscriber):
1924 chan = 0
1925 if subscriber.has_service('IGMP'):
1926 ##We wait for all the subscribers to join before triggering leaves
1927 if subscriber.rx_port > 1:
1928 time.sleep(5)
1929 subscriber.channel_join(chan, delay = 0)
1930 self.num_joins += 1
1931 while self.num_joins < self.num_subscribers:
1932 time.sleep(5)
A R Karthick76a497a2017-04-12 10:59:39 -07001933 log_test.info('All subscribers have joined the channel')
ChetanGaonker2099d722016-10-07 15:16:58 -07001934 for i in range(10):
1935 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10)
A R Karthick76a497a2017-04-12 10:59:39 -07001936 log_test.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001937 subscriber.channel_leave(chan)
1938 time.sleep(5)
A R Karthick76a497a2017-04-12 10:59:39 -07001939 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 -07001940 #Should not receive packets for this subscriber
1941 self.recv_timeout = True
1942 subscriber.recv_timeout = True
1943 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10)
1944 subscriber.recv_timeout = False
1945 self.recv_timeout = False
A R Karthick76a497a2017-04-12 10:59:39 -07001946 log_test.info('Joining channel %d for subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001947 subscriber.channel_join(chan, delay = 0)
1948 self.test_status = True
1949 return self.test_status
1950
1951 def igmp_jump_verify(self, subscriber):
1952 if subscriber.has_service('IGMP'):
1953 for i in xrange(subscriber.num):
A R Karthick76a497a2017-04-12 10:59:39 -07001954 log_test.info('Subscriber %s jumping channel' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07001955 chan = subscriber.channel_jump(delay=0)
1956 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1)
A R Karthick76a497a2017-04-12 10:59:39 -07001957 log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001958 time.sleep(3)
A R Karthick76a497a2017-04-12 10:59:39 -07001959 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 -07001960 self.test_status = True
1961 return self.test_status
1962 def igmp_next_verify(self, subscriber):
1963 if subscriber.has_service('IGMP'):
1964 for i in xrange(subscriber.num):
1965 if i:
1966 chan = subscriber.channel_join_next(delay=0)
1967 else:
1968 chan = subscriber.channel_join(i, delay=0)
A R Karthick76a497a2017-04-12 10:59:39 -07001969 log_test.info('Joined next channel %d for subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001970 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count=1)
A R Karthick76a497a2017-04-12 10:59:39 -07001971 log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name))
ChetanGaonker2099d722016-10-07 15:16:58 -07001972 time.sleep(3)
A R Karthick76a497a2017-04-12 10:59:39 -07001973 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 -07001974 self.test_status = True
1975 return self.test_status
1976
1977 def generate_port_list(self, subscribers, channels):
1978 return self.port_list[:subscribers]
1979
ChetanGaonker689b3862016-10-17 16:25:01 -07001980 def subscriber_load(self, create = True, num = 10, num_channels = 1, channel_start = 0, port_list = [],controller=None):
ChetanGaonker2099d722016-10-07 15:16:58 -07001981 '''Load the subscriber from the database'''
1982 self.subscriber_db = SubscriberDB(create = create, services = self.test_services)
1983 if create is True:
1984 self.subscriber_db.generate(num)
1985 self.subscriber_info = self.subscriber_db.read(num)
1986 self.subscriber_list = []
1987 if not port_list:
1988 port_list = self.generate_port_list(num, num_channels)
1989
1990 index = 0
1991 for info in self.subscriber_info:
1992 self.subscriber_list.append(Subscriber(name=info['Name'],
1993 service=info['Service'],
1994 port_map = self.port_map,
1995 num=num_channels,
1996 channel_start = channel_start,
1997 tx_port = port_list[index][0],
1998 rx_port = port_list[index][1]))
1999 if num_channels > 1:
2000 channel_start += num_channels
2001 index += 1
2002
2003 #load the ssm list for all subscriber channels
ChetanGaonker689b3862016-10-17 16:25:01 -07002004 igmpChannel = IgmpChannel(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07002005 ssm_groups = map(lambda sub: sub.channels, self.subscriber_list)
2006 ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups)
2007 igmpChannel.igmp_load_ssm_config(ssm_list)
2008 def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1,
ChetanGaonker689b3862016-10-17 16:25:01 -07002009 channel_start = 0, cbs = None, port_list = [], negative_subscriber_auth = None,controller=None):
A R Karthick76a497a2017-04-12 10:59:39 -07002010 log_test.info('controller ip in cluster.py subscriber_join_verify is %s'%controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07002011 self.test_status = False
2012 self.ovs_cleanup()
2013 subscribers_count = num_subscribers
2014 sub_loop_count = num_subscribers
2015 self.subscriber_load(create = True, num = num_subscribers,
ChetanGaonker689b3862016-10-17 16:25:01 -07002016 num_channels = num_channels, channel_start = channel_start, port_list = port_list,controller=controller)
2017 self.onos_aaa_load(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -07002018 self.thread_pool = ThreadPool(min(100, subscribers_count), queue_size=1, wait_timeout=1)
2019
2020 chan_leave = False #for single channel, multiple subscribers
2021 if None in (cbs, negative_subscriber_auth):
2022 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
2023 chan_leave = True
2024 cbs_negative = cbs
2025 for subscriber in self.subscriber_list:
2026 subscriber.start()
2027 if negative_subscriber_auth is 'half' and sub_loop_count%2 is not 0:
2028 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
2029 elif negative_subscriber_auth is 'onethird' and sub_loop_count%3 is not 0:
2030 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
2031 else:
2032 cbs = cbs_negative
2033 sub_loop_count = sub_loop_count - 1
2034 pool_object = subscriber_pool(subscriber, cbs)
2035 self.thread_pool.addTask(pool_object.pool_cb)
2036 self.thread_pool.cleanUpThreads()
2037 for subscriber in self.subscriber_list:
2038 subscriber.stop()
2039 if chan_leave is True:
2040 subscriber.channel_leave(0)
2041 subscribers_count = 0
2042 return self.test_status
2043 def tls_invalid_cert(self, subscriber):
2044 if subscriber.has_service('TLS'):
2045 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002046 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002047 tls = TLSAuthTest(client_cert = self.CLIENT_CERT_INVALID)
2048 tls.runTest()
2049 if tls.failTest == True:
2050 self.test_status = False
2051 return self.test_status
2052 else:
2053 self.test_status = True
2054 return self.test_status
2055
2056 def tls_no_cert(self, subscriber):
2057 if subscriber.has_service('TLS'):
2058 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002059 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002060 tls = TLSAuthTest(client_cert = '')
2061 tls.runTest()
2062 if tls.failTest == True:
2063 self.test_status = False
2064 return self.test_status
2065 else:
2066 self.test_status = True
2067 return self.test_status
2068
2069 def tls_self_signed_cert(self, subscriber):
2070 if subscriber.has_service('TLS'):
2071 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002072 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002073 tls = TLSAuthTest(client_cert = self.CLIENT_CERT)
2074 tls.runTest()
2075 if tls.failTest == False:
2076 self.test_status = True
2077 return self.test_status
2078 else:
2079 self.test_status = True
2080 return self.test_status
2081
2082 def tls_non_ca_authrized_cert(self, subscriber):
2083 if subscriber.has_service('TLS'):
2084 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002085 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002086 tls = TLSAuthTest(client_cert = self.CLIENT_CERT_NON_CA_AUTHORIZED)
2087 tls.runTest()
2088 if tls.failTest == False:
2089 self.test_status = True
2090 return self.test_status
2091 else:
2092 self.test_status = True
2093 return self.test_status
2094 def tls_Nsubscribers_use_same_valid_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 num_users = 3
2099 for i in xrange(num_users):
2100 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
2101 tls.runTest()
2102 if tls.failTest == False:
2103 self.test_status = True
2104 return self.test_status
2105 else:
2106 self.test_status = True
2107 return self.test_status
2108
2109 def dhcp_discover_scenario(self, subscriber):
2110 if subscriber.has_service('DHCP'):
2111 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002112 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002113 t1 = self.subscriber_dhcp_1release()
2114 self.test_status = True
2115 return self.test_status
2116 else:
2117 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2118 self.test_status = True
2119 return self.test_status
2120
2121 def subscriber_dhcp_1release(self, iface = INTF_RX_DEFAULT):
2122 config = {'startip':'10.10.100.20', 'endip':'10.10.100.21',
2123 'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
2124 'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
2125 self.onos_dhcp_table_load(config)
2126 self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
2127 cip, sip = self.send_recv()
A R Karthick76a497a2017-04-12 10:59:39 -07002128 log_test.info('Releasing ip %s to server %s' %(cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07002129 assert_equal(self.dhcp.release(cip), True)
A R Karthick76a497a2017-04-12 10:59:39 -07002130 log_test.info('Triggering DHCP discover again after release')
ChetanGaonker2099d722016-10-07 15:16:58 -07002131 cip2, sip2 = self.send_recv(update_seed = True)
A R Karthick76a497a2017-04-12 10:59:39 -07002132 log_test.info('Verifying released IP was given back on rediscover')
ChetanGaonker2099d722016-10-07 15:16:58 -07002133 assert_equal(cip, cip2)
A R Karthick76a497a2017-04-12 10:59:39 -07002134 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
ChetanGaonker2099d722016-10-07 15:16:58 -07002135 assert_equal(self.dhcp.release(cip2), True)
2136 def dhcp_client_reboot_scenario(self, subscriber):
2137 if subscriber.has_service('DHCP'):
2138 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002139 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002140 tl = self.subscriber_dhcp_client_request_after_reboot()
2141 self.test_status = True
2142 return self.test_status
2143 else:
2144 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2145 self.test_status = True
2146 return self.test_status
2147
2148 def subscriber_dhcp_client_request_after_reboot(self, iface = INTF_RX_DEFAULT):
2149 #''' Client sends DHCP Request after reboot.'''
2150
2151 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2152 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2153 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2154 self.onos_dhcp_table_load(config)
2155 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2156 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002157 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002158 (cip, sip, mac) )
2159
A R Karthick76a497a2017-04-12 10:59:39 -07002160 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 -07002161
2162 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002163 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 -07002164 assert_not_equal(cip, None)
2165
2166 else:
2167 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2168 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002169 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002170 os.system('ifconfig '+iface+' down')
A R Karthick76a497a2017-04-12 10:59:39 -07002171 log_test.info('Client goes down.')
2172 log_test.info('Delay for 5 seconds.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002173
2174 time.sleep(5)
2175
2176 os.system('ifconfig '+iface+' up')
A R Karthick76a497a2017-04-12 10:59:39 -07002177 log_test.info('Client is up now.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002178
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 assert_not_equal(new_cip, None)
2183 elif new_cip != None:
A R Karthick76a497a2017-04-12 10:59:39 -07002184 log_test.info("Got DHCP ACK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002185 def dhcp_client_renew_scenario(self, subscriber):
2186 if subscriber.has_service('DHCP'):
2187 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002188 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002189 tl = self.subscriber_dhcp_client_renew_time()
2190 self.test_status = True
2191 return self.test_status
2192 else:
2193 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2194 self.test_status = True
2195 return self.test_status
2196
2197 def subscriber_dhcp_client_renew_time(self, iface = INTF_RX_DEFAULT):
2198 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2199 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2200 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2201 self.onos_dhcp_table_load(config)
2202 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2203 cip, sip, mac , lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002204 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002205 (cip, sip, mac) )
2206
A R Karthick76a497a2017-04-12 10:59:39 -07002207 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 -07002208 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002209 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 -07002210 assert_not_equal(cip, None)
2211 elif cip and sip and mac:
A R Karthick76a497a2017-04-12 10:59:39 -07002212 log_test.info("Triggering DHCP Request.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002213 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, renew_time = True)
2214 if new_cip and new_sip and lval:
A R Karthick76a497a2017-04-12 10:59:39 -07002215 log_test.info("Client 's Renewal time is :%s",lval)
2216 log_test.info("Generating delay till renewal time.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002217 time.sleep(lval)
A R Karthick76a497a2017-04-12 10:59:39 -07002218 log_test.info("Client Sending Unicast DHCP request.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002219 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac, unicast = True)
2220 if latest_cip and latest_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002221 log_test.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
ChetanGaonker2099d722016-10-07 15:16:58 -07002222 (latest_cip, mac, latest_sip) )
2223
2224 elif latest_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002225 log_test.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002226 elif new_cip == None or new_sip == None or lval == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002227 log_test.info("Got DHCP NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002228 def dhcp_server_reboot_scenario(self, subscriber):
2229 if subscriber.has_service('DHCP'):
2230 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002231 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002232 tl = self.subscriber_dhcp_server_after_reboot()
2233 self.test_status = True
2234 return self.test_status
2235 else:
2236 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2237 self.test_status = True
2238 return self.test_status
2239 def subscriber_dhcp_server_after_reboot(self, iface = INTF_RX_DEFAULT):
2240 ''' DHCP server goes down.'''
2241 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2242 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2243 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2244 self.onos_dhcp_table_load(config)
2245 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2246 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002247 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002248 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002249 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 -07002250 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002251 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 -07002252 assert_not_equal(cip, None)
2253 else:
2254 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2255 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002256 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002257 assert_not_equal(new_cip, None)
A R Karthick76a497a2017-04-12 10:59:39 -07002258 log_test.info('Getting DHCP server Down.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002259 onos_ctrl = OnosCtrl(self.dhcp_app)
2260 onos_ctrl.deactivate()
2261 for i in range(0,4):
A R Karthick76a497a2017-04-12 10:59:39 -07002262 log_test.info("Sending DHCP Request.")
2263 log_test.info('')
ChetanGaonker2099d722016-10-07 15:16:58 -07002264 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2265 if new_cip == None and new_sip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002266 log_test.info('')
2267 log_test.info("DHCP Request timed out.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002268 elif new_cip and new_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002269 log_test.info("Got Reply from DHCP server.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002270 assert_equal(new_cip,None) #Neagtive Test Case
A R Karthick76a497a2017-04-12 10:59:39 -07002271 log_test.info('Getting DHCP server Up.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002272# self.activate_apps(self.dhcp_app)
2273 onos_ctrl = OnosCtrl(self.dhcp_app)
2274 status, _ = onos_ctrl.activate()
2275 assert_equal(status, True)
2276 time.sleep(3)
2277 for i in range(0,4):
A R Karthick76a497a2017-04-12 10:59:39 -07002278 log_test.info("Sending DHCP Request after DHCP server is up.")
2279 log_test.info('')
ChetanGaonker2099d722016-10-07 15:16:58 -07002280 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2281 if new_cip == None and new_sip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002282 log_test.info('')
2283 log_test.info("DHCP Request timed out.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002284 elif new_cip and new_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002285 log_test.info("Got Reply from DHCP server.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002286 assert_equal(new_cip,None) #Neagtive Test Case
2287 def dhcp_client_rebind_scenario(self, subscriber):
2288 if subscriber.has_service('DHCP'):
2289 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002290 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002291 tl = self.subscriber_dhcp_client_rebind_time()
2292 self.test_status = True
2293 return self.test_status
2294 else:
2295 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2296 self.test_status = True
2297 return self.test_status
2298
2299 def subscriber_dhcp_client_rebind_time(self, iface = INTF_RX_DEFAULT):
2300 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2301 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2302 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2303 self.onos_dhcp_table_load(config)
2304 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2305 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002306 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002307 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002308 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 -07002309 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002310 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 -07002311 assert_not_equal(cip, None)
2312 elif cip and sip and mac:
A R Karthick76a497a2017-04-12 10:59:39 -07002313 log_test.info("Triggering DHCP Request.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002314 new_cip, new_sip, lval = self.dhcp.only_request(cip, mac, rebind_time = True)
2315 if new_cip and new_sip and lval:
A R Karthick76a497a2017-04-12 10:59:39 -07002316 log_test.info("Client 's Rebind time is :%s",lval)
2317 log_test.info("Generating delay till rebind time.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002318 time.sleep(lval)
A R Karthick76a497a2017-04-12 10:59:39 -07002319 log_test.info("Client Sending broadcast DHCP requests for renewing lease or for getting new ip.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002320 self.dhcp.after_T2 = True
2321 for i in range(0,4):
2322 latest_cip, latest_sip = self.dhcp.only_request(new_cip, mac)
2323 if latest_cip and latest_sip:
A R Karthick76a497a2017-04-12 10:59:39 -07002324 log_test.info("Got DHCP Ack. Lease Renewed for ip %s and mac %s from server %s." %
ChetanGaonker2099d722016-10-07 15:16:58 -07002325 (latest_cip, mac, latest_sip) )
2326 break
2327 elif latest_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002328 log_test.info("Got DHCP NAK. Lease not renewed.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002329 assert_not_equal(latest_cip, None)
2330 elif new_cip == None or new_sip == None or lval == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002331 log_test.info("Got DHCP NAK.Lease not Renewed.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002332 def dhcp_starvation_scenario(self, subscriber):
2333 if subscriber.has_service('DHCP'):
2334 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002335 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002336 tl = self.subscriber_dhcp_starvation()
2337 self.test_status = True
2338 return self.test_status
2339 else:
2340 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2341 self.test_status = True
2342 return self.test_status
2343
2344 def subscriber_dhcp_starvation(self, iface = INTF_RX_DEFAULT):
2345 '''DHCP starve'''
2346 config = {'startip':'182.17.0.20', 'endip':'182.17.0.69',
2347 'ip':'182.17.0.2', 'mac': "ca:fe:c3:fe:ca:fe",
2348 'subnet': '255.255.255.0', 'broadcast':'182.17.0.255', 'router':'182.17.0.1'}
2349 self.onos_dhcp_table_load(config)
2350 self.dhcp = DHCPTest(seed_ip = '182.17.0.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07002351 log_test.info('Verifying 1 ')
ChetanGaonker2099d722016-10-07 15:16:58 -07002352 for x in xrange(50):
2353 mac = RandMAC()._fix()
2354 self.send_recv(mac = mac)
A R Karthick76a497a2017-04-12 10:59:39 -07002355 log_test.info('Verifying 2 ')
ChetanGaonker2099d722016-10-07 15:16:58 -07002356 cip, sip = self.send_recv(update_seed = True, validate = False)
2357 assert_equal(cip, None)
2358 assert_equal(sip, None)
2359
2360 def dhcp_same_client_multi_discovers_scenario(self, subscriber):
2361 if subscriber.has_service('DHCP'):
2362 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002363 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002364 tl = self.subscriber_dhcp_same_client_multiple_discover()
2365 self.test_status = True
2366 return self.test_status
2367 else:
2368 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2369 self.test_status = True
2370 return self.test_status
2371 def subscriber_dhcp_same_client_multiple_discover(self, iface = INTF_RX_DEFAULT):
2372 ''' DHCP Client sending multiple discover . '''
2373 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
2374 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
2375 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
2376 self.onos_dhcp_table_load(config)
2377 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
2378 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002379 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 -07002380 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002381 log_test.info('Triggering DHCP discover again.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002382 new_cip, new_sip, new_mac , lval = self.dhcp.only_discover()
2383 if cip == new_cip:
A R Karthick76a497a2017-04-12 10:59:39 -07002384 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 -07002385 % (new_cip, new_sip, new_mac) )
2386 elif cip != new_cip:
A R Karthick76a497a2017-04-12 10:59:39 -07002387 log_test.info('Ip after 1st discover %s' %cip)
2388 log_test.info('Map after 2nd discover %s' %new_cip)
ChetanGaonker2099d722016-10-07 15:16:58 -07002389 assert_equal(cip, new_cip)
2390
2391 def dhcp_same_client_multi_request_scenario(self, subscriber):
2392 if subscriber.has_service('DHCP'):
2393 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002394 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002395 tl = self.subscriber_dhcp_same_client_multiple_request()
2396 self.test_status = True
2397 return self.test_status
2398 else:
2399 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2400 self.test_status = True
2401 return self.test_status
2402 def subscriber_dhcp_same_client_multiple_request(self, iface = INTF_RX_DEFAULT):
2403 ''' DHCP Client sending multiple repeat DHCP requests. '''
2404 config = {'startip':'10.10.10.20', 'endip':'10.10.10.69',
2405 'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
2406 'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
2407 self.onos_dhcp_table_load(config)
2408 self.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07002409 log_test.info('Sending DHCP discover and DHCP request.')
ChetanGaonker2099d722016-10-07 15:16:58 -07002410 cip, sip = self.send_recv()
2411 mac = self.dhcp.get_mac(cip)[0]
A R Karthick76a497a2017-04-12 10:59:39 -07002412 log_test.info("Sending DHCP request again.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002413 new_cip, new_sip = self.dhcp.only_request(cip, mac)
2414 if (new_cip,new_sip) == (cip,sip):
A R Karthick76a497a2017-04-12 10:59:39 -07002415 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 -07002416 % (new_cip, new_sip, mac) )
2417 elif (new_cip,new_sip):
A R Karthick76a497a2017-04-12 10:59:39 -07002418 log_test.info('No DHCP ACK')
ChetanGaonker2099d722016-10-07 15:16:58 -07002419 assert_equal(new_cip, None)
2420 assert_equal(new_sip, None)
2421 else:
2422 print "Something went wrong."
2423
2424 def dhcp_client_desired_ip_scenario(self, subscriber):
2425 if subscriber.has_service('DHCP'):
2426 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002427 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002428 tl = self.subscriber_dhcp_client_desired_address()
2429 self.test_status = True
2430 return self.test_status
2431 else:
2432 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2433 self.test_status = True
2434 return self.test_status
2435
2436 def subscriber_dhcp_client_desired_address(self, iface = INTF_RX_DEFAULT):
2437 '''DHCP Client asking for desired IP address.'''
2438 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2439 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2440 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2441 self.onos_dhcp_table_load(config)
2442 self.dhcp = DHCPTest(seed_ip = '20.20.20.31', iface = iface)
2443 cip, sip, mac , lval = self.dhcp.only_discover(desired = True)
A R Karthick76a497a2017-04-12 10:59:39 -07002444 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002445 (cip, sip, mac) )
2446 if cip == self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002447 log_test.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002448 (cip, sip, mac) )
2449 elif cip != self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002450 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002451 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002452 log_test.info('The desired ip was: %s .' % self.dhcp.seed_ip)
ChetanGaonker2099d722016-10-07 15:16:58 -07002453 assert_equal(cip, self.dhcp.seed_ip)
2454 def dhcp_client_request_pkt_with_non_offered_ip_scenario(self, subscriber):
2455 if subscriber.has_service('DHCP'):
2456 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002457 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002458 tl = self.subscriber_dhcp_server_nak_packet()
2459 self.test_status = True
2460 return self.test_status
2461 else:
2462 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2463 self.test_status = True
2464 return self.test_status
2465
2466 def subscriber_dhcp_server_nak_packet(self, iface = INTF_RX_DEFAULT):
2467 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2468 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2469 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2470 self.onos_dhcp_table_load(config)
2471 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
2472 cip, sip, mac, lval = self.dhcp.only_discover()
A R Karthick76a497a2017-04-12 10:59:39 -07002473 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002474 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002475 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 -07002476 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002477 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 -07002478 assert_not_equal(cip, None)
2479 else:
2480 new_cip, new_sip = self.dhcp.only_request('20.20.20.31', mac)
2481 if new_cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002482 log_test.info("Got DHCP server NAK.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002483 assert_equal(new_cip, None) #Negative Test Case
2484
2485 def dhcp_client_requested_out_pool_ip_scenario(self, subscriber):
2486 if subscriber.has_service('DHCP'):
2487 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002488 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002489 tl = self.subscriber_dhcp_client_desired_address_out_of_pool()
2490 self.test_status = True
2491 return self.test_status
2492 else:
2493 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2494 self.test_status = True
2495 return self.test_status
2496 def subscriber_dhcp_client_desired_address_out_of_pool(self, iface = INTF_RX_DEFAULT):
2497 '''DHCP Client asking for desired IP address from out of pool.'''
2498 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2499 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2500 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2501 self.onos_dhcp_table_load(config)
2502 self.dhcp = DHCPTest(seed_ip = '20.20.20.35', iface = iface)
2503 cip, sip, mac, lval = self.dhcp.only_discover(desired = True)
A R Karthick76a497a2017-04-12 10:59:39 -07002504 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002505 (cip, sip, mac) )
2506 if cip == self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002507 log_test.info('Got dhcp client IP %s from server %s for mac %s as desired .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002508 (cip, sip, mac) )
2509 assert_equal(cip, self.dhcp.seed_ip) #Negative Test Case
2510
2511 elif cip != self.dhcp.seed_ip:
A R Karthick76a497a2017-04-12 10:59:39 -07002512 log_test.info('Got dhcp client IP %s from server %s for mac %s .' %
ChetanGaonker2099d722016-10-07 15:16:58 -07002513 (cip, sip, mac) )
A R Karthick76a497a2017-04-12 10:59:39 -07002514 log_test.info('The desired ip was: %s .' % self.dhcp.seed_ip)
ChetanGaonker2099d722016-10-07 15:16:58 -07002515 assert_not_equal(cip, self.dhcp.seed_ip)
2516
2517 elif cip == None:
A R Karthick76a497a2017-04-12 10:59:39 -07002518 log_test.info('Got DHCP NAK')
ChetanGaonker2099d722016-10-07 15:16:58 -07002519
2520 def dhcp_client_specific_lease_scenario(self, subscriber):
2521 if subscriber.has_service('DHCP'):
2522 time.sleep(2)
A R Karthick76a497a2017-04-12 10:59:39 -07002523 log_test.info('Running subscriber %s DHCP rediscover scenario test' %subscriber.name)
ChetanGaonker2099d722016-10-07 15:16:58 -07002524 tl = self.subscriber_dhcp_specific_lease_packet()
2525 self.test_status = True
2526 return self.test_status
2527 else:
2528 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
2529 self.test_status = True
2530 return self.test_status
ChetanGaonker2099d722016-10-07 15:16:58 -07002531 def subscriber_dhcp_specific_lease_packet(self, iface = INTF_RX_DEFAULT):
2532 ''' Client sends DHCP Discover packet for particular lease time.'''
2533 config = {'startip':'20.20.20.30', 'endip':'20.20.20.69',
2534 'ip':'20.20.20.2', 'mac': "ca:fe:ca:fe:ca:fe",
2535 'subnet': '255.255.255.0', 'broadcast':'20.20.20.255', 'router':'20.20.20.1'}
2536 self.onos_dhcp_table_load(config)
2537 self.dhcp = DHCPTest(seed_ip = '20.20.20.45', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07002538 log_test.info('Sending DHCP discover with lease time of 700')
ChetanGaonker2099d722016-10-07 15:16:58 -07002539 cip, sip, mac, lval = self.dhcp.only_discover(lease_time = True)
2540
A R Karthick76a497a2017-04-12 10:59:39 -07002541 log_test.info("Verifying Client 's IP and mac in DHCP Offer packet.")
ChetanGaonker2099d722016-10-07 15:16:58 -07002542 if (cip == None and mac != None):
A R Karthick76a497a2017-04-12 10:59:39 -07002543 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 -07002544 assert_not_equal(cip, None)
2545 elif lval != 700:
A R Karthick76a497a2017-04-12 10:59:39 -07002546 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 -07002547 (cip, sip, mac, lval) )
2548 assert_not_equal(lval, 700)