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)
def mesh(self, sta, stations): wlan = sta.ifaceToAssociate sta.params['rssi'][wlan] = -62 sta.params['snr'][wlan] = -62 - (-90.0) if sta.params['mac'][wlan] != '': sta.cmd('iw dev %s interface add %s-mp%s type mp' % (sta.params['wlan'][wlan], sta, wlan)) sta.cmd('ifconfig %s-mp%s down' % (sta, wlan)) sta.cmd('ip link set %s-mp%s address %s' % (sta, wlan, sta.params['mac'][wlan])) sta.cmd('ifconfig %s down' % sta.params['wlan'][wlan]) iface = '%s-mp%s' % (sta, wlan) sta.params['wlan'][wlan] = iface sta.params['frequency'][wlan] = setChannelParams.frequency(sta, wlan) self.getMacAddress(sta, iface, wlan) sta.intfs[wlan] = sta.params['wlan'][wlan] cls = TCLinkWireless cls(sta, port1=wlan, intfName1=sta.params['wlan'][wlan]) sta.cmd('ifconfig %s %s up' % (sta.params['wlan'][wlan], sta.params['ip'][wlan])) if 'position' not in sta.params: self.meshAssociation(sta, wlan)
def behavior(self, mininet): seconds = 5 info('Replaying process starting in %s seconds\n' % seconds) time.sleep(seconds) info('Replaying process has been started\n') currentTime = time.time() stations = mininet.stations for sta in stations: sta.params['frequency'][0] = setChannelParams.frequency(sta, 0) while True: if len(stations) == 0: break time_ = time.time() - currentTime for sta in stations: if hasattr(sta, 'time'): if time_ >= sta.time[0]: if sta.params['associatedTo'][0] != '': bw = sta.bw[0] loss = sta.loss[0] delay = sta.delay[0] latency = sta.latency[0] setChannelParams.tc(sta, 0, bw, loss, latency, delay) del sta.bw[0] del sta.loss[0] del sta.delay[0] del sta.latency[0] del sta.time[0] if len(sta.time) == 0: stations.remove(sta) time.sleep(0.001) info('Replaying process has finished!')
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)
def behavior(self): info('\nReplaying process starting in 20 seconds') time.sleep(20) info('\nReplaying process has been started') currentTime = time.time() staList = mobility.stations for sta in staList: 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 if ap != '': bw = sta.bw[0] loss = sta.loss[0] delay = sta.delay[0] latency = sta.latency[0] setChannelParams.tc(sta, 0, bw, loss, latency, delay) del sta.bw[0] del sta.loss[0] del sta.delay[0] del sta.latency[0] del sta.time[0] if len(sta.time) == 0: staList.remove(sta) time.sleep(0.01) info('Replaying process has finished!')
def updateParams(self, sta, ap, wlan): """ Updates values for frequency and channel :param sta: station :param ap: access point :param wlan: wlan ID """ sta.params['frequency'][wlan] = setChannelParams.frequency(ap, 0) sta.params['channel'][wlan] = ap.params['channel'][0]
def configureAP(self, ap, wlanID=0, aplist=None): """Configure AP :param ap: ap node :param wlanID: wlan ID """ if 'phywlan' in ap.params: wlanID = 1 for wlan in range(len(ap.params['wlan']) + wlanID): if wlanID == 1: wlan = 0 if 'encrypt' in ap.params and 'config' not in ap.params: if ap.params['encrypt'][wlan] == 'wpa': ap.auth_algs = 1 ap.wpa = 1 if 'ieee80211r' in ap.params and ap.params[ 'ieee80211r'] == 'yes': ap.wpa_key_mgmt = 'FT-EAP' else: ap.wpa_key_mgmt = 'WPA-EAP' ap.rsn_pairwise = 'TKIP CCMP' ap.wpa_passphrase = ap.params['passwd'][0] elif ap.params['encrypt'][wlan] == 'wpa2': ap.auth_algs = 1 ap.wpa = 2 if 'ieee80211r' in ap.params and ap.params[ 'ieee80211r'] == 'yes': ap.wpa_key_mgmt = 'FT-PSK' else: ap.wpa_key_mgmt = 'WPA-PSK' ap.rsn_pairwise = 'CCMP' ap.wpa_passphrase = ap.params['passwd'][0] elif ap.params['encrypt'][wlan] == 'wep': ap.auth_algs = 2 ap.wep_key0 = ap.params['passwd'][0] cls = AccessPoint cls(ap, wlan=wlan, aplist=aplist) if 'phywlan' not in ap.params: iface = ap.params['wlan'][wlan] else: iface = ap.params['phywlan'] if not self.useWmediumd: self.setBw(ap, wlan, iface) if ap.func[0] != 'ap': ap.params['frequency'][wlan] = setChannelParams.frequency( ap, 0) wlanID = 0 setChannelParams.recordParams(None, ap) if len(ap.params['ssid']) > 1 and wlan == 0: break
def confirmInfraAssociation(self, sta, ap, wlan): if self.printCon: iface = sta.params['wlan'][wlan] info("Associating %s to %s\n" % (iface, ap)) if 'encrypt' in ap.params: associated = '' currentTime = time() while (associated == '' or len(associated[0]) == 15): associated = self.isAssociated(sta, wlan) if time() >= currentTime + 10: info("Error during the association process\n") break sta.params['frequency'][wlan] = setChannelParams.frequency(ap, 0) ap.params['associatedStations'][sta] = sta.params['rssi'][wlan] sta.params['associatedTo'][wlan] = ap
def confirmInfraAssociation(self, sta, ap, wlan): """ Confirm association when station associates to AP :param sta: station :param ap: access point :param wlan: wlan ID """ if self.printCon: iface = sta.params['wlan'][wlan] info("Associating %s to %s\n" % (iface, ap)) if 'encrypt' in ap.params: associated = '' currentTime = time() while (associated == '' or len(associated[0]) == 15): associated = self.isAssociated(sta, wlan) if time() >= currentTime + 10: info("Error during the association process\n") break sta.params['frequency'][wlan] = setChannelParams.frequency(ap, 0)
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