Ejemplo n.º 1
0
    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!'
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
    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')
Ejemplo n.º 4
0
    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

        if self.DRAW == True:
            debug('Enabling Graph...\n')
            plot.instantiateGraph(self.MAX_X, self.MAX_Y)
            for sta in self.staList:
                self.graphInstantiateNodes(sta)
                if sta not in staMov:
                    plot.pltNode[sta].set_data(sta.params['position'][0], sta.params['position'][1])
                    plot.drawTxt(sta)
                    plot.drawCircle(sta)
            for ap in mobility.apList:
                self.graphInstantiateNodes(ap)
                for c in ap.connections:
                    line = plot.plotLine2d([ap.connections[c].params['position'][0], ap.params['position'][0]], \
                                           [ap.connections[c].params['position'][1], ap.params['position'][1]], 'b')
                    plot.plotLine(line)
            for wall in mobility.wallList:
                line = plot.plotLine2d([wall.params['initPos'][0], wall.params['finalPos'][0]], \
                                           [wall.params['initPos'][1], wall.params['finalPos'][1]], 'r', 10)
                plot.plotLine(line)
        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
                # have to verify this
                time.sleep(0.01)
        except:
            print 'Error! Mobility stopped!'
Ejemplo n.º 5
0
    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

        if self.DRAW == True:
            debug('Enabling Graph...\n')
            plot.instantiateGraph(self.MAX_X, self.MAX_Y)
            for sta in self.staList:
                self.graphInstantiateNodes(sta)
                if sta not in staMov:
                    plot.pltNode[sta].set_data(sta.params['position'][0], sta.params['position'][1])
                    plot.drawTxt(sta)
                    plot.drawCircle(sta)
            for ap in mobility.apList:
                self.graphInstantiateNodes(ap)
                for c in ap.connections:
                    line = plot.plotLine2d([ap.connections[c].params['position'][0], ap.params['position'][0]], \
                                           [ap.connections[c].params['position'][1], ap.params['position'][1]], 'b')
                    plot.plotLine(line)
            for wall in mobility.wallList:
                line = plot.plotLine2d([wall.params['initPos'][0], wall.params['finalPos'][0]], \
                                           [wall.params['initPos'][1], wall.params['finalPos'][1]], 'r', 10)
                plot.plotLine(line)
        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!'
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
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.

        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(self.modelName == 'RandomWalk'):  # # Random Walk model
            mob = random_walk(nr_nodes)
        elif(self.modelName == 'TruncatedLevyWalk'):  # # Truncated Levy Walk model
            mob = truncated_levy_walk(nr_nodes)
        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, 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:
                        plot.graphPause()
                        plot.graphUpdate(node)
        except:
            pass
Ejemplo n.º 10
0
    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)