Пример #1
0
 def rssi(self, mininet, propagationModel='', n=0):
     #if mobility.DRAW:
     #    instantiateGraph(mininet)
     currentTime = time.time()
     staList = mininet.stations
     ang = {}
     for sta in staList:
         ang[sta] = random.uniform(0, 360)
         sta.params['frequency'][0] = setChannelParams.frequency(sta, 0)
     while True:
         if len(staList) == 0:
             break
         time_ = time.time() - currentTime
         for sta in staList:
             if hasattr(sta, 'time'):
                 if time_ >= sta.time[0]:
                     ap = sta.params['associatedTo'][0]  # get AP
                     sta.params['rssi'][0] = sta.rssi[0]
                     if ap != '':
                         rssi = sta.rssi[0]
                         dist = int('%d' % self.calculateDistance(sta, ap, rssi, propagationModel, n))
                         self.moveNodeTo(sta, ap, dist, ang[sta])
                         setChannelParams(sta, ap, 0, dist)
                     del sta.rssi[0]
                     del sta.time[0]
                 if len(sta.time) == 0:
                     staList.remove(sta)
         time.sleep(0.01)
Пример #2
0
    def parameters(self):
        """ 
        Applies channel params and handover
        """
        meshNodes = []
        for node in self.mobilityNodes:
            for wlan in range(0, len(node.params['wlan'])):
                if node.func[wlan] == 'mesh' or node.func[wlan] == 'adhoc':
                    meshNodes.append(node)

        while True:
            for node in self.mobilityNodes:
                for wlan in range(0, len(node.params['wlan'])):
                    if node.func[wlan] == 'mesh' or node.func[wlan] == 'adhoc':
                        if node.type == 'vehicle':
                            node = node.params['carsta']
                            wlan = 0
                        dist = listNodes.pairingNodes(node, wlan, meshNodes)
                        if WmediumdServerConn.connected == False and dist >= 0.01:
                            setChannelParams(sta=node, wlan=wlan, dist=dist)
                    else:
                        self.handoverCheck(node, wlan)
            if meshRouting.routing == 'custom':
                meshRouting(meshNodes)
            # have to verify this
            eval(self.continueParams)
Пример #3
0
 def rssi(self, propagationModel='', n=0):
     if mobility.DRAW:
         instantiateGraph()
     currentTime = time.time()
     staList = mobility.stations
     ang = {}
     for sta in staList:
         ang[sta] = random.uniform(0, 360)
         sta.params['frequency'][0] = setChannelParams.frequency(sta, 0)
     continue_ = True
     while continue_:
         continue_ = False
         time_ = time.time() - currentTime
         for sta in staList:
             if hasattr(sta, 'time'):
                 continue_ = True
                 if time_ >= sta.time[0]:
                     ap = sta.params['associatedTo'][0]  # get AP
                     sta.params['rssi'][0] = sta.rssi[0]
                     if ap != '':
                         dist = self.calculateDistance(
                             sta, ap, sta.rssi[0], propagationModel, n)
                         self.moveStationTo(sta, ap, dist, ang[sta])
                         setChannelParams(sta, ap, dist, 0)
                     del sta.rssi[0]
                     del sta.time[0]
                 if len(sta.time) == 0:
                     staList.remove(sta)
         time.sleep(0.01)
Пример #4
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)
Пример #5
0
    def parameters_(self, node=None):
        """ 
        have to check it!
        Applies channel params and handover
        """
        if node == None:
            nodes = self.stations 
        else:
            nodes = []
            nodes.append(node)  
        for node_ in self.accessPoints:
            if 'link' in node_.params and node_.params['link'] == 'mesh':
                nodes.append(node_)

        for node in nodes:
            for wlan in range(0, len(node.params['wlan'])):
                if node.func[wlan] == 'mesh' or node.func[wlan] == 'adhoc':
                    if node.type == 'vehicle':
                        node = node.params['carsta']
                        wlan = 0
                    dist = listNodes.pairingNodes(node, wlan, nodes)
                    if WmediumdServerConn.connected == False and dist >= 0.01:
                        setChannelParams(sta=node, wlan=wlan, dist=dist)
                else:
                    self.handoverCheck(node, wlan)
        if meshRouting.routing == 'custom':
            meshRouting(nodes)
        # have to verify this
        eval(self.continueParams)        
