def handle_rx(self, packet, port): """ Called by the framework when this Entity receives a packet. packet is a Packet (or subclass). port is the port number it arrived on. You definitely want to fill this in. """ #self.log("RX %s on %s (%s)", packet, port, api.current_time()) if isinstance(packet, basics.RoutePacket): self.routingTable[port] = [packet.latency, packet.destination] if packet.destination in self.distanceVector: if self.distanceVector[packet.destination][ 0] >= packet.latency + self.neighbors[port]: self.distanceVector[packet.destination] = [ packet.latency + self.neighbors[port], port ] else: self.distanceVector[packet.destination] = [ packet.latency + self.neighbors[port], port ] api.create_timer(15, self.expire_route, False, False, [packet.destination]) elif isinstance(packet, basics.HostDiscoveryPacket): self.distanceVector[packet.src] = [self.neighbors[port], port] self.directHosts[packet.src] = port else: # Totally wrong behavior for the sake of demonstration only: send # the packet back to where it came from! # self.send(packet, port=port) if packet.dst in self.distanceVector: if self.distanceVector[packet.dst][1] != port: self.send(packet, self.distanceVector[packet.dst][1])
def start_timer(self, interval=None): """ Start the timer that calls handle_timer() This should get called in the constructor. You shouldn't override this. """ if interval is None: interval = self.DEFAULT_TIMER_INTERVAL if interval is None: return api.create_timer(interval, self.handle_timer)
def start_timer (self, interval = None): """ Start the timer that calls handle_timer() This should get called in the constructor. You shouldn't override this. """ if interval is None: interval = self.DEFAULT_TIMER_INTERVAL if interval is None: return api.create_timer(interval, self.handle_timer)