def parameters(self): while self.continue_: listNodes.ssid_ID = 0 for node in self.staList: for wlan in range(0, len(node.params['wlan'])): if node.func[wlan] != 'mesh' and node.func[wlan] != 'adhoc': self.nodeParameter(node, wlan) elif node.func[wlan] == 'mesh': dist = listNodes.pairingNodes(node, wlan, self.staList) if dist != 0: channelParameters(node, None, wlan, dist, self.staList, 0) else: if dist != 0: channelParameters(node, None, wlan, dist, self.staList, 0) if meshRouting.routing == 'custom': for node in mobility.staList: for wlan in range(0, len(node.params['wlan'])): if node.func[wlan] == 'mesh': """Mesh Routing""" try: meshRouting.customMeshRouting( node, wlan, self.staList) except: pass listNodes.clearList()
def parameters(self): while self.continue_: listNodes.ssid_ID = 0 for node in self.staList: for wlan in range(0, len(node.params['wlan'])): if node.func[wlan] != 'mesh' and node.func[wlan] != 'adhoc': self.nodeParameter(node, wlan) elif node.func[wlan] == 'mesh' : dist = listNodes.pairingNodes(node, wlan, self.staList) if dist != 0: channelParameters(node, None, wlan, dist, self.staList, 0) else: if dist != 0: channelParameters(node, None, wlan, dist, self.staList, 0) if meshRouting.routing == 'custom': for node in mobility.staList: for wlan in range(0, len(node.params['wlan'])): if node.func[wlan] == 'mesh': """Mesh Routing""" try: meshRouting.customMeshRouting(node, wlan, self.staList) except: pass listNodes.clearList() # have to verify this time.sleep(0.01)
def parameters(self): while self.continue_: try: for node in self.staList: for wlan in range(0, node.nWlans): if node.func[wlan] == 'mesh' or node.func[ wlan] == 'adhoc': dist = listNodes.pairingNodes( node, wlan, self.staList) if dist != 0: channelParameters(node, None, wlan, dist, self.staList, abs(node.params['speed'])) else: self.nodeParameter(node, wlan) if meshRouting.routing == 'custom': for node in mobility.staList: for wlan in range(0, node.nWlans): if node.func[wlan] == 'mesh': """Mesh Routing""" meshRouting.customMeshRouting( node, wlan, self.staList) listNodes.clearList() except: pass
def load_positions(net): info("*** Loading Nodes from file\n") numofhosts = 0 nodes = [] with open(load_topo, "r") as ln: ## For each node found we are going to add it to the network as it was lines = ln.readlines() stnd = False for line in lines: if not line.startswith("#"): ## maybe found other global properties if line.startswith("NumOfHosts"): numofhosts = int(line.split("=")[1].split(";")[0]) elif line.startswith("["): node = LNode() ## start node empty then add properties stnd = True elif line.startswith("]"): ## End of node nodes.append(node) node = None stnd = False elif stnd: ## inside a node node.set(line.split(";")[0]) #node.append(line.split(";")[0]) dh = [] for ntmp in nodes: #this is a node to load info("* Loading node %d at position %s with IP %s\n" % (ntmp.get_node_num(), ntmp.get_position(), ntmp.get_ip())) xn = net.addDocker('d' + str(ntmp.get_node_num()), cls=Docker, ip=str(ntmp.get_ip()), dimage=ntmp.get_docker_image(), position=ntmp.get_position2(), range=ntmp.get_rangei(), mode=ntmp.get_mode(), equipmentModel=ntmp.get_equip_model()) container_constraint(node=xn) dh.append(xn) #Do mesh routing (?) info("\n* Adding nodes to Mesh\n") for xn in dh: hlinks = [] hlinks.append(net.addMesh(xn, ssid='meshNet')) xn.verifyingNodes(xn) ## Mesh routing is not doing a mesh, only 1 to nearby info("\n* Routing nodes through mesh\n") meshr = net.meshRouting("custom") for xn in dh: meshRouting.customMeshRouting(xn, 0, net.wifiNodes) sys.stdout.write(str(xn) + " ") sys.stdout.flush() info("** %d Nodes have been loaded\n" % numofhosts) return net, dh, numofhosts
def parameters(self): while emulationEnvironment.continue_: try: for node in emulationEnvironment.staList: for wlan in range(0, node.nWlans): if node.func[wlan] == 'mesh' or node.func[wlan] == 'adhoc': dist = listNodes.pairingNodes(node, wlan, emulationEnvironment.staList) channelParameters(node, None, wlan, dist, emulationEnvironment.staList, abs(node.speed)) else: self.nodeParameter(node, wlan) if emulationEnvironment.meshRouting == 'custom': for node in emulationEnvironment.staList: for wlan in range(0, node.nWlans): if node.func[wlan] == 'mesh': """Mesh Routing""" meshRouting.customMeshRouting(node, wlan, emulationEnvironment.staList) listNodes.clearList() except: pass
def parameters(self): while self.continue_: try: for node in self.staList: for wlan in range(0, node.nWlans): if node.func[wlan] == 'mesh' or node.func[wlan] == 'adhoc': dist = listNodes.pairingNodes(node, wlan, self.staList) if dist!=0: channelParameters(node, None, wlan, dist, self.staList, abs(node.speed)) else: self.nodeParameter(node, wlan) if meshRouting.routing == 'custom': for node in mobility.staList: for wlan in range(0, node.nWlans): if node.func[wlan] == 'mesh': """Mesh Routing""" meshRouting.customMeshRouting(node, wlan, self.staList) listNodes.clearList() except: pass
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()