3 from mininet.net import Mininet
4 from mininet.node import OVSKernelSwitch, RemoteController
5 from mininet.cli import CLI
19 rip = "{0}.{1}.{2}.{3}".format(d, c, b, a)
49 def get_switch(net, hosts):
50 sname = 's{0}'.format(get_next_sid())
51 s = net.addSwitch(sname)
52 for i in range(hosts):
53 hname = 'h{0}'.format(get_next_hid())
55 h = net.addHost(hname, ip=hip)
57 print "switch {0}: host {1}-{2} added".format(sname, hname, hip)
61 def get_net(switches, hostpswtich, controllers=['10.25.2.9']):
63 net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
66 for i, cip in enumerate(controllers):
67 c = net.addController('c{0}'.format(i), controller=RemoteController, ip=cip, port=6633)
69 print "contrller {0} created".format(c)
72 for i in range(switches):
73 s = get_switch(net, hostpswtich)
85 class MininetworkProcess(multiprocessing.Process):
87 Do NOT use this class directly.
89 def __init__(self, swithes, hps, controllers=['10.25.2.9']):
90 super(MininetworkProcess, self).__init__()
91 self._event = multiprocessing.Event()
92 self._net = get_net(swithes, hps, controllers=controllers)
97 while self._event.is_set() is False:
102 if __name__ == '__main__':
103 # setLogLevel( 'info' )
104 parser = argparse.ArgumentParser(description='Starts switches with specified controllers')
105 parser.add_argument('--controllers', default='10.25.2.9',
106 help='Comma separated list of cluster members (default ="10.25.2.9,10.25.2.10,10.25.2.11")')
107 args = parser.parse_args()
109 net = get_net(3, 1, controllers=args.controllers.split(','))