Ejemplo n.º 1
0
 def models(self, wifiNodes=None, model=None, max_x=None, max_y=None, min_v=None, max_v=None, 
            manual_aprange=-10, n_staMov=None, ismobility=None, llf=False, seed=None,
            **mobilityparam):
     
     accessPoint.manual_apRange = manual_aprange
     self.modelName = model
     self.ismobility = ismobility
     self.leastLoadFirst = llf
     np.random.seed(seed)
     
     # set this to true if you want to plot node positions
     self.DRAW = self.plotGraph
     
     self.cancelPlot = True
     
     # number of nodes
     nr_nodes = n_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.DRAW:
         plt.ion()
         ax = plt.subplot(111)
         line, = ax.plot(range(mobility.MAX_X), range(mobility.MAX_X), linestyle='', marker='.', ms=10, mfc='blue')
         self.plottxt = {}
         
         for node in wifiNodes:
             if node.type == 'station' and str(node) not in station.fixedPosition:
                 self.plottxt[str(node)] = ax.annotate(str(node), xy=(0, 0))
                 
             if str(node) in station.fixedPosition:
                 self.plottxt[node] = ax.annotate(node, xy=(node.position[0], node.position[1]))
                 self.plotsta[node], = ax.plot(range(mobility.MAX_X), range(mobility.MAX_Y), \
                                               linestyle='', marker='.', ms=12, mfc='blue')
                 self.plotsta[node].set_data(node.position[0], node.position[1])
                            
     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)
     else:
         print 'Model not defined or wrong!'
     
     ## Reference Point Group model
     #groups = [4 for _ in range(10)]
     #nr_nodes = sum(groups)
     #rpg = reference_point_group(groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)
     
     ## Time-variant Community Mobility Model
     #groups = [4 for _ in range(10)]
     #nr_nodes = sum(groups)
     #tvcm = tvc(groups, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100])
     oneTime = []
             
     if model!='':
         try:
             for xy in mob:
                 if self.DRAW:
                     line.set_data(xy[:,0],xy[:,1])
                 for n in range (0,len(wifiNodes)):
                     node = wifiNodes[n]
                     if 'accessPoint' == node.type and str(node) not in oneTime:
                         ap = node
                         pos_zero = ap.startPosition[0]
                         pos_one = ap.startPosition[1]
                         ap.position = pos_zero, pos_one, 0     
                         if self.DRAW:
                             plt.plot([pos_zero], [pos_one], 'ro')
                             plt.text(int(pos_zero), int(pos_one), str(node))
                             ax.add_patch(
                                 patches.Circle((pos_zero, pos_one),
                                 ap.range, fill=True, alpha=0.1
                                 )
                             )
                         oneTime.append(str(wifiNodes[n]))
                     elif 'accessPoint' != node.type:
                         if str(node) not in station.fixedPosition:
                             pos_zero = xy[n][0]
                             pos_one = xy[n][1]
                             if self.DRAW:
                                 self.plottxt[str(node)].xytext = (pos_zero, pos_one)
                             node.position = pos_zero, pos_one, 0
                             for ap in accessPoint.list:
                                 sta = node
                                 distance = self.getDistance(sta, ap)
                                 association.setInfraParameters(sta, ap, distance, '')
                 if self.DRAW:
                     plt.title("Mininet-WiFi Graph")
                     plt.draw()
         except:
             print "Graph Stopped!"  
Ejemplo n.º 2
0
 def models(self, wifiNodes, associatedAP, startPosition, stationName, modelName,
            max_x, max_y, min_v, max_v):
     
     self.modelName = modelName
     
     # set this to true if you want to plot node positions
     DRAW = self.plotGraph
     
     self.cancelPlot = True
     
     # number of nodes
     nr_nodes = stationName
     
     # 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 DRAW:
         import matplotlib.pyplot as plt
         plt.ion()
         ax = plt.subplot(111)
         line, = ax.plot(range(MAX_X), range(MAX_X), linestyle='', marker='.', ms=12, mfc='blue')
             
     np.random.seed(0xffff)
     
     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))
     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)
     else:
         print 'Model not defined or wrong!'
     
     ## Reference Point Group model
     #groups = [4 for _ in range(10)]
     #nr_nodes = sum(groups)
     #rpg = reference_point_group(groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)
     
     ## Time-variant Community Mobility Model
     #groups = [4 for _ in range(10)]
     #nr_nodes = sum(groups)
     #tvcm = tvc(groups, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100])
     oneTime = []
             
     if modelName!='':
         try:
             for xy in mob:
                 if DRAW:
                     line.set_data(xy[:,0],xy[:,1])
                     for n in range (0,len(wifiNodes)):
                         self.position = []
                         if str(wifiNodes[n])[:2]=='ap' and str(wifiNodes[n]) not in oneTime:
                             self.position.append(startPosition[str(wifiNodes[n])][0])
                             self.position.append(startPosition[str(wifiNodes[n])][1])
                             self.position.append(0)
                             self.nodePosition[str(wifiNodes[n])] = self.position
                             plt.plot([startPosition[str(wifiNodes[n])][0]], [startPosition[str(wifiNodes[n])][1]], 'ro')
                             plt.text(int(startPosition[str(wifiNodes[n])][0]), int(startPosition[str(wifiNodes[n])][1]), str(wifiNodes[n]))
                             ax.add_patch(
                                 patches.Circle((startPosition[str(wifiNodes[n])][0], startPosition[str(wifiNodes[n])][1]),
                                 self.range(accessPoint.apMode[str(str(wifiNodes[n]))]), fill=True,  alpha=0.1
                                 )
                             )
                             oneTime.append(str(wifiNodes[n]))
                         elif str(wifiNodes[n])[:2]!='ap':
                             self.position.append(xy[n][0])
                             self.position.append(xy[n][1])
                             self.position.append(0)
                             self.nodePosition[str(wifiNodes[n])] = self.position
                             distance = self.getDistance(src = str(wifiNodes[n]), dst = associatedAP[str(wifiNodes[n])], pos_src = self.position, pos_dst=startPosition[str(associatedAP[str(wifiNodes[n])])])
                             association.setInfraParameters(wifiNodes[n], station.staMode[str(wifiNodes[n])], distance)
                     plt.title("Mininet-WiFi Graph")
                     plt.draw()
                 else:
                     for n in range (0,len(wifiNodes)):
                         self.position = []
                         if str(wifiNodes[n])[:2]=='ap' and str(wifiNodes[n]) not in oneTime:
                             self.position.append(startPosition[str(wifiNodes[n])][0])
                             self.position.append(startPosition[str(wifiNodes[n])][1])
                             self.position.append(0)
                             self.nodePosition[str(wifiNodes[n])] = self.position
                             oneTime.append(str(wifiNodes[n]))
                         if str(wifiNodes[n])[:2]!='ap':
                             self.position.append(xy[n][0])
                             self.position.append(xy[n][1])
                             self.position.append(0)
                             self.nodePosition[str(wifiNodes[n])] = self.position
                             distance = self.getDistance(src = str(wifiNodes[n]), dst = associatedAP[str(wifiNodes[n])], pos_src = self.position, pos_dst=startPosition[str(associatedAP[str(wifiNodes[n])])])
                             association.setInfraParameters(wifiNodes[n], station.staMode[str(wifiNodes[n])], distance)
         except:
             print "Graphic Stopped!"  
