Пример #1
0
def new_route(session):
    r = model.Route()
    default_origin = CONFIG['routes']['default origin']
    default_dest = CONFIG['routes']['default destination']
    origin = mapper.place_search(default_origin)
    dest = mapper.place_search(default_dest)
    if origin is None or dest is None:
        if origin is None:
            print('Could not find origin', default_origin)
        if dest is None:
            print('Could not find dest', default_dest)
        sys.exit(1)
    r.origin = origin.osm_id
    r.dest = dest.osm_id

    model.add_place_if_not_exists(origin, session)
    model.add_place_if_not_exists(dest, session)
    session.add(r)
    session.commit()
    rs = model.RouteStep()
    rs.route_id = r.id
    rs.route_step = 0
    rs.place = r.origin
    session.add(rs)
    session.commit()

    return r
Пример #2
0
	def setUp(self):
		"""
		Create a small network with a few routes within it.
		"""
		
		self.chips = model.make_rectangular_board(3,3)
		
		# A self-loop on 0,1,0
		model.add_route(model.Route(0), [ self.chips[(0,1)][1][0]
		                                , self.chips[(0,1)][0]
		                                , self.chips[(0,1)][1][0]
		                                ])
		
		# A straight route from 0,0,0 to 2,0,0
		model.add_route(model.Route(1), [ self.chips[(0,0)][1][0]
		                                , self.chips[(0,0)][0]
		                                , self.chips[(1,0)][0]
		                                , self.chips[(2,0)][0]
		                                , self.chips[(2,0)][1][0]
		                                ])
		
		# A multicast from from 0,2,0 to 1,2,0,  2,2,0 and 1,1,0
		r = model.Route(2)
		model.add_route(r, [ self.chips[(0,2)][1][0]
		                   , self.chips[(0,2)][0]
		                   , self.chips[(1,2)][0]
		                   , self.chips[(1,2)][1][0]
		                   ])
		model.add_route(r, [ self.chips[(0,2)][1][0]
		                   , self.chips[(0,2)][0]
		                   , self.chips[(1,2)][0]
		                   , self.chips[(2,2)][0]
		                   , self.chips[(2,2)][1][0]
		                   ])
		model.add_route(r, [ self.chips[(0,2)][1][0]
		                   , self.chips[(0,2)][0]
		                   , self.chips[(1,2)][0]
		                   , self.chips[(1,1)][0]
		                   , self.chips[(1,1)][1][0]
		                   ])
		
		# A self-loop on 1,1,1 to result in 1,1 having multiple routing entries
		model.add_route(model.Route(3), [ self.chips[(1,1)][1][1]
		                                , self.chips[(1,1)][0]
		                                , self.chips[(1,1)][1][1]
		                                ])
Пример #3
0
	def test_get_all_routes_empty(self):
		"""
		Test that model.get_all_routes finds some in a system containing some
		"""
		chips = model.make_rectangular_board(2,2)
		
		# A set of test routes
		ref_routes = {
			# Unicast self loop
			model.Route(0): (chips[(0,0)][1][0], set([chips[(0,0)][1][0]])),
			
			# Broadcast to all cores on a chip
			model.Route(1): (chips[(0,0)][1][0], set(chips[(0,0)][1])),
			
			# Multicast messages from everyone from them to two other chips
			model.Route(2): (chips[(0,0)][1][0], set([chips[(1,0)][1][0], chips[(1,1)][1][1]])),
			model.Route(3): (chips[(1,0)][1][0], set([chips[(0,0)][1][0], chips[(0,1)][1][1]])),
			model.Route(4): (chips[(0,1)][1][0], set([chips[(1,1)][1][0], chips[(1,0)][1][1]])),
			model.Route(5): (chips[(1,1)][1][0], set([chips[(0,1)][1][0], chips[(0,0)][1][1]])),
		}
		
		# Add the reference routes to the network
		for route, (source, sinks) in ref_routes.iteritems():
			source.sources.add(route)
			for sink in sinks:
				sink.sinks.add(route)
		
		# Check that the routes found match the routes added
		found_routes = model.get_all_routes(chips)
		self.assertEqual(len(found_routes), len(ref_routes))
		for route, (source, sinks) in found_routes.iteritems():
			self.assertEqual(ref_routes[route][0], source)
			self.assertEqual(ref_routes[route][1], sinks)
Пример #4
0
def save_route_to_db(name, start, end, travel_mode, user):
    """ Creates new route object and appends to db. """

    # Create new route
    route = model.Route()
    route.name = name
    route.user_id = user
    route.start = start
    route.end = end
    route.travel_mode = travel_mode
    model.session.add(route)
    model.session.commit()

    return route
