blob: f650521b83edf6ca3812e143311bb117c277d3a3 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
YPZhang801d46d2016-08-08 13:26:28 -070022import time
23import json
24'''
25 Warp function for SCPFportLat test
26'''
27
28def capturePortStatusPack( main, deviceName, interface, portStatus, resultDict, warmup ):
29 '''
30 Change device port status and use tshark to capture openflow port package
31 Args:
32 main: TestON class
33 deviceName: Device to change portStatus
34 interface: port number
35 portStatus: up or down
36 resultDict: put result to dictionary
37 warmup: if warmpu, ignore results
38
39 '''
40 main.log.info( "Clean up tshark" )
41 with open( main.tsharkResultPath, "w" ) as tshark:
42 tshark.write("")
43 main.log.info( "Starting tshark capture" )
44 main.ONOSbench.tsharkGrep( main.ofportStatus, main.tsharkResultPath )
45 time.sleep( main.measurementSleep )
46 main.log.info( "{} port {} {}".format( deviceName, interface, portStatus ) )
47 main.Mininet1.changeInterfaceStatus( deviceName, interface, portStatus )
48 time.sleep( main.measurementSleep )
49 main.log.info( "Stopping all Tshark processes" )
50 main.ONOSbench.tsharkStop()
51
52 # Get tshark output
53 with open( main.tsharkResultPath, "r" ) as resultFile:
54 resultText = resultFile.readline()
55 main.log.info( "Capture result:" + resultText )
56 resultText = resultText.split( " " )
57 if len( resultText ) > 1:
58 tsharkResultTime = int( float( resultText[1] ) * 1000.0 )
59 resultFile.close()
Devin Lim142b5342017-07-20 15:22:39 -070060 for i in range( 1, main.Cluster.numCtrls + 1 ):
YPZhang801d46d2016-08-08 13:26:28 -070061 main.log.info( "================================================" )
62 # get onos metrics timestamps
63 try:
Devin Lim142b5342017-07-20 15:22:39 -070064 response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() )
YPZhang801d46d2016-08-08 13:26:28 -070065 deviceTime = int( response.get( "topologyDeviceEventTimestamp" ).get( "value" ) )
66 main.log.info( "ONOS{} device Event timestemp: {}".format( i, deviceTime ) )
67
68 linkTime = int( response.get( "topologyLinkEventTimestamp" ).get( "value" ) )
69 main.log.info( "ONOS{} Link Event timestemp: {}".format( i, linkTime ) )
70
71 graphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) )
72 main.log.info( "ONOS{} Graph Event timestemp: {}".format( i, graphTime ) )
73 except TypeError:
74 main.log.warn( "TypeError!" )
75 break
76 except ValueError:
77 main.log.warn( "Unable to decode Json object!" )
78 break
79 main.log.info( "================================================" )
80 # calculate latency
81 EtoE = graphTime - tsharkResultTime
82 PtoD = deviceTime - tsharkResultTime
83 DtoL = linkTime - deviceTime
84 LtoG = graphTime - linkTime
85 main.log.info( "ONOS{} End to End time: {}".format( i, EtoE ) )
86 main.log.info( "ONOS{} Package to Device time: {}".format( i, PtoD ) )
87 main.log.info( "ONOS{} Device to Link time: {}".format( i, DtoL ) )
88 main.log.info( "ONOS{} Link to Graph time: {}".format( i, LtoG ) )
89 # if less than 0 waring
90 if EtoE < 0 or PtoD < 0 or DtoL < 0 or LtoG < 0:
91 main.log.warn( "Latency less than 0! Ingore this loop." )
92 else:
93 # put result to dictionary
94 if not warmup:
95 resultDict[ portStatus ][ 'node' + str(i) ]['EtoE'].append( EtoE )
96 resultDict[ portStatus ][ 'node' + str(i) ]['PtoD'].append( PtoD )
97 resultDict[ portStatus ][ 'node' + str(i) ]['DtoL'].append( DtoL )
98 resultDict[ portStatus ][ 'node' + str(i) ]['LtoG'].append( LtoG )
99 else:
100 main.log.error( "Tshark output file for packet_in returned unexpected results" )