brian | b87e3b1 | 2014-01-12 22:12:14 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | ''' |
| 3 | Script that tests Flow Manager performance |
| 4 | Author: Brian O'Connor <bocon@onlab.us> |
| 5 | |
| 6 | ''' |
| 7 | |
| 8 | import csv |
| 9 | import os |
| 10 | import sys |
| 11 | from time import sleep, strftime |
| 12 | from subprocess import Popen, call, check_output, PIPE |
| 13 | from datetime import datetime |
| 14 | |
| 15 | try: |
| 16 | import pexpect |
| 17 | except: |
| 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 | |
| 23 | ONOS_HOME = '..' |
| 24 | ONOS_LOG = '%s/onos-logs/onos.%s.log' % ( ONOS_HOME, check_output( 'hostname').strip() ) |
| 25 | ONOS_LOG = '/tmp/onos-1.logs/onos.onos-vm.log' |
| 26 | print "ONOS Log File:", ONOS_LOG |
| 27 | |
| 28 | PORT = 's1-eth2' |
| 29 | N = 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 | |
| 35 | def 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 | |
| 57 | def outputResults(filename, results): |
| 58 | with open(filename, 'a') as csvfile: |
| 59 | writer = csv.writer(csvfile) |
| 60 | writer.writerow(results) |
| 61 | |
| 62 | def 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 | |
| 75 | if __name__ == '__main__': |
| 76 | n = N |
| 77 | runPerf(n) |
| 78 | |