From f4f2e2479e1541b6dce480458ddcb5dfafcdc805 Mon Sep 17 00:00:00 2001 From: AmyangXYZ Date: Fri, 22 Dec 2023 21:06:43 -0500 Subject: [PATCH] rewrite drawlink --- src/hooks/useDrawTopology.ts | 24 +++++++++++------------- src/hooks/useStates.ts | 8 ++++---- src/networks/5G/network.ts | 5 ++++- src/networks/TSCH/network.ts | 8 ++++++-- src/networks/common.ts | 8 ++++++++ 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/hooks/useDrawTopology.ts b/src/hooks/useDrawTopology.ts index a68c7b7..0463175 100644 --- a/src/hooks/useDrawTopology.ts +++ b/src/hooks/useDrawTopology.ts @@ -399,27 +399,24 @@ export function useDrawTopology(dom: HTMLElement) { const drawEndSystems = () => {} - let drawnLinks: any = {} + let drawnLinks: { [uid: number]: any } = {} const drawLinks = () => { - for (const n of Network.Nodes.value) { - for (const nn of n.neighbors) { - const linkName = n.id < nn ? `${n.id}-${nn}` : `${nn}-${n.id}` - if (drawnLinks[linkName] == undefined) { - drawLink(n.id, nn, linkName) - } + for (const l of Network.Links.value) { + if (drawnLinks[l.uid] == undefined) { + drawLink(l.uid, l.v1, l.v2) } } } - const drawLink = (src: number, dst: number, name: string) => { + const drawLink = (uid: number, v1: number, v2: number) => { const p1 = new THREE.Vector3( - Network.Nodes.value[src].pos[0], + Network.Nodes.value[v1].pos[0], 1.6, - Network.Nodes.value[src].pos[1] + Network.Nodes.value[v1].pos[1] ) const p3 = new THREE.Vector3( - Network.Nodes.value[dst].pos[0], + Network.Nodes.value[v2].pos[0], 1.6, - Network.Nodes.value[dst].pos[1] + Network.Nodes.value[v2].pos[1] ) const x2 = (p1.x + p3.x) / 2 @@ -434,7 +431,7 @@ export function useDrawTopology(dom: HTMLElement) { new THREE.LineBasicMaterial({ color: 'white' }) ) scene.add(mesh) - drawnLinks[name] = { mesh, src, dst } + drawnLinks[uid] = { mesh, v1, v2 } } const clearLinks = () => { for (const i in drawnLinks) { @@ -630,6 +627,7 @@ export function useDrawTopology(dom: HTMLElement) { addLights() drawGround() drawNodes() + drawLinks() // draw5GTower() animate() diff --git a/src/hooks/useStates.ts b/src/hooks/useStates.ts index 22c5c63..e2969c8 100644 --- a/src/hooks/useStates.ts +++ b/src/hooks/useStates.ts @@ -2,14 +2,14 @@ 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 { FiveGNetwork } from '@/networks/5G/network' -export const Network = new FiveGNetwork() +// import { FiveGNetwork } from '@/networks/5G/network' +// export const Network = new FiveGNetwork() export const SelectedNode = ref(1) export const MiniMapMode = ref('scatter') diff --git a/src/networks/5G/network.ts b/src/networks/5G/network.ts index a75cdf1..d7171e3 100644 --- a/src/networks/5G/network.ts +++ b/src/networks/5G/network.ts @@ -1,5 +1,5 @@ import { ref } from 'vue' -import { Network, NetworkType, NODE_TYPE } from '../common' +import { Network, NetworkType, NODE_TYPE, type LinkMeta } from '../common' import type { ScheduleConfig, FiveGNodeMeta } from './typedefs' import { SeededRandom } from '@/hooks/useSeed' @@ -53,6 +53,9 @@ export class FiveGNetwork extends Network { rx_cnt: 0, w: new Worker(new URL('@/networks/5G/node.ts', import.meta.url), { type: 'module' }) } + // add links + this.Links.value.push({ uid: i * 3, v1: 0, v2: i }) + // send init msg // n.w!.postMessage({ // type: MSG_TYPES.INIT, diff --git a/src/networks/TSCH/network.ts b/src/networks/TSCH/network.ts index 2eee16f..2b9543e 100644 --- a/src/networks/TSCH/network.ts +++ b/src/networks/TSCH/network.ts @@ -10,10 +10,9 @@ import type { import { ADDR, MSG_TYPES, PKT_TYPES, CELL_TYPES } from './typedefs' import { SeededRandom } from '@/hooks/useSeed' import { Network, NetworkType, NODE_TYPE } from '../common' -import type { Packet, Message, MsgHandler } from '../common' +import type { Packet, Message, MsgHandler, LinkMeta } from '../common' export class TSCHNetwork extends Network { - doneCnt = 0 msgHandlers: { [type: number]: MsgHandler } = {} @@ -82,6 +81,11 @@ export class TSCHNetwork extends Network { this.Nodes.value[node].parent = payload.parent this.Nodes.value[node].neighbors.push(payload.parent) this.Nodes.value[payload.parent].neighbors.push(node) + this.Links.value.push({ + uid: node * 2 + payload.parent * 3, + v1: node, + v2: payload.parent + }) } this.Nodes.value[node].queueLen = payload.queue.length diff --git a/src/networks/common.ts b/src/networks/common.ts index 629f3bf..371fda7 100644 --- a/src/networks/common.ts +++ b/src/networks/common.ts @@ -4,6 +4,7 @@ export class Network { ID: number Type: number Nodes: any + Links = ref([]) EndSystems: any TopoConfig: Ref SchConfig: any @@ -79,6 +80,13 @@ export interface NodeMeta { w: Worker | undefined } +export interface LinkMeta { + // undirected link for visualization + uid: number // uid=v1*2+v2*3 + v1: number + v2: number +} + export enum END_SYSTEM_TYPE { Server, RoboticArm,