From 71cd881d0a3ab70860e6fa13a7b62546edd10bec Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 1 Sep 2017 01:53:27 +0200 Subject: Finish basic implementation of simulator This change introduces a basic coroutine-based simulator implementation. The simulator currently misses the crucial ability to send messages over channels, which will be implemented in later commits. --- .../nl/atlarge/opendc/experiment/Scheduler.kt | 6 +- .../kotlin/nl/atlarge/opendc/experiment/User.kt | 4 +- .../atlarge/opendc/experiment/messaging/Channel.kt | 55 ----- .../nl/atlarge/opendc/experiment/messaging/Port.kt | 34 ---- .../opendc/experiment/messaging/Pullable.kt | 47 ----- .../opendc/experiment/messaging/Pushable.kt | 18 -- .../opendc/experiment/messaging/Receivable.kt | 44 ---- .../experiment/simulator/AbstractSimulator.kt | 52 ----- .../atlarge/opendc/experiment/simulator/Context.kt | 67 ------- .../opendc/experiment/simulator/Simulates.kt | 35 ---- .../opendc/experiment/simulator/Simulator.kt | 67 ------- .../experiment/simulator/impl/MachineSimulator.kt | 44 ---- .../atlarge/opendc/kernel/AbstractEntityKernel.kt | 65 ++++++ .../nl/atlarge/opendc/kernel/ChannelContext.kt | 35 ++++ .../kotlin/nl/atlarge/opendc/kernel/Context.kt | 62 ++++++ .../nl/atlarge/opendc/kernel/EntityContext.kt | 45 +++++ .../main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt | 46 +++++ .../kotlin/nl/atlarge/opendc/kernel/Simulator.kt | 222 +++++++++++++++++++++ .../kotlin/nl/atlarge/opendc/kernel/clock/Clock.kt | 53 +++++ .../nl/atlarge/opendc/kernel/impl/MachineKernel.kt | 58 ++++++ .../nl/atlarge/opendc/kernel/messaging/Channel.kt | 49 +++++ .../opendc/kernel/messaging/DuplexChannel.kt | 33 +++ .../atlarge/opendc/kernel/messaging/DuplexPort.kt | 33 +++ .../nl/atlarge/opendc/kernel/messaging/Envelope.kt | 44 ++++ .../nl/atlarge/opendc/kernel/messaging/Port.kt | 33 +++ .../nl/atlarge/opendc/kernel/messaging/Readable.kt | 47 +++++ .../opendc/kernel/messaging/ReadableChannel.kt | 33 +++ .../opendc/kernel/messaging/ReadablePort.kt | 33 +++ .../nl/atlarge/opendc/kernel/messaging/Writable.kt | 42 ++++ .../opendc/kernel/messaging/WritableChannel.kt | 33 +++ .../opendc/kernel/messaging/WritablePort.kt | 33 +++ .../nl/atlarge/opendc/topology/AdjacencyList.kt | 104 ++++++++++ .../kotlin/nl/atlarge/opendc/topology/Component.kt | 40 ++++ .../main/kotlin/nl/atlarge/opendc/topology/Edge.kt | 67 ++----- .../kotlin/nl/atlarge/opendc/topology/Entity.kt | 17 +- .../kotlin/nl/atlarge/opendc/topology/Graph.kt | 47 ----- .../nl/atlarge/opendc/topology/GraphBuilder.kt | 53 ----- .../atlarge/opendc/topology/ImmutableTopology.kt | 31 +++ .../kotlin/nl/atlarge/opendc/topology/Label.kt | 42 ---- .../nl/atlarge/opendc/topology/MutableTopology.kt | 70 +++++++ .../main/kotlin/nl/atlarge/opendc/topology/Node.kt | 60 ++++++ .../kotlin/nl/atlarge/opendc/topology/Topology.kt | 35 ++++ .../nl/atlarge/opendc/topology/TopologyBuilder.kt | 39 ++++ .../opendc/topology/container/Datacenter.kt | 3 +- .../nl/atlarge/opendc/topology/container/Rack.kt | 35 ++++ .../nl/atlarge/opendc/topology/container/Room.kt | 34 ++++ .../atlarge/opendc/topology/container/rack/Rack.kt | 37 ---- .../atlarge/opendc/topology/container/rack/Slot.kt | 35 ---- .../atlarge/opendc/topology/container/room/Room.kt | 35 ---- .../nl/atlarge/opendc/topology/machine/Cpu.kt | 1 - .../nl/atlarge/opendc/topology/machine/Gpu.kt | 4 +- .../nl/atlarge/opendc/topology/machine/Machine.kt | 3 +- .../opendc/topology/machine/ProcessingUnit.kt | 2 +- .../atlarge/opendc/topology/network/NetworkUnit.kt | 2 +- .../nl/atlarge/opendc/topology/power/PowerUnit.kt | 7 +- .../atlarge/opendc/topology/storage/StorageUnit.kt | 2 +- 56 files changed, 1483 insertions(+), 794 deletions(-) delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Channel.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Port.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pullable.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pushable.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Receivable.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/AbstractSimulator.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Context.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulates.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulator.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/impl/MachineSimulator.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/AbstractEntityKernel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/ChannelContext.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/EntityContext.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/clock/Clock.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/impl/MachineKernel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Channel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexChannel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexPort.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Envelope.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Port.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Readable.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadableChannel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadablePort.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritableChannel.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritablePort.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Component.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Graph.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/GraphBuilder.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/ImmutableTopology.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Label.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Rack.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Room.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Rack.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Slot.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/room/Room.kt (limited to 'opendc-core/src/main') diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Scheduler.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Scheduler.kt index b2845963..14a623a6 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Scheduler.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Scheduler.kt @@ -24,14 +24,14 @@ package nl.atlarge.opendc.experiment -import nl.atlarge.opendc.topology.Entity +import nl.atlarge.opendc.topology.Node /** - * A task scheduler that is coupled to an [Entity] in the topology of the cloud network. + * A task scheduler that is coupled to an [Node] in the topology of the cloud network. * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface Scheduler { +interface Scheduler> { /** * Schedule the given jobs for the given entity. * diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/User.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/User.kt index 8bfba407..bb87a167 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/User.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/User.kt @@ -24,7 +24,7 @@ package nl.atlarge.opendc.experiment -import nl.atlarge.opendc.topology.Graph +import nl.atlarge.opendc.topology.Topology /** * A user of a cloud network that provides [Job]s for the simulation. @@ -37,4 +37,4 @@ import nl.atlarge.opendc.topology.Graph * @param view The view of the user on the topology. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -data class User(val id: Int, val name: String, val view: Graph) +data class User(val id: Int, val name: String, val view: Topology) diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Channel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Channel.kt deleted file mode 100644 index b33b720d..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Channel.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.messaging - -import nl.atlarge.opendc.topology.Entity -import nl.atlarge.opendc.topology.Label - -/** - * A direct bi-directional communication channel between two [Entity] instances as seen from one of the entities. - * - *

A [Channel] is viewed as an edge that connects two entities in the topology of a cloud network. - * - * @param The type of [Entity] this channel points to. - * @param The type of the label data of this channel. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Channel: Pushable, Pullable { - /** - * The [Entity] instance this channel is points to. - */ - val entity: E - - /** - * The label of the channel, possibly containing user-defined information. - */ - val label: Label - - /** - * The channel the message originates from. - */ - val Receivable.channel: Channel - get() = this@Channel -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Port.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Port.kt deleted file mode 100644 index a2cdba32..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Port.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.messaging - -import nl.atlarge.opendc.topology.Entity - -/** - * A port connects multiple [Channel]s to an entity in the topology of a cloud network. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Port: Iterable>, Pullable, Pushable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pullable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pullable.kt deleted file mode 100644 index 7a756a73..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pullable.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.messaging - -/** - * A [Pullable] instance allows objects to pull messages from the instance. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Pullable { - /** - * Pull one message from this [Channel] for processing via the given block. - * - * @param block The block to process the message with. - * @return The result of the processed messaged. - */ - fun pull(block: Receivable.(Any?) -> T): T - - /** - * Pull one message from this [Channel]. - * - * @return The message that was received from the channel - */ - fun pull(): Any? = pull { it } -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pushable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pushable.kt deleted file mode 100644 index 8ec14b6d..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Pushable.kt +++ /dev/null @@ -1,18 +0,0 @@ -package nl.atlarge.opendc.experiment.messaging - -import nl.atlarge.opendc.topology.Entity - -/** - * A [Pushable] instance allows objects to send messages to it. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Pushable { - /** - * Push one message to downstream. - * - * @param msg The message to send downstream. - * @param sender The sender of the message. - */ - fun push(msg: Any?, sender: Entity) -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Receivable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Receivable.kt deleted file mode 100644 index f40ebd30..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/messaging/Receivable.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.messaging - -import nl.atlarge.opendc.topology.Entity - -/** - * A message that is received from a [Channel], also containing the metadata of the message. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Receivable { - /** - * The value of this message. - */ - val value: T - - /** - * The sender of this message. - */ - val sender: Entity -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/AbstractSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/AbstractSimulator.kt deleted file mode 100644 index 109d765e..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/AbstractSimulator.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.simulator - -import nl.atlarge.opendc.experiment.messaging.Port -import nl.atlarge.opendc.topology.Entity - -/** - * A simulator that simulates a single entity in the topology of a cloud network. - * - * @param ctx The context in which the simulation is run. - * @param The type of entity to simulate. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -abstract class AbstractSimulator(val ctx: Context): Simulator { - /** - * The [Entity] that is simulated. - */ - val self: E = ctx.entity - - /** - * Create a [Port] of the given type. - * - * @param name The name of the label to create the port for. - * @return The port that has been created or the cached result. - */ - inline fun port(name: String): Port { - throw NotImplementedError() - } -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Context.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Context.kt deleted file mode 100644 index 29ad4dc8..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Context.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.simulator - -import nl.atlarge.opendc.topology.Entity - -/** - * A context for [Simulator] instance. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Context { - /** - * The current tick of the experiment. - */ - val tick: Long - - /** - * The [Entity] that is simulated. - */ - val entity: E - - /** - * Update the state of the entity being simulated. - * - *

Instead of directly mutating the entity, we create a new instance of the entity to prevent other objects - * referencing the old entity having their data changed. - * - * @param next The next state of the entity. - */ - fun update(next: E) - - /** - * Push the given given tick handler on the stack and change the simulator's behaviour to become the new tick - * handler. - * - * @param block The tick handler to push onto the stack. - */ - fun become(block: Context.() -> Unit) - - /** - * Revert the behaviour of the simulator to the previous handler in the stack. - */ - fun unbecome() -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulates.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulates.kt deleted file mode 100644 index c69c5eff..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulates.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.simulator - -import nl.atlarge.opendc.topology.Entity -import kotlin.reflect.KClass - -/** - * Classes annotated by this annotation indicates that the annotated class simulates the given entity. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -annotation class Simulates(val entity: KClass) diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulator.kt deleted file mode 100644 index 73747d08..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/Simulator.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.simulator - -import nl.atlarge.opendc.topology.Entity - -/** - * A simulator that simulates a single [Entity] instance in a cloud network. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Simulator { - /** - * This method is invoked once at the start of the simulation to setup the initial state of the [Simulator]. - */ - fun Context.setUp() {} - - /** - * This method is invoked at least once before a tick. This allows a [Simulator] to setup its state before a tick - * event. - * - *

The pre-tick consists of multiple sub-cycles in which all messages which have been sent - * in the previous sub-cycle can optionally be processed in the sub-cycle by the receiving [Simulator]. - */ - fun Context.preTick() {} - - /** - * This method is invoked once per tick, which allows a [Simulator] to process events to simulate an entity in a - * cloud network. - */ - fun Context.tick() {} - - /** - * This method is invoked at least once per tick. This allows the [Simulator] to do work after a tick. - * - *

Like the pre-tick, the post-tick consists of multiple sub-cycles in which all messages which have been sent - * in the previous sub-cycle can optionally be processed in the sub-cycle by the receiving [Simulator]. - */ - fun Context.postTick() {} - - /** - * This method is invoked once at the end of the simulation to tear down resources of the [Simulator]. - */ - fun Context.tearDown() {} -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/impl/MachineSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/impl/MachineSimulator.kt deleted file mode 100644 index 4b351753..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/simulator/impl/MachineSimulator.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.experiment.simulator.impl - -import nl.atlarge.opendc.experiment.simulator.AbstractSimulator -import nl.atlarge.opendc.experiment.simulator.Context -import nl.atlarge.opendc.experiment.simulator.Simulates -import nl.atlarge.opendc.topology.machine.Cpu -import nl.atlarge.opendc.topology.machine.Machine - -/** - * A simulator for [Machine] entities. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -@Simulates(Machine::class) -class MachineSimulator(ctx: Context): AbstractSimulator(ctx) { - val cpus = port("cpu") - - override fun Context.tick() { - } -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/AbstractEntityKernel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/AbstractEntityKernel.kt new file mode 100644 index 00000000..35b89e4e --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/AbstractEntityKernel.kt @@ -0,0 +1,65 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel + +import nl.atlarge.opendc.kernel.messaging.ReadablePort +import nl.atlarge.opendc.kernel.messaging.WritableChannel +import nl.atlarge.opendc.topology.Edge +import nl.atlarge.opendc.topology.Entity +import nl.atlarge.opendc.topology.Node + +/** + * A simulation kernel that simulates a single entity in the topology of a cloud network. + * + * @param ctx The context in which the simulation is run. + * @param E The shape of the component to simulate. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +abstract class AbstractEntityKernel>(private val ctx: EntityContext): Kernel> { + /** + * The [Node] that is simulated. + */ + val self: Node = ctx.component + + /** + * Create a [WritableChannel] over the edge with the given tag. + * + * @param tag The tag of the edge to create a channel over. + * @return The channel that has been created or the cached result. + */ + inline fun > output(tag: String): WritableChannel { + TODO() + } + + /** + * Create a [ReadablePort] over the edges with the given tag. + * + * @param tag The tag of the edges to create a port over. + * @return The port that has been created or the cached result. + */ + inline fun > input(tag: String): ReadablePort { + TODO() + } +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/ChannelContext.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/ChannelContext.kt new file mode 100644 index 00000000..aaf5abba --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/ChannelContext.kt @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel + +import nl.atlarge.opendc.kernel.messaging.Writable +import nl.atlarge.opendc.topology.Edge + +/** + * The context provided to a simulation kernel for communication channels between entities. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface ChannelContext: Context>, Writable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt new file mode 100644 index 00000000..81431e02 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt @@ -0,0 +1,62 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel + +import nl.atlarge.opendc.kernel.messaging.Readable +import nl.atlarge.opendc.topology.Component +import nl.atlarge.opendc.topology.Entity + +/** + * The [Context] interface provides a context for a simulation kernel, which defines the environment in which the + * simulation is run. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Context>: Readable { + /** + * The [Component] that is simulated. + */ + val component: T + + /** + * The observable state of an [Entity] within the simulation is provided by context. + */ + val Entity.state: S + + /** + * Suspend the simulation kernel until the next tick occurs in the simulation. + */ + suspend fun tick(): Boolean { + sleep(1) + return true + } + + /** + * Suspend the simulation kernel for n ticks before resuming the execution. + * + * @param n The amount of ticks to suspend the simulation kernel. + */ + suspend fun sleep(n: Int) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/EntityContext.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/EntityContext.kt new file mode 100644 index 00000000..ea9c6b04 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/EntityContext.kt @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel + +import nl.atlarge.opendc.topology.Entity +import nl.atlarge.opendc.topology.Node + +/** + * The context provided to a simulation kernel for stateful entities in the topology. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface EntityContext>: Context> { + /** + * Update the state of the entity being simulated. + * + *

Instead of directly mutating the entity, we create a new instance of the entity to prevent other objects + * referencing the old entity having their data changed. + * + * @param next The next state of the entity. + */ + suspend fun , E: Entity, S> C.update(next: S) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt new file mode 100644 index 00000000..5f399c57 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt @@ -0,0 +1,46 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel + +import nl.atlarge.opendc.topology.Component + +/** + * A simulation kernel that simulates a single [Component] instance in a cloud network. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Kernel> { + /** + * This method is invoked to start the simulation of the [Component] associated with this [Kernel]. + * + *

This method is assumed to be running during the experiment, but should hand back control to the simulator at + * some point by calling [Context.tick] to wait for the next tick to occur, which allows to allows other entity + * simulators to do work in the current tick of the simulation. + * + *

If this method exists early, before the simulation has finished, the entity is assumed to be shutdown and its + * simulation will not run any further. + */ + suspend fun C.run() +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt new file mode 100644 index 00000000..ee8d5072 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulator.kt @@ -0,0 +1,222 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel + +import nl.atlarge.opendc.kernel.clock.Clock +import nl.atlarge.opendc.kernel.clock.Tick +import nl.atlarge.opendc.kernel.messaging.Envelope +import nl.atlarge.opendc.topology.* +import java.util.* +import kotlin.coroutines.experimental.* + +/** + * A [Simulator] runs the simulation over the specified topology. + * + * @param topology The topology to run the simulation over. + * @param mapping The mapping of components in the topology to the simulation kernels the components should use. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class Simulator(val topology: Topology, private val mapping: Map, Class>>): Iterator { + /** + * The registry of the simulation kernels used in the experiment. + */ + private val registry: MutableMap, Pair>, Context<*>>?> = HashMap() + + /** + * A mapping of the entities in the topology to their current state. + */ + private val states: MutableMap, Any?> = HashMap() + + /** + * The clock of the simulator. + */ + private val clock: DefaultClock = DefaultClock() + + /** + * Initialize the simulator. + */ + init { + topology.forEach { node -> + resolve(node) + node.outgoingEdges().forEach { resolve(it) } + } + + registry.values.forEach { + it?.also { (kernel, ctx) -> + // Start all kernel co-routines + kernel.run { + val block: suspend () -> Unit = { ctx.run() } + block.startCoroutine(SimulationCoroutine()) + } + } + } + } + + /** + * Resolve the given [Component] to the [Kernel] of that component. + * + * @param component The component to resolve. + * @return The [Kernel] that simulates that [Component]. + */ + fun > resolve(component: T): Pair>, Context>? { + @Suppress("UNCHECKED_CAST") + return registry.computeIfAbsent(component, { + val constructor = mapping[it]?.constructors?.get(0) + val ctx = if (component is Node<*>) { + DefaultEntityContext(component as Node<*>) + } else { + DefaultChannelContext(component as Edge<*>) + } + + if (constructor == null) { + println("warning: invalid constructor for kernel ${mapping[it]}") + null + } else { + Pair(constructor.newInstance(ctx) as Kernel>, ctx) + } + }) as? Pair>, Context>? + } + + /** + * Determine whether the simulator has a next non-empty cycle available. + * + * @return true if the simulator has a next non-empty cycle, false otherwise. + */ + override fun hasNext(): Boolean = clock.queue.isNotEmpty() + + /** + * Run the next cycle in the simulation. + */ + override fun next() { + clock.tick++ + while (true) { + val (tick, block) = clock.queue.peek() ?: return + + if (tick > clock.tick) + // Tick has yet to occur + break + else if (tick < clock.tick) + // Tick has already occurred + println("error: tick was not handled correctly") + + clock.queue.poll() + block() + } + } + + class SimulationCoroutine: Continuation { + override val context: CoroutineContext = EmptyCoroutineContext + override fun resume(value: Unit) {} + + override fun resumeWithException(exception: Throwable) { + val currentThread = Thread.currentThread() + currentThread.uncaughtExceptionHandler.uncaughtException(currentThread, exception) + } + } + + /** + * The [Context] for an entity within the simulation. + */ + private inner class DefaultEntityContext>(override val component: Node): EntityContext { + /** + * Retrieves and removes a single message from this channel suspending the caller while the channel is empty. + * + * @param block The block to process the message with. + * @return The processed message. + */ + suspend override fun receive(block: Envelope<*>.(Any?) -> T): T = suspendCoroutine {} + + + /** + * The observable state of an [Entity] within the simulation is provided by context. + */ + @Suppress("UNCHECKED_CAST") + override val Entity.state: S + get() = states[this] as S + + /** + * Update the state of the entity being simulated. + * + *

Instead of directly mutating the entity, we create a new instance of the entity to prevent other objects + * referencing the old entity having their data changed. + * + * @param next The next state of the entity. + */ + suspend override fun , E: Entity, S> C.update(next: S) { + states.put(component.entity as Entity<*>, next) + } + + /** + * Suspend the simulation kernel for n ticks before resuming the execution. + * + * @param n The amount of ticks to suspend the simulation kernel. + */ + suspend override fun sleep(n: Int): Unit = suspendCoroutine { cont -> clock.scheduleAfter(n, { cont.resume(Unit) }) } + } + + /** + * The [Context] for an edge within the simulation. + */ + private inner class DefaultChannelContext(override val component: Edge): ChannelContext { + /** + * Retrieves and removes a single message from this channel suspending the caller while the channel is empty. + * + * @param block The block to process the message with. + * @return The processed message. + */ + suspend override fun receive(block: Envelope<*>.(Any?) -> T): T = suspendCoroutine {} + + /** + * Send the given message downstream. + * + * @param msg The message to send. + * @param sender The sender of the message. + */ + suspend override fun send(msg: Any?, sender: Node<*>): Unit = suspendCoroutine {} + + /** + * The observable state of an [Entity] within the simulation is provided by context. + */ + @Suppress("UNCHECKED_CAST") + override val Entity.state: S + get() = states[this] as S + + /** + * Suspend the simulation kernel for n ticks before resuming the execution. + * + * @param n The amount of ticks to suspend the simulation kernel. + */ + suspend override fun sleep(n: Int): Unit = suspendCoroutine { cont -> clock.scheduleAfter(n, { cont.resume(Unit) }) } + } + + private inner class DefaultClock: Clock { + override var tick: Tick = 0 + internal val queue: PriorityQueue Unit>> = PriorityQueue(Comparator.comparingLong { it.first }) + + override fun scheduleAt(tick: Tick, block: () -> Unit) { + queue.add(Pair(tick, block)) + } + } +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/clock/Clock.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/clock/Clock.kt new file mode 100644 index 00000000..db13eee1 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/clock/Clock.kt @@ -0,0 +1,53 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.clock + +/** + * A tick represents a moment of time in which some work is done by an entity. + */ +typealias Tick = Long + +/** + * The clock of a simulation manages the ticks that have elapsed and schedules the tick events. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Clock { + /** + * The tick the clock is currently at. + */ + val tick: Tick + + /** + * + * @throws IllegalArgumentException + */ + fun scheduleAt(tick: Tick, block: () -> Unit) + + /** + * @throws IllegalArgumentException + */ + fun scheduleAfter(n: Int, block: () -> Unit) = scheduleAt(tick + n, block) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/impl/MachineKernel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/impl/MachineKernel.kt new file mode 100644 index 00000000..e34c7060 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/impl/MachineKernel.kt @@ -0,0 +1,58 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.impl + +import nl.atlarge.opendc.experiment.Task +import nl.atlarge.opendc.kernel.AbstractEntityKernel +import nl.atlarge.opendc.kernel.EntityContext +import nl.atlarge.opendc.topology.machine.Cpu +import nl.atlarge.opendc.topology.machine.Machine + +class MachineKernel(ctx: EntityContext): AbstractEntityKernel(ctx) { + + suspend override fun EntityContext.run() { + println("${this}: Initialising!") + + val cpus = component.outgoingEdges().filter { it.tag == "cpu" }.map { it.to.entity as Cpu } + val speed = cpus.fold(0, { acc, (speed, cores) -> acc + speed * cores }) + val task: Task + + loop@while (true) { + val msg = receive() + when (msg) { + is Task -> { + task = msg + break@loop + } + else -> println("warning: unhandled message $msg") + } + } + + while (tick()) { + task.consume(speed.toLong()) + } + } + +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Channel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Channel.kt new file mode 100644 index 00000000..ad966719 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Channel.kt @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +import nl.atlarge.opendc.topology.Edge +import nl.atlarge.opendc.topology.Node + +/** + * A unidirectional communication channel between two [Node] instances as seen from one of the entities. + * + *

A [Channel] is viewed as a directed edge that connects two entities in the topology of a cloud network. + * + * @param T The shape of the label of the edge of this channel. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Channel { + /** + * The directed edge between two nodes which represents this unidirectional communication channel. + */ + val edge: Edge + + /** + * The channel the message originates from. + */ + val Envelope<*>.channel: Channel + get() = this@Channel +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexChannel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexChannel.kt new file mode 100644 index 00000000..a4ef7409 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexChannel.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [DuplexChannel] instance allows bi-directional communication over the channel. + * + * @param T The shape of the label of the edge of this channel. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface DuplexChannel: Channel, Readable, Writable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexPort.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexPort.kt new file mode 100644 index 00000000..5917ac71 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/DuplexPort.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [DuplexPort] instance allows bi-directional communication with multiple channels. + * + * @param T The shape of the label of the edges of the channels of this port. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface DuplexPort: Port>, Readable, Writable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Envelope.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Envelope.kt new file mode 100644 index 00000000..d4d363d5 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Envelope.kt @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +import nl.atlarge.opendc.topology.Node + +/** + * The envelope of a message that is received from a [Channel], also containing the metadata of the message. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +data class Envelope( + /** + * The message in this envelope. + */ + val message: T, + + /** + * The sender of the message. + */ + val sender: Node<*> +) diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Port.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Port.kt new file mode 100644 index 00000000..18ec1918 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Port.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A port connects multiple [Channel]s to an entity in the topology of a cloud network. + * + * @param C The shape of the channels that are connected to this port. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Port>: Iterable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Readable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Readable.kt new file mode 100644 index 00000000..422c5668 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Readable.kt @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [Readable] instance allows objects to pull messages from the instance. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Readable { + /** + * Retrieves and removes a single message from this channel suspending the caller while the channel is empty. + * + * @param block The block to process the message with. + * @return The processed message. + */ + suspend fun receive(block: Envelope<*>.(Any?) -> T): T + + /** + * Retrieve a single message from this [Channel]. + * + * @return The message that was received from the channel + */ + suspend fun receive(): Any? = receive { it } +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadableChannel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadableChannel.kt new file mode 100644 index 00000000..c291b1ea --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadableChannel.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [ReadableChannel] instance allows objects to receive messages from the channel. + * + * @param T The shape of the label of the edge of this channel. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface ReadableChannel: Channel, Readable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadablePort.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadablePort.kt new file mode 100644 index 00000000..bfad9490 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/ReadablePort.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [ReadablePort] instance allows objects to receive messages from the channel. + * + * @param T The shape of the label of the edges of the channels of this port. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface ReadablePort: Port>, Readable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt new file mode 100644 index 00000000..6bd1ce30 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +import nl.atlarge.opendc.topology.Node + +/** + * A [Writable] instance allows objects to send messages to it. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Writable { + /** + * Send the given message downstream. + * + * @param msg The message to send. + * @param sender The sender of the message. + */ + suspend fun send(msg: Any?, sender: Node<*>) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritableChannel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritableChannel.kt new file mode 100644 index 00000000..60f89a97 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritableChannel.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [WritableChannel] instance allows objects to write messages to the channel. + * + * @param T The shape of the label of the edge of this channel. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface WritableChannel: Channel, Writable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritablePort.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritablePort.kt new file mode 100644 index 00000000..0dc92680 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/WritablePort.kt @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.messaging + +/** + * A [WritablePort] instance allows objects to write messages to multiple channels. + * + * @param T The shape of the label of the edges of the channels of this port. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface WritablePort: Port>, Writable diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt new file mode 100644 index 00000000..bdf60056 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt @@ -0,0 +1,104 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +import java.util.concurrent.atomic.AtomicInteger + +/** + * A builder for [Topology] instances, which is backed by an adjacency list. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class AdjacencyListTopologyBuilder: TopologyBuilder { + /** + * Build a [Topology] instance from the current state of this builder. + * + * @return The graph built from this builder. + */ + override fun build(): MutableTopology = AdjacencyListTopology() +} + +/** + * A [Topology] whose graph is represented as adjacency list. + */ +internal class AdjacencyListTopology: MutableTopology { + private val nextId: AtomicInteger = AtomicInteger(0) + private val nodes: MutableList> = ArrayList() + + /** + * Create a [Node] in this [Topology] for the given [Entity]. + * + * @param entity The entity to create a node for. + * @return The node created for the given entity. + */ + override fun > node(entity: T): Node { + val node = AdjacencyListNode(nextId.incrementAndGet(), entity) + nodes.add(node) + return node + } + + /** + * Create a directed edge between two [Node]s in the topology. + * + * @param from The source of the edge. + * @param to The destination of the edge. + * @param label The label of the edge. + * @param tag The tag of the edge that uniquely identifies the relationship the edge represents. + * @return The edge that has been created. + */ + override fun connect(from: Node<*>, to: Node<*>, label: T, tag: String?): Edge { + if (from !is AdjacencyListNode<*> || to !is AdjacencyListNode<*>) + throw IllegalArgumentException() + if (!from.validate(this) || !to.validate(this)) + throw IllegalArgumentException() + val edge: Edge = AdjacencyListEdge(label, tag, from, to) + from.outgoingEdges.add(edge) + to.ingoingEdges.add(edge) + return edge + } + + /** + * Returns an iterator over the elements of this object. + */ + override fun iterator(): Iterator> = nodes.iterator() + + internal inner class AdjacencyListNode>(override val id: Int, override val label: T): Node { + internal var ingoingEdges: MutableSet> = HashSet() + internal var outgoingEdges: MutableSet> = HashSet() + + override fun ingoingEdges(): Set> = ingoingEdges + override fun outgoingEdges(): Set> = outgoingEdges + override fun toString(): String = label.toString() + + internal fun validate(instance: AdjacencyListTopology) = this@AdjacencyListTopology == instance + } + + internal class AdjacencyListEdge(override val label: T, + override val tag: String?, + override val from: Node<*>, + override val to: Node<*>): Edge { + override fun toString(): String = label.toString() + } +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Component.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Component.kt new file mode 100644 index 00000000..79b35e86 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Component.kt @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * A component within a [Topology], which is either an [Node] or an [Edge] representing the relationship between + * entities within a logical topology of a cloud network. + * + *

A [Component]'s label provides access to user-specified data. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Component { + /** + * The label of this [Component]. + */ + val label: T +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Edge.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Edge.kt index 4344e1b5..22ad57c1 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Edge.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Edge.kt @@ -24,72 +24,31 @@ package nl.atlarge.opendc.topology -import java.util.* - /** - * An undirected edge that represents a connection between exactly two instances of [Entity]. + * An edge that represents a directed relationship between exactly two [Node]s in a logical topology of a cloud network. * - * @param from The first incident node. - * @param to The second incident node. - * @param label The label of the edge. - * @param The data type of the label value. + * @param T The relationship type the edge represents within a logical topology. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -class Edge(val from: Entity, val to: Entity, val label: Label) { - /** - * Return the [Entity] at the opposite end of this [Edge] from the - * specified entity. - * - * Throws [IllegalArgumentException] if entity is - * not incident to this edge. - * - * @param entity The entity to get the opposite of for this edge pair. - * @return The entity at the opposite end of this edge from the specified entity. - * @throws IllegalArgumentException if entity is not incident to this edge. - */ - fun opposite(entity: Entity): Entity = when (entity) { - from -> to - to -> from - else -> throw IllegalArgumentException() - } - +interface Edge: Component { /** - * Return a [Pair] representing this edge consisting of both incident nodes. - * Note that the pair is in no particular order. - * - * @return The edge represented as pair of both incident nodes. - */ - fun endpoints(): Pair = Pair(from, to) - - /** - * Determine whether the given object is equal to this instance. - * - * @param other The other object to compare against. - * @return true both edges are equal, false otherwise. + * A tag to uniquely identify the relationship this edge represents. */ - override fun equals(other: Any?): Boolean = - if (other is Edge<*>) { - from == other.from && to == other.to || - from == other.to && to == other.from - } else { - false - } + val tag: String? /** - * Return the hash code of this edge pair. + * The source of the edge. * - * @return The hash code of this edge pair. + * This property is not guaranteed to have a runtime complexity of O(1), but must be at least + * O(n), with respect to the size of the topology. */ - override fun hashCode(): Int { - return Objects.hash(from, to) - } + val from: Node<*> /** - * Return a string representation of this [Edge]. + * The destination of the edge. * - * @return A string representation of this [Edge]. + * This property is not guaranteed to have a runtime complexity of O(1), but must be at least + * O(n), with respect to the size of the topology. */ - override fun toString(): String { - return "Edge($from<->$to)" - } + val to: Node<*> } diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Entity.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Entity.kt index c78cba3c..44264a35 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Entity.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Entity.kt @@ -25,16 +25,15 @@ package nl.atlarge.opendc.topology /** - * An entity in the logical topology of a cloud network. + * An entity within a cloud network. * - *

Instances of the [Entity] interface provide direct access to observable state of the entity to other entities in - * the topology connected to it. + *

A [Entity] contains the immutable properties of this component given by the topology configuration at the start + * of a simulation and remain unchanged during simulation. * + *

In addition, other entities in a simulation have direct, immutable access to the observable state of this entity. + * + * @param S The shape of the observable state of this entity, which is directly accessible by other components within + * a simulation. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface Entity { - /** - * A unique identifier of this entity within the topology represented as a [Int]. - */ - val id: Int -} +interface Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Graph.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Graph.kt deleted file mode 100644 index fe1714fc..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Graph.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology - -/** - * A graph data structure which represents the logical topology of a cloud network consisting of one or more - * datacenters. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Graph { - /** - * Return the set of incoming edges of this node. - * - * @return All edges whose destination is this node. - */ - fun Entity.incomingEdges(): Set> - - /** - * Return the set of outgoing edges of this node. - * - * @return All edges whose source is this node. - */ - fun Entity.outgoingEdges(): Set> -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/GraphBuilder.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/GraphBuilder.kt deleted file mode 100644 index a280e88a..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/GraphBuilder.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology - -/** - * A builder for [Graph] instances. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface GraphBuilder { - /** - * Add the given [Entity] to this graph. - * - * @param entity The entity to add. - */ - fun add(entity: Entity) - - /** - * Add the given [Edge] to this graph. - * - * @param edge The edge to add. - */ - fun add(edge: Edge<*>) - - /** - * Build a [Graph] instance from the current state of this builder. - * - * @return The graph built from this builder. - */ - fun build(): Graph -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/ImmutableTopology.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/ImmutableTopology.kt new file mode 100644 index 00000000..90ba5dc5 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/ImmutableTopology.kt @@ -0,0 +1,31 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology +/** + * A [Topology] whose elements and structural relationships will never change. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface ImmutableTopology: Topology diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Label.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Label.kt deleted file mode 100644 index 69174263..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Label.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology - -/** - * A label for an edge in the topology. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Label { - /** - * The name of the label. - */ - val name: String - - /** - * The user-specified data of the label. - */ - val data: T -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt new file mode 100644 index 00000000..0aa0d1b5 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt @@ -0,0 +1,70 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * A subinterface of [Topology] which adds mutation methods. When mutation is not required, users + * should prefer the [Topology] interface. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface MutableTopology: Topology { + /** + * Create a [Node] in this [Topology] for the given [Entity]. + * + * @param entity The entity to create a node for. + * @return The node created for the given entity. + */ + fun > node(entity: T): Node + + /** + * Create a directed edge between two [Node]s in the topology. + * + * @param from The source of the edge. + * @param to The destination of the edge. + * @param label The label of the edge. + * @param tag The tag of the edge that uniquely identifies the relationship the edge represents. + * @return The edge that has been created. + */ + fun connect(from: Node<*>, to: Node<*>, label: T, tag: String? = null): Edge + + /** + * Create a directed edge between two [Node]s in the topology. + * + * @param from The source of the edge. + * @param to The destination of the edge. + * @param tag The tag of the edge that uniquely identifies the relationship the edge represents. + * @return The edge that has been created. + */ + fun connect(from: Node<*>, to: Node<*>, tag: String? = null): Edge = connect(from, to, Unit, tag) + + /** + * Create a directed edge between two [Node]s in the topology. + * + * @param dest The destination of the edge. + * @return The edge that has been created. + */ + infix fun Node<*>.to(dest: Node<*>): Edge = connect(this, dest) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt new file mode 100644 index 00000000..5b7076ed --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * A labeled node of graph representing an entity in a specific logical topology of a cloud network. + * + *

A [Node] is instantiated and managed by a [Topology] instance containing user-specified data in its label. + * + * @param T The entity type the node represents in a logical topology. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Node>: Component { + /** + * A unique identifier of this node within the topology. + */ + val id: Int + + /** + * Return the set of incoming edges of this node. + * + * @return All edges whose destination is this node. + */ + fun ingoingEdges(): Set> + + /** + * Return the set of outgoing edges of this node. + * + * @return All edges whose source is this node. + */ + fun outgoingEdges(): Set> + + /** + * The [Entity] this node represents within a logical topology of a cloud network. + */ + val entity: T + get() = label +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt new file mode 100644 index 00000000..d8f966d1 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * A graph data structure which represents the logical topology of a cloud network consisting of one or more + * datacenters. + * + *

A topology is [Iterable] and allows implementation-dependent iteration of the nodes in the topology. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Topology: Iterable> diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt new file mode 100644 index 00000000..5752eb89 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt @@ -0,0 +1,39 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * A builder for [Topology] instances. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface TopologyBuilder { + /** + * Build a [Topology] instance from the current state of this builder. + * + * @return The graph built from this builder. + */ + fun build(): MutableTopology +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Datacenter.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Datacenter.kt index 5a57c70a..2b464f15 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Datacenter.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Datacenter.kt @@ -29,7 +29,6 @@ import nl.atlarge.opendc.topology.Entity /** * A representation of a facility used to house computer systems and associated components. * - * @param id The unique identifier of this entity. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -class Datacenter(override val id: Int): Entity +class Datacenter: Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Rack.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Rack.kt new file mode 100644 index 00000000..043ad31a --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Rack.kt @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology.container + +import nl.atlarge.opendc.topology.Entity + +/** + * A type of physical steel and electronic framework that is designed to house servers, networking devices, cables and + * other datacenter computing equipment. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +class Rack: Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Room.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Room.kt new file mode 100644 index 00000000..844d96a0 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Room.kt @@ -0,0 +1,34 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology.container + +import nl.atlarge.opendc.topology.Entity + +/** + * A physical room in a datacenter with relationships to the entities within the room. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Room: Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Rack.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Rack.kt deleted file mode 100644 index c40b1660..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Rack.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology.container.rack - -import nl.atlarge.opendc.topology.Entity - -/** - * A type of physical steel and electronic framework that is designed to house servers, networking devices, cables and - * other datacenter computing equipment. - * - * @param id The unique identifier of this entity. - * @param The type of nodes that are placed in the rack. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -data class Rack(override val id: Int): Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Slot.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Slot.kt deleted file mode 100644 index 203f7f3b..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/rack/Slot.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology.container.rack - -import nl.atlarge.opendc.topology.Edge -import nl.atlarge.opendc.topology.Entity - -/** - * This class represents a slot in a [Rack] of [Machine]s. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class Slot(val rack: Rack, val contents: T, val index: Int): Edge.Directed(rack, contents) diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/room/Room.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/room/Room.kt deleted file mode 100644 index 638d59e3..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/room/Room.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.topology.container.room - -import nl.atlarge.opendc.topology.Entity - -/** - * A physical room in a datacenter which contains [Entity]s. - * - * @param id The unique identifier of this entity. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -abstract class Room(override val id: Int): Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt index 5c1b8b57..e06ad00c 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt @@ -30,7 +30,6 @@ package nl.atlarge.opendc.topology.machine * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ data class Cpu( - override val id: Int, override val speed: Int, override val cores: Int, override val energyConsumption: Int diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt index 91a7be6a..f15847e4 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt @@ -29,9 +29,9 @@ package nl.atlarge.opendc.topology.machine * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -data class Gpu( - override val id: Int, +class Gpu( override val speed: Int, override val cores: Int, override val energyConsumption: Int ): ProcessingUnit + diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt index 39b5267e..396339a2 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt @@ -30,7 +30,6 @@ import nl.atlarge.opendc.topology.Entity * A Physical Machine (PM) inside a rack of a datacenter. It has a speed, and can be given a workload on which it will * work until finished or interrupted. * - * @param id The unique identifier of this entity. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -data class Machine(override val id: Int): Entity +class Machine: Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt index 095a0bb5..a235133f 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt @@ -31,7 +31,7 @@ import nl.atlarge.opendc.topology.Entity * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface ProcessingUnit: Entity { +interface ProcessingUnit: Entity { /** * The speed of this [ProcessingUnit] per core. */ diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/network/NetworkUnit.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/network/NetworkUnit.kt index fcb5f20a..9c294125 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/network/NetworkUnit.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/network/NetworkUnit.kt @@ -31,4 +31,4 @@ import nl.atlarge.opendc.topology.Entity * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface NetworkUnit: Entity +interface NetworkUnit: Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/power/PowerUnit.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/power/PowerUnit.kt index cc047136..e016a12b 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/power/PowerUnit.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/power/PowerUnit.kt @@ -27,10 +27,9 @@ package nl.atlarge.opendc.topology.power import nl.atlarge.opendc.topology.Entity /** - * A [Entity] which provides power for other entities a cloud network to run. + * An [Entity] which provides power for other entities a cloud network to run. * - * @param id The unique identifier of the [Entity]. - * @param output The output of the power unit in Watts. + * @param output The power output of the power unit in Watt. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -data class PowerUnit(override val id: Int, val output: Double): Entity +class PowerUnit(val output: Double): Entity diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/storage/StorageUnit.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/storage/StorageUnit.kt index 6fac585f..8e53e365 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/storage/StorageUnit.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/storage/StorageUnit.kt @@ -31,4 +31,4 @@ import nl.atlarge.opendc.topology.Entity * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface StorageUnit: Entity +interface StorageUnit: Entity -- cgit v1.2.3