Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 1 | ''' |
| 2 | The functions for intentRerouteLat |
| 3 | |
| 4 | ''' |
| 5 | import numpy |
| 6 | import time |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 7 | import json |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 8 | |
| 9 | def _init_( self ): |
| 10 | self.default = '' |
| 11 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 12 | def 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 Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 23 | summary = json.loads( main.Cluster.active( 0 ).CLI.summary( timeout=main.timeout ) ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 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 Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 41 | |
| 42 | def bringBackTopology( main ): |
| 43 | main.log.info( "Bring back topology " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 44 | 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 Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 64 | time.sleep( main.setMasterSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 65 | 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 Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 70 | time.sleep( main.setMasterSleep ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 71 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 72 | def getLogNum( main, nodeId ): |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 73 | ''' |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 74 | Return the number of karaf log files |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 75 | ''' |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 76 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 77 | logNameList = main.ONOSbench.listLog( main.Cluster.active( nodeId ).ipAddress ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 78 | 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 Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 85 | return -1 |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 86 | |
| 87 | def getTopologyTimestamps( main ): |
| 88 | ''' |
| 89 | Get timestamps for the last topology events on all cluster nodes |
| 90 | ''' |
| 91 | timestamps = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 92 | for i in range( main.Cluster.numCtrls ): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 93 | # Search for last topology event in karaf log |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 94 | 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 Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 98 | 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 | |
| 111 | def getIntentTimestamps( main ): |
| 112 | ''' |
| 113 | Get timestamps for all intent keys on all cluster nodes |
| 114 | ''' |
| 115 | timestamps = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 116 | for i in range( main.Cluster.numCtrls ): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 117 | # Search for intent INSTALLED event in karaf log |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 118 | 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 Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 122 | 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 | |
| 143 | def 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 |