Пример #6
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_
Пример #7
0
 def handover(self, sta, ap, wlan, dist):
     """
     handover
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination   
     """
     associated = True        
     
     if dist > ap.params['range']:
         if ap == sta.params['associatedTo'][wlan]:
             sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
             sta.params['associatedTo'][wlan] = ''
             sta.params['rssi'][wlan] = 0
             sta.params['snr'][wlan] = 0
             sta.params['channel'][wlan] = 0
             sta.params['frequency'][wlan] = 0
             ap.params['associatedStations'].pop(sta, None)
     else:
         if dist >= 0.01 and sta.params['associatedTo'][wlan] == ap:
             self.updateParams(sta, ap, wlan)
             setChannelParams(sta, ap, wlan, dist)
         
         if sta.params['associatedTo'][wlan] == '':        
             associated = False        
         else:        
             associated = False
 
         if ap == sta.params['associatedTo'][wlan] or dist <= ap.params['range']:
             changeAP = False
             """Association Control: mechanisms that optimize the use of the APs"""
             if self.associationControlMethod != False and sta.params['associatedTo'][wlan] != '':
                 ac = self.associationControlMethod
                 value = associationControl(sta, ap, wlan, ac)
                 changeAP = value.changeAP
 
             if associated == False or changeAP == True:
                 if ap not in sta.params['associatedTo']:
                     if sta.params['associatedTo'][wlan] == '' or changeAP == True:
                         if 'encrypt' not in ap.params:
                             self.associate_infra(sta, ap, wlan)
                         else:
                             if ap.params['encrypt'][0] == 'wpa' or ap.params['encrypt'][0] == 'wpa2':
                                 self.associate_wpa(sta, ap, wlan)
                             elif ap.params['encrypt'][0] == 'wep':
                                 self.associate_wep(sta, ap, wlan)
                         if dist >= 0.01 and sta.params['associatedTo'][wlan] != '':
                             self.updateParams(sta, ap, wlan)
                             setChannelParams(sta, ap, wlan, dist)
Пример #8
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)
Пример #9
0
    def setParameters(self, nodes, meshNodes=None):
        if meshNodes == None:
            meshNodes = nodes

        for node in nodes:
            for wlan in range(0, len(node.params['wlan'])):
                if node.func[wlan] == 'mesh' or node.func[wlan] == 'adhoc':
                    if node.type == 'vehicle':
                        node = node.params['carsta']
                        wlan = 0
                    dist = listNodes.pairingNodes(node, wlan, meshNodes)
                    if WmediumdServerConn.connected == False and dist >= 0.01:
                        setChannelParams(sta=node, wlan=wlan, dist=dist)
                else:
                    self.handoverCheck(node, wlan)
        if meshRouting.routing == 'custom':
            meshRouting(meshNodes)
        # have to verify this
        eval(self.continueParams)
Пример #10
0
 def parameters(self):
     """ 
     Applies channel params and handover
     """
     while self.continue_:
         for sta in self.stations:
             for wlan in range(0, len(sta.params['wlan'])):
                 if sta.func[wlan] == 'mesh' or sta.func[wlan] == 'adhoc':
                     if sta.type == 'vehicle':
                         sta = sta.params['carsta']
                         wlan = 0
                     dist = listNodes.pairingNodes(sta, wlan, self.stations)
                     if WmediumdServerConn.connected == False and dist >= 0.01:
                         setChannelParams(sta=sta, wlan=wlan, dist=dist)
                 else:
                     self.handoverCheck(sta, wlan)
         if meshRouting.routing == 'custom':
             meshRouting(self.stations)
         # have to verify this
         eval(self.continueParams)
Пример #11
0
    def autoAssociation(self, stations, accessPoints):
        """
        This is useful to make the users' life easier
        
        :param stations: list of stations
        :param accessPoints: list of access points
        """
        ap = []
        for node in accessPoints:
            if 'link' in node.params:
                ap.append(node)

        nodes = stations + ap

        if not self.isVanet:
            for node in nodes:
                pairingAdhocNodes.ssid_ID += 1
                for wlan in range(0, len(node.params['wlan'])):
                    if 'position' in node.params and 'link' not in node.params:
                        mobility.accessPoints = accessPoints
                        mobility.handoverCheck(node, wlan)
                    if 'position' in node.params and node.func[
                            wlan] == 'adhoc' and node.params['associatedTo'][
                                wlan] == '':
                        value = pairingAdhocNodes(node, wlan, nodes)
                        dist = value.dist
                        if dist >= 0.01:
                            setChannelParams(sta=node, wlan=wlan, dist=dist)
                    elif 'position' in node.params and node.func[
                            wlan] == 'mesh':
                        if node.type == 'vehicle':
                            node = node.params['carsta']
                            wlan = 0
                        dist = listNodes.pairingNodes(node, wlan, nodes)
                        if dist >= 0.01:
                            setChannelParams(sta=node, wlan=wlan, dist=dist)
                if meshRouting.routing == 'custom':
                    meshRouting(nodes)
Пример #12
0
 def customMeshRouting(self, sta, wlan, stations):
     """Custom Mesh Routing"""
     associate = False
     controlMeshMac = []
     command = ''
     for ref_sta in stations:
         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 = setChannelParams.getDistance(sta, ref_sta)
                 range_ = int(sta.params['range'])
                 refRange_ = int(ref_sta.params['range'])
                 if refRange_ > range_:
                     range_ = refRange_
                 if dist <= range_:
                     if ref_sta.func[ref_wlan] == 'mesh':
                         if sta.params['associatedTo'][
                                 wlan] == ref_sta.params['associatedTo'][
                                     ref_wlan]:
                             associate = True
                             if WmediumdServerConn.connected:
                                 if WmediumdServerConn.interference_enabled:
                                     cls = Association
                                     cls.setPositionWmediumd(sta)
                                 else:
                                     cls = Association
                                     cls.setSNRWmediumd(
                                         sta, ref_sta,
                                         sta.params['snr'][wlan])
                             else:
                                 setChannelParams(sta=sta,
                                                  wlan=wlan,
                                                  dist=dist)
             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(stations):
             j += 1
             if sta_ref == []:
                 break
             else:
                 newsta = sta_ref[0]
             for sta1, sta2 in zip(listNodes.nodesX, listNodes.nodesY):
                 if sta1 == sta and sta2 not in exist:
                     command = 'iw dev %s mpath new %s next_hop %s' % (sta.params['wlan'][wlan], \
                                                                       sta2.meshMac[wlan], sta2.meshMac[wlan])
                     debug('\n' + command)
                     sta.pexec(command)
                     exist.append(sta2)
                     controlMeshMac.append(sta2.meshMac[wlan])
                     sta_ref.append(sta2)
                 elif sta1 == newsta and sta2 not in exist:
                     command = 'iw dev %s mpath new %s next_hop %s' % (sta.params['wlan'][wlan], \
                                                                       sta2.meshMac[wlan], sta1.meshMac[wlan])
                     debug('\n' + command)
                     sta.pexec(command)
                     exist.append(sta2)
                     controlMeshMac.append(sta2.meshMac[wlan])
                     sta_ref.append(sta2)
             if newsta in sta_ref:
                 sta_ref.remove(newsta)
     """delete unknown paths"""
     if associate:
         for ref_sta in stations:
             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]))
                     if WmediumdServerConn.connected:
                         cls = Association
                         cls.setSNRWmediumd(sta, ref_sta, -10)
     """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] = ''
Пример #13
0
 def customMeshRouting(self, sta, wlan, stations):
     """Custom Mesh Routing"""
     associate = False
     controlMeshMac = []
     command = ''
     for ref_sta in stations:
         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 = setChannelParams.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
                             if not WmediumdServerConn.connected:
                                 setChannelParams(sta=sta,
                                                  wlan=wlan,
                                                  dist=dist)
             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(stations):
             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:
                     if WmediumdServerConn.connected:
                         WmediumdServerConn.send_snr_update(
                             WmediumdSNRLink(sta.wmediumdIface,
                                             y.wmediumdIface,
                                             sta.params['snr'][wlan]))
                     else:
                         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:
                     if WmediumdServerConn.connected:
                         pass
                     else:
                         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 unknown paths"""
     if associate:
         for ref_sta in stations:
             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] = ''
Пример #14
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)