Example #1
0
    def pairing(self, sta, wlan, stationList):
        """Pairing nodes"""
        i=1
        ref_distance = 0
        self.dist = 0       
   
        alreadyConn = []
 
        for ref_sta in stationList:
            if ref_sta != sta:
                dist = channelParameters.getDistance(sta, ref_sta)
                if dist != 0.0:
                    totalRange = int(sta.params['range']) + int(ref_sta.params['range'])
                    if dist < totalRange:
                        ref_distance = ref_distance + dist
                        ssid = sta.params['associatedTo'][wlan]
                        ref_ssid = ref_sta.params['associatedTo'][wlan]
                        i+=1
                        sta.params['frequency'][wlan] = channelParameters.frequency(sta, wlan)
                        if sta.ssid[wlan] == ref_sta.ssid[wlan]:
                            if sta.params['cell'][wlan] == '':
                                alreadyConn.append(sta)
                                sta.params['associatedTo'][wlan] = sta.ssid[wlan]
                                sta.params['cell'][wlan] = ('02:CA:FF:EE:BA:0%s' % self.ssid_ID)
                                iface = sta.params['wlan'][wlan]
                                print "associating %s to %s..." % (iface, sta.ssid[wlan])
                                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.pexec('iw dev %s ibss join %s 2412' % (sta.params['wlan'][wlan], \
                                #                                           sta.params['associatedTo'][wlan]))   
                                sta.params['frequency'][wlan] = channelParameters.frequency(sta, wlan)
                            if sta.params['cell'][wlan] != ref_sta.params['cell'][wlan]:
                                if ref_sta.params['associatedTo'][wlan] == sta.ssid[wlan]: 
                                    if ref_sta.params['cell'][wlan] == '' and sta in alreadyConn:
                                        alreadyConn.append(ref_sta)
                                        iface = ref_sta.params['wlan'][wlan]
                                        ref_sta.params['associatedTo'][wlan] = sta.ssid[wlan]
                                        ref_sta.params['cell'][wlan] = ('02:CA:FF:EE:BA:0%s' % self.ssid_ID)
                                        print "associating %s to %s..." % (iface, sta.ssid[wlan])
                                        ref_sta.pexec('iwconfig %s essid %s ap 02:CA:FF:EE:BA:0%s' % (ref_sta.params['wlan'][wlan], ref_sta.params['associatedTo'][wlan], self.ssid_ID))
                                        #ref_sta.pexec('iw dev %s ibss join %s 2412' % (ref_sta.params['wlan'][wlan], \
                                        #                                               ref_sta.params['associatedTo'][wlan]))
                                        ref_sta.params['frequency'][wlan] = channelParameters.frequency(ref_sta, wlan)
        if alreadyConn != [] and len(alreadyConn) != 1: 
            for ref_sta in stationList:
                if ref_sta not in alreadyConn:
                    if ref_sta.params['cell'][wlan] == sta.params['cell'][wlan]:
                        ref_sta.params['cell'][wlan] = ''
        self.ssid_ID+=1
         
        self.dist = ref_distance / i
        return self.dist
     
    #def confirmAdhocAssociation(self, sta, iface, wlan):
    #    associated = ''
    #    while(associated == '' or len(associated) == 0):
    #        sta.sendCmd("iw dev %s scan ssid | grep %s" % (iface, sta.ssid[wlan]))
    #        associated = sta.waitOutput()
    #    sta.params['frequency'][wlan] = channelParameters.frequency(sta, wlan)
Example #2
0
 def rssi(self):
     if mobility.DRAW:
         instantiateGraph()
     currentTime = time.time()
     staList = mobility.staList
     ang = {}
     for sta in staList:
         ang[sta] = random.uniform(0, 360)
         sta.params['frequency'][0] = channelParameters.frequency(sta, 0)
     continue_ = True
     while continue_:
         continue_ = False
         time_ = time.time() - currentTime
         for sta in staList:
             continue_ = True
             if time_ >= sta.time[0]:
                 freq = sta.params['frequency'][0] * 1000  # freqency in MHz
                 ap = sta.params['associatedTo'][0]  # get AP
                 dist = self.calculateDistance(sta, freq, sta.rssi[0])
                 if ap != '':
                     self.moveStationTo(sta, ap, dist, ang[sta])
                     bw = self.calculateRate(sta, ap, dist)
                     channelParameters.tc(sta, 0, bw, 1, 1, 1)
                     sta.params['rssi'] = sta.rssi[0]
                 del sta.rssi[0]
                 del sta.time[0]
             if len(sta.time) == 0:
                 staList.remove(sta)
         time.sleep(0.01)
 def rssi(self):
     if mobility.DRAW:
         instantiateGraph()
     currentTime = time.time()
     staList = mobility.staList
     ang = {}
     for sta in staList:
         ang[sta] = random.uniform(0, 360)
         sta.params['frequency'][0] = channelParameters.frequency(sta, 0)
     continue_ = True
     while continue_:
         continue_ = False
         time_ = time.time() - currentTime
         for sta in staList:
             continue_ = True
             if time_ >= sta.time[0]:
                 freq = sta.params['frequency'][0] * 1000  # freqency in MHz
                 ap = sta.params['associatedTo'][0]  # get AP
                 dist = self.calculateDistance(sta, freq, sta.rssi[0])
                 if ap != '':
                     self.moveStationTo(sta, ap, dist, ang[sta])
                     bw = self.calculateRate(sta, ap, dist)
                     channelParameters.tc(sta, 0, bw, 1, 1, 1)
                     sta.params['rssi'] = sta.rssi[0]
                 del sta.rssi[0]
                 del sta.time[0]
             if len(sta.time) == 0:
                 staList.remove(sta)
         time.sleep(0.01)
Example #4
0
 def behavior(self):
     info('\nReplaying process starting in 20 seconds')
     time.sleep(20)
     info('\nReplaying process has been started')
     currentTime = time.time()
     staList = mobility.staList
     for sta in staList:
         sta.params['frequency'][0] = channelParameters.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]
                         channelParameters.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!')
Example #5
0
 def handover(self, sta, ap, wlan, distance, changeAP, ac=None):
     """handover"""
     if ac == 'llf' or ac == 'ssf' and sta.params['associatedTo'][
             wlan] != ap:
         if sta.params['associatedTo'][wlan] != '':
             sta.params['associatedTo'][wlan].associatedStations.remove(sta)
         sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
         debug(
             '\niwconfig %s essid %s ap %s' %
             (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac'][wlan]))
         sta.pexec(
             'iwconfig %s essid %s ap %s' %
             (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac'][wlan]))
         sta.params['associatedTo'][wlan] = ap
         sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
         ap.associatedStations.append(sta)
     elif ap not in sta.params['associatedTo']:
         # Useful for stations with more than one wifi iface
         if sta.params['associatedTo'][wlan] == '':
             if sta.encrypt == '':
                 debug('\niwconfig %s essid %s ap %s' %
                       (sta.params['wlan'][wlan], ap.ssid[0],
                        ap.params['mac'][wlan]))
                 sta.pexec('iwconfig %s essid %s ap %s' %
                           (sta.params['wlan'][wlan], ap.ssid[0],
                            ap.params['mac'][wlan]))
             elif sta.encrypt == 'wpa' or sta.encrypt == 'wpa2':
                 os.system(
                     'pkill -f \'wpa_supplicant -B -Dnl80211 -i %s-wlan%s\''
                     % (sta, wlan))
                 debug("\nwpa_supplicant -B -Dnl80211 -i %s-wlan%s -c <(wpa_passphrase \"%s\" \"%s\")\n" \
                                                                                     % (sta, wlan, ap.ssid[0], sta.passwd))
                 sta.cmd("wpa_supplicant -B -Dnl80211 -i %s-wlan%s -c <(wpa_passphrase \"%s\" \"%s\")" \
                                                                                     % (sta, wlan, ap.ssid[0], sta.passwd))
             elif sta.encrypt == 'wep':
                 debug('iw dev %s-wlan%s connect %s key 0:%s' \
                                                         % (sta, wlan, ap.ssid[0], sta.passwd))
                 sta.cmd('iw dev %s-wlan%s connect %s key 0:%s' \
                                                         % (sta, wlan, ap.ssid[0], sta.passwd))
             sta.params['frequency'][wlan] = channelParameters.frequency(
                 ap, 0)
             ap.associatedStations.append(sta)
             sta.params['associatedTo'][wlan] = ap
Example #6
0
 def handover(self, sta, ap, wlan, distance, changeAP, ac=None):
     """handover"""
     if ac == 'llf' or ac == 'ssf' and sta.params['associatedTo'][wlan] != ap:
         if sta.params['associatedTo'][wlan] != '':
             sta.params['associatedTo'][wlan].associatedStations.remove(sta)
         sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
         debug ('\niwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
         sta.pexec('iwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
         sta.params['associatedTo'][wlan] = ap
         sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
         ap.associatedStations.append(sta)
     elif ap not in sta.params['associatedTo']:
         # Useful for stations with more than one wifi iface
         if sta.params['associatedTo'][wlan] == '':
             debug('\niwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
             sta.pexec('iwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
             sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
             ap.associatedStations.append(sta)
             sta.params['associatedTo'][wlan] = ap
Example #7
0
 def handover(self, sta, ap, wlan, distance, changeAP, ac=None):
     """handover"""
     if ac == 'llf' or ac == 'ssf' and sta.params['associatedTo'][wlan] != ap:
         if sta.params['associatedTo'][wlan] != '':
             sta.params['associatedTo'][wlan].associatedStations.remove(sta)
         sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
         debug ('\niwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
         sta.pexec('iwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
         sta.params['associatedTo'][wlan] = ap
         sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
         ap.associatedStations.append(sta)
     elif ap not in sta.params['associatedTo']:
         # Useful for stations with more than one wifi iface
         if sta.params['associatedTo'][wlan] == '':
             debug('\niwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
             sta.pexec('iwconfig %s essid %s ap %s' % (sta.params['wlan'][wlan], ap.ssid[0], ap.params['mac']))
             sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
             ap.associatedStations.append(sta)
             sta.params['associatedTo'][wlan] = ap
Example #8
0
 def rssi(self, propagationModel='', n=0):
     if mobility.DRAW:
         instantiateGraph()
     currentTime = time.time()
     staList = mobility.staList
     ang = {}
     for sta in staList:
         ang[sta] = random.uniform(0, 360)
         sta.params['frequency'][0] = channelParameters.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])
                         loss = channelParameters.loss(dist)
                         latency = channelParameters.latency(dist)
                         delay = channelParameters.delay(dist, 0)
                         bw = channelParameters.bw(sta, ap, dist, 0, isReplay=True)
                         if self.print_bw or self.print_delay or self.print_distance or \
                                                         self.print_latency or self.print_loss:
                             info('station %s:\n' % sta)
                             if self.print_distance:
                                 info('  distance(m) to %s: %s\n' % (ap, dist))
                             if self.print_loss:
                                 info('  loss: %s\n' % loss)
                             if self.print_latency:
                                 info('  latency(ms): %s\n' % latency)
                             if self.print_delay:
                                 info('  delay(ms): %s\n' % delay)
                             if self.print_bw:
                                 info('  bandwidth(Mbps): %s\n' % bw)
                         channelParameters.tc(sta, 0, bw, loss, latency, delay)
                     del sta.rssi[0]
                     del sta.time[0]
                 if len(sta.time) == 0:
                     staList.remove(sta)
         time.sleep(0.01)
Example #9
0
 def setChannelParameters(self, sta, ap, dist, wlan):
     """ Wifi Parameters """
     associated = True
     #time = abs(sta.params['speed'])
     staList = self.staList
     
     if ap == sta.params['associatedTo'][wlan]:            
         if dist > ap.range:  
             debug('\niw dev %s disconnect' % sta.params['wlan'][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
             ap.associatedStations.remove(sta)
         else:
             channelParameters(sta, ap, wlan, dist, staList, 0)
     else:  
         if dist < ap.range:  
             if sta.params['associatedTo'][wlan] == '':
                 associated = False
         else:
             associated = False
     if ap == sta.params['associatedTo'][wlan] or dist < ap.range:
         changeAP = False
         ac = None
         sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
         sta.params['channel'][wlan] = ap.params['channel'][0]
         
         """Association Control: mechanisms that optimize the use of the APs"""
         if self.associationControlMethod != False:
             ac = self.associationControlMethod              
             value = associationControl(sta, ap, wlan, ac)
             changeAP = value.changeAP
             
         #Go to handover    
         if associated == False or changeAP == True:
             self.handover(sta, ap, wlan, dist, changeAP, ac)
             channelParameters(sta, ap, wlan, dist, staList, 0)
     else:
         #have to verify this
         time.sleep(0.01)
 def setChannelParameters(self, sta, ap, dist, wlan):
     """ Wifi Parameters """
     associated = True
     #time = abs(sta.params['speed'])
     staList = self.staList
     
     if ap == sta.params['associatedTo'][wlan]:            
         if dist > ap.params['range']:  
             debug('\niw dev %s disconnect' % sta.params['wlan'][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
             ap.associatedStations.remove(sta)
         else:
             channelParameters(sta, ap, wlan, dist, staList, 0)
     else:  
         if dist < ap.params['range']:  
             if sta.params['associatedTo'][wlan] == '':
                 associated = False
         else:
             associated = False
     if ap == sta.params['associatedTo'][wlan] or dist < ap.params['range']:
         changeAP = False
         ac = None
         sta.params['frequency'][wlan] = channelParameters.frequency(ap, 0)
         sta.params['channel'][wlan] = ap.params['channel'][0]
         
         """Association Control: mechanisms that optimize the use of the APs"""
         if self.associationControlMethod != False:
             ac = self.associationControlMethod              
             value = associationControl(sta, ap, wlan, ac)
             changeAP = value.changeAP
             
         #Go to handover    
         if associated == False or changeAP == True:
             self.handover(sta, ap, wlan, dist, changeAP, ac)
             channelParameters(sta, ap, wlan, dist, staList, 0)
     else:
         #have to verify this
         time.sleep(0.01)
 def rssi(self):
     if mobility.DRAW:
         instantiateGraph()
     currentTime = time.time()
     staList = mobility.staList
     ang = {}
     for sta in staList:
         ang[sta] = random.uniform(0, 360)
         sta.params['frequency'][0] = channelParameters.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])
                         self.moveStationTo(sta, ap, dist, ang[sta])
                         loss = channelParameters.loss(dist)
                         latency = channelParameters.latency(dist)
                         delay = channelParameters.delay(dist, 0)
                         bw = channelParameters.bw(sta,
                                                   ap,
                                                   dist,
                                                   0,
                                                   isReplay=True)
                         channelParameters.tc(sta, 0, bw, loss, latency,
                                              delay)
                     del sta.rssi[0]
                     del sta.time[0]
                 if len(sta.time) == 0:
                     staList.remove(sta)
         time.sleep(0.01)
Example #12
0
 def confirmMeshAssociation(self, sta, wlan):
     sta.params['frequency'][wlan] = channelParameters.frequency(sta, wlan)
Example #13
0
 def confirmAdhocAssociation(self, sta, iface, wlan):
     associated = ''
     while(associated == '' or len(associated) == 0):
         sta.sendCmd("iw dev %s scan ssid | grep %s" % (iface, sta.ssid[wlan]))
         associated = sta.waitOutput()
     sta.params['frequency'][wlan] = channelParameters.frequency(sta, wlan)  
Example #14
0
 def confirmAdhocAssociation(self, sta, iface, wlan):
     associated = ''
     while(associated == '' or len(associated) == 0):
         sta.sendCmd("iw dev %s scan ssid | grep %s" % (iface, sta.ssid[wlan]))
         associated = sta.waitOutput()
     sta.params['frequency'][wlan] = channelParameters.frequency(sta, wlan)