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] = link.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] link.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, 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] = link.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]) link(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 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] = link.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' elif 'enable_radius' in ap.params and ap.params[ 'enable_radius'] == 'yes': ap.wpa_key_mgmt = 'WPA-EAP' else: ap.wpa_key_mgmt = 'WPA-PSK' ap.rsn_pairwise = 'CCMP' if 'enable_radius' not in ap.params or ( 'enable_radius' not in ap.params and ap.params['enable_radius'] != 'yes'): 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 'phywlan' in ap.params: ap.params.pop("phywlan", None) if ap.func[0] != 'ap': ap.params['frequency'][wlan] = link.frequency(ap, 0) link.recordParams(None, ap) if self.useWmediumd: if len(ap.params['channel']) == 0: ap.params['channel'].append(1) for wlan in range(0, len(ap.params['channel'])): if ap.params['range'] == 33 or ap.params['range'] == 18: value = distanceByPropagationModel(ap, wlan) ap.params['range'] = int(value.dist) if len(ap.params['ssid']) > 1 and wlan == 0: break
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