Exemplo n.º 1
0
 def apInRange(self, sta, ap, wlan, dist):
     """
     When ap is in range
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination  
     """
     if self.rec_rssi:
         os.system('hwsim_mgmt -k %s %s >/dev/null 2>&1' %
                   (sta.phyID[wlan], abs(int(sta.params['rssi'][wlan]))))
     if ap not in sta.params['apsInRange']:
         sta.params['apsInRange'].append(ap)
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     else:
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     if ap == sta.params['associatedTo'][wlan]:
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         sta.params['rssi'][wlan] = rssi_
         snr_ = setChannelParams.setSNR(sta, wlan)
         sta.params['snr'][wlan] = snr_
         if sta not in ap.params['associatedStations']:
             ap.params['associatedStations'].append(sta)
         if not WmediumdServerConn.connected and dist >= 0.01:
             setChannelParams(sta, ap, wlan, dist)
         if WmediumdServerConn.connected and dist >= 0.01:
             WmediumdServerConn.send_snr_update(
                 WmediumdSNRLink(sta.wmediumdIface, ap.wmediumdIface,
                                 sta.params['snr'][wlan]))
     setChannelParams.recordParams(sta, ap)
Exemplo n.º 2
0
 def customAssociationControl(self, sta, ap, wlan, ac):
     """Mechanisms that optimize the use of the APs
     llf: Least-loaded-first
     ssf: Strongest-signal-first"""
     if ac == "llf":
         apref = sta.params['associatedTo'][wlan]
         if apref != '':
             ref_llf = len(apref.params['associatedStations'])
             if len(ap.params['associatedStations']) + 2 < ref_llf:
                 debug('iw dev %s disconnect' % sta.params['wlan'][wlan])
                 sta.pexec('iw dev %s disconnect' %
                           sta.params['wlan'][wlan])
                 self.changeAP = True
         else:
             self.changeAP = True
     elif ac == "ssf":
         distance = setChannelParams.getDistance(
             sta, sta.params['associatedTo'][wlan])
         RSSI = setChannelParams.setRSSI(sta,
                                         sta.params['associatedTo'][wlan],
                                         wlan, distance)
         refDistance = setChannelParams.getDistance(sta, ap)
         refRSSI = setChannelParams.setRSSI(sta, ap, wlan, refDistance)
         if float(refRSSI) > float(RSSI + 0.1):
             debug('iw dev %s disconnect' % sta.params['wlan'][wlan])
             sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
             self.changeAP = True
     return self.changeAP
Exemplo n.º 3
0
 def getAPsInRange(self, sta):
     """ 
     Gets all APs in range of the station. It's not used when there is no position defined.
     It's also useful for setting parameters, such as rssi, snr, among others.
     
     :param sta: station
     """
     for ap in self.accessPoints:
         rssi = []
         dist = setChannelParams.getDistance(sta, ap)
         if dist <= ap.params['range']:
             for wlan in range(0, len(sta.params['wlan'])):
                 if sta.params['rssi'][wlan] == 0:
                     self.updateParams(sta, ap, wlan)
                 rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
                 rssi.append(rssi_)
                 if ap == sta.params['associatedTo'][wlan]:
                     sta.params['rssi'][wlan] = rssi_
                     snr_ = setChannelParams.setSNR(sta, wlan)
                     sta.params['snr'][wlan] = snr_
                     ap.params['associatedStations'][sta] = sta.params['rssi'][wlan]
             sta.params['apsInRange'][ap] = rssi
             ap.params['stationsInRange'][sta] = rssi
         else:
             if ap in sta.params['apsInRange']:
                 sta.params['apsInRange'].pop(ap, None)
                 ap.params['stationsInRange'].pop(sta, None)
Exemplo n.º 4
0
    def configureWirelessLink(self, sta, ap, wlan):
        """ 
        Updates RSSI, SNR, and Others...
        
        :param sta: station
        :param ap: access point
        :param wlan: wlan ID
        """

        dist = setChannelParams.getDistance(sta, ap)
        if dist <= ap.params['range']:
            for wlan in range(0, len(sta.params['wlan'])):
                if sta.params['rssi'][wlan] == 0:
                    self.updateParams(sta, ap, wlan)
                if sta.params['associatedTo'][
                        wlan] == '' and ap not in sta.params['associatedTo']:
                    sta.params['associatedTo'][wlan] = ap
                    cls = Association
                    cls.associate_infra(sta, ap, wlan)
                    if dist >= 0.01:
                        setChannelParams(sta, ap, wlan, dist)
                    if sta not in ap.params['associatedStations']:
                        ap.params['associatedStations'].append(sta)
                rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
                sta.params['rssi'][wlan] = rssi_
                snr_ = setChannelParams.setSNR(sta, wlan)
                sta.params['snr'][wlan] = snr_
            if ap not in sta.params['apsInRange']:
                sta.params['apsInRange'].append(ap)
                ap.params['stationsInRange'][sta] = rssi_
