def __init__(self, iface, log_file, cw_init): super(TunerCollisionRate, self).__init__(iface, log_file) self.cr_observer = CollisionRateObserver(iface) self.ao = AirtimeObserver(iface) self.set_cw(cw_init) self.cw_prev = cw_init
def __init__(self, iface, log_file, cw_init, beta, k): super(TunerNew, self).__init__(iface, log_file) self.cr_observer = CollisionRateObserver(iface) self.k = k self.beta = beta self.cw_prev = cw_init self.smooth = None self.set_cw(cw_init)
def __init__(self, iface, log_file): # TODO: implement iface --> phy translation assert (iface == 'wlan0') phy = 'phy0' self.cr_observer = CollisionRateObserver(iface) self.txq_params_fname = '/sys/kernel/debug/ieee80211/' self.txq_params_fname += phy self.txq_params_fname += '/ath9k/txq_params' self.log_file = log_file
class TunerOld(TunerBase): def __init__(self, iface, log_file, cw_init): super(TunerOld, self).__init__(iface, log_file) self.cmd = [ 'cat', '/sys/kernel/debug/ieee80211/phy0/statistics/' 'dot11RTSSuccessCount' ] self.cr_observer = CollisionRateObserver(iface) self.observer = ChannelObserver() self.n = int(subprocess.check_output(self.cmd)) self.n_old = None self.cw_prev = cw_init def update_cw(self, alloc, airtime): self.observer.update() busy = self.observer.surveysays('busy') self.n_old = self.n self.n = int(subprocess.check_output(self.cmd)) n = self.n - self.n_old n_alloc = n * alloc if n * alloc != 0 else 1 cw = int((2 / 9e-3) * (airtime * ((1 - alloc) / (n_alloc)) * busy)) cw = 0 if cw < 0 else cw cw = 1023 if cw > 1023 else cw self.set_cw(cw) self.log(alloc, airtime, self.cw_prev, cw, self.cr_observer.collision_rate()) self.cw_prev = cw
class TunerNew(TunerBase): def __init__(self, iface, log_file, cw_init, beta, k): super(TunerNew, self).__init__(iface, log_file) self.cr_observer = CollisionRateObserver(iface) self.k = k self.beta = beta self.cw_prev = cw_init self.smooth = None self.set_cw(cw_init) def update_cw(self, alloc, airtime): if self.smooth is None: self.smooth = airtime else: self.smooth = self.beta * airtime + (1.0 - self.beta) * self.smooth cw = int((self.smooth - alloc) * self.k) + self.cw_prev cw = 0 if cw < 0 else cw cw = 1023 if cw > 1023 else cw self.set_cw(cw) self.log(alloc, airtime, self.cw_prev, cw, self.cr_observer.collision_rate()) self.cw_prev = cw
class TunerBase(object): def __init__(self, iface, log_file): # TODO: implement iface --> phy translation assert (iface == 'wlan0') phy = 'phy0' self.cr_observer = CollisionRateObserver(iface) self.txq_params_fname = '/sys/kernel/debug/ieee80211/' self.txq_params_fname += phy self.txq_params_fname += '/ath9k/txq_params' self.log_file = log_file def set_cw(self, cw): qumId = 1 #BE aifs = 2 cwmin = int(cw) cwmax = int(cw) burst = 0 txq_params_msg = '{} {} {} {} {}'.format(qumId, aifs, cwmin, cwmax, burst) f_cw = open(self.txq_params_fname, 'w') f_cw.write(txq_params_msg) f_cw.close() def log(self, alloc, airtime, cw_prev, cw, cr): self.log_file.write('{:.5f},{:.5f},{:.5f},{},{},{:.5f}\n'.format( time.time(), alloc, airtime, cw_prev, cw, cr)) self.log_file.flush() def update_cw(self, alloc, airtime): self.log(alloc, airtime, -1, -1, self.cr_observer.collision_rate())
class TunerCollisionRate(TunerBase): def __init__(self, iface, log_file, cw_init): super(TunerCollisionRate, self).__init__(iface, log_file) self.cr_observer = CollisionRateObserver(iface) self.ao = AirtimeObserver(iface) self.set_cw(cw_init) self.cw_prev = cw_init def update_cw(self): coll_rate = self.cr_observer.collision_rate() airtime = self.ao.airtime() if coll_rate < .1: cw = self.cw_prev / 2 elif coll_rate > .2: cw = self.cw_prev * 2 else: cw = self.cw_prev cw = 2 if cw < 2 else cw cw = 1023 if cw > 1023 else cw cw = int(cw) self.set_cw(cw) self.log(-1, airtime, self.cw_prev, cw, coll_rate) self.cw_prev = cw