summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-network/src/main
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-10-25 13:32:41 +0200
committerGitHub <noreply@github.com>2024-10-25 13:32:41 +0200
commit5a365dbc068f2a8cdfa9813c39cc84bb30e15637 (patch)
tree72716d562787b85e03cdc7fe1d30c827054d25a0 /opendc-simulator/opendc-simulator-network/src/main
parent27f5b7dcb05aefdab9b762175d538931face0aba (diff)
Rewrote the FlowEngine (#256)
* Removed unused components. Updated tests. Improved checkpointing model Improved model, started with SimPowerSource implemented FailureModels and Checkpointing First working version midway commit first update All simulation are now run with a single CPU and single MemoryUnit. multi CPUs are combined into one. This is for performance and explainability. * fixed merge conflicts * Updated M3SA paths. * Fixed small typo
Diffstat (limited to 'opendc-simulator/opendc-simulator-network/src/main')
-rw-r--r--opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkLink.java77
-rw-r--r--opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkPort.java110
-rw-r--r--opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSink.java70
-rw-r--r--opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitch.java35
-rw-r--r--opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitchVirtual.java107
5 files changed, 0 insertions, 399 deletions
diff --git a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkLink.java b/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkLink.java
deleted file mode 100644
index 1ea9cb0e..00000000
--- a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkLink.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.network;
-
-/**
- * A physical bidirectional communication link between two [SimNetworkPort]s.
- */
-public final class SimNetworkLink {
- private final SimNetworkPort left;
- private final SimNetworkPort right;
-
- SimNetworkLink(SimNetworkPort left, SimNetworkPort right) {
- this.left = left;
- this.right = right;
- }
-
- /**
- * Determine whether the specified <code>port</code> participates in this network link.
- *
- * @return <code>true</code> if the port participates in this link, <code>false</code> otherwise.
- */
- public boolean contains(SimNetworkPort port) {
- return port == left || port == right;
- }
-
- /**
- * Obtain the opposite port to which the specified <code>port</code> is connected through this link.
- */
- public SimNetworkPort opposite(SimNetworkPort port) {
- if (port == left) {
- return right;
- } else if (port == right) {
- return left;
- }
-
- throw new IllegalArgumentException("Invalid port given");
- }
-
- /**
- * Return the first port of the link.
- */
- public SimNetworkPort getLeft() {
- return left;
- }
-
- /**
- * Return the second port of the link.
- */
- public SimNetworkPort getRight() {
- return right;
- }
-
- @Override
- public String toString() {
- return "SimNetworkLink[left=" + left + ",right=" + right + "]";
- }
-}
diff --git a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkPort.java b/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkPort.java
deleted file mode 100644
index b5e09b9b..00000000
--- a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkPort.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.network;
-
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.Outlet;
-
-/**
- * A network port allows network devices to be connected to network through links.
- */
-public abstract class SimNetworkPort {
- SimNetworkLink link;
-
- /**
- * Determine whether the network port is connected to another port.
- *
- * @return <code>true</code> if the network port is connected, <code>false</code> otherwise.
- */
- public boolean isConnected() {
- return link != null;
- }
-
- /**
- * Return network link which connects this port to another port.
- */
- public SimNetworkLink getLink() {
- return link;
- }
-
- /**
- * Connect this port to the specified <code>port</code>.
- */
- public void connect(SimNetworkPort port) {
- if (port == this) {
- throw new IllegalArgumentException("Circular reference");
- }
- if (isConnected()) {
- throw new IllegalStateException("Port already connected");
- }
- if (port.isConnected()) {
- throw new IllegalStateException("Target port already connected");
- }
-
- final SimNetworkLink link = new SimNetworkLink(this, port);
- this.link = link;
- port.link = link;
-
- // Start bidirectional flow channel between the two ports
- final Outlet outlet = getOutlet();
- final Inlet inlet = getInlet();
-
- outlet.getGraph().connect(outlet, port.getInlet());
- inlet.getGraph().connect(port.getOutlet(), inlet);
- }
-
- /**
- * Disconnect the current network link if it exists.
- */
- public void disconnect() {
- final SimNetworkLink link = this.link;
- if (link == null) {
- return;
- }
-
- final SimNetworkPort opposite = link.opposite(this);
- this.link = null;
- opposite.link = null;
-
- final Outlet outlet = getOutlet();
- final Inlet inlet = getInlet();
-
- outlet.getGraph().disconnect(outlet);
- inlet.getGraph().disconnect(inlet);
- }
-
- /**
- * Return the {@link Outlet} representing the outgoing traffic of this port.
- */
- protected abstract Outlet getOutlet();
-
- /**
- * An [Inlet] representing the ingoing traffic of this port.
- */
- protected abstract Inlet getInlet();
-
- @Override
- public String toString() {
- return "SimNetworkPort[isConnected=" + isConnected() + "]";
- }
-}
diff --git a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSink.java b/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSink.java
deleted file mode 100644
index f8918328..00000000
--- a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSink.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.network;
-
-import org.opendc.simulator.flow2.FlowGraph;
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.Outlet;
-import org.opendc.simulator.flow2.sink.SimpleFlowSink;
-import org.opendc.simulator.flow2.source.EmptyFlowSource;
-
-/**
- * A network sink which discards all received traffic and does not generate any traffic itself.
- */
-public final class SimNetworkSink extends SimNetworkPort {
- private final EmptyFlowSource source;
- private final SimpleFlowSink sink;
-
- /**
- * Construct a {@link SimNetworkSink} instance.
- *
- * @param graph The {@link FlowGraph} to which the sink belongs.
- * @param capacity The capacity of the sink in terms of processed data.
- */
- public SimNetworkSink(FlowGraph graph, float capacity) {
- this.source = new EmptyFlowSource(graph);
- this.sink = new SimpleFlowSink(graph, capacity);
- }
-
- /**
- * Return the capacity of the sink.
- */
- public float getCapacity() {
- return sink.getCapacity();
- }
-
- @Override
- protected Outlet getOutlet() {
- return source.getOutput();
- }
-
- @Override
- protected Inlet getInlet() {
- return sink.getInput();
- }
-
- @Override
- public String toString() {
- return "SimNetworkSink[capacity=" + getCapacity() + "]";
- }
-}
diff --git a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitch.java b/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitch.java
deleted file mode 100644
index b05dc53d..00000000
--- a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitch.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.network;
-
-import java.util.List;
-
-/**
- * A network device connects devices on a network by switching the traffic over its ports.
- */
-public interface SimNetworkSwitch {
- /**
- * Return the ports of the switch.
- */
- List<SimNetworkPort> getPorts();
-}
diff --git a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitchVirtual.java b/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitchVirtual.java
deleted file mode 100644
index a94bf799..00000000
--- a/opendc-simulator/opendc-simulator-network/src/main/java/org/opendc/simulator/network/SimNetworkSwitchVirtual.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.network;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.opendc.simulator.flow2.FlowGraph;
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.Outlet;
-import org.opendc.simulator.flow2.mux.FlowMultiplexer;
-import org.opendc.simulator.flow2.mux.MaxMinFlowMultiplexer;
-
-/**
- * A {@link SimNetworkSwitch} that can support new networking ports on demand.
- */
-public final class SimNetworkSwitchVirtual implements SimNetworkSwitch {
- private final List<Port> ports = new ArrayList<>();
-
- /**
- * The {@link MaxMinFlowMultiplexer} to actually perform the switching.
- */
- private final MaxMinFlowMultiplexer mux;
-
- /**
- * Construct a {@link SimNetworkSwitchVirtual} instance.
- *
- * @param graph The {@link FlowGraph} to drive the simulation.
- */
- public SimNetworkSwitchVirtual(FlowGraph graph) {
- this.mux = new MaxMinFlowMultiplexer(graph);
- }
-
- /**
- * Open a new port on the switch.
- */
- public Port newPort() {
- final Port port = new Port(mux);
- ports.add(port);
- return port;
- }
-
- @Override
- public List<SimNetworkPort> getPorts() {
- return Collections.unmodifiableList(ports);
- }
-
- /**
- * A port on the network switch.
- */
- public class Port extends SimNetworkPort implements AutoCloseable {
- private final FlowMultiplexer mux;
- private final Inlet inlet;
- private final Outlet outlet;
- private boolean isClosed;
-
- private Port(FlowMultiplexer mux) {
- this.mux = mux;
- this.inlet = mux.newInput();
- this.outlet = mux.newOutput();
- }
-
- @Override
- protected Outlet getOutlet() {
- if (isClosed) {
- throw new IllegalStateException("Port is closed");
- }
- return outlet;
- }
-
- @Override
- protected Inlet getInlet() {
- if (isClosed) {
- throw new IllegalStateException("Port is closed");
- }
- return inlet;
- }
-
- @Override
- public void close() {
- isClosed = true;
- mux.releaseInput(inlet);
- mux.releaseOutput(outlet);
- ports.remove(this);
- }
- }
-}