Exemplo n.º 5
0
 def apInRange(self, sta, ap, wlan, dist):
     """
     When ap is in range
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination  
     """
     if self.rec_rssi:
         os.system('hwsim_mgmt -k %s %s >/dev/null 2>&1' %
                   (sta.phyID[wlan], abs(int(sta.params['rssi'][wlan]))))
     if ap not in sta.params['apsInRange']:
         sta.params['apsInRange'].append(ap)
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     else:
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     if ap == sta.params['associatedTo'][wlan]:
         if not WmediumdServerConn.interference_enabled:
             rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
             sta.params['rssi'][wlan] = rssi_
             snr_ = setChannelParams.setSNR(sta, wlan)
             sta.params['snr'][wlan] = snr_
         if sta not in ap.params['associatedStations']:
             ap.params['associatedStations'].append(sta)
         if dist >= 0.01:
             if WmediumdServerConn.connected:
                 if WmediumdServerConn.interference_enabled:
                     if sta.lastpos != sta.params['position']:
                         time.sleep(0.0001)
                         cls = Association
                         cls.setPositionWmediumd(sta)
                         sta.lastpos = sta.params['position']
                 else:
                     if sta.lastpos != sta.params['position']:
                         cls = Association
                         cls.setSNRWmediumd(sta,
                                            ap,
                                            snr=sta.params['snr'][wlan])
             else:
                 setChannelParams(sta, ap, wlan, dist)
     setChannelParams.recordParams(sta, ap)
