Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 | """ |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 21 | import time |
| 22 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 23 | """ |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 24 | Warp function for SCPFportLat test |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 25 | """ |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 26 | def capturePortStatusPack( main, deviceName, interface, portStatus, resultDict, warmup ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 27 | """ |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 28 | 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 Wang | 0e4ca9e | 2017-08-04 16:40:33 -0700 | [diff] [blame] | 35 | warmup: if warmup, ignore results |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 36 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 37 | """ |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 38 | main.log.info( "Clean up tshark" ) |
| 39 | with open( main.tsharkResultPath, "w" ) as tshark: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 40 | tshark.write( "" ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 41 | 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 ) |
| 54 | resultText = resultText.split( " " ) |
| 55 | if len( resultText ) > 1: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 56 | tsharkResultTime = int( float( resultText[ 1 ] ) * 1000.0 ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 57 | resultFile.close() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 58 | for i in range( 1, main.Cluster.numCtrls + 1 ): |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 59 | main.log.info( "================================================" ) |
| 60 | # get onos metrics timestamps |
| 61 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 62 | response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 63 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 93 | 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 ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 97 | else: |
You Wang | 0e4ca9e | 2017-08-04 16:40:33 -0700 | [diff] [blame] | 98 | main.log.error( "Unexpected tshark output file" ) |