Ejemplo n.º 1
0
	def test_block(self):
		# Test that packets are not generated when the link is blocked.
		
		scheduler = Scheduler()
		system = SpiNNakerSystem(scheduler, 10)
		
		link = DeadLink(scheduler)
		
		# Uniform generator node
		tg = SpiNNakerTrafficGenerator( scheduler
		                              , system
		                              , 1
		                              , 0.1
		                              , link
		                              , link
		                              )
		tg.set_mesh_dimensions(100,100)
		tg.set_mesh_position(50,50)
		
		it = scheduler.run()
		
		# Perform 1000 cycles
		while it.next() < 2000 and tg.counters["generator_cycles"] < 1000:
			pass
		
		# Should have done 1000 cycles
		self.assertEqual(tg.counters["generator_cycles"], 1000)
		
		# We should have tried to send some number of packets that isn't all the
		# time and not never (well, in theory we might not but hey, if this is going
		# wrong you've got a bad day on your hands).
		self.assertTrue(10 < tg.counters["generator_dropped_packets"] < 1000)
		
		# None should have gone out
		self.assertEqual(tg.counters["generator_injected_packets"], 0)
Ejemplo n.º 2
0
	def test_normal(self):
		# Test that packets are generated appropriately when distributing with a
		# normal distribution.
		
		scheduler = Scheduler()
		system = SpiNNakerSystem(scheduler, 10)
		
		# Share the same link for sending and receiving, that way the module cleans
		# up after itself!
		link = BufferLink(scheduler)
		
		# Uniform generator node
		tg = SpiNNakerTrafficGenerator( scheduler
		                              , system
		                              , 1
		                              , 0.1
		                              , link
		                              , link
		                              , 10
		                              )
		tg.set_mesh_dimensions(100,100)
		tg.set_mesh_position(50,50)
		
		it = scheduler.run()
		
		# Perform 1000 cycles
		while it.next() < 2000 and tg.counters["generator_cycles"] < 1000:
			# We may have a packet
			if link.can_receive():
				# Check the packet is targeted somewhere in the mesh
				packet = link.receive()
				self.assertTrue(all(0 <= dimension < 100 for dimension in packet.destination))
		
		# XXX: Should probably check that distribution is appropriate too but meh...
		
		# Should have done 1000 cycles
		self.assertEqual(tg.counters["generator_cycles"], 1000)
		
		# We should have sent some number of packets that isn't all the time and not
		# never (well, in theory we might not but hey, if this is going wrong you've
		# got a bad day on your hands).
		self.assertTrue(10 < tg.counters["generator_injected_packets"] < 1000)
		
		# None should be dropped
		self.assertEqual(tg.counters["generator_dropped_packets"], 0)
Ejemplo n.º 3
0
	def __init__( self
	            , scheduler
	            , system
	            
	            , injection_buffer_length
	            
	            , router_period          # SpiNNakerRouter
	            , wait_before_emergency  # SpiNNakerRouter
	            , wait_before_drop       # SpiNNakerRouter
	            
	            , core_period            # SpiNNakerTrafficGenerator
	            , packet_prob            # SpiNNakerTrafficGenerator
	            , distance_std = None    # SpiNNakerTrafficGenerator
	            ):
		"""
		injection_buffer_length is the number of packets that can be buffered internally
		before they're routed.
		
		router_period see SpiNNakerRouter
		wait_before_emergency see SpiNNakerRouter
		wait_before_drop see SpiNNakerRouter
		
		core_period see SpiNNakerTrafficGenerator
		packet_prob see SpiNNakerTrafficGenerator
		distance_std see SpiNNakerTrafficGenerator
		"""
		
		self.scheduler = scheduler
		self.system    = system
		
		# Links between the router and traffic generator
		injection_link = BufferLink(self.scheduler, injection_buffer_length)
		exit_link      = BufferLink(self.scheduler)
		
		# The external connections to the rest of the world
		self.in_links = [DeadLink(self.scheduler)]*6
		self.out_links = [DeadLink(self.scheduler)]*6
		
		self.traffic_generator = SpiNNakerTrafficGenerator( self.scheduler
		                                                  , self.system
		                                                  , core_period
		                                                  , packet_prob
		                                                  , injection_link
		                                                  , exit_link
		                                                  , distance_std
		                                                  )
		
		self.router = SpiNNakerRouter( self.scheduler
		                             , self.system
		                             , injection_link
		                             , exit_link
		                             , self.in_links
		                             , self.out_links
		                             , router_period
		                             , wait_before_emergency
		                             , wait_before_drop
		                             )
