From 5a365dbc068f2a8cdfa9813c39cc84bb30e15637 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Fri, 25 Oct 2024 13:32:41 +0200 Subject: 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 --- .../opendc/simulator/network/SimNetworkLinkTest.kt | 91 ------------ .../opendc/simulator/network/SimNetworkSinkTest.kt | 153 --------------------- .../network/SimNetworkSwitchVirtualTest.kt | 77 ----------- .../org/opendc/simulator/network/TestSource.kt | 56 -------- 4 files changed, 377 deletions(-) delete mode 100644 opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkLinkTest.kt delete mode 100644 opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt delete mode 100644 opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt delete mode 100644 opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt (limited to 'opendc-simulator/opendc-simulator-network/src/test') diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkLinkTest.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkLinkTest.kt deleted file mode 100644 index 9863507d..00000000 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkLinkTest.kt +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 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 io.mockk.mockk -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows - -/** - * Test suite for [SimNetworkLink] class. - */ -class SimNetworkLinkTest { - @Test - fun testContainsLeft() { - val left = mockk() - val right = mockk() - - val link = SimNetworkLink(left, right) - assertTrue(left in link) - } - - @Test - fun testContainsRight() { - val left = mockk() - val right = mockk() - - val link = SimNetworkLink(left, right) - assertTrue(right in link) - } - - @Test - fun testContainsNone() { - val left = mockk() - val right = mockk() - val none = mockk() - - val link = SimNetworkLink(left, right) - assertFalse(none in link) - } - - @Test - fun testOppositeLeft() { - val left = mockk() - val right = mockk() - - val link = SimNetworkLink(left, right) - assertEquals(right, link.opposite(left)) - } - - @Test - fun testOppositeRight() { - val left = mockk() - val right = mockk() - - val link = SimNetworkLink(left, right) - assertEquals(left, link.opposite(right)) - } - - @Test - fun testOppositeNone() { - val left = mockk() - val right = mockk() - val none = mockk() - - val link = SimNetworkLink(left, right) - assertThrows { link.opposite(none) } - } -} diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt deleted file mode 100644 index 4655bfea..00000000 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSinkTest.kt +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2021 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 io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import kotlinx.coroutines.yield -import org.junit.jupiter.api.Assertions.assertAll -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertDoesNotThrow -import org.junit.jupiter.api.assertThrows -import org.opendc.simulator.flow2.FlowEngine -import org.opendc.simulator.kotlin.runSimulation - -/** - * Test suite for the [SimNetworkSink] class. - */ -class SimNetworkSinkTest { - @Test - fun testInitialState() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - - assertAll( - { assertFalse(sink.isConnected) }, - { assertNull(sink.link) }, - { assertEquals(100.0f, sink.capacity) }, - ) - } - - @Test - fun testDisconnectIdempotent() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - - assertDoesNotThrow { sink.disconnect() } - assertFalse(sink.isConnected) - } - - @Test - fun testConnectCircular() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - - assertThrows { - sink.connect(sink) - } - } - - @Test - fun testConnectAlreadyConnectedTarget() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - val source = mockk(relaxUnitFun = true) - every { source.isConnected } returns true - - assertThrows { - sink.connect(source) - } - } - - @Test - fun testConnectAlreadyConnected() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - val source1 = TestSource(graph) - - val source2 = mockk(relaxUnitFun = true) - - every { source2.isConnected } returns false - - sink.connect(source1) - assertThrows { - sink.connect(source2) - } - } - - @Test - fun testConnect() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - val source = TestSource(graph) - - sink.connect(source) - - yield() - - assertAll( - { assertTrue(sink.isConnected) }, - { assertTrue(source.isConnected) }, - { assertEquals(100.0f, source.outlet.capacity) }, - ) - - verify { source.logic.onUpdate(any(), any()) } - } - - @Test - fun testDisconnect() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - val source = TestSource(graph) - - sink.connect(source) - sink.disconnect() - - yield() - - assertAll( - { assertFalse(sink.isConnected) }, - { assertFalse(source.isConnected) }, - { assertEquals(0.0f, source.outlet.capacity) }, - ) - } -} diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt deleted file mode 100644 index b5a00ffc..00000000 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/SimNetworkSwitchVirtualTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021 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 io.mockk.verify -import kotlinx.coroutines.yield -import org.junit.jupiter.api.Assertions.assertAll -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.opendc.simulator.flow2.FlowEngine -import org.opendc.simulator.kotlin.runSimulation - -/** - * Test suite for the [SimNetworkSwitchVirtual] class. - */ -class SimNetworkSwitchVirtualTest { - @Test - fun testConnect() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - val source = TestSource(graph) - val switch = SimNetworkSwitchVirtual(graph) - - switch.newPort().connect(sink) - switch.newPort().connect(source) - - yield() - - assertAll( - { assertTrue(sink.isConnected) }, - { assertTrue(source.isConnected) }, - { assertEquals(100.0f, source.outlet.capacity) }, - ) - - verify { source.logic.onUpdate(any(), any()) } - } - - @Test - fun testConnectClosedPort() = - runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimNetworkSink(graph, 100.0f) - val switch = SimNetworkSwitchVirtual(graph) - - val port = switch.newPort() - port.close() - - assertThrows { - port.connect(sink) - } - } -} diff --git a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt b/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt deleted file mode 100644 index 298a5d48..00000000 --- a/opendc-simulator/opendc-simulator-network/src/test/kotlin/org/opendc/simulator/network/TestSource.kt +++ /dev/null @@ -1,56 +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 io.mockk.spyk -import org.opendc.simulator.flow2.FlowGraph -import org.opendc.simulator.flow2.FlowStage -import org.opendc.simulator.flow2.FlowStageLogic -import org.opendc.simulator.flow2.InPort -import org.opendc.simulator.flow2.Inlet -import org.opendc.simulator.flow2.OutPort -import org.opendc.simulator.flow2.Outlet - -/** - * A [SimNetworkPort] that acts as a test source. - */ -class TestSource(graph: FlowGraph) : SimNetworkPort(), FlowStageLogic { - val logic = spyk(this) - private val stage = graph.newStage(logic) - - val outlet: OutPort = stage.getOutlet("out") - val inlet: InPort = stage.getInlet("in") - - init { - outlet.push(80.0f) - } - - override fun onUpdate( - ctx: FlowStage, - now: Long, - ): Long = Long.MAX_VALUE - - override fun getOutlet(): Outlet = outlet - - override fun getInlet(): Inlet = inlet -} -- cgit v1.2.3