From 3ced2f5a9632e213a11916c6d3bf7aca1e44d494 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 1 Aug 2023 16:25:15 +0100 Subject: [PATCH] move Transceiver and create_transceiver_from_hostname --- spinnman/data/spinnman_data_writer.py | 2 +- spinnman/extended/extended_transceiver.py | 5 +- spinnman/spalloc/spalloc_client.py | 2 +- spinnman/spalloc/spalloc_job.py | 2 +- spinnman/transceiver/__init__.py | 18 +++++ spinnman/{ => transceiver}/transceiver.py | 0 spinnman/transceiver/transceiver_factory.py | 90 +++++++++++++++++++++ unittests/data/test_data.py | 2 +- unittests/test_transceiver.py | 2 +- unittests/test_version.py | 2 +- 10 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 spinnman/transceiver/__init__.py rename spinnman/{ => transceiver}/transceiver.py (100%) create mode 100644 spinnman/transceiver/transceiver_factory.py diff --git a/spinnman/data/spinnman_data_writer.py b/spinnman/data/spinnman_data_writer.py index 2136f6247..f526ff051 100644 --- a/spinnman/data/spinnman_data_writer.py +++ b/spinnman/data/spinnman_data_writer.py @@ -16,7 +16,7 @@ from spinn_utilities.log import FormatAdapter from spinn_utilities.overrides import overrides from spinn_machine.data.machine_data_writer import MachineDataWriter -from spinnman.transceiver import Transceiver +from spinnman.transceiver.transceiver import Transceiver from .spinnman_data_view import _SpiNNManDataModel, SpiNNManDataView logger = FormatAdapter(logging.getLogger(__name__)) diff --git a/spinnman/extended/extended_transceiver.py b/spinnman/extended/extended_transceiver.py index f2120267f..b6f118621 100644 --- a/spinnman/extended/extended_transceiver.py +++ b/spinnman/extended/extended_transceiver.py @@ -23,7 +23,7 @@ from spinn_utilities.logger_utils import warn_once from spinn_machine import CoreSubsets from spinnman.constants import SYSTEM_VARIABLE_BASE_ADDRESS -from spinnman.transceiver import Transceiver +from spinnman.transceiver.transceiver import Transceiver from spinnman.constants import ( ROUTER_REGISTER_BASE_ADDRESS, ROUTER_FILTER_CONTROLS_OFFSET, ROUTER_DIAGNOSTIC_FILTER_SIZE) @@ -42,7 +42,8 @@ from spinnman.processes import ( GetHeapProcess, ReadMemoryProcess, SendSingleCommandProcess, WriteMemoryProcess) -from spinnman.transceiver import _EXECUTABLE_ADDRESS, _ONE_BYTE, _ONE_WORD +from spinnman.transceiver.transceiver import ( + _EXECUTABLE_ADDRESS, _ONE_BYTE, _ONE_WORD) from spinnman.utilities.utility_functions import ( work_out_bmp_from_machine_details) diff --git a/spinnman/spalloc/spalloc_client.py b/spinnman/spalloc/spalloc_client.py index cd2758d4a..945cb27bd 100644 --- a/spinnman/spalloc/spalloc_client.py +++ b/spinnman/spalloc/spalloc_client.py @@ -35,7 +35,7 @@ from spinnman.constants import SCP_SCAMP_PORT, UDP_BOOT_CONNECTION_DEFAULT_PORT from spinnman.exceptions import SpinnmanTimeoutException from spinnman.exceptions import SpallocException -from spinnman.transceiver import Transceiver +from spinnman.transceiver.transceiver import Transceiver from .spalloc_state import SpallocState from .proxy_protocol import ProxyProtocol from .session import Session, SessionAware diff --git a/spinnman/spalloc/spalloc_job.py b/spinnman/spalloc/spalloc_job.py index 3ed3edd16..81035a5ed 100644 --- a/spinnman/spalloc/spalloc_job.py +++ b/spinnman/spalloc/spalloc_job.py @@ -17,7 +17,7 @@ from spinn_utilities.abstract_base import AbstractBase, abstractmethod from spinn_utilities.abstract_context_manager import AbstractContextManager from spinnman.constants import SCP_SCAMP_PORT -from spinnman.transceiver import Transceiver +from spinnman.transceiver.transceiver import Transceiver from spinnman.connections.udp_packet_connections import UDPConnection from .spalloc_state import SpallocState from .spalloc_boot_connection import SpallocBootConnection diff --git a/spinnman/transceiver/__init__.py b/spinnman/transceiver/__init__.py new file mode 100644 index 000000000..899e31121 --- /dev/null +++ b/spinnman/transceiver/__init__.py @@ -0,0 +1,18 @@ +# Copyright (c) 2021 The University of Manchester +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from spinnman.transceiver.transceiver_factory import ( + create_transceiver_from_hostname) + +__all__ = ["create_transceiver_from_hostname"] diff --git a/spinnman/transceiver.py b/spinnman/transceiver/transceiver.py similarity index 100% rename from spinnman/transceiver.py rename to spinnman/transceiver/transceiver.py diff --git a/spinnman/transceiver/transceiver_factory.py b/spinnman/transceiver/transceiver_factory.py new file mode 100644 index 000000000..1078b2d58 --- /dev/null +++ b/spinnman/transceiver/transceiver_factory.py @@ -0,0 +1,90 @@ +# Copyright (c) 2023 The University of Manchester +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +from spinn_utilities.log import FormatAdapter +from spinnman.utilities.utility_functions import ( + work_out_bmp_from_machine_details) +from spinnman.connections.udp_packet_connections import ( + BMPConnection, BootConnection, SCAMPConnection) +from spinnman.transceiver.transceiver import Transceiver + +logger = FormatAdapter(logging.getLogger(__name__)) + + +def create_transceiver_from_hostname( + hostname, version, bmp_connection_data=None, number_of_boards=None, + auto_detect_bmp=False): + """ + Create a Transceiver by creating a :py:class:`~.UDPConnection` to the + given hostname on port 17893 (the default SCAMP port), and a + :py:class:`~.BootConnection` on port 54321 (the default boot port), + optionally discovering any additional links using the UDPConnection, + and then returning the transceiver created with the conjunction of + the created UDPConnection and the discovered connections. + + :param hostname: The hostname or IP address of the board or `None` if + only the BMP connections are of interest + :type hostname: str or None + :param number_of_boards: a number of boards expected to be supported, or + ``None``, which defaults to a single board + :type number_of_boards: int or None + :param int version: the type of SpiNNaker board used within the SpiNNaker + machine being used. If a Spinn-5 board, then the version will be 5, + Spinn-3 would equal 3 and so on. + :param list(BMPConnectionData) bmp_connection_data: + the details of the BMP connections used to boot multi-board systems + :param bool auto_detect_bmp: + ``True`` if the BMP of version 4 or 5 boards should be + automatically determined from the board IP address + :param scamp_connections: + the list of connections used for SCAMP communications + :return: The created transceiver + :rtype: Transceiver + :raise SpinnmanIOException: + If there is an error communicating with the board + :raise SpinnmanInvalidPacketException: + If a packet is received that is not in the valid format + :raise SpinnmanInvalidParameterException: + If a packet is received that has invalid parameters + :raise SpinnmanUnexpectedResponseCodeException: + If a response indicates an error during the exchange + """ + if hostname is not None: + logger.info("Creating transceiver for {}", hostname) + connections = list() + + # if no BMP has been supplied, but the board is a spinn4 or a spinn5 + # machine, then an assumption can be made that the BMP is at -1 on the + # final value of the IP address + if (version >= 4 and auto_detect_bmp is True and + (bmp_connection_data is None or not bmp_connection_data)): + bmp_connection_data = [ + work_out_bmp_from_machine_details(hostname, number_of_boards)] + + # handle BMP connections + if bmp_connection_data is not None: + bmp_ip_list = list() + for conn_data in bmp_connection_data: + bmp_connection = BMPConnection(conn_data) + connections.append(bmp_connection) + bmp_ip_list.append(bmp_connection.remote_ip_address) + logger.info("Transceiver using BMPs: {}", bmp_ip_list) + + connections.append(SCAMPConnection(remote_host=hostname)) + + # handle the boot connection + connections.append(BootConnection(remote_host=hostname)) + + return Transceiver(version, connections=connections) diff --git a/unittests/data/test_data.py b/unittests/data/test_data.py index ab4fa0652..ffa00f898 100644 --- a/unittests/data/test_data.py +++ b/unittests/data/test_data.py @@ -18,7 +18,7 @@ from spinnman.config_setup import unittest_setup from spinnman.data import SpiNNManDataView from spinnman.data.spinnman_data_writer import SpiNNManDataWriter -from spinnman.transceiver import Transceiver +from spinnman.transceiver.transceiver import Transceiver class MockTranceiver(Transceiver): diff --git a/unittests/test_transceiver.py b/unittests/test_transceiver.py index 52c31486c..63b65964a 100644 --- a/unittests/test_transceiver.py +++ b/unittests/test_transceiver.py @@ -19,7 +19,7 @@ from spinnman.config_setup import unittest_setup from spinnman.data.spinnman_data_writer import SpiNNManDataWriter from spinnman.extended.extended_transceiver import ExtendedTransceiver -from spinnman.transceiver import Transceiver +from spinnman.transceiver.transceiver import Transceiver from spinnman import constants from spinnman.messages.spinnaker_boot.system_variable_boot_values import ( SystemVariableDefinition) diff --git a/unittests/test_version.py b/unittests/test_version.py index c8f42fc87..eec3cdc8c 100644 --- a/unittests/test_version.py +++ b/unittests/test_version.py @@ -15,7 +15,7 @@ import unittest import spinn_utilities import spinn_machine -from spinnman.transceiver import Transceiver, _SCAMP_VERSION +from spinnman.transceiver.transceiver import Transceiver, _SCAMP_VERSION import spinnman from spinnman.config_setup import unittest_setup