blob: 3168f63d385c69bddcdc403bf6f203ff32c829ce [file] [log] [blame]
brianb87e3b12014-01-12 22:12:14 -08001#!/usr/bin/python
2'''
3 Script that tests Flow Manager performance
4 Author: Brian O'Connor <bocon@onlab.us>
5
6'''
7
8import csv
9import os
10import sys
11from time import sleep, strftime
12from subprocess import Popen, call, check_output, PIPE
13from datetime import datetime
14
15try:
16 import pexpect
17except:
18 # install pexpect if it cannot be found and re-import
19 print '* Installing Pexpect'
20 call( 'apt-get install -y python-pexpect', stdout=PIPE, shell=True )
21 import pexpect
22
23ONOS_HOME = '..'
24ONOS_LOG = '%s/onos-logs/onos.%s.log' % ( ONOS_HOME, check_output( 'hostname').strip() )
25ONOS_LOG = '/tmp/onos-1.logs/onos.onos-vm.log'
26print "ONOS Log File:", ONOS_LOG
27
28PORT = 's1-eth2'
29N = 100
30
31# ----------------- Running the test and output -------------------------
32
33# 17:43:37.206 [main] ERROR n.o.o.o.f.PerformanceMonitor - Performance Results: {a=0.001ms, b=0.0ms, c=0.0ms} with measurement overhead: 0.022 ms
34
35def test():
36 # Start tailing the onos log
37 tail = pexpect.spawn( "tail -0f %s" % ONOS_LOG )
38
39 # Take link down
40 call( 'ifconfig %s down' % PORT, shell=True )
41
42 # Wait for performance results in the log
43 tail.expect('Performance Results: \{([^\}]*)\} with measurement overhead: ([\d.]+) ms', timeout=6000)
44 s = tail.match.group(1)
45 overhead = float( tail.match.group(2) )
46 results = dict( re.findall(r'(\w[\w\s]*)=([\d.]+)', s) )
47
48 # Output results
49 print "* Results:", results, "Overhead:", overhead
50
51 # Bring port back up
52 call( 'ifconfig %s up' % PORT, shell=True )
53
54 tail.terminate()
55 return results
56
57def outputResults(filename, results):
58 with open(filename, 'a') as csvfile:
59 writer = csv.writer(csvfile)
60 writer.writerow(results)
61
62def runPerf(n):
63 filename = 'results-flowmanager-%s.csv' % strftime( '%Y%m%d-%H%M%S' )
64 print 'Starting experiments:'
65 start = datetime.now()
66 for i in range(n):
67 results = test()
68 outputResults(filename, results)
69 sys.stdout.write('.')
70 sys.stdout.flush()
71 sleep(5000) # sleep for 5 seconds between tests
72 totalTime = datetime.now() - start
73 print '\nExperiments complete in %s (h:m:s.s)' % totalTime
74
75if __name__ == '__main__':
76 n = N
77 runPerf(n)
78