summaryrefslogtreecommitdiff
path: root/opendc-model-odc/core
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2018-01-11 16:27:05 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2018-01-11 16:52:17 +0100
commitb1c4d1f94e35445bdba5a56b614d0ec28a332624 (patch)
treef2a7244fd52a85f0bd5a4a51f8b3243d10005878 /opendc-model-odc/core
parent8666a78b86a40c1d8dab28dd18e841318c01f97f (diff)
refactor(#18): Redesign core simulation API
This change contains the redesign of the core simulation API and provides a cleaner interface for developing simulation models for the users.
Diffstat (limited to 'opendc-model-odc/core')
-rw-r--r--opendc-model-odc/core/build.gradle87
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/OdcModel.kt10
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/FifoScheduler.kt118
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/Scheduler.kt71
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/SrtfScheduler.kt110
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Job.kt53
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Task.kt92
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/TaskState.kt72
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Trace.kt37
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/User.kt45
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt102
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Rack.kt36
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Room.kt35
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Cpu.kt32
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Gpu.kt33
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Machine.kt123
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/ProcessingUnit.kt50
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/network/NetworkUnit.kt35
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/power/PowerUnit.kt35
-rw-r--r--opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/storage/StorageUnit.kt35
20 files changed, 1211 insertions, 0 deletions
diff --git a/opendc-model-odc/core/build.gradle b/opendc-model-odc/core/build.gradle
new file mode 100644
index 00000000..c8336196
--- /dev/null
+++ b/opendc-model-odc/core/build.gradle
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+/* Build configuration */
+buildscript {
+ ext.kotlin_version = '1.2.10'
+ 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'
+ }
+}
+
+apply plugin: 'java'
+apply plugin: 'kotlin'
+apply plugin: 'org.jetbrains.dokka'
+apply plugin: 'org.junit.platform.gradle.plugin'
+
+compileKotlin {
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+compileTestKotlin {
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+kotlin {
+ experimental {
+ coroutines 'enable'
+ }
+}
+
+dokka {
+ outputFormat = 'html'
+ outputDirectory = "$buildDir/javadoc"
+}
+
+/* Project configuration */
+group 'com.atlarge.opendc'
+version '1.1'
+
+repositories {
+ jcenter()
+}
+
+dependencies {
+ compile project(':opendc-core')
+ compile project(':opendc-stdlib')
+ 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-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/OdcModel.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/OdcModel.kt
new file mode 100644
index 00000000..01ffbd2c
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/OdcModel.kt
@@ -0,0 +1,10 @@
+package com.atlarge.opendc.model.odc
+
+import com.atlarge.opendc.model.topology.MutableTopology
+
+/**
+ * The OpenDC standard simulation model used for datacenter simulations.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface OdcModel: MutableTopology
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/FifoScheduler.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/FifoScheduler.kt
new file mode 100644
index 00000000..d2cbcdfe
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/FifoScheduler.kt
@@ -0,0 +1,118 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.platform.scheduler
+
+import com.atlarge.opendc.simulator.Context
+import com.atlarge.opendc.model.odc.platform.workload.Task
+import com.atlarge.opendc.model.odc.topology.machine.Machine
+import java.util.*
+
+/**
+ * A [Scheduler] that distributes work according to the first-in-first-out principle.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+class FifoScheduler : Scheduler {
+ /**
+ * The name of this scheduler.
+ */
+ override val name: String = "FIFO"
+
+ /**
+ * The set of machines the scheduler knows of.
+ */
+ val machines: MutableSet<Machine> = HashSet()
+
+ /**
+ * The queue of [Task]s that need to be scheduled.
+ */
+ val queue: Queue<Task> = ArrayDeque()
+
+ /**
+ * (Re)schedule the tasks submitted to the scheduler over the specified set of machines.
+ */
+ override suspend fun <S, M> Context<S, M>.schedule() {
+ if (queue.isEmpty()) {
+ return
+ }
+
+ // The tasks that need to be rescheduled
+ val rescheduled = ArrayDeque<Task>()
+ val iterator = queue.iterator()
+
+ machines
+ .filter { it.state.status != Machine.Status.HALT }
+ .forEach { machine ->
+ while (iterator.hasNext()) {
+ val task = iterator.next()
+
+ // TODO What to do with tasks that are not ready yet to be processed
+ if (!task.ready) {
+ iterator.remove()
+ rescheduled.add(task)
+ continue
+ } else if (task.finished) {
+ iterator.remove()
+ continue
+ }
+
+ machine.send(task)
+ break
+ }
+ }
+
+ // Reschedule all tasks that are not ready yet
+ while (!rescheduled.isEmpty()) {
+ queue.add(rescheduled.poll())
+ }
+ }
+
+ /**
+ * Submit a [Task] to this scheduler.
+ *
+ * @param task The task to submit to the scheduler.
+ */
+ override fun submit(task: Task) {
+ queue.add(task)
+ }
+
+ /**
+ * Register a [Machine] to this scheduler.
+ *
+ * @param machine The machine to register.
+ */
+ override fun register(machine: Machine) {
+ machines.add(machine)
+ }
+
+ /**
+ * Deregister a [Machine] from this scheduler.
+ *
+ * @param machine The machine to deregister.
+ */
+ override fun deregister(machine: Machine) {
+ machines.remove(machine)
+ }
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/Scheduler.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/Scheduler.kt
new file mode 100644
index 00000000..ee965af9
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/Scheduler.kt
@@ -0,0 +1,71 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.platform.scheduler
+
+import com.atlarge.opendc.simulator.Context
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.odc.platform.workload.Task
+import com.atlarge.opendc.model.odc.topology.machine.Machine
+
+/**
+ * A task scheduler that is coupled to an [Entity] in the topology of the cloud network.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Scheduler {
+ /**
+ * The name of this scheduler.
+ */
+ val name: String
+
+ /**
+ * (Re)schedule the tasks submitted to the scheduler over the specified set of machines.
+ *
+ * This method should be invoked at some interval to allow the scheduler to reschedule existing tasks and schedule
+ * new tasks.
+ */
+ suspend fun <S, M> Context<S, M>.schedule()
+
+ /**
+ * Submit a [Task] to this scheduler.
+ *
+ * @param task The task to submit to the scheduler.
+ */
+ fun submit(task: Task)
+
+ /**
+ * Register a [Machine] to this scheduler.
+ *
+ * @param machine The machine to register.
+ */
+ fun register(machine: Machine)
+
+ /**
+ * Deregister a [Machine] from this scheduler.
+ *
+ * @param machine The machine to deregister.
+ */
+ fun deregister(machine: Machine)
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/SrtfScheduler.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/SrtfScheduler.kt
new file mode 100644
index 00000000..0e497b56
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/SrtfScheduler.kt
@@ -0,0 +1,110 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.platform.scheduler
+
+import com.atlarge.opendc.simulator.Context
+import com.atlarge.opendc.model.odc.platform.workload.Task
+import com.atlarge.opendc.model.odc.topology.machine.Machine
+import java.util.*
+
+/**
+ * A [Scheduler] that distributes work according to the shortest job first policy.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+class SrtfScheduler : Scheduler {
+ /**
+ * The name of this scheduler.
+ */
+ override val name: String = "SRTF"
+
+ /**
+ * The set of machines the scheduler knows of.
+ */
+ val machines: MutableSet<Machine> = HashSet()
+
+ /**
+ * The set of [Task]s that need to be scheduled.
+ */
+ val tasks: MutableSet<Task> = HashSet()
+
+ /**
+ * (Re)schedule the tasks submitted to the scheduler over the specified set of machines.
+ */
+ override suspend fun <S, M> Context<S, M>.schedule() {
+ if (tasks.isEmpty()) {
+ return
+ }
+
+ val iterator = tasks.sortedBy { it.remaining }.iterator()
+
+ machines
+ .filter { it.state.status != Machine.Status.HALT }
+ .forEach { machine ->
+ while (iterator.hasNext()) {
+ val task = iterator.next()
+
+ // TODO What to do with tasks that are not ready yet to be processed
+ if (!task.ready) {
+ tasks.add(task)
+ continue
+ } else if (task.finished) {
+ tasks.remove(task)
+ continue
+ }
+
+ machine.send(task)
+ break
+ }
+ }
+ }
+
+ /**
+ * Submit a [Task] to this scheduler.
+ *
+ * @param task The task to submit to the scheduler.
+ */
+ override fun submit(task: Task) {
+ tasks.add(task)
+ }
+
+ /**
+ * Register a [Machine] to this scheduler.
+ *
+ * @param machine The machine to register.
+ */
+ override fun register(machine: Machine) {
+ machines.add(machine)
+ }
+
+ /**
+ * Deregister a [Machine] from this scheduler.
+ *
+ * @param machine The machine to deregister.
+ */
+ override fun deregister(machine: Machine) {
+ machines.remove(machine)
+ }
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Job.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Job.kt
new file mode 100644
index 00000000..c42bb667
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Job.kt
@@ -0,0 +1,53 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.platform.workload
+
+/**
+ * A bag of tasks which are submitted by a [User] to the cloud network.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Job {
+ /**
+ * A unique identifier of the job.
+ */
+ val id: Int
+
+ /**
+ * The owner of this job.
+ */
+ val owner: User
+
+ /**
+ * The tasks this job consists of.
+ */
+ val tasks: Set<Task>
+
+ /**
+ * A flag to indicate the job has finished.
+ */
+ val finished: Boolean
+ get() = !tasks.any { !it.finished }
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Task.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Task.kt
new file mode 100644
index 00000000..f7b9d60f
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Task.kt
@@ -0,0 +1,92 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.platform.workload
+
+import com.atlarge.opendc.simulator.Instant
+import com.atlarge.opendc.model.odc.topology.machine.Machine
+
+/**
+ * A task that runs as part of a [Job] on a [Machine].
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Task {
+ /**
+ * The unique identifier of the task.
+ */
+ val id: Int
+
+ /**
+ * The amount of flops for this task.
+ */
+ val flops: Long
+
+ /**
+ * The dependencies of the task.
+ */
+ val dependencies: Set<Task>
+
+ /**
+ * A flag to indicate the task is parallelizable.
+ */
+ val parallelizable: Boolean
+
+ /**
+ * The remaining flops for this task.
+ */
+ val remaining: Long
+
+ /**
+ * The state of the task.
+ */
+ val state: TaskState
+
+ /**
+ * A flag to indicate whether the task is ready to be started.
+ */
+ val ready: Boolean
+ get() = !dependencies.any { !it.finished }
+
+ /**
+ * A flag to indicate whether the task has finished.
+ */
+ val finished: Boolean
+ get() = state is TaskState.Finished
+
+ /**
+ * This method is invoked when a task has arrived at a datacenter.
+ *
+ * @param time The moment in time the task has arrived at the datacenter.
+ */
+ fun arrive(time: Instant)
+
+ /**
+ * Consume the given amount of flops of this task.
+ *
+ * @param time The current moment in time of the consumption.
+ * @param flops The total amount of flops to consume.
+ */
+ fun consume(time: Instant, flops: Long)
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/TaskState.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/TaskState.kt
new file mode 100644
index 00000000..2fb3acd9
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/TaskState.kt
@@ -0,0 +1,72 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.platform.workload
+
+import com.atlarge.opendc.simulator.Instant
+
+
+/**
+ * This class hierarchy describes the states of a [Task].
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+sealed class TaskState {
+ /**
+ * A state to indicate the task has not yet arrived at the [Datacenter].
+ */
+ object Underway : TaskState()
+
+ /**
+ * A state to indicate the task has arrived at the [Datacenter].
+ *
+ * @property at The moment in time the task has arrived.
+ */
+ data class Queued(val at: Instant) : TaskState()
+
+ /**
+ * A state to indicate the task has started running on a machine.
+ *
+ * @property previous The previous state of the task.
+ * @property at The moment in time the task started.
+ */
+ data class Running(val previous: Queued, val at: Instant) : TaskState()
+
+ /**
+ * A state to indicate the task has finished.
+ *
+ * @property previous The previous state of the task.
+ * @property at The moment in time the task finished.
+ */
+ data class Finished(val previous: Running, val at: Instant) : TaskState()
+
+ /**
+ * A state to indicate the task has failed.
+ *
+ * @property previous The previous state of the task.
+ * @property at The moment in time the task failed.
+ * @property reason The reason of the failure.
+ */
+ data class Failed(val previous: Running, val at: Instant, val reason: String) : TaskState()
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Trace.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Trace.kt
new file mode 100644
index 00000000..b2d65277
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Trace.kt
@@ -0,0 +1,37 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.platform.workload
+
+/**
+ * A timestamped sequence of jobs received in a cloud network.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Trace {
+ /**
+ * The [Job]s in the trace.
+ */
+ val jobs: Set<Job>
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/User.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/User.kt
new file mode 100644
index 00000000..6099db3e
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/User.kt
@@ -0,0 +1,45 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.platform.workload
+
+/**
+ * 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.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface User {
+ /**
+ * The unique identifier of the user.
+ */
+ val id: Int
+
+ /**
+ * The name of this user.
+ */
+ val name: String
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt
new file mode 100644
index 00000000..2b682410
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Datacenter.kt
@@ -0,0 +1,102 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.topology.container
+
+import mu.KotlinLogging
+import com.atlarge.opendc.simulator.Context
+import com.atlarge.opendc.simulator.Duration
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.simulator.Process
+import com.atlarge.opendc.model.odc.platform.scheduler.Scheduler
+import com.atlarge.opendc.model.odc.platform.workload.Task
+import com.atlarge.opendc.model.odc.topology.machine.Machine
+import com.atlarge.opendc.model.topology.Topology
+import com.atlarge.opendc.model.topology.destinations
+import java.util.*
+
+/**
+ * A representation of a facility used to house computer systems and associated components.
+ *
+ * @property scheduler The tasks scheduler the datacenter uses.
+ * @property interval The interval at which task will be (re)scheduled.
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Datacenter : Process<Unit, Topology> {
+ /**
+ * The task scheduler the datacenter uses.
+ */
+ val scheduler: Scheduler
+
+ /**
+ * The interval at which task will be (re)scheduled.
+ */
+ val interval: Duration
+
+ /**
+ * This method is invoked to start the simulation an [Entity] associated with this [Context].
+ *
+ * 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.hold] - 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 override fun Context<Unit, Topology>.run() = model.run {
+ val logger = KotlinLogging.logger {}
+
+ // The queue of messages to be processed after a cycle
+ val queue: Queue<Any> = ArrayDeque()
+ // Find all machines in the datacenter
+ val machines = outgoingEdges.destinations<Room>("room").asSequence()
+ .flatMap { it.outgoingEdges.destinations<Rack>("rack").asSequence() }
+ .flatMap { it.outgoingEdges.destinations<Machine>("machine").asSequence() }.toList()
+
+ logger.info { "Initialising datacenter with ${machines.size} machines" }
+
+ // Register all machines to the scheduler
+ machines.forEach(scheduler::register)
+
+ while (true) {
+ // Context all messages in the queue
+ while (queue.isNotEmpty()) {
+ val msg = queue.poll()
+ if (msg is Task) {
+ msg.arrive(time)
+ scheduler.submit(msg)
+ }
+ }
+ // (Re)schedule the tasks
+ scheduler.run { schedule() }
+
+ // Sleep a time quantum
+ hold(interval, queue)
+ }
+ }
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Rack.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Rack.kt
new file mode 100644
index 00000000..0ec43f9a
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Rack.kt
@@ -0,0 +1,36 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.topology.container
+
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.topology.Topology
+
+/**
+ * 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)
+ */
+interface Rack : Entity<Unit, Topology>
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Room.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Room.kt
new file mode 100644
index 00000000..50cfc3e6
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Room.kt
@@ -0,0 +1,35 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.topology.container
+
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.topology.Topology
+
+/**
+ * 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<Unit, Topology>
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Cpu.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Cpu.kt
new file mode 100644
index 00000000..58eacdc1
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Cpu.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 com.atlarge.opendc.model.odc.topology.machine
+
+/**
+ * A central processing unit.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Cpu : ProcessingUnit
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Gpu.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Gpu.kt
new file mode 100644
index 00000000..84afc711
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Gpu.kt
@@ -0,0 +1,33 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.topology.machine
+
+/**
+ * A graphics processing unit.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface Gpu : ProcessingUnit
+
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Machine.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Machine.kt
new file mode 100644
index 00000000..4f4ce645
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Machine.kt
@@ -0,0 +1,123 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.topology.machine
+
+import com.atlarge.opendc.simulator.Context
+import com.atlarge.opendc.simulator.Process
+import com.atlarge.opendc.model.odc.platform.workload.Task
+import com.atlarge.opendc.model.topology.Topology
+import com.atlarge.opendc.model.topology.destinations
+import com.atlarge.opendc.simulator.Duration
+import mu.KotlinLogging
+
+/**
+ * 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)
+ */
+open class Machine : Process<Machine.State, Topology> {
+ /**
+ * The logger instance to use for the simulator.
+ */
+ private val logger = KotlinLogging.logger {}
+
+ /**
+ * The status of a machine.
+ */
+ enum class Status {
+ HALT, IDLE, RUNNING
+ }
+
+ /**
+ * The shape of the state of a [Machine] entity.
+ *
+ * @property status The status of the machine.
+ * @property task The task assign to the machine.
+ * @property memory The memory usage of the machine (defaults to 50mb for the kernel)
+ * @property load The load on the machine (defaults to 0.0)
+ * @property temperature The temperature of the machine (defaults to 23 degrees Celcius)
+ */
+ data class State(val status: Status,
+ val task: Task? = null,
+ val memory: Int = 50,
+ val load: Double = 0.0,
+ val temperature: Double = 23.0)
+
+ /**
+ * The initial state of a [Machine] entity.
+ */
+ override val initialState = State(Status.HALT)
+
+ /**
+ * Run the simulation kernel for this entity.
+ */
+ override suspend fun Context<State, Topology>.run() = model.run {
+ state = State(Status.IDLE)
+
+ val interval: Duration = 10
+ val cpus = outgoingEdges.destinations<Cpu>("cpu")
+ val speed = cpus.fold(0, { acc, cpu -> acc + cpu.clockRate * cpu.cores })
+
+ // Halt the machine if it has not processing units (see bug #4)
+ if (cpus.isEmpty()) {
+ state = State(Status.HALT)
+ return
+ }
+
+ var task: Task = receiveTask()
+ state = State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0)
+
+ while (true) {
+ if (task.finished) {
+ logger.info { "$id: Task ${task.id} finished. Machine idle at $time" }
+ state = State(Status.IDLE)
+ task = receiveTask()
+ } else {
+ task.consume(time, speed * delta)
+ }
+
+ // Check if we have received a new order in the meantime.
+ val msg = receive(interval)
+ if (msg is Task) {
+ task = msg
+ state = State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0)
+ }
+ }
+ }
+
+ /**
+ * Wait for a [Task] to be received by the [Context] and discard all other messages received in the meantime.
+ *
+ * @return The task that has been received.
+ */
+ private suspend fun Context<State, Topology>.receiveTask(): Task {
+ while (true) {
+ val msg = receive()
+ if (msg is Task)
+ return msg
+ }
+ }
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/ProcessingUnit.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/ProcessingUnit.kt
new file mode 100644
index 00000000..0b8989de
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/ProcessingUnit.kt
@@ -0,0 +1,50 @@
+/*
+ * 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 com.atlarge.opendc.model.odc.topology.machine
+
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.topology.Topology
+
+/**
+ * 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<Unit, Topology> {
+ /**
+ * The speed of this [ProcessingUnit] per core in MHz.
+ */
+ val clockRate: Int
+
+ /**
+ * The amount of cores within this [ProcessingUnit].
+ */
+ val cores: Int
+
+ /**
+ * The energy consumption of this [ProcessingUnit] in Watt.
+ */
+ val energyConsumption: Double
+}
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/network/NetworkUnit.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/network/NetworkUnit.kt
new file mode 100644
index 00000000..a41a8326
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/network/NetworkUnit.kt
@@ -0,0 +1,35 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.topology.network
+
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.topology.Topology
+
+/**
+ * A generic interface for a network unit in a cloud network.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface NetworkUnit : Entity<Unit, Topology>
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/power/PowerUnit.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/power/PowerUnit.kt
new file mode 100644
index 00000000..8650b5dc
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/power/PowerUnit.kt
@@ -0,0 +1,35 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.topology.power
+
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.topology.Topology
+
+/**
+ * An [Entity] which provides power for other entities a cloud network to run.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface PowerUnit : Entity<Unit, Topology>
diff --git a/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/storage/StorageUnit.kt b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/storage/StorageUnit.kt
new file mode 100644
index 00000000..b5bb4dfb
--- /dev/null
+++ b/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/storage/StorageUnit.kt
@@ -0,0 +1,35 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 atlarge-research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.atlarge.opendc.model.odc.topology.storage
+
+import com.atlarge.opendc.simulator.Entity
+import com.atlarge.opendc.model.topology.Topology
+
+/**
+ * A generic interface for a storage unit in a cloud network.
+ *
+ * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
+ */
+interface StorageUnit : Entity<Unit, Topology>