示例#1
0
    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

        # 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

        if self.DRAW:
            plot2d.instantiateGraph(MAX_X, MAX_Y)
            plot2d.plotGraph(nodes, srcConn, dstConn, MAX_X, MAX_Y)
            plot2d.graphPause()

        if staMov != None:            
            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:
                self.startMobilityModelGraph(mob, staMov)
            else:
                self.startMobilityModelNoGraph(mob, staMov)
示例#2
0
    def models(self, stations=None, aps=None, model=None, staMov=None, min_v=0, max_v=0, seed=None,
               dstConn=None, srcConn=None, walls=None, plotNodes=None, MAX_X=0, MAX_Y=0):
        """ 
        Used when a mobility model is applied
        
        :param stations: list of stations
        :param aps: list of access points
        :param model: mobility model
        :param staMov: list of nodes with mobility
        :param min_v: minimum velocity
        :param max_v: maximum velocity
        :param speed: speed
        :param srcConn:  list of connections for source nodes
        :param dstConn:  list of connections for destination nodes
        :param walls: list of walls (not used yet)
        :param plotNodes: list of nodes to be plotted (including hosts and switches)
        :param MAX_X: Maximum value for X
        :param MAX_Y: Maximum value for Y
        """

        np.random.seed(seed)
        
        self.stations = stations
        self.accessPoints = aps
        self.wallList = walls
        nodes = self.stations + self.accessPoints + plotNodes

        # max waiting time
        MAX_WT = 100.

        for sta in self.stations:
            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

        if self.DRAW:
            plot2d.instantiateGraph(MAX_X, MAX_Y)
            plot2d.plotGraph(nodes, srcConn, dstConn, MAX_X, MAX_Y)
            plot2d.graphPause()

        if staMov != None:            
            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("Mobility Model not defined or doesn't exist!")
            
            if self.DRAW:
                self.startMobilityModelGraph(mob, staMov)
            else:
                self.startMobilityModelNoGraph(mob, staMov)
示例#3
0
    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()
示例#4
0
    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()
