blob: 24cf32be4b0de87325f37029b8be94ac57928ea9 [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 " )
You Wang0b9039d2017-01-12 16:51:29 -080024 main.CLIs[ 0 ].pushTestIntents(main.ingress, main.egress, main.batchSize,
25 offset=1, options="-w", timeout=main.timeout)
Chiyu Chengec63bde2016-11-17 18:11:36 -080026 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 Wang0b9039d2017-01-12 16:51:29 -080031 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 Chengec63bde2016-11-17 18:11:36 -080037
38def 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
81def 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 )