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 | """ |
You Wang | b204392 | 2020-10-28 18:45:24 -0700 | [diff] [blame] | 26 | def capturePortStatusPack( main, deviceName, interface, portStatus, resultDict, warmup, tsharkInterface ): |
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 |
You Wang | b204392 | 2020-10-28 18:45:24 -0700 | [diff] [blame] | 36 | tsharkInterface: name of interface which tshark listens to |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 37 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 38 | """ |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 39 | main.log.info( "Clean up tshark" ) |
| 40 | with open( main.tsharkResultPath, "w" ) as tshark: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 41 | tshark.write( "" ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 42 | main.log.info( "Starting tshark capture" ) |
You Wang | b204392 | 2020-10-28 18:45:24 -0700 | [diff] [blame] | 43 | main.ONOSbench.tsharkGrep( main.ofportStatus, main.tsharkResultPath, interface=tsharkInterface ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 44 | 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 Wang | 2eda181 | 2019-06-21 15:00:45 -0700 | [diff] [blame] | 55 | resultText = resultText.strip().split( " " ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 56 | if len( resultText ) > 1: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 57 | tsharkResultTime = int( float( resultText[ 1 ] ) * 1000.0 ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 58 | resultFile.close() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 59 | for i in range( 1, main.Cluster.numCtrls + 1 ): |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 60 | main.log.info( "================================================" ) |
| 61 | # get onos metrics timestamps |
| 62 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 63 | response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 64 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 94 | 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 ) |
YPZhang | 801d46d | 2016-08-08 13:26:28 -0700 | [diff] [blame] | 98 | else: |
You Wang | 0e4ca9e | 2017-08-04 16:40:33 -0700 | [diff] [blame] | 99 | main.log.error( "Unexpected tshark output file" ) |