示例#5
0
    def models(self, nodes=None, model=None, max_x=None, max_y=None, min_v=None, 
               max_v=None, seed=None, staMov=None, **mobilityparam):
        
        self.modelName = model
        np.random.seed(seed)
        
        # number of nodes
        nr_nodes = len(staMov)
        
        # simulation area (units)
        MAX_X, MAX_Y = max_x, max_y
        
        # max and min velocity
        MIN_V, MAX_V = min_v, max_v
        
        # max waiting time
        MAX_WT = 100.
        
        if(self.modelName=='RandomWalk'): ## Random Walk model            
            mob = random_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) 
        elif(self.modelName=='TruncatedLevyWalk'): ## Truncated Levy Walk model
            mob = truncated_levy_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) 
        elif(self.modelName=='RandomDirection'): ## Random Direction model            
            mob = random_direction(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V)) 
        elif(self.modelName=='RandomWayPoint'): ## Random Waypoint model           
            mob = random_waypoint(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT) 
        elif(self.modelName=='GaussMarkov'): ## Gauss-Markov model           
            mob = gauss_markov(nr_nodes, dimensions=(MAX_X, MAX_Y), alpha=0.99) 
        elif(self.modelName=='ReferencePoint'): ## Reference Point Group model           
            mob = reference_point_group(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=0.5) 
        elif(self.modelName=='TimeVariantCommunity'): ## Time-variant Community Mobility Model            
            mob = tvc(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100])        
        else:
            print 'Model not defined!'

        if emulationEnvironment.DRAW:
            debug('Enabling Graph...\n')
            plot.instantiateGraph(self.MAX_X, self.MAX_Y)
            for node in nodes:
                self.instatiateNodes(node)
                if node not in staMov or 'accessPoint' == node.type:
                    plot.pltNode[node].set_data(node.position[0],node.position[1])
                    plot.drawTxt(node)
                    plot.drawCircle(node)  
                    if node.type == 'accessPoint': 
                        for c in node.connections:
                            line = plot.plotLine2d([node.connections[c].position[0],node.position[0]], \
                                                   [node.connections[c].position[1],node.position[1]], 'b')
                            plot.plotLine(line)    
                            
        #Sometimes getting the error: Failed to connect to generic netlink.
        try:
            if model!='':
                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.position = xy[i][0], xy[i][1], 0
                                i += 1                       
                                if emulationEnvironment.DRAW:
                                    plot.pltNode[node].set_data(xy[:,0],xy[:,1])
                                    plot.drawTxt(node)
                                    plot.drawCircle(node)
                            #self.parameters()
                    if emulationEnvironment.DRAW:
                            plt.title("Mininet-WiFi Graph")
                            plt.draw()   
        except:
            pass               
    def models(self, nodes=None, model=None, min_v=None, max_v=None, seed=None,
               staMov=None, **mobilityparam):

        np.random.seed(seed)

        # simulation area (units)
        MAX_X, MAX_Y = self.MAX_X, self.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('Chossing 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:
            debug('Enabling Graph...\n')
            plot.instantiateGraph(self.MAX_X, self.MAX_Y)
            for node in nodes:
                self.graphInstantiateNodes(node)
                if node not in staMov or 'accessPoint' == node.type:
                    plot.pltNode[node].set_data(node.params['position'][0], node.params['position'][1])
                    plot.drawTxt(node)
                    plot.drawCircle(node)
                    if node.type == 'accessPoint':
                        for c in node.connections:
                            line = plot.plotLine2d([node.connections[c].params['position'][0], node.params['position'][0]], \
                                                   [node.connections[c].params['position'][1], node.params['position'][1]], 'b')
                            plot.plotLine(line)

        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.graphPause()
                plot.graphUpdate(node)
示例#7
0
 def models(self, nodes=None, model=None, max_x=None, max_y=None, min_v=None, 
            max_v=None, seed=None, staMov=None, **mobilityparam):
     
     self.modelName = model
     np.random.seed(seed)
     
     # number of nodes
     nr_nodes = staMov
     
     # simulation area (units)
     MAX_X, MAX_Y = max_x, max_y
     
     # max and min velocity
     MIN_V, MAX_V = min_v, max_v
     
     # max waiting time
     MAX_WT = 100.
     
     if(self.modelName=='RandomWalk'): ## Random Walk model            
         mob = random_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) 
     elif(self.modelName=='TruncatedLevyWalk'): ## Truncated Levy Walk model
         mob = truncated_levy_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) 
     elif(self.modelName=='RandomDirection'): ## Random Direction model            
         mob = random_direction(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V)) 
     elif(self.modelName=='RandomWayPoint'): ## Random Waypoint model           
         mob = random_waypoint(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT) 
     elif(self.modelName=='GaussMarkov'): ## Gauss-Markov model           
         mob = gauss_markov(nr_nodes, dimensions=(MAX_X, MAX_Y), alpha=0.99) 
     elif(self.modelName=='ReferencePoint'): ## Reference Point Group model           
         mob = reference_point_group(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=0.5) 
     elif(self.modelName=='TimeVariantCommunity'): ## Time-variant Community Mobility Model            
         mob = tvc(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100])        
     else:
         print 'Model not defined!'
     
     if self.DRAW:
         debug('Enabling Graph...\n')
         plot.instantiateGraph(self.MAX_X, self.MAX_Y)
         for node in nodes:
             self.graphInstantiateNodes(node)
             if node not in staMov or 'accessPoint' == node.type:
                 plot.pltNode[node].set_data(node.params['position'][0],node.params['position'][1])
                 plot.drawTxt(node)
                 plot.drawCircle(node)  
                 if node.type == 'accessPoint': 
                     for c in node.connections:
                         line = plot.plotLine2d([node.connections[c].params['position'][0],node.params['position'][0]], \
                                                [node.connections[c].params['position'][1],node.params['position'][1]], 'b')
                         plot.plotLine(line)
                         
     #Sometimes getting the error: Failed to connect to generic netlink.
     try:
         if model!='':
             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:
                         plt.title("Mininet-WiFi Graph")
                         plt.draw()   
     except:
         pass