blob: 61a204b692b739029f9d76bcecbd16df54787c08 [file] [log] [blame]
Brian O'Connor477ddbe2013-12-09 18:35:18 -08001#!/usr/bin/python
2'''
3 Script that tests Flow Synchronizer performance
4 Author: Brian O'Connor <bocon@onlab.us>
5
6 Usage:
7 1. Ensure that ONOS is running
Brian O'Connorcd5a8bc2013-12-09 21:29:31 -08008 2. sudo ./flow-sync-perf.sh <list of tests>
9 e.g. sudo ./flow-sync-perf.sh 1 10 100 1000
10 or to run the default tests:
11 sudo ./flow-sync-perf.sh
12 3. Results are CSV files in a date stamped directory
Brian O'Connor477ddbe2013-12-09 18:35:18 -080013'''
14
15import csv
16import os
Brian O'Connorb405d082013-12-09 19:45:58 -080017import sys
Brian O'Connor477ddbe2013-12-09 18:35:18 -080018from time import sleep, strftime
19from subprocess import Popen, call, check_output, PIPE
20from mininet.net import Mininet
21from mininet.topo import SingleSwitchTopo
22from mininet.node import RemoteController
23from mininet.cli import CLI
24from mininet.log import setLogLevel
25try:
26 import pexpect
27except:
28 # install pexpect if it cannot be found and re-import
29 print '* Installing Pexpect'
30 call( 'apt-get install -y python-pexpect', stdout=PIPE, shell=True )
31 import pexpect
32
Brian O'Connorb405d082013-12-09 19:45:58 -080033ONOS_HOME = '..'
Brian O'Connore4531d82013-12-11 15:49:39 -080034ONOS_LOG = '%s/onos-logs/onos.%s.log' % ( ONOS_HOME, check_output( 'hostname').strip() )
35print "ONOS Log File:", ONOS_LOG
Brian O'Connorb405d082013-12-09 19:45:58 -080036
Brian O'Connor477ddbe2013-12-09 18:35:18 -080037# Verify that tcpkill is installed
Yuta HIGUCHI0bf51bc2014-01-05 15:37:15 -080038tcpkill_check = Popen( 'which tcpkill', stdout=PIPE, shell=True)
39tcpkill_check.communicate()
40if tcpkill_check.returncode != 0:
Brian O'Connor477ddbe2013-12-09 18:35:18 -080041 print '* Installing tcpkill'
42 call( 'apt-get install -y dsniff', stdout=PIPE, shell=True )
43
44# ----------------- Tests scenarios -------------------------
45def doNothing(n):
46 print "Doing nothing with %d flows..." % n
47
48def addFakeFlows(n):
Brian O'Connore4531d82013-12-11 15:49:39 -080049 print "Adding %d random flows to switch..." % n
Brian O'Connor477ddbe2013-12-09 18:35:18 -080050 for i in range( 1, (n+1) ):
51 a = i / (256*256) % 256
52 b = i / 256 % 256
53 c = i % 256
54 ip = '10.%d.%d.%d' % (a,b,c)
55 call( 'ovs-ofctl add-flow s1 "ip, nw_src=%s/32, idle_timeout=0, hard_timeout=0, cookie=%d, actions=output:2"' % ( ip, i ), shell=True )
56
57def delFlowsFromSwitch(n):
58 print "Removing all %d flows from switch..." % n
59 call( 'ovs-ofctl del-flows s1', shell=True )
60
61
62# ----------------- Utility Functions -------------------------
Brian O'Connore4531d82013-12-11 15:49:39 -080063def wait(time, msg=None):
64 if msg:
65 print msg,
66 for i in range(time):
67 sys.stdout.write('.')
68 sys.stdout.flush()
69 sleep(1)
70 print ". done"
Brian O'Connor477ddbe2013-12-09 18:35:18 -080071
72def startNet(net):
Brian O'Connore4531d82013-12-11 15:49:39 -080073 tail = pexpect.spawn( 'tail -0f %s' % ONOS_LOG )
74 sleep(1)
Brian O'Connor477ddbe2013-12-09 18:35:18 -080075 net.start()
Brian O'Connor66b255a2013-12-11 16:05:19 -080076 print "Waiting for ONOS to detech the switch..."
Brian O'Connorb405d082013-12-09 19:45:58 -080077 index = tail.expect(['Sync time \(ms\)', pexpect.EOF, pexpect.TIMEOUT])
78 if index >= 1:
79 print '* ONOS not started'
80 net.stop()
81 exit(1)
82 tail.terminate()
Brian O'Connor477ddbe2013-12-09 18:35:18 -080083
84def dumpFlows():
85 return check_output( 'ovs-ofctl dump-flows s1', shell=True )
86
87def addFlowsToONOS(n):
Brian O'Connor66b255a2013-12-11 16:05:19 -080088 print "Adding %d flows to ONOS" % n,
Brian O'Connorb405d082013-12-09 19:45:58 -080089 call( './generate_flows.py 1 %d > /tmp/flows.txt' % n, shell=True )
Brian O'Connor66b255a2013-12-11 16:05:19 -080090 #call( '%s/web/add_flow.py -m onos -f /tmp/flows.txt' % ONOS_HOME, shell=True )
91 p = Popen( '%s/web/add_flow.py -m onos -f /tmp/flows.txt' % ONOS_HOME, shell=True )
92 while p.poll() is None:
93 sys.stdout.write('.')
94 sys.stdout.flush()
95 sleep(1)
96 print ". done\nWaiting for flow entries to be added to switch",
Brian O'Connor477ddbe2013-12-09 18:35:18 -080097 while True:
98 output = check_output( 'ovs-ofctl dump-flows s1', shell=True )
99 lines = len(output.split('\n'))
100 if lines >= (n+2):
101 break
Brian O'Connore4531d82013-12-11 15:49:39 -0800102 sys.stdout.write('.')
103 sys.stdout.flush()
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800104 sleep(1)
Brian O'Connore4531d82013-12-11 15:49:39 -0800105 print ". done\nWaiting for flow entries to be visible in network graph",
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800106 while True:
Brian O'Connorb405d082013-12-09 19:45:58 -0800107 output = pexpect.spawn( '%s/web/get_flow.py all' % ONOS_HOME )
Brian O'Connore4531d82013-12-11 15:49:39 -0800108 count = 0
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800109 while count < n:
110 if output.expect(['FlowEntry', pexpect.EOF], timeout=2000) == 1:
111 break
112 count += 1
Brian O'Connore4531d82013-12-11 15:49:39 -0800113 print '. done'
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800114 return
Brian O'Connore4531d82013-12-11 15:49:39 -0800115 sys.stdout.write('.')
116 sys.stdout.flush()
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800117 sleep(5)
118
Brian O'Connor66b255a2013-12-11 16:05:19 -0800119def removeFlowsFromONOS(checkSwitch=True):
120 print "Removing all flows from ONOS",
121 #call( '%s/web/delete_flow.py all' % ONOS_HOME, shell=True )
122 p = Popen( '%s/web/delete_flow.py all' % ONOS_HOME, shell=True )
123 while p.poll() is None:
Brian O'Connore4531d82013-12-11 15:49:39 -0800124 sys.stdout.write('.')
125 sys.stdout.flush()
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800126 sleep(1)
Brian O'Connor66b255a2013-12-11 16:05:19 -0800127 print ". done"
128 if checkSwitch:
129 print "Waiting for flow entries to be removed from switch",
130 while True:
131 output = check_output( 'ovs-ofctl dump-flows s1', shell=True )
132 lines = len(output.split('\n'))
133 if lines == 2:
134 break
135 sys.stdout.write('.')
136 sys.stdout.flush()
137 sleep(1)
138 print ". done"
139 print "Waiting for flow entries to be removed from network graph",
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800140 while True:
Brian O'Connorb405d082013-12-09 19:45:58 -0800141 output = pexpect.spawn( '%s/web/get_flow.py all' % ONOS_HOME )
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800142 if output.expect(['FlowEntry', pexpect.EOF], timeout=2000) == 1:
143 break
Brian O'Connore4531d82013-12-11 15:49:39 -0800144 sys.stdout.write('.')
145 sys.stdout.flush()
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800146 sleep(5)
Brian O'Connore4531d82013-12-11 15:49:39 -0800147 print '. done'
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800148
149# ----------------- Running the test and output -------------------------
150def test(i, fn):
151 # Start tailing the onos log
Brian O'Connore4531d82013-12-11 15:49:39 -0800152 tail = pexpect.spawn( "tail -0f %s" % ONOS_LOG )
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800153 # disconnect the switch from the controller using tcpkill
154 tcp = Popen( 'exec tcpkill -i lo -9 port 6633 > /dev/null 2>&1', shell=True )
155 # wait until the switch has been disconnected
156 tail.expect( 'Switch removed' )
157 # call the test function
158 fn(i)
159 # dump to flows to ensure they have all made it to ovs
160 dumpFlows()
161 # end tcpkill process to reconnect the switch to the controller
162 tcp.terminate()
163 tail.expect('Sync time \(ms\):', timeout=6000)
Brian O'Connorb405d082013-12-09 19:45:58 -0800164 tail.expect('([\d.]+,?)+\s')
Brian O'Connore4531d82013-12-11 15:49:39 -0800165 print "* Results:", tail.match.group(0)
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800166 tail.terminate()
Brian O'Connore4531d82013-12-11 15:49:39 -0800167 wait(3, "Waiting for 3 seconds between tests")
Brian O'Connorb405d082013-12-09 19:45:58 -0800168 return tail.match.group(0).strip().split(',')
169
170def initResults(files):
171 headers = ['# of FEs', 'Flow IDs from Graph', 'FEs from Switch', 'Compare',
172 'Read FE from graph', 'Extract FE', 'Push', 'Total' ]
173 for filename in files.values():
174 with open(filename, 'w') as csvfile:
175 writer = csv.writer(csvfile)
176 writer.writerow(headers)
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800177
178def outputResults(filename, n, results):
179 results.insert(0, n)
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800180 with open(filename, 'a') as csvfile:
181 writer = csv.writer(csvfile)
182 writer.writerow(results)
183
184def runPerf( resultDir, tests):
185 fileMap = { 'add': os.path.join(resultDir, 'add.csv'),
186 'delete': os.path.join(resultDir, 'delete.csv'),
187 'sync': os.path.join(resultDir, 'sync.csv') }
Brian O'Connorb405d082013-12-09 19:45:58 -0800188 initResults(fileMap)
Brian O'Connor66b255a2013-12-11 16:05:19 -0800189 removeFlowsFromONOS(checkSwitch=False) # clear ONOS before starting
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800190 # start Mininet
191 topo = SingleSwitchTopo()
192 net = Mininet(topo=topo, controller=RemoteController)
Brian O'Connore4531d82013-12-11 15:49:39 -0800193 print "Starting Mininet"
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800194 startNet(net)
Brian O'Connore4531d82013-12-11 15:49:39 -0800195 wait(30, "Give ONOS 30 seconds to warm up") # let ONOS "warm-up"
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800196 for i in tests:
197 addFlowsToONOS(i)
198 outputResults(fileMap['sync'], i, test(i, doNothing))
199 outputResults(fileMap['delete'], i, test(i, delFlowsFromSwitch))
200 removeFlowsFromONOS()
201 outputResults(fileMap['add'], i, test(i, addFakeFlows)) # test needs empty DB
202 net.stop()
203
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800204if __name__ == '__main__':
205 setLogLevel( 'output' )
206 resultDir = strftime( '%Y%m%d-%H%M%S' )
207 os.mkdir( resultDir )
Yuta HIGUCHI526f7cb2013-12-16 10:18:47 -0800208 tests = map(int, sys.argv[1:])
Brian O'Connorb405d082013-12-09 19:45:58 -0800209 if not tests:
210 tests = [1, 10, 100, 1000, 10000]
211 runPerf( resultDir, tests )
Brian O'Connor477ddbe2013-12-09 18:35:18 -0800212