Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/AmyangXYZ/VeRNet into jem/f…
Browse files Browse the repository at this point in the history
…eatures
  • Loading branch information
jmedrek1 committed Jan 31, 2024
2 parents 202158d + 68db740 commit 98bd857
Show file tree
Hide file tree
Showing 23 changed files with 592 additions and 382 deletions.
2 changes: 1 addition & 1 deletion src/components/EventLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const resetTimer = () => {
Network.Logs.value = []
})
showLog.value = false
}, 5000)
}, 8000)
}
onUnmounted(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/PacketSniffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const columns: any = [
key: 'type',
title: 'TYPE',
dataKey: 'type',
width: 60,
width: 50,
align: 'center',
cellRenderer: ({ cellData: type }: any) => PKT_TYPE[type]
},
Expand All @@ -80,7 +80,7 @@ const columns: any = [
key: 'len',
title: 'LEN',
dataKey: 'len',
width: 40,
width: 60,
align: 'center'
}
]
Expand Down Expand Up @@ -124,7 +124,7 @@ Row.inheritAttrs = false
class="table"
:columns="columns"
:data="Network.Packets.value.filter(filterFunc)"
:width="360"
:width="370"
:height="370"
:expand-column-key="columns[7].key"
:estimated-row-height="16"
Expand Down
88 changes: 64 additions & 24 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
LINK_TYPE,
type InitMsgPayload,
PROTOCOL_TYPE,
type RoutingGraph
type RoutingGraph,
type RoutingMsgPayload,
type FlowMsgPayload
} 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,8 +37,9 @@ 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
// SelectedTopo = ref('Routing test') // realistic topo example

asnTimer: any
SignalReset = ref(0)
Expand All @@ -56,6 +57,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 @@ -126,7 +137,7 @@ export class NetworkHub {
default:
isValid = true
}

pkt.asn = this.ASN.value
if (isValid) {
this.Nodes.value[pkt.mac_src].tx_cnt++
this.Nodes.value[pkt.mac_dst].rx_cnt++
Expand Down Expand Up @@ -189,7 +200,10 @@ export class NetworkHub {
this.Nodes.value.push(<Node>{
id: n.id,
type: n.type,
pos: n.pos
pos: n.pos,
tx_cnt: 0,
rx_cnt: 0,
neighbors: <number[]>[]
})
}
}
Expand Down Expand Up @@ -256,11 +270,14 @@ export class NetworkHub {
break
}
}

n.neighbors = neighbors

n.neighbors.forEach((nn: number) => {
neighbors.forEach((nn: number) => {
this.AddLink(n.id, nn)
if (n.neighbors.indexOf(nn) == -1) {
n.neighbors.push(nn)
}
if (this.Nodes.value[nn].neighbors.indexOf(n.id) == -1) {
this.Nodes.value[nn].neighbors.push(n.id)
}
})
}

Expand Down Expand Up @@ -293,21 +310,21 @@ export class NetworkHub {

switch (n.type) {
case NODE_TYPE.TSCH:
n.w = new Worker(new URL('@/core/node_tsch.ts', import.meta.url), { type: 'module' })
n.w = new Worker(new URL('@/core/nodes/tsch.ts', import.meta.url), { type: 'module' })
break
case NODE_TYPE.TSN:
n.w = new Worker(new URL('@/core/node_tsn.ts', import.meta.url), { type: 'module' })
n.w = new Worker(new URL('@/core/nodes/tsn.ts', import.meta.url), { type: 'module' })
break
case NODE_TYPE.FIVE_G_GNB:
n.w = new Worker(new URL('@/core/node_five_g_gnb.ts', import.meta.url), {
n.w = new Worker(new URL('@/core/nodes/five_g_gnb.ts', import.meta.url), {
type: 'module'
})
break
case NODE_TYPE.FIVE_G_UE:
n.w = new Worker(new URL('@/core/node_five_g_ue.ts', import.meta.url), { type: 'module' })
n.w = new Worker(new URL('@/core/nodes/five_g_ue.ts', import.meta.url), { type: 'module' })
break
default:
n.w = new Worker(new URL('@/core/node_end_system.ts', import.meta.url), {
n.w = new Worker(new URL('@/core/nodes/end_system.ts', import.meta.url), {
type: 'module'
})
break
Expand All @@ -319,6 +336,31 @@ export class NetworkHub {
payload: <InitMsgPayload>{ id: n.id, neighbors: toRaw(n.neighbors) }
})

const routingTable: RoutingMsgPayload = {}
const endSystems: Node[] = this.Nodes.value.filter((n) => n.type >= 11)
for (const s of endSystems) {
const path = this.findPath(n.id, s.id)
if (path.length > 1) {
routingTable[s.id] = path[1]
}
}
n.w.postMessage(<Message>{
type: MSG_TYPE.ROUTING,
id: n.id,
payload: toRaw(routingTable)
})

if (n.type >= 11) {
const flows = toRaw(this.Flows.value).filter((f: Flow) => f.e2e_src == n.id)
if (flows.length > 0) {
n.w.postMessage(<Message>{
type: MSG_TYPE.FLOW,
id: n.id,
payload: <FlowMsgPayload>{ flows: flows }
})
}
}

n.w.onmessage = (e: any) => {
if ('uid' in e.data) {
this.handlePkt(e.data)
Expand Down Expand Up @@ -369,7 +411,7 @@ export class NetworkHub {
}
}

constructRoutingGraph() {
ConstructRoutingGraph() {
const graph: RoutingGraph = {}

for (const link of Object.values(this.Links.value)) {
Expand Down Expand Up @@ -443,12 +485,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 @@ -458,15 +499,14 @@ export class NetworkHub {
id: this.Flows.value.length,
e2e_src: src.id,
e2e_dst: dst.id,
period: Math.floor(this.Rand.next() * 10), // from 0 to 9 - change this later
deadline: Math.floor(this.Rand.next() * 10), // from 0 to 9 - change this later
workload: Math.floor(this.Rand.next() * 10), // from 0 to 9 - change this later
period: Math.floor(this.Rand.next() * 4 + 1) * 5, // from 5 to 10 - change this later
deadline: Math.floor(this.Rand.next() * 4 + 1) * 5, // from 5 to 10 - change this later
workload: Math.floor(this.Rand.next() * 10) + 1, // from 1 to 10 - change this later
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
3 changes: 2 additions & 1 deletion src/core/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export class Node {
pkt_seq: number = 0
tx_cnt: number = 0
rx_cnt: number = 0
queue: Packet[] = []
ASN: number = 0

routingTable: { [dst: number]: number } = {}
msgHandlers: { [type: number]: MsgHandler } = {}
pktHandlers: { [type: number]: PktHandler } = {}

Expand Down
43 changes: 0 additions & 43 deletions src/core/node_end_system.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/core/node_five_g_gnb.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/core/node_five_g_ue.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/core/node_tsch.ts

This file was deleted.

Loading

0 comments on commit 98bd857

Please sign in to comment.