blob: 947917bec5073e8ac7c4eaf36653341e22cf4d3d [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" )
Devin Lime6fe3c42017-10-18 16:28:40 -070027 flowNum = main.Cluster.active( 0 ).CLI.getTotalFlowsNum( timeout=600, noExit=True )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070028 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" )
Devin Lime6fe3c42017-10-18 16:28:40 -070036 main.log.warn( "[Expected] links: {}, flows: {}, intents: {}".format( linkNumExpected, flowNumExpected, intentNumExpected ) )
37 main.log.warn( "[Actual] links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
You Wang6d301d42017-04-21 10:49:33 -070038 # bring back topology
39 bringBackTopology( main )
40 if main.validRun >= main.warmUp:
41 main.invalidRun += 1
42 else:
43 main.validRun += 1
Chiyu Chengec63bde2016-11-17 18:11:36 -080044
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070045
Chiyu Chengec63bde2016-11-17 18:11:36 -080046def bringBackTopology( main ):
47 main.log.info( "Bring back topology " )
Devin Lim142b5342017-07-20 15:22:39 -070048 main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
49 main.egress,
50 main.batchSize,
51 offset=1,
52 options="-w",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053 timeout=main.timeout )
Devin Lim142b5342017-07-20 15:22:39 -070054 main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
55 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
56 "deviceCount",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070057 value=0 )
Devin Lim142b5342017-07-20 15:22:39 -070058 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
59 "enabled",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070060 value="false" )
Devin Lime6fe3c42017-10-18 16:28:40 -070061 time.sleep( main.startUpSleep )
62 main.Cluster.active( 0 ).CLI.wipeout()
63 time.sleep( main.startUpSleep )
Devin Lim142b5342017-07-20 15:22:39 -070064 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
65 "deviceCount",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070066 value=main.deviceCount )
Devin Lim142b5342017-07-20 15:22:39 -070067 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
68 "enabled",
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070069 value="true" )
Devin Lim142b5342017-07-20 15:22:39 -070070 main.Cluster.active( 0 ).CLI.balanceMasters()
You Wang0b9039d2017-01-12 16:51:29 -080071 time.sleep( main.setMasterSleep )
Devin Lim142b5342017-07-20 15:22:39 -070072 if main.Cluster.numCtrls > 1:
73 main.Cluster.active( 0 ).CLI.deviceRole( main.end1[ 'name' ],
74 main.Cluster.active( 0 ).ipAddress )
75 main.Cluster.active( 0 ).CLI.deviceRole( main.end2[ 'name' ],
76 main.Cluster.active( 0 ).ipAddress )
You Wang0b9039d2017-01-12 16:51:29 -080077 time.sleep( main.setMasterSleep )
Chiyu Chengec63bde2016-11-17 18:11:36 -080078
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070079
You Wang6d301d42017-04-21 10:49:33 -070080def getLogNum( main, nodeId ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070081 """
You Wang6d301d42017-04-21 10:49:33 -070082 Return the number of karaf log files
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070083 """
You Wang6d301d42017-04-21 10:49:33 -070084 try:
Devin Lim142b5342017-07-20 15:22:39 -070085 logNameList = main.ONOSbench.listLog( main.Cluster.active( nodeId ).ipAddress )
You Wang6d301d42017-04-21 10:49:33 -070086 assert logNameList is not None
87 # FIXME: are two karaf logs enough to cover the events we want?
88 if len( logNameList ) >= 2:
89 return 2
90 return 1
91 except AssertionError:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070092 main.log.error( "There is no karaf log" )
Chiyu Chengec63bde2016-11-17 18:11:36 -080093 return -1
You Wang6d301d42017-04-21 10:49:33 -070094
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070095
You Wang6d301d42017-04-21 10:49:33 -070096def getTopologyTimestamps( main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070097 """
You Wang6d301d42017-04-21 10:49:33 -070098 Get timestamps for the last topology events on all cluster nodes
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070099 """
You Wang6d301d42017-04-21 10:49:33 -0700100 timestamps = []
Devin Lim142b5342017-07-20 15:22:39 -0700101 for i in range( main.Cluster.numCtrls ):
You Wang6d301d42017-04-21 10:49:33 -0700102 # Search for last topology event in karaf log
Devin Lim142b5342017-07-20 15:22:39 -0700103 lines = main.Cluster.active( i ).CLI.logSearch( mode='last',
104 searchTerm=main.searchTerm[ "TopologyTime" ],
105 startLine=main.startLine[ i ],
106 logNum=getLogNum( main, i ) )
You Wang6d301d42017-04-21 10:49:33 -0700107 if lines is None or len( lines ) != 1:
108 main.log.error( "Error when trying to get topology event timestamp" )
109 return main.ERROR
110 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700111 timestampField = lines[ 0 ].split( "creationTime=" )
You Wang6d301d42017-04-21 10:49:33 -0700112 timestamp = timestampField[ 1 ].split( "," )
113 timestamp = int( timestamp[ 0 ] )
114 timestamps.append( timestamp )
115 except KeyError:
116 main.log.error( "Error when trying to get intent key or timestamp" )
117 return main.ERROR
118 return timestamps
119
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700120
You Wang6d301d42017-04-21 10:49:33 -0700121def getIntentTimestamps( main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700122 """
You Wang6d301d42017-04-21 10:49:33 -0700123 Get timestamps for all intent keys on all cluster nodes
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700124 """
You Wang6d301d42017-04-21 10:49:33 -0700125 timestamps = {}
Devin Lim142b5342017-07-20 15:22:39 -0700126 for i in range( main.Cluster.numCtrls ):
You Wang6d301d42017-04-21 10:49:33 -0700127 # Search for intent INSTALLED event in karaf log
Devin Lim142b5342017-07-20 15:22:39 -0700128 lines = main.Cluster.active( i ).CLI.logSearch( mode='all',
129 searchTerm=main.searchTerm[ "InstallTime" ],
130 startLine=main.startLine[ i ],
131 logNum=getLogNum( main, i ) )
You Wang6d301d42017-04-21 10:49:33 -0700132 if lines is None or len( lines ) == 0:
133 main.log.error( "Error when trying to get intent key or timestamp" )
134 return main.ERROR
135 for line in lines:
136 try:
137 # Get intent key
138 keyField = line.split( "key=" )
139 key = keyField[ 1 ].split( "," )
140 key = key[ 0 ]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700141 if key not in timestamps.keys():
You Wang6d301d42017-04-21 10:49:33 -0700142 timestamps[ key ] = []
143 # Get timestamp
144 timestampField = line.split( "time = " )
145 timestamp = timestampField[ 1 ].split( " " )
146 timestamp = int( timestamp[ 0 ] )
147 timestamps[ key ].append( timestamp )
148 except KeyError:
149 main.log.error( "Error when trying to get intent key or timestamp" )
150 return main.ERROR
151 return timestamps
152
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700153
You Wang6d301d42017-04-21 10:49:33 -0700154def calculateLatency( main, topologyTimestamps, intentTimestamps ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700155 """
You Wang6d301d42017-04-21 10:49:33 -0700156 Calculate reroute latency values using timestamps
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700157 """
You Wang6d301d42017-04-21 10:49:33 -0700158 topologyTimestamp = numpy.min( topologyTimestamps )
159 firstInstalledLatency = {}
160 lastInstalledLatency = {}
161 for key in intentTimestamps.keys():
162 firstInstalledTimestamp = numpy.min( intentTimestamps[ key ] )
163 lastInstalledTimestamp = numpy.max( intentTimestamps[ key ] )
164 firstInstalledLatency[ key ] = firstInstalledTimestamp - topologyTimestamp
165 lastInstalledLatency[ key ] = lastInstalledTimestamp - topologyTimestamp
166 firstLocalLatnecy = numpy.min( firstInstalledLatency.values() )
167 lastLocalLatnecy = numpy.max( firstInstalledLatency.values() )
168 firstGlobalLatency = numpy.min( lastInstalledLatency.values() )
169 lastGlobalLatnecy = numpy.max( lastInstalledLatency.values() )
170 main.log.info( "firstLocalLatnecy: {}, lastLocalLatnecy: {}, firstGlobalLatency: {}, lastGlobalLatnecy: {}".format( firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy ) )
171 return firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy