Beispiel #1
0
    def pairingNodes(self, sta, wlan, stationList, **params):
        """Pairing nodes"""
        i = 1
        ref_distance = 0
        self.ssid_ID += 1
        cont = True
        par = []
        alreadyConn = []
        self.list = []
        self.list.append(sta)
        currentSta = sta

        while cont:
            if len(par) != 0:
                sta = par[0]
                par.pop(0)
            for ref_sta in stationList:
                if ref_sta.type == 'vehicle':
                    car = ref_sta
                    ref_sta = ref_sta.params['carsta']
                    ref_sta.params['position'] = car.params['position']
                    ref_sta.params['range'] = car.params['range']
                if ref_sta != sta and ref_sta.func[wlan] == 'mesh' :
                    dist = channelParams.getDistance(sta, ref_sta)
                    if dist >= 0.1:
                        totalRange = int(sta.params['range'])
                        ref_totalRange = int(ref_sta.params['range'])
                        if ref_totalRange > totalRange:
                            totalRange = ref_totalRange
                        if dist <= totalRange:
                            cont = True
                            ref_distance = ref_distance + dist
                            if currentSta == sta:
                                self.nodesX.append(sta)
                                self.nodesY.append(ref_sta)
                            ssid = sta.params['associatedTo'][wlan]
                            ref_ssid = ref_sta.params['associatedTo'][wlan]
                            if ssid != ref_ssid or ssid == sta.params['ssid'][wlan] or ssid == '':
                                if sta not in alreadyConn:
                                    if ref_ssid != '' and ref_ssid != ssid:
                                        alreadyConn.append(sta)
                                        sta.params['associatedTo'][wlan] = ref_sta.params['associatedTo'][wlan]
                                        self.meshAssociation(sta, wlan)
                                    elif ssid != sta.params['ssid'][wlan] + str(self.ssid_ID):
                                        alreadyConn.append(sta)
                                        sta.params['associatedTo'][wlan] = sta.params['ssid'][wlan] + str(self.ssid_ID)
                                        self.meshAssociation(sta, wlan)
                                if ref_sta not in alreadyConn:
                                    alreadyConn.append(ref_sta)
                                    ref_sta.params['associatedTo'][wlan] = sta.params['ssid'][wlan] + str(self.ssid_ID)
                                    self.meshAssociation(ref_sta, wlan)
                            if ref_sta not in self.list:
                                par.append(ref_sta)
                                self.list.append(ref_sta)
                            i += 1
            if len(par) == 0:
                cont = False
                self.ssid_ID += 1
        dist = ref_distance / i
        return dist
