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" ) |
| 27 | flowNum = summary.get( "flows" ) |
| 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" ) |
| 36 | main.log.warn( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 37 | # bring back topology |
| 38 | bringBackTopology( main ) |
| 39 | if main.validRun >= main.warmUp: |
| 40 | main.invalidRun += 1 |
| 41 | else: |
| 42 | main.validRun += 1 |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 43 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 44 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 45 | def bringBackTopology( main ): |
| 46 | main.log.info( "Bring back topology " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 47 | main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress, |
| 48 | main.egress, |
| 49 | main.batchSize, |
| 50 | offset=1, |
| 51 | options="-w", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 52 | timeout=main.timeout ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 53 | main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents() |
| 54 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 55 | "deviceCount", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 56 | value=0 ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 57 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 58 | "enabled", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 59 | value="false" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 60 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 61 | "deviceCount", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 62 | value=main.deviceCount ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 63 | main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, |
| 64 | "enabled", |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 65 | value="true" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 66 | main.Cluster.active( 0 ).CLI.balanceMasters() |
You Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 67 | time.sleep( main.setMasterSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 68 | if main.Cluster.numCtrls > 1: |
| 69 | main.Cluster.active( 0 ).CLI.deviceRole( main.end1[ 'name' ], |
| 70 | main.Cluster.active( 0 ).ipAddress ) |
| 71 | main.Cluster.active( 0 ).CLI.deviceRole( main.end2[ 'name' ], |
| 72 | main.Cluster.active( 0 ).ipAddress ) |
You Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 73 | time.sleep( main.setMasterSleep ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 74 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 75 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 76 | def getLogNum( main, nodeId ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 77 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 78 | Return the number of karaf log files |
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 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 81 | logNameList = main.ONOSbench.listLog( main.Cluster.active( nodeId ).ipAddress ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 82 | assert logNameList is not None |
| 83 | # FIXME: are two karaf logs enough to cover the events we want? |
| 84 | if len( logNameList ) >= 2: |
| 85 | return 2 |
| 86 | return 1 |
| 87 | except AssertionError: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 88 | main.log.error( "There is no karaf log" ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 89 | return -1 |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 90 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 91 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 92 | def getTopologyTimestamps( main ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 93 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 94 | Get timestamps for the last topology events on all cluster nodes |
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 | timestamps = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 97 | for i in range( main.Cluster.numCtrls ): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 98 | # Search for last topology event in karaf log |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 99 | lines = main.Cluster.active( i ).CLI.logSearch( mode='last', |
| 100 | searchTerm=main.searchTerm[ "TopologyTime" ], |
| 101 | startLine=main.startLine[ i ], |
| 102 | logNum=getLogNum( main, i ) ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 103 | if lines is None or len( lines ) != 1: |
| 104 | main.log.error( "Error when trying to get topology event timestamp" ) |
| 105 | return main.ERROR |
| 106 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 107 | timestampField = lines[ 0 ].split( "creationTime=" ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 108 | timestamp = timestampField[ 1 ].split( "," ) |
| 109 | timestamp = int( timestamp[ 0 ] ) |
| 110 | timestamps.append( timestamp ) |
| 111 | except KeyError: |
| 112 | main.log.error( "Error when trying to get intent key or timestamp" ) |
| 113 | return main.ERROR |
| 114 | return timestamps |
| 115 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 116 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 117 | def getIntentTimestamps( main ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 118 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 119 | Get timestamps for all intent keys on all cluster nodes |
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 | timestamps = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 122 | for i in range( main.Cluster.numCtrls ): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 123 | # Search for intent INSTALLED event in karaf log |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 124 | lines = main.Cluster.active( i ).CLI.logSearch( mode='all', |
| 125 | searchTerm=main.searchTerm[ "InstallTime" ], |
| 126 | startLine=main.startLine[ i ], |
| 127 | logNum=getLogNum( main, i ) ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 128 | if lines is None or len( lines ) == 0: |
| 129 | main.log.error( "Error when trying to get intent key or timestamp" ) |
| 130 | return main.ERROR |
| 131 | for line in lines: |
| 132 | try: |
| 133 | # Get intent key |
| 134 | keyField = line.split( "key=" ) |
| 135 | key = keyField[ 1 ].split( "," ) |
| 136 | key = key[ 0 ] |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 137 | if key not in timestamps.keys(): |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 138 | timestamps[ key ] = [] |
| 139 | # Get timestamp |
| 140 | timestampField = line.split( "time = " ) |
| 141 | timestamp = timestampField[ 1 ].split( " " ) |
| 142 | timestamp = int( timestamp[ 0 ] ) |
| 143 | timestamps[ key ].append( timestamp ) |
| 144 | except KeyError: |
| 145 | main.log.error( "Error when trying to get intent key or timestamp" ) |
| 146 | return main.ERROR |
| 147 | return timestamps |
| 148 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 149 | |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 150 | def calculateLatency( main, topologyTimestamps, intentTimestamps ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 151 | """ |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 152 | Calculate reroute latency values using timestamps |
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 | topologyTimestamp = numpy.min( topologyTimestamps ) |
| 155 | firstInstalledLatency = {} |
| 156 | lastInstalledLatency = {} |
| 157 | for key in intentTimestamps.keys(): |
| 158 | firstInstalledTimestamp = numpy.min( intentTimestamps[ key ] ) |
| 159 | lastInstalledTimestamp = numpy.max( intentTimestamps[ key ] ) |
| 160 | firstInstalledLatency[ key ] = firstInstalledTimestamp - topologyTimestamp |
| 161 | lastInstalledLatency[ key ] = lastInstalledTimestamp - topologyTimestamp |
| 162 | firstLocalLatnecy = numpy.min( firstInstalledLatency.values() ) |
| 163 | lastLocalLatnecy = numpy.max( firstInstalledLatency.values() ) |
| 164 | firstGlobalLatency = numpy.min( lastInstalledLatency.values() ) |
| 165 | lastGlobalLatnecy = numpy.max( lastInstalledLatency.values() ) |
| 166 | main.log.info( "firstLocalLatnecy: {}, lastLocalLatnecy: {}, firstGlobalLatency: {}, lastGlobalLatnecy: {}".format( firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy ) ) |
| 167 | return firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy |