blob: 4eb2fb851adb45a4991a54aaaeb1073d8c18f812 [file] [log] [blame]
kavitha Alagesan373e0552016-11-22 05:22:05 +05301class FUNCgroup:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
7 import os
8 import imp
9
10 """
11 - Construct tests variables
12 - GIT ( optional )
13 - Checkout ONOS master branch
14 - Pull latest ONOS code
15 - Building ONOS ( optional )
16 - Install ONOS package
17 - Build ONOS package
18 """
19 main.case( "Constructing test variables and building ONOS package" )
20 main.step( "Constructing test variables" )
21
22 # Test variables
23 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
24 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
25 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
26 gitBranch = main.params[ 'GIT' ][ 'branch' ]
27 gitPull = main.params[ 'GIT' ][ 'pull' ]
28 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
29 main.dependencyPath = main.testOnDirectory + \
30 main.params[ 'DEPENDENCY' ][ 'path' ]
31 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
32 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
33 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
34 bucket = main.params[ 'DEPENDENCY' ][ 'bucket' ]
35 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
36 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
37 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
38 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
39 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
40 main.addGroupSleep = int( main.params[ 'SLEEP' ][ 'addGroup' ] )
41 main.delGroupSleep = int( main.params[ 'SLEEP' ][ 'delGroup' ] )
42 main.debug = main.params[ 'DEBUG' ]
43 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
44 egressPort1 = main.params[ 'TEST' ][ 'egressPort1' ]
45 egressPort2 = main.params[ 'TEST' ][ 'egressPort2' ]
46 egressPort3 = main.params[ 'TEST' ][ 'egressPort3' ]
47 ingressPort = main.params[ 'TEST' ][ 'ingressPort' ]
48 appCookie = main.params[ 'TEST' ][ 'appCookie' ]
49 type1 = main.params[ 'TEST' ][ 'type1' ]
50 type2 = main.params[ 'TEST' ][ 'type2' ]
51 groupId = main.params[ 'TEST' ][ 'groupId' ]
52 priority = main.params[ 'TEST' ][ 'priority' ]
53 deviceId = main.params[ 'TEST' ][ 'swDPID' ]
54
55 main.cellData = { } # for creating cell file
56 main.CLIs = [ ]
57 main.ONOSip = [ ]
58
59 main.debug = True if "on" in main.debug else False
60
61 main.ONOSip = main.ONOSbench.getOnosIps( )
62
63 # Assigning ONOS cli handles to a list
64 for i in range( 1, main.maxNodes + 1 ):
65 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
66
67 # -- INIT SECTION, ONLY RUNS ONCE -- #
68 main.startUp = imp.load_source( wrapperFile1,
69 main.dependencyPath +
70 wrapperFile1 +
71 ".py" )
72
73 main.topo = imp.load_source( wrapperFile2,
74 main.dependencyPath +
75 wrapperFile2 +
76 ".py" )
77
78 main.buckets = imp.load_source( bucket,
79 main.dependencyPath +
80 bucket +
81 ".py" )
82
83 copyResult = main.ONOSbench.scp( main.Mininet1,
84 main.dependencyPath + main.topology,
85 main.Mininet1.home + '/custom/',
86 direction="to" )
87
88 utilities.assert_equals( expect=main.TRUE,
89 actual=copyResult,
90 onpass="Successfully copy " + "test variables ",
91 onfail="Failed to copy test variables" )
92
93 if main.CLIs:
94 stepResult = main.TRUE
95 else:
96 main.log.error( "Did not properly created list of ONOS CLI handle" )
97 stepResult = main.FALSE
98
99 utilities.assert_equals( expect=main.TRUE,
100 actual=stepResult,
101 onpass="Successfully construct " + "test variables ",
102 onfail="Failed to construct test variables" )
103
104 if gitPull == 'True':
105 main.step( "Building ONOS in " + gitBranch + " branch" )
106 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
107 stepResult = onosBuildResult
108 utilities.assert_equals( expect=main.TRUE,
109 actual=stepResult,
110 onpass="Successfully compiled " + "latest ONOS",
111 onfail="Failed to compile " + "latest ONOS" )
112 else:
113 main.log.warn( "Did not pull new code so skipping mvn " +
114 "clean install" )
115
116 def CASE2( self, main ):
117 """
118 - Set up cell
119 - Create cell file
120 - Set cell file
121 - Verify cell file
122 - Kill ONOS process
123 - Uninstall ONOS cluster
124 - Verify ONOS start up
125 - Install ONOS cluster
126 - Connect to cli
127 """
128 import time
129
130 main.numCtrls = int( main.maxNodes )
131
132 main.case( "Starting up " + str( main.numCtrls ) +
133 " node(s) ONOS cluster" )
134
135 #kill off all onos processes
136 main.log.info( "Safety check, killing all ONOS processes" +
137 " before initiating environment setup" )
138
139 for i in range( main.maxNodes ):
140 main.ONOSbench.onosDie( main.ONOSip[ i ] )
141
142 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
143
144 tempOnosIp = [ ]
145 for i in range( main.numCtrls ):
146 tempOnosIp.append( main.ONOSip[ i ] )
147
148 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
149 "temp",
150 main.Mininet1.ip_address,
151 main.apps,
152 tempOnosIp )
153
154 main.step( "Apply cell to environment" )
155 cellResult = main.ONOSbench.setCell( "temp" )
156 verifyResult = main.ONOSbench.verifyCell( )
157 stepResult = cellResult and verifyResult
158 utilities.assert_equals( expect=main.TRUE,
159 actual=stepResult,
160 onpass="Successfully applied cell to " + "environment",
161 onfail="Failed to apply cell to environment " )
162
163 main.step( "Creating ONOS package" )
164 packageResult = main.ONOSbench.buckBuild()
165 stepResult = packageResult
166 utilities.assert_equals( expect=main.TRUE,
167 actual=stepResult,
168 onpass="Successfully created ONOS package",
169 onfail="Failed to create ONOS package" )
170
171 time.sleep( main.startUpSleep )
172 main.step( "Uninstalling ONOS package" )
173 onosUninstallResult = main.TRUE
174 for ip in main.ONOSip:
175 onosUninstallResult = onosUninstallResult and \
176 main.ONOSbench.onosUninstall( nodeIp=ip )
177 stepResult = onosUninstallResult
178 utilities.assert_equals( expect=main.TRUE,
179 actual=stepResult,
180 onpass="Successfully uninstalled ONOS package",
181 onfail="Failed to uninstall ONOS package" )
182 time.sleep( main.startUpSleep )
183 main.step( "Installing ONOS package" )
184 onosInstallResult = main.TRUE
185 for i in range( main.numCtrls ):
186 onosInstallResult = onosInstallResult and \
187 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
188 stepResult = onosInstallResult
189 utilities.assert_equals( expect=main.TRUE,
190 actual=stepResult,
191 onpass="Successfully installed ONOS package",
192 onfail="Failed to install ONOS package" )
193
194 time.sleep( main.startUpSleep )
195 main.step( "Starting ONOS service" )
196 stopResult = main.TRUE
197 startResult = main.TRUE
198 onosIsUp = main.TRUE
199
200 for i in range( main.numCtrls ):
201 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
202 if onosIsUp == main.TRUE:
203 main.log.report( "ONOS instance is up and ready" )
204 else:
205 main.log.report( "ONOS instance may not be up, stop and " +
206 "start ONOS again " )
207 for i in range( main.numCtrls ):
208 stopResult = stopResult and \
209 main.ONOSbench.onosStop( main.ONOSip[ i ] )
210 for i in range( main.numCtrls ):
211 startResult = startResult and \
212 main.ONOSbench.onosStart( main.ONOSip[ i ] )
213 stepResult = onosIsUp and stopResult and startResult
214 utilities.assert_equals( expect=main.TRUE,
215 actual=stepResult,
216 onpass="ONOS service is ready",
217 onfail="ONOS service did not start properly" )
218
219 main.step( "Set up ONOS secure SSH" )
220 secureSshResult = main.TRUE
221 for i in range( int( main.numCtrls ) ):
222 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
223 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
224 onpass="Test step PASS",
225 onfail="Test step FAIL" )
226
227 main.step( "Start ONOS cli" )
228 cliResult = main.TRUE
229 for i in range( main.numCtrls ):
230 cliResult = cliResult and \
231 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
232 stepResult = cliResult
233 utilities.assert_equals( expect=main.TRUE,
234 actual=stepResult,
235 onpass="Successfully start ONOS cli",
236 onfail="Failed to start ONOS cli" )
237
238 def CASE3( self, main ):
239 '''
240 Start Mininet
241 '''
242 import json
243
244 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
245 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
246 "elements between Mininet and ONOS"
247
248 main.step( "Setup Mininet Topology" )
249 topology = main.Mininet1.home + '/custom/' + main.topology
250 stepResult = main.Mininet1.startNet( topoFile = topology )
251
252 utilities.assert_equals( expect=main.TRUE,
253 actual=stepResult,
254 onpass="Successfully loaded topology",
255 onfail="Failed to load topology" )
256
257 main.step( "Assign switch to controller" )
258 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] )
259
260 utilities.assert_equals( expect=main.TRUE,
261 actual=stepResult,
262 onpass="Successfully assigned switch to controller",
263 onfail="Failed to assign switch to controller" )
264
265 time.sleep( main.startMNSleep )
266
267 main.step( "Comparing MN topology to ONOS topology" )
268 main.log.info( "Gathering topology information" )
269 devices = main.topo.getAllDevices( main )
270 hosts = main.topo.getAllHosts( main )
271 ports = main.topo.getAllPorts( main )
272 links = main.topo.getAllLinks( main )
273
274 mnSwitches = main.Mininet1.getSwitches( )
275 mnLinks = main.Mininet1.getLinks( )
276 mnHosts = main.Mininet1.getHosts( )
277
278 for controller in range( main.numCtrls ):
279 controllerStr = str( controller + 1 )
280 if devices[ controller ] and ports[ controller ] and\
281 "Error" not in devices[ controller ] and\
282 "Error" not in ports[ controller ]:
283
284 currentDevicesResult = main.Mininet1.compareSwitches(
285 mnSwitches,
286 json.loads( devices[ controller ] ),
287 json.loads( ports[ controller ] ) )
288 else:
289 currentDevicesResult = main.FALSE
290 utilities.assert_equals( expect=main.TRUE,
291 actual=currentDevicesResult,
292 onpass="ONOS" + controllerStr +
293 " Switches view is correct",
294 onfail="ONOS" + controllerStr +
295 " Switches view is incorrect" )
296 if links[ controller ] and "Error" not in links[ controller ]:
297 currentLinksResult = main.Mininet1.compareLinks(
298 mnSwitches, mnLinks,
299 json.loads( links[ controller ] ) )
300 else:
301 currentLinksResult = main.FALSE
302 utilities.assert_equals( expect=main.TRUE,
303 actual=currentLinksResult,
304 onpass="ONOS" + controllerStr +
305 " links view is correct",
306 onfail="ONOS" + controllerStr +
307 " links view is incorrect" )
308
309 if hosts[ controller ] or "Error" not in hosts[ controller ]:
310 currentHostsResult = main.Mininet1.compareHosts(
311 mnHosts,
312 json.loads( hosts[ controller ] ) )
313 else:
314 currentHostsResult = main.FALSE
315 utilities.assert_equals( expect=main.TRUE,
316 actual=currentHostsResult,
317 onpass="ONOS" + controllerStr +
318 " hosts exist in Mininet",
319 onfail="ONOS" + controllerStr +
320 " hosts don't match Mininet")
321
322
323 def CASE4( self, main ):
324 '''
325 Testing scapy
326 '''
327 main.case( "Testing scapy" )
328 main.step( "Creating Host1 component" )
329 main.Scapy.createHostComponent( "h1" )
330 main.Scapy.createHostComponent( "h2" )
331 hosts = [ main.h1, main.h2 ]
332 for host in hosts:
333 host.startHostCli( )
334 host.startScapy( )
335 host.updateSelf( )
336 main.log.debug( host.name )
337 main.log.debug( host.hostIp )
338 main.log.debug( host.hostMac )
339
340 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
341 main.log.info( "Starting Filter..." )
342 main.h2.startFilter( )
343 main.log.info( "Building Ether frame..." )
344 main.h1.buildEther( dst=main.h2.hostMac )
345 main.log.info( "Sending Packet..." )
346 main.h1.sendPacket( )
347 main.log.info( "Checking Filter..." )
348 finished = main.h2.checkFilter( )
349 main.log.debug( finished )
350 i = ""
351 if finished:
352 a = main.h2.readPackets( )
353 for i in a.splitlines( ):
354 main.log.info( i )
355 else:
356 kill = main.h2.killFilter( )
357 main.log.debug( kill )
358 main.h2.handle.sendline( "" )
359 main.h2.handle.expect( main.h2.scapyPrompt )
360 main.log.debug( main.h2.handle.before )
361 utilities.assert_equals( expect=True,
362 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
363 onpass="Pass",
364 onfail="Fail" )
365
366 main.step( "Sending/Receiving Test packet - Filter matches" )
367 main.h2.startFilter( )
368 main.h1.buildEther( dst=main.h2.hostMac )
369 main.h1.buildIP( dst=main.h2.hostIp )
370 main.h1.sendPacket( )
371 finished = main.h2.checkFilter( )
372 i = ""
373 if finished:
374 a = main.h2.readPackets( )
375 for i in a.splitlines( ):
376 main.log.info( i )
377 else:
378 kill = main.h2.killFilter( )
379 main.log.debug( kill )
380 main.h2.handle.sendline( "" )
381 main.h2.handle.expect( main.h2.scapyPrompt )
382 main.log.debug( main.h2.handle.before )
383 utilities.assert_equals( expect=True,
384 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
385 onpass="Pass",
386 onfail="Fail" )
387
388
389
390 main.step( "Clean up host components" )
391 for host in hosts:
392 host.stopScapy( )
393 main.Mininet1.removeHostComponent( "h1" )
394 main.Mininet1.removeHostComponent( "h2" )
395
396 def CASE5( self, main ):
397 '''
398 Adding Group of type "ALL" using Rest api
399 '''
400 import json
401 import time
402 isAdded = main.FALSE
403 main.case( "Verify Group of type All are successfully Added" )
404 main.caseExplanation = " Install a Group of type ALL " +\
405 " Verify the Group is Added " +\
406 " Add a flow using the group " +\
407 " Send a packet that verifies the action bucket of the group"
408
409 main.step( "Add Group using Rest api" )
410 bucketList = []
411 bucket = main.buckets.addBucket( main, egressPort = egressPort1 )
412 bucketList.append( bucket )
413 bucket = main.buckets.addBucket( main, egressPort = egressPort2 )
414 bucketList.append( bucket )
415 bucket = main.buckets.addBucket( main, egressPort = egressPort3 )
416 bucketList.append( bucket )
417 response = main.ONOSrest.addGroup( deviceId = deviceId,
418 groupType = type1,
419 bucketList = bucketList,
420 appCookie = appCookie,
421 groupId = groupId )
422
423 utilities.assert_equals( expect=main.TRUE,
424 actual=response,
425 onpass="Successfully added Groups of type ALL",
426 onfail="Failed to add Groups of type ALL" )
427
428 # Giving ONOS time to add the group
429 time.sleep( main.addGroupSleep )
430
431 main.step( "Check groups are in ADDED state" )
432
433 response = main.ONOSrest.getGroups( deviceId = deviceId,
434 appCookie = appCookie )
435 responsejson = json.loads( response )
436 for item in responsejson :
437 if item["state"] == "ADDED" :
438 isAdded = main.TRUE
439
440 utilities.assert_equals( expect=main.TRUE,
441 actual=isAdded,
442 onpass="All Group is in Added State",
443 onfail="All Group is not in Added State" )
444
445 '''
446 Adding flow using rest api
447 '''
448 isAdded = main.FALSE
449
450 main.step( "Adding flow with Group using rest api" )
451 response = main.ONOSrest.addFlow( deviceId = deviceId,
452 priority = priority,
453 ingressPort = ingressPort,
454 groupId = groupId )
455 utilities.assert_equals( expect=main.TRUE,
456 actual=response,
457 onpass="Successfully Added Flows",
458 onfail="Failed to Add flows" )
459
460 # Giving ONOS time to add the flow
461 time.sleep( main.addFlowSleep )
462
463 response = main.ONOSrest.getFlows( deviceId = deviceId )
464 responsejson = json.loads( response )
465 for item in responsejson :
466 if item["priority"] == int( priority ) and item["state"] == "ADDED" :
467 isAdded = main.TRUE
468
469 utilities.assert_equals( expect=main.TRUE,
470 actual=isAdded,
471 onpass="Flow is in Added State",
472 onfail="Flow is not in Added State" )
473
474 '''
475 Sends a packet using scapy
476 '''
477 main.step( "Testing Group by sending packet using Scapy" )
478 main.log.info( "Creating host components" )
479 main.Scapy.createHostComponent( "h1" )
480 main.Scapy.createHostComponent( "h2" )
481 main.Scapy.createHostComponent( "h3" )
482 main.Scapy.createHostComponent( "h4" )
483
484 hosts = [main.h1, main.h2, main.h3, main.h4]
485 for host in hosts:
486 host.startHostCli( )
487 host.startScapy( )
488 host.updateSelf( )
489 main.log.info( "Constructing Packet" )
490 main.h1.buildEther( dst=main.h1.hostMac )
491 main.h1.buildIP( dst=main.h1.hostIp )
492 main.log.info( "Start Filter on host2,host3,host4" )
493 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
494 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
495 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
496 main.log.info( "sending packet to Host" )
497 main.h1.sendPacket( )
498 main.log.info( "Checking filter for our packet" )
499 stepResultH2 = main.h2.checkFilter( )
500 stepResultH3 = main.h3.checkFilter( )
501 stepResultH4 = main.h4.checkFilter( )
502
503 if stepResultH2:
504 main.log.info( "Packet : %s" % main.h2.readPackets( ) )
505 else:
506 main.h2.killFilter( )
507
508 if stepResultH3:
509 main.log.info( "Packet : %s" % main.h3.readPackets( ) )
510 else:
511 main.h2.killFilter( )
512
513 if stepResultH4:
514 main.log.info( "Packet : %s" % main.h4.readPackets( ) )
515 else:
516 main.h4.killFilter( )
517
518 if stepResultH2 and stepResultH3 and stepResultH4 :
519 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
520 stepResult = main.TRUE
521 else:
522 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
523 stepResult = main.FALSE
524
525 main.log.info( "Clean up host components" )
526 for host in hosts:
527 host.stopScapy( )
528 main.Mininet1.removeHostComponent( "h1" )
529 main.Mininet1.removeHostComponent( "h2" )
530 main.Mininet1.removeHostComponent( "h3" )
531 main.Mininet1.removeHostComponent( "h4" )
532
533 utilities.assert_equals( expect=main.TRUE,
534 actual=stepResult,
535 onpass="Packet sent to port 1 is received at port 2,3,4 ",
536 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
537
538 def CASE6( self, main ):
539 '''
540 Deleting the Group and Flow
541 '''
542 import json
543 import time
544 respFlowId = 1
545
546 main.case( "Delete the Group and Flow added through Rest api " )
547 main.step( "Deleting Group and Flows" )
548
549 #Get Flow ID
550 response = main.ONOSrest.getFlows( deviceId = deviceId )
551 responsejson = json.loads( response )
552 for item in responsejson :
553 if item["priority"] == int( priority ) :
554 respFlowId = item["id"]
555
556 main.step( "Deleting the created flow by deviceId and flowId" )
557 flowResponse = main.ONOSrest.removeFlow( deviceId = deviceId,
558 flowId = respFlowId )
559
560 utilities.assert_equals( expect=main.TRUE,
561 actual=flowResponse,
562 onpass="Deleting flow is successful!!!",
563 onfail="Deleting flow is failure!!!" )
564
565 # Giving ONOS time to delete the flow
566 time.sleep( main.delFlowSleep )
567
568 main.step( "Deleting the created group by deviceId and appCookie" )
569 groupResponse = main.ONOSrest.removeGroup( deviceId = deviceId,
570 appCookie = appCookie )
571
572 utilities.assert_equals( expect=main.TRUE,
573 actual=groupResponse,
574 onpass="Deleting Group is successful!!!",
575 onfail="Deleting Group is failure!!!" )
576
577 # Giving ONOS time to delete the group
578 time.sleep( main.delGroupSleep )
579
580 def CASE7( self, main ):
581 '''
582 Adding Group of type "INDIRECT" using Rest api.
583 '''
584 import json
585 import time
586 isAdded = main.FALSE
587
588 main.case( "Verify Group of type INDIRECT are successfully Added" )
589 main.caseExplanation = " Install a Group of type INDIRECT " +\
590 " Verify the Group is Added " +\
591 " Add a flow using the group " +\
592 " Send a packet that verifies the action bucket of the group"
593
594 main.step( "Add Group using Rest api" )
595 bucketList = []
596 bucket = main.buckets.addBucket( main, egressPort = egressPort1 )
597 bucketList.append( bucket )
598 response = main.ONOSrest.addGroup( deviceId = deviceId,
599 groupType = type2,
600 bucketList = bucketList,
601 appCookie = appCookie,
602 groupId = groupId )
603
604 utilities.assert_equals( expect=main.TRUE,
605 actual=response,
606 onpass="Successfully added Groups of type INDIRECT",
607 onfail="Failed to add Groups of type INDIRECT" )
608
609 # Giving ONOS time to add the group
610 time.sleep( main.addGroupSleep )
611
612 main.step( "Check groups are in ADDED state" )
613
614 response = main.ONOSrest.getGroups( deviceId = deviceId,
615 appCookie = appCookie )
616 responsejson = json.loads( response )
617 for item in responsejson :
618 if item["state"] == "ADDED" :
619 isAdded = main.TRUE
620
621 utilities.assert_equals( expect=main.TRUE,
622 actual=isAdded,
623 onpass="INDIRECT Group is in Added State",
624 onfail="INDIRECT Group is not in Added State" )
625
626 '''
627 Adding flows using rest api
628 '''
629 isAdded = main.FALSE
630
631 main.step( "Adding flow with Group using rest api" )
632 response = main.ONOSrest.addFlow( deviceId = deviceId,
633 priority = priority,
634 ingressPort = ingressPort,
635 groupId = groupId )
636 utilities.assert_equals( expect=main.TRUE,
637 actual=response,
638 onpass="Successfully Added Flows",
639 onfail="Failed to Add flows" )
640
641 # Giving ONOS time to add the flow
642 time.sleep( main.addFlowSleep )
643
644 response = main.ONOSrest.getFlows( deviceId = deviceId )
645 responsejson = json.loads( response )
646 for item in responsejson :
647 if item["priority"] == int( priority ) and item["state"] == "ADDED" :
648 isAdded = main.TRUE
649
650 utilities.assert_equals( expect=main.TRUE,
651 actual=isAdded,
652 onpass="Flow is in Added State",
653 onfail="Flow is not in Added State" )
654
655 '''
656 Sends a packet using scapy
657 '''
658 main.step( "Testing Group by sending packet using Scapy" )
659 main.log.info( "Creating host components" )
660 main.Scapy.createHostComponent( "h1" )
661 main.Scapy.createHostComponent( "h2" )
662
663 hosts = [main.h1, main.h2]
664 for host in hosts:
665 host.startHostCli( )
666 host.startScapy( )
667 host.updateSelf( )
668 main.log.info( "Constructing Packet" )
669 main.h1.buildEther( dst=main.h1.hostMac )
670 main.h1.buildIP( dst=main.h1.hostIp )
671 main.log.info( "Start Filter on host2" )
672 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
673 main.log.info( "sending packet to Host" )
674 main.h1.sendPacket( )
675 main.log.info( "Checking filter for our packet" )
676 stepResultH2 = main.h2.checkFilter( )
677
678 if stepResultH2:
679 main.log.info( "Packet : %s" % main.h2.readPackets( ) )
680 else:
681 main.h2.killFilter( )
682
683 main.log.info( "Clean up host components" )
684 for host in hosts:
685 host.stopScapy( )
686 main.Mininet1.removeHostComponent( "h1" )
687 main.Mininet1.removeHostComponent( "h2" )
688
689 utilities.assert_equals( expect=main.TRUE,
690 actual=stepResultH2,
691 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
692 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
693
694 def CASE8( self, main ):
695 '''
696 Deleting the Group and Flow
697 '''
698 import json
699 import time
700 respFlowId = 1
701
702 main.case( "Delete the Group and Flow added through Rest api " )
703 main.step( "Deleting Group and Flows" )
704
705 #Getting Flow ID
706 response = main.ONOSrest.getFlows( deviceId = deviceId )
707 responsejson = json.loads( response )
708 for item in responsejson :
709 if item["priority"] == int( priority ) :
710 respFlowId = item["id"]
711
712 main.step( "Deleting the created flow by deviceId and flowId" )
713 flowResponse = main.ONOSrest.removeFlow( deviceId = deviceId,
714 flowId = respFlowId )
715
716 utilities.assert_equals( expect=main.TRUE,
717 actual=flowResponse,
718 onpass="Deleting flow is successful!!!",
719 onfail="Deleting flow is failure!!!" )
720
721 # Giving ONOS time to delete the flow
722 time.sleep( main.delFlowSleep )
723
724 groupResponse = main.ONOSrest.removeGroup( deviceId = deviceId,
725 appCookie = appCookie )
726
727 utilities.assert_equals( expect=main.TRUE,
728 actual=groupResponse,
729 onpass="Deleting Group is successful!!!",
730 onfail="Deleting Group is failure!!!" )
731
732 # Giving ONOS time to delete the group
733 time.sleep( main.delGroupSleep )
734
735 def CASE100( self, main ):
736 '''
737 Report errors/warnings/exceptions
738 '''
739 main.log.info( "Error report: \n" )
740 main.ONOSbench.logReport( main.ONOSip[ 0 ],
741 [ "INFO",
742 "FOLLOWER",
743 "WARN",
744 "flow",
745 "group",
746 "ERROR",
747 "Except" ],
748 "s" )