Exemplo n.º 6
0
    def apInRange(self, sta, ap, wlan, dist):
        """
        When ap is in range
        
        :param sta: station
        :param ap: access point
        :param wlan: wlan ID
        :param dist: distance between source and destination  
        """

        outevent = False
        if self.rec_rssi:
            os.system('hwsim_mgmt -k %s %s >/dev/null 2>&1' %
                      (sta.phyID[wlan], abs(int(sta.params['rssi'][wlan]))))
        if ap not in sta.params['apsInRange']:
            sta.params['apsInRange'].append(ap)
            rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
            ap.params['stationsInRange'][sta] = rssi_
        else:
            rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
            ap.params['stationsInRange'][sta] = rssi_
            if sta in ap.params['associatedStations'] and ap.params[
                    'stationsInRange'][sta] > -43 and ap.func[0] == 'ap':
                sta.params['minswch'] = False
            if sta in ap.params['associatedStations'] and ap.params[
                    'stationsInRange'][sta] > -45.95 and ap.func[0] == 'ap':
                sta.params['maxswch'] = False
            outevent = True
        if ap == sta.params['associatedTo'][wlan]:
            rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
            sta.params['rssi'][wlan] = rssi_
            snr_ = setChannelParams.setSNR(sta, wlan)
            sta.params['snr'][wlan] = snr_
            if sta not in ap.params['associatedStations']:
                ap.params['associatedStations'].append(sta)
            if not WmediumdServerConn.connected and dist >= 0.01:
                setChannelParams(sta, ap, wlan, dist)
            if ap.func[0] == 'ap':
                #~ ap.params['out']=False
                if ap.params['stationsInRange'][sta] <= -44 and sta.params[
                        'minswch'] == False:
                    #~ ap.cmd('echo "%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],ap.params['controller_IP']))
                    #~ print(sta.params['mac'], ap.params['stationsInRange'][sta],ap.params['controller_IP'],ap.name)

                    #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['ASSO'],ap.params['controller_IP']))
                    #~ print 'STA ' + str(sta.params['mac']) + 'is ASSOCIATED to '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
                    ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                                (sta.params['mac'][0],
                                 ap.params['stationsInRange'][sta], "ASSO", 1,
                                 ap.params['controller_IP']))
                    sta.params['minswch'] = True
                    sta.params['x'] = len(sta.params['apsInRange']) - 1
                    ap.params['AssoMacRSSI1'][sta.params['mac'][
                        0]] = ap.params['stationsInRange'][sta]
                elif ap.params['stationsInRange'][sta] <= -46 and sta.params[
                        'maxswch'] == False:
                    #~ print 'STA ' + str(sta.params['mac']) + 'is ASSOCIATED to '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
                    ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                                (sta.params['mac'][0],
                                 ap.params['stationsInRange'][sta], "ASSO", 2,
                                 ap.params['controller_IP']))
                    #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['ASSO'],ap.params['controller_IP']))
                    sta.params['maxswch'] = True
                    sta.params['y'] = len(sta.params['apsInRange']) - 1
                    ap.params['AssoMacRSSI2'][sta.params['mac'][
                        0]] = ap.params['stationsInRange'][sta]
                    #~ if (ap.params['AssoMacRSSI1'] != {}) and (ap.params['AssoMacRSSI2'] != {}):
                    #~ if (ap.params['AssoMacRSSI1'][sta.params['mac'][0]] != None) and (ap.params['AssoMacRSSI2'][sta.params['mac'][0]] != None):
                    #~ print (ap.name, 'ASSO', sta.params['mac'], ap.params['AssoMacRSSI2'][sta.params['mac'][0]] - ap.params['AssoMacRSSI1'][sta.params['mac'][0]])
                    #~ ap.cmd('echo "%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],ap.params['controller_IP']))

                    #~ Uncomment this one for exact getrssi
                    #~ ap.cmd('echo "%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['AssoMacRSSI2'][sta.params['mac'][0]] - ap.params['AssoMacRSSI1'][sta.params['mac'][0]],'ASSO',ap.params['controller_IP']))
                    #~ print 'STA ' + str(sta.params['mac']) + 'is ASSOCIATED to '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
            if WmediumdServerConn.connected and dist >= 0.01:
                WmediumdServerConn.send_snr_update(
                    WmediumdSNRLink(sta.wmediumdIface, ap.wmediumdIface,
                                    sta.params['snr'][wlan]))
        elif ap != sta.params['associatedTo'][wlan] and sta.params[
                'x'] > 0 and ap.func[0] == 'ap':
            #~ ap.params['out'][sta.params['mac'][0]]=True
            #~ print 'STA ' + str(sta.params['mac']) + 'is in RANGE of '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
            ap.cmdPrint(
                'echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                (sta.params['mac'][0], ap.params['stationsInRange'][sta],
                 "RANGE", 1, ap.params['controller_IP']))
            #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['RANGE'],ap.params['controller_IP']))
            sta.params['x'] = sta.params['x'] - 1
            ap.params['InRgMacRSSI1'][sta.params['mac']
                                      [0]] = ap.params['stationsInRange'][sta]
            ap.params['r1_r2_sentevent'][0] = True
        elif ap != sta.params['associatedTo'][wlan] and sta.params[
                'y'] > 0 and ap.func[0] == 'ap':
            #~ ap.params['out'][sta.params['mac'][0]]=False
            #~ print 'STA ' + str(sta.params['mac']) + 'is in RANGE of '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
            ap.cmdPrint(
                'echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                (sta.params['mac'][0], ap.params['stationsInRange'][sta],
                 "RANGE", 2, ap.params['controller_IP']))
            #~ ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta], "DONE", 2, ap.params['controller_IP']))
            #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['RANGE'],ap.params['controller_IP']))
            sta.params['y'] = sta.params['y'] - 1
            ap.params['InRgMacRSSI2'][sta.params['mac']
                                      [0]] = ap.params['stationsInRange'][sta]
            ap.params['r1_r2_sentevent'][1] = True
            if ap.params['r1_r2_sentevent'] == [
                    True, True
            ] or ap.params['r1_r2_sentevent'] == [False, True]:
                ap.params['r1_r2_sentevent'] = [False, False]
            #~ if (ap.params['InRgMacRSSI1'] != {}) and (ap.params['InRgMacRSSI2'] != {}):
            #~ if (ap.params['InRgMacRSSI1'][sta.params['mac'][0]] != None) and (ap.params['InRgMacRSSI2'][sta.params['mac'][0]] != None):
            #~ print (ap.name, 'InRg', sta.params['mac'], ap.params['InRgMacRSSI2'][sta.params['mac'][0]] - ap.params['InRgMacRSSI1'][sta.params['mac'][0]])
            #~ ap.cmd('echo "%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['InRgMacRSSI2'][sta.params['mac'][0]] - ap.params['InRgMacRSSI1'][sta.params['mac'][0]],'RANGE',ap.params['controller_IP']))
            #~ elif  ap.func[0]=='ap' and ap != sta.params['associatedTo'][wlan] and float(setChannelParams.getDistance(ap, sta))>=((float(ap.params['range']))-1) and outevent==True:
            #~ if sta not in ap.params['associatedStations'] and ap.params['r1_r2_sentevent']==[True,False]:
            #~ ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta], "OUT", 1, ap.params['controller_IP']))

        setChannelParams.recordParams(sta, ap)