blob: 1f830ad338e7746ffff6e44a8a8c5c14f3dd1689 [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)
23 summary = json.loads( main.CLIs[0].summary( timeout=main.timeout ) )
24 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 " )
You Wang0b9039d2017-01-12 16:51:29 -080044 main.CLIs[ 0 ].pushTestIntents(main.ingress, main.egress, main.batchSize,
45 offset=1, options="-w", timeout=main.timeout)
Chiyu Chengec63bde2016-11-17 18:11:36 -080046 main.CLIs[ 0 ].purgeWithdrawnIntents()
47 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "deviceCount", value=0)
48 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "enabled", value="false")
49 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "deviceCount", value=main.deviceCount)
50 main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "enabled", value="true")
You Wang0b9039d2017-01-12 16:51:29 -080051 main.CLIs[ 0 ].balanceMasters()
52 time.sleep( main.setMasterSleep )
53 if len( main.ONOSip ) > 1:
54 main.CLIs[ 0 ].deviceRole(main.end1[ 'name' ], main.ONOSip[ 0 ])
55 main.CLIs[ 0 ].deviceRole(main.end2[ 'name' ], main.ONOSip[ 0 ])
56 time.sleep( main.setMasterSleep )
Chiyu Chengec63bde2016-11-17 18:11:36 -080057
You Wang6d301d42017-04-21 10:49:33 -070058def getLogNum( main, nodeId ):
Chiyu Chengec63bde2016-11-17 18:11:36 -080059 '''
You Wang6d301d42017-04-21 10:49:33 -070060 Return the number of karaf log files
Chiyu Chengec63bde2016-11-17 18:11:36 -080061 '''
You Wang6d301d42017-04-21 10:49:33 -070062 try:
63 logNameList = main.ONOSbench.listLog( main.onosIp[ nodeId ] )
64 assert logNameList is not None
65 # FIXME: are two karaf logs enough to cover the events we want?
66 if len( logNameList ) >= 2:
67 return 2
68 return 1
69 except AssertionError:
70 main.log.error("There is no karaf log")
Chiyu Chengec63bde2016-11-17 18:11:36 -080071 return -1
You Wang6d301d42017-04-21 10:49:33 -070072
73def getTopologyTimestamps( main ):
74 '''
75 Get timestamps for the last topology events on all cluster nodes
76 '''
77 timestamps = []
78 for i in range( main.numCtrls ):
79 # Search for last topology event in karaf log
80 lines = main.CLIs[ i ].logSearch( mode='last', searchTerm=main.searchTerm[ "TopologyTime" ], startLine=main.startLine[ i ], logNum=getLogNum( main, i ) )
81 if lines is None or len( lines ) != 1:
82 main.log.error( "Error when trying to get topology event timestamp" )
83 return main.ERROR
84 try:
85 timestampField = lines[0].split( "creationTime=" )
86 timestamp = timestampField[ 1 ].split( "," )
87 timestamp = int( timestamp[ 0 ] )
88 timestamps.append( timestamp )
89 except KeyError:
90 main.log.error( "Error when trying to get intent key or timestamp" )
91 return main.ERROR
92 return timestamps
93
94def getIntentTimestamps( main ):
95 '''
96 Get timestamps for all intent keys on all cluster nodes
97 '''
98 timestamps = {}
99 for i in range( main.numCtrls ):
100 # Search for intent INSTALLED event in karaf log
101 lines = main.CLIs[ i ].logSearch( mode='all', searchTerm=main.searchTerm[ "InstallTime" ], startLine=main.startLine[ i ], logNum=getLogNum( main, i ) )
102 if lines is None or len( lines ) == 0:
103 main.log.error( "Error when trying to get intent key or timestamp" )
104 return main.ERROR
105 for line in lines:
106 try:
107 # Get intent key
108 keyField = line.split( "key=" )
109 key = keyField[ 1 ].split( "," )
110 key = key[ 0 ]
111 if not key in timestamps.keys():
112 timestamps[ key ] = []
113 # Get timestamp
114 timestampField = line.split( "time = " )
115 timestamp = timestampField[ 1 ].split( " " )
116 timestamp = int( timestamp[ 0 ] )
117 timestamps[ key ].append( timestamp )
118 except KeyError:
119 main.log.error( "Error when trying to get intent key or timestamp" )
120 return main.ERROR
121 return timestamps
122
123def calculateLatency( main, topologyTimestamps, intentTimestamps ):
124 '''
125 Calculate reroute latency values using timestamps
126 '''
127 topologyTimestamp = numpy.min( topologyTimestamps )
128 firstInstalledLatency = {}
129 lastInstalledLatency = {}
130 for key in intentTimestamps.keys():
131 firstInstalledTimestamp = numpy.min( intentTimestamps[ key ] )
132 lastInstalledTimestamp = numpy.max( intentTimestamps[ key ] )
133 firstInstalledLatency[ key ] = firstInstalledTimestamp - topologyTimestamp
134 lastInstalledLatency[ key ] = lastInstalledTimestamp - topologyTimestamp
135 firstLocalLatnecy = numpy.min( firstInstalledLatency.values() )
136 lastLocalLatnecy = numpy.max( firstInstalledLatency.values() )
137 firstGlobalLatency = numpy.min( lastInstalledLatency.values() )
138 lastGlobalLatnecy = numpy.max( lastInstalledLatency.values() )
139 main.log.info( "firstLocalLatnecy: {}, lastLocalLatnecy: {}, firstGlobalLatency: {}, lastGlobalLatnecy: {}".format( firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy ) )
140 return firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy