blob: d9d0271bba642c83b620bb4c226c4bad1d2503d1 [file] [log] [blame]
Chiyu Chengec63bde2016-11-17 18:11:36 -08001'''
2The functions for intentRerouteLat
3
4'''
5import numpy
6import time
You Wang6d301d42017-04-21 10:49:33 -07007import json
Chiyu Chengec63bde2016-11-17 18:11:36 -08008
9def _init_( self ):
10 self.default = ''
11
You Wang6d301d42017-04-21 10:49:33 -070012def sanityCheck( main, linkNumExpected, flowNumExpected, intentNumExpected ):
13 '''
14 Sanity check on numbers of links, flows and intents in ONOS
15 '''
16 attemps = 0
17 main.verify = main.FALSE
18 linkNum = 0
19 flowNum = 0
20 intentNum = 0
21 while attemps <= main.verifyAttempts:
22 time.sleep(main.verifySleep)
Devin Lim142b5342017-07-20 15:22:39 -070023 summary = json.loads( main.Cluster.active( 0 ).CLI.summary( timeout=main.timeout ) )
You Wang6d301d42017-04-21 10:49:33 -070024 linkNum = summary.get("links")
25 flowNum = summary.get("flows")
26 intentNum = summary.get("intents")
27 if linkNum == linkNumExpected and flowNum == flowNumExpected and intentNum == intentNumExpected:
28 main.log.info("links: {}, flows: {}, intents: {}".format(linkNum, flowNum, intentNum))
29 main.verify = main.TRUE
30 break
31 attemps += 1
32 if not main.verify:
33 main.log.warn("Links or flows or intents number not as expected")
34 main.log.warn("links: {}, flows: {}, intents: {}".format(linkNum, flowNum, intentNum))
35 # bring back topology
36 bringBackTopology( main )
37 if main.validRun >= main.warmUp:
38 main.invalidRun += 1
39 else:
40 main.validRun += 1
Chiyu Chengec63bde2016-11-17 18:11:36 -080041
42def bringBackTopology( main ):
43 main.log.info( "Bring back topology " )
Devin Lim142b5342017-07-20 15:22:39 -070044 main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
45 main.egress,
46 main.batchSize,
47 offset=1,
48 options="-w",
49 timeout=main.timeout)
50 main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
51 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
52 "deviceCount",
53 value=0)
54 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
55 "enabled",
56 value="false")
57 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
58 "deviceCount",
59 value=main.deviceCount)
60 main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
61 "enabled",
62 value="true")
63 main.Cluster.active( 0 ).CLI.balanceMasters()
You Wang0b9039d2017-01-12 16:51:29 -080064 time.sleep( main.setMasterSleep )
Devin Lim142b5342017-07-20 15:22:39 -070065 if main.Cluster.numCtrls > 1:
66 main.Cluster.active( 0 ).CLI.deviceRole( main.end1[ 'name' ],
67 main.Cluster.active( 0 ).ipAddress )
68 main.Cluster.active( 0 ).CLI.deviceRole( main.end2[ 'name' ],
69 main.Cluster.active( 0 ).ipAddress )
You Wang0b9039d2017-01-12 16:51:29 -080070 time.sleep( main.setMasterSleep )
Chiyu Chengec63bde2016-11-17 18:11:36 -080071
You Wang6d301d42017-04-21 10:49:33 -070072def getLogNum( main, nodeId ):
Chiyu Chengec63bde2016-11-17 18:11:36 -080073 '''
You Wang6d301d42017-04-21 10:49:33 -070074 Return the number of karaf log files
Chiyu Chengec63bde2016-11-17 18:11:36 -080075 '''
You Wang6d301d42017-04-21 10:49:33 -070076 try:
Devin Lim142b5342017-07-20 15:22:39 -070077 logNameList = main.ONOSbench.listLog( main.Cluster.active( nodeId ).ipAddress )
You Wang6d301d42017-04-21 10:49:33 -070078 assert logNameList is not None
79 # FIXME: are two karaf logs enough to cover the events we want?
80 if len( logNameList ) >= 2:
81 return 2
82 return 1
83 except AssertionError:
84 main.log.error("There is no karaf log")
Chiyu Chengec63bde2016-11-17 18:11:36 -080085 return -1
You Wang6d301d42017-04-21 10:49:33 -070086
87def getTopologyTimestamps( main ):
88 '''
89 Get timestamps for the last topology events on all cluster nodes
90 '''
91 timestamps = []
Devin Lim142b5342017-07-20 15:22:39 -070092 for i in range( main.Cluster.numCtrls ):
You Wang6d301d42017-04-21 10:49:33 -070093 # Search for last topology event in karaf log
Devin Lim142b5342017-07-20 15:22:39 -070094 lines = main.Cluster.active( i ).CLI.logSearch( mode='last',
95 searchTerm=main.searchTerm[ "TopologyTime" ],
96 startLine=main.startLine[ i ],
97 logNum=getLogNum( main, i ) )
You Wang6d301d42017-04-21 10:49:33 -070098 if lines is None or len( lines ) != 1:
99 main.log.error( "Error when trying to get topology event timestamp" )
100 return main.ERROR
101 try:
102 timestampField = lines[0].split( "creationTime=" )
103 timestamp = timestampField[ 1 ].split( "," )
104 timestamp = int( timestamp[ 0 ] )
105 timestamps.append( timestamp )
106 except KeyError:
107 main.log.error( "Error when trying to get intent key or timestamp" )
108 return main.ERROR
109 return timestamps
110
111def getIntentTimestamps( main ):
112 '''
113 Get timestamps for all intent keys on all cluster nodes
114 '''
115 timestamps = {}
Devin Lim142b5342017-07-20 15:22:39 -0700116 for i in range( main.Cluster.numCtrls ):
You Wang6d301d42017-04-21 10:49:33 -0700117 # Search for intent INSTALLED event in karaf log
Devin Lim142b5342017-07-20 15:22:39 -0700118 lines = main.Cluster.active( i ).CLI.logSearch( mode='all',
119 searchTerm=main.searchTerm[ "InstallTime" ],
120 startLine=main.startLine[ i ],
121 logNum=getLogNum( main, i ) )
You Wang6d301d42017-04-21 10:49:33 -0700122 if lines is None or len( lines ) == 0:
123 main.log.error( "Error when trying to get intent key or timestamp" )
124 return main.ERROR
125 for line in lines:
126 try:
127 # Get intent key
128 keyField = line.split( "key=" )
129 key = keyField[ 1 ].split( "," )
130 key = key[ 0 ]
131 if not key in timestamps.keys():
132 timestamps[ key ] = []
133 # Get timestamp
134 timestampField = line.split( "time = " )
135 timestamp = timestampField[ 1 ].split( " " )
136 timestamp = int( timestamp[ 0 ] )
137 timestamps[ key ].append( timestamp )
138 except KeyError:
139 main.log.error( "Error when trying to get intent key or timestamp" )
140 return main.ERROR
141 return timestamps
142
143def calculateLatency( main, topologyTimestamps, intentTimestamps ):
144 '''
145 Calculate reroute latency values using timestamps
146 '''
147 topologyTimestamp = numpy.min( topologyTimestamps )
148 firstInstalledLatency = {}
149 lastInstalledLatency = {}
150 for key in intentTimestamps.keys():
151 firstInstalledTimestamp = numpy.min( intentTimestamps[ key ] )
152 lastInstalledTimestamp = numpy.max( intentTimestamps[ key ] )
153 firstInstalledLatency[ key ] = firstInstalledTimestamp - topologyTimestamp
154 lastInstalledLatency[ key ] = lastInstalledTimestamp - topologyTimestamp
155 firstLocalLatnecy = numpy.min( firstInstalledLatency.values() )
156 lastLocalLatnecy = numpy.max( firstInstalledLatency.values() )
157 firstGlobalLatency = numpy.min( lastInstalledLatency.values() )
158 lastGlobalLatnecy = numpy.max( lastInstalledLatency.values() )
159 main.log.info( "firstLocalLatnecy: {}, lastLocalLatnecy: {}, firstGlobalLatency: {}, lastGlobalLatnecy: {}".format( firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy ) )
160 return firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy