blob: 5d64d622cf22bb2df4be2b6be93baba10d7ceb9f [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
26import threading
27from IGMP import *
28from McastTraffic import *
29from Stats import Stats
30from OnosCtrl import OnosCtrl
31from OltConfig import OltConfig
32from Channels import IgmpChannel
33from EapTLS import TLSAuthTest
34from scapy_ssl_tls.ssl_tls import *
35from scapy_ssl_tls.ssl_tls_crypto import *
36log.setLevel('INFO')
37from EapolAAA import *
38from enum import *
39import noseTlsAuthHolder as tlsAuthHolder
40from tls_cert import Key
41from socket import *
42from CordTestServer import cord_test_radius_restart
43import struct
44import scapy
45from CordTestBase import CordTester
46from CordContainer import *
47import re
48from random import randint
49from time import sleep
50
51import json
52from OnosFlowCtrl import OnosFlowCtrl
53from OltConfig import OltConfig
54from threading import current_thread
55import collections
56
57class IGMPTestState:
58
59 def __init__(self, groups = [], df = None, state = 0):
60 self.df = df
61 self.state = state
62 self.counter = 0
63 self.groups = groups
64 self.group_map = {} ##create a send/recv count map
65 for g in groups:
66 self.group_map[g] = (Stats(), Stats())
67
68 def update(self, group, tx = 0, rx = 0, t = 0):
69 self.counter += 1
70 index = 0 if rx == 0 else 1
71 v = tx if rx == 0 else rx
72 if self.group_map.has_key(group):
73 self.group_map[group][index].update(packets = v, t = t)
74
75 def update_state(self):
76 self.state = self.state ^ 1
77
78class netCondition_exchange(unittest.TestCase):
79
80 V_INF1 = 'veth0'
81 V_INF2 = 'veth1'
82 MGROUP1 = '239.1.2.3'
83 MGROUP2 = '239.2.2.3'
84 MINVALIDGROUP1 = '255.255.255.255'
85 MINVALIDGROUP2 = '239.255.255.255'
86 MMACGROUP1 = "01:00:5e:01:02:03"
87 MMACGROUP2 = "01:00:5e:02:02:03"
88 IGMP_DST_MAC = "01:00:5e:00:00:16"
89 IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1"
90 IP_SRC = '1.2.3.4'
91 IP_DST = '224.0.0.22'
92 NEGATIVE_TRAFFIC_STATUS = 1
93 igmp_eth = Ether(dst = IGMP_DST_MAC, type = ETH_P_IP)
94 igmp_ip = IP(dst = IP_DST)
95 IGMP_TEST_TIMEOUT = 5
96 IGMP_QUERY_TIMEOUT = 60
97 MCAST_TRAFFIC_TIMEOUT = 10
98 TEST_TIMEOUT_DELAY = 340
99 PORT_TX_DEFAULT = 2
100 PORT_RX_DEFAULT = 1
101 max_packets = 100
102 app_igmp = 'org.opencord.igmp'
103 olt_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup/olt_config.json')
104 ROVER_TEST_TIMEOUT = 10 #3600*86
105 ROVER_TIMEOUT = (ROVER_TEST_TIMEOUT - 100)
106 ROVER_JOIN_TIMEOUT = 60
107
108 app_tls = 'org.opencord.aaa'
109 TLS_TIMEOUT = 20
110 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
111MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
112VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE
113ChMKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
114JAYDVQQDEx1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNjAzMTEx
115ODUzMzVaFw0xNzAzMDYxODUzMzVaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECBMC
116Q0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UEChMKQ2llbmEgSW5jLjEeMBwG
117CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDEx1FeGFtcGxlIENl
118cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
119ggEBAL9Jv54TkqycL3U2Fdd/y5NXdnPVXwAVV3m6I3eIffVCv8eS+mwlbl9dnbjo
120qqlGEgA3sEg5HtnKoW81l3PSyV/YaqzUzbcpDlgWlbNkFQ3nVxh61gSU34Fc4h/W
121plSvCkwGSbV5udLtEe6S9IflP2Fu/eXa9vmUtoPqDk66p9U/nWVf2H1GJy7XanWg
122wke+HpQvbzoSfPJS0e5Rm9KErrzaIkJpqt7soW+OjVJitUax7h45RYY1HHHlbMQ0
123ndWW8UDsCxFQO6d7nsijCzY69Y8HarH4mbVtqhg3KJevxD9UMRy6gdtPMDZLah1c
124LHRu14ucOK4aF8oICOgtcD06auUCAwEAAaOCASwwggEoMB0GA1UdDgQWBBQwEs0m
125c8HARTVp21wtiwgav5biqjCBwAYDVR0jBIG4MIG1gBQwEs0mc8HARTVp21wtiwga
126v5biqqGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRIwEAYDVQQH
127EwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
128D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
129dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
130oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
131hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp
132jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo
133bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L
134opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej
135gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM
136729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
137-----END CERTIFICATE-----'''
138
139 def onos_aaa_config(self):
140 aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
141 'radiusIp': '172.17.0.2' } } } }
142 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
143 aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip
144 self.onos_ctrl.activate()
145 time.sleep(2)
146 self.onos_load_tls_config(aaa_dict)
147
148 def onos_load_tls_config(self, config):
149 status, code = OnosCtrl.config(config)
150 if status is False:
151 log.info('Configure request for AAA returned status %d' %code)
152 assert_equal(status, True)
153 time.sleep(3)
154
155 @classmethod
156 def setUpClass(cls):
157 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
158 cls.port_map, _ = cls.olt.olt_port_map()
159 OnosCtrl.cord_olt_config(cls.olt.olt_device_data())
160 cls.device_id = OnosCtrl.get_device_id()
161
162 @classmethod
163 def tearDownClass(cls): pass
164
165 def setUp_igmp(self):
166 ''' Activate the igmp app'''
167 apps = self.app_igmp
168 self.onos_ctrl = OnosCtrl(apps)
169# self.onos_ctrl = OnosCtrl(self.app_tls)
170 self.onos_aaa_config()
171 self.onos_ctrl.activate()
172 self.igmp_channel = IgmpChannel()
173
174 def setUp_tls(self):
175 ''' Activate the igmp app'''
176 apps = self.app_tls
177 self.onos_ctrl = OnosCtrl(apps)
178 self.onos_aaa_config()
179
180 def tearDown(self):
181 '''Deactivate the dhcp app'''
182 apps = [self.app_igmp, self.app_tls]
183 for app in apps:
184 onos_ctrl = OnosCtrl(app)
185 onos_ctrl.deactivate()
186# log.info('Restarting the Radius container in the setup after running every subscriber test cases by default')
187# rest = Container('cord-radius', 'cord-test/radius',)
188# rest.restart('cord-radius','10')
189# radius = Radius()
190# radius_ip = radius.ip()
191# print('Radius server is running with IP %s' %radius_ip)
192 #os.system('ifconfig '+INTF_RX_DEFAULT+' up')
193
194 def onos_load_igmp_config(self, config):
195 log.info('onos load config is %s'%config)
196 status, code = OnosCtrl.config(config)
197 if status is False:
198 log.info('JSON request returned status %d' %code)
199 assert_equal(status, True)
200 time.sleep(2)
201
202 def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],flag = False):
203 ssm_dict = {'apps' : { 'org.onosproject.igmp' : { 'ssmTranslate' : [] } } }
204 ssm_xlate_list = ssm_dict['apps']['org.onosproject.igmp']['ssmTranslate']
205 if flag: #to maintain seperate group-source pair.
206 for i in range(len(groups)):
207 d = {}
208 d['source'] = src_list[i] or '0.0.0.0'
209 d['group'] = groups[i]
210 ssm_xlate_list.append(d)
211 else:
212 for g in groups:
213 for s in src_list:
214 d = {}
215 d['source'] = s or '0.0.0.0'
216 d['group'] = g
217 ssm_xlate_list.append(d)
218 self.onos_load_igmp_config(ssm_dict)
219 cord_port_map = {}
220 for g in groups:
221 cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT)
222 self.igmp_channel.cord_port_table_load(cord_port_map)
223 time.sleep(2)
224
225 def mcast_ip_range(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'):
226 start = list(map(int, start_ip.split(".")))
227 end = list(map(int, end_ip.split(".")))
228 temp = start
229 ip_range = []
230 ip_range.append(start_ip)
231 while temp != end:
232 start[3] += 1
233 for i in (3, 2, 1):
234 if temp[i] == 255:
235 temp[i] = 0
236 temp[i-1] += 1
237 ip_range.append(".".join(map(str, temp)))
238 return ip_range
239
240 def random_mcast_ip(self,start_ip = '224.0.1.0', end_ip = '224.0.1.100'):
241 start = list(map(int, start_ip.split(".")))
242 end = list(map(int, end_ip.split(".")))
243 temp = start
244 ip_range = []
245 ip_range.append(start_ip)
246 while temp != end:
247 start[3] += 1
248 for i in (3, 2, 1):
249 if temp[i] == 255:
250 temp[i] = 0
251 temp[i-1] += 1
252 ip_range.append(".".join(map(str, temp)))
253 return random.choice(ip_range)
254
255 def source_ip_range(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
256 start = list(map(int, start_ip.split(".")))
257 end = list(map(int, end_ip.split(".")))
258 temp = start
259 ip_range = []
260 ip_range.append(start_ip)
261 while temp != end:
262 start[3] += 1
263 for i in (3, 2, 1):
264 if temp[i] == 255:
265 temp[i] = 0
266 temp[i-1] += 1
267 ip_range.append(".".join(map(str, temp)))
268 return ip_range
269
270 def randomsourceip(self,start_ip = '10.10.0.1', end_ip = '10.10.0.100'):
271 start = list(map(int, start_ip.split(".")))
272 end = list(map(int, end_ip.split(".")))
273 temp = start
274 ip_range = []
275 ip_range.append(start_ip)
276 while temp != end:
277 start[3] += 1
278 for i in (3, 2, 1):
279 if temp[i] == 255:
280 temp[i] = 0
281 temp[i-1] += 1
282 ip_range.append(".".join(map(str, temp)))
283 return random.choice(ip_range)
284
285 def get_igmp_intf(self):
286 inst = os.getenv('TEST_INSTANCE', None)
287 if not inst:
288 return 'veth0'
289 inst = int(inst) + 1
290 if inst >= self.port_map['uplink']:
291 inst += 1
292 if self.port_map.has_key(inst):
293 return self.port_map[inst]
294 return 'veth0'
295
296 def igmp_verify_join(self, igmpStateList):
297 sendState, recvState = igmpStateList
298 ## check if the send is received for the groups
299 for g in sendState.groups:
300 tx_stats = sendState.group_map[g][0]
301 tx = tx_stats.count
302 assert_greater(tx, 0)
303 rx_stats = recvState.group_map[g][1]
304 rx = rx_stats.count
305 assert_greater(rx, 0)
306 log.info('Receive stats %s for group %s' %(rx_stats, g))
307
308 log.info('IGMP test verification success')
309
310 def igmp_verify_leave(self, igmpStateList, leave_groups):
311 sendState, recvState = igmpStateList[0], igmpStateList[1]
312 ## check if the send is received for the groups
313 for g in sendState.groups:
314 tx_stats = sendState.group_map[g][0]
315 rx_stats = recvState.group_map[g][1]
316 tx = tx_stats.count
317 rx = rx_stats.count
318 assert_greater(tx, 0)
319 if g not in leave_groups:
320 log.info('Received %d packets for group %s' %(rx, g))
321 for g in leave_groups:
322 rx = recvState.group_map[g][1].count
323 assert_equal(rx, 0)
324
325 log.info('IGMP test verification success')
326
327 def mcast_traffic_timer(self):
328 self.mcastTraffic.stopReceives()
329
330 def send_mcast_cb(self, send_state):
331 for g in send_state.groups:
332 send_state.update(g, tx = 1)
333 return 0
334
335 ##Runs in the context of twisted reactor thread
336 def igmp_recv(self, igmpState, iface = 'veth0'):
337 p = self.recv_socket.recv()
338 try:
339 send_time = float(p.payload.load)
340 recv_time = monotonic.monotonic()
341 except:
342 log.info('Unexpected Payload received: %s' %p.payload.load)
343 return 0
344 #log.info( 'Recv in %.6f secs' %(recv_time - send_time))
345 igmpState.update(p.dst, rx = 1, t = recv_time - send_time)
346 return 0
347
348 def send_igmp_join(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE,
349 ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1):
350 if ssm_load is True:
351 self.onos_ssm_table_load(groups, src_list)
352 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
353 gaddr=self.IP_DST)
354 for g in groups:
355 gr = IGMPv3gr(rtype= record_type, mcaddr=g)
356 gr.sources = src_list
357 igmp.grps.append(gr)
358 if ip_pkt is None:
359 ip_pkt = self.igmp_eth/self.igmp_ip
360 pkt = ip_pkt/igmp
361 IGMPv3.fixup(pkt)
362 sendp(pkt, iface=iface)
363 if delay != 0:
364 time.sleep(delay)
365
366 def send_igmp_join_recvQuery(self, groups, rec_queryCount = None, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2):
367 self.onos_ssm_table_load(groups, src_list)
368 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
369 gaddr=self.IP_DST)
370 for g in groups:
371 gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g)
372 gr.sources = src_list
373 gr.sources = src_list
374 igmp.grps.append(gr)
375 if ip_pkt is None:
376 ip_pkt = self.igmp_eth/self.igmp_ip
377 pkt = ip_pkt/igmp
378 IGMPv3.fixup(pkt)
379 if rec_queryCount == None:
380 log.info('Sending IGMP join for group %s and waiting for one query packet and printing the packet' %groups)
381 resp = srp1(pkt, iface=iface)
382 else:
383 log.info('Sending IGMP join for group %s and waiting for periodic query packets and printing one packet' %groups)
384 resp = srp1(pkt, iface=iface)
385# resp = srp1(pkt, iface=iface) if rec_queryCount else srp3(pkt, iface=iface)
386 resp[0].summary()
387 log.info('Sent IGMP join for group %s and received a query packet and printing packet' %groups)
388 if delay != 0:
389 time.sleep(delay)
390
391 def send_igmp_leave(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2):
392 log.info('entering into igmp leave function')
393 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
394 gaddr=self.IP_DST)
395 for g in groups:
396 gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
397 gr.sources = src_list
398 igmp.grps.append(gr)
399 if ip_pkt is None:
400 ip_pkt = self.igmp_eth/self.igmp_ip
401 pkt = ip_pkt/igmp
402 IGMPv3.fixup(pkt)
403 sendp(pkt, iface = iface)
404 if delay != 0:
405 time.sleep(delay)
406
407 def send_igmp_leave_listening_group_specific_query(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2):
408 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
409 gaddr=self.IP_DST)
410 for g in groups:
411 gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g)
412 gr.sources = src_list
413 igmp.grps.append(gr)
414 if ip_pkt is None:
415 ip_pkt = self.igmp_eth/self.igmp_ip
416 pkt = ip_pkt/igmp
417 IGMPv3.fixup(pkt)
418 log.info('Sending IGMP leave for group %s and waiting for one group specific query packet and printing the packet' %groups)
419 resp = srp1(pkt, iface=iface)
420 resp[0].summary()
421 log.info('Sent IGMP leave for group %s and received a group specific query packet and printing packet' %groups)
422 if delay != 0:
423 time.sleep(delay)
424
425 @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+390)
426 def test_netCondition_with_delay_between_igmp_join_and_data_recv(self):
427 self.setUp_igmp()
428 randomDelay = randint(10,300)
429 groups = ['224.0.1.1', '225.0.0.1']
430 self.onos_ssm_table_load(groups)
431 df = defer.Deferred()
432 igmpState = IGMPTestState(groups = groups, df = df)
433 igmpStateRecv = IGMPTestState(groups = groups, df = df)
434 igmpStateList = (igmpState, igmpStateRecv)
435 mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, arg = igmpState)
436 self.df = df
437 self.mcastTraffic = mcastTraffic
438 self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP)
439
440 def mcast_traffic_delay_start():
441 mcastTraffic.start()
442
443 def igmp_srp_task(stateList):
444 igmpSendState, igmpRecvState = stateList
445 if not mcastTraffic.isRecvStopped():
446 result = self.igmp_recv(igmpRecvState)
447 reactor.callLater(0, igmp_srp_task, stateList)
448 else:
449 self.mcastTraffic.stop()
450 self.recv_socket.close()
451 self.igmp_verify_join(stateList)
452 self.df.callback(0)
453
454 self.send_igmp_join(groups)
455 log.info('Holding multicast data for a period of random delay = {} secs'.format(randomDelay))
456 t = Timer(randomDelay, mcast_traffic_delay_start)
457 t.start()
458
459 self.test_timer = reactor.callLater(randomDelay+30, self.mcast_traffic_timer)
460 reactor.callLater(randomDelay+10, igmp_srp_task, igmpStateList)
461 return df
462
463 @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+390)
464 def test_netCondition_with_delay_between_data_recv_and_igmp_join(self):
465 self.setUp_igmp()
466 randomDelay = randint(10,300)
467 groups = ['224.0.1.1', '225.0.0.1']
468 self.onos_ssm_table_load(groups)
469 df = defer.Deferred()
470 igmpState = IGMPTestState(groups = groups, df = df)
471 igmpStateRecv = IGMPTestState(groups = groups, df = df)
472 igmpStateList = (igmpState, igmpStateRecv)
473 mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, arg = igmpState)
474 self.df = df
475 self.mcastTraffic = mcastTraffic
476 self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP)
477
478 def mcast_join_delay_start():
479 log.info('Holding channel join for a period of random delay = {} secs'.format(randomDelay))
480 self.send_igmp_join(groups)
481
482 def igmp_srp_task(stateList):
483 igmpSendState, igmpRecvState = stateList
484 if not mcastTraffic.isRecvStopped():
485 result = self.igmp_recv(igmpRecvState)
486 reactor.callLater(0, igmp_srp_task, stateList)
487 else:
488 self.mcastTraffic.stop()
489 self.recv_socket.close()
490 self.igmp_verify_join(stateList)
491 self.df.callback(0)
492
493 mcastTraffic.start()
494 t = Timer(randomDelay, mcast_join_delay_start)
495 t.start()
496
497 self.test_timer = reactor.callLater(randomDelay+30, self.mcast_traffic_timer)
498 reactor.callLater(randomDelay+10, igmp_srp_task, igmpStateList)
499 return df
500
501
502 @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+340)
503 def test_netCondition_with_delay_between_igmp_leave_and_data(self):
504 self.setUp_igmp()
505 randomDelay = randint(10,300)
506 groups = ['224.0.1.10', '225.0.0.10']
507 leave_groups = ['224.0.1.10']
508 self.onos_ssm_table_load(groups)
509 df = defer.Deferred()
510 igmpState = IGMPTestState(groups = groups, df = df)
511 igmpStateRecv = IGMPTestState(groups = groups, df = df)
512 igmpStateList = (igmpState, igmpStateRecv)
513 mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb,
514 arg = igmpState)
515 self.df = df
516 self.mcastTraffic = mcastTraffic
517 self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP)
518
519 def mcast_leave_delay_start():
520 self.send_igmp_leave(leave_groups, delay = 3)
521 join_state = IGMPTestState(groups = leave_groups)
522 status = self.igmp_not_recv_task(self.V_INF1,leave_groups, join_state)
523 log.info('Verified status for igmp recv task %s'%status)
524 assert status == 1 , 'EXPECTED RESULT'
525 self.df.callback(0)
526
527 mcastTraffic.start()
528 self.send_igmp_join(groups)
529 log.info('Holding multicast leave packet for a period of random delay = {} secs'.format(randomDelay))
530 t = Timer(randomDelay+10, mcast_leave_delay_start)
531 t.start()
532 return df
533
534 def igmp_not_recv_task(self, intf, groups, join_state):
535 log.info('entering igmp not recv task loop')
536 recv_socket = L2Socket(iface = intf, type = ETH_P_IP)
537 group_map = {}
538 for g in groups:
539 group_map[g] = [0,0]
540
541 log.info('Verifying join interface should not receive any multicast data')
542 self.NEGATIVE_TRAFFIC_STATUS = 1
543 def igmp_recv_cb(pkt):
544 log.info('Multicast packet %s received for left groups %s' %(pkt[IP].dst, groups))
545 self.NEGATIVE_TRAFFIC_STATUS = 2
546 sniff(prn = igmp_recv_cb, count = 1, lfilter = lambda p: IP in p and p[IP].dst in groups,
547 timeout = 3, opened_socket = recv_socket)
548 recv_socket.close()
549 return self.NEGATIVE_TRAFFIC_STATUS
550
551 ## Its sample test case based on this test case we had added all below scenarios.
552 @deferred(TEST_TIMEOUT_DELAY+50)
553 def test_netCondition_in_eap_tls_with_delay_between_positive_IdReq_and_tlsHelloReq(self):
554 self.setUp_tls()
555 randomDelay = randint(10,300)
556 df = defer.Deferred()
557 tls = TLSAuthTest()
558 def eap_tls_eapTlsHelloReq_pkt_delay():
559 tls._eapTlsHelloReq()
560 tls._eapTlsCertReq()
561 tls._eapTlsChangeCipherSpec()
562 tls._eapTlsFinished()
563 df.callback(0)
564 def eap_tls_verify(df):
565 tls._eapSetup()
566 tls.tlsEventTable.EVT_EAP_SETUP
567 tls._eapStart()
568 tls.tlsEventTable.EVT_EAP_START
569 tls._eapIdReq()
570 tls.tlsEventTable.EVT_EAP_ID_REQ
571 log.info('Holding tlsHelloReq packet for a period of random delay = {} secs'.format(randomDelay))
572 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
573 t.start()
574 reactor.callLater(0, eap_tls_verify, df)
575 return df
576
577 @deferred(TEST_TIMEOUT_DELAY+50)
578 def test_netCondition_in_eap_tls_with_delay_between_IdReq_and_tlsHelloReq(self):
579 self.setUp_tls()
580 randomDelay = randint(10,300)
581 df = defer.Deferred()
582 tls = TLSAuthTest()
583 def eap_tls_eapTlsHelloReq_pkt_delay():
584 log.info('Holding tlsHelloReq packet for a period of random delay = {} secs'.format(randomDelay))
585 tls._eapTlsHelloReq()
586 tls._eapTlsCertReq()
587 tls._eapTlsChangeCipherSpec()
588 tls._eapTlsFinished()
589 df.callback(0)
590 def eap_tls_verify(df):
591 tls._eapSetup()
592 tls.tlsEventTable.EVT_EAP_SETUP
593 tls._eapStart()
594 tls.tlsEventTable.EVT_EAP_START
595 tls._eapIdReq()
596 tls.tlsEventTable.EVT_EAP_ID_REQ
597 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
598 t.start()
599 reactor.callLater(0, eap_tls_verify, df)
600 return df
601
602 @deferred(TEST_TIMEOUT_DELAY+100)
603 def test_netCondition_in_eap_tls_with_delay_between_tlsHelloReq_and_eapTlsCertReq(self):
604 self.setUp_tls()
605 randomDelay = randint(10,300)
606 df = defer.Deferred()
607 tls = TLSAuthTest()
608 def eap_tls_eapTlsCertReq_pkt_delay():
609 log.info('Holding eapTlsCertReq packet for a period of random delay = {} secs'.format(randomDelay))
610 tls._eapTlsCertReq_delay()
611 tls._eapTlsChangeCipherSpec()
612 tls._eapTlsFinished()
613 df.callback(0)
614 def eap_tls_verify(df):
615 tls._eapSetup()
616 tls.tlsEventTable.EVT_EAP_SETUP
617 tls._eapStart()
618 tls.tlsEventTable.EVT_EAP_START
619 tls._eapIdReq()
620 tls.tlsEventTable.EVT_EAP_ID_REQ
621 tls._eapTlsHelloReq()
622 while tls.server_hello_done_received == False:
623 r = tls.eapol_scapy_recv(cb = tls.eapol_server_hello_cb,
624 lfilter =
625 lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \
626 pkt[EAP].code == EAP.REQUEST)
627 if len(r) == 0:
628 tls.tlsFail()
629 t = Timer(randomDelay, eap_tls_eapTlsCertReq_pkt_delay)
630 t.start()
631 reactor.callLater(0, eap_tls_verify, df)
632 return df
633
634 @deferred(TEST_TIMEOUT_DELAY+50)
635 def test_netCondition_in_eap_tls_with_delay_between_TlsCertReq_and_TlsChangeCipherSpec(self):
636 self.setUp_tls()
637 randomDelay = randint(10,300)
638 df = defer.Deferred()
639 tls = TLSAuthTest()
640 def eap_tls_TlsChangeCipherSpec_pkt_delay():
641 log.info('Holding TlsChangeCipherSpec packet for a period of random delay = {} secs'.format(randomDelay))
642 tls._eapTlsChangeCipherSpec()
643 tls._eapTlsFinished()
644 df.callback(0)
645 def eap_tls_verify(df):
646 tls._eapSetup()
647 tls.tlsEventTable.EVT_EAP_SETUP
648 tls._eapStart()
649 tls.tlsEventTable.EVT_EAP_START
650 tls._eapIdReq()
651 tls.tlsEventTable.EVT_EAP_ID_REQ
652 tls._eapTlsHelloReq()
653 tls._eapTlsCertReq()
654 t = Timer(randomDelay, eap_tls_TlsChangeCipherSpec_pkt_delay)
655 t.start()
656 reactor.callLater(0, eap_tls_verify, df)
657 return df
658
659 @deferred(TEST_TIMEOUT_DELAY+50)
660 def test_netCondition_in_eap_tls_with_no_cert_delay_between_IdReq_and_HelloReq(self):
661 self.setUp_tls()
662 randomDelay = randint(10,300)
663 df = defer.Deferred()
664 def tls_no_cert_cb():
665 log.info('TLS authentication failed with no certificate')
666 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
667 def eap_tls_eapTlsHelloReq_pkt_delay():
668 log.info('Holding HelloReq packet with no cert for a period of random delay = {} secs'.format(randomDelay))
669 tls._eapTlsHelloReq()
670 tls._eapTlsCertReq()
671 assert_equal(tls.failTest, True)
672 tls._eapTlsChangeCipherSpec()
673 tls._eapTlsFinished()
674 df.callback(0)
675 def eap_tls_no_cert(df):
676 tls._eapSetup()
677 tls.tlsEventTable.EVT_EAP_SETUP
678 tls._eapStart()
679 tls.tlsEventTable.EVT_EAP_START
680 tls._eapIdReq()
681 tls.tlsEventTable.EVT_EAP_ID_REQ
682 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
683 t.start()
684 reactor.callLater(0, eap_tls_no_cert, df)
685 return df
686
687 @deferred(TEST_TIMEOUT_DELAY+100)
688 def test_netCondition_in_eap_tls_with_delay_and_no_cert_between_tlsHelloReq_and_eapTlsCertReq(self):
689 self.setUp_tls()
690 randomDelay = randint(10,300)
691 df = defer.Deferred()
692 def tls_no_cert_cb():
693 log.info('TLS authentication failed with no certificate')
694 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
695 def eap_tls_eapTlsHelloReq_pkt_delay():
696 log.info('Holding eapTlsCertReq packet with no cert for a period of random delay = {} secs'.format(randomDelay))
697 tls._eapTlsCertReq_delay()
698 assert_equal(tls.failTest, True)
699 tls._eapTlsChangeCipherSpec()
700 assert_equal(tls.failTest, True)
701 tls._eapTlsFinished()
702 df.callback(0)
703 def eap_tls_no_cert(df):
704 tls._eapSetup()
705 tls.tlsEventTable.EVT_EAP_SETUP
706 tls._eapStart()
707 tls.tlsEventTable.EVT_EAP_START
708 tls._eapIdReq()
709 tls.tlsEventTable.EVT_EAP_ID_REQ
710 tls._eapTlsHelloReq()
711 while tls.server_hello_done_received == False:
712 r = tls.eapol_scapy_recv(cb = tls.eapol_server_hello_cb,
713 lfilter =
714 lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \
715 pkt[EAP].code == EAP.REQUEST)
716 if len(r) == 0:
717 tls.tlsFail()
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
724 @deferred(TEST_TIMEOUT_DELAY+50)
725 def test_netCondition_in_eap_tls_with_delay_and_no_cert_between_TlsCertReq_and_TlsChangeCipherSpec(self):
726 self.setUp_tls()
727 randomDelay = randint(10,300)
728 df = defer.Deferred()
729 def tls_no_cert_cb():
730 log.info('TLS authentication failed with no certificate')
731 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
732 def eap_tls_TlsChangeCipherSpec_pkt_delay():
733 tls._eapTlsChangeCipherSpec()
734 assert_equal(tls.failTest, True)
735 tls._eapTlsFinished()
736 df.callback(0)
737 def eap_tls_no_cert(df):
738 tls._eapSetup()
739 tls.tlsEventTable.EVT_EAP_SETUP
740 tls._eapStart()
741 tls._eapIdReq()
742 tls.tlsEventTable.EVT_EAP_ID_REQ
743 tls._eapTlsHelloReq()
744 tls._eapTlsCertReq()
745 log.info('Holding TlsChangeCipherSpec packet with no cert for a period of random delay = {} secs'.format(randomDelay))
746 t = Timer(randomDelay, eap_tls_TlsChangeCipherSpec_pkt_delay)
747 t.start()
748 reactor.callLater(0, eap_tls_no_cert, df)
749 return df
750
751 @deferred(TEST_TIMEOUT_DELAY+50)
752 def test_netCondition_in_eap_tls_with_invalid_cert_and_delay_between_IdReq_and_HelloReq(self):
753 self.setUp_tls()
754 randomDelay = randint(10,300)
755 df = defer.Deferred()
756 def tls_invalid_cert_cb():
757 log.info('TLS authentication failed with invalid certificate')
758 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, client_cert = self.CLIENT_CERT_INVALID)
759 def eap_tls_eapTlsHelloReq_pkt_delay():
760 tls._eapTlsHelloReq()
761 tls._eapTlsCertReq()
762 assert_equal(tls.failTest, True)
763 tls._eapTlsChangeCipherSpec()
764 tls._eapTlsFinished()
765 df.callback(0)
766 def eap_tls_invalid_cert(df):
767 tls._eapSetup()
768 tls.tlsEventTable.EVT_EAP_SETUP
769 tls._eapStart()
770 tls.tlsEventTable.EVT_EAP_START
771 tls._eapIdReq()
772 tls.tlsEventTable.EVT_EAP_ID_REQ
773 log.info('Holding HelloReq packet with invalid cert for a period of random delay = {} secs'.format(randomDelay))
774 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
775 t.start()
776 reactor.callLater(0, eap_tls_invalid_cert, df)
777 return df
778
779 @deferred(TEST_TIMEOUT_DELAY+100)
780 def test_netCondition_in_eap_tls_with_invalid_cert_and_delay_between_tlsHelloReq_and_eapTlsCertReq(self):
781 self.setUp_tls()
782 randomDelay = randint(10,300)
783 df = defer.Deferred()
784 def tls_invalid_cert_cb():
785 log.info('TLS authentication failed with invalid certificate')
786 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, client_cert = self.CLIENT_CERT_INVALID)
787 def eap_tls_eapTlsHelloReq_pkt_delay():
788 log.info('Holding eapTlsCertReq packet with invalid cert for a period of random delay = {} sec, delay ended'.format(randomDelay))
789 tls._eapTlsCertReq_delay()
790 tls._eapTlsChangeCipherSpec()
791 assert_equal(tls.failTest, True)
792 tls._eapTlsFinished()
793 df.callback(0)
794 def eap_tls_invalid_cert(df):
795 tls._eapSetup()
796 tls.tlsEventTable.EVT_EAP_SETUP
797 tls._eapStart()
798 tls.tlsEventTable.EVT_EAP_START
799 tls._eapIdReq()
800 tls.tlsEventTable.EVT_EAP_ID_REQ
801 tls._eapTlsHelloReq()
802 while tls.server_hello_done_received == False:
803 r = tls.eapol_scapy_recv(cb = tls.eapol_server_hello_cb,
804 lfilter =
805 lambda pkt: EAP in pkt and pkt[EAP].type == EAP_TYPE_TLS and \
806 pkt[EAP].code == EAP.REQUEST)
807 if len(r) == 0:
808 tls.tlsFail()
809
810 log.info('Holding eapTlsCertReq packet with invalid cert for a period of random delay = {} secs'.format(randomDelay))
811 t = Timer(randomDelay, eap_tls_eapTlsHelloReq_pkt_delay)
812 t.start()
813 reactor.callLater(0, eap_tls_invalid_cert, df)
814 return df
815
816
817 @deferred(TEST_TIMEOUT_DELAY+50)
818 def test_netCondition_in_eap_tls_with_invalid_cert_delay_between_TlsCertReq_and_TlsChangeCipherSpec(self):
819 self.setUp_tls()
820 randomDelay = randint(10,300)
821 df = defer.Deferred()
822 def tls_invalid_cert_cb():
823 log.info('TLS authentication failed with invalid certificate')
824 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb, client_cert = self.CLIENT_CERT_INVALID)
825 def eap_tls_TlsChangeCipherSpec_pkt_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 tls._eapTlsCertReq()
839 log.info('Holding TlsChangeCipherSpec packet with invalid cert for a period of random delay = {} secs'.format(randomDelay))
840 t = Timer(randomDelay, eap_tls_TlsChangeCipherSpec_pkt_delay)
841 t.start()
842 reactor.callLater(0, eap_tls_invalid_cert, df)
843 return df
844
845 @deferred(TEST_TIMEOUT_DELAY+50)
846 def test_netCondition_in_multiple_eap_tls_requests_with_delay_between_IdReq_and_HelloReq(self):
847 self.setUp_tls()
848 df = defer.Deferred()
849 threads = []
850 clients = 10
851 def eap_tls_eapTlsHelloReq_pkt_delay(df):
852 def multiple_tls_random_delay():
853 randomDelay = randint(10,300)
854 tls = TLSAuthTest(src_mac = 'random')
855 tls._eapSetup()
856 tls.tlsEventTable.EVT_EAP_SETUP
857 tls._eapStart()
858 tls.tlsEventTable.EVT_EAP_START
859 tls._eapIdReq()
860 tls.tlsEventTable.EVT_EAP_ID_REQ
861 log.info('Holding tlsHelloReq packet for a period of random delay = {} secs'.format(randomDelay))
862 time.sleep(randomDelay)
863 tls._eapTlsHelloReq()
864 tls._eapTlsCertReq()
865 tls._eapTlsChangeCipherSpec()
866 tls._eapTlsFinished()
867 log.info('Authentication successfull for user %d'%i)
868 # Sending multiple tls clients and making random delay in between client and server packets.
869 for i in xrange(clients):
870 thread = threading.Thread(target = multiple_tls_random_delay)
871 time.sleep(randint(1,2))
872 thread.start()
873 threads.append(thread)
874 time.sleep(300)
875 for thread in threads:
876 thread.join()
877 #df.callback(0)
878 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
879 return df
880
881 @deferred(TEST_TIMEOUT_DELAY+450)
882 def test_netCondition_multiple_authentications_tls_with_delay_between_every_auth_complete(self):
883 self.setUp_tls()
884 df = defer.Deferred()
885 threads = []
886 clients = 100
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 tls._eapTlsHelloReq()
898 tls._eapTlsCertReq()
899 tls._eapTlsChangeCipherSpec()
900 tls._eapTlsFinished()
901 log.info('Authentication successfull for user %d'%i)
902 # Client authendicating multiple times one after other and making random delay in between authendication.
903 for i in xrange(clients):
904# thread = threading.Thread(target = multiple_tls_random_delay)
905 multiple_tls_random_delay()
906 time.sleep(randomDelay)
907 df.callback(0)
908 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
909 return df
910
911 @deferred(TEST_TIMEOUT_DELAY+450)
912 def test_netCondition_multiple_authentications_tls_with_delay_between_every_100_tls_burst(self):
913 self.setUp_tls()
914 randomDelay = randint(10,300)
915 df = defer.Deferred()
916 threads = []
917 tls = []
918 clients = 10
919 def eap_tls_eapTlsHelloReq_pkt_delay(df):
920 def multiple_tls_random_delay():
921 #randomDelay = 3
922 for x in xrange(clients):
923 tls.append(TLSAuthTest(src_mac = 'random'))
924 for x in xrange(clients):
925 tls[x]._eapSetup()
926 tls[x].tlsEventTable.EVT_EAP_SETUP
927 for x in xrange(clients):
928 tls[x]._eapStart()
929 tls[x].tlsEventTable.EVT_EAP_START
930 for x in xrange(clients):
931 tls[x]._eapIdReq()
932 tls[x].tlsEventTable.EVT_EAP_ID_REQ
933 for x in xrange(clients):
934 tls[x]._eapTlsHelloReq()
935 for x in xrange(clients):
936 tls[x]._eapTlsCertReq()
937 for x in xrange(clients):
938 tls[x]._eapTlsChangeCipherSpec()
939 for x in xrange(clients):
940 tls[x]._eapTlsFinished()
941 for x in xrange(clients):
942 log.info('Authentication successfull for user %d'%i)
943 # Client authendicating multiple times one after other and making random delay in between authendication.
944 for i in xrange(2):
945 multiple_tls_random_delay()
946 time.sleep(randomDelay)
947 df.callback(0)
948 reactor.callLater(0, eap_tls_eapTlsHelloReq_pkt_delay, df)
949 return df
950
951 @deferred(TEST_TIMEOUT_DELAY+90)
952 def test_netCondition_with_delay_between_mac_flow_and_traffic(self):
953 df = defer.Deferred()
954 randomDelay = randint(10,300)
955 #self.setUpClass_flows()
956 egress = 1
957 ingress = 2
958 egress_mac = '00:00:00:00:00:01'
959 ingress_mac = '00:00:00:00:00:02'
960 pkt = Ether(src = ingress_mac, dst = egress_mac)/IP()
961 self.success = False
962
963 def mac_recv_task():
964 def recv_cb(pkt):
965 log.info('Pkt seen with ingress mac %s, egress mac %s' %(pkt.src, pkt.dst))
966 self.success = True
967 sniff(count=2, timeout=randomDelay+50, lfilter = lambda p: p.src == ingress_mac,
968 prn = recv_cb, iface = self.port_map[egress])
969
970 thread = threading.Thread(target = mac_recv_task)
971
972 def send_flow_pkt_delay():
973 sendp(pkt, count=50, iface = self.port_map[ingress])
974 thread.join()
975 assert_equal(self.success, True)
976 df.callback(0)
977
978 def creating_mac_flow(df):
979
980 flow = OnosFlowCtrl(deviceId = self.device_id,
981 egressPort = egress,
982 ingressPort = ingress,
983 ethSrc = ingress_mac,
984 ethDst = egress_mac)
985 result = flow.addFlow()
986 assert_equal(result, True)
987 ##wait for flows to be added to ONOS
988 time.sleep(1)
989 thread.start()
990 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
991 t = Timer(randomDelay, send_flow_pkt_delay)
992 t.start()
993 reactor.callLater(0, creating_mac_flow, df)
994 return df
995
996
997 @deferred(TEST_TIMEOUT_DELAY+90)
998 def test_netCondition_with_delay_between_ip_flow_and_traffic(self):
999 df = defer.Deferred()
1000 randomDelay = randint(10,300)
1001 egress = 1
1002 ingress = 2
1003 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
1004 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
1005 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1006 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1007 pkt = L2/L3
1008
1009 def mac_recv_task():
1010 def recv_cb(pkt):
1011 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
1012 self.success = True
1013 sniff(count=2, timeout= randomDelay + 30,
1014 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip'],
1015 prn = recv_cb, iface = self.port_map[egress])
1016
1017 thread = threading.Thread(target = mac_recv_task)
1018
1019 def send_flow_ip_pkt_delay():
1020 sendp(pkt, count=50, iface = self.port_map[ingress])
1021 thread.join()
1022 assert_equal(self.success, True)
1023 df.callback(0)
1024
1025 def creating_ip_flow(df):
1026 flow = OnosFlowCtrl(deviceId = self.device_id,
1027 egressPort = egress,
1028 ingressPort = ingress,
1029 ethType = '0x0800',
1030 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
1031 ipDst = ('IPV4_DST', egress_map['ip']+'/32')
1032 )
1033 result = flow.addFlow()
1034 assert_equal(result, True)
1035 ##wait for flows to be added to ONOS
1036 time.sleep(1)
1037 self.success = False
1038 ##wait for flows to be added to ONOS
1039 time.sleep(1)
1040 thread.start()
1041 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
1042 t = Timer(randomDelay, send_flow_ip_pkt_delay)
1043 t.start()
1044 reactor.callLater(0, creating_ip_flow, df)
1045 return df
1046
1047 @deferred(TEST_TIMEOUT_DELAY+90)
1048 def test_netCondition_with_delay_between_tcp_port_flow_and_traffic(self):
1049 df = defer.Deferred()
1050 egress = 1
1051 ingress = 2
1052 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': 9500 }
1053 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': 9000 }
1054 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1055 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1056 L4 = TCP(sport = ingress_map['tcp_port'], dport = egress_map['tcp_port'])
1057 pkt = L2/L3/L4
1058
1059 def mac_recv_task():
1060 def recv_cb(pkt):
1061 log.info('Pkt seen with ingress TCP port %s, egress TCP port %s' %(pkt[TCP].sport, pkt[TCP].dport))
1062 self.success = True
1063 sniff(count=2, timeout= randomDelay+30, lfilter = lambda p: TCP in p and p[TCP].dport == egress_map['tcp_port']
1064 and p[TCP].sport == ingress_map['tcp_port'], prn = recv_cb, iface = self.port_map[egress])
1065
1066 thread = threading.Thread(target = mac_recv_task)
1067
1068 def send_flow_tcp_pkt_delay():
1069 sendp(pkt, count=50, iface = self.port_map[ingress])
1070 thread.join()
1071 assert_equal(self.success, True)
1072 df.callback(0)
1073
1074 def creating_tcp_flow(df):
1075 flow = OnosFlowCtrl(deviceId = self.device_id,
1076 egressPort = egress,
1077 ingressPort = ingress,
1078 tcpSrc = ingress_map['tcp_port'],
1079 tcpDst = egress_map['tcp_port']
1080 )
1081 result = flow.addFlow()
1082 assert_equal(result, True)
1083 ##wait for flows to be added to ONOS
1084 time.sleep(1)
1085 self.success = False
1086 thread.start()
1087 randomDelay = randint(10,300)
1088 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
1089 t = Timer(randomDelay, send_flow_tcp_pkt_delay)
1090 t.start()
1091 df.callback(0)
1092 reactor.callLater(0, creating_tcp_flow, df)
1093 return df
1094
1095 @deferred(TEST_TIMEOUT_DELAY+90)
1096 def test_netCondition_with_delay_between_udp_port_flow_and_traffic(self):
1097 df = defer.Deferred()
1098 randomDelay = randint(10,300)
1099 egress = 1
1100 ingress = 2
1101 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'udp_port': 9500 }
1102 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'udp_port': 9000 }
1103 L2 = Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1104 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
1105 L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port'])
1106 pkt = L2/L3/L4
1107
1108 def mac_recv_task():
1109 def recv_cb(pkt):
1110 log.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
1111 self.success = True
1112 sniff(count=2, timeout=randomDelay + 30,
1113 lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port']
1114 and p[UDP].sport == ingress_map['udp_port'], prn = recv_cb, iface = self.port_map[egress])
1115
1116 thread = threading.Thread(target = mac_recv_task)
1117
1118 def send_flow_udp_pkt_delay():
1119 sendp(pkt, count=50, iface = self.port_map[ingress])
1120 thread.join()
1121 assert_equal(self.success, True)
1122 df.callback(0)
1123
1124 def creating_udp_flow(df):
1125 flow = OnosFlowCtrl(deviceId = self.device_id,
1126 egressPort = egress,
1127 ingressPort = ingress,
1128 udpSrc = ingress_map['udp_port'],
1129 udpDst = egress_map['udp_port']
1130 )
1131 result = flow.addFlow()
1132 assert_equal(result, True)
1133 ##wait for flows to be added to ONOS
1134 time.sleep(1)
1135 self.success = False
1136 thread.start()
1137 log.info('Holding a packet to verify if flows are active after {} secs'.format(randomDelay))
1138 t = Timer(randomDelay, send_flow_udp_pkt_delay)
1139 t.start()
1140
1141 df.callback(0)
1142 reactor.callLater(0, creating_udp_flow, df)
1143 return df
1144