Exemple #1
0
 def test_send_scp_request_to_nonexistent_host(self):
     with self.assertRaises(SpinnmanTimeoutException):
         board_config.set_up_nonexistent_board()
         connection = SCAMPConnection(remote_host=board_config.remotehost)
         scp = ReadMemory(0, 0, 0, 256)
         connection.send_scp_request(scp)
         _, _, _, _ = connection.receive_scp_response(2)
Exemple #2
0
 def test_scp_read_memory_request_and_response_board(self):
     board_config.set_up_remote_board()
     connection = SCAMPConnection(remote_host=board_config.remotehost)
     scp_link = ReadMemory(0, 0, 0x70000000, 256)
     connection.send_scp_request(scp_link)
     result, _, _, _ = connection.receive_scp_response()
     self.assertEqual(result, SCPResult.RC_OK)
Exemple #3
0
 def test_scp_version_request_and_response_board(self):
     board_config.set_up_remote_board()
     connection = SCAMPConnection(remote_host=board_config.remotehost)
     scp_req = GetVersion(0, 0, 0)
     scp_response = GetVersionResponse()
     connection.send_scp_request(scp_req)
     _, _, data, offset = connection.receive_scp_response()
     scp_response.read_bytestring(data, offset)
     print(scp_response.version_info)
     self.assertEqual(scp_response._scp_response_header._result,
                      SCPResult.RC_OK)
    def get_data(
            self, transceiver, placement, memory_address, length_in_bytes,
            fixed_routes):
        """ Gets data from a given core and memory address.

        :param transceiver: spinnman instance
        :param placement: placement object for where to get data from
        :param memory_address: the address in SDRAM to start reading from
        :param length_in_bytes: the length of data to read in bytes
        :param fixed_routes: the fixed routes, used in the report of which\
            chips were used by the speed up process
        :return: byte array of the data
        """
        start = float(time.time())

        # if asked for no data, just return a empty byte array
        if length_in_bytes == 0:
            data = bytearray(0)
            end = float(time.time())
            self._provenance_data_items[
                placement, memory_address,
                length_in_bytes].append((end - start, [0]))
            return data

        if (length_in_bytes <
                self.THRESHOLD_WHERE_SDP_BETTER_THAN_DATA_EXTRACTOR_IN_BYTES):
            data = transceiver.read_memory(
                placement.x, placement.y, memory_address, length_in_bytes)
            end = float(time.time())
            self._provenance_data_items[
                placement, memory_address,
                length_in_bytes].append((end - start, [0]))
            return data

        # Update the IP Tag to work through a NAT firewall
        connection = SCAMPConnection(
            chip_x=self._x, chip_y=self._y, remote_host=self._ip_address)
        request = IPTagSet(
            self._x, self._y, [0, 0, 0, 0], 0,
            self._remote_tag, strip=True, use_sender=True)
        data = connection.get_scp_data(request)
        sent = False
        tries_to_go = 3
        while not sent:
            try:
                connection.send(data)
                _, _, response, offset = \
                    connection.receive_scp_response()
                request.get_scp_response().read_bytestring(response, offset)
                sent = True
            except SpinnmanTimeoutException:
                if not tries_to_go:
                    reraise(*sys.exc_info())
                tries_to_go -= 1

        data = _THREE_WORDS.pack(
            self.SDP_PACKET_START_SENDING_COMMAND_ID,
            memory_address, length_in_bytes)

        # logger.debug("sending to core %d:%d:%d",
        #              placement.x, placement.y, placement.p)

        # send
        connection.send_sdp_message(SDPMessage(
            sdp_header=SDPHeader(
                destination_chip_x=placement.x,
                destination_chip_y=placement.y,
                destination_cpu=placement.p,
                destination_port=self.SDP_PORT,
                flags=SDPFlag.REPLY_NOT_EXPECTED),
            data=data))

        # receive
        self._output = bytearray(length_in_bytes)
        self._view = memoryview(self._output)
        self._max_seq_num = self.calculate_max_seq_num()
        lost_seq_nums = self._receive_data(transceiver, placement, connection)

        # Stop anything else getting through (and reduce traffic)
        data = _ONE_WORD.pack(self.SDP_PACKET_CLEAR)
        connection.send_sdp_message(SDPMessage(
            sdp_header=SDPHeader(
                destination_chip_x=placement.x,
                destination_chip_y=placement.y,
                destination_cpu=placement.p,
                destination_port=self.SDP_PORT,
                flags=SDPFlag.REPLY_NOT_EXPECTED),
            data=data))
        connection.close()

        end = float(time.time())
        self._provenance_data_items[
            placement, memory_address, length_in_bytes].append(
                (end - start, lost_seq_nums))

        # create report elements
        if self._write_data_speed_up_report:
            routers_been_in_use = self._determine_which_routers_were_used(
                placement, fixed_routes, transceiver.get_machine_details())
            self._write_routers_used_into_report(
                self._report_path, routers_been_in_use, placement)

        return self._output