Ejemplo n.º 4
0
	def test_receive(self):
		# Test that packets are received by the unit
		
		scheduler = Scheduler()
		system = SpiNNakerSystem(scheduler, 10)
		
		# Share the same link for sending and receiving, that way the module cleans
		# up after itself!
		link = BufferLink(scheduler)
		packet = SpiNNakerP2PPacket(system, None, (0,0), 1)
		
		# Uniform generator node
		tg = SpiNNakerTrafficGenerator( scheduler
		                              , system
		                              , 1
		                              , 0
		                              , link
		                              , link
		                              , 10
		                              )
		tg.set_mesh_dimensions(100,100)
		tg.set_mesh_position(50,50)
		
		it = scheduler.run()
		
		# Perform 10 cycles, injecting some packets each time
		while it.next() < 20 and tg.counters["generator_cycles"] < 10:
			self.assertTrue(link.can_send())
			link.send(packet)
		
		# Should have done 10 cycles
		self.assertEqual(tg.counters["generator_cycles"], 10)
		
		# We should have sent no packets
		self.assertEqual(tg.counters["generator_injected_packets"], 0)
		
		# None should be dropped
		self.assertEqual(tg.counters["generator_dropped_packets"], 0)
		
		# Should have received 10 packets
		self.assertEqual(tg.counters["generator_packets_received"], 10)
Ejemplo n.º 5
0
class SpiNNaker101(object):
	"""
	A single SpiNNaker chip, a 101 machine in SpiNNaker parlance.
	
	Contains a traffic generator and router. The links from the router are
	initially dead.
	"""
	
	def __init__( self
	            , scheduler
	            , system
	            
	            , injection_buffer_length
	            
	            , router_period          # SpiNNakerRouter
	            , wait_before_emergency  # SpiNNakerRouter
	            , wait_before_drop       # SpiNNakerRouter
	            
	            , core_period            # SpiNNakerTrafficGenerator
	            , packet_prob            # SpiNNakerTrafficGenerator
	            , distance_std = None    # SpiNNakerTrafficGenerator
	            ):
		"""
		injection_buffer_length is the number of packets that can be buffered internally
		before they're routed.
		
		router_period see SpiNNakerRouter
		wait_before_emergency see SpiNNakerRouter
		wait_before_drop see SpiNNakerRouter
		
		core_period see SpiNNakerTrafficGenerator
		packet_prob see SpiNNakerTrafficGenerator
		distance_std see SpiNNakerTrafficGenerator
		"""
		
		self.scheduler = scheduler
		self.system    = system
		
		# Links between the router and traffic generator
		injection_link = BufferLink(self.scheduler, injection_buffer_length)
		exit_link      = BufferLink(self.scheduler)
		
		# The external connections to the rest of the world
		self.in_links = [DeadLink(self.scheduler)]*6
		self.out_links = [DeadLink(self.scheduler)]*6
		
		self.traffic_generator = SpiNNakerTrafficGenerator( self.scheduler
		                                                  , self.system
		                                                  , core_period
		                                                  , packet_prob
		                                                  , injection_link
		                                                  , exit_link
		                                                  , distance_std
		                                                  )
		
		self.router = SpiNNakerRouter( self.scheduler
		                             , self.system
		                             , injection_link
		                             , exit_link
		                             , self.in_links
		                             , self.out_links
		                             , router_period
		                             , wait_before_emergency
		                             , wait_before_drop
		                             )
		
	
	
	def set_mesh_dimensions(self, w, h):
		"""
		Set the size of the mesh of chips this system is in.
		"""
		self.traffic_generator.set_mesh_dimensions(w,h)
		self.router.set_mesh_dimensions(w,h)
	
	
	def set_mesh_position(self, x, y):
		"""
		Set the size of the mesh of chips this system is in.
		"""
		self.traffic_generator.set_mesh_position(x,y)
		self.router.set_mesh_position(x,y)
	
	
	def get_mesh_position(self):
		"""
		Set the size of the mesh of chips this system is in.
		"""
		return self.router.get_mesh_position()
	
	
	def set_in_link(self, direction, link):
		"""
		Set the given link to the link specified.
		"""
		self.in_links[direction] = link
	
	
	def set_out_link(self, direction, link):
		"""
		Set the given link to the link specified.
		"""
		self.out_links[direction] = link
	
	
	def get_in_link(self, direction):
		"""
		Get the link specified.
		"""
		return self.in_links[direction]
	
	
	def get_out_link(self, direction):
		"""
		Get the link specified.
		"""
		return self.out_links[direction]