def measurement_average_packet_distance(self, datafile): """ Measure the time/hops taken by packets around the network """ # Set up datafile.write("shortest_hops actual_hops time\n") yield # Do nothing during the experiment try: while True: yield except Simulation.StopExperiment: pass # Collect the results after the experiment for packet in self.system.packets: # All delivered packets if packet.receive_time is not None: datafile.write("%d %d %d\n"%( # Shortest Hops topology.manhattan( topology.get_path(topology.zero_pad(packet.source), topology.zero_pad(packet.destination), (12*Simulation.WIDTH, 12*Simulation.HEIGHT)) ) + 1, # Actual Hops packet.distance, # Time packet.receive_time - packet.send_time, ))