Skip to content

Commit

Permalink
adding flows
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Dec 29, 2023
1 parent 00ebb0d commit 0931bdf
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 223 deletions.
13 changes: 10 additions & 3 deletions src/components/PacketSniffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import ChannelChart from '@/components/ChannelChart.vue'
import { ref, watch, nextTick } from 'vue'
import { Network } from '@/hooks/useStates'
import type { Packet } from '@/networks/common'
import { PKT_TYPES } from '@/networks/TSCH/typedefs'
import { NETWORK_TYPE, type Packet } from '@/networks/common'
import { TSCH_PKT_TYPE } from '@/networks/TSCH/typedefs'
import { TSN_PKT_TYPE } from '@/networks/TSN/typedefs'
import { FIVE_G_PKT_TYPE } from '@/networks/5G/typedefs'
import { Filter } from '@element-plus/icons-vue'
const filterRules = ref()
function filterFunc(pkt: Packet) {
Expand Down Expand Up @@ -65,7 +68,11 @@ const columns: any = [
dataKey: 'type',
width: 80,
align: 'center',
cellRenderer: ({ cellData: type }: any) => PKT_TYPES[type]
cellRenderer: ({ cellData: type }: any) => {
if (Network.Type == NETWORK_TYPE.TSCH) return TSCH_PKT_TYPE[type]
if (Network.Type == NETWORK_TYPE.TSN) return TSN_PKT_TYPE[type]
if (Network.Type == NETWORK_TYPE.FIVE_G) return FIVE_G_PKT_TYPE[type]
}
},
// {
// key: 'seq',
Expand Down
57 changes: 40 additions & 17 deletions src/hooks/useDrawTopology.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { watch } from 'vue'
import { Network, SelectedNode, SignalEditTopology, SignalResetCamera } from './useStates'
import { ADDR, PKT_TYPES } from '@/networks/TSCH/typedefs'
import { TSCH_PKT_TYPE } from '@/networks/TSCH/typedefs'

import * as THREE from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
Expand All @@ -11,6 +11,7 @@ import * as TWEEN from '@tweenjs/tween.js'
import {
NODE_TYPE,
NETWORK_TYPE,
ADDR,
type Packet,
type LinkMeta,
LINK_TYPE,
Expand Down Expand Up @@ -124,7 +125,7 @@ export function useDrawTopology(dom: HTMLElement) {
case NETWORK_TYPE.TSN:
drawTSNNodes()
break
case NETWORK_TYPE.FiveG:
case NETWORK_TYPE.FIVE_G:
drawFiveGBS()
drawFiveGUE()
break
Expand Down Expand Up @@ -404,7 +405,7 @@ export function useDrawTopology(dom: HTMLElement) {
}

// Load and place models
loadAndPlaceModel('/models/server/scene.gltf', [.08, .08, .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, 0)
loadAndPlaceModel(
'/models/robotic_arm/scene.gltf',
[0.004, 0.004, 0.004],
Expand Down Expand Up @@ -449,7 +450,7 @@ export function useDrawTopology(dom: HTMLElement) {
}
}
const drawLink = (l: LinkMeta) => {
let p1: THREE.Vector3
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],
Expand All @@ -465,7 +466,6 @@ export function useDrawTopology(dom: HTMLElement) {
)
}

let p3: THREE.Vector3
if (l.v2 <= Network.TopoConfig.value.num_nodes) {
p3 = new THREE.Vector3(
Network.Nodes.value[l.v2].pos[0],
Expand Down Expand Up @@ -531,9 +531,10 @@ export function useDrawTopology(dom: HTMLElement) {
const drawPackets = () => {
time = 0 // reset animation timer
for (const pkt of Network.PacketsCurrent.value) {
if (pkt.type != PKT_TYPES.ACK && pkt.dst != ADDR.BROADCAST) {
if (Network.Type == NETWORK_TYPE.TSCH && pkt.type == TSCH_PKT_TYPE.ACK) continue
if (pkt.dst != ADDR.BROADCAST) {
drawUnicastPacket(pkt)
} else if (pkt.type == PKT_TYPES.BEACON) {
} else if (Network.Type == NETWORK_TYPE.TSCH && pkt.type == TSCH_PKT_TYPE.BEACON) {
drawBeaconPacket(pkt)
}
}
Expand Down Expand Up @@ -571,16 +572,38 @@ export function useDrawTopology(dom: HTMLElement) {
const mesh = new THREE.Points(geometry, material)
scene.add(mesh)

const p1 = new THREE.Vector3(
Network.Nodes.value[pkt.src].pos[0],
1.6,
Network.Nodes.value[pkt.src].pos[1]
)
const p3 = new THREE.Vector3(
Network.Nodes.value[pkt.dst].pos[0],
1.6,
Network.Nodes.value[pkt.dst].pos[1]
)
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]
)
}

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 x2 = (p1.x + p3.x) / 2
const z2 = (p1.z + p3.z) / 2
const h = 5
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 7 additions & 6 deletions src/networks/5G/network.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ref } from 'vue'
import { LINK_TYPE, Network, NETWORK_TYPE, NODE_TYPE } from '../common'
import { LINK_TYPE, NETWORK_TYPE, NODE_TYPE } from '../common'
import type { ScheduleConfig, FiveGNodeMeta } from './typedefs'
import { KDNode } from '../TSN/kdtree'
import { KDNode } from '../kdtree'
import { Network } from '../network'

export class FiveGNetwork extends Network {
constructor() {
super()
this.Type = NETWORK_TYPE.FiveG
this.Type = NETWORK_TYPE.FIVE_G
// this.Schedule = ref<Cell[][]>([])
this.SchConfig = ref<ScheduleConfig>({
num_slots: 40
Expand Down Expand Up @@ -59,7 +60,7 @@ export class FiveGNetwork extends Network {

// send init msg
// n.w!.postMessage(<Message>{
// type: MSG_TYPES.INIT,
// type: MSG_TYPE.INIT,
// payload: <INIT_MSG_PAYLOAD>{
// id: n.id,
// pos: toRaw(n.pos),
Expand All @@ -68,7 +69,7 @@ export class FiveGNetwork extends Network {
// })
// handle msg/pkt from nodes
// n.w!.onmessage = (e: any) => {
// if ('ch' in e.data == false) {
// if ('uid' in e.data == false) {
// const msg: Message = e.data
// if (this.msgHandlers[msg.type] != undefined) {
// this.msgHandlers[msg.type](msg)
Expand All @@ -80,7 +81,7 @@ export class FiveGNetwork extends Network {
// // check channel interference, only one packet can be transmitted on each channel in a slot
// if (
// this.PacketsCurrent.value.filter((p) => p.ch == pkt.ch).length == 0 ||
// pkt.type == PKT_TYPES.ACK
// pkt.type == PKT_TYPE.ACK
// ) {
// // must use this format for the detailedView function of el-table-v2
// pkt.id = this.Packets.value.length
Expand Down
5 changes: 5 additions & 0 deletions src/networks/5G/typedefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ export interface ScheduleConfig {
}

export interface FiveGNodeMeta extends NodeMeta {}

export enum FIVE_G_PKT_TYPE {
ACK,
DATA
}
32 changes: 16 additions & 16 deletions src/networks/TSCH/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type {
Cell,
TSCHNodeMeta,
ScheduleConfig,
INIT_MSG_PAYLOAD,
ASN_MSG_PAYLOAD,
TSCH_INIT_MSG_PAYLOAD,
ASSOC_RSP_PKT_PAYLOAD
} from './typedefs'
import { ADDR, MSG_TYPES, PKT_TYPES, CELL_TYPES } from './typedefs'
import { LINK_TYPE, Network, NETWORK_TYPE, NODE_TYPE } from '../common'
import type { Packet, Message, MsgHandler } from '../common'
import { KDNode } from '../TSN/kdtree'
import { TSCH_PKT_TYPE, CELL_TYPES } from './typedefs'
import { ADDR, MSG_TYPE, LINK_TYPE, NETWORK_TYPE, NODE_TYPE } from '../common'
import type { Packet, Message, ASN_MSG_PAYLOAD, MsgHandler } from '../common'
import { KDNode } from '../kdtree'
import { Network } from '../network'

export class TSCHNetwork extends Network {
doneCnt = 0
Expand All @@ -30,9 +30,9 @@ export class TSCHNetwork extends Network {
num_shared_slots: 8
})

this.registerMsgHandler(MSG_TYPES.DONE, this.doneMsgHandler)
this.registerMsgHandler(MSG_TYPES.STAT, this.statMsgHandler)
this.registerMsgHandler(MSG_TYPES.ASSOC_REQ, this.assocReqMsgHandler)
this.registerMsgHandler(MSG_TYPE.DONE, this.doneMsgHandler)
this.registerMsgHandler(MSG_TYPE.STAT, this.statMsgHandler)
this.registerMsgHandler(MSG_TYPE.ASSOC_REQ, this.assocReqMsgHandler)

this.createNodes()
super.createEndSystems()
Expand All @@ -45,7 +45,7 @@ export class TSCHNetwork extends Network {
for (const n of this.Nodes.value) {
if (n.w != undefined) {
n.w.postMessage(<Packet>{
type: MSG_TYPES.ASN,
type: MSG_TYPE.ASN,
dst: n.id,
payload: <ASN_MSG_PAYLOAD>{ asn: this.ASN.value }
})
Expand Down Expand Up @@ -98,7 +98,7 @@ export class TSCHNetwork extends Network {

if (topo_check) {
const p = <Packet>{
type: PKT_TYPES.ASSOC_RSP,
type: TSCH_PKT_TYPE.ASSOC_RSP,
uid: Math.floor(Math.random() * 0xffff),
ch: 2,
src: 0,
Expand Down Expand Up @@ -147,7 +147,7 @@ export class TSCHNetwork extends Network {
const n = <TSCHNodeMeta>{
id: i,
type: NODE_TYPE.TSCH,
pos: [
pos: <[number, number]>[
Math.floor(this.Rand.next() * this.TopoConfig.value.grid_size) -
this.TopoConfig.value.grid_size / 2,
Math.floor(this.Rand.next() * this.TopoConfig.value.grid_size) -
Expand All @@ -166,16 +166,16 @@ export class TSCHNetwork extends Network {

// send init msg
n.w!.postMessage(<Message>{
type: MSG_TYPES.INIT,
payload: <INIT_MSG_PAYLOAD>{
type: MSG_TYPE.INIT,
payload: <TSCH_INIT_MSG_PAYLOAD>{
id: n.id,
pos: toRaw(n.pos),
sch_config: toRaw(this.SchConfig.value)
}
})
// handle msg/pkt from nodes
n.w!.onmessage = (e: any) => {
if ('ch' in e.data == false) {
if ('uid' in e.data == false) {
const msg: Message = e.data
if (this.msgHandlers[msg.type] != undefined) {
this.msgHandlers[msg.type](msg)
Expand All @@ -187,7 +187,7 @@ export class TSCHNetwork extends Network {
// check channel interference, only one packet can be transmitted on each channel in a slot
if (
this.PacketsCurrent.value.filter((p) => p.ch == pkt.ch).length == 0 ||
pkt.type == PKT_TYPES.ACK
pkt.type == TSCH_PKT_TYPE.ACK
) {
// must use this format for the detailedView function of el-table-v2
pkt.id = this.Packets.value.length
Expand Down
Loading

0 comments on commit 0931bdf

Please sign in to comment.