From 62895f71b7a7479652d9b86f7036b6580b40b7c7 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 18 Sep 2017 00:12:24 +0200 Subject: Refactor and split up code base This change splits up the current code base into three different module: - opendc-core - This module defines the API which you can use to write simulatable entities in a topology. - opendc-omega - This module is the reference implementation of the API defined the `opendc-core` module. - opendc-stdlib - This module provides a standard library of entities which can be used for datacenter simulation. --- opendc-core/build.gradle | 19 +- .../nl/atlarge/opendc/experiment/Experiment.kt | 34 --- .../atlarge/opendc/experiment/ExperimentRunner.kt | 39 ---- .../kotlin/nl/atlarge/opendc/experiment/Job.kt | 36 ---- .../nl/atlarge/opendc/experiment/Scheduler.kt | 42 ---- .../kotlin/nl/atlarge/opendc/experiment/Task.kt | 64 ------ .../kotlin/nl/atlarge/opendc/experiment/User.kt | 40 ---- .../main/kotlin/nl/atlarge/opendc/kernel/Clock.kt | 42 ++++ .../kotlin/nl/atlarge/opendc/kernel/Context.kt | 86 ++++++++ .../kotlin/nl/atlarge/opendc/kernel/Interrupt.kt | 32 +++ .../main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt | 68 ++++++ .../kotlin/nl/atlarge/opendc/kernel/Process.kt | 51 +++++ .../nl/atlarge/opendc/kernel/messaging/Envelope.kt | 56 +++++ .../nl/atlarge/opendc/kernel/messaging/Readable.kt | 47 +++++ .../nl/atlarge/opendc/kernel/messaging/Writable.kt | 43 ++++ .../nl/atlarge/opendc/simulator/ChannelContext.kt | 35 ---- .../kotlin/nl/atlarge/opendc/simulator/Context.kt | 68 ------ .../nl/atlarge/opendc/simulator/EntityContext.kt | 45 ---- .../kotlin/nl/atlarge/opendc/simulator/Kernel.kt | 46 ---- .../nl/atlarge/opendc/simulator/Simulator.kt | 44 ---- .../nl/atlarge/opendc/simulator/clock/Clock.kt | 53 ----- .../atlarge/opendc/simulator/messaging/Channel.kt | 49 ----- .../atlarge/opendc/simulator/messaging/Envelope.kt | 44 ---- .../nl/atlarge/opendc/simulator/messaging/Port.kt | 33 --- .../atlarge/opendc/simulator/messaging/Readable.kt | 47 ----- .../atlarge/opendc/simulator/messaging/Writable.kt | 42 ---- .../opendc/simulator/omega/OmegaSimulator.kt | 233 --------------------- .../nl/atlarge/opendc/topology/AdjacencyList.kt | 202 ++++++++++++++---- .../kotlin/nl/atlarge/opendc/topology/Component.kt | 13 +- .../main/kotlin/nl/atlarge/opendc/topology/Edge.kt | 13 +- .../kotlin/nl/atlarge/opendc/topology/Entity.kt | 8 +- .../atlarge/opendc/topology/ImmutableTopology.kt | 31 --- .../nl/atlarge/opendc/topology/MutableTopology.kt | 22 +- .../main/kotlin/nl/atlarge/opendc/topology/Node.kt | 77 ------- .../kotlin/nl/atlarge/opendc/topology/Topology.kt | 11 +- .../nl/atlarge/opendc/topology/TopologyContext.kt | 48 +++++ .../opendc/topology/container/Datacenter.kt | 36 ---- .../nl/atlarge/opendc/topology/container/Rack.kt | 37 ---- .../nl/atlarge/opendc/topology/container/Room.kt | 34 --- .../nl/atlarge/opendc/topology/machine/Cpu.kt | 38 ---- .../nl/atlarge/opendc/topology/machine/Gpu.kt | 39 ---- .../nl/atlarge/opendc/topology/machine/Machine.kt | 88 -------- .../opendc/topology/machine/ProcessingUnit.kt | 49 ----- .../atlarge/opendc/topology/network/NetworkUnit.kt | 34 --- .../nl/atlarge/opendc/topology/power/PowerUnit.kt | 37 ---- .../atlarge/opendc/topology/storage/StorageUnit.kt | 34 --- .../src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 59 ------ 47 files changed, 679 insertions(+), 1669 deletions(-) delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Experiment.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/ExperimentRunner.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Job.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Scheduler.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Task.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/User.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Clock.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/Interrupt.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/Process.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/Readable.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/ChannelContext.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Context.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/EntityContext.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Kernel.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/clock/Clock.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Channel.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Envelope.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Port.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Readable.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Writable.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt delete 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/Node.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyContext.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Datacenter.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Rack.kt delete 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/machine/Cpu.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/network/NetworkUnit.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/power/PowerUnit.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/storage/StorageUnit.kt delete mode 100644 opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt (limited to 'opendc-core') diff --git a/opendc-core/build.gradle b/opendc-core/build.gradle index bf71b63b..92cdb2c4 100644 --- a/opendc-core/build.gradle +++ b/opendc-core/build.gradle @@ -25,24 +25,24 @@ /* Build configuration */ buildscript { ext.kotlin_version = '1.1.4-3' + ext.dokka_version = '0.9.15' repositories { mavenCentral() + jcenter() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3' } } -plugins { - id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.1.4' -} - -apply plugin: 'org.junit.platform.gradle.plugin' +apply plugin: 'java' apply plugin: 'kotlin' +apply plugin: 'org.jetbrains.dokka' +apply plugin: 'org.junit.platform.gradle.plugin' compileKotlin { kotlinOptions { @@ -62,6 +62,11 @@ kotlin { } } +dokka { + outputFormat = 'html' + outputDirectory = "$buildDir/javadoc" +} + /* Project configuration */ group 'nl.atlarge.opendc' version '1.0' @@ -74,9 +79,9 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.18" - compile "io.github.microutils:kotlin-logging:1.4.6" testCompile "org.junit.jupiter:junit-jupiter-api:5.0.0-RC3" testRuntime "org.junit.jupiter:junit-jupiter-engine:5.0.0-RC3" + testCompile "org.junit.platform:junit-platform-launcher:1.0.0-RC3" testCompile "org.slf4j:slf4j-simple:1.7.25" } diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Experiment.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Experiment.kt deleted file mode 100644 index a4f947c8..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Experiment.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 - -/** - * A simulation of multiple simultaneous workloads running on top of a topology. - * - * @param id The unique identifier of the experiment. - * @param name The name of the experiment. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -data class Experiment(val id: Int, val name: String) diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/ExperimentRunner.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/ExperimentRunner.kt deleted file mode 100644 index e53c6e08..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/ExperimentRunner.kt +++ /dev/null @@ -1,39 +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 - -/** - * An [ExperimentRunner] is responsible for executing an [Experiment]. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface ExperimentRunner { - /** - * Run the given [Experiment] using this runner. - * - * @param experiment The experiment to run. - */ - fun run(experiment: Experiment) -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Job.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Job.kt deleted file mode 100644 index 8c41735d..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Job.kt +++ /dev/null @@ -1,36 +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 - -/** - * A job that is submitted to a cloud network, which consists of one or multiple [Task]s. - * - * @param id The unique identifier of this job. - * @param name The name of this job. - * @param owner The user to which the job belongs. - * @param tasks The tasks of which the job consists. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -data class Job(val id: Int, val name: String, val owner: User, val tasks: Collection) 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 deleted file mode 100644 index 14a623a6..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Scheduler.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.experiment - -import nl.atlarge.opendc.topology.Node - -/** - * 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> { - /** - * Schedule the given jobs for the given entity. - * - * @param entity The entity in the cloud network topology representing the entity. - * @param jobs The jobs that have been submitted to the cloud network. - */ - fun schedule(entity: E, jobs: Set) -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Task.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Task.kt deleted file mode 100644 index ec2eb2fa..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/Task.kt +++ /dev/null @@ -1,64 +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 - -/** - * A task represents some computation that is part of a [Job]. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -data class Task( - val id: Int, - val dependencies: Set, - val flops: Long -) { - /** - * The remaining amount of flops to compute. - */ - var remaining: Long = flops - private set - - /** - * A flag to indicate whether the task is finished. - */ - var finished: Boolean = false - private set - - /** - * Consume the given amount of flops of this task. - * - * @param flops The total amount of flops to consume. - */ - fun consume(flops: Long) { - if (finished) - return - if (remaining <= flops) { - finished = true - remaining = 0 - } else { - remaining -= flops - } - } -} 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 deleted file mode 100644 index bb87a167..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/experiment/User.kt +++ /dev/null @@ -1,40 +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 - -import nl.atlarge.opendc.topology.Topology - -/** - * A user of a cloud network that provides [Job]s for the simulation. - * - *

Each [User] in a simulation has its own logical view of the cloud network which is used to route its jobs in the - * physical network. - * - * @param id The unique identifier of the user. - * @param name The name of the user. - * @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: Topology) diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Clock.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Clock.kt new file mode 100644 index 00000000..0328bbe6 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Clock.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 + +/** + * 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 simulation time of a simulation [Kernel]. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Clock { + /** + * The tick the clock is currently at. + */ + val tick: Tick +} 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..600a9cee --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Context.kt @@ -0,0 +1,86 @@ +/* + * 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.kernel.messaging.Writable +import nl.atlarge.opendc.topology.Entity +import nl.atlarge.opendc.topology.Topology +import nl.atlarge.opendc.topology.TopologyContext + +/** + * This interface provides a context for simulation [Process]es, which defines the environment in which the simulation + * is run and provides means of communicating with other entities in the environment and control its own behaviour. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Context> : Readable, Writable, TopologyContext { + /** + * The [Topology] over which the simulation is run. + */ + val topology: Topology + + /** + * The global [Clock] that keeps track of the simulation time. + */ + val clock: Clock + + /** + * The [Entity] in simulation by the [Process]. + */ + val entity: E + + /** + * The observable state of an [Entity] in simulation, which is provided by the simulation context. + */ + val , S> E.state: S + + /** + * Interrupt the [Process] of an [Entity] in simulation. + */ + suspend fun Entity<*>.interrupt() + + /** + * Suspend the [Process] of the [Entity] in simulation until the next tick has occurred in the simulation. + */ + suspend fun tick(): Boolean + + /** + * Suspend the [Process] of the [Entity] in simulation for n ticks before resuming execution. + * + * @param n The amount of ticks to suspend the process. + */ + suspend fun wait(n: Int) + + /** + * Update the observable 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/Interrupt.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Interrupt.kt new file mode 100644 index 00000000..de7c5c6c --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Interrupt.kt @@ -0,0 +1,32 @@ +/* + * 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 + +/** + * An [Interrupt] message is sent to a [Process] in order to interrupt its suspended state. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +object Interrupt: Throwable("The process has been interrupted by another entity") 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..9678db41 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Kernel.kt @@ -0,0 +1,68 @@ +/* + * 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.Topology +import java.lang.Process + +/** + * A message-based discrete event simulator (DES). This interface allows running simulations over a [Topology]. + * This discrete event simulator works by having entities in a [Topology] interchange messages between each other and + * updating their observable state accordingly. + * + * In order to run a simulation, a kernel needs to bootstrapped by an initial set of messages to be processed by + * entities in the topology of the simulation. Otherwise, the simulation will immediately exit. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Kernel { + /** + * The [Topology] over which the simulation is run. + */ + val topology: Topology + + /** + * Step through one cycle in the simulation. This method will process all events in a single tick, update the + * internal clock and then return the control to the user. + */ + fun step() + + /** + * Run a simulation over the specified [Topology]. + * This method will step through multiple cycles in the simulation until no more message exist in the queue. + */ + fun run() + + /** + * Schedule a message for processing by a [Process]. + * + * @param message The message to schedule. + * @param destination The destination of the message. + * @param sender The sender of the message. + * @param delay The amount of ticks to wait before processing the message. + */ + fun schedule(message: Any?, destination: Entity<*>, sender: Entity<*>? = null, delay: Int = 0) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Process.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Process.kt new file mode 100644 index 00000000..40fbefbf --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Process.kt @@ -0,0 +1,51 @@ +/* + * 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 + +/** + * A [Process] defines the behaviour of an [Entity] within simulation. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Process> { + /** + * This method is invoked to start the simulation an [Entity] associated with this [Process]. + * + * This method is assumed to be running during a simulation, but should hand back control to the simulator at + * some point by suspending the process. This allows other processes to do work in the current tick of the + * simulation. + * Suspending the process can be achieved by calling suspending method in the context: + * - [Context.tick] - Wait for the next tick to occur + * - [Context.wait] - Wait for `n` amount of ticks before resuming execution. + * - [Context.receive] - Wait for a message to be received in the mailbox of the [Entity] before resuming + * execution. + * + * If this method exits early, before the simulation has finished, the entity is assumed to be shutdown and its + * simulation will not run any further. + */ + suspend fun Context.run() +} 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..61d1a0cf --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Envelope.kt @@ -0,0 +1,56 @@ +/* + * 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.kernel.Tick +import nl.atlarge.opendc.topology.Entity + +/** + * The envelope of a message that is received from a [Channel], also containing the metadata of the message. + * + * @param T The shape of the message inside the envelope. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +data class Envelope( + /** + * The message in this envelope. + */ + val message: T, + + /** + * The tick at which the message should be delivered. + */ + val tick: Tick, + + /** + * The sender of the message. + */ + val sender: Entity<*>?, + + /** + * The destination of the message. + */ + val destination: Entity<*> +) 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/Writable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt new file mode 100644 index 00000000..45c81e39 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/messaging/Writable.kt @@ -0,0 +1,43 @@ +/* + * 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.Entity + +/** + * A [Writable] instance allows entities to send messages. + * + * @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. + * @param delay The number of ticks before the message should be received. + */ + suspend fun Entity<*>.send(msg: Any?, sender: Entity<*>? = null, delay: Int = 0) +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/ChannelContext.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/ChannelContext.kt deleted file mode 100644 index dee55730..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/ChannelContext.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.simulator - -import nl.atlarge.opendc.simulator.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/simulator/Context.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Context.kt deleted file mode 100644 index 61ba8192..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Context.kt +++ /dev/null @@ -1,68 +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.simulator - -import nl.atlarge.opendc.simulator.messaging.Readable -import nl.atlarge.opendc.topology.Component -import nl.atlarge.opendc.topology.Entity -import nl.atlarge.opendc.topology.Topology - -/** - * 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 [Topology] over which the simulation is run. - */ - val topology: Topology - - /** - * 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 { - wait(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 wait(n: Int) -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/EntityContext.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/EntityContext.kt deleted file mode 100644 index 3cbbea71..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/EntityContext.kt +++ /dev/null @@ -1,45 +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.simulator - -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/simulator/Kernel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Kernel.kt deleted file mode 100644 index 0e0a62a6..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Kernel.kt +++ /dev/null @@ -1,46 +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.simulator - -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.simulate() -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.kt deleted file mode 100644 index 72494793..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/Simulator.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.simulator - -import nl.atlarge.opendc.topology.Topology - -/** - * A [Simulator] runs a simulation over the specified topology. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Simulator { - /** - * The [Topology] over which the simulation runs. - */ - val topology: Topology - - /** - * Run the next cycle in the simulation. - */ - fun next() -} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/clock/Clock.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/clock/Clock.kt deleted file mode 100644 index 07377e4a..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/clock/Clock.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.simulator.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/simulator/messaging/Channel.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Channel.kt deleted file mode 100644 index 35407897..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Channel.kt +++ /dev/null @@ -1,49 +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.simulator.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/simulator/messaging/Envelope.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Envelope.kt deleted file mode 100644 index 2c09fe8a..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Envelope.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.simulator.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/simulator/messaging/Port.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Port.kt deleted file mode 100644 index a7d7caba..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Port.kt +++ /dev/null @@ -1,33 +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.simulator.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/simulator/messaging/Readable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Readable.kt deleted file mode 100644 index 161bcbd8..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Readable.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.simulator.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/simulator/messaging/Writable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Writable.kt deleted file mode 100644 index c8b354b1..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/messaging/Writable.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.simulator.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/simulator/omega/OmegaSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt deleted file mode 100644 index dc3c0d0f..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt +++ /dev/null @@ -1,233 +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.simulator.omega - -import mu.KotlinLogging -import nl.atlarge.opendc.simulator.* -import nl.atlarge.opendc.simulator.clock.Clock -import nl.atlarge.opendc.simulator.clock.Tick -import nl.atlarge.opendc.simulator.messaging.Envelope -import nl.atlarge.opendc.topology.* -import java.util.* -import kotlin.coroutines.experimental.* - -/** - * The Omega simulator is the default [Simulator] implementation for the OpenDC core. - * - *

This simulator implementation is a single-threaded implementation running simulation kernels synchronously and - * provides a single priority queue for all events (messages, ticks, etc) that occur in the components. - * - *

By default, [Kernel]s are resolved as part of the [Topology], meaning each [Component] in the topology also - * implements its simulation logic by deriving from the [Kernel] interface. - * - * @param topology The topology to run the simulation over. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class OmegaSimulator(override val topology: Topology) : Simulator, Iterator { - /** - * The logger instance to use for the simulator. - */ - private val logger = KotlinLogging.logger {} - - /** - * The registry of the simulation kernels used in the experiment. - */ - private val registry: MutableMap, 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: OmegaClock = OmegaClock() - - /** - * Initialize the simulator. - */ - init { - topology.forEach { node -> - resolve(node) - node.outgoingEdges.forEach { resolve(it) } - } - - registry.values.forEach { context -> - if (context == null) - return@forEach - @Suppress("UNCHECKED_CAST") - val kernel = context.component.label as Kernel> - - // Start all kernel co-routines - val block: suspend () -> Unit = { kernel.run { context.simulate() } } - block.startCoroutine(KernelCoroutine()) - } - } - - /** - * 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): Context? { - @Suppress("UNCHECKED_CAST") - return registry.computeIfAbsent(component, { - if (component.label !is Kernel<*>) - null - else when (component) { - is Node<*> -> OmegaEntityContext(component as Node<*>) - is Edge<*> -> OmegaChannelContext(component as Edge<*>) - else -> null - } - }) as 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 - // Jump in time to next event - clock.tick = tick - 1 - break - } else if (tick < clock.tick) { - // Tick has already occurred - logger.warn { "tick was not handled correctly" } - } - clock.queue.poll() - block() - } - } - - /** - * The co-routine which runs a simulation kernel. - */ - private class KernelCoroutine : 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 [Clock] for this [OmegaSimulator] that keeps track of the simulation time in ticks. - */ - private inner class OmegaClock : 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)) - } - } - - /** - * This internal class provides the default implementation for the [Context] interface for this simulator. - */ - private abstract inner class OmegaAbstractContext> : Context { - /** - * The [Topology] over which the simulation is run. - */ - override val topology: Topology = this@OmegaSimulator.topology - - /** - * 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 { - TODO("not implemented") - } - - /** - * The observable state of an [Entity] within the simulation is provided by the context of the simulation. - */ - @Suppress("UNCHECKED_CAST") - override val Entity.state: S - get() = states.computeIfAbsent(this, { initialState }) as S - - /** - * Suspend the simulation kernel for n ticks before resuming the execution. - * - * @param n The amount of ticks to suspend the simulation kernel, with n > 0 - */ - suspend override fun wait(n: Int) { - require(n > 0) { "The amount of ticks to suspend must be a non-zero positive number" } - return suspendCoroutine { cont -> - clock.scheduleAfter(n, { cont.resume(Unit) }) - } - } - } - - /** - * An internal class to provide [Context] for an entity within the simulation. - */ - private inner class OmegaEntityContext>(override val component: Node) : OmegaAbstractContext>(), EntityContext { - /** - * 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) - } - } - - /** - * An internal class to provide the [Context] for an edge kernel within the simulation. - */ - private inner class OmegaChannelContext(override val component: Edge) : OmegaAbstractContext>(), ChannelContext { - /** - * 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<*>) { - TODO("not implemented") - } - } -} 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 index 28154695..e2824f5d 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt @@ -24,14 +24,32 @@ package nl.atlarge.opendc.topology +import nl.atlarge.opendc.topology.Edge as BaseEdge import java.util.concurrent.atomic.AtomicInteger +/** + * This module provides a [Topology] implementation backed internally by an adjacency list. + * + * This implementation is best suited for sparse graphs, where an adjacency matrix would take up too much space with + * empty cells. + * + * *Note that this implementation is not synchronized.* + */ +object AdjacencyList { + /** + * Return a [TopologyBuilder] that constructs the topology represents as an adjacency list. + * + * @return A [TopologyBuilder] instance. + */ + fun builder(): TopologyBuilder = AdjacencyListTopologyBuilder() +} + /** * A builder for [Topology] instances, which is backed by an adjacency list. * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -class AdjacencyListTopologyBuilder: TopologyBuilder { +internal class AdjacencyListTopologyBuilder : TopologyBuilder { /** * Build a [Topology] instance from the current state of this builder. * @@ -43,41 +61,38 @@ class AdjacencyListTopologyBuilder: TopologyBuilder { /** * A [Topology] whose graph is represented as adjacency list. */ -internal class AdjacencyListTopology: MutableTopology { - private val nextId: AtomicInteger = AtomicInteger(0) - private val nodes: MutableList> = ArrayList() - +internal class AdjacencyListTopology : MutableTopology { /** - * Returns the size of the collection. + * The identifier for the next node in the graph. */ - override val size: Int = nodes.size + private var nextId: AtomicInteger = AtomicInteger(0) /** - * Checks if the specified element is contained in this collection. + * A mapping of nodes to their internal representation with the edges of the nodes. */ - override fun contains(element: Node<*>): Boolean = nodes.contains(element) + private var nodes: MutableMap, Node> = HashMap() + + // Topology /** - * Checks if all elements in the specified collection are contained in this collection. + * A unique identifier of this node within the topology. */ - override fun containsAll(elements: Collection>): Boolean = nodes.containsAll(elements) + override val Entity<*>.id: Int + get() = nodes[this]!!.id /** - * Returns `true` if the collection is empty (contains no elements), `false` otherwise. + * The set of ingoing edges of this node. */ - override fun isEmpty(): Boolean = nodes.isEmpty() + override val Entity<*>.ingoingEdges: MutableSet> + get() = nodes[this]!!.ingoingEdges /** - * 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. + * The set of outgoing edges of this node. */ - override fun > node(entity: T): Node { - val node = AdjacencyListNode(nextId.getAndIncrement(), entity) - nodes.add(node) - return node - } + override val Entity<*>.outgoingEdges: MutableSet> + get() = nodes[this]!!.outgoingEdges + + // MutableTopology /** * Create a directed edge between two [Node]s in the topology. @@ -88,33 +103,140 @@ internal class AdjacencyListTopology: MutableTopology { * @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) + override fun connect(from: Entity<*>, to: Entity<*>, label: T, tag: String?): BaseEdge { + if (!contains(from) || !contains(to)) + throw IllegalArgumentException("One of the entities is not part of the topology") + val edge = Edge(label, tag, from, to) from.outgoingEdges.add(edge) to.ingoingEdges.add(edge) return edge } + // Cloneable + + /** + * Create a copy of the graph. + * + * @return A new [Topology] instance with a copy of the graph. + */ + override public fun clone(): Topology { + val copy = AdjacencyListTopology() + copy.nextId = AtomicInteger(nextId.get()) + copy.nodes = HashMap(nodes) + return copy + } + + // Set + + /** + * Returns the size of the collection. + */ + override val size: Int = nodes.size + + /** + * Checks if the specified element is contained in this collection. + */ + override fun contains(element: Entity<*>): Boolean = nodes.contains(element) + + /** + * Checks if all elements in the specified collection are contained in this collection. + */ + override fun containsAll(elements: Collection>): Boolean = elements.all { nodes.containsKey(it) } + + /** + * Returns `true` if the collection is empty (contains no elements), `false` otherwise. + */ + override fun isEmpty(): Boolean = nodes.isEmpty() + + // MutableSet + + /** + * Add a node to the graph. + * + * @param element The element to add to this graph. + * @return `true` if the graph has changed, `false` otherwise. + */ + override fun add(element: Entity<*>): Boolean = nodes.putIfAbsent(element, Node(nextId.getAndIncrement())) == null + + /** + * Add all nodes in the specified collection to the graph. + * + * @param elements The nodes to add to this graph. + * @return `true` if the graph has changed, `false` otherwise. + */ + override fun addAll(elements: Collection>): Boolean = elements.any { add(it) } + + /** + * Remove all nodes and their respective edges from the graph. + */ + override fun clear() = nodes.clear() + + /** + * Remove the given node and its edges from the graph. + * + * @param element The element to remove from the graph. + * @return `true` if the graph has changed, `false` otherwise. + */ + override fun remove(element: Entity<*>): Boolean { + nodes[element]?.ingoingEdges?.forEach { + it.from.outgoingEdges.remove(it) + } + nodes[element]?.outgoingEdges?.forEach { + it.to.ingoingEdges.remove(it) + } + return nodes.keys.remove(element) + } + + + /** + * Remove all nodes in the given collection from the graph. + * + * @param elements The elements to remove from the graph. + * @return `true` if the graph has changed, `false` otherwise. + */ + override fun removeAll(elements: Collection>): Boolean = elements.any(this::remove) + /** - * Returns an iterator over the elements of this object. + * Remove all nodes in the graph, except those in the specified collection. + * + * Take note that this method currently only guarantees a maximum runtime complexity of O(n^2). + * + * @param elements The elements to retain in the graph. */ - override fun iterator(): MutableIterator> = nodes.iterator() + override fun retainAll(elements: Collection>): Boolean { + val iterator = nodes.keys.iterator() + var changed = false + while (iterator.hasNext()) { + val entity = iterator.next() - internal inner class AdjacencyListNode>(override val id: Int, override val label: T): Node { - override var ingoingEdges: MutableSet> = HashSet() - override var outgoingEdges: MutableSet> = HashSet() - override fun toString(): String = label.toString() - internal fun validate(instance: AdjacencyListTopology) = this@AdjacencyListTopology == instance + if (entity !in elements) { + iterator.remove() + changed = true + } + } + return changed } - 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() + /** + * Return a mutable iterator over the nodes of the graph. + * + * @return A [MutableIterator] over the nodes of the graph. + */ + override fun iterator(): MutableIterator> = nodes.keys.iterator() + + /** + * The internal representation of a node within the graph. + */ + internal data class Node(val id: Int) { + val ingoingEdges: MutableSet> = HashSet() + val outgoingEdges: MutableSet> = HashSet() } + + /** + * The internal representation of an edge within the graph. + */ + internal class Edge(override val label: T, + override val tag: String?, + override val from: Entity<*>, + override val to: Entity<*>) : BaseEdge } 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 index 79b35e86..3c383892 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Component.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Component.kt @@ -25,16 +25,9 @@ package nl.atlarge.opendc.topology /** - * A component within a [Topology], which is either an [Node] or an [Edge] representing the relationship between + * A component within a [Topology], which is either a 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 -} +interface Component 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 22ad57c1..3be14dec 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 @@ -25,12 +25,17 @@ package nl.atlarge.opendc.topology /** - * An edge that represents a directed relationship between exactly two [Node]s in a logical topology of a cloud network. + * An edge that represents a directed relationship between exactly two nodes in a logical topology of a cloud network. * * @param T The relationship type the edge represents within a logical topology. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface Edge: Component { +interface Edge : Component { + /** + * The label of this edge. + */ + val label: T + /** * A tag to uniquely identify the relationship this edge represents. */ @@ -42,7 +47,7 @@ interface Edge: Component { * 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. */ - val from: Node<*> + val from: Entity<*> /** * The destination of the edge. @@ -50,5 +55,5 @@ interface Edge: Component { * 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. */ - val to: Node<*> + val to: Entity<*> } 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 e6f37cf6..66a31d77 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,10 +25,10 @@ package nl.atlarge.opendc.topology /** - * An entity within a cloud network. + * An entity within a cloud network, represented as a node within a topology. * - *

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. + *

A [Entity] contains immutable properties 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. * @@ -36,7 +36,7 @@ package nl.atlarge.opendc.topology * a simulation. * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface Entity { +interface Entity : Component { /** * The initial state of the entity. */ 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 deleted file mode 100644 index 90ba5dc5..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/ImmutableTopology.kt +++ /dev/null @@ -1,31 +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 [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/MutableTopology.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt index 0aa0d1b5..10a55e5b 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/MutableTopology.kt @@ -30,17 +30,9 @@ package nl.atlarge.opendc.topology * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface MutableTopology: Topology { +interface MutableTopology : Topology, MutableSet> { /** - * 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. + * Create a directed, labeled edge between two nodes in the topology. * * @param from The source of the edge. * @param to The destination of the edge. @@ -48,23 +40,23 @@ interface MutableTopology: Topology { * @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 + fun connect(from: Entity<*>, to: Entity<*>, label: T, tag: String? = null): Edge /** - * Create a directed edge between two [Node]s in the topology. + * Create a directed, unlabeled edge between two nodes 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) + fun connect(from: Entity<*>, to: Entity<*>, tag: String? = null): Edge = connect(from, to, Unit, tag) /** - * Create a directed edge between two [Node]s in the topology. + * Create a directed, unlabeled edge between two nodes 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) + infix fun Entity<*>.to(dest: Entity<*>): 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 deleted file mode 100644 index ee1cde9b..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt +++ /dev/null @@ -1,77 +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 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 - - /** - * The set of ingoing edges of this node. - */ - val ingoingEdges: Set> - - /** - * The set of outgoing edges of this node. - */ - val outgoingEdges: Set> - - /** - * The [Entity] this node represents within a logical topology of a cloud network. - */ - val entity: T - get() = label -} - -/** - * Return the set of entities that are connected inwards to this node with the given tag. - * - * @param tag The tag of the edges to get. - * @param T The shape of the label of these edges. - * @return The entities of all edges whose destination is this node and have the given tag. - */ -inline fun Node<*>.ingoing(tag: String) = - ingoingEdges.filter { it.tag == tag }.map { it.to.entity as T }.toSet() - - -/** - * Return the set of entities that are connected outwards to this node with the given tag. - * - * @param tag The tag of the edges to get. - * @param T The shape of the label of these edges. - * @return The entities of all edges whose source is this node and have the given tag. - */ -inline fun Node<*>.outgoing(tag: String) = - outgoingEdges.filter { it.tag == tag }.map { it.to.entity as T }.toSet() 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 index 5d88334c..5b697bfb 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt @@ -28,8 +28,15 @@ 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. + * 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: Set> +interface Topology : TopologyContext, Cloneable, Set> { + /** + * Create a copy of the topology. + * + * @return A new [Topology] with a copy of the graph. + */ + public override fun clone(): Topology +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyContext.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyContext.kt new file mode 100644 index 00000000..22e7dd94 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyContext.kt @@ -0,0 +1,48 @@ +/* + * 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 [TopologyContext] represents the context for entities in a specific topology, providing access to the identifier + * and ingoing and outgoing edges of the [Entity] within a [Topology]. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface TopologyContext { + /** + * A unique identifier of an [Entity] within the topology. + */ + val Entity<*>.id: Int + + /** + * The set of ingoing edges of an [Entity]. + */ + val Entity<*>.ingoingEdges: Set> + + /** + * The set of outgoing edges of an [Entity]. + */ + val Entity<*>.outgoingEdges: Set> +} 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 deleted file mode 100644 index b484f70e..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Datacenter.kt +++ /dev/null @@ -1,36 +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 - -import nl.atlarge.opendc.topology.Entity - -/** - * A representation of a facility used to house computer systems and associated components. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class Datacenter: Entity { - override val initialState = Unit -} 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 deleted file mode 100644 index f9595adc..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/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 - -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 { - override val initialState = Unit -} 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 deleted file mode 100644 index 844d96a0..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/container/Room.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.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/machine/Cpu.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt deleted file mode 100644 index 1e2135e8..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt +++ /dev/null @@ -1,38 +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.machine - -/** - * A central processing unit. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -data class Cpu( - override val speed: Int, - override val cores: Int, - override val energyConsumption: Int -): ProcessingUnit { - override val initialState = Unit -} 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 deleted file mode 100644 index a294db38..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt +++ /dev/null @@ -1,39 +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.machine - -/** - * A graphics processing unit. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class Gpu( - override val speed: Int, - override val cores: Int, - override val energyConsumption: Int -): ProcessingUnit { - override val initialState = Unit -} - 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 deleted file mode 100644 index b313b78b..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt +++ /dev/null @@ -1,88 +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.machine - -import nl.atlarge.opendc.experiment.Task -import nl.atlarge.opendc.simulator.EntityContext -import nl.atlarge.opendc.simulator.Kernel -import nl.atlarge.opendc.topology.Entity -import nl.atlarge.opendc.topology.outgoing -import java.util.* - -/** - * 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. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class Machine: Entity, Kernel> { - /** - * The status of a machine. - */ - enum class Status { - HALT, IDLE, RUNNING - } - - /** - * The shape of the state of a [Machine] entity. - */ - data class State(val status: Status) - - /** - * The initial state of a [Machine] entity. - */ - override val initialState = State(Status.HALT) - - /** - * Run the simulation kernel for this entity. - */ - override suspend fun EntityContext.simulate() { - update(state.copy(status = Machine.Status.IDLE)) - - val cpus = component.outgoing("cpu") - val speed = cpus.fold(0, { acc, (speed, cores) -> acc + speed * cores }) - val task: Task - - val delay = Random().nextInt(1000) + 1 - wait(delay) - - loop@while (true) { - val msg = receive() - when (msg) { - is Task -> { - task = msg - break@loop - } - else -> println("warning: unhandled message $msg") - } - } - - update(state.copy(status = Machine.Status.RUNNING)) - while (tick()) { - task.consume(speed.toLong()) - } - update(state.copy(status = Machine.Status.HALT)) - } -} 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 deleted file mode 100644 index a235133f..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt +++ /dev/null @@ -1,49 +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.machine - -import nl.atlarge.opendc.topology.Entity - -/** - * An interface representing a generic processing unit which is placed into a [Machine]. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface ProcessingUnit: Entity { - /** - * The speed of this [ProcessingUnit] per core. - */ - val speed: Int - - /** - * The amount of cores within this [ProcessingUnit]. - */ - val cores: Int - - /** - * The energy consumption of this [ProcessingUnit] in Kj/s. - */ - val energyConsumption: Int -} 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 deleted file mode 100644 index 9c294125..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/network/NetworkUnit.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.topology.network - -import nl.atlarge.opendc.topology.Entity - -/** - * A generic interface for a network unit in a cloud network. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -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 deleted file mode 100644 index 2938e530..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/power/PowerUnit.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.power - -import nl.atlarge.opendc.topology.Entity - -/** - * An [Entity] which provides power for other entities a cloud network to run. - * - * @param output The power output of the power unit in Watt. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -class PowerUnit(val output: Double): Entity { - override val initialState = Unit -} 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 deleted file mode 100644 index 8e53e365..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/storage/StorageUnit.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.topology.storage - -import nl.atlarge.opendc.topology.Entity - -/** - * A generic interface for a storage unit in a cloud network. - * - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface StorageUnit: Entity diff --git a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt deleted file mode 100644 index 6d67c941..00000000 --- a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt +++ /dev/null @@ -1,59 +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 - -import nl.atlarge.opendc.simulator.omega.OmegaSimulator -import nl.atlarge.opendc.topology.AdjacencyListTopologyBuilder -import nl.atlarge.opendc.topology.container.Rack -import nl.atlarge.opendc.topology.machine.Cpu -import nl.atlarge.opendc.topology.machine.Machine -import org.junit.jupiter.api.Test - -internal class SmokeTest { - @Test - fun smoke() { - val builder = AdjacencyListTopologyBuilder() - val topology = builder.construct { - val rack = node(Rack()) - val n = 100 - // Create n machines in the rack - repeat(n) { - val machine = node(Machine()) - connect(rack, machine, tag = "machine") - - val cpu1 = node(Cpu(10, 2, 2)) - val cpu2 = node(Cpu(5, 3, 2)) - - connect(machine, cpu1, tag = "cpu") - connect(machine, cpu2, tag = "cpu") - } - } - - val simulator = OmegaSimulator(topology) - while (simulator.hasNext()) { - simulator.next() - } - } -} -- cgit v1.2.3