blob: d91f09ee708aee739cfd7b2bfe499e921212cc4d [file] [log] [blame]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07001"""
Chiyu Chengec63bde2016-11-17 18:11:36 -08002The functions for intentRerouteLat
3
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07004"""
Chiyu Chengec63bde2016-11-17 18:11:36 -08005import numpy
6import time
You Wang6d301d42017-04-21 10:49:33 -07007import json
Chiyu Chengec63bde2016-11-17 18:11:36 -08008
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07009
Chiyu Chengec63bde2016-11-17 18:11:36 -080010def _init_( self ):
11 self.default = ''
12
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070013
You Wang6d301d42017-04-21 10:49:33 -070014def sanityCheck( main, linkNumExpected, flowNumExpected, intentNumExpected ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070015 """
You Wang6d301d42017-04-21 10:49:33 -070016 Sanity check on numbers of links, flows and intents in ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070017 """
You Wang6d301d42017-04-21 10:49:33 -070018 attemps = 0
19 main.verify = main.FALSE
20 linkNum = 0
21 flowNum = 0
22 intentNum = 0
23 while attemps <= main.verifyAttempts:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070024 time.sleep( main.verifySleep )
Devin Lim142b5342017-07-20 15:22:39 -070025 summary = json.loads( main.Cluster.active( 0 ).CLI.summary( timeout=main.timeout ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070026 linkNum = summary.get( "links" )
27 flowNum = summary.get( "flows" )
28 intentNum = summary.get( "intents" )
You Wang6d301d42017-04-21 10:49:33 -070029 if linkNum == linkNumExpected and flowNum == flowNumExpected and intentNum == intentNumExpected:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070030 main.log.info( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
You Wang6d301d42017-04-21 10:49:33 -070031 main.verify = main.TRUE
32 break
33 attemps += 1
34 if not main.verify:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070035 main.log.warn( "Links or flows or intents number not as expected" )
36 main.log.warn( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
You Wang6d301d42017-04-21 10:49:33 -070037 # bring back topology
38 bringBackTopology( main )
39 if main.validRun >= main.warmUp:
40 main.invalidRun += 1
41 else:
42 main.validRun += 1
Chiyu Chengec63bde2016-11-17 18:11:36 -080043
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070044
Chiyu Chengec63bde2016-11-17 18:11:36 -080045def bringBackTopology( main ):
46 main.log.info( "Bring back topology " )
Devin Lim142b5342017-07-20 15:22:39 -070047 main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
48 main.egress,
49 main.batchSize,
50 offset=1,
51 options="-w",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070052 timeout=main.timeout )
Devin Lim142b5342017-07-20 15:22:39 -070053 main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
54 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
55 "deviceCount",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070056 value=0 )
Devin Lim142b5342017-07-20 15:22:39 -070057 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
58 "enabled",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070059 value="false" )
Devin Lim142b5342017-07-20 15:22:39 -070060 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
61 "deviceCount",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062 value=main.deviceCount )
Devin Lim142b5342017-07-20 15:22:39 -070063 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
64 "enabled",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070065 value="true" )
Devin Lim142b5342017-07-20 15:22:39 -070066 main.Cluster.active( 0 ).CLI.balanceMasters()
You Wang0b9039d2017-01-12 16:51:29 -080067 time.sleep( main.setMasterSleep )
Devin Lim142b5342017-07-20 15:22:39 -070068 if main.Cluster.numCtrls > 1:
69 main.Cluster.active( 0 ).CLI.deviceRole( main.end1[ 'name' ],
70 main.Cluster.active( 0 ).ipAddress )
71 main.Cluster.active( 0 ).CLI.deviceRole( main.end2[ 'name' ],
72 main.Cluster.active( 0 ).ipAddress )
You Wang0b9039d2017-01-12 16:51:29 -080073 time.sleep( main.setMasterSleep )
Chiyu Chengec63bde2016-11-17 18:11:36 -080074
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070075
You Wang6d301d42017-04-21 10:49:33 -070076def getLogNum( main, nodeId ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070077 """
You Wang6d301d42017-04-21 10:49:33 -070078 Return the number of karaf log files
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070079 """
You Wang6d301d42017-04-21 10:49:33 -070080 try:
Devin Lim142b5342017-07-20 15:22:39 -070081 logNameList = main.ONOSbench.listLog( main.Cluster.active( nodeId ).ipAddress )
You Wang6d301d42017-04-21 10:49:33 -070082 assert logNameList is not None
83 # FIXME: are two karaf logs enough to cover the events we want?
84 if len( logNameList ) >= 2:
85 return 2
86 return 1
87 except AssertionError:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070088 main.log.error( "There is no karaf log" )
Chiyu Chengec63bde2016-11-17 18:11:36 -080089 return -1
You Wang6d301d42017-04-21 10:49:33 -070090
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070091
You Wang6d301d42017-04-21 10:49:33 -070092def getTopologyTimestamps( main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070093 """
You Wang6d301d42017-04-21 10:49:33 -070094 Get timestamps for the last topology events on all cluster nodes
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070095 """
You Wang6d301d42017-04-21 10:49:33 -070096 timestamps = []
Devin Lim142b5342017-07-20 15:22:39 -070097 for i in range( main.Cluster.numCtrls ):
You Wang6d301d42017-04-21 10:49:33 -070098 # Search for last topology event in karaf log
Devin Lim142b5342017-07-20 15:22:39 -070099 lines = main.Cluster.active( i ).CLI.logSearch( mode='last',
100 searchTerm=main.searchTerm[ "TopologyTime" ],
101 startLine=main.startLine[ i ],
102 logNum=getLogNum( main, i ) )
You Wang6d301d42017-04-21 10:49:33 -0700103 if lines is None or len( lines ) != 1:
104 main.log.error( "Error when trying to get topology event timestamp" )
105 return main.ERROR
106 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700107 timestampField = lines[ 0 ].split( "creationTime=" )
You Wang6d301d42017-04-21 10:49:33 -0700108 timestamp = timestampField[ 1 ].split( "," )
109 timestamp = int( timestamp[ 0 ] )
110 timestamps.append( timestamp )
111 except KeyError:
112 main.log.error( "Error when trying to get intent key or timestamp" )
113 return main.ERROR
114 return timestamps
115
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700116
You Wang6d301d42017-04-21 10:49:33 -0700117def getIntentTimestamps( main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700118 """
You Wang6d301d42017-04-21 10:49:33 -0700119 Get timestamps for all intent keys on all cluster nodes
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700120 """
You Wang6d301d42017-04-21 10:49:33 -0700121 timestamps = {}
Devin Lim142b5342017-07-20 15:22:39 -0700122 for i in range( main.Cluster.numCtrls ):
You Wang6d301d42017-04-21 10:49:33 -0700123 # Search for intent INSTALLED event in karaf log
Devin Lim142b5342017-07-20 15:22:39 -0700124 lines = main.Cluster.active( i ).CLI.logSearch( mode='all',
125 searchTerm=main.searchTerm[ "InstallTime" ],
126 startLine=main.startLine[ i ],
127 logNum=getLogNum( main, i ) )
You Wang6d301d42017-04-21 10:49:33 -0700128 if lines is None or len( lines ) == 0:
129 main.log.error( "Error when trying to get intent key or timestamp" )
130 return main.ERROR
131 for line in lines:
132 try:
133 # Get intent key
134 keyField = line.split( "key=" )
135 key = keyField[ 1 ].split( "," )
136 key = key[ 0 ]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700137 if key not in timestamps.keys():
You Wang6d301d42017-04-21 10:49:33 -0700138 timestamps[ key ] = []
139 # Get timestamp
140 timestampField = line.split( "time = " )
141 timestamp = timestampField[ 1 ].split( " " )
142 timestamp = int( timestamp[ 0 ] )
143 timestamps[ key ].append( timestamp )
144 except KeyError:
145 main.log.error( "Error when trying to get intent key or timestamp" )
146 return main.ERROR
147 return timestamps
148
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700149
You Wang6d301d42017-04-21 10:49:33 -0700150def calculateLatency( main, topologyTimestamps, intentTimestamps ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700151 """
You Wang6d301d42017-04-21 10:49:33 -0700152 Calculate reroute latency values using timestamps
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700153 """
You Wang6d301d42017-04-21 10:49:33 -0700154 topologyTimestamp = numpy.min( topologyTimestamps )
155 firstInstalledLatency = {}
156 lastInstalledLatency = {}
157 for key in intentTimestamps.keys():
158 firstInstalledTimestamp = numpy.min( intentTimestamps[ key ] )
159 lastInstalledTimestamp = numpy.max( intentTimestamps[ key ] )
160 firstInstalledLatency[ key ] = firstInstalledTimestamp - topologyTimestamp
161 lastInstalledLatency[ key ] = lastInstalledTimestamp - topologyTimestamp
162 firstLocalLatnecy = numpy.min( firstInstalledLatency.values() )
163 lastLocalLatnecy = numpy.max( firstInstalledLatency.values() )
164 firstGlobalLatency = numpy.min( lastInstalledLatency.values() )
165 lastGlobalLatnecy = numpy.max( lastInstalledLatency.values() )
166 main.log.info( "firstLocalLatnecy: {}, lastLocalLatnecy: {}, firstGlobalLatency: {}, lastGlobalLatnecy: {}".format( firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy ) )
167 return firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy