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
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)
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_
def handoverCheck(self, sta, wlan): """ handover check :param sta: station :param wlan: wlan ID """ for ap in self.accessPoints: dist = setChannelParams.getDistance(sta, ap) if dist > ap.params['range']: self.apOutOfRange(sta, ap, wlan, dist) for ap in self.accessPoints: dist = setChannelParams.getDistance(sta, ap) if dist <= ap.params['range']: self.handover(sta, ap, wlan, dist) self.apInRange(sta, ap, wlan, dist)
def handoverCheck(self, sta, wlan): """ Does handover :param sta: station :param wlan: wlan ID """ for ap in self.accessPoints: dist = setChannelParams.getDistance(sta, ap) self.getAPsInRange(sta) self.handover(sta, ap, wlan, dist)
def getAPsInRange(self, sta): """ Gets all APs in range of the station. It's not used when there is no position defined :param sta: station """ for ap in self.accessPoints: dist = setChannelParams.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 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 != '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": refDistance = setChannelParams.getDistance(sta, ap) refValue = propagationModel(sta, ap, refDistance, wlan) if refValue.rssi > float(sta.params['rssi'][wlan] + 1): self.changeAP = True return self.changeAP
def getDistance(self, src, dst): dist = setChannelParams.getDistance(src, dst) return dist
def pairingNodes(self, sta, wlan, nodes, **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 nodes: 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 = setChannelParams.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
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] = ''
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] = ''
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 = setChannelParams.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] = setChannelParams.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] = setChannelParams.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