blob: fc18cb6fa033ef8c685d77d901386206484d43e9 [file] [log] [blame]
Chiyu Chengec63bde2016-11-17 18:11:36 -08001'''
2The functions for intentRerouteLat
3
4'''
5import numpy
6import time
7
8def _init_( self ):
9 self.default = ''
10
11def 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
22def bringBackTopology( main ):
23 main.log.info( "Bring back topology " )
24 main.CLIs[ 0 ].removeAllIntents(purge=True, sync=True, timeout=main.timeout)
25 time.sleep( 1 )
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")
31
32def getValues( main ):
33 '''
34 Calculated the wanted values for intentRerouteTest
35
36 1. Get the first "last topology timestamp" from karaf.log in different node
37 2. Get the first "first intent installed timestamp" from karaf log in different node
38 3. Get the last "last intent installed timestamp" from karaf log in different node
39
40 Return:
41 last_topology_to_first_installed: The time from the last topology to the first intent installed
42 first_installed_to_last_installed: Time time from the first topology to the last intent installed
43 totalTime: The time from the last topology to the last intent installed
44
45 '''
46 lastTopologyTimestamp = compareTimestamp( main, main.searchTerm[ "TopologyTime" ], "creationTime=", ",", 'last',func='min' )
47 firstIntentInstalledTimestamp = compareTimestamp( main, main.searchTerm[ "InstallTime" ], "time = ", " ", 'first',func='min' )
48 lastIntentInstalledTimestamp = compareTimestamp( main, main.searchTerm[ "InstallTime" ], "time = ", " ", 'last',func='max' )
49
50 if lastTopologyTimestamp == -1 or firstIntentInstalledTimestamp == -1 or lastIntentInstalledTimestamp == -1:
51 main.log.warn( "Can't get timestamp from karaf log! " )
52 bringBackTopology( main )
53 return -1, -1, -1
54
55 #calculate values
56 lastTopologyToFirstInstalled = firstIntentInstalledTimestamp - lastTopologyTimestamp
57 if lastTopologyToFirstInstalled < 0:
58 main.record = main.record + 1
59
60 firstInstalledToLastInstalled = lastIntentInstalledTimestamp - firstIntentInstalledTimestamp
61 totalTime = lastIntentInstalledTimestamp - lastTopologyTimestamp
62
63 if main.validRun >= main.warmUp and main.verify:
64 main.log.info( "Last topology time stamp: {0:f}".format( lastTopologyTimestamp ))
65 main.log.info( "First installed time stamp: {0:f}".format( firstIntentInstalledTimestamp ))
66 main.log.info( "Last installed time stamp: {0:f}".format( lastIntentInstalledTimestamp ))
67 main.log.info( "Last topology to first installed latency:{0:f}".format( lastTopologyToFirstInstalled ))
68 main.log.info( "First installed to last installed latency:{0:f}".format( firstInstalledToLastInstalled ))
69 main.log.info( "Overall latency:{0:f}".format( totalTime ))
70 main.LatencyList.append( totalTime )
71 main.LatencyListTopoToFirstInstalled.append( lastTopologyToFirstInstalled )
72 main.LatencyListFirstInstalledToLastInstalled.append( firstInstalledToLastInstalled )
73 return lastTopologyToFirstInstalled, firstInstalledToLastInstalled, totalTime
74
75def compareTimestamp( main, compareTerm, splitTerm_before, splitTerm_after, mode, func='max' ):
76 '''
77 Compare all the timestamps of compareTerm from different node.
78
79 func:
80 max: Compare which one is the biggest and retun it
81 min: Compare which one is the smallest and return it
82
83 return:
84 This function will return the biggest or smallest timestamps of the compareTerm.
85
86 '''
87 compareTermList = []
88 for i in range( main.numCtrls ):
89 timestamp = main.CLIs[ i ].getTimeStampFromLog( mode, compareTerm, splitTerm_before, splitTerm_after, startLine=main.totalLines[ i ], logNum=checkLog( main, i ) )
90 compareTermList.append( timestamp )
91 main.log.info("-----------------------------------------------")
92 for i in range( main.numCtrls ):
93 main.log.info( "ONOS Node {} {} {} time stamp: {}".format((i+1), mode, compareTerm, compareTermList[ i ]))
94 x = min( compareTermList )
95 main.log.info("-----------------------------------------------")
96 if x == -1:
97 main.log.warn( "Can't compare timestamps" )
98 return -1
99 else:
100 if func == 'max':
101 return max( compareTermList )
102 if func == 'min':
103 return min( compareTermList )