blob: 7a159bacb569e59833873ee5f08783b737974a8d [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"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070021"""
YPZhang38fb1192016-08-11 11:03:38 -070022 Wrapper function for SCPFswitchLat test
23 Assign switch and capture openflow package
24 remove switch and caputer openflow package
25 calculate latency
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070026"""
YPZhang38fb1192016-08-11 11:03:38 -070027import time
28import json
chengchiyu08303a02016-09-08 17:40:26 -070029
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070030
chengchiyu08303a02016-09-08 17:40:26 -070031def getTimestampFromLog( index, searchTerm ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070032 """
chengchiyu08303a02016-09-08 17:40:26 -070033 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 Ronquillo23fb2162017-09-15 14:59:57 -070038 """
Devin Lim142b5342017-07-20 15:22:39 -070039 lines = main.Cluster.active( index ).CLI.logSearch( mode='last', searchTerm=searchTerm )
chengchiyu08303a02016-09-08 17:40:26 -070040 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070041 assert lines is not None
42 logString = lines[ len( lines ) - 1 ]
43 # get the target value
chengchiyu08303a02016-09-08 17:40:26 -070044 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 Ronquillo23fb2162017-09-15 14:59:57 -070054
YPZhang38fb1192016-08-11 11:03:38 -070055def processPackage( package ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070056 """
YPZhang38fb1192016-08-11 11:03:38 -070057 split package information to dictionary
58 Args:
59 package: Package String
60
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070061 """
chengchiyu08303a02016-09-08 17:40:26 -070062 pacakge = package.split( " " )
YPZhang38fb1192016-08-11 11:03:38 -070063 dic = {}
64 for s in pacakge:
65 try:
chengchiyu08303a02016-09-08 17:40:26 -070066 [ key, value ] = s.split( "=" )
67 dic[ key ] = value
YPZhang38fb1192016-08-11 11:03:38 -070068 except:
69 continue
70 return dic
71
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070072
chengchiyu08303a02016-09-08 17:40:26 -070073def findSeqBySeqAck( seq, packageList ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070074 """
YPZhang38fb1192016-08-11 11:03:38 -070075 Find specific Seq of package in packageList
76 Args:
77 seq: seq from last TCP package
78 packageList: find package in packageList
79
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070080 """
YPZhang38fb1192016-08-11 11:03:38 -070081 for l in packageList:
chengchiyu08303a02016-09-08 17:40:26 -070082 temp = processPackage( l )
83 tA = temp[ 'Ack' ]
84 if int( seq ) + 1 == int( tA ):
85 return temp[ 'Seq' ]
86
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070087
chengchiyu08303a02016-09-08 17:40:26 -070088def arrangeTsharkFile( switchStatus, keyTerm ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070089 """
chengchiyu08303a02016-09-08 17:40:26 -070090 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 Ronquillo23fb2162017-09-15 14:59:57 -070095 """
chengchiyu08303a02016-09-08 17:40:26 -070096 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 Ronquillo23fb2162017-09-15 14:59:57 -0700108
chengchiyu08303a02016-09-08 17:40:26 -0700109def checkResult( result1, result2, result3 ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700110 """
chengchiyu08303a02016-09-08 17:40:26 -0700111 Check if the inputs meet the requirement
112 Returns:
113 1 means the results are right, 0 means the results are wrong
114
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700115 """
chengchiyu08303a02016-09-08 17:40:26 -0700116 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 Ronquillo23fb2162017-09-15 14:59:57 -0700125
chengchiyu08303a02016-09-08 17:40:26 -0700126def check( result ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700127 """
chengchiyu08303a02016-09-08 17:40:26 -0700128 Check the single input.
129 Returns:
130 1 means the input is good, 0 means the input is wrong
131
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700132 """
chengchiyu08303a02016-09-08 17:40:26 -0700133 if result < int( main.resultRange[ 'Min' ] ) or result > int( main.resultRange[ 'Max' ] ):
134 main.log.debug( str( result ) + " is not meet the requirement" )
135 return 0
136 return 1
137
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700138
chengchiyu08303a02016-09-08 17:40:26 -0700139def checkTotalWrongNum():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700140 """
chengchiyu08303a02016-09-08 17:40:26 -0700141 Check if the total wrong number is bigger than the max wrong number. If it is, then exit the
142 test.
143
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700144 """
chengchiyu08303a02016-09-08 17:40:26 -0700145 # if there are too many wrongs in this test, then exit
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700146 if main.wrong[ 'totalWrong' ] > main.maxWrong:
chengchiyu08303a02016-09-08 17:40:26 -0700147 main.log.error( "The total wrong number exceeds %d, test terminated" % main.maxWrong )
Devin Lim44075962017-08-11 10:56:37 -0700148 main.cleanAndExit()
chengchiyu08303a02016-09-08 17:40:26 -0700149
YPZhang38fb1192016-08-11 11:03:38 -0700150
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700151def captureOfPack( main, deviceName, ofPack, switchStatus, resultDict, warmup ):
152 """
YPZhang38fb1192016-08-11 11:03:38 -0700153 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 Ronquillo23fb2162017-09-15 14:59:57 -0700161 """
chengchiyu08303a02016-09-08 17:40:26 -0700162 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 Ronquillo23fb2162017-09-15 14:59:57 -0700177 grepString = grepString[ :-1 ]
chengchiyu08303a02016-09-08 17:40:26 -0700178 # open tshark
179 main.log.info( "starting tshark capture" )
180 main.ONOSbench.tsharkGrep( grepString, main.tsharkResultPath[ switchStatus ][ 'ALL' ], grepOptions='-E' )
YPZhang38fb1192016-08-11 11:03:38 -0700181 if switchStatus == 'up':
182 # if up, assign switch to controller
chengchiyu08303a02016-09-08 17:40:26 -0700183 time.sleep( main.measurementSleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700184 main.log.info( 'Assigning {} to controller'.format( deviceName ) )
Devin Lim142b5342017-07-20 15:22:39 -0700185 main.Mininet1.assignSwController( sw=deviceName, ip=main.Cluster.active( 0 ).ipAddress )
chengchiyu08303a02016-09-08 17:40:26 -0700186 time.sleep( main.measurementSleep )
YPZhang38fb1192016-08-11 11:03:38 -0700187 if switchStatus == 'down':
188 # if down, remove switch from topology
chengchiyu08303a02016-09-08 17:40:26 -0700189 time.sleep( main.measurementSleep )
190 main.step( 'Remove switch from controler' )
191 main.Mininet1.deleteSwController( deviceName )
192 time.sleep( main.deleteSwSleep )
YPZhang38fb1192016-08-11 11:03:38 -0700193 main.log.info( "Stopping all Tshark processes" )
194 main.ONOSbench.tsharkStop()
YPZhang38fb1192016-08-11 11:03:38 -0700195 tempResultDict = {}
chengchiyu08303a02016-09-08 17:40:26 -0700196 arrangeTsharkFile( switchStatus, keyTerm )
197
YPZhang38fb1192016-08-11 11:03:38 -0700198 if switchStatus == 'up':
chengchiyu08303a02016-09-08 17:40:26 -0700199 for d in main.tsharkResultPath[ 'up' ]:
200 with open( main.tsharkResultPath[ switchStatus ][ d ], "r" ) as resultFile:
YPZhang38fb1192016-08-11 11:03:38 -0700201 # grep tshark result timestamp
202 resultText = resultFile.readlines()
You Wang5b811272017-08-04 17:22:18 -0700203 if not resultText:
204 main.log.warn( "Empty tshark result!" )
205 main.wrong[ 'TsharkValueIncorrect' ] += 1
206 main.wrong[ 'totalWrong' ] += 1
207 checkTotalWrongNum()
208 return
YPZhang21adb602016-08-18 16:00:11 -0700209 if d == "TCP":
210 # if TCP package, we should use the latest one package
chengchiyu08303a02016-09-08 17:40:26 -0700211 resultText = resultText[ len( resultText ) - 1 ]
YPZhang21adb602016-08-18 16:00:11 -0700212 else:
chengchiyu08303a02016-09-08 17:40:26 -0700213 resultText = resultText[ 0 ]
214 main.log.info( "Capture result:" + resultText )
YPZhang38fb1192016-08-11 11:03:38 -0700215 resultText = resultText.strip()
216 resultText = resultText.split( " " )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700217 if len( resultText ) > 1:
218 tempResultDict[ d ] = int( ( float( resultText[ 1 ] ) * 1000 ) )
YPZhang38fb1192016-08-11 11:03:38 -0700219 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
chengchiyu08303a02016-09-08 17:40:26 -0700223 with open( main.tsharkResultPath[ 'down' ][ 'FA' ], 'r' ) as resultFile:
YPZhang38fb1192016-08-11 11:03:38 -0700224 resultText = resultFile.readlines()
chengchiyu08303a02016-09-08 17:40:26 -0700225 FinAckText = resultText.pop( 0 )
YPZhang38fb1192016-08-11 11:03:38 -0700226 resultFile.close()
chengchiyu08303a02016-09-08 17:40:26 -0700227 FinAckSeq = processPackage( FinAckText )[ 'Seq' ]
228 FinAckOFseq = findSeqBySeqAck( FinAckSeq, resultText )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700229 if FinAckOFseq is None:
You Wang18477602017-02-24 15:48:01 -0800230 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
chengchiyu08303a02016-09-08 17:40:26 -0700236 with open( main.tsharkResultPath[ 'down' ][ 'ACK' ], "r" ) as resultFile:
YPZhang38fb1192016-08-11 11:03:38 -0700237 ACKlines = resultFile.readlines()
238 resultFile.close()
YPZhang3943fbe2016-08-18 14:33:29 -0700239 AckPackage = ""
YPZhang38fb1192016-08-11 11:03:38 -0700240 for l in ACKlines:
chengchiyu08303a02016-09-08 17:40:26 -0700241 temp = processPackage( l )
242 finSeq = findSeqBySeqAck( FinAckOFseq, ACKlines )
243 if temp[ 'Seq' ] == finSeq:
YPZhang38fb1192016-08-11 11:03:38 -0700244 AckPackage = l
chengchiyu08303a02016-09-08 17:40:26 -0700245 if len( AckPackage ) > 0:
YPZhang3943fbe2016-08-18 14:33:29 -0700246 FinAckText = FinAckText.strip()
chengchiyu08303a02016-09-08 17:40:26 -0700247 FinAckText = FinAckText.split( " " )
YPZhang3943fbe2016-08-18 14:33:29 -0700248 AckPackage = AckPackage.strip()
chengchiyu08303a02016-09-08 17:40:26 -0700249 AckPackage = AckPackage.split( " " )
250 tempResultDict[ 'ACK' ] = int( float( AckPackage[ 1 ] ) * 1000 )
251 tempResultDict[ 'FA' ] = int( float( FinAckText[ 1 ] ) * 1000 )
YPZhang3943fbe2016-08-18 14:33:29 -0700252 else:
chengchiyu08303a02016-09-08 17:40:26 -0700253 main.wrong[ 'skipDown' ] += 1
254 main.wrong[ 'totalWrong' ] += 1
255 checkTotalWrongNum()
YPZhang3943fbe2016-08-18 14:33:29 -0700256 return
chengchiyu08303a02016-09-08 17:40:26 -0700257
YPZhang38fb1192016-08-11 11:03:38 -0700258 # calculate latency
259 if switchStatus == "up":
260 # up Latency
chengchiyu08303a02016-09-08 17:40:26 -0700261 for d in resultDict[ switchStatus ]:
YPZhang38fb1192016-08-11 11:03:38 -0700262 T_Ftemp = 0
263 F_Rtemp = 0
264 RQ_RRtemp = 0
265 try:
chengchiyu08303a02016-09-08 17:40:26 -0700266 T_Ftemp = tempResultDict[ 'Feature' ] - tempResultDict[ 'TCP' ]
267 F_Rtemp = tempResultDict[ 'RQ' ] - tempResultDict[ 'Feature' ]
268 RQ_RRtemp = tempResultDict[ 'RR' ] - tempResultDict[ 'RQ' ]
YPZhang38fb1192016-08-11 11:03:38 -0700269 except KeyError:
chengchiyu08303a02016-09-08 17:40:26 -0700270 main.log.warn( "Tshark Result was incorrect!" )
271 main.log.warn( tempResultDict )
272 main.wrong[ 'TsharkValueIncorrect' ] += 1
273 main.wrong[ 'totalWrong' ] += 1
274 checkTotalWrongNum()
YPZhang38fb1192016-08-11 11:03:38 -0700275 return
276 if not warmup:
chengchiyu08303a02016-09-08 17:40:26 -0700277 resultDict[ switchStatus ][ d ][ 'T_F' ].append( T_Ftemp )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700278 resultDict[ switchStatus ][ d ][ 'F_R' ].append( F_Rtemp )
chengchiyu08303a02016-09-08 17:40:26 -0700279 resultDict[ switchStatus ][ d ][ 'RQ_RR' ].append( RQ_RRtemp )
YPZhang38fb1192016-08-11 11:03:38 -0700280
chengchiyu08303a02016-09-08 17:40:26 -0700281 main.log.info( "{} TCP to Feature: {}".format( d, str( T_Ftemp ) ) )
282 main.log.info( "{} Feature to Role Request: {}".format( d, str( F_Rtemp ) ) )
283 main.log.info( "{} Role Request to Role Reply: {}".format( d, str( RQ_RRtemp ) ) )
YPZhang38fb1192016-08-11 11:03:38 -0700284
Devin Lim142b5342017-07-20 15:22:39 -0700285 for i in range( 1, main.Cluster.numCtrls + 1 ):
YPZhang38fb1192016-08-11 11:03:38 -0700286 RR_Dtemp = 0
287 D_Gtemp = 0
288 E_Etemp = 0
chengchiyu08303a02016-09-08 17:40:26 -0700289 main.log.info( "================================================" )
YPZhang38fb1192016-08-11 11:03:38 -0700290 # get onos metrics timestamps
291 try:
Devin Lim142b5342017-07-20 15:22:39 -0700292 response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700293 DeviceTime = getTimestampFromLog( i - 1, searchTerm=main.searchTerm[ switchStatus ] )
chengchiyu08303a02016-09-08 17:40:26 -0700294 main.log.info( "ONOS{} device Event timestamp: {}".format( i, "%.2f" % DeviceTime ) )
295 GraphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) )
296 main.log.info( "ONOS{} Graph Event timestamp: {}".format( i, GraphTime ) )
YPZhang38fb1192016-08-11 11:03:38 -0700297 except TypeError:
chengchiyu08303a02016-09-08 17:40:26 -0700298 main.log.warn( "TypeError" )
299 main.wrong[ 'TypeError' ] += 1
300 main.wrong[ 'totalWrong' ] += 1
301 checkTotalWrongNum()
YPZhang38fb1192016-08-11 11:03:38 -0700302 break
303 except ValueError:
chengchiyu08303a02016-09-08 17:40:26 -0700304 main.log.warn( "Error to decode Json object!" )
305 main.wrong[ 'decodeJasonError' ] += 1
306 main.wrong[ 'totalWrong' ] += 1
307 checkTotalWrongNum()
YPZhang38fb1192016-08-11 11:03:38 -0700308 break
chengchiyu08303a02016-09-08 17:40:26 -0700309 if DeviceTime != 0:
310 try:
311 RR_Dtemp = DeviceTime - tempResultDict[ 'RR' ]
312 D_Gtemp = GraphTime - DeviceTime
313 E_Etemp = GraphTime - tempResultDict[ 'TCP' ]
314 check = checkResult( RR_Dtemp, D_Gtemp, E_Etemp )
315 if check == 1:
316 main.log.info( "Role reply to Device:{}".format( RR_Dtemp ) )
317 main.log.info( "Device to Graph:{}".format( D_Gtemp ) )
318 main.log.info( "End to End:{}".format( E_Etemp ) )
319 main.log.info( "================================================" )
320 except KeyError:
321 main.log.warn( "Tshark Result was incorrect!" )
322 main.log.warn( tempResultDict )
323 main.wrong[ 'TsharkValueIncorrect' ] += 1
324 main.wrong[ 'totalWrong' ] += 1
325 checkTotalWrongNum()
326 return
327 except TypeError:
328 main.log.warn( "TypeError" )
329 main.wrong[ 'TypeError' ] += 1
330 main.wrong[ 'totalWrong' ] += 1
331 checkTotalWrongNum()
332 break
333 except ValueError:
334 main.log.warn( "Error to decode Json object!" )
335 main.wrong[ 'decodeJasonError' ] += 1
336 main.wrong[ 'totalWrong' ] += 1
337 checkTotalWrongNum()
338 break
339 if not warmup and check == 1:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700340 resultDict[ switchStatus ][ 'node' + str( i ) ][ 'RR_D' ].append( RR_Dtemp )
341 resultDict[ switchStatus ][ 'node' + str( i ) ][ 'D_G' ].append( D_Gtemp )
342 resultDict[ switchStatus ][ 'node' + str( i ) ][ 'E_E' ].append( E_Etemp )
chengchiyu08303a02016-09-08 17:40:26 -0700343 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700344 main.wrong[ 'checkResultIncorrect' ] += 1
chengchiyu08303a02016-09-08 17:40:26 -0700345 main.wrong[ 'totalWrong' ] += 1
346 checkTotalWrongNum()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700347 main.log.debug( "Skip this iteration due to the None Devicetime" )
YPZhang38fb1192016-08-11 11:03:38 -0700348
349 if switchStatus == "down":
350 # down Latency
chengchiyu08303a02016-09-08 17:40:26 -0700351 for d in resultDict[ switchStatus ]:
YPZhang38fb1192016-08-11 11:03:38 -0700352 FA_Atemp = 0
353 try:
chengchiyu08303a02016-09-08 17:40:26 -0700354 FA_Atemp = tempResultDict[ 'ACK' ] - tempResultDict[ 'FA' ]
YPZhang38fb1192016-08-11 11:03:38 -0700355 except KeyError:
chengchiyu08303a02016-09-08 17:40:26 -0700356 main.log.warn( "Tshark Result was incorrect!" )
357 main.log.warn( tempResultDict )
358 main.wrong[ 'TsharkValueIncorrect' ] += 1
359 main.wrong[ 'totalWrong' ] += 1
360 checkTotalWrongNum()
YPZhang38fb1192016-08-11 11:03:38 -0700361 return
362 if not warmup:
chengchiyu08303a02016-09-08 17:40:26 -0700363 resultDict[ switchStatus ][ d ][ 'FA_A' ].append( FA_Atemp )
364 main.log.info( "{} FIN/ACK TO ACK {}:".format( d, FA_Atemp ) )
Devin Lim142b5342017-07-20 15:22:39 -0700365 for i in range( 1, main.Cluster.numCtrls + 1 ):
YPZhang38fb1192016-08-11 11:03:38 -0700366 A_Dtemp = 0
367 D_Gtemp = 0
368 E_Etemp = 0
chengchiyu08303a02016-09-08 17:40:26 -0700369 main.log.info( "================================================" )
YPZhang38fb1192016-08-11 11:03:38 -0700370 # get onos metrics timestamps
371 try:
Devin Lim142b5342017-07-20 15:22:39 -0700372 response = json.loads( main.Cluster.active( i - 1 ).CLI.topologyEventsMetrics() )
373 DeviceTime = getTimestampFromLog( i - 1, searchTerm=main.searchTerm[ switchStatus ] )
chengchiyu08303a02016-09-08 17:40:26 -0700374 main.log.info( "ONOS{} device Event timestamp: {}".format( i, DeviceTime ) )
375 GraphTime = int( response.get( "topologyGraphEventTimestamp" ).get( "value" ) )
376 main.log.info( "ONOS{} Graph Event timestamp: {}".format( i, GraphTime ) )
YPZhang38fb1192016-08-11 11:03:38 -0700377 except TypeError:
chengchiyu08303a02016-09-08 17:40:26 -0700378 main.log.warn( "TypeError" )
379 main.wrong[ 'TypeError' ] += 1
380 main.wrong[ 'totalWrong' ] += 1
381 checkTotalWrongNum()
YPZhang38fb1192016-08-11 11:03:38 -0700382 break
383 except ValueError:
chengchiyu08303a02016-09-08 17:40:26 -0700384 main.log.warn( "Error to decode Json object!" )
385 main.wrong[ 'decodeJasonError' ] += 1
386 main.wrong[ 'totalWrong' ] += 1
387 checkTotalWrongNum()
YPZhang38fb1192016-08-11 11:03:38 -0700388 break
chengchiyu08303a02016-09-08 17:40:26 -0700389 if DeviceTime != 0:
390 main.log.info( "================================================" )
391 try:
392 A_Dtemp = DeviceTime - tempResultDict[ 'ACK' ]
393 D_Gtemp = GraphTime - DeviceTime
394 E_Etemp = GraphTime - tempResultDict[ 'FA' ]
395 check = checkResult( A_Dtemp, D_Gtemp, E_Etemp )
396 if check == 1:
397 main.log.info( "ACK to device: {}".format( A_Dtemp ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700398 main.log.info( "Device to Graph: {}".format( D_Gtemp ) )
chengchiyu08303a02016-09-08 17:40:26 -0700399 main.log.info( "End to End: {}".format( E_Etemp ) )
400 main.log.info( "================================================" )
401 except KeyError:
402 main.log.warn( "Tshark Result was incorrect!" )
403 main.log.warn( tempResultDict )
404 main.wrong[ 'TsharkValueIncorrect' ] += 1
405 main.wrong[ 'totalWrong' ] += 1
406 checkTotalWrongNum()
407 return
408 except TypeError:
409 main.log.warn( "TypeError" )
410 main.wrong[ 'TypeError' ] += 1
411 main.wrong[ 'totalWrong' ] += 1
412 checkTotalWrongNum()
413 break
414 except ValueError:
415 main.log.warn( "Error to decode Json object!" )
416 main.wrong[ 'decodeJasonError' ] += 1
417 main.wrong[ 'totalWrong' ] += 1
418 checkTotalWrongNum()
419 break
420 if not warmup and check == 1:
421 resultDict[ switchStatus ][ 'node' + str( i ) ][ 'A_D' ].append( A_Dtemp )
422 resultDict[ switchStatus ][ 'node' + str( i ) ][ 'D_G' ].append( D_Gtemp )
423 resultDict[ switchStatus ][ 'node' + str( i ) ][ 'E_E' ].append( E_Etemp )
424
425 else:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700426 main.wrong[ 'checkResultIncorrect' ] += 1
427 main.wrong[ 'totalWrong' ] += 1
chengchiyu08303a02016-09-08 17:40:26 -0700428 checkTotalWrongNum()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700429 main.log.debug( "Skip this iteration due to the None Devicetime" )