def __init__(self, mininet, stdin=sys.stdin, script=None): """Start and run interactive or batch mode CLI mininet: Mininet network object stdin: standard input for CLI script: script to run in batch mode""" if mobility.isMobility == False and mobility.DRAW: nodes = mobility.staList + mobility.apList plot.instantiateGraph(mobility.MAX_X, mobility.MAX_Y) plot.plotGraph(nodes, mobility.wallList, mobility.staMov, **mobility.dic) plot.graphPause() self.mn = mininet # Local variable bindings for py command self.locals = { 'net': mininet } # Attempt to handle input self.stdin = stdin self.inPoller = poll() self.inPoller.register(stdin) self.inputFile = script Cmd.__init__(self) info('*** Starting CLI:\n') if self.inputFile: self.do_source(self.inputFile) return self.initReadline() self.run()
def mobilityPositionDefined(self, initial_time, final_time, staMov): """ ongoing Mobility """ t_end = time.time() + final_time t_initial = time.time() + initial_time currentTime = time.time() i = 1 nodes = self.staList + self.apList dic = dict() dic['max_x'] = self.MAX_X dic['max_y'] = self.MAX_Y if self.DRAW == True: plot.instantiateGraph(self.MAX_X, self.MAX_Y) plot.plotGraph(nodes, mobility.wallList, staMov, **dic) try: while time.time() < t_end and time.time() > t_initial: if self.continue_: if time.time() - currentTime >= i: for sta in staMov: if time.time() - currentTime >= sta.startTime and time.time() - currentTime <= sta.endTime: x = float(sta.params['position'][0]) + float(self.moveFac[sta][0]) y = float(sta.params['position'][1]) + float(self.moveFac[sta][1]) z = float(sta.params['position'][2]) + float(self.moveFac[sta][2]) sta.params['position'] = x, y, z for wlan in range(0, len(sta.params['wlan'])): self.nodeParameter(sta, wlan) if self.DRAW: plot.graphPause() plot.graphUpdate(sta) i += 1 except: print 'Error! Mobility stopped!'
def instantiateGraph(mininet): MAX_X = mininet.MAX_X MAX_Y = mininet.MAX_Y nodes = mininet.stations + mininet.accessPoints for node in nodes: replayingMobility.addNode(node) plot.instantiateGraph(MAX_X, MAX_Y) plot.plotGraph(nodes, [], [], MAX_X, MAX_Y)
def positionDefined(self, init_time=0, final_time=0, stations=None, aps=None, walls=None, staMov=None, dstConn=None, srcConn=None, plotnodes=None, MAX_X=0, MAX_Y=0): """ ongoing Mobility """ t_end = time.time() + final_time t_initial = time.time() + init_time currentTime = time.time() i = 1 self.staList = stations self.apList = aps self.wallList = walls nodes = self.staList + self.apList + plotnodes dic = dict() dic['max_x'] = MAX_X dic['max_y'] = MAX_Y if self.DRAW == True: plot.instantiateGraph(MAX_X, MAX_Y) plot.plotGraph(nodes, self.wallList, staMov, srcConn, dstConn, **dic) try: while time.time() < t_end and time.time() > t_initial: if self.continue_: if time.time() - currentTime >= i: for sta in staMov: if time.time( ) - currentTime >= sta.startTime and time.time( ) - currentTime <= sta.endTime: x = float(sta.params['position'][0]) + float( self.moveFac[sta][0]) y = float(sta.params['position'][1]) + float( self.moveFac[sta][1]) z = float(sta.params['position'][2]) + float( self.moveFac[sta][2]) sta.params['position'] = x, y, z for wlan in range(0, len(sta.params['wlan'])): self.nodeParameter(sta, wlan) if self.DRAW: plot.graphPause() plot.graphUpdate(sta) i += 1 except: info('Error! Mobility stopped!\n')
def __init__(self, mininet, stdin=sys.stdin, script=None): """Start and run interactive or batch mode CLI mininet: Mininet network object stdin: standard input for CLI script: script to run in batch mode""" if mobility.isMobility == False and mobility.DRAW: staMov = [] for sta in mobility.staList: if 'position' not in sta.params: staMov.append(sta) sta.params['position'] = 0,0,0 if mobility.apList == []: mobility.apList = mininet.accessPoints if mobility.staList == []: mobility.staList = mininet.stations nodes = mininet.stations + mininet.accessPoints plot.instantiateGraph(mininet.MAX_X, mininet.MAX_Y) plot.plotGraph(nodes, mininet.walls, staMov, **mobility.dic) plot.graphPause() self.mn = mininet # Local variable bindings for py command self.locals = { 'net': mininet } # Attempt to handle input self.stdin = stdin self.inPoller = poll() self.inPoller.register(stdin) self.inputFile = script Cmd.__init__(self) info('*** Starting CLI:\n') if self.inputFile: self.do_source(self.inputFile) return self.initReadline() self.run()
def models(self, nodes=None, model=None, min_v=0, max_v=0, seed=None, staMov=None, **mobilityparam): np.random.seed(seed) # simulation area (units) MAX_X, MAX_Y = self.MAX_X, self.MAX_Y dic = dict() dic['max_x'] = MAX_X dic['max_y'] = MAX_Y # max waiting time MAX_WT = 100. for node in nodes: if node.max_x == 0: node.max_x = MAX_X if node.max_y == 0: node.max_y = MAX_Y if node.max_v == 0: node.max_v = max_v if node.min_v == 0: node.min_v = min_v debug('Setting the mobility model %s' % model) if (model == 'RandomWalk'): # Random Walk model mob = random_walk(staMov) elif (model == 'TruncatedLevyWalk'): # Truncated Levy Walk model mob = truncated_levy_walk(staMov) elif (model == 'RandomDirection'): # Random Direction model mob = random_direction(staMov, dimensions=(MAX_X, MAX_Y)) elif (model == 'RandomWayPoint'): # Random Waypoint model mob = random_waypoint(staMov, wt_max=MAX_WT) elif (model == 'GaussMarkov'): # Gauss-Markov model mob = gauss_markov(staMov, alpha=0.99) elif (model == 'ReferencePoint'): # Reference Point Group model mob = reference_point_group(staMov, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif (model == 'TimeVariantCommunity' ): # Time-variant Community Mobility Model mob = tvc(staMov, dimensions=(MAX_X, MAX_Y), aggregation=[0.5, 0.], epoch=[100, 100]) else: raise Exception("Model not defined!") if self.DRAW: plot.instantiateGraph(self.MAX_X, self.MAX_Y) plot.plotGraph(nodes, mobility.wallList, staMov, **dic) for xy in mob: i = 0 for n in range(0, len(nodes)): node = nodes[n] if node in staMov: if 'station' == node.type: node.params['position'] = xy[i][0], xy[i][1], 0 i += 1 if self.DRAW: plot.pltNode[node].set_data(xy[:, 0], xy[:, 1]) plot.drawTxt(node) plot.drawCircle(node) if self.DRAW: plot.graphUpdate(node) plot.graphPause()
def models(self, model=None, staMov=None, min_v=0, max_v=0, seed=None, stations=None, aps=None, dstConn=None, srcConn=None, walls=None, plotNodes=None, MAX_X=0, MAX_Y=0): np.random.seed(seed) self.staList = stations self.apList = aps self.wallList = walls nodes = self.staList + self.apList + plotNodes dic = dict() dic['max_x'] = MAX_X dic['max_y'] = MAX_Y # max waiting time MAX_WT = 100. for sta in self.staList: if sta.max_x == 0: sta.max_x = MAX_X if sta.max_y == 0: sta.max_y = MAX_Y if sta.max_v == 0: sta.max_v = max_v if sta.min_v == 0: sta.min_v = min_v debug('Configuring the mobility model %s' % model) if (model == 'RandomWalk'): # Random Walk model mob = random_walk(staMov) elif (model == 'TruncatedLevyWalk'): # Truncated Levy Walk model mob = truncated_levy_walk(staMov) elif (model == 'RandomDirection'): # Random Direction model mob = random_direction(staMov, dimensions=(MAX_X, MAX_Y)) elif (model == 'RandomWayPoint'): # Random Waypoint model mob = random_waypoint(staMov, wt_max=MAX_WT) elif (model == 'GaussMarkov'): # Gauss-Markov model mob = gauss_markov(staMov, alpha=0.99) elif (model == 'ReferencePoint'): # Reference Point Group model mob = reference_point_group(staMov, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif (model == 'TimeVariantCommunity' ): # Time-variant Community Mobility Model mob = tvc(staMov, dimensions=(MAX_X, MAX_Y), aggregation=[0.5, 0.], epoch=[100, 100]) else: raise Exception("Model not defined!") if self.DRAW: plot.instantiateGraph(MAX_X, MAX_Y) plot.plotGraph(nodes, self.wallList, staMov, srcConn, dstConn, **dic) for xy in mob: i = 0 for node in staMov: node.params['position'] = xy[i][0], xy[i][1], 0 i += 1 if self.DRAW: plot.pltNode[node].set_data(xy[:, 0], xy[:, 1]) plot.drawTxt(node) plot.drawCircle(node) if self.DRAW: plot.graphUpdate(node) plot.graphPause()