summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-29 22:05:03 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-03 17:17:39 +0200
commitd2f15fd7fd16922c11b0dcaa8807e8a321859773 (patch)
treeb39b16890f1d8106e691427c622637431bd2a54b /opendc-simulator/opendc-simulator-compute/src/main
parentf00c5f3663a2bdbfacc2d6f812503f22f1ed26bb (diff)
refactor(simulator): Merge distributor and aggregator into switch
This change removes the distributor and aggregator interfaces in favour of a single switch interface. Since the switch interface is as powerful as both the distributor and aggregator, we don't need the latter two.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt14
1 files changed, 11 insertions, 3 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
index 98271fb0..cf9e3230 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
@@ -131,7 +131,7 @@ public abstract class SimAbstractHypervisor(
/**
* The vCPUs of the machine.
*/
- override val cpus = model.cpus.map { VCpu(switch.newOutput(interferenceKey), it) }
+ override val cpus = model.cpus.map { VCpu(switch, switch.newOutput(interferenceKey), it) }
override fun close() {
super.close()
@@ -153,9 +153,10 @@ public abstract class SimAbstractHypervisor(
* A [SimProcessingUnit] of a virtual machine.
*/
private class VCpu(
- private val source: SimResourceCloseableProvider,
+ private val switch: SimResourceSwitch,
+ private val source: SimResourceProvider,
override val model: ProcessingUnit
- ) : SimProcessingUnit, SimResourceCloseableProvider by source {
+ ) : SimProcessingUnit, SimResourceProvider by source {
override var capacity: Double
get() = source.capacity
set(_) {
@@ -163,6 +164,13 @@ public abstract class SimAbstractHypervisor(
}
override fun toString(): String = "SimAbstractHypervisor.VCpu[model=$model]"
+
+ /**
+ * Close the CPU
+ */
+ fun close() {
+ switch.removeOutput(source)
+ }
}
/**