suibin-onlab | bd2b6e5 | 2014-08-07 20:56:49 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | This example shows how to create an empty Mininet object |
| 5 | (without a topology object) and add nodes to it manually. |
| 6 | """ |
| 7 | import sys |
| 8 | import subprocess |
| 9 | import time |
| 10 | from mininet.net import Mininet |
| 11 | from mininet.node import Controller |
| 12 | from mininet.cli import CLI |
| 13 | from mininet.log import setLogLevel, info |
| 14 | |
| 15 | swlist = [] |
| 16 | hostlist= [] |
| 17 | count = 0 |
| 18 | |
| 19 | def createSwPorts(numsw, numport): |
| 20 | |
| 21 | "Create an empty network and add nodes to it." |
| 22 | |
| 23 | net = Mininet() |
| 24 | swlist = [] |
| 25 | hostlist= [] |
| 26 | print ("Starting Mininet Network....") |
| 27 | for i in range(numsw): |
| 28 | sw = net.addSwitch( 's' + str(i), dpid = ('00000000000000' + '%0d'%i)) |
| 29 | print str(sw), |
| 30 | for p in range(numport): |
| 31 | host = net.addHost("s"+str(i)+"h"+str(p)) |
| 32 | hostlist.append(host) |
| 33 | print str(host), |
| 34 | net.addLink(host,sw) |
| 35 | swlist.append(sw) |
| 36 | |
| 37 | |
| 38 | info( '*** Starting network\n') |
| 39 | net.start() |
| 40 | |
| 41 | return swlist |
| 42 | |
| 43 | def loadsw(urllist, swlist, addrate, delrate, duration): |
| 44 | global numport |
| 45 | urlindex = 0 |
| 46 | count = 0 |
| 47 | addsleeptimer = 1.000 /addrate |
| 48 | delsleeptimer = 1.000/delrate |
| 49 | print (" Add sleeptimer: " + str('%.3f' %addsleeptimer) + "; Delete sleeptimer: " + str('%.3f' %delsleeptimer)) |
| 50 | print str(swlist) |
| 51 | |
| 52 | tstart = time.time() |
| 53 | while ( (time.time() - tstart) <= duration ): |
| 54 | #print (time.time() - tstart) |
| 55 | astart = time.time() |
| 56 | for sw in swlist: |
| 57 | if urlindex < len(urllist): |
| 58 | i = urlindex |
| 59 | else: |
| 60 | i = 0 |
| 61 | urlindex = 0 |
| 62 | |
| 63 | ovscmd = "sudo ovs-vsctl set-controller " + str(sw) + " tcp:" + urllist[i] |
| 64 | print ("a"), |
| 65 | s = subprocess.Popen(ovscmd, shell=True ) |
| 66 | time.sleep(addsleeptimer) |
| 67 | count += 1 |
| 68 | urlindex += 1 |
| 69 | aelapse = time.time() - astart |
| 70 | print ("Number of switches connected: " + str(len(swlist)) + " in: " + str('%.3f' %aelapse) + "seconds.") |
| 71 | |
| 72 | dstart = time.time() |
| 73 | for sw in swlist: |
| 74 | ovscmd = "sudo ovs-vsctl set-controller " + str(sw) + " tcp:127.0.0.1:6633" |
| 75 | print ("d"), |
| 76 | s = subprocess.Popen(ovscmd, shell=True ) |
| 77 | time.sleep(delsleeptimer) |
| 78 | count += 1 |
| 79 | delapse = time.time() - dstart |
| 80 | print ("Number of switches disconnected: " + str(len(swlist)) + " in: " + str('%.3f' %delapse) + "seconds.") |
| 81 | telapse = time.time() - tstart |
| 82 | |
| 83 | return telapse, count |
| 84 | def cleanMN(): |
| 85 | print ("Cleaning MN switches...") |
| 86 | s = subprocess.Popen("sudo mn -c > /dev/null 2>&1", shell=True) |
| 87 | print ("Done.") |
| 88 | |
| 89 | def main(): |
| 90 | import argparse |
| 91 | import threading |
| 92 | from threading import Thread |
| 93 | |
| 94 | parser = argparse.ArgumentParser(description="less script") |
| 95 | parser.add_argument("-u", "--urls", dest="urls", default="10.128.10.1", type=str, help="a string to show urls to post intents to separated by space, ex. '10.128.10.1:6633 10.128.10.2:6633' ") |
| 96 | parser.add_argument("-s", "--switches", dest="numsw", default=100, type=int, help="number of switches use in the load generator; together with the ports per switch config, each switch generates (numport + 2) events") |
| 97 | parser.add_argument("-p", "--ports", dest="numport", default=1, type=int, help="number of ports per switches") |
| 98 | parser.add_argument("-a", "--addrate", dest="addrate", default=10, type=float, help="rate to add intents groups, groups per second") |
| 99 | parser.add_argument("-d", "--delrate", dest="delrate", default=100, type=float, help= "rate to delete intents, intents/second") |
| 100 | parser.add_argument("-l", "--testlength", dest="duration", default=0, type=int, help= "pausing time between add and delete of intents") |
| 101 | args = parser.parse_args() |
| 102 | |
| 103 | urllist = args.urls.split() |
| 104 | numsw = args.numsw |
| 105 | numport = args.numport |
| 106 | addrate = args.addrate |
| 107 | delrate = args.delrate |
| 108 | duration = args.duration |
| 109 | setLogLevel( 'info' ) |
| 110 | swlist = createSwPorts(numsw,numport) |
| 111 | telapse,count = loadsw(urllist, swlist, addrate, delrate, duration) |
| 112 | print ("Total number of switches connected/disconnected: " + str(count) + "; Total events generated: " + str(count * (2 + numport)) + "; Elalpse time: " + str('%.1f' %telapse)) |
| 113 | print ("Effective aggregated loading is: " + str('%.1f' %((( count * (2+ numport))) / telapse ) ) + "Events/s.") |
| 114 | cleanMN() |
| 115 | |
| 116 | if __name__ == '__main__': |
| 117 | main() |