diff --git a/src/components/FlowsPanel.vue b/src/components/FlowsPanel.vue index b2b400a..41740c9 100644 --- a/src/components/FlowsPanel.vue +++ b/src/components/FlowsPanel.vue @@ -52,11 +52,11 @@ const columns: any = [ const tableRef = ref() watch( - Network.Packets, + Network.Flows, () => { - if (Network.Packets.value.length > 0) { + if (Network.Flows.value.length > 0) { nextTick(() => { - tableRef.value?.scrollToRow(Network.Packets.value.length) + tableRef.value?.scrollToRow(Network.Flows.value.length) }) } }, @@ -80,7 +80,7 @@ Row.inheritAttrs = false ref="tableRef" class="table" :columns="columns" - :data="Network.Packets.value" + :data="Network.Flows.value" :width="360" :height="180" :expand-column-key="columns[5].key" diff --git a/src/hooks/useDrawTopology.ts b/src/hooks/useDrawTopology.ts index 95633c0..0d02050 100644 --- a/src/hooks/useDrawTopology.ts +++ b/src/hooks/useDrawTopology.ts @@ -14,8 +14,7 @@ import { ADDR, type Packet, type LinkMeta, - LINK_TYPE, - END_SYSTEM_TYPE + LINK_TYPE } from '@/networks/common' export function useDrawTopology(dom: HTMLElement) { @@ -120,10 +119,10 @@ export function useDrawTopology(dom: HTMLElement) { const drawNodes = () => { switch (Network.Type) { case NETWORK_TYPE.TSCH: - drawTSCHNodes() + drawTSCHDevices() break case NETWORK_TYPE.TSN: - drawTSNNodes() + drawTSNDevices() break case NETWORK_TYPE.FIVE_G: drawFiveGBS() @@ -142,7 +141,7 @@ export function useDrawTopology(dom: HTMLElement) { } drawnNodes = {} } - const drawTSCHNodes = () => { + const drawTSCHDevices = () => { // GLTF Loader const loader = new GLTFLoader() loader.load('/models/wi-fi_router/scene.gltf', function (gltf: any) { @@ -195,7 +194,7 @@ export function useDrawTopology(dom: HTMLElement) { } }) } - const drawTSNNodes = () => { + const drawTSNDevices = () => { // GLTF Loader const loader = new GLTFLoader() loader.load('/models/wi-fi_router/scene.gltf', function (gltf: any) { @@ -375,26 +374,26 @@ export function useDrawTopology(dom: HTMLElement) { const size = new THREE.Vector3() box.getSize(size) - for (const es of Network.EndSystems.value) { + for (const es of Network.Nodes.value) { if (es.type !== typeVal) continue const model = modelTemplate.clone() model.position.set(es.pos[0], positionY, es.pos[1]) model.traverse((object: any) => { if (object.isMesh) { - object.userData.type = END_SYSTEM_TYPE[es.type] + object.userData.type = NODE_TYPE[es.type] object.userData.node_id = es.id } }) scene.add(model) - const label = createLabel(`${END_SYSTEM_TYPE[es.type]}-${es.id}`) + const label = createLabel(`${NODE_TYPE[es.type]}-${es.id}`) label.position.set(model.position.x, labelY, model.position.z) scene.add(label) const { dragBox, dragBoxHelper } = createDragBox(es, model) - drawnNodes[`${END_SYSTEM_TYPE[es.type]}-${es.id}`] = { + drawnNodes[`${NODE_TYPE[es.type]}-${es.id}`] = { model, label, modelGroup: model, @@ -405,16 +404,23 @@ export function useDrawTopology(dom: HTMLElement) { } // Load and place models - loadAndPlaceModel('/models/server/scene.gltf', [0.08, 0.08, 0.08], -Math.PI / 2, 1.9, 7, 0) + loadAndPlaceModel( + '/models/server/scene.gltf', + [0.08, 0.08, 0.08], + -Math.PI / 2, + 1.9, + 7, + NODE_TYPE.SERVER + ) loadAndPlaceModel( '/models/robotic_arm/scene.gltf', [0.004, 0.004, 0.004], -Math.PI / 2, 0, 7, - 1 + NODE_TYPE.ROBOT ) - loadAndPlaceModel('/models/sensor/scene.gltf', [2, 2, 2], -Math.PI / 2, 0, 5, 2) + loadAndPlaceModel('/models/sensor/scene.gltf', [2, 2, 2], -Math.PI / 2, 0, 5, NODE_TYPE.SENSOR) } const createDragBox = (node: any, model: any): any => { @@ -450,37 +456,18 @@ export function useDrawTopology(dom: HTMLElement) { } } const drawLink = (l: LinkMeta) => { - let p1: THREE.Vector3, p3: THREE.Vector3 - if (l.v1 <= Network.TopoConfig.value.num_nodes) { - p1 = new THREE.Vector3( - Network.Nodes.value[l.v1].pos[0], - 1.6, - Network.Nodes.value[l.v1].pos[1] - ) - } else { - // is an end system - p1 = new THREE.Vector3( - Network.EndSystems.value[l.v1 - Network.TopoConfig.value.num_nodes - 1].pos[0], - 1.6, - Network.EndSystems.value[l.v1 - Network.TopoConfig.value.num_nodes - 1].pos[1] - ) - } - - if (l.v2 <= Network.TopoConfig.value.num_nodes) { - p3 = new THREE.Vector3( - Network.Nodes.value[l.v2].pos[0], - 1.6, - Network.Nodes.value[l.v2].pos[1] - ) - } else { - // is an end system - p3 = new THREE.Vector3( - Network.EndSystems.value[l.v2 - Network.TopoConfig.value.num_nodes - 1].pos[0], - 1.6, - Network.EndSystems.value[l.v2 - Network.TopoConfig.value.num_nodes - 1].pos[1] - ) - } + const p1 = new THREE.Vector3( + Network.Nodes.value[l.v1].pos[0], + 1.6, + Network.Nodes.value[l.v1].pos[1] + ) + const p3 = new THREE.Vector3( + Network.Nodes.value[l.v2].pos[0], + 1.6, + Network.Nodes.value[l.v2].pos[1] + ) + const x2 = (p1.x + p3.x) / 2 const z2 = (p1.z + p3.z) / 2 const h = 5 @@ -532,7 +519,7 @@ export function useDrawTopology(dom: HTMLElement) { time = 0 // reset animation timer for (const pkt of Network.PacketsCurrent.value) { if (Network.Type == NETWORK_TYPE.TSCH && pkt.type == TSCH_PKT_TYPE.ACK) continue - if (pkt.dst != ADDR.BROADCAST) { + if (pkt.mac_dst != ADDR.BROADCAST) { drawUnicastPacket(pkt) } else if (Network.Type == NETWORK_TYPE.TSCH && pkt.type == TSCH_PKT_TYPE.BEACON) { drawBeaconPacket(pkt) @@ -572,37 +559,17 @@ export function useDrawTopology(dom: HTMLElement) { const mesh = new THREE.Points(geometry, material) scene.add(mesh) - let p1: THREE.Vector3, p3: THREE.Vector3 - - if (pkt.src <= Network.TopoConfig.value.num_nodes) { - p1 = new THREE.Vector3( - Network.Nodes.value[pkt.src].pos[0], - 1.6, - Network.Nodes.value[pkt.src].pos[1] - ) - } else { - // is an end system - p1 = new THREE.Vector3( - Network.EndSystems.value[pkt.src - Network.TopoConfig.value.num_nodes - 1].pos[0], - 1.6, - Network.EndSystems.value[pkt.src - Network.TopoConfig.value.num_nodes - 1].pos[1] - ) - } + const p1 = new THREE.Vector3( + Network.Nodes.value[pkt.mac_src].pos[0], + 1.6, + Network.Nodes.value[pkt.mac_src].pos[1] + ) - if (pkt.dst <= Network.TopoConfig.value.num_nodes) { - p3 = new THREE.Vector3( - Network.Nodes.value[pkt.dst].pos[0], - 1.6, - Network.Nodes.value[pkt.dst].pos[1] - ) - } else { - // is an end system - p3 = new THREE.Vector3( - Network.EndSystems.value[pkt.dst - Network.TopoConfig.value.num_nodes - 1].pos[0], - 1.6, - Network.EndSystems.value[pkt.dst - Network.TopoConfig.value.num_nodes - 1].pos[1] - ) - } + const p3 = new THREE.Vector3( + Network.Nodes.value[pkt.mac_dst].pos[0], + 1.6, + Network.Nodes.value[pkt.mac_dst].pos[1] + ) const x2 = (p1.x + p3.x) / 2 const z2 = (p1.z + p3.z) / 2 @@ -614,8 +581,8 @@ export function useDrawTopology(dom: HTMLElement) { curve: new THREE.QuadraticBezierCurve3(p1, p2, p3), positions: [], uid: pkt.uid, - src: pkt.src, - dst: pkt.dst + src: pkt.mac_src, + dst: pkt.mac_dst } } const drawBeaconPacket = (pkt: Packet) => { @@ -637,9 +604,13 @@ export function useDrawTopology(dom: HTMLElement) { }) const mesh = new THREE.Mesh(geometry, material) mesh.rotation.x = Math.PI / 2 - mesh.position.set(Network.Nodes.value[pkt.src].pos[0], 0.5, Network.Nodes.value[pkt.src].pos[1]) + mesh.position.set( + Network.Nodes.value[pkt.mac_src].pos[0], + 0.5, + Network.Nodes.value[pkt.mac_src].pos[1] + ) scene.add(mesh) - drawnBeaconPackets[pkt.uid] = { mesh, uid: pkt.uid, src: pkt.src, dst: pkt.dst } + drawnBeaconPackets[pkt.uid] = { mesh, uid: pkt.uid, src: pkt.mac_dst, dst: pkt.mac_dst } } const clearPacket = (uid: number) => { if (drawnUnicastPackets[uid] != undefined) { diff --git a/src/hooks/useStates.ts b/src/hooks/useStates.ts index e2969c8..63fd629 100644 --- a/src/hooks/useStates.ts +++ b/src/hooks/useStates.ts @@ -2,11 +2,11 @@ import { ref } from 'vue' -import { TSCHNetwork } from '@/networks/TSCH/network' -export const Network = new TSCHNetwork() +// import { TSCHNetwork } from '@/networks/TSCH/network' +// export const Network = new TSCHNetwork() -// import { TSNNetwork } from '@/networks/TSN/network' -// export const Network = new TSNNetwork() +import { TSNNetwork } from '@/networks/TSN/network' +export const Network = new TSNNetwork() // import { FiveGNetwork } from '@/networks/5G/network' // export const Network = new FiveGNetwork() diff --git a/src/networks/TSCH/network.ts b/src/networks/TSCH/network.ts index e9d05bb..26bd0e6 100644 --- a/src/networks/TSCH/network.ts +++ b/src/networks/TSCH/network.ts @@ -41,12 +41,12 @@ export class TSCHNetwork extends Network { watch(this.ASN, () => { this.doneCnt = 0 this.PacketsCurrent.value = [] - if (this.Nodes.value.length > 1) { - for (const n of this.Nodes.value) { + if (this.NetworkDevices.value.length > 1) { + for (const n of this.NetworkDevices.value) { if (n.w != undefined) { n.w.postMessage({ type: MSG_TYPE.ASN, - dst: n.id, + id: n.id, payload: { asn: this.ASN.value } }) } @@ -72,37 +72,37 @@ export class TSCHNetwork extends Network { } statMsgHandler = (msg: Message) => { const payload = msg.payload - const node = msg.src + const node = msg.id - if (!this.Nodes.value[node].joined && payload.joined) { + if (!this.NetworkDevices.value[node].joined && payload.joined) { // join succeed // console.log(node, 'joined') - this.Nodes.value[node].joined = payload.joined - this.Nodes.value[node].parent = payload.parent - this.Nodes.value[node].neighbors.push(payload.parent) - this.Nodes.value[payload.parent].neighbors.push(node) + this.NetworkDevices.value[node].joined = payload.joined + this.NetworkDevices.value[node].parent = payload.parent + this.NetworkDevices.value[node].neighbors.push(payload.parent) + this.NetworkDevices.value[payload.parent].neighbors.push(node) super.addLink(node, payload.parent, LINK_TYPE.WIRELESS) } - this.Nodes.value[node].queueLen = payload.queue.length - this.Nodes.value[node].tx_cnt = payload.tx_cnt - this.Nodes.value[node].rx_cnt = payload.rx_cnt - this.Nodes.value[node].rank = payload.rank + this.NetworkDevices.value[node].queueLen = payload.queue.length + this.NetworkDevices.value[node].tx_cnt = payload.tx_cnt + this.NetworkDevices.value[node].rx_cnt = payload.rx_cnt + this.NetworkDevices.value[node].rank = payload.rank } assocReqMsgHandler = (msg: Message) => { const new_node: number = msg.payload.id const parent: number = msg.payload.parent // to improve - const topo_check = !this.Nodes.value[new_node].joined + const topo_check = !this.NetworkDevices.value[new_node].joined if (topo_check) { const p = { type: TSCH_PKT_TYPE.ASSOC_RSP, uid: Math.floor(Math.random() * 0xffff), ch: 2, - src: 0, - dst: ADDR.ROOT, + mac_src: 0, + mac_dst: ADDR.ROOT, seq: 0, len: 7, payload: { @@ -112,22 +112,22 @@ export class TSCHNetwork extends Network { cell_list: this.assignMgmtCells(new_node, parent) } } - this.Nodes.value[ADDR.ROOT].w!.postMessage(p) + this.NetworkDevices.value[ADDR.ROOT].w!.postMessage(p) } } createNodes = () => { - this.Nodes = ref([]) + this.NetworkDevices = ref([]) // clear old nodes - if (this.Nodes.value.length > 1) { - for (const n of this.Nodes.value) { + if (this.NetworkDevices.value.length > 1) { + for (const n of this.NetworkDevices.value) { if (n.w != undefined) { n.w.terminate() } } } - this.Nodes.value = [ + this.NetworkDevices.value = [ { id: 0, type: NODE_TYPE.TSCH, @@ -201,8 +201,8 @@ export class TSCHNetwork extends Network { this.Packets.value.push(pkt) this.PacketsCurrent.value.push(pkt) - if (pkt.dst == ADDR.BROADCAST) { - for (const nn of this.Nodes.value) { + if (pkt.mac_dst == ADDR.BROADCAST) { + for (const nn of this.NetworkDevices.value) { // check if in tx_range const distance = Math.sqrt( Math.pow(n.pos[0] - nn.pos[0], 2) + Math.pow(n.pos[1] - nn.pos[1], 2) @@ -212,7 +212,7 @@ export class TSCHNetwork extends Network { } } } else { - const nn = this.Nodes.value[pkt.dst] + const nn = this.NetworkDevices.value[pkt.mac_dst] if (nn != undefined) { // check if in tx_range const distance = Math.sqrt( @@ -227,6 +227,7 @@ export class TSCHNetwork extends Network { } } this.Nodes.value.push(n) + this.NetworkDevices.value.push(n) } } @@ -241,16 +242,16 @@ export class TSCHNetwork extends Network { type: CELL_TYPES.MGMT, slot: 1, ch: this.SchConfig.value.beacon_channel, - src: ADDR.ROOT, - dst: ADDR.BROADCAST + mac_src: ADDR.ROOT, + mac_dst: ADDR.BROADCAST } for (let slot = 2; slot < 2 + this.SchConfig.value.num_shared_slots; slot++) { this.Schedule.value[slot][this.SchConfig.value.shared_channel] = { type: CELL_TYPES.SHARED, slot: slot, ch: this.SchConfig.value.shared_channel, - src: ADDR.ANY, - dst: ADDR.ANY + mac_src: ADDR.ANY, + mac_dst: ADDR.ANY } } } @@ -282,8 +283,8 @@ export class TSCHNetwork extends Network { (x: any) => x.src == src || x.src == dst || - x.dst == src || - x.dst == dst || + x.mac_dst == src || + x.mac_dst == dst || x.type == CELL_TYPES.SHARED ).length > 0 ) { @@ -295,8 +296,8 @@ export class TSCHNetwork extends Network { type: type, slot: slot, ch: this.SchConfig.value.beacon_channel, - src: src, - dst: dst + mac_src: src, + mac_dst: dst } this.Schedule.value[slot][this.SchConfig.value.beacon_channel] = cell return cell @@ -308,8 +309,8 @@ export class TSCHNetwork extends Network { type: type, slot: slot, ch: ch, - src: src, - dst: dst + mac_src: src, + mac_dst: dst } this.Schedule.value[slot][ch] = cell return cell diff --git a/src/networks/TSCH/node.ts b/src/networks/TSCH/node.ts index 7d50f6f..22dd9f8 100644 --- a/src/networks/TSCH/node.ts +++ b/src/networks/TSCH/node.ts @@ -29,7 +29,7 @@ class TSCHNode { schedule: Cell[][] = [] queue: Packet[] = [] joinedNeighbors: { [id: number]: boolean } = {} - routingTable: { [dst: number]: number } = {} + routingTable: { [mac_dst: number]: number } = {} pkt_seq: number = 0 tx_cnt: number = 0 rx_cnt: number = 0 @@ -71,7 +71,7 @@ class TSCHNode { this.respondAck(pkt) // update routing table - this.routingTable[pkt.src] = pkt.src + this.routingTable[pkt.mac_src] = pkt.mac_src if (this.pktHandlers[pkt.type] != undefined) { this.pktHandlers[pkt.type](pkt) @@ -84,11 +84,11 @@ class TSCHNode { } respondAck(pkt: Packet) { - if (pkt.dst != ADDR.BROADCAST && pkt.src != ADDR.CONTROLLER && pkt.type != TSCH_PKT_TYPE.ACK) { + if (pkt.mac_dst != ADDR.BROADCAST && pkt.mac_src != ADDR.CONTROLLER && pkt.type != TSCH_PKT_TYPE.ACK) { const ack: Packet = { ...pkt } ack.type = TSCH_PKT_TYPE.ACK - ack.src = this.id - ack.dst = pkt.src + ack.mac_src = this.id + ack.mac_dst = pkt.mac_src ack.len = 0 ack.payload = {} // send immediately, in the same time slot @@ -99,11 +99,11 @@ class TSCHNode { const slot = this.ASN % this.sch_config.num_slots || this.sch_config.num_slots if (this.queue.length > 0) { const pkt = this.queue[0] - if (this.joined && this.joinedNeighbors[pkt.dst]) { + if (this.joined && this.joinedNeighbors[pkt.mac_dst]) { // use dedicate cells for (let ch = 1; ch <= this.schedule[slot].length; ch++) { const cell = this.schedule[slot][ch] - if (cell != undefined && cell.dst == pkt.dst) { + if (cell != undefined && cell.mac_dst == pkt.mac_dst) { pkt.ch = ch pkt.asn = this.ASN pkt.len = JSON.stringify(pkt.payload).length @@ -111,7 +111,7 @@ class TSCHNode { this.tx_cnt++ // no need of ack, transmission has finished - if (pkt.dst == ADDR.BROADCAST) { + if (pkt.mac_dst == ADDR.BROADCAST) { this.queue.shift() } break @@ -131,14 +131,14 @@ class TSCHNode { } } checkSchRx(pkt: Packet): boolean { - if (!this.joined || pkt.type == TSCH_PKT_TYPE.ACK || pkt.src == ADDR.CONTROLLER) { + if (!this.joined || pkt.type == TSCH_PKT_TYPE.ACK || pkt.mac_src == ADDR.CONTROLLER) { return true } const slot = this.ASN % this.sch_config.num_slots || this.sch_config.num_slots for (const cell of this.schedule[slot]) { if ( cell != undefined && - (cell.src == pkt.src || pkt.dst == ADDR.BROADCAST || cell.type == CELL_TYPES.SHARED) + (cell.mac_src == pkt.mac_src || pkt.mac_dst == ADDR.BROADCAST || cell.type == CELL_TYPES.SHARED) ) { this.rx_cnt++ return true @@ -157,8 +157,8 @@ class TSCHNode { this.queue.push({ uid: Math.floor(Math.random() * 0xffff), type: TSCH_PKT_TYPE.BEACON, - src: this.id, - dst: -1, + mac_src: this.id, + mac_dst: -1, seq: ++this.pkt_seq, len: 1, payload: { pan_id: 1, rank: this.rank } @@ -172,8 +172,7 @@ class TSCHNode { }) postMessage({ type: MSG_TYPE.STAT, - src: this.id, - dst: ADDR.CONTROLLER, + id: this.id, payload: JSON.parse(JSON.stringify(this)) }) } @@ -191,8 +190,8 @@ class TSCHNode { this.schedule[1][this.sch_config.beacon_channel] = { slot: 1, ch: this.sch_config.beacon_channel, - src: this.id, - dst: ADDR.BROADCAST + mac_src: this.id, + mac_dst: ADDR.BROADCAST } } // shared slots @@ -201,8 +200,8 @@ class TSCHNode { type: CELL_TYPES.SHARED, slot: s, ch: this.sch_config.shared_channel, - src: this.id, - dst: ADDR.ANY + mac_src: this.id, + mac_dst: ADDR.ANY } } } @@ -227,10 +226,10 @@ class TSCHNode { const assoc_req = { uid: Math.floor(Math.random() * 0xffff), type: TSCH_PKT_TYPE.ASSOC_REQ, - src: this.id, - dst: pkt.src, + mac_src: this.id, + mac_dst: pkt.mac_src, seq: ++this.pkt_seq, - payload: { id: this.id, parent: pkt.src } + payload: { id: this.id, parent: pkt.mac_src } } this.queue.push(assoc_req) } @@ -239,20 +238,19 @@ class TSCHNode { const payload: ASSOC_REQ_PKT_PAYLOAD = pkt.payload // update routing table if (this.routingTable[payload.id] == undefined) { - this.routingTable[payload.id] = pkt.src + this.routingTable[payload.id] = pkt.mac_src } if (this.id != ADDR.ROOT) { // forward to parent - pkt.src = this.id - pkt.dst = this.parent + pkt.mac_src = this.id + pkt.mac_dst = this.parent pkt.seq = ++this.pkt_seq this.queue.push(pkt) } else { // send to controller postMessage({ type: MSG_TYPE.ASSOC_REQ, - src: this.id, - dst: ADDR.CONTROLLER, + id: this.id, payload: pkt.payload }) } @@ -273,16 +271,15 @@ class TSCHNode { postMessage({ type: MSG_TYPE.STAT, - src: this.id, - dst: ADDR.CONTROLLER, + id: this.id, payload: JSON.parse(JSON.stringify(this)) }) this.queue.push({ uid: Math.floor(Math.random() * 0xffff), type: TSCH_PKT_TYPE.BEACON, - src: this.id, - dst: -1, + mac_src: this.id, + mac_dst: -1, seq: ++this.pkt_seq, len: 1, payload: { pan_id: 1, rank: this.rank } @@ -300,15 +297,15 @@ class TSCHNode { } // need forwarding if (payload.id != this.id) { - pkt.src = this.id + pkt.mac_src = this.id if (this.children.indexOf(pkt.payload.id) > -1) { - pkt.dst = pkt.payload.id + pkt.mac_dst = pkt.payload.id pkt.seq = ++this.pkt_seq this.queue.push(pkt) } else { // not related to this if (this.routingTable[pkt.payload.id] != undefined) { - pkt.dst = this.routingTable[pkt.payload.id] + pkt.mac_dst = this.routingTable[pkt.payload.id] pkt.seq = ++this.pkt_seq this.queue.push(pkt) } diff --git a/src/networks/TSCH/typedefs.ts b/src/networks/TSCH/typedefs.ts index 9926638..cd36411 100644 --- a/src/networks/TSCH/typedefs.ts +++ b/src/networks/TSCH/typedefs.ts @@ -23,8 +23,8 @@ export interface Cell { type: number slot: number ch: number - src: number - dst: number + mac_src: number + mac_dst: number } export enum CELL_TYPES { diff --git a/src/networks/TSN/network.ts b/src/networks/TSN/network.ts index 40382b3..30b4f59 100644 --- a/src/networks/TSN/network.ts +++ b/src/networks/TSN/network.ts @@ -19,7 +19,7 @@ export class TSNNetwork extends Network { super.createEndSystems() } createNodes = () => { - this.Nodes = ref([]) + this.NetworkDevices = ref([]) // clear old nodes and webworkers if (this.Nodes.value.length > 1) { @@ -68,6 +68,7 @@ export class TSNNetwork extends Network { } }) + this.NetworkDevices.value.push(n) this.Nodes.value.push(n) this.KDTree.Insert(new KDNode(i, n.pos)) } diff --git a/src/networks/TSN/node.ts b/src/networks/TSN/node.ts index 50b5e97..c1194d9 100644 --- a/src/networks/TSN/node.ts +++ b/src/networks/TSN/node.ts @@ -3,7 +3,6 @@ import { type Message, type MsgHandler, type PktHandler, - ADDR, MSG_TYPE, type ASN_MSG_PAYLOAD } from '../common' @@ -66,13 +65,12 @@ class TSNNode { }) postMessage({ type: MSG_TYPE.STAT, - src: this.id, - dst: ADDR.CONTROLLER, + id: this.id, payload: JSON.parse(JSON.stringify(this)) }) } dataPktHandler = (pkt: Packet) => { - console.log('tsn', pkt) + console.log(pkt) } } diff --git a/src/networks/common.ts b/src/networks/common.ts index a92bb1e..70ba4b6 100644 --- a/src/networks/common.ts +++ b/src/networks/common.ts @@ -8,14 +8,10 @@ export enum NODE_TYPE { TSCH, TSN, FIVE_G_BS, - FIVE_G_UE -} - -export enum END_SYSTEM_TYPE { - Server, - RoboticArm, - Sensor - // add more and find the corresponding 3D models + FIVE_G_UE, + SERVER, + ROBOT, + SENSOR } export interface NodeMeta { @@ -41,13 +37,22 @@ export enum LINK_TYPE { WIRELESS } + +export interface FlowMeta { + id: number + src: number + dst: number +} + // Packet is transfered among nodes, at data-link layer export interface Packet { uid: number type: number ch: number - src: number - dst: number + e2e_src: number + e2e_dst: number + mac_src: number + mac_dst: number seq: number asn: number len: number @@ -61,8 +66,7 @@ export interface Packet { // Message is used for direct communication (debug, cmd, stats) between nodes and controller export interface Message { type: number - src: number - dst: number + id: number // node id payload: any } diff --git a/src/networks/es.ts b/src/networks/es.ts index b3b854b..a8b358d 100644 --- a/src/networks/es.ts +++ b/src/networks/es.ts @@ -28,8 +28,8 @@ class EndSystem { postMessage({ uid: 11, type: 0, - src: 11, - dst: 3 + mac_src: 11, + mac_dst: 3 }) } else { // console.log('!! undefined message type:', msg.type) diff --git a/src/networks/network.ts b/src/networks/network.ts index 29aeb5b..2950316 100644 --- a/src/networks/network.ts +++ b/src/networks/network.ts @@ -1,14 +1,26 @@ import { ref, toRaw, type Ref } from 'vue' import { SeededRandom } from '@/hooks/useSeed' import { KDTree } from './kdtree' -import { END_SYSTEM_TYPE, LINK_TYPE, MSG_TYPE, type LinkMeta, type Message, type NodeMeta, type Packet, type TopologyConfig, type INIT_MSG_PAYLOAD } from './common' +import { + LINK_TYPE, + MSG_TYPE, + type LinkMeta, + type Message, + type NodeMeta, + type Packet, + type TopologyConfig, + type INIT_MSG_PAYLOAD, + type FlowMeta +} from './common' export class Network { ID: number Type: number - Nodes: any // tsn bridges, tsch node or 5g ue/bs - EndSystems: any + Nodes = ref([]) // nodes and endsystems, for visualization + NetworkDevices: any // tsn bridges, tsch relay or 5g ue/bs + EndSystems = ref([]) Links = ref<{ [uid: number]: LinkMeta }>([]) + Flows = ref([]) TopoConfig: Ref KDTree: KDTree SchConfig: any @@ -36,6 +48,7 @@ export class Network { tx_range: 25 }) this.Rand = new SeededRandom(this.TopoConfig.value.seed) + this.Nodes.value.push({}) this.KDTree = new KDTree() } // call after createNodes @@ -43,8 +56,6 @@ export class Network { // initialize ref array if it does not already exist this.EndSystems = ref([]) - this.EndSystems.value = [] // clear any old end systems - for ( let i = 1 + this.TopoConfig.value.num_nodes; i <= this.TopoConfig.value.num_es + this.TopoConfig.value.num_nodes; @@ -52,9 +63,7 @@ export class Network { ) { const es = { id: i, - type: Math.floor( - this.Rand.next() * Object.keys(END_SYSTEM_TYPE).filter((key) => isNaN(Number(key))).length - ), // Object.keys(...).filter(...) is used to count # of elements in enum + type: Math.floor(4 + this.Rand.next() * 3), pos: [ Math.floor(this.Rand.next() * this.TopoConfig.value.grid_size) - this.TopoConfig.value.grid_size / 2, @@ -66,11 +75,11 @@ export class Network { neighbors: [], w: new Worker(new URL('@/networks/es.ts', import.meta.url), { type: 'module' }) } + console.log(i) es.neighbors = this.KDTree.FindKNearest(es.pos, 1, this.TopoConfig.value.grid_size) if (es.neighbors.length > 0) { this.addLink(es.id, es.neighbors[0], LINK_TYPE.WIRED) } - this.EndSystems.value.push(es) es.w!.postMessage({ type: MSG_TYPE.INIT, @@ -86,12 +95,15 @@ export class Network { console.log(msg) } else { const pkt: Packet = e.data - this.Nodes.value[pkt.dst].w!.postMessage(pkt) + this.Nodes.value[pkt.mac_dst].w!.postMessage(pkt) this.Packets.value.push(pkt) this.PacketsCurrent.value.push(pkt) this.SlotDone.value = true } } + + this.EndSystems.value.push(es) + this.Nodes.value.push(es) } } addLink(v1: number, v2: number, type: number) {