blob: 98ed397c37b9ee4cbd844ab833cd8b0861ce6835 [file] [log] [blame]
YPZhang801d46d2016-08-08 13:26:28 -07001import time
2import json
3'''
4 Warp function for SCPFportLat test
5'''
6
7def capturePortStatusPack( main, deviceName, interface, portStatus, resultDict, warmup ):
8 '''
9 Change device port status and use tshark to capture openflow port package
10 Args:
11 main: TestON class
12 deviceName: Device to change portStatus
13 interface: port number
14 portStatus: up or down
15 resultDict: put result to dictionary
16 warmup: if warmpu, ignore results
17
18 '''
19 main.log.info( "Clean up tshark" )
20 with open( main.tsharkResultPath, "w" ) as tshark:
21 tshark.write("")
22 main.log.info( "Starting tshark capture" )
23 main.ONOSbench.tsharkGrep( main.ofportStatus, main.tsharkResultPath )
24 time.sleep( main.measurementSleep )
25 main.log.info( "{} port {} {}".format( deviceName, interface, portStatus ) )
26 main.Mininet1.changeInterfaceStatus( deviceName, interface, portStatus )
27 time.sleep( main.measurementSleep )
28 main.log.info( "Stopping all Tshark processes" )
29 main.ONOSbench.tsharkStop()
30
31 # Get tshark output
32 with open( main.tsharkResultPath, "r" ) as resultFile:
33 resultText = resultFile.readline()
34 main.log.info( "Capture result:" + resultText )
35 resultText = resultText.split( " " )
36 if len( resultText ) > 1:
37 tsharkResultTime = int( float( resultText[1] ) * 1000.0 )
38 resultFile.close()
39 for i in range( 1, main.numCtrls + 1 ):
40 main.log.info( "================================================" )
41 # get onos metrics timestamps
42 try:
43 response = json.loads( main.CLIs[i - 1].topologyEventsMetrics() )
44 deviceTime = int( response.get( "topologyDeviceEventTimestamp" ).get( "value" ) )
45 main.log.info( "ONOS{} device Event timestemp: {}".format( i, deviceTime ) )
46
47 linkTime = int( response.get( "topologyLinkEventTimestamp" ).get( "value" ) )
48 main.log.info( "ONOS{} Link Event timestemp: {}".format( i, linkTime ) )
49
50 graphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) )
51 main.log.info( "ONOS{} Graph Event timestemp: {}".format( i, graphTime ) )
52 except TypeError:
53 main.log.warn( "TypeError!" )
54 break
55 except ValueError:
56 main.log.warn( "Unable to decode Json object!" )
57 break
58 main.log.info( "================================================" )
59 # calculate latency
60 EtoE = graphTime - tsharkResultTime
61 PtoD = deviceTime - tsharkResultTime
62 DtoL = linkTime - deviceTime
63 LtoG = graphTime - linkTime
64 main.log.info( "ONOS{} End to End time: {}".format( i, EtoE ) )
65 main.log.info( "ONOS{} Package to Device time: {}".format( i, PtoD ) )
66 main.log.info( "ONOS{} Device to Link time: {}".format( i, DtoL ) )
67 main.log.info( "ONOS{} Link to Graph time: {}".format( i, LtoG ) )
68 # if less than 0 waring
69 if EtoE < 0 or PtoD < 0 or DtoL < 0 or LtoG < 0:
70 main.log.warn( "Latency less than 0! Ingore this loop." )
71 else:
72 # put result to dictionary
73 if not warmup:
74 resultDict[ portStatus ][ 'node' + str(i) ]['EtoE'].append( EtoE )
75 resultDict[ portStatus ][ 'node' + str(i) ]['PtoD'].append( PtoD )
76 resultDict[ portStatus ][ 'node' + str(i) ]['DtoL'].append( DtoL )
77 resultDict[ portStatus ][ 'node' + str(i) ]['LtoG'].append( LtoG )
78 else:
79 main.log.error( "Tshark output file for packet_in returned unexpected results" )