blob: 10dc7cebd988df7c29c3d4f8156e67d2ff6eed40 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
YPZhang801d46d2016-08-08 13:26:28 -070021import time
22import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070023"""
YPZhang801d46d2016-08-08 13:26:28 -070024 Warp function for SCPFportLat test
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070025"""
YPZhang801d46d2016-08-08 13:26:28 -070026def capturePortStatusPack( main, deviceName, interface, portStatus, resultDict, warmup ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070027 """
YPZhang801d46d2016-08-08 13:26:28 -070028 Change device port status and use tshark to capture openflow port package
29 Args:
30 main: TestON class
31 deviceName: Device to change portStatus
32 interface: port number
33 portStatus: up or down
34 resultDict: put result to dictionary
You Wang0e4ca9e2017-08-04 16:40:33 -070035 warmup: if warmup, ignore results
YPZhang801d46d2016-08-08 13:26:28 -070036
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070037 """
YPZhang801d46d2016-08-08 13:26:28 -070038 main.log.info( "Clean up tshark" )
39 with open( main.tsharkResultPath, "w" ) as tshark:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070040 tshark.write( "" )
YPZhang801d46d2016-08-08 13:26:28 -070041 main.log.info( "Starting tshark capture" )
42 main.ONOSbench.tsharkGrep( main.ofportStatus, main.tsharkResultPath )
43 time.sleep( main.measurementSleep )
44 main.log.info( "{} port {} {}".format( deviceName, interface, portStatus ) )
45 main.Mininet1.changeInterfaceStatus( deviceName, interface, portStatus )
46 time.sleep( main.measurementSleep )
47 main.log.info( "Stopping all Tshark processes" )
48 main.ONOSbench.tsharkStop()
49
50 # Get tshark output
51 with open( main.tsharkResultPath, "r" ) as resultFile:
52 resultText = resultFile.readline()
53 main.log.info( "Capture result:" + resultText )
You Wang1ecfd0a2019-06-21 15:00:45 -070054 resultText = resultText.strip().split( " " )
YPZhang801d46d2016-08-08 13:26:28 -070055 if len( resultText ) > 1:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070056 tsharkResultTime = int( float( resultText[ 1 ] ) * 1000.0 )
YPZhang801d46d2016-08-08 13:26:28 -070057 resultFile.close()
Devin Lim142b5342017-07-20 15:22:39 -070058 for i in range( 1, main.Cluster.numCtrls + 1 ):
YPZhang801d46d2016-08-08 13:26:28 -070059 main.log.info( "================================================" )
60 # get onos metrics timestamps
61 try:
Devin Lim142b5342017-07-20 15:22:39 -070062 response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() )
YPZhang801d46d2016-08-08 13:26:28 -070063 deviceTime = int( response.get( "topologyDeviceEventTimestamp" ).get( "value" ) )
64 main.log.info( "ONOS{} device Event timestemp: {}".format( i, deviceTime ) )
65
66 linkTime = int( response.get( "topologyLinkEventTimestamp" ).get( "value" ) )
67 main.log.info( "ONOS{} Link Event timestemp: {}".format( i, linkTime ) )
68
69 graphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) )
70 main.log.info( "ONOS{} Graph Event timestemp: {}".format( i, graphTime ) )
71 except TypeError:
72 main.log.warn( "TypeError!" )
73 break
74 except ValueError:
75 main.log.warn( "Unable to decode Json object!" )
76 break
77 main.log.info( "================================================" )
78 # calculate latency
79 EtoE = graphTime - tsharkResultTime
80 PtoD = deviceTime - tsharkResultTime
81 DtoL = linkTime - deviceTime
82 LtoG = graphTime - linkTime
83 main.log.info( "ONOS{} End to End time: {}".format( i, EtoE ) )
84 main.log.info( "ONOS{} Package to Device time: {}".format( i, PtoD ) )
85 main.log.info( "ONOS{} Device to Link time: {}".format( i, DtoL ) )
86 main.log.info( "ONOS{} Link to Graph time: {}".format( i, LtoG ) )
87 # if less than 0 waring
88 if EtoE < 0 or PtoD < 0 or DtoL < 0 or LtoG < 0:
89 main.log.warn( "Latency less than 0! Ingore this loop." )
90 else:
91 # put result to dictionary
92 if not warmup:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070093 resultDict[ portStatus ][ 'node' + str( i ) ][ 'EtoE' ].append( EtoE )
94 resultDict[ portStatus ][ 'node' + str( i ) ][ 'PtoD' ].append( PtoD )
95 resultDict[ portStatus ][ 'node' + str( i ) ][ 'DtoL' ].append( DtoL )
96 resultDict[ portStatus ][ 'node' + str( i ) ][ 'LtoG' ].append( LtoG )
YPZhang801d46d2016-08-08 13:26:28 -070097 else:
You Wang0e4ca9e2017-08-04 16:40:33 -070098 main.log.error( "Unexpected tshark output file" )