blob: 601eb95cd6604951edb14c1f957364b593f8c6c9 [file] [log] [blame]
ChetanGaonker3441faf2016-10-27 12:15:21 -07001#
2# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import unittest
17from threading import Timer
18from nose.tools import *
19from nose.twistedtools import reactor, deferred
20from twisted.internet import defer
21from scapy.all import *
22import time, monotonic
23import os, sys
24import tempfile
25import random
ChetanGaonkerfc7b0302016-11-10 08:45:56 -080026import Queue
ChetanGaonker3441faf2016-10-27 12:15:21 -070027import threading
28from IGMP import *
29from McastTraffic import *
30from Stats import Stats
31from OnosCtrl import OnosCtrl
32from OltConfig import OltConfig
33from Channels import IgmpChannel
34from EapTLS import TLSAuthTest
35from scapy_ssl_tls.ssl_tls import *
36from scapy_ssl_tls.ssl_tls_crypto import *
37log.setLevel('INFO')
38from EapolAAA import *
39from enum import *
40import noseTlsAuthHolder as tlsAuthHolder
41from tls_cert import Key
42from socket import *
43from CordTestServer import cord_test_radius_restart
44import struct
45import scapy
46from CordTestBase import CordTester
47from CordContainer import *
A R Karthick9313b762016-11-07 13:14:35 -080048from CordLogger import CordLogger
ChetanGaonker3441faf2016-10-27 12:15:21 -070049import re
50from random import randint
51from time import sleep
52
53import json
54from OnosFlowCtrl import OnosFlowCtrl
55from OltConfig import OltConfig
56from threading import current_thread
57import collections
58
59class IGMPTestState:
60
61 def __init__(self, groups = [], df = None, state = 0):
62 self.df = df
63 self.state = state
64 self.counter = 0
65 self.groups = groups
66 self.group_map = {} ##create a send/recv count map
67 for g in groups:
68 self.group_map[g] = (Stats(), Stats())
69
70 def update(self, group, tx = 0, rx = 0, t = 0):
71 self.counter += 1
72 index = 0 if rx == 0 else 1
73 v = tx if rx == 0 else rx
74 if self.group_map.has_key(group):
75 self.group_map[group][index].update(packets = v, t = t)
76
77 def update_state(self):
78 self.state = self.state ^ 1
79
A R Karthick9313b762016-11-07 13:14:35 -080080class netCondition_exchange(CordLogger):
ChetanGaonker3441faf2016-10-27 12:15:21 -070081
82 V_INF1 = 'veth0'
83 V_INF2 = 'veth1'
84 MGROUP1 = '239.1.2.3'
85 MGROUP2 = '239.2.2.3'
86 MINVALIDGROUP1 = '255.255.255.255'
87 MINVALIDGROUP2 = '239.255.255.255'
88 MMACGROUP1 = "01:00:5e:01:02:03"
89 MMACGROUP2 = "01:00:5e:02:02:03"
90 IGMP_DST_MAC = "01:00:5e:00:00:16"
91 IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1"
92 IP_SRC = '1.2.3.4'
93 IP_DST = '224.0.0.22'
94 NEGATIVE_TRAFFIC_STATUS = 1
95 igmp_eth = Ether(dst = IGMP_DST_MAC, type = ETH_P_IP)
96 igmp_ip = IP(dst = IP_DST)
97 IGMP_TEST_TIMEOUT = 5
98 IGMP_QUERY_TIMEOUT = 60
99 MCAST_TRAFFIC_TIMEOUT = 10
100 TEST_TIMEOUT_DELAY = 340
101 PORT_TX_DEFAULT = 2
102 PORT_RX_DEFAULT = 1
103 max_packets = 100
104 app_igmp = 'org.opencord.igmp'
105 olt_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json')
106 ROVER_TEST_TIMEOUT = 10 #3600*86
107 ROVER_TIMEOUT = (ROVER_TEST_TIMEOUT - 100)
108 ROVER_JOIN_TIMEOUT = 60
109
110 app_tls = 'org.opencord.aaa'
111 TLS_TIMEOUT = 20
112 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
113MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
114VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE
115ChMKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
116JAYDVQQDEx1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjAzMTEx
117ODUzMzVaFw0xNzAzMDYxODUzMzVaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECBMC
118Q0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UEChMKQ2llbmEgSW5jLjEeMBwG
119CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDEx1FeGFtcGxlIENl
120cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
121ggEBAL9Jv54TkqycL3U2Fdd/y5NXdnPVXwAVV3m6I3eIffVCv8eS+mwlbl9dnbjo
122qqlGEgA3sEg5HtnKoW81l3PSyV/YaqzUzbcpDlgWlbNkFQ3nVxh61gSU34Fc4h/W
123plSvCkwGSbV5udLtEe6S9IflP2Fu/eXa9vmUtoPqDk66p9U/nWVf2H1GJy7XanWg
124wke+HpQvbzoSfPJS0e5Rm9KErrzaIkJpqt7soW+OjVJitUax7h45RYY1HHHlbMQ0
125ndWW8UDsCxFQO6d7nsijCzY69Y8HarH4mbVtqhg3KJevxD9UMRy6gdtPMDZLah1c
126LHRu14ucOK4aF8oICOgtcD06auUCAwEAAaOCASwwggEoMB0GA1UdDgQWBBQwEs0m
127c8HARTVp21wtiwgav5biqjCBwAYDVR0jBIG4MIG1gBQwEs0mc8HARTVp21wtiwga
128v5biqqGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQH
129EwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
130D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
131dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
132oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
133hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp
134jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo
135bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L
136opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej
137gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM
138729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
139-----END CERTIFICATE-----'''
140
141 def onos_aaa_config(self):
142 aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
143 'radiusIp': '172.17.0.2' } } } }
144 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
145 aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip
146 self.onos_ctrl.activate()
147 time.sleep(2)
148 self.onos_load_tls_config(aaa_dict)
149
150 def onos_load_tls_config(self, config):
151 status, code = OnosCtrl.config(config)
152 if status is False:
153 log.info('Configure request for AAA returned status %d' %code)
154 assert_equal(status, True)
155 time.sleep(3)
156
157 @classmethod
158 def setUpClass(cls):
159 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
160 cls.port_map, _ = cls.olt.olt_port_map()
161 OnosCtrl.cord_olt_config(cls.olt.olt_device_data())
162 cls.device_id = OnosCtrl.get_device_id()
163
164 @classmethod
165 def tearDownClass(cls): pass
166
167 def setUp_igmp(self):
168 ''' Activate the igmp app'''
169 apps = self.app_igmp
170 self.onos_ctrl = OnosCtrl(apps)
171# self.onos_ctrl = OnosCtrl(self.app_tls)
172 self.onos_aaa_config()
173 self.onos_ctrl.activate()
174 self.igmp_channel = IgmpChannel()
175
176 def setUp_tls(self):
177 ''' Activate the igmp app'''
178 apps = self.app_tls
179 self.onos_ctrl = OnosCtrl(apps)
180 self.onos_aaa_config()
181
182 def tearDown(self):
183 '''Deactivate the dhcp app'''
184 apps = [self.app_igmp, self.app_tls]
185 for app in apps:
186 onos_ctrl = OnosCtrl(app)
187 onos_ctrl.deactivate()
188# log.info('Restarting the Radius container in the setup after running every subscriber test cases by default')
189# rest = Container('cord-radius', 'cord-test/radius',)
190# rest.restart('cord-radius','10')
191# radius = Radius()
192# radius_ip = radius.ip()
193# print('Radius server is running with IP %s' %radius_ip)
194 #os.system('ifconfig '+INTF_RX_DEFAULT+' up')
195
196 def onos_load_igmp_config(self, config):
197 log.info('onos load config is %s'%config)
198 status, code = OnosCtrl.config(config)
199 if status is False:
200 log.info('JSON request returned status %d' %code)
201 assert_equal(status, True)
202 time.sleep(2)
203
204 def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],flag = False):
205 ssm_dict = {'apps' : { 'org.onosproject.igmp' : { 'ssmTranslate' : [] } } }
206 ssm_xlate_list = ssm_dict['apps']['org.onosproject.igmp']['ssmTranslate']
207 if flag: #to maintain seperate group-source pair.
208 for i in range(len(groups)):
209 d = {}
210 d['source'] = src_list[i] or '0.0.0.0'
211 d['group'] = groups[i]
212 ssm_xlate_list.append(d)
213 else:
214 for g in groups:
215 for s in src_list:
216 d = {}
217 d['source'] = s or '0.0.0.0'
218 d['group'] = g
219 ssm_xlate_list.append(d)
220 self.onos_load_igmp_config(ssm_dict)
221 cord_port_map = {}
222 for g in groups:
223 cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT)
224 self.igmp_channel.cord_port_table_load(cord_port_map)
225 time.sleep(2)
226
227 def mcast_ip_range(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'):
228 start = list(map(int, start_ip.split(".")))
229 end = list(map(int, end_ip.split(".")))
230 temp = start
231 ip_range = []
232 ip_range.append(start_ip)
233 while temp != end:
234 start[3] += 1
235 for i in (3, 2, 1):
236 if temp[i] == 255:
237 temp[i] = 0
238 temp[i-1] += 1
239 ip_range.append(".".join(map(str, temp)))
240 return ip_range
241
242 def random_mcast_ip(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'):
243 start = list(map(int, start_ip.split(".")))
244 end = list(map(int, end_ip.split(".")))
245 temp = start
246 ip_range = []
247 ip_range.append(start_ip)
248 while temp != end:
249 start[3] += 1
250 for i in (3, 2, 1):
251 if temp[i] == 255:
252 temp[i] = 0
253 temp[i-1] += 1
254 ip_range.append(".".join(map(str, temp)))
255 return random.choice(ip_range)
256
257 def source_ip_range(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
258 start = list(map(int, start_ip.split(".")))
259 end = list(map(int, end_ip.split(".")))
260 temp = start
261 ip_range = []
262 ip_range.append(start_ip)
263 while temp != end:
264 start[3] += 1
265 for i in (3, 2, 1):
266 if temp[i] == 255:
267 temp[i] = 0
268 temp[i-1] += 1
269 ip_range.append(".".join(map(str, temp)))
270 return ip_range
271
272 def randomsourceip(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
273 start = list(map(int, start_ip.split(".")))
274 end = list(map(int, end_ip.split(".")))
275 temp = start
276 ip_range = []
277 ip_range.append(start_ip)
278 while temp != end:
279 start[3] += 1
280 for i in (3, 2, 1):
281 if temp[i] == 255:
282 temp[i] = 0
283 temp[i-1] += 1
284 ip_range.append(".".join(map(str, temp)))
285 return random.choice(ip_range)
286
287 def get_igmp_intf(self):
288 inst = os.getenv('TEST_INSTANCE', None)
289 if not inst:
290 return 'veth0'
291 inst = int(inst) + 1
292 if inst >= self.port_map['uplink']:
293 inst += 1
294 if self.port_map.has_key(inst):
295 return self.port_map[inst]
296 return 'veth0'
297
298 def igmp_verify_join(self, igmpStateList):
299 sendState, recvState = igmpStateList
300 ## check if the send is received for the groups
301 for g in sendState.groups:
302 tx_stats = sendState.group_map[g][0]
303 tx = tx_stats.count
304 assert_greater(tx, 0)
305 rx_stats = recvState.group_map[g][1]
306 rx = rx_stats.count
307 assert_greater(rx, 0)
308 log.info('Receive stats %s for group %s' %(rx_stats, g))
309
310 log.info('IGMP test verification success')
311
312 def igmp_verify_leave(self, igmpStateList, leave_groups):
313 sendState, recvState = igmpStateList[0], igmpStateList[1]
314 ## check if the send is received for the groups
315 for g in sendState.groups:
316 tx_stats = sendState.group_map[g][0]
317 rx_stats = recvState.group_map[g][1]
318 tx = tx_stats.count
319 rx = rx_stats.count
320 assert_greater(tx, 0)
321 if g not in leave_groups:
322 log.info('Received %d packets for group %s' %(rx, g))
323 for g in leave_groups:
324 rx = recvState.group_map[g][1].count
325 assert_equal(rx, 0)
326
327 log.info('IGMP test verification success')
328
329 def mcast_traffic_timer(self):
330 self.mcastTraffic.stopReceives()
331
332 def send_mcast_cb(self, send_state):
333 for g in send_state.groups:
334 send_state.update(g, tx = 1)
335 return 0
336
337 ##Runs in the context of twisted reactor thread
338 def igmp_recv(self, igmpState, iface = 'veth0'):
339 p = self.recv_socket.recv()
340 try:
341 send_time = float(p.payload.load)
342 recv_time = monotonic.monotonic()
343 except:
344 log.info('Unexpected Payload received: %s' %p.payload.load)
345 return 0
346 #log.info( 'Recv in %.6f secs' %(recv_time - send_time))
347 igmpState.update(p.dst, rx = 1, t = recv_time - send_time)
348 return 0
349
350 def send_igmp_join(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE,
351 ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1):
352 if ssm_load is True:
353 self.onos_ssm_table_load(groups, src_list)
354 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
355 gaddr=self.IP_DST)
356 for g in groups:
357 gr = IGMPv3gr(rtype= record_type, mcaddr=g)
358 gr.sources = src_list
359 igmp.grps.append(gr)
360 if ip_pkt is None:
361 ip_pkt = self.igmp_eth/self.igmp_ip
362 pkt = ip_pkt/igmp
363 IGMPv3.fixup(pkt)
364 sendp(pkt, iface=iface)
365 if delay != 0:
366 time.sleep(delay)
367
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800368
369 def send_igmp_join_negative(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE,
370 ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1, ip_src = None, invalid_igmp_join = None ):
371 if ssm_load is True:
372 self.onos_ssm_table_load(groups, src_list)
373 if invalid_igmp_join == 'igmp_type':
374 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT_NEGATIVE, max_resp_code=30,
375 gaddr=self.IP_DST)
376 else:
377 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
378 gaddr=self.IP_DST)
379 if invalid_igmp_join == 'record_type':
380 record_type = IGMP_V3_GR_TYPE_INCLUDE_NEGATIVE
381
382 for g in groups:
383 gr = IGMPv3gr(rtype= record_type, mcaddr=g)
384 gr.sources = src_list
385 igmp.grps.append(gr)
386 if ip_pkt is None:
387 if ip_src is None:
388 ip_pkt = self.igmp_eth/self.igmp_ip
389 else:
390 igmp_ip_src = IP(dst = self.IP_DST, src = ip_src)
391 ip_pkt = self.igmp_eth/igmp_ip_src
392 pkt = ip_pkt/igmp
393 if invalid_igmp_join == 'ttl':
394 set_ttl = 10
395 IGMPv3.fixup(pkt,invalid_ttl = set_ttl)
396 else:
397 IGMPv3.fixup(pkt)
398 sendp(pkt, iface=iface)
399 if delay != 0:
400 time.sleep(delay)
401
ChetanGaonker3441faf2016-10-27 12:15:21 -0700402 def send_igmp_join_recvQuery(self, groups, rec_queryCount = None, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2):
403 self.onos_ssm_table_load(groups, src_list)
404 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
405 gaddr=self.IP_DST)
406 for g in groups:
407 gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
408 gr.sources = src_list
409 gr.sources = src_list
410 igmp.grps.append(gr)
411 if ip_pkt is None:
412 ip_pkt = self.igmp_eth/self.igmp_ip
413 pkt = ip_pkt/igmp
414 IGMPv3.fixup(pkt)
415 if rec_queryCount == None:
416 log.info('Sending IGMP join for group %s and waiting for one query packet and printing the packet' %groups)
417 resp = srp1(pkt, iface=iface)
418 else:
419 log.info('Sending IGMP join for group %s and waiting for periodic query packets and printing one packet' %groups)
420 resp = srp1(pkt, iface=iface)
421# resp = srp1(pkt, iface=iface) if rec_queryCount else srp3(pkt, iface=iface)
422 resp[0].summary()
423 log.info('Sent IGMP join for group %s and received a query packet and printing packet' %groups)
424 if delay != 0:
425 time.sleep(delay)
426
427 def send_igmp_leave(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2):
428 log.info('entering into igmp leave function')
429 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
430 gaddr=self.IP_DST)
431 for g in groups:
432 gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
433 gr.sources = src_list
434 igmp.grps.append(gr)
435 if ip_pkt is None:
436 ip_pkt = self.igmp_eth/self.igmp_ip
437 pkt = ip_pkt/igmp
438 IGMPv3.fixup(pkt)
439 sendp(pkt, iface = iface)
440 if delay != 0:
441 time.sleep(delay)
442
443 def send_igmp_leave_listening_group_specific_query(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2):
444 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
445 gaddr=self.IP_DST)
446 for g in groups:
447 gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
448 gr.sources = src_list
449 igmp.grps.append(gr)
450 if ip_pkt is None:
451 ip_pkt = self.igmp_eth/self.igmp_ip
452 pkt = ip_pkt/igmp
453 IGMPv3.fixup(pkt)
454 log.info('Sending IGMP leave for group %s and waiting for one group specific query packet and printing the packet' %groups)
455 resp = srp1(pkt, iface=iface)
456 resp[0].summary()
457 log.info('Sent IGMP leave for group %s and received a group specific query packet and printing packet' %groups)
458 if delay != 0:
459 time.sleep(delay)
460
461 @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+390)
462 def test_netCondition_with_delay_between_igmp_join_and_data_recv(self):
463 self.setUp_igmp()
464 randomDelay = randint(10,300)
465 groups = ['224.0.1.1', '225.0.0.1']
466 self.onos_ssm_table_load(groups)
467 df = defer.Deferred()
468 igmpState = IGMPTestState(groups = groups, df = df)
469 igmpStateRecv = IGMPTestState(groups = groups, df = df)
470 igmpStateList = (igmpState, igmpStateRecv)
471 mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, arg = igmpState)
472 self.df = df
473 self.mcastTraffic = mcastTraffic
474 self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP)
475
476 def mcast_traffic_delay_start():
477 mcastTraffic.start()
478
479 def igmp_srp_task(stateList):
480 igmpSendState, igmpRecvState = stateList
481 if not mcastTraffic.isRecvStopped():
482 result = self.igmp_recv(igmpRecvState)
483 reactor.callLater(0, igmp_srp_task, stateList)
484 else:
485 self.mcastTraffic.stop()
486 self.recv_socket.close()
487 self.igmp_verify_join(stateList)
488 self.df.callback(0)
489
490 self.send_igmp_join(groups)
491 log.info('Holding multicast data for a period of random delay = {} secs'.format(randomDelay))
492 t = Timer(randomDelay, mcast_traffic_delay_start)
493 t.start()
494
495 self.test_timer = reactor.callLater(randomDelay+30, self.mcast_traffic_timer)
496 reactor.callLater(randomDelay+10, igmp_srp_task, igmpStateList)
497 return df
498
499 @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+390)
500 def test_netCondition_with_delay_between_data_recv_and_igmp_join(self):
501 self.setUp_igmp()
502 randomDelay = randint(10,300)
503 groups = ['224.0.1.1', '225.0.0.1']
504 self.onos_ssm_table_load(groups)
505 df = defer.Deferred()
506 igmpState = IGMPTestState(groups = groups, df = df)
507 igmpStateRecv = IGMPTestState(groups = groups, df = df)
508 igmpStateList = (igmpState, igmpStateRecv)
509 mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, arg = igmpState)
510 self.df = df
511 self.mcastTraffic = mcastTraffic
512 self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP)
513
514 def mcast_join_delay_start():
515 log.info('Holding channel join for a period of random delay = {} secs'.format(randomDelay))
516 self.send_igmp_join(groups)
517
518 def igmp_srp_task(stateList):
519 igmpSendState, igmpRecvState = stateList
520 if not mcastTraffic.isRecvStopped():
521 result = self.igmp_recv(igmpRecvState)
522 reactor.callLater(0, igmp_srp_task, stateList)
523 else:
524 self.mcastTraffic.stop()
525 self.recv_socket.close()
526 self.igmp_verify_join(stateList)
527 self.df.callback(0)
528
529 mcastTraffic.start()
530 t = Timer(randomDelay, mcast_join_delay_start)
531 t.start()
532
533 self.test_timer = reactor.callLater(randomDelay+30, self.mcast_traffic_timer)
534 reactor.callLater(randomDelay+10, igmp_srp_task, igmpStateList)
535 return df
536
537
538 @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+340)
539 def test_netCondition_with_delay_between_igmp_leave_and_data(self):
540 self.setUp_igmp()
541 randomDelay = randint(10,300)
542 groups = ['224.0.1.10', '225.0.0.10']
543 leave_groups = ['224.0.1.10']
544 self.onos_ssm_table_load(groups)
545 df = defer.Deferred()
546 igmpState = IGMPTestState(groups = groups, df = df)
547 igmpStateRecv = IGMPTestState(groups = groups, df = df)
548 igmpStateList = (igmpState, igmpStateRecv)
549 mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb,
550 arg = igmpState)
551 self.df = df
552 self.mcastTraffic = mcastTraffic
553 self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP)
554
555 def mcast_leave_delay_start():
556 self.send_igmp_leave(leave_groups, delay = 3)
557 join_state = IGMPTestState(groups = leave_groups)
558 status = self.igmp_not_recv_task(self.V_INF1,leave_groups, join_state)
559 log.info('Verified status for igmp recv task %s'%status)
560 assert status == 1 , 'EXPECTED RESULT'
561 self.df.callback(0)
562
563 mcastTraffic.start()
564 self.send_igmp_join(groups)
565 log.info('Holding multicast leave packet for a period of random delay = {} secs'.format(randomDelay))
566 t = Timer(randomDelay+10, mcast_leave_delay_start)
567 t.start()
568 return df
569
570 def igmp_not_recv_task(self, intf, groups, join_state):
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800571 log.info('Entering igmp not recv task loop')
ChetanGaonker3441faf2016-10-27 12:15:21 -0700572 recv_socket = L2Socket(iface = intf, type = ETH_P_IP)
573 group_map = {}
574 for g in groups:
575 group_map[g] = [0,0]
576
577 log.info('Verifying join interface should not receive any multicast data')
578 self.NEGATIVE_TRAFFIC_STATUS = 1
579 def igmp_recv_cb(pkt):
580 log.info('Multicast packet %s received for left groups %s' %(pkt[IP].dst, groups))
581 self.NEGATIVE_TRAFFIC_STATUS = 2
582 sniff(prn = igmp_recv_cb, count = 1, lfilter = lambda p: IP in p and p[IP].dst in groups,
583 timeout = 3, opened_socket = recv_socket)
584 recv_socket.close()
585 return self.NEGATIVE_TRAFFIC_STATUS
586
587 ## Its sample test case based on this test case we had added all below scenarios.
588 @deferred(TEST_TIMEOUT_DELAY+50)
589 def test_netCondition_in_eap_tls_with_delay_between_positive_IdReq_and_tlsHelloReq(self):
590 self.setUp_tls()
591 randomDelay = randint(10,300)
592 df = defer.Deferred()
593 tls = TLSAuthTest()
594 def eap_tls_eapTlsHelloReq_pkt_delay():
595 tls._eapTlsHelloReq()
596 tls._eapTlsCertReq()
597 tls._eapTlsChangeCipherSpec()
598 tls._eapTlsFinished()
599 df.callback(0)
600 def eap_tls_verify(df):
601 tls._eapSetup()
602 tls.tlsEventTable.EVT_EAP_SETUP
603 tls._eapStart()
604 tls.tlsEventTable.EVT_EAP_START
605 tls._eapIdReq()
606 tls.tlsEventTable.EVT_EAP_ID_REQ
607 log.info('Holding tlsHelloReq packet for a period of random delay = {} secs'.format(randomDelay))
608 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
609 t.start()
610 reactor.callLater(0, eap_tls_verify, df)
611 return df
612
613 @deferred(TEST_TIMEOUT_DELAY+50)
614 def test_netCondition_in_eap_tls_with_delay_between_IdReq_and_tlsHelloReq(self):
615 self.setUp_tls()
616 randomDelay = randint(10,300)
617 df = defer.Deferred()
618 tls = TLSAuthTest()
619 def eap_tls_eapTlsHelloReq_pkt_delay():
620 log.info('Holding tlsHelloReq packet for a period of random delay = {} secs'.format(randomDelay))
621 tls._eapTlsHelloReq()
622 tls._eapTlsCertReq()
623 tls._eapTlsChangeCipherSpec()
624 tls._eapTlsFinished()
625 df.callback(0)
626 def eap_tls_verify(df):
627 tls._eapSetup()
628 tls.tlsEventTable.EVT_EAP_SETUP
629 tls._eapStart()
630 tls.tlsEventTable.EVT_EAP_START
631 tls._eapIdReq()
632 tls.tlsEventTable.EVT_EAP_ID_REQ
633 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
634 t.start()
635 reactor.callLater(0, eap_tls_verify, df)
636 return df
637
638 @deferred(TEST_TIMEOUT_DELAY+100)
639 def test_netCondition_in_eap_tls_with_delay_between_tlsHelloReq_and_eapTlsCertReq(self):
640 self.setUp_tls()
641 randomDelay = randint(10,300)
642 df = defer.Deferred()
643 tls = TLSAuthTest()
644 def eap_tls_eapTlsCertReq_pkt_delay():
645 log.info('Holding eapTlsCertReq packet for a period of random delay = {} secs'.format(randomDelay))
646 tls._eapTlsCertReq_delay()
647 tls._eapTlsChangeCipherSpec()
648 tls._eapTlsFinished()
649 df.callback(0)
650 def eap_tls_verify(df):
651 tls._eapSetup()
652 tls.tlsEventTable.EVT_EAP_SETUP
653 tls._eapStart()
654 tls.tlsEventTable.EVT_EAP_START
655 tls._eapIdReq()
656 tls.tlsEventTable.EVT_EAP_ID_REQ
657 tls._eapTlsHelloReq()
658 while tls.server_hello_done_received == False:
659 r = tls.eapol_scapy_recv(cb = tls.eapol_server_hello_cb,
660 lfilter =
661 lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \
662 pkt[EAP].code == EAP.REQUEST)
663 if len(r) == 0:
664 tls.tlsFail()
665 t = Timer(randomDelay, eap_tls_eapTlsCertReq_pkt_delay)
666 t.start()
667 reactor.callLater(0, eap_tls_verify, df)
668 return df
669
670 @deferred(TEST_TIMEOUT_DELAY+50)
671 def test_netCondition_in_eap_tls_with_delay_between_TlsCertReq_and_TlsChangeCipherSpec(self):
672 self.setUp_tls()
673 randomDelay = randint(10,300)
674 df = defer.Deferred()
675 tls = TLSAuthTest()
676 def eap_tls_TlsChangeCipherSpec_pkt_delay():
677 log.info('Holding TlsChangeCipherSpec packet for a period of random delay = {} secs'.format(randomDelay))
678 tls._eapTlsChangeCipherSpec()
679 tls._eapTlsFinished()
680 df.callback(0)
681 def eap_tls_verify(df):
682 tls._eapSetup()
683 tls.tlsEventTable.EVT_EAP_SETUP
684 tls._eapStart()
685 tls.tlsEventTable.EVT_EAP_START
686 tls._eapIdReq()
687 tls.tlsEventTable.EVT_EAP_ID_REQ
688 tls._eapTlsHelloReq()
689 tls._eapTlsCertReq()
690 t = Timer(randomDelay, eap_tls_TlsChangeCipherSpec_pkt_delay)
691 t.start()
692 reactor.callLater(0, eap_tls_verify, df)
693 return df
694
695 @deferred(TEST_TIMEOUT_DELAY+50)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800696 def test_netCondition_in_eap_tls_with_no_cert_and_delay_between_IdReq_and_HelloReq(self):
ChetanGaonker3441faf2016-10-27 12:15:21 -0700697 self.setUp_tls()
698 randomDelay = randint(10,300)
699 df = defer.Deferred()
700 def tls_no_cert_cb():
701 log.info('TLS authentication failed with no certificate')
702 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
703 def eap_tls_eapTlsHelloReq_pkt_delay():
704 log.info('Holding HelloReq packet with no cert for a period of random delay = {} secs'.format(randomDelay))
705 tls._eapTlsHelloReq()
706 tls._eapTlsCertReq()
707 assert_equal(tls.failTest, True)
708 tls._eapTlsChangeCipherSpec()
709 tls._eapTlsFinished()
710 df.callback(0)
711 def eap_tls_no_cert(df):
712 tls._eapSetup()
713 tls.tlsEventTable.EVT_EAP_SETUP
714 tls._eapStart()
715 tls.tlsEventTable.EVT_EAP_START
716 tls._eapIdReq()
717 tls.tlsEventTable.EVT_EAP_ID_REQ
718 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
719 t.start()
720 reactor.callLater(0, eap_tls_no_cert, df)
721 return df
722
723 @deferred(TEST_TIMEOUT_DELAY+100)
724 def test_netCondition_in_eap_tls_with_delay_and_no_cert_between_tlsHelloReq_and_eapTlsCertReq(self):
725 self.setUp_tls()
726 randomDelay = randint(10,300)
727 df = defer.Deferred()
728 def tls_no_cert_cb():
729 log.info('TLS authentication failed with no certificate')
730 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
731 def eap_tls_eapTlsHelloReq_pkt_delay():
732 log.info('Holding eapTlsCertReq packet with no cert for a period of random delay = {} secs'.format(randomDelay))
733 tls._eapTlsCertReq_delay()
734 assert_equal(tls.failTest, True)
735 tls._eapTlsChangeCipherSpec()
736 assert_equal(tls.failTest, True)
737 tls._eapTlsFinished()
738 df.callback(0)
739 def eap_tls_no_cert(df):
740 tls._eapSetup()
741 tls.tlsEventTable.EVT_EAP_SETUP
742 tls._eapStart()
743 tls.tlsEventTable.EVT_EAP_START
744 tls._eapIdReq()
745 tls.tlsEventTable.EVT_EAP_ID_REQ
746 tls._eapTlsHelloReq()
747 while tls.server_hello_done_received == False:
748 r = tls.eapol_scapy_recv(cb = tls.eapol_server_hello_cb,
749 lfilter =
750 lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \
751 pkt[EAP].code == EAP.REQUEST)
752 if len(r) == 0:
753 tls.tlsFail()
754 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
755 t.start()
756 reactor.callLater(0, eap_tls_no_cert, df)
757 return df
758
759
760 @deferred(TEST_TIMEOUT_DELAY+50)
761 def test_netCondition_in_eap_tls_with_delay_and_no_cert_between_TlsCertReq_and_TlsChangeCipherSpec(self):
762 self.setUp_tls()
763 randomDelay = randint(10,300)
764 df = defer.Deferred()
765 def tls_no_cert_cb():
766 log.info('TLS authentication failed with no certificate')
767 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
768 def eap_tls_TlsChangeCipherSpec_pkt_delay():
769 tls._eapTlsChangeCipherSpec()
770 assert_equal(tls.failTest, True)
771 tls._eapTlsFinished()
772 df.callback(0)
773 def eap_tls_no_cert(df):
774 tls._eapSetup()
775 tls.tlsEventTable.EVT_EAP_SETUP
776 tls._eapStart()
777 tls._eapIdReq()
778 tls.tlsEventTable.EVT_EAP_ID_REQ
779 tls._eapTlsHelloReq()
780 tls._eapTlsCertReq()
781 log.info('Holding TlsChangeCipherSpec packet with no cert for a period of random delay = {} secs'.format(randomDelay))
782 t = Timer(randomDelay, eap_tls_TlsChangeCipherSpec_pkt_delay)
783 t.start()
784 reactor.callLater(0, eap_tls_no_cert, df)
785 return df
786
787 @deferred(TEST_TIMEOUT_DELAY+50)
788 def test_netCondition_in_eap_tls_with_invalid_cert_and_delay_between_IdReq_and_HelloReq(self):
789 self.setUp_tls()
790 randomDelay = randint(10,300)
791 df = defer.Deferred()
792 def tls_invalid_cert_cb():
793 log.info('TLS authentication failed with invalid certificate')
794 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, client_cert = self.CLIENT_CERT_INVALID)
795 def eap_tls_eapTlsHelloReq_pkt_delay():
796 tls._eapTlsHelloReq()
797 tls._eapTlsCertReq()
798 assert_equal(tls.failTest, True)
799 tls._eapTlsChangeCipherSpec()
800 tls._eapTlsFinished()
801 df.callback(0)
802 def eap_tls_invalid_cert(df):
803 tls._eapSetup()
804 tls.tlsEventTable.EVT_EAP_SETUP
805 tls._eapStart()
806 tls.tlsEventTable.EVT_EAP_START
807 tls._eapIdReq()
808 tls.tlsEventTable.EVT_EAP_ID_REQ
809 log.info('Holding HelloReq packet with invalid cert for a period of random delay = {} secs'.format(randomDelay))
810 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
811 t.start()
812 reactor.callLater(0, eap_tls_invalid_cert, df)
813 return df
814
815 @deferred(TEST_TIMEOUT_DELAY+100)
816 def test_netCondition_in_eap_tls_with_invalid_cert_and_delay_between_tlsHelloReq_and_eapTlsCertReq(self):
817 self.setUp_tls()
818 randomDelay = randint(10,300)
819 df = defer.Deferred()
820 def tls_invalid_cert_cb():
821 log.info('TLS authentication failed with invalid certificate')
822 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, client_cert = self.CLIENT_CERT_INVALID)
823 def eap_tls_eapTlsHelloReq_pkt_delay():
ChetanGaonker12f9f422016-11-10 23:21:21 -0800824 log.info('Holding eapTlsCertReq packet with invalid cert for a period of random delay = {} sec, delay'.format(randomDelay))
ChetanGaonker3441faf2016-10-27 12:15:21 -0700825 tls._eapTlsCertReq_delay()
826 tls._eapTlsChangeCipherSpec()
827 assert_equal(tls.failTest, True)
828 tls._eapTlsFinished()
829 df.callback(0)
830 def eap_tls_invalid_cert(df):
831 tls._eapSetup()
832 tls.tlsEventTable.EVT_EAP_SETUP
833 tls._eapStart()
834 tls.tlsEventTable.EVT_EAP_START
835 tls._eapIdReq()
836 tls.tlsEventTable.EVT_EAP_ID_REQ
837 tls._eapTlsHelloReq()
838 while tls.server_hello_done_received == False:
839 r = tls.eapol_scapy_recv(cb = tls.eapol_server_hello_cb,
840 lfilter =
841 lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \
842 pkt[EAP].code == EAP.REQUEST)
843 if len(r) == 0:
844 tls.tlsFail()
845
846 log.info('Holding eapTlsCertReq packet with invalid cert for a period of random delay = {} secs'.format(randomDelay))
847 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
848 t.start()
849 reactor.callLater(0, eap_tls_invalid_cert, df)
850 return df
851
852
853 @deferred(TEST_TIMEOUT_DELAY+50)
854 def test_netCondition_in_eap_tls_with_invalid_cert_delay_between_TlsCertReq_and_TlsChangeCipherSpec(self):
855 self.setUp_tls()
856 randomDelay = randint(10,300)
857 df = defer.Deferred()
858 def tls_invalid_cert_cb():
859 log.info('TLS authentication failed with invalid certificate')
860 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, client_cert = self.CLIENT_CERT_INVALID)
861 def eap_tls_TlsChangeCipherSpec_pkt_delay():
862 tls._eapTlsChangeCipherSpec()
863 assert_equal(tls.failTest, True)
864 tls._eapTlsFinished()
865 df.callback(0)
866 def eap_tls_invalid_cert(df):
867 tls._eapSetup()
868 tls.tlsEventTable.EVT_EAP_SETUP
869 tls._eapStart()
870 tls.tlsEventTable.EVT_EAP_START
871 tls._eapIdReq()
872 tls.tlsEventTable.EVT_EAP_ID_REQ
873 tls._eapTlsHelloReq()
874 tls._eapTlsCertReq()
875 log.info('Holding TlsChangeCipherSpec packet with invalid cert for a period of random delay = {} secs'.format(randomDelay))
876 t = Timer(randomDelay, eap_tls_TlsChangeCipherSpec_pkt_delay)
877 t.start()
878 reactor.callLater(0, eap_tls_invalid_cert, df)
879 return df
880
881 @deferred(TEST_TIMEOUT_DELAY+50)
882 def test_netCondition_in_multiple_eap_tls_requests_with_delay_between_IdReq_and_HelloReq(self):
883 self.setUp_tls()
884 df = defer.Deferred()
885 threads = []
886 clients = 10
887 def eap_tls_eapTlsHelloReq_pkt_delay(df):
888 def multiple_tls_random_delay():
889 randomDelay = randint(10,300)
890 tls = TLSAuthTest(src_mac = 'random')
891 tls._eapSetup()
892 tls.tlsEventTable.EVT_EAP_SETUP
893 tls._eapStart()
894 tls.tlsEventTable.EVT_EAP_START
895 tls._eapIdReq()
896 tls.tlsEventTable.EVT_EAP_ID_REQ
897 log.info('Holding tlsHelloReq packet for a period of random delay = {} secs'.format(randomDelay))
898 time.sleep(randomDelay)
899 tls._eapTlsHelloReq()
900 tls._eapTlsCertReq()
901 tls._eapTlsChangeCipherSpec()
902 tls._eapTlsFinished()
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800903 log.info('Authentication successful for user %d'%i)
ChetanGaonker3441faf2016-10-27 12:15:21 -0700904 # Sending multiple tls clients and making random delay in between client and server packets.
905 for i in xrange(clients):
906 thread = threading.Thread(target = multiple_tls_random_delay)
907 time.sleep(randint(1,2))
908 thread.start()
909 threads.append(thread)
910 time.sleep(300)
911 for thread in threads:
912 thread.join()
913 #df.callback(0)
914 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
915 return df
916
917 @deferred(TEST_TIMEOUT_DELAY+450)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800918 def test_netCondition_with_multiple_authentication_and_delay_between_complete_authentication(self):
ChetanGaonker3441faf2016-10-27 12:15:21 -0700919 self.setUp_tls()
920 df = defer.Deferred()
921 threads = []
922 clients = 100
923 def eap_tls_eapTlsHelloReq_pkt_delay(df):
924 def multiple_tls_random_delay():
925 randomDelay = randint(10,300)
926 tls = TLSAuthTest(src_mac = 'random')
927 tls._eapSetup()
928 tls.tlsEventTable.EVT_EAP_SETUP
929 tls._eapStart()
930 tls.tlsEventTable.EVT_EAP_START
931 tls._eapIdReq()
932 tls.tlsEventTable.EVT_EAP_ID_REQ
933 tls._eapTlsHelloReq()
934 tls._eapTlsCertReq()
935 tls._eapTlsChangeCipherSpec()
936 tls._eapTlsFinished()
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800937 log.info('Authentication successful for user %d'%i)
ChetanGaonker3441faf2016-10-27 12:15:21 -0700938 # Client authendicating multiple times one after other and making random delay in between authendication.
939 for i in xrange(clients):
940# thread = threading.Thread(target = multiple_tls_random_delay)
941 multiple_tls_random_delay()
942 time.sleep(randomDelay)
943 df.callback(0)
944 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
945 return df
946
947 @deferred(TEST_TIMEOUT_DELAY+450)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800948 def test_netCondition_with_multiple_authentication_and_delay_between_every_100_tls_burst(self):
ChetanGaonker3441faf2016-10-27 12:15:21 -0700949 self.setUp_tls()
950 randomDelay = randint(10,300)
951 df = defer.Deferred()
952 threads = []
953 tls = []
954 clients = 10
955 def eap_tls_eapTlsHelloReq_pkt_delay(df):
956 def multiple_tls_random_delay():
957 #randomDelay = 3
958 for x in xrange(clients):
959 tls.append(TLSAuthTest(src_mac = 'random'))
960 for x in xrange(clients):
961 tls[x]._eapSetup()
962 tls[x].tlsEventTable.EVT_EAP_SETUP
963 for x in xrange(clients):
964 tls[x]._eapStart()
965 tls[x].tlsEventTable.EVT_EAP_START
966 for x in xrange(clients):
967 tls[x]._eapIdReq()
968 tls[x].tlsEventTable.EVT_EAP_ID_REQ
969 for x in xrange(clients):
970 tls[x]._eapTlsHelloReq()
971 for x in xrange(clients):
972 tls[x]._eapTlsCertReq()
973 for x in xrange(clients):
974 tls[x]._eapTlsChangeCipherSpec()
975 for x in xrange(clients):
976 tls[x]._eapTlsFinished()
977 for x in xrange(clients):
ChetanGaonkerfc7b0302016-11-10 08:45:56 -0800978 log.info('Authentication successful for user %d'%i)
ChetanGaonker3441faf2016-10-27 12:15:21 -0700979 # Client authendicating multiple times one after other and making random delay in between authendication.
980 for i in xrange(2):
981 multiple_tls_random_delay()
982 time.sleep(randomDelay)
983 df.callback(0)
984 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
985 return df
986
987 @deferred(TEST_TIMEOUT_DELAY+90)
988 def test_netCondition_with_delay_between_mac_flow_and_traffic(self):
989 df = defer.Deferred()
990 randomDelay = randint(10,300)
991 #self.setUpClass_flows()
992 egress = 1
993 ingress = 2
994 egress_mac = '00:00:00:00:00:01'
995 ingress_mac = '00:00:00:00:00:02'
996 pkt = Ether(src = ingress_mac, dst = egress_mac)/IP()
997 self.success = False
998
999 def mac_recv_task():
1000 def recv_cb(pkt):
1001 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
1002 self.success = True
1003 sniff(count=2, timeout=randomDelay+50, lfilter = lambda p: p.src == ingress_mac,
1004 prn = recv_cb, iface = self.port_map[egress])
1005
1006 thread = threading.Thread(target = mac_recv_task)
1007
1008 def send_flow_pkt_delay():
1009 sendp(pkt, count=50, iface = self.port_map[ingress])
1010 thread.join()
1011 assert_equal(self.success, True)
1012 df.callback(0)
1013
1014 def creating_mac_flow(df):
1015
1016 flow = OnosFlowCtrl(deviceId = self.device_id,
1017 egressPort = egress,
1018 ingressPort = ingress,
1019 ethSrc = ingress_mac,
1020 ethDst = egress_mac)
1021 result = flow.addFlow()
1022 assert_equal(result, True)
1023 ##wait for flows to be added to ONOS
1024 time.sleep(1)
1025 thread.start()
1026 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
1027 t = Timer(randomDelay, send_flow_pkt_delay)
1028 t.start()
1029 reactor.callLater(0, creating_mac_flow, df)
1030 return df
1031
1032
1033 @deferred(TEST_TIMEOUT_DELAY+90)
1034 def test_netCondition_with_delay_between_ip_flow_and_traffic(self):
1035 df = defer.Deferred()
1036 randomDelay = randint(10,300)
1037 egress = 1
1038 ingress = 2
1039 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
1040 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
1041 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1042 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1043 pkt = L2/L3
1044
1045 def mac_recv_task():
1046 def recv_cb(pkt):
1047 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1048 self.success = True
1049 sniff(count=2, timeout= randomDelay + 30,
1050 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'],
1051 prn = recv_cb, iface = self.port_map[egress])
1052
1053 thread = threading.Thread(target = mac_recv_task)
1054
1055 def send_flow_ip_pkt_delay():
1056 sendp(pkt, count=50, iface = self.port_map[ingress])
1057 thread.join()
1058 assert_equal(self.success, True)
1059 df.callback(0)
1060
1061 def creating_ip_flow(df):
1062 flow = OnosFlowCtrl(deviceId = self.device_id,
1063 egressPort = egress,
1064 ingressPort = ingress,
1065 ethType = '0x0800',
1066 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
1067 ipDst = ('IPV4_DST', egress_map['ip']+'/32')
1068 )
1069 result = flow.addFlow()
1070 assert_equal(result, True)
1071 ##wait for flows to be added to ONOS
1072 time.sleep(1)
1073 self.success = False
1074 ##wait for flows to be added to ONOS
1075 time.sleep(1)
1076 thread.start()
1077 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
1078 t = Timer(randomDelay, send_flow_ip_pkt_delay)
1079 t.start()
1080 reactor.callLater(0, creating_ip_flow, df)
1081 return df
1082
1083 @deferred(TEST_TIMEOUT_DELAY+90)
1084 def test_netCondition_with_delay_between_tcp_port_flow_and_traffic(self):
1085 df = defer.Deferred()
1086 egress = 1
1087 ingress = 2
1088 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 9500 }
1089 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 9000 }
1090 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1091 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1092 L4 = TCP(sport = ingress_map['tcp_port'], dport = egress_map['tcp_port'])
1093 pkt = L2/L3/L4
1094
1095 def mac_recv_task():
1096 def recv_cb(pkt):
1097 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
1098 self.success = True
1099 sniff(count=2, timeout= randomDelay+30, lfilter = lambda p: TCP in p and p[TCP].dport == egress_map['tcp_port']
1100 and p[TCP].sport == ingress_map['tcp_port'], prn = recv_cb, iface = self.port_map[egress])
1101
1102 thread = threading.Thread(target = mac_recv_task)
1103
1104 def send_flow_tcp_pkt_delay():
1105 sendp(pkt, count=50, iface = self.port_map[ingress])
1106 thread.join()
1107 assert_equal(self.success, True)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001108 # df.callback(0)
ChetanGaonker3441faf2016-10-27 12:15:21 -07001109
1110 def creating_tcp_flow(df):
1111 flow = OnosFlowCtrl(deviceId = self.device_id,
1112 egressPort = egress,
1113 ingressPort = ingress,
1114 tcpSrc = ingress_map['tcp_port'],
1115 tcpDst = egress_map['tcp_port']
1116 )
1117 result = flow.addFlow()
1118 assert_equal(result, True)
1119 ##wait for flows to be added to ONOS
1120 time.sleep(1)
1121 self.success = False
1122 thread.start()
ChetanGaonker12f9f422016-11-10 23:21:21 -08001123 log.info('Holding a packet to verify if flows are active after {} sec, delay'.format(randomDelay))
1124 t = Timer(randomDelay, send_flow_tcp_pkt_delay)
ChetanGaonker3441faf2016-10-27 12:15:21 -07001125 t.start()
1126 df.callback(0)
1127 reactor.callLater(0, creating_tcp_flow, df)
1128 return df
1129
1130 @deferred(TEST_TIMEOUT_DELAY+90)
1131 def test_netCondition_with_delay_between_udp_port_flow_and_traffic(self):
1132 df = defer.Deferred()
1133 randomDelay = randint(10,300)
1134 egress = 1
1135 ingress = 2
1136 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 9500 }
1137 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 9000 }
1138 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1139 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1140 L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port'])
1141 pkt = L2/L3/L4
1142
1143 def mac_recv_task():
1144 def recv_cb(pkt):
1145 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
1146 self.success = True
1147 sniff(count=2, timeout=randomDelay + 30,
1148 lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port']
1149 and p[UDP].sport == ingress_map['udp_port'], prn = recv_cb, iface = self.port_map[egress])
1150
1151 thread = threading.Thread(target = mac_recv_task)
1152
1153 def send_flow_udp_pkt_delay():
1154 sendp(pkt, count=50, iface = self.port_map[ingress])
1155 thread.join()
1156 assert_equal(self.success, True)
1157 df.callback(0)
1158
1159 def creating_udp_flow(df):
1160 flow = OnosFlowCtrl(deviceId = self.device_id,
1161 egressPort = egress,
1162 ingressPort = ingress,
1163 udpSrc = ingress_map['udp_port'],
1164 udpDst = egress_map['udp_port']
1165 )
1166 result = flow.addFlow()
1167 assert_equal(result, True)
1168 ##wait for flows to be added to ONOS
1169 time.sleep(1)
1170 self.success = False
1171 thread.start()
1172 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
1173 t = Timer(randomDelay, send_flow_udp_pkt_delay)
1174 t.start()
1175
1176 df.callback(0)
1177 reactor.callLater(0, creating_udp_flow, df)
1178 return df
1179
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001180 def netCondition_with_delay_between_multiple_igmp_joins_and_data(self,users,group_end_ip,source_list_end_ip,user_src_end_ip, data_pkt =50):
1181 self.setUp_igmp()
ChetanGaonker12f9f422016-11-10 23:21:21 -08001182 randomDelay = []
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001183 groups = []
1184 sources = []
1185 subscribers_src_ip = []
1186 status = []
1187 join_threads = []
1188 delay_threads = []
1189 data_threads = []
1190 threads = []
1191 subscriber = users
1192 count = 1
1193 mcastips = self.mcast_ip_range(start_ip = '229.0.0.1',end_ip = group_end_ip)
1194 sourceips = self.source_ip_range(start_ip = '10.10.0.1',end_ip = source_list_end_ip)
1195 subscriber_sourceips = self.source_ip_range(start_ip = '20.20.0.1',end_ip = user_src_end_ip)
1196 while count<=subscriber:
1197 group = random.choice(mcastips)
1198 source = random.choice(sourceips)
1199 subscriber_sourceip = random.choice(subscriber_sourceips)
1200 if group in groups:
1201 pass
1202 else:
1203 log.info('group = %s source list = %s and subscriber source ip in join = %s'%(group,source, subscriber_sourceip))
1204 groups.append(group)
1205 sources.append(source)
1206 subscribers_src_ip.append(subscriber_sourceip)
1207 count += 1
1208 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
1209
1210 def multiple_joins_send_in_threads(group, source, subscriber_src_ip,data_pkt = data_pkt):
1211 self.send_igmp_join(groups = [group], src_list = [source],record_type = IGMP_V3_GR_TYPE_INCLUDE,
1212 iface = self.V_INF1, ip_src = [subscriber_src_ip])
ChetanGaonker12f9f422016-11-10 23:21:21 -08001213 randomDelay_in_thread = randint(10,30)
1214 log.info('This is running in a thread, with igmp join sent and delay {}'.format(randomDelay_in_thread))
1215 time.sleep(randomDelay_in_thread)
1216 log.info('This is running in a thread, with igmp join sent and delay {}'.format(randomDelay_in_thread))
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001217 status = self.verify_igmp_data_traffic_in_thread(group,intf=self.V_INF1,source=source, data_pkt = data_pkt)
1218 #assert_equal(status, True)
1219 log.info('Data received for group %s from source %s and status is %s '%(group,source,status))
1220 self.igmp_threads_result.append(status)
1221
1222 for i in range(subscriber):
1223 thread = threading.Thread(target = multiple_joins_send_in_threads, args = (groups[i], sources[i], subscribers_src_ip[i]))
1224 time.sleep(randint(1,2))
1225 thread.start()
1226 threads.append(thread)
1227
1228# time.sleep(50)
1229 for thread in threads:
1230 thread.join()
1231
1232 def verify_igmp_data_traffic_in_thread(self, group, intf='veth0', source='1.2.3.4', data_pkt =50, negative = None):
1233 log.info('Verifying multicast traffic for group %s from source %s'%(group,source))
1234 self.success = False
1235 def recv_task():
1236 def igmp_recv_cb(pkt):
1237 #log.info('received multicast data packet is %s'%pkt.show())
1238 log.info('Multicast data received for group %s from source %s'%(group,source))
1239 self.success = True
1240 sniff(prn = igmp_recv_cb,lfilter = lambda p: IP in p and p[IP].dst == group and p[IP].src == source, count=1,timeout = 2, iface='veth0')
1241 t = threading.Thread(target = recv_task)
1242 t.start()
1243 self.send_multicast_data_traffic_from_thread(group,source=source, data_pkt=data_pkt)
1244 t.join()
1245 if (negative is None) and self.success is True:
1246 return self.success
1247 elif (negative is not None) and self.success is True:
1248 log.info('Multicast traffic should not received because this is negative scenario, but it is received')
1249 self.success = False
1250 elif (negative is not None) and self.success is False:
1251 log.info('Multicast traffic should is not received because this is negative scenario, hence status is True')
1252 self.success = True
1253 return self.success
1254
1255 def send_multicast_data_traffic_from_thread(self, group, intf= 'veth2',source = '1.2.3.4', data_pkt = 50):
1256 dst_mac = self.iptomac_convert(group)
1257 eth = Ether(dst= dst_mac)
1258 ip = IP(dst=group,src=source)
1259 data = repr(monotonic.monotonic())
1260 log.info('Sending %s number of multicast packet to the multicast group %s'%(data_pkt, group))
1261 sendp(eth/ip/data,count=data_pkt, iface = intf)
1262 pkt = (eth/ip/data)
1263 #log.info('multicast traffic packet %s'%pkt.show())
1264
1265 def iptomac_convert(self, mcast_ip):
1266 mcast_mac = '01:00:5e:'
1267 octets = mcast_ip.split('.')
1268 second_oct = int(octets[1]) & 127
1269 third_oct = int(octets[2])
1270 fourth_oct = int(octets[3])
1271 mcast_mac = mcast_mac + format(second_oct,'02x') + ':' + format(third_oct, '02x') + ':' + format(fourth_oct, '02x')
1272 return mcast_mac
1273
1274 @deferred(TEST_TIMEOUT_DELAY+50)
1275 def test_netCondition_with_delay_between_multiple_igmp_joins_and_data_for_multiple_subscribers(self):
1276 self.setUp_tls()
1277 df = defer.Deferred()
1278 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1279 def netCondition_multiple_igmp_joins_and_data(df):
1280 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1281 no_users = 10
1282 group_end_ip = '229.0.30.254'
1283 source_list_end_ip = '10.10.30.254'
1284 subscriber_src_end_ip = '20.20.20.254'
1285 self.netCondition_with_delay_between_multiple_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip,
1286 source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip )
1287 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1288 for i in xrange(no_users):
1289 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1290 if assert_equal(self.igmp_threads_result[i], True) is True:
1291 df.callback(0)
1292 df.callback(0)
1293 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1294 return df
1295
1296 @deferred(TEST_TIMEOUT_DELAY+50)
1297 def test_netCondition_with_delay_between_multiple_igmp_joins_and_data_from_multiple_subscribers_with_low_multicast_data_rate(self):
1298 self.setUp_tls()
1299 df = defer.Deferred()
1300 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1301 def netCondition_multiple_igmp_joins_and_data(df):
1302 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1303 no_users = 10
1304 group_end_ip = '229.0.30.254'
1305 source_list_end_ip = '10.10.30.254'
1306 subscriber_src_end_ip = '20.20.20.254'
1307 self.netCondition_with_delay_between_multiple_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip,
1308 source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip, data_pkt = 20)
1309 log.info('IGMP Thread status after running igmp thread %s '%(self.igmp_threads_result))
1310 for i in xrange(no_users):
1311 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1312 if assert_equal(self.igmp_threads_result[i], True) is True:
1313 df.callback(0)
1314 df.callback(0)
1315 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1316 return df
1317
1318 @deferred(TEST_TIMEOUT_DELAY+50)
1319 def test_netCondition_with_delay_between_multiple_igmp_joins_and_data_for_same_subscriber(self):
1320 self.setUp_tls()
1321 df = defer.Deferred()
1322 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1323 def netCondition_multiple_igmp_joins_and_data(df):
1324 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1325 no_users = 5
1326 group_end_ip = '229.0.30.254'
1327 source_list_end_ip = '10.10.30.254'
1328 subscriber_src_end_ip = '20.20.0.1'
1329 self.netCondition_with_delay_between_multiple_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip,
1330 source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip )
1331 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1332 for i in xrange(no_users):
1333 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1334 if assert_equal(self.igmp_threads_result[i], True) is True:
1335 df.callback(0)
1336 df.callback(0)
1337 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1338 return df
1339
1340
1341 @deferred(TEST_TIMEOUT_DELAY+50)
1342 def test_netCondition_with_delay_between_same_igmp_joins_and_data_from_multiple_subscriber(self):
1343 self.setUp_tls()
1344 df = defer.Deferred()
1345 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1346 def netCondition_multiple_igmp_joins_and_data(df):
1347 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1348 no_users = 100
1349 group_end_ip = '229.0.0.1'
1350 source_list_end_ip = '10.10.30.254'
1351 subscriber_src_end_ip = '20.20.20.254'
1352 self.netCondition_with_delay_between_multiple_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip,
1353 source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip )
1354 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1355 for i in xrange(no_users):
1356 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1357 if assert_equal(self.igmp_threads_result[i], True) is True:
1358 df.callback(0)
1359 df.callback(0)
1360 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1361 return df
1362
1363 @deferred(TEST_TIMEOUT_DELAY+50)
1364 def test_netCondition_with_delay_between_multiple_igmp_joins_and_data_from_same_sourcelist_for_multiple_subscriber(self):
1365 self.setUp_tls()
1366 df = defer.Deferred()
1367 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1368 def netCondition_multiple_igmp_joins_and_data(df):
1369 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1370 no_users = 20
1371 group_end_ip = '229.0.30.254'
1372 source_list_end_ip = '10.10.0.1'
1373 subscriber_src_end_ip = '20.20.20.254'
1374 self.netCondition_with_delay_between_multiple_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip,
1375 source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip )
1376 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1377 for i in xrange(no_users):
1378 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1379 if assert_equal(self.igmp_threads_result[i], True) is True:
1380 df.callback(0)
1381 df.callback(0)
1382 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1383 return df
1384
1385
1386 def netCondition_with_multiple_scenarios_igmp_joins_and_data(self,users,group_end_ip,source_list_end_ip,user_src_end_ip,bunch_traffic, data_pkt =50,invalid_joins = None):
1387 self.setUp_igmp()
ChetanGaonker12f9f422016-11-10 23:21:21 -08001388 randomDelay = []
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001389 groups = []
1390 sources = []
1391 subscribers_src_ip = []
1392 status = []
1393 join_threads = []
1394 delay_threads = []
1395 data_threads = []
1396 threads = []
1397 subscriber = users
1398 count = 1
1399 j = 1
1400 negative_traffic = None
1401 mcastips = self.mcast_ip_range(start_ip = '229.0.0.1',end_ip = group_end_ip)
1402 sourceips = self.source_ip_range(start_ip = '10.10.0.1',end_ip = source_list_end_ip)
1403 subscriber_sourceips = self.source_ip_range(start_ip = '20.20.0.1',end_ip = user_src_end_ip)
1404 while count<=subscriber:
1405 group = random.choice(mcastips)
1406 source = random.choice(sourceips)
1407 subscriber_sourceip = random.choice(subscriber_sourceips)
1408 if group in groups:
1409 pass
1410 else:
1411 log.info('group = %s source list = %s and subscriber source ip in join = %s'%(group,source, subscriber_sourceip))
1412 groups.append(group)
1413 sources.append(source)
1414 subscribers_src_ip.append(subscriber_sourceip)
1415 count += 1
1416 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
1417
1418 def multiple_joins_send_in_threads(group, source, subscriber_src_ip,invalid_igmp_join,data_pkt = data_pkt):
1419 if invalid_igmp_join is None:
1420 self.send_igmp_join(groups = [group], src_list = [source],record_type = IGMP_V3_GR_TYPE_INCLUDE,
1421 iface = self.V_INF1, ip_src = [subscriber_src_ip])
1422 else:
1423 negative_traffic = True
1424 self.send_igmp_join_negative(groups = [group], src_list = [source],record_type = IGMP_V3_GR_TYPE_INCLUDE,
1425 iface = self.V_INF1, ip_src = [subscriber_src_ip], invalid_igmp_join = invalid_igmp_join)
ChetanGaonker12f9f422016-11-10 23:21:21 -08001426 randomDelay_in_thread = randint(10,30)
1427 log.info('This is running in thread with igmp join sent and delay {}'.format(randomDelay_in_thread))
1428 time.sleep(randomDelay_in_thread)
1429 log.info('This is running in thread with igmp join sent and delay {}'.format(randomDelay_in_thread))
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001430 status = self.verify_igmp_data_traffic_in_thread(group,intf=self.V_INF1,source=source, data_pkt = data_pkt,negative=negative_traffic)
1431 #assert_equal(status, True)
1432 log.info('data received for group %s from source %s and status is %s '%(group,source,status))
1433 self.igmp_threads_result.append(status)
1434
1435 for i in range(subscriber):
1436 thread = threading.Thread(target = multiple_joins_send_in_threads, args = (groups[i], sources[i], subscribers_src_ip[i], invalid_joins))
1437 if bunch_traffic == 'yes':
1438 if j == 10:
1439 log.info('Here we are throttle traffic for 100 sec of delay and agian creating igmp threads')
1440 time.sleep(randint(100,110))
1441 j = 1
1442 else:
1443 j = j+ 1
1444 time.sleep(randint(1,2))
1445 thread.start()
1446 threads.append(thread)
1447
1448# time.sleep(250)
1449 for thread in threads:
1450 thread.join()
1451
1452
1453 @deferred(TEST_TIMEOUT_DELAY+50)
1454 def test_netCondition_with_throttle_between_multiple_igmp_joins_and_data_from_multiple_subscribers(self):
1455 self.setUp_tls()
1456 df = defer.Deferred()
1457 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1458 def netCondition_multiple_igmp_joins_and_data(df):
1459 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1460 batch_traffic_run = 'yes'
1461 no_users = 11
1462 group_end_ip = '229.0.30.254'
1463 source_list_end_ip = '10.10.30.254'
1464 subscriber_src_end_ip = '20.20.20.254'
1465 self.netCondition_with_multiple_scenarios_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip, source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip, bunch_traffic = batch_traffic_run, data_pkt = 50 )
1466 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1467 for i in xrange(no_users):
1468 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1469 if assert_equal(self.igmp_threads_result[i], True) is True:
1470 df.callback(0)
1471 df.callback(0)
1472 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1473 return df
1474
1475 @deferred(TEST_TIMEOUT_DELAY+50)
1476 def test_netCondition_with_invalid_igmp_type_and_multiple_igmp_joins_and_data_from_multiple_subscribers(self):
1477 self.setUp_tls()
1478 df = defer.Deferred()
1479 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1480 def netCondition_multiple_igmp_joins_and_data(df):
1481 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1482 batch_traffic_run = 'no'
1483 invalid_igmp_join = 'igmp_type'
1484 no_users = 11
1485 group_end_ip = '229.0.30.254'
1486 source_list_end_ip = '10.10.30.254'
1487 subscriber_src_end_ip = '20.20.20.254'
1488 self.netCondition_with_multiple_scenarios_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip, source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip, bunch_traffic = batch_traffic_run, data_pkt = 50, invalid_joins = invalid_igmp_join )
1489 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1490 for i in xrange(no_users):
1491 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1492 if assert_equal(self.igmp_threads_result[i], True) is True:
1493 df.callback(0)
1494 df.callback(0)
1495 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1496 return df
1497
1498 @deferred(TEST_TIMEOUT_DELAY+50)
1499 def test_netCondition_with_invalid_record_type_and_multiple_igmp_joins_and_data_from_multiple_subscribers(self):
1500 self.setUp_tls()
1501 df = defer.Deferred()
1502 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1503 def netCondition_multiple_igmp_joins_and_data(df):
1504 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1505 batch_traffic_run = 'no'
1506 invalid_igmp_join = 'record_type'
1507 no_users = 11
1508 group_end_ip = '229.0.30.254'
1509 source_list_end_ip = '10.10.30.254'
1510 subscriber_src_end_ip = '20.20.20.254'
1511 self.netCondition_with_multiple_scenarios_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip, source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip, bunch_traffic = batch_traffic_run, data_pkt = 50, invalid_joins = invalid_igmp_join )
1512 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1513 for i in xrange(no_users):
1514 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1515 if assert_equal(self.igmp_threads_result[i], True) is True:
1516 df.callback(0)
1517 df.callback(0)
1518 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1519 return df
1520
1521
1522 @deferred(TEST_TIMEOUT_DELAY+50)
1523 def test_netCondition_with_invalid_ttl_and_multiple_igmp_joins_and_data_from_multiple_subscribers(self):
1524 self.setUp_tls()
1525 df = defer.Deferred()
1526 log.info('IGMP Thread status before running igmp thread %s '%(self.igmp_threads_result))
1527 def netCondition_multiple_igmp_joins_and_data(df):
1528 ### Start ips of multicast, source list and subscriber source ip are '229.0.0.1', '10.10.0.1' and '20.20.0.1' respectively
1529 batch_traffic_run = 'no'
1530 invalid_igmp_join = 'ttl_type'
1531 no_users = 11
1532 group_end_ip = '229.0.30.254'
1533 source_list_end_ip = '10.10.30.254'
1534 subscriber_src_end_ip = '20.20.20.254'
1535 self.netCondition_with_multiple_scenarios_igmp_joins_and_data(users = no_users, group_end_ip = group_end_ip, source_list_end_ip = source_list_end_ip, user_src_end_ip = subscriber_src_end_ip, bunch_traffic = batch_traffic_run, data_pkt = 10, invalid_joins = invalid_igmp_join )
1536 log.info('IGMP Thread status after running igmp thread %s '%(self. igmp_threads_result))
1537 for i in xrange(no_users):
1538 log.info('IGMP Thread %s status is %s after running igmp thread '%(i,self.igmp_threads_result[i]))
1539 if assert_equal(self.igmp_threads_result[i], True) is True:
1540 df.callback(0)
1541 df.callback(0)
1542 reactor.callLater(0, netCondition_multiple_igmp_joins_and_data, df)
1543 return df
1544
1545
1546 @deferred(TEST_TIMEOUT_DELAY-250)
1547 def test_netCondition_in_multiple_eap_tls_sessions_with_out_of_order_exchanges_between_serverHello_and_client_packet(self):
1548 self.setUp_tls()
1549 df = defer.Deferred()
1550 threads = []
1551 clients = 1
1552 def eap_tls_eapTlsHelloReq_pkt_delay(df):
1553 def multiple_tls_random_delay():
ChetanGaonker12f9f422016-11-10 23:21:21 -08001554 randomDelay = randint(10,300)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001555 tls = TLSAuthTest(src_mac = 'random')
1556 tls._eapSetup()
1557 tls.tlsEventTable.EVT_EAP_SETUP
1558 tls._eapStart()
1559 tls.tlsEventTable.EVT_EAP_START
1560 tls._eapIdReq()
1561 tls.tlsEventTable.EVT_EAP_ID_REQ
1562 tls._eapTlsCertReq()
1563 assert_equal(tls.failTest, True)
1564 tls._eapTlsHelloReq()
1565 assert_equal(tls.failTest, True)
1566 tls._eapTlsChangeCipherSpec()
1567 assert_equal(tls.failTest, True)
1568 tls._eapTlsFinished()
1569 assert_equal(tls.failTest, True)
1570 log.info('Authentication successful for user %d'%i)
1571 # Sending multiple tls clients and making random delay in between client and server packets.
1572 for i in xrange(clients):
1573 thread = threading.Thread(target = multiple_tls_random_delay)
1574 time.sleep(randint(1,2))
1575 thread.start()
1576 threads.append(thread)
1577 time.sleep(300)
1578 for thread in threads:
1579 thread.join()
1580 #df.callback(0)
1581 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
1582 return df
1583
1584 @deferred(TEST_TIMEOUT_DELAY-250)
1585 def test_netCondition_in_multiple_eap_tls_session_with_out_of_order_exchanges_in_eapTlsCertReq_packets(self):
1586 self.setUp_tls()
1587 df = defer.Deferred()
1588 threads = []
1589 clients = 1
1590 def eap_tls_eapTlsHelloReq_pkt_delay(df):
1591 def multiple_tls_random_delay():
ChetanGaonker12f9f422016-11-10 23:21:21 -08001592 randomDelay = randint(10,300)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001593 tls = TLSAuthTest(src_mac = 'random')
1594 tls._eapSetup()
1595 tls.tlsEventTable.EVT_EAP_SETUP
1596 tls._eapStart()
1597 tls.tlsEventTable.EVT_EAP_START
1598 tls._eapTlsCertReq()
1599 assert_equal(tls.failTest, True)
1600 tls._eapIdReq()
1601 tls.tlsEventTable.EVT_EAP_ID_REQ
1602 assert_equal(tls.failTest, True)
1603 tls._eapTlsCertReq()
1604 assert_equal(tls.failTest, True)
1605 tls._eapTlsHelloReq()
1606 assert_equal(tls.failTest, True)
1607 tls._eapTlsChangeCipherSpec()
1608 assert_equal(tls.failTest, True)
1609 tls._eapTlsFinished()
1610 assert_equal(tls.failTest, True)
1611 log.info('Authentication successful for user %d'%i)
1612 # Sending multiple tls clients and making random delay in between client and server packets.
1613 for i in xrange(clients):
1614 thread = threading.Thread(target = multiple_tls_random_delay)
1615 time.sleep(randint(1,2))
1616 thread.start()
1617 threads.append(thread)
1618 time.sleep(300)
1619 for thread in threads:
1620 thread.join()
1621 #df.callback(0)
1622 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
1623 return df
1624
1625 @deferred(TEST_TIMEOUT_DELAY-250)
1626 def test_netCondition_in_multiple_eap_tls_sessions_with_out_of_order_eapTlsChangeCipherSpec_packets(self):
1627 self.setUp_tls()
1628 df = defer.Deferred()
1629 threads = []
1630 clients = 1
1631 def eap_tls_eapTlsHelloReq_pkt_delay(df):
1632 def multiple_tls_random_delay():
ChetanGaonker12f9f422016-11-10 23:21:21 -08001633 randomDelay = randint(10,300)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001634 tls = TLSAuthTest(src_mac = 'random')
1635 tls._eapSetup()
1636 tls.tlsEventTable.EVT_EAP_SETUP
1637 tls._eapStart()
1638 tls.tlsEventTable.EVT_EAP_START
1639 tls._eapTlsChangeCipherSpec()
1640 tls.failTest = False
1641 tls._eapIdReq()
1642 tls.tlsEventTable.EVT_EAP_ID_REQ
1643 assert_equal(tls.failTest, True)
1644 tls._eapTlsHelloReq()
1645 assert_equal(tls.failTest, True)
1646 tls._eapTlsCertReq()
1647 assert_equal(tls.failTest, True)
1648 tls._eapTlsChangeCipherSpec()
1649 assert_equal(tls.failTest, True)
1650 tls._eapTlsFinished()
1651 assert_equal(tls.failTest, True)
1652 log.info('Authentication successful for user %d'%i)
1653 # Sending multiple tls clients and making random delay in between client and server packets.
1654 for i in xrange(clients):
1655 thread = threading.Thread(target = multiple_tls_random_delay)
1656 time.sleep(randint(1,2))
1657 thread.start()
1658 threads.append(thread)
1659 time.sleep(300)
1660 for thread in threads:
1661 thread.join()
1662 #df.callback(0)
1663 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
1664 return df
1665
1666 @deferred(TEST_TIMEOUT_DELAY-250)
1667 def test_netCondition_in_multiple_eap_tls_sessions_dropping_eapTlsHelloReq_packets(self):
1668 self.setUp_tls()
1669 df = defer.Deferred()
1670 threads = []
1671 clients = 1
1672 def eap_tls_eapTlsHelloReq_pkt_delay(df):
1673 def multiple_tls_random_delay():
ChetanGaonker12f9f422016-11-10 23:21:21 -08001674 randomDelay = randint(10,300)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001675 tls = TLSAuthTest(src_mac = 'random')
1676 tls._eapSetup()
1677 tls.tlsEventTable.EVT_EAP_SETUP
1678 tls._eapStart()
1679 tls.tlsEventTable.EVT_EAP_START
1680 tls._eapIdReq()
1681 tls.tlsEventTable.EVT_EAP_ID_REQ
1682 #tls._eapTlsHelloReq()
1683 tls._eapTlsCertReq()
1684 tls._eapTlsChangeCipherSpec()
1685 assert_equal(tls.failTest, True)
1686 tls._eapTlsFinished()
1687 log.info('Authentication successful for user %d'%i)
1688 # Sending multiple tls clients and making random delay in between client and server packets.
1689 for i in xrange(clients):
1690 thread = threading.Thread(target = multiple_tls_random_delay)
1691 time.sleep(randint(1,2))
1692 thread.start()
1693 threads.append(thread)
1694 time.sleep(300)
1695 for thread in threads:
1696 thread.join()
1697 #df.callback(0)
1698 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
1699 return df
1700
1701 @deferred(TEST_TIMEOUT_DELAY-250)
1702 def test_netCondition_in_multiple_eap_tls_sessions_dropping_eapTlsChangeCipherSpec_packets(self):
1703 self.setUp_tls()
1704 df = defer.Deferred()
1705 threads = []
1706 clients = 1
1707 def eap_tls_eapTlsHelloReq_pkt_delay(df):
1708 def multiple_tls_random_delay():
ChetanGaonker12f9f422016-11-10 23:21:21 -08001709 randomDelay = randint(10,300)
ChetanGaonkerfc7b0302016-11-10 08:45:56 -08001710 tls = TLSAuthTest(src_mac = 'random')
1711 tls._eapSetup()
1712 tls.tlsEventTable.EVT_EAP_SETUP
1713 tls._eapStart()
1714 tls.tlsEventTable.EVT_EAP_START
1715 tls._eapIdReq()
1716 tls.tlsEventTable.EVT_EAP_ID_REQ
1717 tls._eapTlsHelloReq()
1718 tls._eapTlsCertReq()
1719 #tls._eapTlsChangeCipherSpec()
1720 assert_equal(tls.failTest, True)
1721 tls._eapTlsFinished()
1722 log.info('Authentication successful for user %d'%i)
1723 # Sending multiple tls clients and making random delay in between client and server packets.
1724 for i in xrange(clients):
1725 thread = threading.Thread(target = multiple_tls_random_delay)
1726 time.sleep(randint(1,2))
1727 thread.start()
1728 threads.append(thread)
1729 time.sleep(300)
1730 for thread in threads:
1731 thread.join()
1732 #df.callback(0)
1733 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
1734 return df
1735