Beispiel #2
0
 def getAPsInRange(self, sta):
     for ap in self.apList:
         dist = channelParams.getDistance(sta, ap)
         if dist < ap.params['range']:
             if ap not in sta.params['apsInRange']:
                 sta.params['apsInRange'].append(ap)
         else:
             if ap in sta.params['apsInRange']:
                 sta.params['apsInRange'].remove(ap)
    def pairing(self, sta, wlan, stationList):
        """Pairing nodes"""
        i = 1
        ref_distance = 0
        self.dist = 0

        alreadyConn = []

        for sta_ref in stationList:
            if sta_ref != sta:
                dist = channelParams.getDistance(sta, sta_ref)
                if dist != 0.0:
                    totalRange = min(sta.params['range'], sta_ref.params['range'])
                    if dist < totalRange:
                        ref_distance = ref_distance + dist
                        i += 1
                        for wlan_ref in range(len(sta_ref.params['wlan'])):
                            if sta.params['ssid'][wlan] == sta_ref.params['ssid'][wlan_ref]:
                                if sta.params['cell'][wlan] == '':
                                    alreadyConn.append(sta)
                                    sta.params['associatedTo'][wlan] = sta.params['ssid'][wlan]
                                    sta.params['cell'][wlan] = ('02:CA:FF:EE:BA:0%s' % self.ssid_ID)
                                    iface = sta.params['wlan'][wlan]
                                    info("\nassociating %s to %s..." % (iface, sta.params['ssid'][wlan]))
                                    debug('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % \
                                          (sta.params['wlan'][wlan], sta.params['associatedTo'][wlan], self.ssid_ID))
                                    sta.pexec('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % \
                                          (sta.params['wlan'][wlan], sta.params['associatedTo'][wlan], self.ssid_ID))
                                    sta.params['frequency'][wlan] = channelParams.frequency(sta, wlan)
                                if sta.params['cell'][wlan] != sta_ref.params['cell'][wlan_ref]:
                                    if sta_ref.params['associatedTo'][wlan_ref] == sta.params['ssid'][wlan]:
                                        if sta_ref.params['cell'][wlan_ref] == '' and sta in alreadyConn:
                                            alreadyConn.append(sta_ref)
                                            iface = sta_ref.params['wlan'][wlan_ref]
                                            sta_ref.params['associatedTo'][wlan_ref] = sta.params['ssid'][wlan]
                                            sta_ref.params['cell'][wlan_ref] = ('02:CA:FF:EE:BA:0%s' % self.ssid_ID)
                                            info("\nassociating %s to %s..." % (iface, sta.params['ssid'][wlan]))
                                            debug('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % \
                                                          (sta_ref.params['wlan'][wlan_ref], sta_ref.params['associatedTo'][wlan_ref], self.ssid_ID))
                                            sta_ref.pexec('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % \
                                                          (sta_ref.params['wlan'][wlan_ref], sta_ref.params['associatedTo'][wlan_ref], self.ssid_ID))
                                            sta_ref.params['frequency'][wlan_ref] = channelParams.frequency(sta_ref, wlan_ref)
        if alreadyConn != [] and len(alreadyConn) != 1:
            for sta_ref in stationList:
                if sta_ref not in alreadyConn:
                    if sta_ref.params['cell'][wlan_ref] == sta.params['cell'][wlan]:
                        sta_ref.params['cell'][wlan_ref] = ''
        self.ssid_ID += 1

        self.dist = ref_distance / i
        return self.dist
 def customAssociationControl(self, sta, ap, wlan, ac):
     """Mechanisms that optimize the use of the APs"""
     if ac == "llf":  # useful for llf (Least-loaded-first)
         apref = sta.params['associatedTo'][wlan]
         if apref != 'NoAssociated':
             ref_llf = len(apref.params['associatedStations'])
             if len(ap.params['associatedStations']) + 2 < ref_llf:
                 self.changeAP = True
         else:
             self.changeAP = True
     elif ac == "ssf":  # useful for ssf (Strongest-signal-first)
         refDistance = channelParams.getDistance(sta, ap)
         refValue = propagationModel(sta, ap, refDistance, wlan)
         if refValue.rssi > float(sta.params['rssi'][wlan] + 1):
             self.changeAP = True
     return self.changeAP
Beispiel #5
0
 def nodeParameter(self, sta, wlan):
     for ap in self.apList:
         dist = channelParams.getDistance(sta, ap)
         self.getAPsInRange(sta)
         self.handover(sta, ap, wlan, dist)
Beispiel #6
0
    def pairing(self, sta, wlan, stationList):
        """Pairing nodes"""
        i = 1
        ref_distance = 0
        self.dist = 0

        alreadyConn = []

        for ref_sta in stationList:
            if ref_sta != sta:
                dist = channelParams.getDistance(sta, ref_sta)
                if dist != 0.0:
                    totalRange = int(sta.params['range']) + int(
                        ref_sta.params['range'])
                    if dist < totalRange:
                        ref_distance = ref_distance + dist
                        #ssid = sta.params['associatedTo'][wlan]
                        #ref_ssid = ref_sta.params['associatedTo'][wlan]
                        i += 1
                        sta.params['frequency'][
                            wlan] = channelParams.frequency(sta, wlan)
                        if sta.params['ssid'][wlan] == ref_sta.params['ssid'][
                                wlan]:
                            if sta.params['cell'][wlan] == '':
                                alreadyConn.append(sta)
                                sta.params['associatedTo'][wlan] = sta.params[
                                    'ssid'][wlan]
                                sta.params['cell'][wlan] = (
                                    '02:CA:FF:EE:BA:0%s' % self.ssid_ID)
                                iface = sta.params['wlan'][wlan]
                                print "associating %s to %s..." % (
                                    iface, sta.params['ssid'][wlan])
                                sta.pexec(
                                    'iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s'
                                    % (sta.params['wlan'][wlan],
                                       sta.params['associatedTo'][wlan],
                                       self.ssid_ID))
                                # sta.pexec('iw dev %s ibss join %s 2412' % (sta.params['wlan'][wlan], \
                                #                                           sta.params['associatedTo'][wlan]))
                                sta.params['frequency'][
                                    wlan] = channelParams.frequency(sta, wlan)
                            if sta.params['cell'][wlan] != ref_sta.params[
                                    'cell'][wlan]:
                                if ref_sta.params['associatedTo'][
                                        wlan] == sta.params['ssid'][wlan]:
                                    if ref_sta.params['cell'][
                                            wlan] == '' and sta in alreadyConn:
                                        alreadyConn.append(ref_sta)
                                        iface = ref_sta.params['wlan'][wlan]
                                        ref_sta.params['associatedTo'][
                                            wlan] = sta.params['ssid'][wlan]
                                        ref_sta.params['cell'][wlan] = (
                                            '02:CA:FF:EE:BA:0%s' %
                                            self.ssid_ID)
                                        print "associating %s to %s..." % (
                                            iface, sta.params['ssid'][wlan])
                                        ref_sta.pexec(
                                            'iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s'
                                            % (ref_sta.params['wlan'][wlan],
                                               ref_sta.params['associatedTo']
                                               [wlan], self.ssid_ID))
                                        # ref_sta.pexec('iw dev %s ibss join %s 2412' % (ref_sta.params['wlan'][wlan], \
                                        #                                               ref_sta.params['associatedTo'][wlan]))
                                        ref_sta.params['frequency'][
                                            wlan] = channelParams.frequency(
                                                ref_sta, wlan)
        if alreadyConn != [] and len(alreadyConn) != 1:
            for ref_sta in stationList:
                if ref_sta not in alreadyConn:
                    if ref_sta.params['cell'][wlan] == sta.params['cell'][
                            wlan]:
                        ref_sta.params['cell'][wlan] = ''
        self.ssid_ID += 1

        self.dist = ref_distance / i
        return self.dist
Beispiel #7
0
    def customMeshRouting(self, sta, wlan, stationList, **params):
        """Custom Mesh Routing"""
        associate = False
        controlMeshMac = []
        command = ''
        for ref_sta in stationList:
            if ref_sta.type == 'vehicle':
                ref_sta = ref_sta.params['carsta']
            for ref_wlan in range(len(ref_sta.params['wlan'])):
                if ref_sta != sta and ref_sta.func[ref_wlan] == 'mesh' and 'position' in sta.params:
                    dist = channelParams.getDistance(sta, ref_sta)
                    totalRange = int(sta.params['range'])
                    ref_totalRange = int(ref_sta.params['range'])
                    if ref_totalRange > totalRange:
                        totalRange = ref_totalRange
                    if dist <= totalRange:
                        if ref_sta.func[ref_wlan] == 'mesh':
                            if sta.params['associatedTo'][wlan] == ref_sta.params['associatedTo'][ref_wlan]:
                                associate = True
                elif 'position' not in sta.params:
                    associate = True

        """Adding all reached target paths"""
        if associate:
            exist = []
            sta_ref = []
            sta_ref.append(sta)
            j = 0
            exist.append(sta)
            while j < len(stationList):
                j += 1
                if sta_ref == []:
                    break
                else:
                    newsta = sta_ref[0]
                for x, y in zip(listNodes.nodesX, listNodes.nodesY):
                    if x == sta and y not in exist:
                        command = 'iw dev %s mpath new %s next_hop %s' % (sta.params['wlan'][wlan], \
                                                                          y.meshMac[wlan], y.meshMac[wlan])
                        debug('\n'+command)
                        sta.pexec(command)
                        exist.append(y)
                        controlMeshMac.append(y.meshMac[wlan])
                        sta_ref.append(y)
                    elif x == newsta and y not in exist:
                        command = 'iw dev %s mpath new %s next_hop %s' % (sta.params['wlan'][wlan], \
                                                                          y.meshMac[wlan], x.meshMac[wlan])
                        debug('\n'+command)
                        sta.pexec(command)
                        exist.append(y)
                        controlMeshMac.append(y.meshMac[wlan])
                        sta_ref.append(y)
                if newsta in sta_ref:
                    sta_ref.remove(newsta)

        """delete all unknown paths"""
        if associate:
            for ref_sta in stationList:
                for ref_wlan in range(len(ref_sta.params['wlan'])):
                    if ref_sta != sta and ref_sta.func[ref_wlan] == 'mesh' :
                        if ref_sta.type == 'vehicle':
                            ref_wlan = 0
                            ref_sta = ref_sta.params['carsta']
                        if ref_sta.meshMac[ref_wlan] not in controlMeshMac:
                            sta.pexec('iw dev %s mpath del %s' % (sta.params['wlan'][wlan], ref_sta.meshMac[ref_wlan]))

        """mesh leave"""
        if associate == False:
            debug('\niw dev %s mesh leave' % sta.params['wlan'][wlan])
            sta.pexec('iw dev %s mesh leave' % sta.params['wlan'][wlan])
            sta.params['associatedTo'][wlan] = ''