def received_bcn(self, pkt): """ Called if a BCN packet was received """ # Sync to beacon if pkt is from node with higher prio! # Add Node to neighborhood table self.bcn_rx_no += 1 #print "DEBUG: BCN received no.", self.bcn_rx_no bcn_src = int(pkt[1]) if not self.neighbors[bcn_src - 1]: self.neighbors[bcn_src - 1] = True print "Node", bcn_src, "detected!" # TODO: DEMO-STUFF! # ---> Tell higher layer which nodes we've found (routing) known_hosts_msg = [107, 104, 58] for node in self.neighbors: if node is True: known_hosts_msg.append(43) else: known_hosts_msg.append(45) known_hosts_msg.append(10) blob = self.mgr.acquire(True) # block pmt.blob_resize(blob, len(known_hosts_msg)) pmt.blob_rw_data(blob)[:] = known_hosts_msg self.post_msg(APP_PORT, pmt.string_to_symbol('rx'), blob, pmt.string_to_symbol('fhss')) # Synchronization if (pkt[1] < self.own_adr and self.discovery_finished and not self.synced): self.interval_start = int(math.floor(self.time_update)) + ( self._msg_to_time(pkt[3:11])[0] % 1) + (2 * self.hop_interval) #self.interval_start = self.time_update + (2 * self.hop_interval) #DEBUG print "BCN sent at", repr(self._msg_to_time(pkt[3:11])[0]), " time now", self.time_update #DEBUG print "interval start", self.interval_start # TODO: This is for DEBUGGING ONLY! #while self.interval_start > (self.time_update + 1) and self.interval_start < (self.time_update + 2): # print "+++Interval-Start increased!" # self.interval_start += 1 #while self.interval_start > (self.time_update - 1) and self.interval_start < (self.time_update): # self.interval_start -= 1 # print "---Interval-Start decreased!" # Send tune command before the USRP has to tune self.time_tune_start = self.interval_start - (10 * self.post_guard) self.hop_index = (pkt[11] + 1) % self.freq_list_length if self.hops_to_beacon != 0: self.hops_to_beacon -= 1 if not self.synced: print "SYNCED!" self.synced = True
def received_data(self, pkt): """ Called if a data packet was received """ print "DATA received" #self.waiting_for_data = False self.state = IDLE self.hops_since_cts = 0 #switch back to broadcast self._shift_freq_list(self.max_neighbors - self.own_adr) blob = self.mgr.acquire(True) # block pmt.blob_resize(blob, len(pkt) - 1) pmt.blob_rw_data(blob)[:] = pkt[1:] self.post_msg(APP_PORT, pmt.string_to_symbol('rx'), blob, pmt.string_to_symbol('fhss'))
def waiting_for_cts(self): """ Called after setting next tune command if node is waiting for CTS pkt. """ # Waiting for CTS - Set random time to retransmit RTS! # TODO: Delete message if max_num_retries reached!!! # ---> self.tx_queue element loeschen # set False in neighbors if self.hops_to_retx == 0: print "Try no.", self.retx_no self.retx_no += 1 if self.retx_no > (self.max_rts_tries + 1): self.queue.get() self.neighbors[self.dst_adr - 1] = False #self.waiting_for_cts = False self.state = IDLE self.hops_to_retx = 0 self.retx_no = 1 print "Node", self.dst_adr, "appears to be down - remove from known nodes." # TODO: DEMO-STUFF! known_hosts_msg = [107, 104, 58] for node in self.neighbors: if node is True: known_hosts_msg.append(43) else: known_hosts_msg.append(45) known_hosts_msg.append(10) blob = self.mgr.acquire(True) # block pmt.blob_resize(blob, len(known_hosts_msg)) pmt.blob_rw_data(blob)[:] = known_hosts_msg self.post_msg(APP_PORT, pmt.string_to_symbol('rx'), blob, pmt.string_to_symbol('fhss')) else: self.hops_to_retx = random.randint( (self.retx_no - 1) * self.max_hops_to_retx, self.retx_no * self.max_hops_to_retx) self.get_cts() self.hops_to_retx -= 1 self.hops_to_beacon += 1