diff --git a/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/BMPController.java b/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/BMPController.java index eb4d280eee..c564e7fb98 100644 --- a/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/BMPController.java +++ b/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/BMPController.java @@ -67,9 +67,9 @@ import uk.ac.manchester.spinnaker.alloc.db.Row; import uk.ac.manchester.spinnaker.alloc.model.Direction; import uk.ac.manchester.spinnaker.alloc.model.JobState; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.machine.board.BMPBoard; import uk.ac.manchester.spinnaker.machine.board.BMPCoords; +import uk.ac.manchester.spinnaker.machine.board.HasBMPLocation; import uk.ac.manchester.spinnaker.messages.model.ADCInfo; import uk.ac.manchester.spinnaker.messages.model.Blacklist; import uk.ac.manchester.spinnaker.transceiver.ProcessException; @@ -156,6 +156,7 @@ private void init() { var sched = new ThreadPoolTaskScheduler(); scheduler = sched; sched.setThreadGroupName("BMP"); + sched.initialize(); controllerFactory = controllerFactoryBean::getObject; allocator.setBMPController(this); @@ -292,7 +293,7 @@ final boolean bmpAction(ThrowingAction body, exn = e; log.error("Requests failed on BMP {}", bmpId, e); } catch (PermanentProcessException e) { - log.error("BMP {} on {} is unreachable", e.core, bmpId, e); + log.error("BMP {} on {} is unreachable", e.source, bmpId, e); onServiceRemove.accept(e); exn = e; } catch (CallerProcessException e) { @@ -643,7 +644,7 @@ public String toString() { private void badBoard(ProcessException failure) { try (var c = getConnection()) { c.transaction(() -> { - getBoardId(failure.core).ifPresent(boardId -> { + getBoardId(failure.source).ifPresent(boardId -> { // Mark the board as dead right now markBoardAsDead(c, boardId, REPORT_MSG + failure); // Add a report if we can @@ -661,8 +662,8 @@ private void badBoard(ProcessException failure) { * The board address. * @return The ID, if one can be found. */ - private Optional getBoardId(HasCoreLocation addr) { - return Optional.ofNullable(boardToId.get(addr.getP())); + private Optional getBoardId(HasBMPLocation addr) { + return Optional.ofNullable(boardToId.get(addr.getBoard())); } private Integer getBoardId(BMPBoard board) { diff --git a/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/FirmwareLoader.java b/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/FirmwareLoader.java index 5a13c60bae..0cb109b7b9 100644 --- a/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/FirmwareLoader.java +++ b/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/bmp/FirmwareLoader.java @@ -398,13 +398,13 @@ private void updateFlashData(ByteBuffer data) private void logBMPVersion() throws ProcessException, IOException, InterruptedException { var info = txrx.readBMPVersion(board); - // TODO validate which field is which; some of these seem... unlikely log.info("BMP INFO: {}", format("%s %s at %s:%s (built %s) [C=%s, F=%s, B=%s]", info.name, info.versionNumber, info.hardware, - info.core.getP(), Instant.ofEpochSecond(info.buildDate), - info.physicalCPUID, info.core.getY(), - info.core.getX())); + info.physicalCPUID, + Instant.ofEpochSecond(info.buildDate), + info.location.getCabinet(), info.location.getFrame(), + info.location.getBoard())); } /** diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/connections/UDPConnection.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/connections/UDPConnection.java index f6eba3ee85..3840c1b6ac 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/connections/UDPConnection.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/connections/UDPConnection.java @@ -49,8 +49,8 @@ import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper; import uk.ac.manchester.spinnaker.connections.model.Connection; -import uk.ac.manchester.spinnaker.machine.CoreLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPMessage; /** @@ -697,7 +697,7 @@ public final void sendPortTriggerMessage(InetAddress host) * REPLY_NOT_EXPECTED flag is set (see scamp-3.c line 728 and 625-644) */ var triggerMessage = new SDPMessage(new SDPHeader(REPLY_NOT_EXPECTED, - new CoreLocation(0, 0, 0), RUNNING_COMMAND_SDP_PORT)); + new SDPLocation(0, 0, 0), RUNNING_COMMAND_SDP_PORT)); sendTo(triggerMessage.getMessageData(null), host, SCP_SCAMP_PORT); } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPRequest.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPRequest.java index b92b27e137..4cf6b75665 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPRequest.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPRequest.java @@ -31,6 +31,7 @@ import uk.ac.manchester.spinnaker.messages.scp.SCPRequest; import uk.ac.manchester.spinnaker.messages.scp.SCPResponse; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; import uk.ac.manchester.spinnaker.utils.UsedInJavadocOnly; /** @@ -43,7 +44,7 @@ public abstract class BMPRequest extends SCPRequest { private static SDPHeader header(int board) { - return new SDPHeader(REPLY_EXPECTED, new BMPLocation(board), + return new SDPHeader(REPLY_EXPECTED, new SDPLocation(0, 0, board), DEFAULT_PORT); } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/model/VersionInfo.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/model/VersionInfo.java index 99c0108f19..6194df6c53 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/model/VersionInfo.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/model/VersionInfo.java @@ -26,9 +26,7 @@ import java.nio.ByteBuffer; import java.util.regex.Pattern; -import uk.ac.manchester.spinnaker.machine.CoreLocation; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; -import uk.ac.manchester.spinnaker.messages.bmp.BMPLocation; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; /** * Decodes SC&MP/SARK version information as returned by the SVER command. @@ -57,7 +55,7 @@ public final class VersionInfo { public final String versionString; /** The location of the core where the information was obtained. */ - public final HasCoreLocation core; + public final SDPLocation location; private static final Pattern VERSION_RE = Pattern .compile("(?\\d+)\\.(?\\d+)\\.(?\\d+)"); @@ -100,11 +98,7 @@ public VersionInfo(ByteBuffer buffer, boolean isBMP) { physicalCPUID = toUnsignedInt(buffer.get()); int y = toUnsignedInt(buffer.get()); int x = toUnsignedInt(buffer.get()); - if (isBMP) { - core = new BMPLocation(x, y, p); - } else { - core = new CoreLocation(x, y, p); - } + location = new SDPLocation(x, y, p); buffer.getShort(); // Ignore 2 bytes int vn = toUnsignedInt(buffer.getShort()); buildDate = buffer.getInt(); @@ -144,7 +138,7 @@ public VersionInfo(ByteBuffer buffer, boolean isBMP) { @Override public String toString() { - return "VersionInfo(" + core + " (phys:" + physicalCPUID + return "VersionInfo(" + location + " (phys:" + physicalCPUID + "), version: " + versionNumber + ", " + name + "/" + hardware + ", " + ofInstant(ofEpochSecond(buildDate, 0), UTC) .format(ISO_INSTANT) diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/FECRequest.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/FECRequest.java index 26cade2b89..4e0ab3a479 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/FECRequest.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/FECRequest.java @@ -22,6 +22,7 @@ import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; /** * A command message to a core using FrontEndCommon lib's simulation management @@ -79,7 +80,7 @@ public abstract class FECRequest extends SCPRequest { private static SDPHeader header(HasCoreLocation core, boolean replyExpected) { return new SDPHeader( - replyExpected ? REPLY_EXPECTED : REPLY_NOT_EXPECTED, core, - RUNNING_COMMAND_SDP_PORT); + replyExpected ? REPLY_EXPECTED : REPLY_NOT_EXPECTED, + new SDPLocation(core), RUNNING_COMMAND_SDP_PORT); } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/ReinjectorRequest.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/ReinjectorRequest.java index 870b6884a3..014ccffa00 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/ReinjectorRequest.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/ReinjectorRequest.java @@ -22,6 +22,7 @@ import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; /** * A command message to an extra monitor control core to manipulate the packet @@ -86,7 +87,7 @@ public abstract class ReinjectorRequest * @return The SDP header. */ private static SDPHeader header(HasCoreLocation core) { - return new SDPHeader(REPLY_EXPECTED, core, + return new SDPHeader(REPLY_EXPECTED, new SDPLocation(core), EXTRA_MONITOR_CORE_REINJECTION); } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/RouterTableRequest.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/RouterTableRequest.java index 96d0b70c29..4cc1a1b70c 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/RouterTableRequest.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/RouterTableRequest.java @@ -25,6 +25,7 @@ import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.model.UnexpectedResponseCodeException; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; /** * A command message to an extra monitor control core to manipulate the router @@ -70,6 +71,7 @@ public final EmptyResponse getSCPResponse(ByteBuffer buffer) * @return The SDP header. */ static final SDPHeader header(HasCoreLocation core) { - return new SDPHeader(REPLY_EXPECTED, core, GATHERER_DATA_SPEED_UP); + return new SDPHeader(REPLY_EXPECTED, new SDPLocation(core), + GATHERER_DATA_SPEED_UP); } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/SCPRequest.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/SCPRequest.java index e4f78c497f..ba72d7d7db 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/SCPRequest.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/scp/SCPRequest.java @@ -25,6 +25,7 @@ import uk.ac.manchester.spinnaker.machine.CoreLocation; import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; import uk.ac.manchester.spinnaker.messages.sdp.SpinnakerRequest; /** @@ -82,7 +83,8 @@ public abstract class SCPRequest * @return The SDP header. */ private static SDPHeader header(HasCoreLocation core) { - return new SDPHeader(REPLY_EXPECTED, core, DEFAULT_PORT); + return new SDPHeader(REPLY_EXPECTED, new SDPLocation(core), + DEFAULT_PORT); } /** diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPHeader.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPHeader.java index c32029083e..4687a4c7b7 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPHeader.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPHeader.java @@ -16,20 +16,15 @@ package uk.ac.manchester.spinnaker.messages.sdp; import static java.lang.Byte.toUnsignedInt; -import static uk.ac.manchester.spinnaker.machine.MachineDefaults.MAX_NUM_CORES; -import static uk.ac.manchester.spinnaker.machine.MachineDefaults.validateChipLocation; import static uk.ac.manchester.spinnaker.utils.CollectionUtils.makeEnumBackingMap; import java.nio.ByteBuffer; import java.util.Map; import javax.validation.Valid; -import javax.validation.constraints.PositiveOrZero; import uk.ac.manchester.spinnaker.machine.CoreLocation; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.SerializableMessage; -import uk.ac.manchester.spinnaker.messages.bmp.BMPLocation; /** * Represents the header of an SDP message. @@ -48,12 +43,12 @@ public final class SDPHeader implements SerializableMessage { private static final int PORT_MASK = (1 << PORT_BITS) - 1; @Valid - private HasCoreLocation destination; + private SDPLocation destination; private int destinationPort; @Valid - private HasCoreLocation source; + private SDPLocation source; private int sourcePort; @@ -85,7 +80,7 @@ public SDPHeader() { * @throws IllegalArgumentException * if a bad SDP port is given */ - public SDPHeader(Flag flags, HasCoreLocation destination, + public SDPHeader(Flag flags, SDPLocation destination, int destinationPort) { this.flags = flags; this.destination = destination; @@ -109,7 +104,7 @@ public SDPHeader(Flag flags, HasCoreLocation destination, * this is not a UDP port! Those are associated with a * connection, not a message. */ - public SDPHeader(Flag flags, HasCoreLocation destination, + public SDPHeader(Flag flags, SDPLocation destination, SDPPort destinationPort) { this.flags = flags; this.destination = destination; @@ -137,52 +132,8 @@ public SDPHeader(ByteBuffer buffer, boolean isBMP) { int scx = toUnsignedInt(buffer.get()); destinationPort = (dpc >> CPU_ADDR_BITS) & PORT_MASK; sourcePort = (spc >> CPU_ADDR_BITS) & PORT_MASK; - if (isBMP) { - destination = new BMPLocation(dcx, dcy, dpc & CPU_MASK); - source = new BMPLocation(scx, scy, spc & CPU_MASK); - } else { - destination = allocCoreLocation(dcx, dcy, dpc & CPU_MASK); - source = allocCoreLocation(scx, scy, spc & CPU_MASK); - } - } - - private HasCoreLocation allocCoreLocation(int x, int y, int p) { - if (p >= 0 && p < MAX_NUM_CORES) { - return new CoreLocation(x, y, p); - } - validateChipLocation(x, y); - return new HasCoreLocation() { - @Override - public int getX() { - return x; - } - - @Override - public int getY() { - return y; - } - - @Override - @PositiveOrZero - public int getP() { - return p; - } - - @Override - public int hashCode() { - throw new UnsupportedOperationException( - "this object may not be used as a key"); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof HasCoreLocation)) { - return false; - } - var c = (HasCoreLocation) other; - return x == c.getX() && y == c.getY() && p == c.getP(); - } - }; + destination = new SDPLocation(dcx, dcy, dpc & CPU_MASK); + source = new SDPLocation(scx, scy, spc & CPU_MASK); } @Override @@ -196,10 +147,10 @@ public void addToBuffer(ByteBuffer buffer) { buffer.put((byte) tag); buffer.put((byte) dpc); buffer.put((byte) spc); - buffer.put((byte) destination.getY()); - buffer.put((byte) destination.getX()); - buffer.put((byte) source.getY()); - buffer.put((byte) source.getX()); + buffer.put((byte) destination.minor); + buffer.put((byte) destination.major); + buffer.put((byte) source.minor); + buffer.put((byte) source.major); } /** @@ -207,7 +158,7 @@ public void addToBuffer(ByteBuffer buffer) { * address for addresses off the machine; that address is not * normally representable in a {@link CoreLocation}. */ - public HasCoreLocation getDestination() { + public SDPLocation getDestination() { return destination; } @@ -217,7 +168,7 @@ public HasCoreLocation getDestination() { * special address for addresses off the machine; that address * is not normally representable in a {@link CoreLocation}. */ - public void setDestination(HasCoreLocation destination) { + public void setDestination(SDPLocation destination) { this.destination = destination; } @@ -252,7 +203,7 @@ public void setDestinationPort(int port) { } /** @return What "chip" originated the message. */ - public HasCoreLocation getSource() { + public SDPLocation getSource() { return source; } @@ -262,7 +213,7 @@ public HasCoreLocation getSource() { * special address for origination off the machine; that address * is not normally representable in a {@link CoreLocation}. */ - public void setSource(HasCoreLocation source) { + public void setSource(SDPLocation source) { this.source = source; } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPLocation.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPLocation.java new file mode 100644 index 0000000000..d755626d98 --- /dev/null +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SDPLocation.java @@ -0,0 +1,196 @@ +/* + * 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. + */ +package uk.ac.manchester.spinnaker.messages.sdp; + +import uk.ac.manchester.spinnaker.machine.ChipLocation; +import uk.ac.manchester.spinnaker.machine.CoreLocation; +import uk.ac.manchester.spinnaker.machine.HasCoreLocation; +import uk.ac.manchester.spinnaker.machine.board.BMPLocation; +import uk.ac.manchester.spinnaker.machine.board.HasBMPLocation; + +/** + * Represents a location in an SDP message. This could be a core location + * or a BMP location. As such it can be interpreted as either. + */ +public class SDPLocation implements HasCoreLocation, HasBMPLocation { + + /** Shift for major in hash code. **/ + private static final int MAJOR_SHIFT = 24; + + /** Shift for minor in hash code. **/ + private static final int MINOR_SHIFT = 16; + + /** The first value. **/ + final int major; + + /** The second value. **/ + final int minor; + + /** The third value. **/ + final int detail; + + /** Was constructed from a core location. **/ + private final boolean fromCoreLocation; + + /** Was constructed from a BMP location. **/ + private final boolean fromBMPLocation; + + /** + * Make an SDPLocation from a core location. + * + * @param core The core location to use. + */ + public SDPLocation(HasCoreLocation core) { + major = core.getX(); + minor = core.getY(); + detail = core.getP(); + fromCoreLocation = true; + fromBMPLocation = false; + } + + /** + * Make an SDPLocation from a BMP location. + * + * @param bmp The BMP location to use. + */ + public SDPLocation(HasBMPLocation bmp) { + major = bmp.getCabinet(); + minor = bmp.getFrame(); + detail = bmp.getBoard(); + fromCoreLocation = false; + fromBMPLocation = true; + } + + /** + * Make an SDPLocation from components. + * + * @param major The first part of the location (x or cabinet). + * @param minor The second part of the location (y or frame). + * @param detail The third part of the location (p or board). + */ + public SDPLocation(int major, int minor, int detail) { + this.major = major; + this.minor = minor; + this.detail = detail; + fromCoreLocation = false; + fromBMPLocation = false; + } + + private void errorIfBMP() { + if (fromBMPLocation) { + throw new InvalidSDPHeaderUseException("This SDP Location is" + + " specifically constructed from a BMPLocation so use with" + + " CoreLocation properties is not supported!"); + } + } + + private void errorIfCore() { + if (fromCoreLocation) { + throw new InvalidSDPHeaderUseException("This SDP Location is" + + " specifically constructed from a CoreLocation so use" + + " with BMPLocation properties is not supported!"); + } + } + + @Override + public int getX() { + errorIfBMP(); + return major; + } + + @Override + public int getY() { + errorIfBMP(); + return minor; + } + + @Override + public int getP() { + errorIfBMP(); + return detail; + } + + @Override + public int getCabinet() { + errorIfCore(); + return major; + } + + @Override + public int getFrame() { + errorIfCore(); + return minor; + } + + @Override + public int getBoard() { + errorIfCore(); + return detail; + } + + @Override + public ChipLocation asChipLocation() { + errorIfBMP(); + return HasCoreLocation.super.asChipLocation(); + } + + @Override + public CoreLocation asCoreLocation() { + errorIfBMP(); + return HasCoreLocation.super.asCoreLocation(); + } + + @Override + public BMPLocation asBMPLocation() { + errorIfCore(); + return HasBMPLocation.super.asBMPLocation(); + } + + @Override + public String toString() { + if (fromCoreLocation) { + return "SDPLocation(X=" + major + ", Y=" + minor + + ", P=" + detail + ")"; + } + if (fromBMPLocation) { + return "SDPLocation(Cabinet=" + major + ", Frame=" + minor + + ", Board=" + detail + ")"; + } + return "SDPLocation(" + major + ", " + minor + ", " + detail + ")"; + } + + @Override + public int hashCode() { + return (major << MAJOR_SHIFT) + (minor << MINOR_SHIFT) + detail; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SDPLocation)) { + return false; + } + SDPLocation sdp = (SDPLocation) obj; + return sdp.major == major && sdp.minor == minor && sdp.detail == detail; + } + + private static class InvalidSDPHeaderUseException extends RuntimeException { + private static final long serialVersionUID = 1L; + + InvalidSDPHeaderUseException(String reason) { + super(reason); + } + } +} diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SpinnakerRequest.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SpinnakerRequest.java index b8d603e2d1..e562537883 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SpinnakerRequest.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/sdp/SpinnakerRequest.java @@ -70,7 +70,7 @@ public final ByteBuffer getMessageData(HasChipLocation originatingChip) { // Set ready for sending sdpHeader.setTag(SDP_TAG); sdpHeader.setSourcePort(SDP_SOURCE_PORT); - sdpHeader.setSource(new SDPSource(originatingChip)); + sdpHeader.setSource(new SDPLocation(new SDPSource(originatingChip))); // Serialize var buffer = newMessageBuffer(); diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPCommandProcess.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPCommandProcess.java index 0c7f5180da..1837d263b0 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPCommandProcess.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPCommandProcess.java @@ -38,7 +38,7 @@ import uk.ac.manchester.spinnaker.connections.BMPConnection; import uk.ac.manchester.spinnaker.connections.ConnectionSelector; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; +import uk.ac.manchester.spinnaker.machine.board.HasBMPLocation; import uk.ac.manchester.spinnaker.messages.bmp.BMPRequest; import uk.ac.manchester.spinnaker.messages.bmp.BMPRequest.BMPResponse; import uk.ac.manchester.spinnaker.messages.scp.SCPResultMessage; @@ -359,7 +359,7 @@ private void parseReceivedResponse(SCPResultMessage msg) } } - private HasCoreLocation dest() { + private HasBMPLocation dest() { return request.sdpHeader.getDestination(); } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPSendFailedException.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPSendFailedException.java index 2705fd7e91..0592f31b60 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPSendFailedException.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/BMPSendFailedException.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.util.List; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; +import uk.ac.manchester.spinnaker.machine.board.HasBMPLocation; import uk.ac.manchester.spinnaker.messages.scp.SCPRequest; /** @@ -30,12 +30,12 @@ public final class BMPSendFailedException extends IOException { private static final long serialVersionUID = -7806549580351626377L; - BMPSendFailedException(SCPRequest req, HasCoreLocation core, + BMPSendFailedException(SCPRequest req, HasBMPLocation bmp, List retryReason) { super(format( "Errors sending request %s (%s) to %d,%d,%d over %d retries:" + " %s", - req.scpRequestHeader.command, req, core.getX(), core.getY(), - core.getP(), BMP_RETRIES, retryReason)); + req.scpRequestHeader.command, req, bmp.getCabinet(), + bmp.getFrame(), bmp.getBoard(), BMP_RETRIES, retryReason)); } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/ProcessException.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/ProcessException.java index 761f5ab336..8bc70d6d12 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/ProcessException.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/ProcessException.java @@ -18,9 +18,9 @@ import static java.lang.String.format; import static java.util.Objects.requireNonNull; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.model.UnexpectedResponseCodeException; import uk.ac.manchester.spinnaker.messages.scp.SCPResult; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; /** * Encapsulates exceptions from processes which communicate with some core/chip. @@ -35,7 +35,7 @@ public class ProcessException extends SpinnmanException { + "with message: %s"; /** Where does the code believe this exception originated? */ - public final HasCoreLocation core; + public final SDPLocation source; /** * The response that cause this exception to be thrown, if known. Never @@ -44,23 +44,23 @@ public class ProcessException extends SpinnmanException { */ public final SCPResult responseCode; - private ProcessException(HasCoreLocation core, Throwable cause, + private ProcessException(SDPLocation source, Throwable cause, SCPResult responseCode) { - super(format(MSG_TEMPLATE, core.getX(), core.getY(), core.getP(), + super(format(MSG_TEMPLATE, source.getX(), source.getY(), source.getP(), cause.getClass().getName(), cause.getMessage()), cause); - this.core = core.asCoreLocation(); + this.source = source; this.responseCode = responseCode; } - private ProcessException(HasCoreLocation core, + private ProcessException(SDPLocation source, UnexpectedResponseCodeException cause) { - this(core, cause, cause.response); + this(source, cause, cause.response); } /** * Create an exception. * - * @param core + * @param source * What core were we talking to. * @param cause * What exception caused problems. @@ -68,44 +68,44 @@ private ProcessException(HasCoreLocation core, * @throws InterruptedException * If the cause was an interrupt, it is immediately rethrown. */ - static ProcessException makeInstance(HasCoreLocation core, + static ProcessException makeInstance(SDPLocation source, Throwable cause) throws InterruptedException { if (requireNonNull(cause) instanceof UnexpectedResponseCodeException) { var urc = (UnexpectedResponseCodeException) cause; if (urc.response == null) { - return new ProcessException(core, cause, null); + return new ProcessException(source, cause, null); } switch (urc.response) { case RC_LEN: - return new BadPacketLength(core, urc); + return new BadPacketLength(source, urc); case RC_SUM: - return new BadChecksum(core, urc); + return new BadChecksum(source, urc); case RC_CMD: - return new BadCommand(core, urc); + return new BadCommand(source, urc); case RC_ARG: - return new InvalidArguments(core, urc); + return new InvalidArguments(source, urc); case RC_PORT: - return new BadSCPPort(core, urc); + return new BadSCPPort(source, urc); case RC_TIMEOUT: - return new TimedOut(core, urc); + return new TimedOut(source, urc); case RC_ROUTE: - return new NoP2PRoute(core, urc); + return new NoP2PRoute(source, urc); case RC_CPU: - return new BadCPUNumber(core, urc); + return new BadCPUNumber(source, urc); case RC_DEAD: - return new DeadDestination(core, urc); + return new DeadDestination(source, urc); case RC_BUF: - return new NoBufferAvailable(core, urc); + return new NoBufferAvailable(source, urc); case RC_P2P_NOREPLY: - return new P2PNoReply(core, urc); + return new P2PNoReply(source, urc); case RC_P2P_REJECT: - return new P2PReject(core, urc); + return new P2PReject(source, urc); case RC_P2P_BUSY: - return new P2PBusy(core, urc); + return new P2PBusy(source, urc); case RC_P2P_TIMEOUT: - return new P2PTimedOut(core, urc); + return new P2PTimedOut(source, urc); case RC_PKT_TX: - return new PacketTransmissionFailed(core, urc); + return new PacketTransmissionFailed(source, urc); default: // Fall through } @@ -113,7 +113,7 @@ static ProcessException makeInstance(HasCoreLocation core, if (cause instanceof InterruptedException) { throw (InterruptedException) cause; } - return new ProcessException(core, cause, null); + return new ProcessException(source, cause, null); } /** @@ -124,9 +124,9 @@ public abstract static class CallerProcessException extends ProcessException { private static final long serialVersionUID = 1L; - private CallerProcessException(HasCoreLocation core, + private CallerProcessException(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -138,9 +138,9 @@ public abstract static class TransientProcessException extends ProcessException { private static final long serialVersionUID = 1L; - private TransientProcessException(HasCoreLocation core, + private TransientProcessException(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -154,9 +154,9 @@ public abstract static class PermanentProcessException extends ProcessException { private static final long serialVersionUID = 1L; - private PermanentProcessException(HasCoreLocation core, + private PermanentProcessException(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -167,9 +167,9 @@ private PermanentProcessException(HasCoreLocation core, public static final class BadPacketLength extends CallerProcessException { private static final long serialVersionUID = 4329836896716525422L; - private BadPacketLength(HasCoreLocation core, + private BadPacketLength(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -180,9 +180,9 @@ private BadPacketLength(HasCoreLocation core, public static final class BadChecksum extends CallerProcessException { private static final long serialVersionUID = -5660270018252119601L; - private BadChecksum(HasCoreLocation core, + private BadChecksum(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -194,9 +194,9 @@ private BadChecksum(HasCoreLocation core, public static final class BadCommand extends CallerProcessException { private static final long serialVersionUID = 2446636059917726286L; - private BadCommand(HasCoreLocation core, + private BadCommand(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -207,9 +207,9 @@ private BadCommand(HasCoreLocation core, public static final class InvalidArguments extends CallerProcessException { private static final long serialVersionUID = 3907517289211998444L; - private InvalidArguments(HasCoreLocation core, + private InvalidArguments(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -220,9 +220,9 @@ private InvalidArguments(HasCoreLocation core, public static final class BadSCPPort extends CallerProcessException { private static final long serialVersionUID = -5171910962257032626L; - private BadSCPPort(HasCoreLocation core, + private BadSCPPort(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -234,9 +234,9 @@ private BadSCPPort(HasCoreLocation core, public static final class TimedOut extends TransientProcessException { private static final long serialVersionUID = -298985937364034661L; - private TimedOut(HasCoreLocation core, + private TimedOut(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -248,9 +248,9 @@ private TimedOut(HasCoreLocation core, public static final class NoP2PRoute extends PermanentProcessException { private static final long serialVersionUID = -6132417061161625508L; - private NoP2PRoute(HasCoreLocation core, + private NoP2PRoute(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -261,9 +261,9 @@ private NoP2PRoute(HasCoreLocation core, public static final class BadCPUNumber extends CallerProcessException { private static final long serialVersionUID = 6532417803149087690L; - private BadCPUNumber(HasCoreLocation core, + private BadCPUNumber(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -276,9 +276,9 @@ public static final class DeadDestination extends PermanentProcessException { private static final long serialVersionUID = -3842030808096451015L; - private DeadDestination(HasCoreLocation core, + private DeadDestination(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -290,9 +290,9 @@ public static final class NoBufferAvailable extends TransientProcessException { private static final long serialVersionUID = 3647501054775981197L; - private NoBufferAvailable(HasCoreLocation core, + private NoBufferAvailable(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -304,9 +304,9 @@ private NoBufferAvailable(HasCoreLocation core, public static final class P2PNoReply extends TransientProcessException { private static final long serialVersionUID = 2196366740196153289L; - private P2PNoReply(HasCoreLocation core, + private P2PNoReply(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -318,9 +318,9 @@ private P2PNoReply(HasCoreLocation core, public static final class P2PReject extends TransientProcessException { private static final long serialVersionUID = -2903670314989693747L; - private P2PReject(HasCoreLocation core, + private P2PReject(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -332,9 +332,9 @@ private P2PReject(HasCoreLocation core, public static final class P2PBusy extends TransientProcessException { private static final long serialVersionUID = 4445680981367158468L; - private P2PBusy(HasCoreLocation core, + private P2PBusy(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -346,9 +346,9 @@ private P2PBusy(HasCoreLocation core, public static final class P2PTimedOut extends TransientProcessException { private static final long serialVersionUID = -7686611958418374003L; - private P2PTimedOut(HasCoreLocation core, + private P2PTimedOut(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } @@ -360,9 +360,9 @@ public static final class PacketTransmissionFailed extends TransientProcessException { private static final long serialVersionUID = 5119831821960433468L; - private PacketTransmissionFailed(HasCoreLocation core, + private PacketTransmissionFailed(SDPLocation source, UnexpectedResponseCodeException cause) { - super(core, cause); + super(source, cause); } } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/Transceiver.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/Transceiver.java index dec814a456..d0f31773ca 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/Transceiver.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/Transceiver.java @@ -895,7 +895,7 @@ void updateMachine() // Get the details of all the chips machine = new GetMachineProcess(scpSelector, ignoreChips, ignoreCores, ignoreLinks, maxSDRAMSize, this) - .getMachineDetails(versionInfo.core, dimensions); + .getMachineDetails(versionInfo.location, dimensions); /* * Ask the machine to check itself and if required to rebuild itself @@ -1303,7 +1303,7 @@ private VersionInfo findScampAndBoot(int numAttempts, while (versionInfo == null && triesLeft > 0) { try { versionInfo = getScampVersion(); - if (versionInfo.core.asChipLocation().equals(BOOT_CHIP)) { + if (versionInfo.location.asChipLocation().equals(BOOT_CHIP)) { versionInfo = null; sleep(CONNECTION_CHECK_DELAY); } @@ -1331,7 +1331,7 @@ private VersionInfo findScampAndBoot(int numAttempts, // The last thing we tried was booting, so try again to get the version if (versionInfo == null) { versionInfo = getScampVersion(); - if (versionInfo.core.asChipLocation().equals(BOOT_CHIP)) { + if (versionInfo.location.asChipLocation().equals(BOOT_CHIP)) { versionInfo = null; } } diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/TxrxProcess.java b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/TxrxProcess.java index 0167de55a6..e36e3b5216 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/TxrxProcess.java +++ b/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/transceiver/TxrxProcess.java @@ -60,6 +60,7 @@ import uk.ac.manchester.spinnaker.messages.scp.SCPResponse; import uk.ac.manchester.spinnaker.messages.scp.SCPResult; import uk.ac.manchester.spinnaker.messages.scp.SCPResultMessage; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; import uk.ac.manchester.spinnaker.utils.ValueHolder; /** @@ -602,7 +603,7 @@ public void parseReceivedResponse(SCPResultMessage msg) } @Override - public HasCoreLocation getDestination() { + public SDPLocation getDestination() { return request.sdpHeader.getDestination(); } @@ -968,9 +969,8 @@ static class SendFailedException extends IOException { */ SendFailedException(Req req, int numRetries) { super(format( - "Errors sending request %s to %d,%d,%d over %d retries: %s", - req.getCommand(), req.getDestination().getX(), - req.getDestination().getY(), req.getDestination().getP(), + "Errors sending request %s to %s over %d retries: %s", + req.getCommand(), req.getDestination(), numRetries, req.getRetryReasons())); } } diff --git a/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/model/TestVersionInfo.java b/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/model/TestVersionInfo.java index 2e4bc1253b..21a63a2bf1 100644 --- a/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/model/TestVersionInfo.java +++ b/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/model/TestVersionInfo.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; -import uk.ac.manchester.spinnaker.machine.CoreLocation; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; class TestVersionInfo { private ByteBuffer packVersionData(int arg1, int arg2, int arg3, @@ -54,7 +54,7 @@ void testRetrievingBitsFromVersionData() assertEquals("my", vi.name); assertEquals(new Version(2, 55, 0), vi.versionNumber); assertEquals("spinnaker", vi.hardware); - assertEquals(new CoreLocation(0xf0, 0xa1, 0x0b), vi.core); + assertEquals(new SDPLocation(0xf0, 0xa1, 0x0b), vi.location); assertEquals(buildDate, vi.buildDate); assertEquals("my/spinnaker", vi.versionString); } diff --git a/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/GeneralMessageTest.java b/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/GeneralMessageTest.java index d02994217f..4110181f89 100644 --- a/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/GeneralMessageTest.java +++ b/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/GeneralMessageTest.java @@ -61,6 +61,7 @@ import uk.ac.manchester.spinnaker.messages.bmp.WriteFlashBuffer; import uk.ac.manchester.spinnaker.messages.bmp.WriteSerialFlash; import uk.ac.manchester.spinnaker.messages.model.AppID; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; class GeneralMessageTest { private static final AppID APP = new AppID(1); @@ -84,9 +85,9 @@ class GeneralMessageTest { private int length(SCPRequest req) { // Serialise and get message length var b = allocate(280); - req.sdpHeader.setSource(ZERO_ZERO_ZERO); + req.sdpHeader.setSource(new SDPLocation(ZERO_ZERO_ZERO)); req.sdpHeader.setSourcePort(0); - req.sdpHeader.setDestination(ZERO_ZERO_ZERO); + req.sdpHeader.setDestination(new SDPLocation(ZERO_ZERO_ZERO)); req.sdpHeader.setDestinationPort(0); req.scpRequestHeader.issueSequenceNumber(set); req.addToBuffer(b); diff --git a/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/TestVersion.java b/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/TestVersion.java index 18670b9036..c466b4400d 100644 --- a/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/TestVersion.java +++ b/SpiNNaker-comms/src/test/java/uk/ac/manchester/spinnaker/messages/scp/TestVersion.java @@ -29,6 +29,7 @@ import uk.ac.manchester.spinnaker.machine.CoreLocation; import uk.ac.manchester.spinnaker.messages.model.UnexpectedResponseCodeException; import uk.ac.manchester.spinnaker.messages.model.Version; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; class TestVersion { private static final short PADDING = 0; @@ -37,7 +38,7 @@ class TestVersion { void testNewVersionRequest() { var verRequest = new GetVersion(new CoreLocation(0, 1, 2)); assertEquals(CMD_VER, verRequest.scpRequestHeader.command); - assertEquals(new CoreLocation(0, 1, 2), + assertEquals(new SDPLocation(0, 1, 2), verRequest.sdpHeader.getDestination()); } @@ -78,7 +79,7 @@ void testParseVersionResponseFormat1() assertEquals("sark", ver.name); assertEquals("spinnaker", ver.hardware); assertEquals(new Version(2, 34, 0), ver.versionNumber); - assertEquals(new CoreLocation(14, 31, 0), ver.core); + assertEquals(new SDPLocation(14, 31, 0), ver.location); } @Test @@ -118,6 +119,6 @@ void testParseVersionResponseFormat2() assertEquals("SC&MP", response.get().name); assertEquals("SpiNNaker", response.get().hardware); assertEquals(new Version(3, 2, 0), response.get().versionNumber); - assertEquals(new CoreLocation(14, 31, 0), response.get().core); + assertEquals(new SDPLocation(14, 31, 0), response.get().location); } } diff --git a/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/download/GatherProtocolMessage.java b/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/download/GatherProtocolMessage.java index cc9afc7c3d..22b4bf1aab 100644 --- a/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/download/GatherProtocolMessage.java +++ b/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/download/GatherProtocolMessage.java @@ -21,6 +21,7 @@ import uk.ac.manchester.spinnaker.machine.HasCoreLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPMessage; import uk.ac.manchester.spinnaker.messages.sdp.SDPPort; @@ -43,8 +44,8 @@ public abstract class GatherProtocolMessage extends SDPMessage { */ protected GatherProtocolMessage(HasCoreLocation destination, SDPPort destPort, ByteBuffer payload) { - super(new SDPHeader(REPLY_NOT_EXPECTED, destination, destPort), - payload); + super(new SDPHeader(REPLY_NOT_EXPECTED, new SDPLocation(destination), + destPort), payload); } /** The various IDs of messages used in the fast download protocol. */ diff --git a/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/dse/FastDataInProtocol.java b/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/dse/FastDataInProtocol.java index 5de90448f1..0b7b4fca4d 100644 --- a/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/dse/FastDataInProtocol.java +++ b/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/dse/FastDataInProtocol.java @@ -38,6 +38,7 @@ import uk.ac.manchester.spinnaker.machine.Machine; import uk.ac.manchester.spinnaker.machine.MemoryLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPHeader; +import uk.ac.manchester.spinnaker.messages.sdp.SDPLocation; import uk.ac.manchester.spinnaker.messages.sdp.SDPMessage; /** @@ -107,7 +108,7 @@ class FastDataInProtocol { } private SDPHeader header() { - return new SDPHeader(REPLY_NOT_EXPECTED, gathererCore, + return new SDPHeader(REPLY_NOT_EXPECTED, new SDPLocation(gathererCore), GATHERER_DATA_SPEED_UP.value); } diff --git a/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/HasCoreLocation.java b/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/HasCoreLocation.java index 628b3bb4fd..3a0939790a 100644 --- a/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/HasCoreLocation.java +++ b/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/HasCoreLocation.java @@ -24,9 +24,7 @@ public interface HasCoreLocation extends HasChipLocation { /** * @return The processor coordinate of the core on its chip. */ - // We would like to validate this, but BMP also uses it and that uses - // P values outside of the valid range! - // @ValidP + @ValidP int getP(); /** diff --git a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPLocation.java b/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/board/BMPLocation.java similarity index 72% rename from SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPLocation.java rename to SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/board/BMPLocation.java index a8640a5ac0..41bbc70764 100644 --- a/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/messages/bmp/BMPLocation.java +++ b/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/board/BMPLocation.java @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package uk.ac.manchester.spinnaker.messages.bmp; +package uk.ac.manchester.spinnaker.machine.board; + +import static uk.ac.manchester.spinnaker.machine.board.Limits.MAX_FRAME; +import static uk.ac.manchester.spinnaker.machine.board.Limits.MAX_CABINET; import uk.ac.manchester.spinnaker.machine.CoreLocation; -import uk.ac.manchester.spinnaker.machine.HasCoreLocation; -import uk.ac.manchester.spinnaker.machine.board.ValidBoardNumber; -import uk.ac.manchester.spinnaker.machine.board.ValidCabinetNumber; -import uk.ac.manchester.spinnaker.machine.board.ValidFrameNumber; import uk.ac.manchester.spinnaker.utils.UsedInJavadocOnly; /** @@ -29,7 +28,7 @@ * @author Donal Fellows */ @UsedInJavadocOnly(CoreLocation.class) -public final class BMPLocation implements HasCoreLocation { +public final class BMPLocation implements HasBMPLocation { @ValidCabinetNumber private final int cabinet; @@ -65,29 +64,18 @@ public BMPLocation(int cabinet, int frame, int board) { this.board = board; } - /** - * @return The cabinet number of the board. Not actually a processor - * coordinate. - */ @Override - public int getX() { + public int getCabinet() { return cabinet; } - /** - * @return The frame number of the board. Not actually a processor - * coordinate. - */ @Override - public int getY() { + public int getFrame() { return frame; } - /** - * @return The board number of the board. Not actually a processor ID. - */ @Override - public int getP() { + public int getBoard() { return board; } @@ -103,6 +91,6 @@ public boolean equals(Object other) { @Override public int hashCode() { - return board; + return (((board * MAX_FRAME) + frame) * MAX_CABINET) + cabinet; } } diff --git a/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/board/HasBMPLocation.java b/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/board/HasBMPLocation.java new file mode 100644 index 0000000000..3feb14ea77 --- /dev/null +++ b/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/board/HasBMPLocation.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018 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. + */ +package uk.ac.manchester.spinnaker.machine.board; + +/** + * The interface supported by any object that is associated with a board + * location. + */ +public interface HasBMPLocation { + /** + * @return The cabinet number of the board. Not actually a processor + * coordinate. + */ + @ValidCabinetNumber + int getCabinet(); + + /** + * @return The frame number of the board. Not actually a processor + * coordinate. + */ + @ValidFrameNumber + int getFrame(); + + /** + * @return The board number of the board. Not actually a processor ID. + */ + @ValidBoardNumber + int getBoard(); + + /** + * Converts (if required) this to a simple X, Y, P tuple. + * + * @return A CoreLocation representation of the X, Y, P tuple + */ + default BMPLocation asBMPLocation() { + return new BMPLocation(getCabinet(), getFrame(), getBoard()); + } +}