blob: 2e5eb7654b3fd0e061118d2dbcc612d604182318 [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"""
You Wangb2043922020-10-28 18:45:24 -070026def capturePortStatusPack( main, deviceName, interface, portStatus, resultDict, warmup, tsharkInterface ):
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
You Wangb2043922020-10-28 18:45:24 -070036 tsharkInterface: name of interface which tshark listens to
YPZhang801d46d2016-08-08 13:26:28 -070037
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070038 """
YPZhang801d46d2016-08-08 13:26:28 -070039 main.log.info( "Clean up tshark" )
40 with open( main.tsharkResultPath, "w" ) as tshark:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070041 tshark.write( "" )
YPZhang801d46d2016-08-08 13:26:28 -070042 main.log.info( "Starting tshark capture" )
You Wangb2043922020-10-28 18:45:24 -070043 main.ONOSbench.tsharkGrep( main.ofportStatus, main.tsharkResultPath, interface=tsharkInterface )
YPZhang801d46d2016-08-08 13:26:28 -070044 time.sleep( main.measurementSleep )
45 main.log.info( "{} port {} {}".format( deviceName, interface, portStatus ) )
46 main.Mininet1.changeInterfaceStatus( deviceName, interface, portStatus )
47 time.sleep( main.measurementSleep )
48 main.log.info( "Stopping all Tshark processes" )
49 main.ONOSbench.tsharkStop()
50
51 # Get tshark output
52 with open( main.tsharkResultPath, "r" ) as resultFile:
53 resultText = resultFile.readline()
54 main.log.info( "Capture result:" + resultText )
You Wang2eda1812019-06-21 15:00:45 -070055 resultText = resultText.strip().split( " " )
YPZhang801d46d2016-08-08 13:26:28 -070056 if len( resultText ) > 1:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070057 tsharkResultTime = int( float( resultText[ 1 ] ) * 1000.0 )
YPZhang801d46d2016-08-08 13:26:28 -070058 resultFile.close()
Devin Lim142b5342017-07-20 15:22:39 -070059 for i in range( 1, main.Cluster.numCtrls + 1 ):
YPZhang801d46d2016-08-08 13:26:28 -070060 main.log.info( "================================================" )
61 # get onos metrics timestamps
62 try:
Devin Lim142b5342017-07-20 15:22:39 -070063 response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() )
YPZhang801d46d2016-08-08 13:26:28 -070064 deviceTime = int( response.get( "topologyDeviceEventTimestamp" ).get( "value" ) )
65 main.log.info( "ONOS{} device Event timestemp: {}".format( i, deviceTime ) )
66
67 linkTime = int( response.get( "topologyLinkEventTimestamp" ).get( "value" ) )
68 main.log.info( "ONOS{} Link Event timestemp: {}".format( i, linkTime ) )
69
70 graphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) )
71 main.log.info( "ONOS{} Graph Event timestemp: {}".format( i, graphTime ) )
72 except TypeError:
73 main.log.warn( "TypeError!" )
74 break
75 except ValueError:
76 main.log.warn( "Unable to decode Json object!" )
77 break
78 main.log.info( "================================================" )
79 # calculate latency
80 EtoE = graphTime - tsharkResultTime
81 PtoD = deviceTime - tsharkResultTime
82 DtoL = linkTime - deviceTime
83 LtoG = graphTime - linkTime
84 main.log.info( "ONOS{} End to End time: {}".format( i, EtoE ) )
85 main.log.info( "ONOS{} Package to Device time: {}".format( i, PtoD ) )
86 main.log.info( "ONOS{} Device to Link time: {}".format( i, DtoL ) )
87 main.log.info( "ONOS{} Link to Graph time: {}".format( i, LtoG ) )
88 # if less than 0 waring
89 if EtoE < 0 or PtoD < 0 or DtoL < 0 or LtoG < 0:
90 main.log.warn( "Latency less than 0! Ingore this loop." )
91 else:
92 # put result to dictionary
93 if not warmup:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070094 resultDict[ portStatus ][ 'node' + str( i ) ][ 'EtoE' ].append( EtoE )
95 resultDict[ portStatus ][ 'node' + str( i ) ][ 'PtoD' ].append( PtoD )
96 resultDict[ portStatus ][ 'node' + str( i ) ][ 'DtoL' ].append( DtoL )
97 resultDict[ portStatus ][ 'node' + str( i ) ][ 'LtoG' ].append( LtoG )
YPZhang801d46d2016-08-08 13:26:28 -070098 else:
You Wang0e4ca9e2017-08-04 16:40:33 -070099 main.log.error( "Unexpected tshark output file" )