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 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 21 | """ |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 22 | Wrapper function for SCPFswitchLat test |
| 23 | Assign switch and capture openflow package |
| 24 | remove switch and caputer openflow package |
| 25 | calculate latency |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 26 | """ |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 27 | import time |
| 28 | import json |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 29 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 30 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 31 | def getTimestampFromLog( index, searchTerm ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 32 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 33 | Get timestamp value of the search term from log. |
| 34 | Args: |
| 35 | index: the index of cli |
| 36 | searchTerm: the key term of timestamp |
| 37 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 38 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 39 | lines = main.Cluster.active( index ).CLI.logSearch( mode='last', searchTerm=searchTerm ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 40 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 41 | assert lines is not None |
| 42 | logString = lines[ len( lines ) - 1 ] |
| 43 | # get the target value |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 44 | line = logString.split( "time = " ) |
| 45 | key = line[ 1 ].split( " " ) |
| 46 | return int( key[ 0 ] ) |
| 47 | except IndexError: |
| 48 | main.log.warn( "Index Error!" ) |
| 49 | return 0 |
| 50 | except AssertionError: |
| 51 | main.log.warn( "Search Term Not Found" ) |
| 52 | return 0 |
| 53 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 54 | |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 55 | def processPackage( package ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 56 | """ |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 57 | split package information to dictionary |
| 58 | Args: |
| 59 | package: Package String |
| 60 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 61 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 62 | pacakge = package.split( " " ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 63 | dic = {} |
| 64 | for s in pacakge: |
| 65 | try: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 66 | [ key, value ] = s.split( "=" ) |
| 67 | dic[ key ] = value |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 68 | except: |
| 69 | continue |
| 70 | return dic |
| 71 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 72 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 73 | def findSeqBySeqAck( seq, packageList ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 74 | """ |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 75 | Find specific Seq of package in packageList |
| 76 | Args: |
| 77 | seq: seq from last TCP package |
| 78 | packageList: find package in packageList |
| 79 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 80 | """ |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 81 | for l in packageList: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 82 | temp = processPackage( l ) |
| 83 | tA = temp[ 'Ack' ] |
| 84 | if int( seq ) + 1 == int( tA ): |
| 85 | return temp[ 'Seq' ] |
| 86 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 87 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 88 | def arrangeTsharkFile( switchStatus, keyTerm ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 89 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 90 | Arrange different tshark messeage from overall file to different specific files |
| 91 | Args: |
| 92 | switchStatus: switch up or down |
| 93 | keyTerm: A dictionary that store the path name as value and the searchTerm as key |
| 94 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 95 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 96 | with open( main.tsharkResultPath[ switchStatus ][ 'ALL' ], 'r' ) as resultFile: |
| 97 | resultText = resultFile.readlines() |
| 98 | resultFile.close() |
| 99 | |
| 100 | for line in resultText: |
| 101 | for term in keyTerm: |
| 102 | if term in line: |
| 103 | path = '/tmp/Tshark_' + str( keyTerm[ term ] ) |
| 104 | with open( path, 'a' ) as outputfile: |
| 105 | outputfile.write( line ) |
| 106 | outputfile.close() |
| 107 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 108 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 109 | def checkResult( result1, result2, result3 ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 110 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 111 | Check if the inputs meet the requirement |
| 112 | Returns: |
| 113 | 1 means the results are right, 0 means the results are wrong |
| 114 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 115 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 116 | result = check( result1 ) + check( result2 ) + check( result3 ) |
| 117 | if result < 3: |
| 118 | # if any result is wrong, increase the main wrong number |
| 119 | main.wrong[ 'checkResultIncorrect' ] += 1 |
| 120 | main.wrong[ 'totalWrong' ] += 1 |
| 121 | checkTotalWrongNum() |
| 122 | return 0 |
| 123 | return 1 |
| 124 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 125 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 126 | def check( result ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 127 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 128 | Check the single input. |
| 129 | Returns: |
| 130 | 1 means the input is good, 0 means the input is wrong |
| 131 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 132 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 133 | if result < int( main.resultRange[ 'Min' ] ) or result > int( main.resultRange[ 'Max' ] ): |
Devin Lim | aa256a7 | 2017-10-13 13:40:30 -0700 | [diff] [blame] | 134 | main.log.warn( str( result ) + " is not meet the requirement" ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 135 | return 0 |
| 136 | return 1 |
| 137 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 138 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 139 | def checkTotalWrongNum(): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 140 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 141 | Check if the total wrong number is bigger than the max wrong number. If it is, then exit the |
| 142 | test. |
| 143 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 144 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 145 | # if there are too many wrongs in this test, then exit |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 146 | if main.wrong[ 'totalWrong' ] > main.maxWrong: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 147 | main.log.error( "The total wrong number exceeds %d, test terminated" % main.maxWrong ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 148 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 149 | |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 150 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 151 | def captureOfPack( main, deviceName, ofPack, switchStatus, resultDict, warmup ): |
| 152 | """ |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 153 | Args: |
| 154 | main: TestON class |
| 155 | deviceName: device name |
| 156 | ofPack: openflow package key word |
| 157 | switchStatus: Up -- assign, down -- remove |
| 158 | resultDict: dictionary to contain result |
| 159 | warmup: warm up boolean |
| 160 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 161 | """ |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 162 | main.log.debug( "TOTAL WRONG: " + str( main.wrong ) ) |
| 163 | for d in ofPack[ switchStatus ]: |
| 164 | main.log.info( "Clean up Tshark" ) |
| 165 | with open( main.tsharkResultPath[ switchStatus ][ d ], "w" ) as tshark: |
| 166 | tshark.write( "" ) |
| 167 | # use one tshark to grep everything |
| 168 | # Get the grep string |
| 169 | grepString = '' |
| 170 | keyTerm = {} |
| 171 | for d in ofPack[ switchStatus ]: |
| 172 | grepString = grepString + ofPack[ switchStatus ][ d ] + '|' |
| 173 | # get rid of regular experssion format |
| 174 | cleanTerm = ofPack[ switchStatus ][ d ].replace( '\\', '' ) |
| 175 | keyTerm[ cleanTerm ] = d |
| 176 | # Delete the last '|' |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 177 | grepString = grepString[ :-1 ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 178 | # open tshark |
| 179 | main.log.info( "starting tshark capture" ) |
| 180 | main.ONOSbench.tsharkGrep( grepString, main.tsharkResultPath[ switchStatus ][ 'ALL' ], grepOptions='-E' ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 181 | if switchStatus == 'up': |
| 182 | # if up, assign switch to controller |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 183 | time.sleep( main.measurementSleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 184 | main.log.info( 'Assigning {} to controller'.format( deviceName ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 185 | main.Mininet1.assignSwController( sw=deviceName, ip=main.Cluster.active( 0 ).ipAddress ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 186 | time.sleep( main.measurementSleep ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 187 | if switchStatus == 'down': |
| 188 | # if down, remove switch from topology |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 189 | time.sleep( main.measurementSleep ) |
| 190 | main.step( 'Remove switch from controler' ) |
| 191 | main.Mininet1.deleteSwController( deviceName ) |
| 192 | time.sleep( main.deleteSwSleep ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 193 | main.log.info( "Stopping all Tshark processes" ) |
| 194 | main.ONOSbench.tsharkStop() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 195 | tempResultDict = {} |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 196 | arrangeTsharkFile( switchStatus, keyTerm ) |
| 197 | |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 198 | if switchStatus == 'up': |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 199 | for d in main.tsharkResultPath[ 'up' ]: |
| 200 | with open( main.tsharkResultPath[ switchStatus ][ d ], "r" ) as resultFile: |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 201 | # grep tshark result timestamp |
| 202 | resultText = resultFile.readlines() |
You Wang | 5b81127 | 2017-08-04 17:22:18 -0700 | [diff] [blame] | 203 | if not resultText: |
| 204 | main.log.warn( "Empty tshark result!" ) |
| 205 | main.wrong[ 'TsharkValueIncorrect' ] += 1 |
| 206 | main.wrong[ 'totalWrong' ] += 1 |
| 207 | checkTotalWrongNum() |
| 208 | return |
YPZhang | 21adb60 | 2016-08-18 16:00:11 -0700 | [diff] [blame] | 209 | if d == "TCP": |
| 210 | # if TCP package, we should use the latest one package |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 211 | resultText = resultText[ len( resultText ) - 1 ] |
YPZhang | 21adb60 | 2016-08-18 16:00:11 -0700 | [diff] [blame] | 212 | else: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 213 | resultText = resultText[ 0 ] |
| 214 | main.log.info( "Capture result:" + resultText ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 215 | resultText = resultText.strip() |
| 216 | resultText = resultText.split( " " ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 217 | if len( resultText ) > 1: |
| 218 | tempResultDict[ d ] = int( ( float( resultText[ 1 ] ) * 1000 ) ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 219 | resultFile.close() |
| 220 | elif switchStatus == 'down': |
| 221 | # if state is down, we should capture Fin/Ack and ACK package |
| 222 | # Use seq number in FIN/ACK package to located ACK package |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 223 | with open( main.tsharkResultPath[ 'down' ][ 'FA' ], 'r' ) as resultFile: |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 224 | resultText = resultFile.readlines() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 225 | FinAckText = resultText.pop( 0 ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 226 | resultFile.close() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 227 | FinAckSeq = processPackage( FinAckText )[ 'Seq' ] |
| 228 | FinAckOFseq = findSeqBySeqAck( FinAckSeq, resultText ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 229 | if FinAckOFseq is None: |
You Wang | 1847760 | 2017-02-24 15:48:01 -0800 | [diff] [blame] | 230 | main.log.warn( "Tshark Result was incorrect!" ) |
| 231 | main.log.warn( resultText ) |
| 232 | main.wrong[ 'TsharkValueIncorrect' ] += 1 |
| 233 | main.wrong[ 'totalWrong' ] += 1 |
| 234 | checkTotalWrongNum() |
| 235 | return |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 236 | with open( main.tsharkResultPath[ 'down' ][ 'ACK' ], "r" ) as resultFile: |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 237 | ACKlines = resultFile.readlines() |
| 238 | resultFile.close() |
YPZhang | 3943fbe | 2016-08-18 14:33:29 -0700 | [diff] [blame] | 239 | AckPackage = "" |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 240 | for l in ACKlines: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 241 | temp = processPackage( l ) |
| 242 | finSeq = findSeqBySeqAck( FinAckOFseq, ACKlines ) |
| 243 | if temp[ 'Seq' ] == finSeq: |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 244 | AckPackage = l |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 245 | if len( AckPackage ) > 0: |
YPZhang | 3943fbe | 2016-08-18 14:33:29 -0700 | [diff] [blame] | 246 | FinAckText = FinAckText.strip() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 247 | FinAckText = FinAckText.split( " " ) |
YPZhang | 3943fbe | 2016-08-18 14:33:29 -0700 | [diff] [blame] | 248 | AckPackage = AckPackage.strip() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 249 | AckPackage = AckPackage.split( " " ) |
| 250 | tempResultDict[ 'ACK' ] = int( float( AckPackage[ 1 ] ) * 1000 ) |
| 251 | tempResultDict[ 'FA' ] = int( float( FinAckText[ 1 ] ) * 1000 ) |
YPZhang | 3943fbe | 2016-08-18 14:33:29 -0700 | [diff] [blame] | 252 | else: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 253 | main.wrong[ 'skipDown' ] += 1 |
| 254 | main.wrong[ 'totalWrong' ] += 1 |
| 255 | checkTotalWrongNum() |
YPZhang | 3943fbe | 2016-08-18 14:33:29 -0700 | [diff] [blame] | 256 | return |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 257 | |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 258 | # calculate latency |
| 259 | if switchStatus == "up": |
| 260 | # up Latency |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 261 | for d in resultDict[ switchStatus ]: |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 262 | T_Ftemp = 0 |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 263 | try: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 264 | T_Ftemp = tempResultDict[ 'Feature' ] - tempResultDict[ 'TCP' ] |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 265 | except KeyError: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 266 | main.log.warn( "Tshark Result was incorrect!" ) |
| 267 | main.log.warn( tempResultDict ) |
| 268 | main.wrong[ 'TsharkValueIncorrect' ] += 1 |
| 269 | main.wrong[ 'totalWrong' ] += 1 |
| 270 | checkTotalWrongNum() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 271 | return |
| 272 | if not warmup: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 273 | resultDict[ switchStatus ][ d ][ 'T_F' ].append( T_Ftemp ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 274 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 275 | main.log.info( "{} TCP to Feature: {}".format( d, str( T_Ftemp ) ) ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 276 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 277 | for i in range( 1, main.Cluster.numCtrls + 1 ): |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 278 | F_Dtemp = 0 |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 279 | D_Gtemp = 0 |
| 280 | E_Etemp = 0 |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 281 | main.log.info( "================================================" ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 282 | # get onos metrics timestamps |
| 283 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 284 | response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() ) |
Devin Lim | aa256a7 | 2017-10-13 13:40:30 -0700 | [diff] [blame] | 285 | |
| 286 | # Just to show the other event times. |
| 287 | main.log.info( "ONOS{} device Event timestamp: {}".format( |
| 288 | i, int( response.get( "topologyDeviceEventTimestamp" ).get( "value" ) ) ) ) |
| 289 | main.log.info( "ONOS{} graph reason Event timestamp: {}".format( |
| 290 | i, int( response.get( "topologyGraphReasonsEventTimestamp" ).get( "value" ) ) ) ) |
| 291 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 292 | DeviceTime = getTimestampFromLog( i - 1, searchTerm=main.searchTerm[ switchStatus ] ) |
Devin Lim | aa256a7 | 2017-10-13 13:40:30 -0700 | [diff] [blame] | 293 | main.log.info( "ONOS{} device from karaf log: {}".format( i, DeviceTime ) ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 294 | GraphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) ) |
| 295 | main.log.info( "ONOS{} Graph Event timestamp: {}".format( i, GraphTime ) ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 296 | except TypeError: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 297 | main.log.warn( "TypeError" ) |
| 298 | main.wrong[ 'TypeError' ] += 1 |
| 299 | main.wrong[ 'totalWrong' ] += 1 |
| 300 | checkTotalWrongNum() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 301 | break |
| 302 | except ValueError: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 303 | main.log.warn( "Error to decode Json object!" ) |
| 304 | main.wrong[ 'decodeJasonError' ] += 1 |
| 305 | main.wrong[ 'totalWrong' ] += 1 |
| 306 | checkTotalWrongNum() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 307 | break |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 308 | if DeviceTime != 0: |
| 309 | try: |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 310 | F_Dtemp = DeviceTime - tempResultDict[ 'Feature' ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 311 | D_Gtemp = GraphTime - DeviceTime |
| 312 | E_Etemp = GraphTime - tempResultDict[ 'TCP' ] |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 313 | check = checkResult( F_Dtemp, D_Gtemp, E_Etemp ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 314 | if check == 1: |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 315 | main.log.info( "Feature to Device:{}".format( F_Dtemp ) ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 316 | main.log.info( "Device to Graph:{}".format( D_Gtemp ) ) |
| 317 | main.log.info( "End to End:{}".format( E_Etemp ) ) |
| 318 | main.log.info( "================================================" ) |
| 319 | except KeyError: |
| 320 | main.log.warn( "Tshark Result was incorrect!" ) |
| 321 | main.log.warn( tempResultDict ) |
| 322 | main.wrong[ 'TsharkValueIncorrect' ] += 1 |
| 323 | main.wrong[ 'totalWrong' ] += 1 |
| 324 | checkTotalWrongNum() |
| 325 | return |
| 326 | except TypeError: |
| 327 | main.log.warn( "TypeError" ) |
| 328 | main.wrong[ 'TypeError' ] += 1 |
| 329 | main.wrong[ 'totalWrong' ] += 1 |
| 330 | checkTotalWrongNum() |
| 331 | break |
| 332 | except ValueError: |
| 333 | main.log.warn( "Error to decode Json object!" ) |
| 334 | main.wrong[ 'decodeJasonError' ] += 1 |
| 335 | main.wrong[ 'totalWrong' ] += 1 |
| 336 | checkTotalWrongNum() |
| 337 | break |
| 338 | if not warmup and check == 1: |
Devin Lim | f70bb3a | 2018-04-13 19:15:51 -0700 | [diff] [blame] | 339 | resultDict[ switchStatus ][ 'node' + str( i ) ][ 'F_D' ].append( F_Dtemp ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 340 | resultDict[ switchStatus ][ 'node' + str( i ) ][ 'D_G' ].append( D_Gtemp ) |
| 341 | resultDict[ switchStatus ][ 'node' + str( i ) ][ 'E_E' ].append( E_Etemp ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 342 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 343 | main.wrong[ 'checkResultIncorrect' ] += 1 |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 344 | main.wrong[ 'totalWrong' ] += 1 |
| 345 | checkTotalWrongNum() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 346 | main.log.debug( "Skip this iteration due to the None Devicetime" ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 347 | |
| 348 | if switchStatus == "down": |
| 349 | # down Latency |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 350 | for d in resultDict[ switchStatus ]: |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 351 | FA_Atemp = 0 |
| 352 | try: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 353 | FA_Atemp = tempResultDict[ 'ACK' ] - tempResultDict[ 'FA' ] |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 354 | except KeyError: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 355 | main.log.warn( "Tshark Result was incorrect!" ) |
| 356 | main.log.warn( tempResultDict ) |
| 357 | main.wrong[ 'TsharkValueIncorrect' ] += 1 |
| 358 | main.wrong[ 'totalWrong' ] += 1 |
| 359 | checkTotalWrongNum() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 360 | return |
| 361 | if not warmup: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 362 | resultDict[ switchStatus ][ d ][ 'FA_A' ].append( FA_Atemp ) |
| 363 | main.log.info( "{} FIN/ACK TO ACK {}:".format( d, FA_Atemp ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 364 | for i in range( 1, main.Cluster.numCtrls + 1 ): |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 365 | A_Dtemp = 0 |
| 366 | D_Gtemp = 0 |
| 367 | E_Etemp = 0 |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 368 | main.log.info( "================================================" ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 369 | # get onos metrics timestamps |
| 370 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 371 | response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() ) |
Devin Lim | aa256a7 | 2017-10-13 13:40:30 -0700 | [diff] [blame] | 372 | # Just to show the other event times. |
| 373 | main.log.info( "ONOS{} device Event timestamp: {}".format( |
| 374 | i, int( response.get( "topologyDeviceEventTimestamp" ).get( "value" ) ) ) ) |
| 375 | main.log.info( "ONOS{} graph reason Event timestamp: {}".format( |
| 376 | i, int( response.get( "topologyGraphReasonsEventTimestamp" ).get( "value" ) ) ) ) |
| 377 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 378 | DeviceTime = getTimestampFromLog( i - 1, searchTerm=main.searchTerm[ switchStatus ] ) |
Devin Lim | aa256a7 | 2017-10-13 13:40:30 -0700 | [diff] [blame] | 379 | main.log.info( "ONOS{} device from karaf log: {}".format( i, DeviceTime ) ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 380 | GraphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) ) |
| 381 | main.log.info( "ONOS{} Graph Event timestamp: {}".format( i, GraphTime ) ) |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 382 | except TypeError: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 383 | main.log.warn( "TypeError" ) |
| 384 | main.wrong[ 'TypeError' ] += 1 |
| 385 | main.wrong[ 'totalWrong' ] += 1 |
| 386 | checkTotalWrongNum() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 387 | break |
| 388 | except ValueError: |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 389 | main.log.warn( "Error to decode Json object!" ) |
| 390 | main.wrong[ 'decodeJasonError' ] += 1 |
| 391 | main.wrong[ 'totalWrong' ] += 1 |
| 392 | checkTotalWrongNum() |
YPZhang | 38fb119 | 2016-08-11 11:03:38 -0700 | [diff] [blame] | 393 | break |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 394 | if DeviceTime != 0: |
| 395 | main.log.info( "================================================" ) |
| 396 | try: |
| 397 | A_Dtemp = DeviceTime - tempResultDict[ 'ACK' ] |
| 398 | D_Gtemp = GraphTime - DeviceTime |
| 399 | E_Etemp = GraphTime - tempResultDict[ 'FA' ] |
| 400 | check = checkResult( A_Dtemp, D_Gtemp, E_Etemp ) |
| 401 | if check == 1: |
| 402 | main.log.info( "ACK to device: {}".format( A_Dtemp ) ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 403 | main.log.info( "Device to Graph: {}".format( D_Gtemp ) ) |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 404 | main.log.info( "End to End: {}".format( E_Etemp ) ) |
| 405 | main.log.info( "================================================" ) |
| 406 | except KeyError: |
| 407 | main.log.warn( "Tshark Result was incorrect!" ) |
| 408 | main.log.warn( tempResultDict ) |
| 409 | main.wrong[ 'TsharkValueIncorrect' ] += 1 |
| 410 | main.wrong[ 'totalWrong' ] += 1 |
| 411 | checkTotalWrongNum() |
| 412 | return |
| 413 | except TypeError: |
| 414 | main.log.warn( "TypeError" ) |
| 415 | main.wrong[ 'TypeError' ] += 1 |
| 416 | main.wrong[ 'totalWrong' ] += 1 |
| 417 | checkTotalWrongNum() |
| 418 | break |
| 419 | except ValueError: |
| 420 | main.log.warn( "Error to decode Json object!" ) |
| 421 | main.wrong[ 'decodeJasonError' ] += 1 |
| 422 | main.wrong[ 'totalWrong' ] += 1 |
| 423 | checkTotalWrongNum() |
| 424 | break |
| 425 | if not warmup and check == 1: |
| 426 | resultDict[ switchStatus ][ 'node' + str( i ) ][ 'A_D' ].append( A_Dtemp ) |
| 427 | resultDict[ switchStatus ][ 'node' + str( i ) ][ 'D_G' ].append( D_Gtemp ) |
| 428 | resultDict[ switchStatus ][ 'node' + str( i ) ][ 'E_E' ].append( E_Etemp ) |
| 429 | |
| 430 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 431 | main.wrong[ 'checkResultIncorrect' ] += 1 |
| 432 | main.wrong[ 'totalWrong' ] += 1 |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 433 | checkTotalWrongNum() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 434 | main.log.debug( "Skip this iteration due to the None Devicetime" ) |