From 732766e552622f0f202bf32ec9621df499d4d8e9 Mon Sep 17 00:00:00 2001 From: AmyangXYZ Date: Tue, 30 Jan 2024 23:06:37 -0500 Subject: [PATCH] add data packet forwarding --- src/components/EventLogs.vue | 2 +- src/components/PacketSniffer.vue | 6 +- src/core/network.ts | 64 ++++-- src/core/node.ts | 3 +- src/core/node_end_system.ts | 43 ---- src/core/node_five_g_gnb.ts | 31 --- src/core/node_five_g_ue.ts | 30 --- src/core/node_tsch.ts | 31 --- src/core/node_tsn.ts | 31 --- src/core/nodes/end_system.ts | 72 +++++++ src/core/nodes/five_g_gnb.ts | 56 +++++ src/core/nodes/five_g_ue.ts | 55 +++++ src/core/nodes/tsch.ts | 56 +++++ src/core/nodes/tsn.ts | 59 +++++ src/core/typedefs.ts | 16 +- src/hooks/useDrawTopology.ts | 8 +- src/topologies/5G single-cell.json | 60 +++--- src/topologies/5G-TSN-TSCH.json | 333 +++++++++++------------------ src/topologies/6TiSCH tree.json | 38 ++-- src/topologies/Random.json | 6 +- src/topologies/Routing test.json | 25 +++ src/topologies/Scratch.json | 6 +- 22 files changed, 572 insertions(+), 459 deletions(-) delete mode 100644 src/core/node_end_system.ts delete mode 100644 src/core/node_five_g_gnb.ts delete mode 100644 src/core/node_five_g_ue.ts delete mode 100644 src/core/node_tsch.ts delete mode 100644 src/core/node_tsn.ts create mode 100644 src/core/nodes/end_system.ts create mode 100644 src/core/nodes/five_g_gnb.ts create mode 100644 src/core/nodes/five_g_ue.ts create mode 100644 src/core/nodes/tsch.ts create mode 100644 src/core/nodes/tsn.ts create mode 100644 src/topologies/Routing test.json diff --git a/src/components/EventLogs.vue b/src/components/EventLogs.vue index 6572683..a31bc75 100644 --- a/src/components/EventLogs.vue +++ b/src/components/EventLogs.vue @@ -31,7 +31,7 @@ const resetTimer = () => { Network.Logs.value = [] }) showLog.value = false - }, 5000) + }, 8000) } onUnmounted(() => { diff --git a/src/components/PacketSniffer.vue b/src/components/PacketSniffer.vue index fbb8222..3f41b03 100644 --- a/src/components/PacketSniffer.vue +++ b/src/components/PacketSniffer.vue @@ -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] }, @@ -80,7 +80,7 @@ const columns: any = [ key: 'len', title: 'LEN', dataKey: 'len', - width: 40, + width: 60, align: 'center' } ] @@ -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" diff --git a/src/core/network.ts b/src/core/network.ts index 40a9c76..78075a2 100644 --- a/src/core/network.ts +++ b/src/core/network.ts @@ -13,7 +13,9 @@ import { LINK_TYPE, type InitMsgPayload, PROTOCOL_TYPE, - type RoutingGraph + type RoutingGraph, + type RoutingMsgPayload, + type FlowMsgPayload } from './typedefs' import { SeededRandom } from '@/utils/rand' @@ -37,6 +39,7 @@ export class NetworkHub { PresetTopos: { [name: string]: any } = {} SelectedTopo = ref('5G-TSN-TSCH') // realistic topo example + // SelectedTopo = ref('Routing test') // realistic topo example asnTimer: any SignalReset = ref(0) @@ -134,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++ @@ -197,7 +200,8 @@ export class NetworkHub { this.Nodes.value.push({ id: n.id, type: n.type, - pos: n.pos + pos: n.pos, + neighbors: [] }) } } @@ -264,11 +268,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) + } }) } @@ -284,21 +291,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 @@ -310,6 +317,31 @@ export class NetworkHub { payload: { 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({ + 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({ + type: MSG_TYPE.FLOW, + id: n.id, + payload: { flows: flows } + }) + } + } + n.w.onmessage = (e: any) => { if ('uid' in e.data) { this.handlePkt(e.data) @@ -360,7 +392,7 @@ export class NetworkHub { } } - constructRoutingGraph() { + ConstructRoutingGraph() { const graph: RoutingGraph = {} for (const link of Object.values(this.Links.value)) { @@ -448,9 +480,9 @@ 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) diff --git a/src/core/node.ts b/src/core/node.ts index c7e9bab..e2b6ac5 100644 --- a/src/core/node.ts +++ b/src/core/node.ts @@ -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 } = {} diff --git a/src/core/node_end_system.ts b/src/core/node_end_system.ts deleted file mode 100644 index 9710d4c..0000000 --- a/src/core/node_end_system.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Node } from './node' -import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs' - -class EndSystem extends Node { - constructor() { - super() - this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) - this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) - this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) - } - initMsgHandler = (msg: Message) => { - const payload: InitMsgPayload = msg.payload - this.id = payload.id - this.neighbors = payload.neighbors - } - asnMsgHandler = (msg: Message) => { - const payload: ASNMsgPayload = msg.payload - this.ASN = payload.asn - - // do something - if (this.ASN % 3 == this.id % 3) { - postMessage({ - uid: Math.floor(Math.random() * 0xffff), - type: PKT_TYPE.DATA, - asn: this.ASN, - e2e_src: this.id, - mac_src: this.id, - mac_dst: this.neighbors[0], - len: 'biubiubiu'.length, - payload: 'biubiubiu' - }) - } - - postMessage({ - type: MSG_TYPE.DONE - }) - } - dataPktHandler = (pkt: Packet) => { - // console.log('tsn', pkt) - } -} - -new EndSystem().Run() diff --git a/src/core/node_five_g_gnb.ts b/src/core/node_five_g_gnb.ts deleted file mode 100644 index ae5ec6f..0000000 --- a/src/core/node_five_g_gnb.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Node } from './node' -import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs' - -class FiveGBS extends Node { - constructor() { - super() - this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) - this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) - this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) - } - initMsgHandler = (msg: Message) => { - const payload: InitMsgPayload = msg.payload - this.id = payload.id - this.neighbors = payload.neighbors - } - asnMsgHandler = (msg: Message) => { - const payload: ASNMsgPayload = msg.payload - this.ASN = payload.asn - - // do something - - postMessage({ - type: MSG_TYPE.DONE - }) - } - dataPktHandler = (pkt: Packet) => { - // console.log('tsn', pkt) - } -} - -new FiveGBS().Run() diff --git a/src/core/node_five_g_ue.ts b/src/core/node_five_g_ue.ts deleted file mode 100644 index f5fd441..0000000 --- a/src/core/node_five_g_ue.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Node } from './node' -import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs' - -class FiveGUE extends Node { - constructor() { - super() - this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) - this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) - this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) - } - initMsgHandler = (msg: Message) => { - const payload: InitMsgPayload = msg.payload - this.id = payload.id - this.neighbors = payload.neighbors - } - asnMsgHandler = (msg: Message) => { - const payload: ASNMsgPayload = msg.payload - this.ASN = payload.asn - - // do something - - postMessage({ - type: MSG_TYPE.DONE - }) - } - dataPktHandler = (pkt: Packet) => { - // console.log('tsn', pkt) - } -} -new FiveGUE().Run() diff --git a/src/core/node_tsch.ts b/src/core/node_tsch.ts deleted file mode 100644 index b978f37..0000000 --- a/src/core/node_tsch.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Node } from './node' -import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs' - -class TSCHNode extends Node { - constructor() { - super() - this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) - this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) - this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) - } - asnMsgHandler = (msg: Message) => { - const payload: ASNMsgPayload = msg.payload - this.ASN = payload.asn - - // do something - - postMessage({ - type: MSG_TYPE.DONE - }) - } - initMsgHandler = (msg: Message) => { - const payload: InitMsgPayload = msg.payload - this.id = payload.id - this.neighbors = payload.neighbors - } - dataPktHandler = (pkt: Packet) => { - // console.log(this.id, 'tsch', pkt) - } -} - -new TSCHNode().Run() diff --git a/src/core/node_tsn.ts b/src/core/node_tsn.ts deleted file mode 100644 index 88d7012..0000000 --- a/src/core/node_tsn.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Node } from './node' -import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs' - -class TSNNode extends Node { - constructor() { - super() - this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) - this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) - this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) - } - initMsgHandler = (msg: Message) => { - const payload: InitMsgPayload = msg.payload - this.id = payload.id - this.neighbors = payload.neighbors - } - asnMsgHandler = (msg: Message) => { - const payload: ASNMsgPayload = msg.payload - this.ASN = payload.asn - - // do something - - postMessage({ - type: MSG_TYPE.DONE - }) - } - dataPktHandler = (pkt: Packet) => { - // console.log('tsn', pkt) - } -} - -new TSNNode().Run() diff --git a/src/core/nodes/end_system.ts b/src/core/nodes/end_system.ts new file mode 100644 index 0000000..30509dc --- /dev/null +++ b/src/core/nodes/end_system.ts @@ -0,0 +1,72 @@ +import { Node } from '../node' +import { + PKT_TYPE, + type Message, + type Packet, + MSG_TYPE, + type ASNMsgPayload, + type InitMsgPayload, + type FlowMsgPayload, + type Flow, + type RoutingMsgPayload +} from '../typedefs' + +class EndSystem extends Node { + flows: Flow[] = [] + constructor() { + super() + this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) + this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) + this.registerMsgHandler(MSG_TYPE.FLOW, this.flowMsgHandler) + this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler) + + this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) + } + initMsgHandler = (msg: Message) => { + const payload: InitMsgPayload = msg.payload + this.id = payload.id + this.neighbors = payload.neighbors + } + asnMsgHandler = (msg: Message) => { + const payload: ASNMsgPayload = msg.payload + this.ASN = payload.asn + + // do something + for (const flow of this.flows) { + if (this.ASN % flow.period == 1) { + this.queue.push({ + uid: Math.floor(Math.random() * 0xffff), + type: PKT_TYPE.DATA, + e2e_src: this.id, + e2e_dst: flow.e2e_dst, + mac_src: this.id, + mac_dst: this.routingTable[flow.e2e_dst], + len: flow.workload, + payload: 'biubiubiu' + }) + } + } + + if (this.queue.length > 0) { + const pkt = this.queue.pop() + postMessage(pkt) + } + + postMessage({ + type: MSG_TYPE.DONE + }) + } + flowMsgHandler = (msg: Message) => { + const payload: FlowMsgPayload = msg.payload + this.flows = payload.flows + } + routingMsgHandler = (msg: Message) => { + const payload: RoutingMsgPayload = msg.payload + this.routingTable = payload + } + dataPktHandler = (pkt: Packet) => { + console.log('received', pkt) + } +} + +new EndSystem().Run() diff --git a/src/core/nodes/five_g_gnb.ts b/src/core/nodes/five_g_gnb.ts new file mode 100644 index 0000000..e34d315 --- /dev/null +++ b/src/core/nodes/five_g_gnb.ts @@ -0,0 +1,56 @@ +import { Node } from '../node' +import { + PKT_TYPE, + type Message, + type Packet, + MSG_TYPE, + type ASNMsgPayload, + type InitMsgPayload, + type RoutingMsgPayload +} from '../typedefs' + +class FiveGBS extends Node { + constructor() { + super() + this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) + this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) + this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler) + this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) + } + initMsgHandler = (msg: Message) => { + const payload: InitMsgPayload = msg.payload + this.id = payload.id + this.neighbors = payload.neighbors + } + asnMsgHandler = (msg: Message) => { + const payload: ASNMsgPayload = msg.payload + this.ASN = payload.asn + + // do something + if (this.queue.length > 0) { + const pkt = this.queue.pop() + postMessage(pkt) + } + + postMessage({ + type: MSG_TYPE.DONE + }) + } + routingMsgHandler = (msg: Message) => { + const payload: RoutingMsgPayload = msg.payload + this.routingTable = payload + } + dataPktHandler = (pkt: Packet) => { + if (pkt.e2e_dst != this.id) { + if (this.routingTable[pkt.e2e_dst] != undefined) { + pkt.mac_src = this.id + pkt.mac_dst = this.routingTable[pkt.e2e_dst] + this.queue.push(pkt) + } else { + console.log(`[v${this.id}] cannot find next hop for dst ${pkt.e2e_dst}}`) + } + } + } +} + +new FiveGBS().Run() diff --git a/src/core/nodes/five_g_ue.ts b/src/core/nodes/five_g_ue.ts new file mode 100644 index 0000000..b320acf --- /dev/null +++ b/src/core/nodes/five_g_ue.ts @@ -0,0 +1,55 @@ +import { Node } from '../node' +import { + PKT_TYPE, + type Message, + type Packet, + MSG_TYPE, + type ASNMsgPayload, + type InitMsgPayload, + type RoutingMsgPayload +} from '../typedefs' + +class FiveGUE extends Node { + constructor() { + super() + this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) + this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) + this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler) + this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) + } + initMsgHandler = (msg: Message) => { + const payload: InitMsgPayload = msg.payload + this.id = payload.id + this.neighbors = payload.neighbors + } + asnMsgHandler = (msg: Message) => { + const payload: ASNMsgPayload = msg.payload + this.ASN = payload.asn + + // do something + if (this.queue.length > 0) { + const pkt = this.queue.pop() + postMessage(pkt) + } + + postMessage({ + type: MSG_TYPE.DONE + }) + } + routingMsgHandler = (msg: Message) => { + const payload: RoutingMsgPayload = msg.payload + this.routingTable = payload + } + dataPktHandler = (pkt: Packet) => { + if (pkt.e2e_dst != this.id) { + if (this.routingTable[pkt.e2e_dst] != undefined) { + pkt.mac_src = this.id + pkt.mac_dst = this.routingTable[pkt.e2e_dst] + this.queue.push(pkt) + } else { + console.log(`[v${this.id}] cannot find next hop for dst ${pkt.e2e_dst}}`) + } + } + } +} +new FiveGUE().Run() diff --git a/src/core/nodes/tsch.ts b/src/core/nodes/tsch.ts new file mode 100644 index 0000000..70f8e52 --- /dev/null +++ b/src/core/nodes/tsch.ts @@ -0,0 +1,56 @@ +import { Node } from '../node' +import { + PKT_TYPE, + type Message, + type Packet, + MSG_TYPE, + type ASNMsgPayload, + type InitMsgPayload, + type RoutingMsgPayload +} from '../typedefs' + +class TSCHNode extends Node { + constructor() { + super() + this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) + this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) + this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler) + this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) + } + asnMsgHandler = (msg: Message) => { + const payload: ASNMsgPayload = msg.payload + this.ASN = payload.asn + + // do something + if (this.queue.length > 0) { + const pkt = this.queue.pop() + postMessage(pkt) + } + + postMessage({ + type: MSG_TYPE.DONE + }) + } + initMsgHandler = (msg: Message) => { + const payload: InitMsgPayload = msg.payload + this.id = payload.id + this.neighbors = payload.neighbors + } + routingMsgHandler = (msg: Message) => { + const payload: RoutingMsgPayload = msg.payload + this.routingTable = payload + } + dataPktHandler = (pkt: Packet) => { + if (pkt.e2e_dst != this.id) { + if (this.routingTable[pkt.e2e_dst] != undefined) { + pkt.mac_src = this.id + pkt.mac_dst = this.routingTable[pkt.e2e_dst] + this.queue.push(pkt) + } else { + console.log(`[v${this.id}] cannot find next hop for dst ${pkt.e2e_dst}}`) + } + } + } +} + +new TSCHNode().Run() diff --git a/src/core/nodes/tsn.ts b/src/core/nodes/tsn.ts new file mode 100644 index 0000000..5bdd108 --- /dev/null +++ b/src/core/nodes/tsn.ts @@ -0,0 +1,59 @@ +import { Node } from '../node' +import { + PKT_TYPE, + type Message, + type Packet, + MSG_TYPE, + type ASNMsgPayload, + type InitMsgPayload, + type RoutingMsgPayload +} from '../typedefs' + +class TSNNode extends Node { + constructor() { + super() + this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler) + this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler) + this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler) + this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler) + } + initMsgHandler = (msg: Message) => { + const payload: InitMsgPayload = msg.payload + this.id = payload.id + + this.neighbors = payload.neighbors + } + asnMsgHandler = (msg: Message) => { + const payload: ASNMsgPayload = msg.payload + this.ASN = payload.asn + + // do something + if (this.queue.length > 0) { + const pkt = this.queue.pop() + postMessage(pkt) + } + + postMessage({ + type: MSG_TYPE.DONE + }) + } + routingMsgHandler = (msg: Message) => { + const payload: RoutingMsgPayload = msg.payload + this.routingTable = payload + } + + dataPktHandler = (pkt: Packet) => { + if (pkt.e2e_dst != this.id) { + console.log(pkt.e2e_dst) + if (this.routingTable[pkt.e2e_dst] != undefined) { + pkt.mac_src = this.id + pkt.mac_dst = this.routingTable[pkt.e2e_dst] + this.queue.push(pkt) + } else { + console.log(`[v${this.id}] cannot find next hop for dst ${pkt.e2e_dst}}`) + } + } + } +} + +new TSNNode().Run() diff --git a/src/core/typedefs.ts b/src/core/typedefs.ts index 758cc03..96f0c43 100644 --- a/src/core/typedefs.ts +++ b/src/core/typedefs.ts @@ -111,21 +111,31 @@ export enum MSG_TYPE { INIT, ASN, DONE, // finished all activities of the current slot + ROUTING, FLOW, // install periodic flow STAT } -export type MsgHandler = (msg: Message) => void -export type PktHandler = (pkt: Packet) => void - export interface InitMsgPayload { id: number neighbors: number[] } + export interface ASNMsgPayload { asn: number } +export interface RoutingMsgPayload { + [dst: number]: number +} + +export interface FlowMsgPayload { + flows: Flow[] +} + +export type MsgHandler = (msg: Message) => void +export type PktHandler = (pkt: Packet) => void + export interface RoutingGraph { [id: number]: number[] } diff --git a/src/hooks/useDrawTopology.ts b/src/hooks/useDrawTopology.ts index 16d42a3..429f82c 100644 --- a/src/hooks/useDrawTopology.ts +++ b/src/hooks/useDrawTopology.ts @@ -371,7 +371,7 @@ export async function useDrawTopology(dom: HTMLElement) { ) { linkType = LINK_TYPE.WIRED } - const hMid = linkType == LINK_TYPE.WIRED ? 5 : (srcSize.y + dstSize.y) / 2 + const hMid = linkType == LINK_TYPE.WIRED ? 5 : (srcSize.y + dstSize.y) / 2 + 4 const hEndSrc = linkType == LINK_TYPE.WIRED ? 1.6 : srcSize.y * 0.7 const hEndDst = linkType == LINK_TYPE.WIRED ? 1.6 : dstSize.y * 0.7 @@ -586,10 +586,10 @@ export async function useDrawTopology(dom: HTMLElement) { drawNodes() createDragControls() Network.EstablishConnection() - Network.StartWebWorkers() drawLinks() - Network.constructRoutingGraph() - Network.AddFlows(10) // specify number of flows + Network.ConstructRoutingGraph() + Network.AddFlows(3) // specify number of flows + Network.StartWebWorkers() // ################### diff --git a/src/topologies/5G single-cell.json b/src/topologies/5G single-cell.json index 94c4bb6..dcf1c31 100644 --- a/src/topologies/5G single-cell.json +++ b/src/topologies/5G single-cell.json @@ -1,37 +1,25 @@ { - "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": [] -} \ No newline at end of file + "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": [] +} diff --git a/src/topologies/5G-TSN-TSCH.json b/src/topologies/5G-TSN-TSCH.json index 3068fb5..f831f7f 100644 --- a/src/topologies/5G-TSN-TSCH.json +++ b/src/topologies/5G-TSN-TSCH.json @@ -1,205 +1,130 @@ { - "nodes": [ - { - "id": 1, - "type": 1, - "pos": [ - -10, - -10 - ] - }, - { - "id": 2, - "type": 1, - "pos": [ - 10, - -10 - ] - }, - { - "id": 3, - "type": 1, - "pos": [ - 10, - 10 - ] - }, - { - "id": 4, - "type": 1, - "pos": [ - -10, - 10 - ] - }, - { - "id": 5, - "type": 1, - "pos": [ - -25, - -20 - ] - }, - { - "id": 6, - "type": 1, - "pos": [ - 25, - -20 - ] - }, - { - "id": 7, - "type": 1, - "pos": [ - 25, - 20 - ] - }, - { - "id": 8, - "type": 2, - "pos": [ - -25, - 20 - ] - }, - { - "id": 9, - "type": 1, - "pos": [ - -40, - -10 - ] - }, - { - "id": 10, - "type": 1, - "pos": [ - 40, - -10 - ] - }, - { - "id": 11, - "type": 1, - "pos": [ - -40, - 10 - ] - }, - { - "id": 12, - "type": 1, - "pos": [ - 40, - 10 - ] - }, - { - "id": 13, - "type": 16, - "pos": [ - -40, - -20 - ] - }, - { - "id": 14, - "type": 16, - "pos": [ - 40, - 20 - ] - }, - { - "id": 15, - "type": 15, - "pos": [ - -20, - 40 - ] - }, - { - "id": 16, - "type": 17, - "pos": [ - 45, - -20 - ] - }, - { - "id": 17, - "type": 16, - "pos": [ - -30, - 40 - ] - }, - { - "id": 18, - "type": 0, - "pos": [ - 20, - -40 - ] - }, - { - "id": 19, - "type": 11, - "pos": [ - 25, - 30 - ] - }, - { - "id": 20, - "type": 11, - "pos": [ - -25, - -30 - ] - }, - { - "id": 21, - "type": 11, - "pos": [ - -40, - 20 - ] - }, - { - "id": 22, - "type": 3, - "pos": [ - -20, - 30 - ] - }, - { - "id": 23, - "type": 3, - "pos": [ - -30, - 30 - ] - }, - { - "id": 24, - "type": 0, - "pos": [ - 15, - -30 - ] - }, - { - "id": 25, - "type": 0, - "pos": [ - 30, - -30 - ] - } - ], - "links": [] -} \ No newline at end of file + "nodes": [ + { + "id": 1, + "type": 1, + "pos": [-10, -10] + }, + { + "id": 2, + "type": 1, + "pos": [10, -10] + }, + { + "id": 3, + "type": 1, + "pos": [10, 10] + }, + { + "id": 4, + "type": 1, + "pos": [-10, 10] + }, + { + "id": 5, + "type": 1, + "pos": [-25, -20] + }, + { + "id": 6, + "type": 1, + "pos": [25, -20] + }, + { + "id": 7, + "type": 1, + "pos": [25, 20] + }, + { + "id": 8, + "type": 2, + "pos": [-25, 20] + }, + { + "id": 9, + "type": 1, + "pos": [-40, -10] + }, + { + "id": 10, + "type": 1, + "pos": [40, -10] + }, + { + "id": 11, + "type": 1, + "pos": [-40, 10] + }, + { + "id": 12, + "type": 1, + "pos": [40, 10] + }, + { + "id": 13, + "type": 16, + "pos": [-40, -20] + }, + { + "id": 14, + "type": 16, + "pos": [40, 20] + }, + { + "id": 15, + "type": 15, + "pos": [-20, 40] + }, + { + "id": 16, + "type": 17, + "pos": [45, -20] + }, + { + "id": 17, + "type": 16, + "pos": [-30, 40] + }, + { + "id": 18, + "type": 0, + "pos": [20, -40] + }, + { + "id": 19, + "type": 11, + "pos": [25, 30] + }, + { + "id": 20, + "type": 11, + "pos": [-25, -30] + }, + { + "id": 21, + "type": 11, + "pos": [-40, 20] + }, + { + "id": 22, + "type": 3, + "pos": [-20, 30] + }, + { + "id": 23, + "type": 3, + "pos": [-30, 30] + }, + { + "id": 24, + "type": 0, + "pos": [15, -30] + }, + { + "id": 25, + "type": 0, + "pos": [30, -30] + } + ], + "links": [] +} diff --git a/src/topologies/6TiSCH tree.json b/src/topologies/6TiSCH tree.json index aa09d43..337dd8c 100644 --- a/src/topologies/6TiSCH tree.json +++ b/src/topologies/6TiSCH tree.json @@ -1,20 +1,20 @@ { - "nodes": [ - { - "id": 1, - "type": 0, - "pos": [0, 0] - }, - { - "id": 2, - "type": 0, - "pos": [10, 10] - }, - { - "id": 3, - "type": 0, - "pos": [-10, 10] - } - ], - "links":[] - } \ No newline at end of file + "nodes": [ + { + "id": 1, + "type": 0, + "pos": [0, 0] + }, + { + "id": 2, + "type": 0, + "pos": [10, 10] + }, + { + "id": 3, + "type": 0, + "pos": [-10, 10] + } + ], + "links": [] +} diff --git a/src/topologies/Random.json b/src/topologies/Random.json index 8c8e692..9b90ea2 100644 --- a/src/topologies/Random.json +++ b/src/topologies/Random.json @@ -1,4 +1,4 @@ { - "nodes": [], - "links": [] -} \ No newline at end of file + "nodes": [], + "links": [] +} diff --git a/src/topologies/Routing test.json b/src/topologies/Routing test.json new file mode 100644 index 0000000..cce02c4 --- /dev/null +++ b/src/topologies/Routing test.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "id": 1, + "type": 1, + "pos": [-10, 0] + }, + { + "id": 2, + "type": 1, + "pos": [10, 0] + }, + { + "id": 3, + "type": 11, + "pos": [-20, 0] + }, + { + "id": 4, + "type": 11, + "pos": [20, 0] + } + ], + "links": [] +} diff --git a/src/topologies/Scratch.json b/src/topologies/Scratch.json index 8c8e692..9b90ea2 100644 --- a/src/topologies/Scratch.json +++ b/src/topologies/Scratch.json @@ -1,4 +1,4 @@ { - "nodes": [], - "links": [] -} \ No newline at end of file + "nodes": [], + "links": [] +}