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_adding_a_reverse_iptag(self): """ check that adding a reverse iptag works correctly """ tag_info = Tags() reverse_iptag = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_reverse_ip_tag(reverse_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 _allocate_ports_for_reverse_ip_tags(self, tasks, ports, tags): for tag_constraint, board_address, tag, vertex, placement in tasks: if board_address not in ports: ports[board_address] = OrderedSet(_BOARD_PORTS) port = ports[board_address].pop(last=False) reverse_ip_tag = ReverseIPTag(board_address, tag, port, placement.x, placement.y, placement.p, tag_constraint.sdp_port) tags.add_reverse_ip_tag(reverse_ip_tag, vertex)
def test_add_conflicting_reverse_ip_tag(self): tags = Tags() tag1 = ReverseIPTag("", 1, 23, 0, 0, 1, 1) tag2 = ReverseIPTag("", 1, 23, 0, 0, 1, 1) tag3 = IPTag("", 0, 7, 1, "122.2.2.3", 1, False) machine_vertex = SimpleMachineVertex(None, "") tags.add_reverse_ip_tag(tag1, machine_vertex) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_reverse_ip_tag(tag2, 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("The tag has already been assigned to a reverse IP tag" " on the given board", str(e.exception)) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_reverse_ip_tag(tag3, machine_vertex) self.assertIn("Only add reverse IP tags with this method.", str(e.exception))
def test_add_reverse_iptag_then_locate_tag(self): """ check that asking for a reverse iptag for a specific machine vertex works """ tag_info = Tags() reverse_iptag = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_reverse_ip_tag(reverse_iptag, machine_vertex) gotton_tag = tag_info.get_reverse_ip_tags_for_vertex(machine_vertex) self.assertEqual(gotton_tag[0], reverse_iptag)
def test_add_reverse_iptag_then_not_locate_tag(self): """ check that asking for a reverse iptag with a incorrect machine vertex will cause a none returned """ tag_info = Tags() reverse_iptag = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") machine_vertex2 = SimpleMachineVertex(None, "") tag_info.add_reverse_ip_tag(reverse_iptag, machine_vertex2) gotton_tag = tag_info.get_reverse_ip_tags_for_vertex(machine_vertex) self.assertEqual(gotton_tag, None)
def __allocate_ports_for_reverse_ip_tags(tasks, ports, tags): """ :param list(_Task) tag_port_tasks: :param dict(str,set(int)) ports: :param Tags tags: """ for task in tasks: if task.board not in ports: ports[task.board] = OrderedSet(_BOARD_PORTS) port = ports[task.board].pop(last=False) reverse_ip_tag = ReverseIPTag(task.board, task.tag, port, task.placement.x, task.placement.y, task.placement.p, task.constraint.sdp_port) tags.add_reverse_ip_tag(reverse_ip_tag, task.vertex)
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)
def test_tag_rendering(self): riptag = ReverseIPTag("somewhere.local", 2, 3, 4, 5, 6) assert riptag.__repr__() == ( "ReverseIPTag(board_address=somewhere.local, tag=2, port=3, " "destination_x=4, destination_y=5, destination_p=6, sdp_port=1)")