Ejemplo n.º 3
0
    def models(self,
               wifiNodes=None,
               model=None,
               max_x=None,
               max_y=None,
               min_v=None,
               max_v=None,
               manual_aprange=-10,
               n_staMov=None,
               ismobility=None,
               llf=False,
               seed=None,
               **mobilityparam):

        accessPoint.manual_apRange = manual_aprange
        self.modelName = model
        self.ismobility = ismobility
        self.leastLoadFirst = llf
        np.random.seed(seed)

        # set this to true if you want to plot node positions
        self.DRAW = self.plotGraph

        self.cancelPlot = True

        # number of nodes
        nr_nodes = n_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.DRAW:
            plt.ion()
            ax = plt.subplot(111)
            line, = ax.plot(range(mobility.MAX_X),
                            range(mobility.MAX_X),
                            linestyle='',
                            marker='.',
                            ms=10,
                            mfc='blue')
            self.plottxt = {}

            for node in wifiNodes:
                if node.type == 'station' and str(
                        node) not in station.fixedPosition:
                    self.plottxt[str(node)] = ax.annotate(str(node), xy=(0, 0))

                if str(node) in station.fixedPosition:
                    self.plottxt[node] = ax.annotate(node,
                                                     xy=(node.position[0],
                                                         node.position[1]))
                    self.plotsta[node], = ax.plot(range(mobility.MAX_X), range(mobility.MAX_Y), \
                                                  linestyle='', marker='.', ms=12, mfc='blue')
                    self.plotsta[node].set_data(node.position[0],
                                                node.position[1])

        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)
        else:
            print 'Model not defined or wrong!'

        ## Reference Point Group model
        #groups = [4 for _ in range(10)]
        #nr_nodes = sum(groups)
        #rpg = reference_point_group(groups, dimensions=(MAX_X, MAX_Y), aggregation=0.5)

        ## Time-variant Community Mobility Model
        #groups = [4 for _ in range(10)]
        #nr_nodes = sum(groups)
        #tvcm = tvc(groups, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100])
        oneTime = []

        if model != '':
            try:
                for xy in mob:
                    if self.DRAW:
                        line.set_data(xy[:, 0], xy[:, 1])
                    for n in range(0, len(wifiNodes)):
                        node = wifiNodes[n]
                        if 'accessPoint' == node.type and str(
                                node) not in oneTime:
                            ap = node
                            pos_zero = ap.startPosition[0]
                            pos_one = ap.startPosition[1]
                            ap.position = pos_zero, pos_one, 0
                            if self.DRAW:
                                plt.plot([pos_zero], [pos_one], 'ro')
                                plt.text(int(pos_zero), int(pos_one),
                                         str(node))
                                ax.add_patch(
                                    patches.Circle((pos_zero, pos_one),
                                                   ap.range,
                                                   fill=True,
                                                   alpha=0.1))
                            oneTime.append(str(wifiNodes[n]))
                        elif 'accessPoint' != node.type:
                            if str(node) not in station.fixedPosition:
                                pos_zero = xy[n][0]
                                pos_one = xy[n][1]
                                if self.DRAW:
                                    self.plottxt[str(node)].xytext = (pos_zero,
                                                                      pos_one)
                                node.position = pos_zero, pos_one, 0
                                for ap in accessPoint.list:
                                    sta = node
                                    distance = self.getDistance(sta, ap)
                                    association.setInfraParameters(
                                        sta, ap, distance, '')
                    if self.DRAW:
                        plt.title("Mininet-WiFi Graph")
                        plt.draw()
            except:
                print "Graph Stopped!"