Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1 | """ |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 2 | The functions for intentRerouteLat |
| 3 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 4 | """ |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 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 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 9 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 10 | def _init_( self ): |
| 11 | self.default = '' |
| 12 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 13 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 14 | def sanityCheck( main, linkNumExpected, flowNumExpected, intentNumExpected ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 15 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 16 | Sanity check on numbers of links, flows and intents in ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 17 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 18 | attemps = 0 |
| 19 | main.verify = main.FALSE |
| 20 | linkNum = 0 |
| 21 | flowNum = 0 |
| 22 | intentNum = 0 |
| 23 | while attemps <= main.verifyAttempts: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 24 | time.sleep( main.verifySleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 25 | summary = json.loads( main.Cluster.active( 0 ).CLI.summary( timeout=main.timeout ) ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 26 | linkNum = summary.get( "links" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 27 | flowNum = main.Cluster.active( 0 ).CLI.getTotalFlowsNum( timeout=600, noExit=True ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 28 | intentNum = summary.get( "intents" ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 29 | if linkNum == linkNumExpected and flowNum == flowNumExpected and intentNum == intentNumExpected: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 30 | main.log.info( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 31 | main.verify = main.TRUE |
| 32 | break |
| 33 | attemps += 1 |
| 34 | if not main.verify: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 35 | main.log.warn( "Links or flows or intents number not as expected" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 36 | main.log.warn( "[Expected] links: {}, flows: {}, intents: {}".format( linkNumExpected, flowNumExpected, intentNumExpected ) ) |
| 37 | main.log.warn( "[Actual] links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 38 | # bring back topology |
| 39 | bringBackTopology( main ) |
| 40 | if main.validRun >= main.warmUp: |
| 41 | main.invalidRun += 1 |
| 42 | else: |
| 43 | main.validRun += 1 |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 44 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 45 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 46 | def bringBackTopology( main ): |
| 47 | main.log.info( "Bring back topology " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 48 | main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress, |
| 49 | main.egress, |
| 50 | main.batchSize, |
| 51 | offset=1, |
| 52 | options="-w", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 53 | timeout=main.timeout ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 54 | main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents() |
| 55 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 56 | "deviceCount", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 57 | value=0 ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 58 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 59 | "enabled", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 60 | value="false" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 61 | time.sleep( main.startUpSleep ) |
| 62 | main.Cluster.active( 0 ).CLI.wipeout() |
| 63 | time.sleep( main.startUpSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 64 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 65 | "deviceCount", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 66 | value=main.deviceCount ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 67 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 68 | "enabled", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 69 | value="true" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 70 | main.Cluster.active( 0 ).CLI.balanceMasters() |
You Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 71 | time.sleep( main.setMasterSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 72 | 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 Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 77 | time.sleep( main.setMasterSleep ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 78 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 79 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 80 | def getLogNum( main, nodeId ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 81 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 82 | Return the number of karaf log files |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 83 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 84 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 85 | logNameList = main.ONOSbench.listLog( main.Cluster.active( nodeId ).ipAddress ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 86 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 92 | main.log.error( "There is no karaf log" ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 93 | return -1 |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 94 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 95 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 96 | def getTopologyTimestamps( main ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 97 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 98 | Get timestamps for the last topology events on all cluster nodes |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 99 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 100 | timestamps = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 101 | for i in range( main.Cluster.numCtrls ): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 102 | # Search for last topology event in karaf log |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 103 | 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 Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 107 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 111 | timestampField = lines[ 0 ].split( "creationTime=" ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 112 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 120 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 121 | def getIntentTimestamps( main ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 122 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 123 | Get timestamps for all intent keys on all cluster nodes |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 124 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 125 | timestamps = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 126 | for i in range( main.Cluster.numCtrls ): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 127 | # Search for intent INSTALLED event in karaf log |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 128 | 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 Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 132 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 141 | if key not in timestamps.keys(): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 142 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 153 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 154 | def calculateLatency( main, topologyTimestamps, intentTimestamps ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 155 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 156 | Calculate reroute latency values using timestamps |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 157 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 158 | 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 |