Пример #5
0
	def test_dor_perfect_case(self):
		"""
		Test dimension-order-routing in the case where routing should be possible.
		"""
		
		width  = 5
		height = 5
		
		port_to_dimension = {
			topology.EAST: 0,
			topology.WEST: 0,
			topology.NORTH: 1,
			topology.SOUTH: 1,
			topology.NORTH_EAST: 2,
			topology.SOUTH_WEST: 2,
		}
		
		for wrap_around in (True, False):
			chips = model.make_rectangular_board(width, height, wrap_around = wrap_around)
			for dimension_order in ( (0,1,2), (2,1,0) ):
				for route, source, sinks in ( # Self-loop
				                              (model.Route(0), chips[(0,0)][1][0], ( chips[(0,0)][1][0], )),
				                              # One-to-one (same row)
				                              (model.Route(1), chips[(0,0)][1][0], ( chips[(4,0)][1][0], )),
				                              # One-to-one (different row)
				                              (model.Route(2), chips[(0,0)][1][0], ( chips[(2,1)][1][0], )),
				                              # One-to-one (may use wrap-around)
				                              (model.Route(3), chips[(0,0)][1][0], ( chips[(4,4)][1][0], )),
				                              # One-to-N
				                              (model.Route(4), chips[(0,0)][1][0], ( chips[(0,0)][1][0]
				                                                                   , chips[(4,0)][1][0]
				                                                                   , chips[(0,4)][1][0]
				                                                                   , chips[(4,4)][1][0]
				                                                                   )),
				                            ):
					node_sequences, unrouted_sinks = \
						routers.dimension_order_route(source, sinks, chips
						                             , use_wrap_around = wrap_around
						                             , dimension_order = dimension_order
						                             )
					
					# Nothing should be unroutable
					self.assertFalse(unrouted_sinks)
					
					# Should be one route per sink
					self.assertEqual(len(sinks), len(node_sequences))
					
					# All node sequences should start from the source
					for node_sequence in node_sequences:
						self.assertEqual(node_sequence[0], source)
					
					sinks_routed = set()
					for node_sequence in node_sequences:
						sequence_sink = node_sequence[-1]
						# Each sink must not have multiple node sequences leading to it
						self.assertNotIn(sequence_sink, sinks_routed)
						sinks_routed.add(sequence_sink)
					
					# Every sink must have node sequence leading to it
					self.assertEqual(set(sinks), sinks_routed)
					
					# Test that the route follows the order of dimensions required
					for node_sequence in node_sequences:
						dimensions = list(dimension_order)
						for step in xrange(1, len(node_sequence) - 2):
							router = node_sequence[step]
							next_router = node_sequence[step+1]
							
							# Find the port to the next router
							for port, next_router_ in router.connections.iteritems():
								if next_router_ == next_router:
									break
								port = None
							
							# Whenever the direction changes, it must change to a direction
							# next in the ordering
							while dimensions[0] != port_to_dimension[port]:
								dimensions.pop(0)
								self.assertTrue(dimensions)
Пример #6
0
	def test_add_route(self):
		"""
		Test that model.add_route successfully works for a simple multicast route (and
		that defining the route twice has no ill-effects).
		"""
		chips = model.make_rectangular_board(2,2)
		
		# Make a path travelling round the system (do it twice to make sure nothing
		# gets duplicated)
		route = model.Route(0)
		for _ in range(2):
			model.add_route( route
			               , [ chips[(0,0)][1][0]
			                 , chips[(0,0)][0]
			                 , chips[(0,1)][0]
			                 , chips[(1,1)][0]
			                 , chips[(1,0)][0]
			                 , chips[(1,0)][1][17]
			                 ]
			               )
			model.add_route( route
			               , [ chips[(0,0)][1][0]
			                 , chips[(0,0)][0]
			                 , chips[(0,1)][0]
			                 , chips[(1,1)][0]
			                 , chips[(1,1)][1][17]
			                 ]
			               )
		
		# Check that the route was added in the appropriate sink/source and nowhere
		# else
		for (position, core) in sum(( list((router.position, core) for core in cores)
		                              for (router,cores) in chips.itervalues()
		                            ), []):
			# Source should be in chip (0,0)'s 0th core
			if position == (0,0) and core.core_id == 0:
				self.assertEqual(core.sources, set([route]))
			else:
				self.assertEqual(core.sources, set())
			
			# Sink should be in chips (1,0)'s and (1,1)'s 17th core
			if position in ((1,0), (1,1)) and core.core_id == 17:
				self.assertEqual(core.sinks, set([route]))
			else:
				self.assertEqual(core.sinks, set())
		
		
		# Check that all connecting edges between routers are valid (i.e. face in
		# opposite directions and make sense)
		for router, cores in chips.itervalues():
			for route, (input_port, output_ports) in router.routes.iteritems():
				# Test the input has a corresponding output in the router/core
				if input_port in model.Router.INTERNAL_PORTS:
					# If a route is from a core, make sure the core knows about it
					core = router.connections[input_port]
					self.assertIn(route, core.sources)
				else:
					# Check the corresponding router has an output for this route pointing
					# at this router.
					other_router = router.connections[input_port]
					self.assertIn( topology.opposite(input_port)
					             , other_router.routes[route][1]
					             )
				
				# Test all outputs have a coresponding input in another router/core
				for output_port in output_ports:
					if output_port in model.Router.INTERNAL_PORTS:
						# If a route is to a core, make sure the core knows about it
						core = router.connections[output_port]
						self.assertIn(route, core.sinks)
					else:
						# Check the corresponding router has an input for this route pointing
						# from this router.
						other_router = router.connections[output_port]
						self.assertEqual( topology.opposite(output_port)
						                , other_router.routes[route][0]
						                )