def run(self): while True: self.getack.wait() settings.ts_print("MAC | ACKReceivingThread: wait for ACK", time.time()) self.getack.clear() self.receive_ack() self._client.close()
def run(self): if self._options.verbose: settings.ts_print (' '.join(["Established connection:", self._details [ 0 ]]), time.time()) while True: _payload = self._client.recv(1024) self.change_width(_payload) self._client.close()
def send_width(self): payload = '_'.join([str(self.width_map), str(self.occupied_tones)]) try: self._client.send(payload) if self._verbose: settings.ts_print("MAC | sent width change params", time.time()) except socket.error: print 'Could not send width, socket error'
def change_width(self, payload): _values = payload.split('_') if self._options.verbose: settings.ts_print(' '.join(['Change map to:', str(_values[0]), 'and num carriers to', str(_values[1])]), time.time()) _new_width_map = _values[0] _new_occupied_tones = int(_values[1]) self._options.width_map = _new_width_map self._tb.stop() self._tb.wait() self._tb.rxpath.reset_ofdm_params(_new_width_map) self._tb.start() if self._options.verbose: settings.ts_print('Change width completed',time.time())
def run(self): if self._verbose: settings.ts_print (' '.join(["Established connection:", str(self._details [ 0 ])]), time.time()) while True: self.ok2ack.wait() self.ok2ack.clear() _gain = "" for i in range(len(self.width_ranking)): _gain = ''.join([_gain, "_", str(self.width_ranking[i])]) self._channel.send(''.join([str(self.pktno), "_", str(self.good), _gain])) if self._verbose: settings.ts_print(' '.join(["MAC | ACKSendingThread: sent ACK #", str(self.pktno)]), time.time()) self._channel.close()
def update_table(self, pkt_size, current_mcs, current_width, num_sent, num_acked): _size_bin = _size_to_bin(pkt_size) _current_time = time.time() self.table[_size_bin]["last_update"] = time.time() self.table[_size_bin][current_mcs][current_width]["tries"] = num_sent self.table[_size_bin][current_mcs][current_width]["packets_acked"] = num_acked if num_acked == 0: self.table[_size_bin][current_mcs][current_width]["succ_fails"] = num_sent self.table[_size_bin][current_mcs][current_width]["loss"] = 1 - self.table[_size_bin][current_mcs][current_width]["packets_acked"] / float(self.table[_size_bin][current_mcs][current_width]["tries"]) self.table[_size_bin][current_mcs][current_width]["total_tx_time"] = self.table[_size_bin][current_mcs][current_width]["tries"] * self.table[_size_bin][current_mcs][current_width]["lossless_tx_time"] if self.table[_size_bin][current_mcs][current_width]["packets_acked"] > 0: self.table[_size_bin][current_mcs][current_width]["average_tx_time"] = self.table[_size_bin][current_mcs][current_width]["total_tx_time"]/float(self.table[_size_bin][current_mcs][current_width]["packets_acked"]) else: self.table[_size_bin][current_mcs][current_width]["average_tx_time"] = sys.maxint settings.ts_print("RATE | table update for " + current_mcs + " " + str(current_width) +" to "+str(self.table[_size_bin][current_mcs][current_width]["loss"]), time.time())
def receive_ack(self): _payload = "" try: _payload = self._client.recv(1024) if not _payload: if self._verbose: settings.ts_print("MAC | ACKReceivingThread: ACK not received!", time.time()) self.good_ack = False else: if self._verbose: settings.ts_print(' '.join(["MAC | ACKReceivingThread: ACK received:", _payload, "wanted", str(self.ackwanted)]), time.time()) _values = _payload.split('_') if (int(_values[0])==self.ackwanted) and (str(_values[1]) == "True"): self.good_ack = True else: self.good_ack = False if self._top.refresh_gains: j = 0 for i in range (self._top.num_groups): gain_rank = int(_values[i+2]) if int(gain_rank) != self._top.num_groups//2: self._top.group_sort[j] = gain_rank j += 1 self._top.refresh_gains = False self.acked.set() except: if self._verbose: settings.ts_print("MAC | ACKReceivingThread: ACK not received (except)", time.time()) self.good_ack = False self.acked.set() finally: pass
def run(self, steps): stats_steps = 0 # NOTE: we do not take stats of probe packets correct = 0 total = 0 f = open('losses.txt', 'w') for i in range(steps): change = False if (i == 1): change = True self.s.change_width(462) self._current_width_x = 462 if (i == 301): change = True self.s.change_width(132) self._current_width_x = 132 if (i == 601): change = True self.s.change_width(462) self._current_width_x = 462 if (self._state == _NORMAL): if (i%_P == 0): self._state=_PROBING self.old_mcs = self._current_mcs self.old_width = self._current_width if not change: _new_mcs, _new_width = self.s.find_rate(self._current_mcs, self._current_width, self._state) else: _new_mcs, _new_width = self.s.find_rate(self._current_mcs, self._current_width_x, self._state) _new_width_map = "".join(self.width_to_groups(_new_width)) if self.verbose: settings.ts_print( ' '.join(["Calculated", str(_new_mcs), str(_new_width), "width map", str(_new_width_map)]), time.time()) if _new_width != self._current_width: while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self.width_sender.width_map = _new_width_map self.width_sender.sendit.set() time.sleep(0.1) # NOTE: pause for the other end to reconfigure itself elif _new_mcs != self._current_mcs: while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self._current_mcs = _new_mcs self._current_width = _new_width payload = (self._pkt_size-2) * chr(i & 0xff) payload = struct.pack('!H', i & 0xffff) + payload time.sleep(self._spacing) self.send_pkt(payload, False, i) self.ack_recvr.ackwanted = i self.ack_recvr.getack.set() self.ack_recvr.acked.wait() self.ack_recvr.acked.clear() value = self.ack_recvr.good_ack settings.ts_print(' '.join(["Tx num:", str(i), _new_mcs, str(_new_width), str(value)]), time.time()) self.s.update_table(self._current_mcs, self._current_width, value) if i%20 != 0: if self._state == _NORMAL: small_current_time = float(_coding_rate[self._current_mcs]*self._time_per_subcarrier)/(_bits_per_tone[self._current_mcs]*self._current_width) self._small_time += small_current_time small_energy = self.calc_energy(small_current_time, self._current_width) self._small_total_energy += small_energy if value: correct += 1 total += 1 else: if (total > 0): loss = 1 - float(correct)/total bitrate = 1/(self._small_time/total) energy = self._small_total_energy/float(total) if correct > 0: tput = bitrate*(correct/float(total)) else: tput = 0 else: loss = 1 bitrate = 0 energy = 0 tput = 0 correct = 0 total = 0 self._small_time = 0 self._small_total_energy = 0 print str(i) + " " + str(loss) + "\t" + str(tput) + "\t" + str(bitrate) + "\t" + str(energy) + "\n" f.write(str(i) + " " + str(loss) + "\t" + str(tput) + "\t" + str(bitrate) + "\t" + str(energy) + "\n") self.s.print_table() if self.verbose: self.s.print_table() if (self._state == _PROBING): if self._current_width != self.old_width: _new_width_map = string.join(self.width_to_groups(self.old_width), "") _new_mcs = self.old_mcs while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass if self.verbose: settings.ts_print("Reset to old params after probing - width and MCS change", time.time()) self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self.width_sender.width_map = _new_width_map self.width_sender.sendit.set() time.sleep(0.1) elif self._current_mcs != self.old_mcs: _new_width_map = string.join(self.width_to_groups(self.old_width), "") _new_mcs = self.old_mcs while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass if self.verbose: settings.ts_print("Reset to old params after probing - MCS change", time.time()) self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self._current_mcs = self.old_mcs self._current_width = self.old_width elif i > 10: # we skip the first 100 packets when collecting the stats current_time = float(_coding_rate[self._current_mcs]*self._time_per_subcarrier)/(_bits_per_tone[self._current_mcs]*self._current_width) self._time += current_time stats_steps += 1 energy = self.calc_energy(current_time, self._current_width) self._total_energy += energy self._total_ok += int(value) self._state = _NORMAL avg_bitrate = 1/(self._time/stats_steps) avg_energy = self._total_energy/float(stats_steps) avg_tput = avg_bitrate*(self._total_ok/float(stats_steps)) print ' '.join(["Avg loss:", str(1 - self._total_ok/float(stats_steps)), "total time", str(self._time), " avg bitrate", str(avg_bitrate), "avg tput ", str(avg_tput)]) MOS = self.calc_mos(1 - self._total_ok/float(stats_steps)) print ' '.join(["MOS:", str(MOS), "energy:", str(avg_energy)]) #(1 - self.total_ok/float(steps)) f.close()
def run(self, steps): stats_steps = 0 # NOTE: we do not take stats of probe packets for i in range(steps): if (self._state == _NORMAL): if (i%_P == 0): self._state=_PROBING self.old_mcs = self._current_mcs self.old_width = self._current_width _new_mcs, _new_width = self.s.find_rate(self._current_mcs, self._current_width, self._state) _new_width_map = "".join(self.width_to_groups(_new_width)) if self.verbose: settings.ts_print( ' '.join(["Calculated", str(_new_mcs), str(_new_width), "width map", str(_new_width_map)]), time.time()) if _new_width != self._current_width: while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self.width_sender.width_map = _new_width_map self.width_sender.sendit.set() time.sleep(0.1) # NOTE: pause for the other end to reconfigure itself elif _new_mcs != self._current_mcs: while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self._current_mcs = _new_mcs self._current_width = _new_width payload = (self._pkt_size-2) * chr(i & 0xff) payload = struct.pack('!H', i & 0xffff) + payload time.sleep(self._spacing) self.send_pkt(payload, False, i) self.ack_recvr.ackwanted = i self.ack_recvr.getack.set() self.ack_recvr.acked.wait() self.ack_recvr.acked.clear() value = self.ack_recvr.good_ack settings.ts_print(' '.join(["Tx num:", str(i), _new_mcs, str(_new_width), str(value)]), time.time()) self.s.update_table(self._current_mcs, self._current_width, value) self.s.print_table() if self.verbose: self.s.print_table() if (self._state == _PROBING): if self._current_width != self.old_width: _new_width_map = string.join(self.width_to_groups(self.old_width), "") _new_mcs = self.old_mcs while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass if self.verbose: settings.ts_print("Reset to old params after probing - width and MCS change", time.time()) self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self.width_sender.width_map = _new_width_map self.width_sender.sendit.set() time.sleep(0.1) elif self._current_mcs != self.old_mcs: _new_width_map = string.join(self.width_to_groups(self.old_width), "") _new_mcs = self.old_mcs while not self.txpath.ofdm_tx._pkt_input.msgq().empty_p(): pass if self.verbose: settings.ts_print("Reset to old params after probing - MCS change", time.time()) self.txpath.reset_ofdm_params_groups(_new_width_map, _new_mcs) self._current_mcs = self.old_mcs self._current_width = self.old_width elif i > 100: # we skip the first 100 packets when collecting the stats current_time = float(_coding_rate[self._current_mcs]*self._time_per_subcarrier)/(_bits_per_tone[self._current_mcs]*self._current_width) self._time += current_time stats_steps += 1 energy = self.calc_energy(current_time, self._current_width) self._total_energy += energy self._total_ok += int(value) self._state = _NORMAL avg_bitrate = 1/(self._time/stats_steps) avg_energy = self._total_energy/float(stats_steps) avg_tput = avg_bitrate*(self._total_ok/float(stats_steps)) print ' '.join(["Avg loss:", str(1 - self._total_ok/float(stats_steps)), "total time", str(self._time), " avg bitrate", str(avg_bitrate), "avg tput ", str(avg_tput)]) MOS = self.calc_mos(1 - self._total_ok/float(stats_steps)) print ' '.join(["MOS:", str(MOS), "energy:", str(avg_energy)]) #(1 - self.total_ok/float(steps))