summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-06-21 21:33:06 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-06-22 13:25:42 +0200
commitba3efea6c5d2f4d2fbd2ecc9364817f541000839 (patch)
treebbd964d3c1b1cee9983c038ec3ff887eb5884cc4 /opendc-simulator/opendc-simulator-compute/src/test
parentb29f90e5ad5bcac29cde86e56c06e0b65a52cedc (diff)
simulator: Add support for attaching network adapter to machine
This change bridges the compute and network simulation module by adding support for network adapters in the compute module. With these network adapters, compute workloads can communicate over the network that the adapters are connected to.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/test')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt37
1 files changed, 32 insertions, 5 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
index dcf509e2..47ae119c 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
@@ -30,10 +30,8 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.compute.model.MachineModel
-import org.opendc.simulator.compute.model.MemoryUnit
-import org.opendc.simulator.compute.model.ProcessingNode
-import org.opendc.simulator.compute.model.ProcessingUnit
+import org.opendc.simulator.compute.device.SimNetworkAdapter
+import org.opendc.simulator.compute.model.*
import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.power.LinearPowerModel
import org.opendc.simulator.compute.power.SimplePowerDriver
@@ -41,6 +39,7 @@ import org.opendc.simulator.compute.workload.SimFlopsWorkload
import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.compute.workload.SimWorkloadLifecycle
import org.opendc.simulator.core.runBlockingSimulation
+import org.opendc.simulator.network.SimNetworkSink
import org.opendc.simulator.power.SimPowerSource
import org.opendc.simulator.resources.SimResourceInterpreter
import org.opendc.simulator.resources.consumer.SimWorkConsumer
@@ -58,7 +57,8 @@ class SimMachineTest {
machineModel = MachineModel(
cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 1000.0) },
- memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) }
+ memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) },
+ net = listOf(NetworkAdapter("Mellanox", "ConnectX-5", 25000.0))
)
}
@@ -233,6 +233,33 @@ class SimMachineTest {
}
@Test
+ fun testNetUsage() = runBlockingSimulation {
+ val interpreter = SimResourceInterpreter(coroutineContext, clock)
+ val machine = SimBareMetalMachine(
+ interpreter,
+ machineModel,
+ SimplePowerDriver(ConstantPowerModel(0.0))
+ )
+
+ val adapter = (machine.peripherals[0] as SimNetworkAdapter)
+ adapter.connect(SimNetworkSink(interpreter, adapter.bandwidth))
+
+ try {
+ machine.run(object : SimWorkload {
+ override fun onStart(ctx: SimMachineContext) {
+ val lifecycle = SimWorkloadLifecycle(ctx)
+ val iface = ctx.net[0]
+ iface.tx.startConsumer(lifecycle.waitFor(SimWorkConsumer(iface.bandwidth, utilization = 0.8)))
+ }
+ })
+
+ assertEquals(1250, clock.millis())
+ } finally {
+ machine.close()
+ }
+ }
+
+ @Test
fun testCancellation() = runBlockingSimulation {
val machine = SimBareMetalMachine(
SimResourceInterpreter(coroutineContext, clock),