def topology(num=100, max_r=100, mode="g", xp=None, plot=False, ping=False, serf_conf=False, devmodel=None, sleep_test=-1, new_met=False): info( "Creating a network with docker containers acting as hosts and wireless mesh network environment.\n" ) net = Containernet(controller=Controller) #info('*** Adding docker containers\n') ## In automated way will create Hosts dh = [] if load_topo: net, dh, num = load_positions(net) net = start_network(net) seed_node = "10.0.0.254:5001" ## seed will be always the first container! config_nodes(seed_node, dh) printTopo(net, num=num, plotgrp=plot, ping=ping) if not xp: info("> Not running automatic experience!\n") else: #TODO: for now there is only one!!!!! experiment1(net, dh, num=num, sleep_test=sleep_test, new_met=new_met) info('*** Running CLI\n') CLI(net) info('*** Stopping network') net.stop() sys.exit() ## save(?) and exit #Using the new method to calculate positions info("*** Creating positions for nodes\n") listPos, G = prepareGraph(num, max_r) print("* Nodes positions created!") print("** Creating %d Station(s) " % (num)) if save_topo: with open(save_topo_file, "w+") as tdh: #start writing things #NumOfHosts;[(posx,posy,posz),..];docker_image;device_model;range;ip?;other info tdh.write("### Topology for %d hosts\n" % (num)) tdh.write( "#NumOfHosts;[(posx,posy,posz);docker_image;device_model;range;ip?];other info\n" ) tdh.write("NumOfHosts=%d;\n" % num) tdh.flush() for x in range(0, num): ip = (254 - x) posx, posy = getPosition(listPos) posz = 10 r = max_r position = str(posx) + ',' + str(posy) + ',' + str(posz) ## This will create the hosts with image ubuntu:trusty, position and range of the device ## other information can be added later #dh.append("null") dh.append( net.addDocker('d' + str(x), cls=Docker, ip='10.0.0.' + str(ip), dimage=docker_image, position=position, range=r, mode=mode, equipmentModel=devmodel)) d = dh[x] sys.stdout.write(str(d) + " ") sys.stdout.flush() if save_topo: with open(save_topo_file, "a+") as tdh: tdh.write( "[\nnode_num=%d;\nposition=(%s);\ndocker_image=%s;\nequip_model=%s;\nrange=%d;\nmode=%s;\nip=10.0.0.%d;\n]\n" % (x, position, docker_image, devmodel, r, mode, ip)) tdh.flush() container_constraint(dh=dh) info("\n** Adding nodes to Mesh\n") hlinks = [] for x in dh: hlinks.append(net.addMesh(x, ssid='meshNet')) x.verifyingNodes(x) ## Mesh routing is not doing a mesh, only 1 to nearby meshr = net.meshRouting("custom") info("** Routing nodes through mesh\n") for x in dh: meshRouting.customMeshRouting(x, 0, net.wifiNodes) sys.stdout.write(str(x) + " ") sys.stdout.flush() start_network(net) seed_node = "10.0.0.254:5001" ## seed will be always the first container! config_nodes(seed_node, dh) # This will print the topology and network configuration of the # random created network printTopo(net, num=num, plotgrp=plot, ping=ping) # The simulation selected will start: if not xp: info("> Not running automatic experiment!\n") elif xp == "None": info("> Not running automatic experiment\n") elif xp == 'dataset': exp_dataset(net) else: #TODO: for now there is only one!!!!! experiment1(net, dh, num=num, sleep_test=sleep_test, new_met=new_met) info('*** Running CLI\n') CLI(net) info('*** Stopping network') net.stop()
def topology(num=100): info( "Creating a network with docker containers acting as hosts and wireless mesh network environment.\n" ) net = Containernet(controller=Controller) info('*** Adding docker containers\n') ## In automated way will create Hosts dh = [] listPos = positions(num) prepareGraph(num) sys.exit() print("** Creating %d Station(s) " % (num)) for x in range(0, num): ip = (254 - x) posx, posy, posz, r = getPosition(listPos) ## This will create the hosts with image ubuntu:trusty, position and range of the device ## other information can be added later dh.append( net.addDocker('d' + str(x), cls=Docker, ip='10.0.0.' + str(ip), dimage="ubuntu:trusty", position=str(posx) + ',' + str(posy) + ',' + str(posz), range=r)) d = dh[x] sys.stdout.write(str(d) + " ") sys.stdout.flush() info("\n** Adding nodes to Mesh\n") for x in dh: net.addMesh(x, ssid='meshNet') #pdb.set_trace() meshr = net.meshRouting("mesh") info("** Routing nodes through mesh\n") for x in dh: meshRouting.customMeshRouting(x, 0, net.wifiNodes) sys.stdout.write(str(x) + " ") sys.stdout.flush() info('\n*** Starting network\n') net.build( ) ## Build should do the same as start but it will interconnect hosts #net.start() seed_node = "10.0.0.254:5001" ## seed will be always the first container! info("** Configuring node(s)\n") for d in dh: sys.stdout.write(str(d) + " - ") sys.stdout.flush() port = 5001 dev = str(d) + "-mp0" ## Calling inside script to configure each container nn = d.cmd( "/bin/bash /home/config-serf.sh config rpc=127.0.0.1:7373 port=" + str(port) + " dev=" + str(dev) + " seed=" + str(seed_node)) if nn: print("Configured for 10.0.0.%s:%d in device %s " % (str(ip), port, dev)) print("> %s " % (nn)) else: print("Error in configuring %s " % (str(d))) info('*** Starting our simulation\n') slpv = 10 * num / 4 ### SLEEP VARIABLE!!!! #This will start our simulation of SERF+monitor #Calling our inside script to start the processes st = time.time() with open('/home/simul.' + str(num) + '-' + str(int(time.time())) + '.txt', "a+") as myfile: for d in range(0, num): dh[d].sendCmd("/bin/bash /home/config-serf.sh test " + str(slpv) + " 2>&1 /dev/null &") see_pub(dh, out=myfile) #dh[d+1].cmd("/bin/bash /home/config-serf.sh test 50") time.sleep(1) ## So that each will start after each other info("** All nodes have published services.\n") info("** waiting for them to end.") et = 0 while ((st + slpv) - et) >= 0: ## while within the time frame #for i in range(0,slpv): sys.stdout.write(".") sys.stdout.flush() see_pub(dh, out=myfile) #time.sleep(1) et = time.time() sys.stdout.flush() myfile.flush() print("\n") printTopo(net, num=num) info("*** Simulation has ended (?)\n") info('*** Running CLI\n') CLI(net) info('*** Stopping network') net.stop()