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 = link.getDistance(sta, sta.params['associatedTo'][wlan]) RSSI = link.setRSSI(sta, sta.params['associatedTo'][wlan], wlan, distance) refDistance = link.getDistance(sta, ap) refRSSI = link.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 autoAssociation(self, stations, accessPoints): """ This is useful to make the users' life easier :param stations: list of stations :param accessPoints: list of access points """ nodes = stations + accessPoints for node in nodes: for wlan in range(0, len(node.params['wlan'])): if node.type == 'vehicle' and wlan == 1: node = node.params['carsta'] wlan = 0 node.setTxPower_(node.params['wlan'][wlan], node.params['txpower'][wlan]) node.setAntennaGain_(node.params['wlan'][wlan], node.params['antennaGain'][wlan]) #node.setAntennaHeight_(node.params['wlan'][wlan], node.params['antennaHeight'][wlan]) ap = [] for node in accessPoints: if 'link' in node.params: ap.append(node) nodes = stations + ap if self.nroads == 0: for node in stations: for wlan in range(0, len(node.params['wlan'])): if node.func[wlan] == 'mesh': mobility.meshNodes.append(node) elif node.func[wlan] == 'adhoc': mobility.adhocNodes.append(node) for node in nodes: if 'position' in node.params and 'link' not in node.params: mobility.accessPoints = accessPoints mobility.parameters_(node) for sta in stations: for wlan in range(0, len(sta.params['wlan'])): for ap in accessPoints: if 'position' in sta.params and 'position' in ap.params: dist = link.getDistance(sta, ap) if dist <= ap.params['range']: mobility.handover(sta, ap, wlan)
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 """ nodes = stations + accessPoints for node in nodes: for wlan in range(0, len(node.params['wlan'])): node.setTxPower_(node.params['wlan'][wlan], node.params['txpower'][wlan]) ap = [] for node in accessPoints: if 'link' in node.params: ap.append(node) nodes = stations + ap if not self.isVanet: for node in stations: for wlan in range(0, len(node.params['wlan'])): if node.func[wlan] == 'mesh': mobility.meshNodes.append(node) elif node.func[wlan] == 'adhoc': mobility.adhocNodes.append(node) for node in nodes: if 'position' in node.params and 'link' not in node.params: mobility.accessPoints = accessPoints mobility.parameters_(node) for sta in stations: for wlan in range(0, len(node.params['wlan'])): for ap in accessPoints: if 'position' in sta.params and 'position' in ap.params: dist = link.getDistance(sta, ap) if dist <= ap.params['range']: mobility.handover(sta, ap, wlan, dist)
def getDistance(self, src, dst): dist = link.getDistance(src, dst) return dist
def pairing(self, node, wlan, nodes): """Pairing nodes""" i = 1 ref_distance = 0 self.dist = 0 alreadyConn = [] for sta_ref in nodes: if sta_ref != node: dist = link.getDistance(node, sta_ref) if dist != 0.0: totalRange = min(node.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 node.params['ssid'][wlan] == sta_ref.params[ 'ssid'][wlan_ref]: if node.params['cell'][wlan] == '': alreadyConn.append(node) node.params['associatedTo'][ wlan] = node.params['ssid'][wlan] node.params['cell'][wlan] = ( '02:CA:FF:EE:BA:0%s' % self.ssid_ID) iface = node.params['wlan'][wlan] debug("\nassociating %s to %s..." % (iface, node.params['ssid'][wlan])) debug('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % \ (node.params['wlan'][wlan], node.params['associatedTo'][wlan], self.ssid_ID)) node.pexec('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % \ (node.params['wlan'][wlan], node.params['associatedTo'][wlan], self.ssid_ID)) node.params['frequency'][ wlan] = link.frequency(node, wlan) if node.params['cell'][wlan] != sta_ref.params[ 'cell'][wlan_ref]: if sta_ref.params['associatedTo'][ wlan_ref] == node.params['ssid'][ wlan]: if sta_ref.params['cell'][ wlan_ref] == '' and node in alreadyConn: alreadyConn.append(sta_ref) iface = sta_ref.params['wlan'][ wlan_ref] sta_ref.params['associatedTo'][ wlan_ref] = node.params[ 'ssid'][wlan] sta_ref.params['cell'][ wlan_ref] = ( '02:CA:FF:EE:BA:0%s' % self.ssid_ID) debug("\nassociating %s to %s..." % (iface, node.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] = link.frequency( sta_ref, wlan_ref) if alreadyConn != [] and len(alreadyConn) != 1: for sta_ref in nodes: if sta_ref not in alreadyConn: if sta_ref.params['cell'][wlan_ref] == node.params['cell'][ wlan]: sta_ref.params['cell'][wlan_ref] = '' self.ssid_ID += 1 self.dist = ref_distance / i return self.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 = link.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 = link.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 not WmediumdServerConn.interference_enabled: cls = Association cls.setSNRWmediumd( sta, ref_sta, sta.params['snr'][wlan]) else: link(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.params['mac'][wlan], sta2.params['mac'][wlan]) debug('\n' + command) sta.pexec(command) exist.append(sta2) controlMeshMac.append(sta2.params['mac'][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.params['mac'][wlan], sta1.params['mac'][wlan]) debug('\n' + command) sta.pexec(command) exist.append(sta2) controlMeshMac.append(sta2.params['mac'][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.params['mac'][ ref_wlan] not in controlMeshMac: sta.pexec('iw dev %s mpath del %s' % (sta.params['wlan'][wlan], ref_sta.params['mac'][ref_wlan])) if not 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] = ''