summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-topology/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute/opendc-compute-topology/src')
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt98
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt4
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/HostSpec.kt6
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt3
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt15
5 files changed, 64 insertions, 62 deletions
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
index 721119cd..a857f496 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
@@ -37,76 +37,99 @@ import org.opendc.simulator.compute.models.MachineModel
import org.opendc.simulator.compute.models.MemoryUnit
import java.io.File
import java.io.InputStream
-import java.util.SplittableRandom
-import java.util.UUID
-import java.util.random.RandomGenerator
/**
* A [TopologyReader] that is used to read the cluster definition file.
*/
private val reader = TopologyReader()
+// Lists used to make sure all cluster, host, power source and battery have unique names
+private val clusterNames: ArrayList<String> = ArrayList()
+private val hostNames: ArrayList<String> = ArrayList()
+private val powerSourceNames: ArrayList<String> = ArrayList()
+private val batteryNames: ArrayList<String> = ArrayList()
+
+/**
+ * Create a unique name for the specified [name] that is not already in the [names] list.
+ *
+ * If [name] is already in [names], "-$i" is appended to the name until a unique name is found.
+ * In which "$i" is an increasing integer starting from 0.
+ */
+private fun createUniqueName(
+ name: String,
+ names: ArrayList<String>,
+): String {
+ if (name !in names) {
+ names.add(name)
+ return name
+ }
+
+ var i = 0
+ var newName = "$name-$i"
+ while (newName in names) {
+ newName = "$name-${++i}"
+ }
+
+ names.add(newName)
+ return newName
+}
+
/**
* Construct a topology from the specified [pathToFile].
*/
-public fun clusterTopology(
- pathToFile: String,
- random: RandomGenerator = SplittableRandom(0),
-): List<ClusterSpec> {
- return clusterTopology(File(pathToFile), random)
+public fun clusterTopology(pathToFile: String): List<ClusterSpec> {
+ return clusterTopology(File(pathToFile))
}
/**
* Construct a topology from the specified [file].
*/
-public fun clusterTopology(
- file: File,
- random: RandomGenerator = SplittableRandom(0),
-): List<ClusterSpec> {
+public fun clusterTopology(file: File): List<ClusterSpec> {
val topology = reader.read(file)
- return topology.toClusterSpec(random)
+ return topology.toClusterSpec()
}
/**
* Construct a topology from the specified [input].
*/
-public fun clusterTopology(
- input: InputStream,
- random: RandomGenerator = SplittableRandom(0),
-): List<ClusterSpec> {
+public fun clusterTopology(input: InputStream): List<ClusterSpec> {
val topology = reader.read(input)
- return topology.toClusterSpec(random)
+ return topology.toClusterSpec()
}
/**
* Helper method to convert a [TopologySpec] into a list of [HostSpec]s.
*/
-private fun TopologySpec.toClusterSpec(random: RandomGenerator): List<ClusterSpec> {
+private fun TopologySpec.toClusterSpec(): List<ClusterSpec> {
+ clusterNames.clear()
+ hostNames.clear()
+ powerSourceNames.clear()
+ batteryNames.clear()
+
return clusters.map { cluster ->
- cluster.toClusterSpec(random)
+ cluster.toClusterSpec()
}
}
/**
* Helper method to convert a [ClusterJSONSpec] into a list of [HostSpec]s.
*/
-private var clusterId = 0
+private fun ClusterJSONSpec.toClusterSpec(): ClusterSpec {
+ val clusterName = createUniqueName(this.name, clusterNames)
-private fun ClusterJSONSpec.toClusterSpec(random: RandomGenerator): ClusterSpec {
val hostSpecs =
hosts.flatMap { host ->
(
List(host.count) {
host.toHostSpec(
- clusterId,
- random,
+ clusterName,
)
}
)
}
val powerSourceSpec =
PowerSourceSpec(
- UUID(random.nextLong(), (clusterId).toLong()),
+ createUniqueName(this.powerSource.name, powerSourceNames),
totalPower = this.powerSource.totalPower,
carbonTracePath = this.powerSource.carbonTracePath,
)
@@ -115,7 +138,7 @@ private fun ClusterJSONSpec.toClusterSpec(random: RandomGenerator): ClusterSpec
if (this.battery != null) {
batterySpec =
BatterySpec(
- UUID(random.nextLong(), clusterId.toLong()),
+ createUniqueName(this.battery.name, batteryNames),
this.battery.capacity,
this.battery.chargingSpeed,
this.battery.batteryPolicy,
@@ -123,20 +146,15 @@ private fun ClusterJSONSpec.toClusterSpec(random: RandomGenerator): ClusterSpec
)
}
- clusterId++
- return ClusterSpec(this.name, hostSpecs, powerSourceSpec, batterySpec)
+ return ClusterSpec(clusterName, hostSpecs, powerSourceSpec, batterySpec)
}
/**
* Helper method to convert a [HostJSONSpec] into a [HostSpec]s.
*/
-private var hostId = 0
private var globalCoreId = 0
-private fun HostJSONSpec.toHostSpec(
- clusterId: Int,
- random: RandomGenerator,
-): HostSpec {
+private fun HostJSONSpec.toHostSpec(clusterName: String): HostSpec {
val units =
List(cpu.count) {
CpuModel(
@@ -156,22 +174,12 @@ private fun HostJSONSpec.toHostSpec(
val powerModel =
getPowerModel(powerModel.modelType, powerModel.power.toWatts(), powerModel.maxPower.toWatts(), powerModel.idlePower.toWatts())
- var hostName: String
- if (name == null) {
- hostName = "Host-$hostId"
- } else {
- hostName = name
- }
-
val hostSpec =
HostSpec(
- UUID(random.nextLong(), (hostId).toLong()),
- hostName,
- mapOf("cluster" to clusterId),
+ createUniqueName(this.name, hostNames),
+ clusterName,
machineModel,
powerModel,
)
- hostId++
-
return hostSpec
}
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt
index fd849b01..79a23a9e 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/BatterySpec.kt
@@ -22,10 +22,8 @@
package org.opendc.compute.topology.specs
-import java.util.UUID
-
public data class BatterySpec(
- val uid: UUID,
+ val name: String,
val capacity: Double,
val chargingSpeed: Double,
val batteryPolicy: BatteryPolicyJSONSpec,
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/HostSpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/HostSpec.kt
index 0d0dd24d..0c614658 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/HostSpec.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/HostSpec.kt
@@ -24,21 +24,17 @@ package org.opendc.compute.topology.specs
import org.opendc.simulator.compute.cpu.CpuPowerModel
import org.opendc.simulator.compute.models.MachineModel
-import java.util.UUID
/**
* Description of a physical host that will be simulated by OpenDC and host the virtual machines.
*
- * @param uid Unique identifier of the host.
* @param name The name of the host.
- * @param meta The metadata of the host.
* @param model The physical model of the machine.
* @param cpuPowerModel The [cpuPowerModel] that determines the power draw based on cpu utilization
*/
public data class HostSpec(
- val uid: UUID,
val name: String,
- val meta: Map<String, Any>,
+ val clusterName: String,
val model: MachineModel,
val cpuPowerModel: CpuPowerModel,
)
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt
index 179e8f9e..9028965f 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt
@@ -22,11 +22,8 @@
package org.opendc.compute.topology.specs
-import java.util.UUID
-
// TODO: add name to class
public data class PowerSourceSpec(
- val uid: UUID,
val name: String = "unknown",
val meta: Map<String, Any> = emptyMap(),
val totalPower: Long = Long.MAX_VALUE,
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
index 3ccb4e59..0f7694c1 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
@@ -66,7 +66,7 @@ public data class ClusterJSONSpec(
*/
@Serializable
public data class HostJSONSpec(
- val name: String? = null,
+ val name: String = "Host",
val cpu: CPUJSONSpec,
val memory: MemoryJSONSpec,
val powerModel: PowerModelSpec = PowerModelSpec.DFLT,
@@ -143,6 +143,7 @@ public data class PowerModelSpec(
*/
@Serializable
public data class PowerSourceJSONSpec(
+ val name: String = "PowerSource",
val vendor: String = "unknown",
val modelName: String = "unknown",
val arch: String = "unknown",
@@ -158,15 +159,17 @@ public data class PowerSourceJSONSpec(
}
/**
- * Definition of a power source used for JSON input.
+ * Definition of a battery used for JSON input.
*
- * @property vendor
- * @property modelName
- * @property arch
- * @property totalPower
+ * @property name The name of the battery
+ * @property capacity The capacity of the battery in kWh
+ * @property chargingSpeed The charging speed of the battery in J
+ * @property batteryPolicy The policy used to decide when the battery charges and discharges
+ * @property initialCharge The initial charge in the battery
*/
@Serializable
public data class BatteryJSONSpec(
+ val name: String = "Battery",
var capacity: Double,
val chargingSpeed: Double,
val batteryPolicy: BatteryPolicyJSONSpec,