def test_call(self): """ Test calling the tags loader """ vertex = _TestVertex() tag_1 = IPTag("127.0.0.1", 0, 0, 1, "localhost", 12345, True, "Test") tag_2 = IPTag("127.0.0.1", 0, 0, 2, "localhost", 54321, True, "Test") rip_tag_1 = ReverseIPTag("127.0.0.1", 3, 12345, 0, 0, 0, 0) rip_tag_2 = ReverseIPTag("127.0.0.1", 4, 12346, 0, 0, 0, 0) tags = Tags() tags.add_ip_tag(tag_1, vertex) tags.add_ip_tag(tag_2, vertex) tags.add_reverse_ip_tag(rip_tag_1, vertex) tags.add_reverse_ip_tag(rip_tag_2, vertex) txrx = _MockTransceiver() loader = TagsLoader() loader.__call__(txrx, tags) self.assertIn(tag_1, txrx.ip_tags) self.assertIn(tag_2, txrx.ip_tags) self.assertIn(rip_tag_1, txrx.reverse_ip_tags) self.assertIn(rip_tag_2, txrx.reverse_ip_tags)
def test_listener_creation(self): # Test of buffer manager listener creation problem, where multiple # listeners were being created for the buffer manager traffic from # individual boards, where it's preferred all traffic is received by # a single listener # Create two vertices v1 = _TestVertex(10, "v1", 256) v2 = _TestVertex(10, "v2", 256) # Create two tags - important thing is port=None t1 = IPTag(board_address='127.0.0.1', destination_x=0, destination_y=1, tag=1, port=None, ip_address=None, strip_sdp=True, traffic_identifier='BufferTraffic') t2 = IPTag(board_address='127.0.0.1', destination_x=0, destination_y=2, tag=1, port=None, ip_address=None, strip_sdp=True, traffic_identifier='BufferTraffic') # Create 'Tags' object and add tags t = Tags() t.add_ip_tag(t1, v1) t.add_ip_tag(t2, v2) # Create board connections connections = [] connections.append(SCAMPConnection( remote_host=None)) connections.append(EIEIOConnection()) # Create two placements and 'Placements' object pl1 = Placement(v1, 0, 1, 1) pl2 = Placement(v2, 0, 2, 1) pl = Placements([pl1, pl2]) # Create transceiver trnx = Transceiver(version=5, connections=connections) # Alternatively, one can register a udp listener for testing via: # trnx.register_udp_listener(callback=None, # connection_class=EIEIOConnection) # Create buffer manager bm = BufferManager(pl, t, trnx) # Register two listeners, and check the second listener uses the # first rather than creating a new one bm._add_buffer_listeners(vertex=v1) bm._add_buffer_listeners(vertex=v2) number_of_listeners = 0 for i in bm._transceiver._udp_listenable_connections_by_class[ EIEIOConnection]: # Check if listener is registered on connection - we only expect # one listener to be registered, as all connections can use the # same listener for the buffer manager if not i[1] is None: number_of_listeners += 1 print i self.assertEqual(number_of_listeners, 1)
def test_adding_a_iptag_to_tag_info(self): """ check that adding a tag after initialisation works """ tag_info = Tags() iptag = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_ip_tag(iptag, machine_vertex)
def __allocate_tags_for_placement(placement, resource_tracker, tag_collector, ports_collector, tag_port_tasks): """ :param Placement placement: :param ResourceTracker resource_tracker: :param Tags tag_collector: :param dict(str,set(int)) ports_collector: :param list(_Task) tag_port_tasks: """ vertex = placement.vertex resources = vertex.resources_required # Get the constraint details for the tags (board_address, ip_tags, reverse_ip_tags) = \ ResourceTracker.get_ip_tag_info(resources, vertex.constraints) # Allocate the tags, first-come, first-served, using the fixed # placement of the vertex, and the required resources chips = [(placement.x, placement.y)] (_, _, _, returned_ip_tags, returned_reverse_ip_tags) = \ resource_tracker.allocate_resources( resources, chips, placement.p, board_address, ip_tags, reverse_ip_tags) # Put the allocated IP tag information into the tag object if returned_ip_tags is not None: for (tag_constraint, (board_address, tag, dest_x, dest_y)) in \ zip(ip_tags, returned_ip_tags): ip_tag = IPTag( board_address=board_address, destination_x=dest_x, destination_y=dest_y, tag=tag, ip_address=tag_constraint.ip_address, port=tag_constraint.port, strip_sdp=tag_constraint.strip_sdp, traffic_identifier=tag_constraint.traffic_identifier) tag_collector.add_ip_tag(ip_tag, vertex) if returned_reverse_ip_tags is None: return # Put the allocated reverse IP tag information into the tag object for tag_constraint, (board_address, tag) in zip(reverse_ip_tags, returned_reverse_ip_tags): if board_address not in ports_collector: ports_collector[board_address] = OrderedSet(_BOARD_PORTS) if tag_constraint.port is not None: reverse_ip_tag = ReverseIPTag(board_address, tag, tag_constraint.port, placement.x, placement.y, placement.p, tag_constraint.sdp_port) tag_collector.add_reverse_ip_tag(reverse_ip_tag, vertex) ports_collector[board_address].discard(tag_constraint.port) else: tag_port_tasks.append( _Task(tag_constraint, board_address, tag, vertex, placement))
def test_add_conflicting_ip_tag(self): tags = Tags() tag1 = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) tag2 = IPTag("", 0, 7, 1, "122.2.2.3", 1, False) tag3 = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") tags.add_ip_tag(tag1, machine_vertex) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_ip_tag(tag2, machine_vertex) self.assertIn( "The tag specified has already been assigned with " "different properties", str(e.exception)) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_reverse_ip_tag(tag3, machine_vertex) self.assertIn("The tag has already been assigned on the given board", str(e.exception)) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_ip_tag(tag3, machine_vertex) self.assertIn("Only add IP tags with this method.", str(e.exception))
def test_new_iptag(self): board_config.set_up_remote_board() ip = "8.8.8.8" port = 1337 tag = 255 board_address = board_config.remotehost iptag = IPTag(board_address, 0, 0, tag, ip, port) self.assertEqual(ip, iptag.ip_address) self.assertEqual(port, iptag.port) self.assertEqual(tag, iptag.tag)
def test_add_iptag_then_locate_tag(self): """ check that locating a iptag via get_ip_tags_for_vertex function """ tag_info = Tags() iptag = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_ip_tag(iptag, machine_vertex) gotton_tag = tag_info.get_ip_tags_for_vertex(machine_vertex) self.assertEqual(gotton_tag[0], iptag)
def test_add_iptag_then_fail_to_locate(self): """ test that asking for a invalid iptag returns a None value """ tag_info = Tags() iptag = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) machine_vertex = SimpleMachineVertex(None, "") machine_vertex_2 = SimpleMachineVertex(None, "") tag_info.add_ip_tag(iptag, machine_vertex) gotton_tag = tag_info.get_ip_tags_for_vertex(machine_vertex_2) self.assertEqual(gotton_tag, None)
def __handle_get_tag_response(self, tag, board_address, response): if response.in_use: ip_address = response.ip_address host = "{}.{}.{}.{}".format(ip_address[0], ip_address[1], ip_address[2], ip_address[3]) if response.is_reverse: self._tags[tag] = ReverseIPTag(board_address, tag, response.rx_port, response.spin_chip_x, response.spin_chip_y, response.spin_cpu, response.spin_port) else: self._tags[tag] = IPTag(board_address, response.sdp_header.source_chip_x, response.sdp_header.source_chip_y, tag, host, response.port, response.strip_sdp)