def getNodeListOfType(self, typeName): expInfo = self.exp.getPersistentInfo() nodeInfoByType = expInfo["nodeInfoByType"] if typeName not in nodeInfoByType: return [] else: result = nodeInfoByType[typeName]["nodes"] return [extractNodeId(node) for node in result]
def updateInfo(self): CacheNodeList = "cache-node-list.json" CacheResource = "cache-resource-server.json" # XXX: move if self.exp.hasFile(CacheNodeList): self.expNodeList = fromJson(self.exp.readFile(CacheNodeList)) else: self.expNodeList = self.exp.getNodeList() self.exp.writeFile(CacheNodeList, toJson(self.expNodeList)) self.expServer = IotlabHelper.getExpUniqueServer( self.exp, self.expNodeList) self.expServer = self.expServer.split(".")[0] if self.exp.hasFile(CacheResource): self.serverInfo = fromJson(self.exp.readFile(CacheResource)) else: self.serverInfo = self.iotlab.getResources(self.expServer) self.exp.writeFile(CacheResource, toJson(self.serverInfo)) siteInfo = self.serverInfo archi = "m3:at86rf231" nodePosList = [(extractNodeId(info["network_address"]), (float(info["x"]), float(info["y"]), float(info["z"]))) for info in siteInfo if info["archi"] == archi and info["state"] in ("Alive", "Busy")] if DisplayHack: nodePosList = [(extractNodeId(info["network_address"]), (-float(info["y"]), float(info["x"]), float(info["z"]))) for info in siteInfo if info["archi"] == archi and info["state"] in ("Alive", "Busy")] expInfo = self.exp.getPersistentInfo() nodeInfoByType = expInfo["nodeInfoByType"] #print nodeInfoByType.get("contiki-rpl-node") self.posOfNode = dict(nodePosList) nodeOfType = {} rplNodes = set() for typeName, info in nodeInfoByType.iteritems(): nodeOfType[typeName] = [ extractNodeId(node) for node in info["nodes"] ] if typeName in ["border-router", "contiki-rpl-node"]: rplNodes = rplNodes.union(set(nodeOfType[typeName])) #print posOfNode xPosList = [x for x,y,z in self.posOfNode.itervalues()] yPosList = [y for x,y,z in self.posOfNode.itervalues()] self.xPosMin, self.xPosMax = min(xPosList), max(xPosList) self.yPosMin, self.yPosMax = min(yPosList), max(yPosList) self.nodeOfType = nodeOfType #print xPosMin, xPosMax, yPosMin, yPosMax self.nodeInfo = {} layoutInfoList = [] nodeInfoFileName = "grenoble-node.txt" if os.path.exists(nodeInfoFileName): #XXX!! big hack f = open(nodeInfoFileName) for line in f.readlines(): line = line.strip() if len(line) == 0: continue tokens = [x for x in line.split(" ") if x != ""] addressParts = tokens[0].split(":") nodeId = extractNodeId(tokens[1]) address = "aaaa::200:0:0:" + addressParts[4] host = tokens[2] self.nodeInfo[nodeId] = (address, host) if nodeId not in rplNodes: continue # XXX!! another hack if nodeId not in self.posOfNode: print "(cannot find node %s)" % nodeId continue x,y,z = self.posOfNode[nodeId] if DisplayHack and x > 21.85: continue sx,sy = 4.5, 3.0 ox,oy = -60,-30 layoutInfo = { "x": (x-self.xPosMin)*sx +ox, "y": (y-self.yPosMin)*sy +oy, "id": addressParts[4], "name": "n%s" %nodeId } layoutInfoList.append(layoutInfo) # Another hack layoutStr = Foren6Helper.genLayoutFile(layoutInfoList, scale=5.0) IotlabHelper.writeFile("sample.ini", layoutStr)
def getNodeList(self): return [extractNodeId(address) for address in self.expNodeList]
#--------------------------------------------------------------------------- #RiotFirmwareFileName = "../riot/RIOT/examples/default/bin/iot-lab_M3/default.elf" #RiotFirmwareFileName = "../riot/RIOT/examples/rpl_udp/bin/iot-lab_M3/rpl_udp.elf" RiotFirmwareFileName = IotlabHelper.TypeToFirmware["riot"] nodeList = exp.getNodeList() currentNodeList = nodeList[:] currentNodeList.sort() if args.with_sniffer: print ". option --with-sniffer, putting sniffer on nodes with even IDs" tentativeSnifferNodeList = [address for address in currentNodeList if extractNodeId(address)%2 == 0] # Sniffer nodes foren6SnifferList, unusedNodeList = exp.ensureFlashedStdNodes( "foren6-sniffer", len(tentativeSnifferNodeList), tentativeSnifferNodeList, False) currentNodeList = list(set(currentNodeList).difference( set(foren6SnifferList))) currentNodeList.sort() riotRouterList, currentNodeList = exp.ensureFlashedStdNodes( "riot", AllPossibleNodes, currentNodeList, False) #--------------------------------------------------------------------------- # Save scenario #--------------------------------------------------
#--------------------------------------------------------------------------- #RiotFirmwareFileName = "../riot/RIOT/examples/default/bin/iot-lab_M3/default.elf" #RiotFirmwareFileName = "../riot/RIOT/examples/rpl_udp/bin/iot-lab_M3/rpl_udp.elf" RiotFirmwareFileName = IotlabHelper.TypeToFirmware["riot"] nodeList = exp.getNodeList() currentNodeList = nodeList[:] currentNodeList.sort() if args.with_sniffer: print ". option --with-sniffer, putting sniffer on nodes with even IDs" tentativeSnifferNodeList = [ address for address in currentNodeList if extractNodeId(address) % 2 == 0 ] # Sniffer nodes foren6SnifferList, unusedNodeList = exp.ensureFlashedStdNodes( "foren6-sniffer", len(tentativeSnifferNodeList), tentativeSnifferNodeList, False) currentNodeList = list( set(currentNodeList).difference(set(foren6SnifferList))) currentNodeList.sort() riotRouterList, currentNodeList = exp.ensureFlashedStdNodes( "riot", AllPossibleNodes, currentNodeList, False) #--------------------------------------------------------------------------- # Save scenario
def matchName(nodeRef, address): nodeId = extractNodeId(address) shortName = extractNodeName(address) return (nodeRef == address or nodeRef == nodeId or nodeRef == str(nodeId) or nodeRef == shortName)
def getNodeId(self): return extractNodeId(self.name)
def updateInfo(self): CacheNodeList = "cache-node-list.json" CacheResource = "cache-resource-server.json" # XXX: move if self.exp.hasFile(CacheNodeList): self.expNodeList = fromJson(self.exp.readFile(CacheNodeList)) else: self.expNodeList = self.exp.getNodeList() self.exp.writeFile(CacheNodeList, toJson(self.expNodeList)) self.expServer = IotlabHelper.getExpUniqueServer( self.exp, self.expNodeList) self.expServer = self.expServer.split(".")[0] if self.exp.hasFile(CacheResource): self.serverInfo = fromJson(self.exp.readFile(CacheResource)) else: self.serverInfo = self.iotlab.getResources(self.expServer) self.exp.writeFile(CacheResource, toJson(self.serverInfo)) siteInfo = self.serverInfo archi = "m3:at86rf231" nodePosList = [(extractNodeId(info["network_address"]), (float(info["x"]), float(info["y"]), float(info["z"]))) for info in siteInfo if info["archi"] == archi and "null" not in (info["network_address"], info["x"], info["y"], info["z"]) and info["state"] in ("Alive", "Busy")] if not self.args.full_topology: nodePosList = [(extractNodeId(info["network_address"]), (-float(info["y"]), float(info["x"]), float(info["z"]))) for info in siteInfo if info["archi"] == archi and "null" not in (info["network_address"], info["x"], info["y"], info["z"]) and info["state"] in ("Alive", "Busy")] expInfo = self.exp.getPersistentInfo() if self.exp.hasFile("ssh-forward-port.json"): self.sshTunnelByType = IotlabHelper.fromJson(self.exp.readFile( "ssh-forward-port.json")) else: self.sshTunnelByType = {} self.portOfNode = {} for nodeAndPortList in self.sshTunnelByType.values(): for (address, port) in nodeAndPortList: self.portOfNode[extractNodeId(address)] = port nodeInfoByType = expInfo["nodeInfoByType"] #print nodeInfoByType.get("contiki-rpl-node") self.posOfNode = dict(nodePosList) nodeOfType = {} rplNodes = set() for typeName, info in nodeInfoByType.iteritems(): nodeOfType[typeName] = [ extractNodeId(node) for node in info["nodes"] ] if typeName in ["border-router", "contiki-rpl-node"]: rplNodes = rplNodes.union(set(nodeOfType[typeName])) #print posOfNode xPosList = [x for x,y,z in self.posOfNode.itervalues()] yPosList = [y for x,y,z in self.posOfNode.itervalues()] self.xPosMin, self.xPosMax = min(xPosList), max(xPosList) self.yPosMin, self.yPosMax = min(yPosList), max(yPosList) self.nodeOfType = nodeOfType #print xPosMin, xPosMax, yPosMin, yPosMax self.nodeInfo = {} layoutInfoList = [] nodeInfoFileName = "grenoble-node.txt" if os.path.exists(nodeInfoFileName): #XXX!! big hack f = open(nodeInfoFileName) for line in f.readlines(): line = line.strip() if len(line) == 0: continue tokens = [x for x in line.split(" ") if x != ""] addressParts = tokens[0].split(":") nodeId = extractNodeId(tokens[1]) address = "aaaa::200:0:0:" + addressParts[4] host = tokens[2] self.nodeInfo[nodeId] = (address, host) if nodeId not in rplNodes: continue # XXX!! another hack if nodeId not in self.posOfNode: print "(cannot find node %s)" % nodeId continue x,y,z = self.posOfNode[nodeId] if not self.args.full_topology and x > 21.85: continue sx,sy = 4.5, 3.0 ox,oy = -60,-30 layoutInfo = { "x": (x-self.xPosMin)*sx +ox, "y": (y-self.yPosMin)*sy +oy, "id": addressParts[4], "name": "n%s" %nodeId } layoutInfoList.append(layoutInfo) # Another hack layoutStr = Foren6Helper.genLayoutFile(layoutInfoList, scale=5.0) IotlabHelper.writeFile("sample.ini", layoutStr)
def matchName(nodeRef, address): nodeId = extractNodeId(address) shortName = extractNodeName(address) return nodeRef == address or nodeRef == nodeId or nodeRef == str(nodeId) or nodeRef == shortName