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 |
| 7 | |
| 8 | def _init_( self ): |
| 9 | self.default = '' |
| 10 | |
| 11 | def checkLog( main, nodeId ): |
| 12 | try: |
| 13 | logNames = main.ONOSbench.listLog( main.onosIp[ nodeId ] ) |
| 14 | assert logNames is not None |
| 15 | if len( logNames ) >= 2: |
| 16 | return 2 |
| 17 | return 1 |
| 18 | except AssertionError: |
| 19 | main.log.error("There is no karaf log") |
| 20 | return -1 |
| 21 | |
| 22 | def bringBackTopology( main ): |
| 23 | main.log.info( "Bring back topology " ) |
You Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 24 | main.CLIs[ 0 ].pushTestIntents(main.ingress, main.egress, main.batchSize, |
| 25 | offset=1, options="-w", timeout=main.timeout) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 26 | main.CLIs[ 0 ].purgeWithdrawnIntents() |
| 27 | main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "deviceCount", value=0) |
| 28 | main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "enabled", value="false") |
| 29 | main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "deviceCount", value=main.deviceCount) |
| 30 | main.CLIs[ 0 ].setCfg( "org.onosproject.provider.nil.NullProviders", "enabled", value="true") |
You Wang | 0b9039d | 2017-01-12 16:51:29 -0800 | [diff] [blame] | 31 | main.CLIs[ 0 ].balanceMasters() |
| 32 | time.sleep( main.setMasterSleep ) |
| 33 | if len( main.ONOSip ) > 1: |
| 34 | main.CLIs[ 0 ].deviceRole(main.end1[ 'name' ], main.ONOSip[ 0 ]) |
| 35 | main.CLIs[ 0 ].deviceRole(main.end2[ 'name' ], main.ONOSip[ 0 ]) |
| 36 | time.sleep( main.setMasterSleep ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 37 | |
| 38 | def getValues( main ): |
| 39 | ''' |
| 40 | Calculated the wanted values for intentRerouteTest |
| 41 | |
| 42 | 1. Get the first "last topology timestamp" from karaf.log in different node |
| 43 | 2. Get the first "first intent installed timestamp" from karaf log in different node |
| 44 | 3. Get the last "last intent installed timestamp" from karaf log in different node |
| 45 | |
| 46 | Return: |
| 47 | last_topology_to_first_installed: The time from the last topology to the first intent installed |
| 48 | first_installed_to_last_installed: Time time from the first topology to the last intent installed |
| 49 | totalTime: The time from the last topology to the last intent installed |
| 50 | |
| 51 | ''' |
| 52 | lastTopologyTimestamp = compareTimestamp( main, main.searchTerm[ "TopologyTime" ], "creationTime=", ",", 'last',func='min' ) |
| 53 | firstIntentInstalledTimestamp = compareTimestamp( main, main.searchTerm[ "InstallTime" ], "time = ", " ", 'first',func='min' ) |
| 54 | lastIntentInstalledTimestamp = compareTimestamp( main, main.searchTerm[ "InstallTime" ], "time = ", " ", 'last',func='max' ) |
| 55 | |
| 56 | if lastTopologyTimestamp == -1 or firstIntentInstalledTimestamp == -1 or lastIntentInstalledTimestamp == -1: |
| 57 | main.log.warn( "Can't get timestamp from karaf log! " ) |
| 58 | bringBackTopology( main ) |
| 59 | return -1, -1, -1 |
| 60 | |
| 61 | #calculate values |
| 62 | lastTopologyToFirstInstalled = firstIntentInstalledTimestamp - lastTopologyTimestamp |
| 63 | if lastTopologyToFirstInstalled < 0: |
| 64 | main.record = main.record + 1 |
| 65 | |
| 66 | firstInstalledToLastInstalled = lastIntentInstalledTimestamp - firstIntentInstalledTimestamp |
| 67 | totalTime = lastIntentInstalledTimestamp - lastTopologyTimestamp |
| 68 | |
| 69 | if main.validRun >= main.warmUp and main.verify: |
| 70 | main.log.info( "Last topology time stamp: {0:f}".format( lastTopologyTimestamp )) |
| 71 | main.log.info( "First installed time stamp: {0:f}".format( firstIntentInstalledTimestamp )) |
| 72 | main.log.info( "Last installed time stamp: {0:f}".format( lastIntentInstalledTimestamp )) |
| 73 | main.log.info( "Last topology to first installed latency:{0:f}".format( lastTopologyToFirstInstalled )) |
| 74 | main.log.info( "First installed to last installed latency:{0:f}".format( firstInstalledToLastInstalled )) |
| 75 | main.log.info( "Overall latency:{0:f}".format( totalTime )) |
| 76 | main.LatencyList.append( totalTime ) |
| 77 | main.LatencyListTopoToFirstInstalled.append( lastTopologyToFirstInstalled ) |
| 78 | main.LatencyListFirstInstalledToLastInstalled.append( firstInstalledToLastInstalled ) |
| 79 | return lastTopologyToFirstInstalled, firstInstalledToLastInstalled, totalTime |
| 80 | |
| 81 | def compareTimestamp( main, compareTerm, splitTerm_before, splitTerm_after, mode, func='max' ): |
| 82 | ''' |
| 83 | Compare all the timestamps of compareTerm from different node. |
| 84 | |
| 85 | func: |
| 86 | max: Compare which one is the biggest and retun it |
| 87 | min: Compare which one is the smallest and return it |
| 88 | |
| 89 | return: |
| 90 | This function will return the biggest or smallest timestamps of the compareTerm. |
| 91 | |
| 92 | ''' |
| 93 | compareTermList = [] |
| 94 | for i in range( main.numCtrls ): |
| 95 | timestamp = main.CLIs[ i ].getTimeStampFromLog( mode, compareTerm, splitTerm_before, splitTerm_after, startLine=main.totalLines[ i ], logNum=checkLog( main, i ) ) |
| 96 | compareTermList.append( timestamp ) |
| 97 | main.log.info("-----------------------------------------------") |
| 98 | for i in range( main.numCtrls ): |
| 99 | main.log.info( "ONOS Node {} {} {} time stamp: {}".format((i+1), mode, compareTerm, compareTermList[ i ])) |
| 100 | x = min( compareTermList ) |
| 101 | main.log.info("-----------------------------------------------") |
| 102 | if x == -1: |
| 103 | main.log.warn( "Can't compare timestamps" ) |
| 104 | return -1 |
| 105 | else: |
| 106 | if func == 'max': |
| 107 | return max( compareTermList ) |
| 108 | if func == 'min': |
| 109 | return min( compareTermList ) |