def _create_host(experiment, host): logger.debug("creating host for experiment={}, host={}, pos={}".format( experiment, host['name'], host['pos'])) exp = experiments[experiment] host_id = len(exp.hosts) + 1 hst = exp.addHost(host['name'], ip=Tools.makeIP(host_id), max=Tools.makeMAC(host_id), pos=host['pos']) return hst
def post(self): args = Topology_request_parser.parse_args() switch.append(args) print args["switch_name"] exp.addSwitch(args["switch_name"], dpid=Tools.makeDPID(args["worker_id"])) return {"msg": "Switch added", "switch_data": args}
def createInternet(self, internetTopo='singleRouter'): routerIndex = 1 internetRouterList = [] if internetTopo == 'singleRouter': internetRouter = self.addSwitch('intR'+ str(routerIndex), dpid=Tools.makeDPID(routerIndex), **dict(listenPort=(10000+routerIndex-1))) internetRouterList.append(internetRouter) elif internetTopo == 'doubleRouter': internetRouter = self.addSwitch('intR'+ str(routerIndex), dpid=Tools.makeDPID(routerIndex), **dict(listenPort=(10000+routerIndex-1))) internetRouterList.append(internetRouter) routerIndex += 1 internetRouter = self.addSwitch('intR'+ str(routerIndex), dpid=Tools.makeDPID(routerIndex), **dict(listenPort=(10000+routerIndex-1))) internetRouterList.append(internetRouter) print("internet is like: %s" % internetRouterList) return internetRouterList
def create_switch(self): switch_name = 's{}'.format(self._sid) host_name = 'h{}'.format(self._sid) self.expr.addSwitch(switch_name, dpid=Tools.makeDPID(self._sid), wid=self._wid) self.expr.addHost(host_name, ip=self._ip_addr, max=Tools.makeMAC(self._sid), pos=switch_name) self.expr.addLink(switch_name, host_name, autoconf=True) logging.info('Created switch {} ({}) on worker {}'.format( self._sid, self._ip_addr, self._wid + 1, )) time.sleep(2)
def daemonize_script(self, script, args): """Call MaxiNet Script (non-blocking) Args: cmd: name of script to call """ cmd = Tools.get_script_dir()+script+" "+args p = subprocess.Popen(cmd, shell=True) atexit.register(p.terminate)
def daemonize_script(self, script, args): """Call MaxiNet Script (non-blocking) Args: cmd: name of script to call """ cmd = Tools.get_script_dir() + script + " " + args p = subprocess.Popen(cmd, shell=True) atexit.register(p.terminate)
def script_check_output(self, cmd): """Call MaxiNet Script and return output Args: cmd: name of script to call Returns: Shell output of script """ # Prefix command by our worker directory cmd = Tools.get_script_dir() + cmd return self.check_output(cmd)
def _create_switch(experiment, switch): exp = experiments[experiment] switch_id = len(exp.switches) + 1 logger.debug( "creating switch for experiment={}, switch={}, workerId={}, dpid={}". format(experiment, switch['name'], switch['workerId'], switch_id)) sw = exp.addSwitch(switch['name'], dpid=Tools.makeDPID(switch_id), wid=switch['workerId']) return sw
def create_link_with(self, link_switch): switch_name_1 = 's{}'.format(self._sid) switch_name_2 = 's{}'.format(link_switch) self.expr.addLink(switch_name_1, switch_name_2, autoconf=True) logging.info('Built link: {} ({}) <-> {} ({})'.format( self._sid, self._ip_addr, link_switch, Tools.makeIP(link_switch), )) time.sleep(2)
def createDC(self, numofDC, numSr, nodesPerSr, DCtopo, subnet, bwlimit, lat): srList = [] nodeList = [] DCIdx = numofDC + 1 srIdx = numofDC * numSr + 1 nodeIdx = numofDC * numSr * nodesPerSr + 1 #create service router for i in range(numSr): sr = self.addSwitch('sr'+ str(srIdx), dpid=Tools.makeDPID(srIdx), **dict(listenPort=(13000+srIdx-1))) print("create sr %s" % sr) # create nodes if i != 0: for j in range(nodesPerSr): h = self.addHost('h' + str(nodeIdx), mac=Tools.makeMAC(nodeIdx), ip=subnet + str(numofDC) + '.' +str(nodeIdx+100)+'/24', defaultRoute ='h'+str(nodeIdx)+'-eth0') print("create host %s" % h) nodeList.append(h) self.addLink(h, sr, bw=2*bwlimit, delay=str(lat)+'ms') print("add link between %s and %s" % (h, sr)) nodeIdx += 1 srIdx += 1 # if fullmesh, ovs should be defined to break loop!!! if DCtopo == 'fullmesh': # connect sr to previous srs for tempSrIdx in range(len(srList)): self.addLink(sr, srList[tempSrIdx], bw=bwlimit, delay=str(lat)+'ms') print("add link between %s and %s" % (sr, srList[tempSrIdx])) elif DCtopo == 'line': if len(srList) > 0: self.addLink(sr, srList[-1], bw=2*bwlimit, delay=str(lat)+'ms') print("add link between %s and %s" % (sr, srList[-1])) srList.append(sr) DC = [DCIdx, srList[0]] return DC, srList, nodeList
def create_topo(topo): t = Topo() i = 1 for host in topo['hosts']: logger.debug("add host {} to topo".format(host['name'])) t.addHost(host['name'], ip=Tools.makeIP(i), mac=Tools.makeMAC(i)) i += 1 i = 1 for switch in topo['switches']: logger.debug("add switch {} to topo".format(switch['name'])) t.addSwitch(switch['name'], dpid=Tools.makeDPID(i)) i += 1 i = 1 for link in topo['links']: logger.debug("add link from {} to {} to topo".format( link['node1']['name'], link['node2']['name'])) t.addLink(link['node1']['name'], link['node2']['name']) i += 1 return t
def hello_world(): topo = Topo() topo.addHost("h1", cls=Docker, ip="10.0.0.251", dimage="ubuntu:trusty") topo.addHost("h2", cls=Docker, ip="10.0.0.252", dimage="ubuntu:trusty") topo.addSwitch("s1", dpid=Tools.makeDPID(1)) topo.addLink("h1", "s1") topo.addLink("h2", "s1") # start cluster cluster = maxinet.Cluster(minWorkers=1, maxWorkers=2) # start experiment with OVSSwitch on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() return 'Welcome to our Library!'
def __init__(self, switch_id, worker_id, children): self._sid = switch_id self._wid = worker_id self._children = children self._ip_addr = Tools.makeIP(self._sid)
def start(self, ip, port, password, retry=float("inf")): """Start WorkerServer and ssh daemon and connect to nameserver.""" self.logger.info("starting up and connecting to %s:%d" % (ip, port)) #store for reconnection attempts self._ip = ip self._port = port self._password = password #Pyro4.config.HMAC_KEY = password tries = 1 self._ns = None while not self._ns: try: self._ns = Pyro4.locateNS(ip, port, hmac_key=password) except Pyro4.errors.NamingError: if tries < retry: self.logger.warn( "Unable to locate Nameserver. Trying again in 5 seconds..." ) time.sleep(5) tries += 1 else: self.logger.error("Unable to locate Nameserver.") sys.exit() self.config = Pyro4.Proxy(self._ns.lookup("config")) self.config._pyroHmacKey = password self.ip = self.config.get_worker_ip(self.get_hostname()) if (not self.ip): self.ip = Tools.guess_ip() if not self.config.has_section(self.get_hostname()): self.config.add_section(self.get_hostname()) self.config.set(self.get_hostname(), "ip", self.ip) self.logger.warn( """FrontendServer did not know IP of this host (check configuration for hostname). Guessed: %s""" % self.ip) self.logger.info("configuring and starting ssh daemon...") self.sshManager = SSH_Manager(folder=self.ssh_folder, ip=self.ip, port=self.config.get_sshd_port(), user=self.config.get("all", "sshuser")) self.sshManager.start_sshd() self._pyrodaemon = Pyro4.Daemon(host=self.ip) self._pyrodaemon._pyroHmacKey = password uri = self._pyrodaemon.register(self) self._ns.register(self._get_pyroname(), uri) uri = self._pyrodaemon.register(self.mnManager) self._ns.register(self._get_pyroname() + ".mnManager", uri) uri = self._pyrodaemon.register(self.sshManager) self._ns.register(self._get_pyroname() + ".sshManager", uri) atexit.register(self._stop) self.logger.info("looking for manager application...") manager_uri = self._ns.lookup("MaxiNetManager") if (manager_uri): self._manager = Pyro4.Proxy(manager_uri) self._manager._pyroHmacKey = self._password self.logger.info("signing in...") if (self._manager.worker_signin(self._get_pyroname(), self.get_hostname())): self.logger.info("done. Entering requestloop.") self._started = True self._looping_thread = threading.Thread( target=self._pyrodaemon.requestLoop) self._looping_thread.daemon = True self._looping_thread.start() else: self.logger.error("signin failed.") else: self.logger.error("no manager found.")
# Dynamic adding and removing of nodes also does not work when using the # UserSwitch. import time from mininet.topo import Topo from mininet.node import OVSSwitch from MaxiNet.Frontend import maxinet from MaxiNet.tools import Tools # create topology topo = Topo() topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1)) topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2)) topo.addSwitch("s1", dpid=Tools.makeDPID(1)) topo.addLink("h1", "s1") topo.addLink("h2", "s1") # start cluster cluster = maxinet.Cluster(minWorkers=5, maxWorkers=5) # start experiment with OVSSwitch on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() print "waiting 5 seconds for routing algorithms on the controller to converge" time.sleep(5)
print exp.get_node("d2").cmd("ifconfig") print "waiting 5 seconds for routing algorithms on the controller to converge" #time.sleep(5) print "ping d1 ---> d2" print exp.get_node("d1").cmd("ping -c 5 10.0.0.252") print "ping d2 ---> d1" print exp.get_node("d2").cmd("ping -c 5 10.0.0.251") #exp.CLI(locals(), globals()) print "add d3 at runtime" #worker = exp.get_worker('s1') #worker.addDocker('d4', dimage="ubuntu:trusty") d3 = exp.addDocker("d3", pos="s1", dimage="ubuntu:trusty", ip="10.0.0.254", max=Tools.makeMAC(3)) #d3.setIP(ip='10.0.0.254') #h3 = exp.get_worker("s1").addHost('h3', ip=Tools.makeIP(3), max=Tools.makeMAC(3)) #d3 = exp.get_worker("s1").addDocker('d3', dimage="ubuntu:trusty") print "add link s1 <---> d3" #exp.addLink(exp.get_node("d3"), exp.get_node("s1"), params1={"ip": "10.0.0.254/8"}) exp.addLink("d3", "s1", autoconf=True) print "wait 5 seconds" time.sleep(5) print "ping d3 --> d1" print d3.cmd("ping -c 5 10.0.0.251") print "ping d1 --> d3"
os.rename("t1_experiment.cfg", "experiment.cfg") os.system("sudo rm /log/*") # Now also copy the given input topo file as in_topo.json in each of worker copy2(topo_fname, 'in_topo.json') print "File sucessfully copied as in_topo.json..." with open('in_topo.json') as data_file: data = json.load(data_file) hnames = data["hosts"] hlen = len(hnames) cnt = 1 for x in range(0, hlen): tmp = str(hnames[x]) myglobalTopo.addHost(tmp, ip=Tools.makeIP(cnt), mac=Tools.makeMAC(cnt)) cnt = cnt + 1 my_swlist = [] for key, value in dict.items(data["switches"]): my_swlist.append(key) # Add to list of switches in topology cnt = 1 for value1, value2 in dict.items(data["switches"][key]): tmp = str(key) myglobalTopo.addSwitch(tmp, dpid=Tools.makeDPID(cnt)) cnt = cnt + 1 #hnames = data["hosts"] hnames = data["links"] hlen = len(hnames) for x in range(0, hlen):
from mininet.node import OVSSwitch # messing with topo from mininet.topo import Topo from MaxiNet.tools import Tools topo = Topo() #empty topo cluster = maxinet.Cluster(minWorkers=5, maxWorkers=5) exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() # SIGN print "adding switches on workers..." exp.addSwitch("s1", dpid=Tools.makeDPID(1), wid=0) exp.addSwitch("s2", dpid=Tools.makeDPID(2), wid=1) exp.addSwitch("s3", dpid=Tools.makeDPID(3), wid=2) exp.addSwitch("s4", dpid=Tools.makeDPID(4), wid=3) exp.addSwitch("s5", dpid=Tools.makeDPID(2), wid=4) print "adding 5 hosts..." exp.addHost("h1", ip=Tools.makeIP(1), max=Tools.makeMAC(1), pos="s1") exp.addHost("h2", ip=Tools.makeIP(2), max=Tools.makeMAC(2), pos="s2") exp.addHost("h3", ip=Tools.makeIP(3), max=Tools.makeMAC(3), pos="s3") exp.addHost("h4", ip=Tools.makeIP(4), max=Tools.makeMAC(4), pos="s4") exp.addHost("h5", ip=Tools.makeIP(5), max=Tools.makeMAC(5), pos="s5") print "add links between h_i and s_i" exp.addLink("s1", "h1", autoconf=True)
def start(self, ip, port, password, retry=float("inf")): """Start WorkerServer and ssh daemon and connect to nameserver.""" self.logger.info("starting up and connecting to %s:%d" % (ip, port)) #store for reconnection attempts self._ip = ip self._port = port self._password = password #Pyro4.config.HMAC_KEY = password tries=1 self._ns = None while not self._ns: try: self._ns = Pyro4.locateNS(ip, port, hmac_key=password) except Pyro4.errors.NamingError: if tries < retry: self.logger.warn("Unable to locate Nameserver. Trying again in 5 seconds...") time.sleep(5) tries += 1 else: self.logger.error("Unable to locate Nameserver.") sys.exit() self.config = Pyro4.Proxy(self._ns.lookup("config")) self.config._pyroHmacKey=password self.ip = self.config.get_worker_ip(self.get_hostname()) if(not self.ip): self.ip = Tools.guess_ip() if not self.config.has_section(self.get_hostname()): self.config.add_section(self.get_hostname()) self.config.set(self.get_hostname(), "ip", self.ip) self.logger.warn("""FrontendServer did not know IP of this host. Guessed: %s""" % self.ip) self.logger.info("configuring and starting ssh daemon...") self.sshManager = SSH_Manager(folder=self.ssh_folder, ip=self.ip, port=self.config.get_sshd_port(), user=self.config.get("all", "sshuser")) self.sshManager.start_sshd() self._pyrodaemon = Pyro4.Daemon(host=self.ip) self._pyrodaemon._pyroHmacKey=password uri = self._pyrodaemon.register(self) self._ns.register(self._get_pyroname(), uri) uri = self._pyrodaemon.register(self.mnManager) self._ns.register(self._get_pyroname()+".mnManager", uri) uri = self._pyrodaemon.register(self.sshManager) self._ns.register(self._get_pyroname()+".sshManager", uri) atexit.register(self._stop) self.logger.info("looking for manager application...") manager_uri = self._ns.lookup("MaxiNetManager") if(manager_uri): self._manager = Pyro4.Proxy(manager_uri) self._manager._pyroHmacKey=self._password self.logger.info("signing in...") if(self._manager.worker_signin(self._get_pyroname(), self.get_hostname())): self.logger.info("done. Entering requestloop.") self._started = True self._looping_thread = threading.Thread(target=self._pyrodaemon.requestLoop) self._looping_thread.daemon = True self._looping_thread.start() else: self.logger.error("signin failed.") else: self.logger.error("no manager found.")
from mininet.topo import Topo from mininet.node import OVSSwitch from MaxiNet.Frontend.container import Docker from MaxiNet.Frontend import maxinet from MaxiNet.tools import Tools topo = Topo() topo.addHost("h1", cls=Docker, ip="10.0.0.251", dimage="ubuntu:trusty") topo.addHost("h2", cls=Docker, ip="10.0.0.252", dimage="ubuntu:trusty") topo.addSwitch("s5", dpid=Tools.makeDPID(5)) ## set datapath id topo.addLink("h1", "s5") topo.addLink("h2", "s5") cluster = maxinet.Cluster(minWorkers=1, maxWorkers=2) # start experiment with OVSSwitch on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() exp.get_node("h1").cmd("ping -c 1 10.0.0.252") exp.get_node("h2").cmd("ping -c 1 10.0.0.251")
# UserSwitch. import time from mininet.topo import Topo from mininet.node import OVSSwitch from MaxiNet.Frontend import maxinet from MaxiNet.tools import Tools # create topology cluster = maxinet.Cluster(minWorkers=1, maxWorkers=1) topo = Topo() topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1)) topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2)) topo.addHost("h3", ip=Tools.makeIP(3), mac=Tools.makeMAC(3)) topo.addHost("h4", ip=Tools.makeIP(4), mac=Tools.makeMAC(4)) topo.addHost("h5", ip=Tools.makeIP(5), mac=Tools.makeMAC(5)) topo.addHost("h6", ip=Tools.makeIP(6), mac=Tools.makeMAC(6)) topo.addHost("h7", ip=Tools.makeIP(7), mac=Tools.makeMAC(7)) topo.addHost("h8", ip=Tools.makeIP(8), mac=Tools.makeMAC(8)) topo.addSwitch("s1", dpid=Tools.makeDPID(1)) topo.addSwitch("s2", dpid=Tools.makeDPID(2)) topo.addSwitch("s3", dpid=Tools.makeDPID(3)) topo.addSwitch("s4", dpid=Tools.makeDPID(4)) topo.addSwitch("s5", dpid=Tools.makeDPID(5)) topo.addSwitch("s6", dpid=Tools.makeDPID(6)) topo.addSwitch("s7", dpid=Tools.makeDPID(7))
# emulated hosts. # import subprocess from mininet.node import OVSSwitch from mininet.topo import Topo from MaxiNet.Frontend import maxinet from MaxiNet.tools import Tools topo = Topo() topo.addSwitch("s1") topo.addSwitch("s2") topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1)) topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2)) topo.addLink("h1", "s1") topo.addLink("s1", "s2") topo.addLink("h2", "s2") cluster = maxinet.Cluster() # we need to add the root node after the simulation has started as we do # not know which worker id the frontend machine will get. Therefore we # need a dynamic topology which is only supported in openvswitch exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() # Start ssh servers h1 = exp.get("h1")
# start cluster cluster = maxinet.Cluster(minWorkers=2, maxWorkers=2) # start experiment on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() print('****Setting up topology part 1') print('Creating switches s1 (on worker1) and s2 (on worker2)...') exp.addSwitch("s1", dpid="00:00:00:00:00:00:00:01", wid=0) exp.addSwitch("s2", dpid="00:00:00:00:00:00:00:02", wid=1) print('Adding hosts h1 in worker 1...') exp.addHost('h1',ip=Tools.makeIP(1), max=Tools.makeMAC(1), pos='s1') print('Adding hosts h2 in worker 2...') exp.addHost('h2',ip=Tools.makeIP(2), max=Tools.makeMAC(2), pos='s2') print('Connecting h1 with s1') exp.addLink("h1", "s1", autoconf=True) print('Connecting h2 with s2') exp.addLink("h2", "s2", autoconf=True) print('Connecting s1 and s2...') exp.addLink("s1", "s2", autoconf=True) maxinet.Experiment.CLI(exp, None, None)
# start cluster cluster = maxinet.Cluster(minWorkers=2, maxWorkers=2) # start experiment on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() print('****Setting up topology part 1') print('Creating switches s1 (on worker1) and s2 (on worker2)...') exp.addSwitch("s1", dpid="00:00:00:00:00:00:00:01", wid=0) exp.addSwitch("s2", dpid="00:00:00:00:00:00:00:02", wid=1) print('Adding hosts h1 in worker 1...') exp.addHost('h1', ip=Tools.makeIP(1), max=Tools.makeMAC(1), pos='s1') print('Adding hosts h2 in worker 2...') exp.addHost('h2', ip=Tools.makeIP(2), max=Tools.makeMAC(2), pos='s2') print('Connecting h1 with s1') exp.addLink("h1", "s1", autoconf=True) print('Connecting h2 with s2') exp.addLink("h2", "s2", autoconf=True) print('Connecting s1 and s2...') exp.addLink("s1", "s2", autoconf=True) raw_input('[Continue]')
# Dynamic adding and removing of nodes also does not work when using the # UserSwitch. import time from mininet.topo import Topo from mininet.node import OVSSwitch from MaxiNet.Frontend import maxinet from MaxiNet.tools import Tools # create topology topo = Topo() topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1)) topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2)) topo.addSwitch("s1", dpid=Tools.makeDPID(1)) topo.addLink("h1", "s1") topo.addLink("h2", "s1") # start cluster cluster = maxinet.Cluster(minWorkers=2, maxWorkers=2) # start experiment with OVSSwitch on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() print "waiting 5 seconds for routing algorithms on the controller to converge" time.sleep(5)