之前搜的时候,搜到了这里的,还以为到时候程序执行的时候,会调用这里的库
使用pdb调试的时候才知道python的这些库,是在这里:
/usr/local/lib/python2.7/dist-packages/mininet_wifi-2.2.1d1-py2.7.egg/mininet/wifi/net.py
然后下面记录一下找到association的过程。
mininet/wifi/associationControl.py
from mininet.log import debug
class associationControl(object):
changeAP = False
def __init__(self, sta, ap, wlan, ac):
self.customAssociationControl(sta, ap, wlan, ac)
def customAssociationControl(self, sta, ap, wlan, ac):
"""Mechanisms that optimize the use of the APs 自定义AP的Association的方式
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])
# 断开当前wlan网络
sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
self.changeAP = True
else:
self.changeAP = True
elif ac == "ssf": #信号最强优先
distance = sta.get_distance_to(sta.params['associatedTo'][wlan])
rssi = sta.set_rssi(sta.params['associatedTo'][wlan],
wlan, distance)
ref_dist = sta.get_distance_to(ap)
ref_rssi = sta.set_rssi(ap, wlan, ref_dist)
if float(ref_rssi) > 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
其中sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
这一句,是在sta上执行字符串中的命令。在这个命令中,后面的sta.params['wlan'][wlan]
中的中括号里的带引号的’wlan’是指sta中的所有wlan网卡,然后再加一个[wlan]这个wlan是一个wlan id,表示第几个wlan网卡,所以这句话的意思就是使用iw dev
命令断开当前wlan网路。
mininet/wifi/mobility.py
class mobility(object):
...
@classmethod
def handover(cls, sta, ap, wlan, ap_wlan):
"""handover
:param sta: station
:param ap: access point
:param wlan: wlan ID"""
changeAP = False
# Assocation策略不为空,并且sta的Associated AP不是参数ap,并且这个wlan不为空
"Association Control: mechanisms that optimize the use of the APs"
if cls.AC != '' and sta.params['associatedTo'][wlan] != ap \
and sta.params['associatedTo'][wlan] != '':
ac = cls.AC
value = associationControl(sta, ap, wlan, ac)
changeAP = value.changeAP
if sta.params['associatedTo'][wlan] == '' or changeAP is True:
if ap not in sta.params['associatedTo']:
Association.printCon = False
Association.associate_infra(sta, ap, wlan, ap_wlan)
关键的是associationControl()这个方法。在mininet/wifi/associationControl.py中的associationControl类。
from mininet.wifi.associationControl import associationControl
mininet/wifi/link.py
class Association(object):
...
@classmethod
def associate(cls, sta, ap, enable_wmediumd, enable_interference,
wlan=0, ap_wlan=0):
"Associate to Access Point"
if wlan == 0:
wlan = sta.ifaceToAssociate
if 'position' in sta.params:
cls.configureWirelessLink(sta, ap, enable_wmediumd,
enable_interference, ap_wlan=0)
else:
cls.associate_infra(sta, ap, wlan=0, ap_wlan=0)
sta.ifaceToAssociate += 1
@classmethod
def associate_infra(cls, sta, ap, wlan, ap_wlan):
"""Association when infra
:param sta: station
:param ap: access point
:param wlan: wlan ID"""
associated = 0
if 'ieee80211r' in ap.params and ap.params['ieee80211r'] == 'yes' \
and ('encrypt' not in sta.params or 'encrypt' in sta.params and
'wpa' in sta.params['encrypt'][wlan]):
if sta.params['associatedTo'][wlan] == '':
command = ('ps -aux | grep %s | wc -l' % sta.params['wlan'][wlan])
np = int(subprocess.check_output(command, shell=True))
if np == 2:
cls.associate_wpa(sta, ap, wlan, ap_wlan)
else:
cls.handover_ieee80211r(sta, ap, wlan, ap_wlan)
else:
cls.handover_ieee80211r(sta, ap, wlan, ap_wlan)
associated = 1
elif 'encrypt' not in ap.params:
associated = 1
cls.associate_noEncrypt(sta, ap, wlan, ap_wlan)
else:
if sta.params['associatedTo'][wlan] == '':
if 'wpa' in ap.params['encrypt'][ap_wlan] \
and ('encrypt' not in sta.params or 'encrypt' in sta.params and
'wpa' in sta.params['encrypt'][wlan]):
cls.associate_wpa(sta, ap, wlan, ap_wlan)
associated = 1
elif ap.params['encrypt'][ap_wlan] == 'wep':
cls.associate_wep(sta, ap, wlan, ap_wlan)
associated = 1
if cls.printCon:
iface = sta.params['wlan'][wlan]
info("Associating %s to %s\n" % (iface, ap))
if associated:
cls.update_association(sta, ap, wlan)
3月29日更新
取消自动关联
allAutoAssociation = False
然后根据算法决策,主动关联到某ap(当然前提是该ap在此sta的信号范围内)
from mininet.wifi.link import Association
Association.associate(sta, ap, ...)
参考:
https://groups.google.com/forum/#!topic/mininet-wifi-discuss/YMuDNTuoS0k