Skip to content

Commit

Permalink
split preset topologies into different files
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Jan 31, 2024
1 parent 29d6042 commit e95cd6c
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 188 deletions.
22 changes: 14 additions & 8 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
} from './typedefs'
import { SeededRandom } from '@/utils/rand'

import presetTopos from './preset_topologies.json'

export class NetworkHub {
Config: Ref<Config>
Nodes: Ref<Node[]>
Expand All @@ -37,7 +35,7 @@ export class NetworkHub {
kdTreeTSN: KDTree // TSN only
kdTreeFiveGgNB: KDTree // 5G gNB only

PresetTopos: { [name: string]: any } = presetTopos
PresetTopos: { [name: string]: any } = {}
SelectedTopo = ref('5G-TSN-TSCH') // realistic topo example

asnTimer: any
Expand All @@ -56,6 +54,16 @@ export class NetworkHub {
this.kdTreeTSN = new KDTree()
this.kdTreeFiveGgNB = new KDTree()

// load preset topologies
const topos = import.meta.glob('@/topologies/*.json')
for (const path in topos) {
const name = path.split('/')[3].replace('.json', '')
this.PresetTopos[name] = {} // placeholder before fully load json files
topos[path]().then((f: any) => {
this.PresetTopos[name] = f.default
})
}

watch(this.SelectedTopo, () => {
this.LoadTopology()
})
Expand Down Expand Up @@ -426,12 +434,11 @@ export class NetworkHub {
}

AddFlows(num_flows: number) {

const endSystems = this.Nodes.value.filter(n => n.type >= 11)
const endSystems = this.Nodes.value.filter((n) => n.type >= 11)

for (let i = 0; i < num_flows; i++) {
const src = endSystems[Math.floor(this.Rand.next() * endSystems.length)]

let dst = src
while (dst.id === src.id) {
dst = endSystems[Math.floor(this.Rand.next() * endSystems.length)]
Expand All @@ -447,9 +454,8 @@ export class NetworkHub {
path: this.findPath(src.id, dst.id)
}
this.Flows.value.push(f)

this.Logs.value.unshift(`New flow: ID:${f.id}, source:${f.e2e_src}, dest:${f.e2e_dst}.`)
}
this.Logs.value.unshift(`Generated ${this.Flows.value.length} flows.`)
}

Run = () => {
Expand Down
180 changes: 0 additions & 180 deletions src/core/preset_topologies.json

This file was deleted.

37 changes: 37 additions & 0 deletions src/topologies/5G single-cell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"nodes": [
{
"id": 1,
"type": 2,
"pos": [
0,
0
]
},
{
"id": 2,
"type": 3,
"pos": [
-20,
0
]
},
{
"id": 3,
"type": 3,
"pos": [
20,
0
]
},
{
"id": 4,
"type": 3,
"pos": [
0,
20
]
}
],
"links": []
}
Loading

0 comments on commit e95cd6c

Please sign in to comment.