Skip to content

Commit

Permalink
change max print width of formatter and improve EstConn function
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Jan 17, 2024
1 parent 735ab9a commit bf4cedd
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 524 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"printWidth": 120,
"trailingComma": "none"
}
4 changes: 2 additions & 2 deletions src/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
body {
min-height: 100vh;
line-height: 1.6;
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans',
'Droid Sans', 'Helvetica Neue', sans-serif;
font-size: 15px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
Expand Down
24 changes: 3 additions & 21 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,17 @@ onKeyStroke('ArrowRight', () => {
<el-col :span="8" style="margin-top: 3px">
<a href="https://github.com/AmyangXYZ/VeRNet"><img height="48" :src="VeRNetLogo" /></a>
<el-button-group class="btns">
<el-button
class="btn"
:disabled="Network.Running.value"
size="small"
type="primary"
@click="Network.Run"
>
<el-button class="btn" :disabled="Network.Running.value" size="small" type="primary" @click="Network.Run">
<el-icon size="18">
<IconPlay />
</el-icon>
</el-button>
<el-button
class="btn"
:disabled="Network.Running.value"
size="small"
type="info"
@click="Network.Step"
>
<el-button class="btn" :disabled="Network.Running.value" size="small" type="info" @click="Network.Step">
<el-icon size="18">
<IconPlusOne />
</el-icon>
</el-button>
<el-button
class="btn"
:disabled="!Network.Running.value"
size="small"
type="warning"
@click="Network.Pause"
>
<el-button class="btn" :disabled="!Network.Running.value" size="small" type="warning" @click="Network.Pause">
<el-icon size="18">
<IconPause />
</el-icon>
Expand Down
8 changes: 1 addition & 7 deletions src/components/EventLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ onUnmounted(() => {
</script>

<template>
<div
class="log-container"
v-show="showLog"
ref="logContainer"
@mouseover="handleMouseOver"
@mouseleave="resetTimer"
>
<div class="log-container" v-show="showLog" ref="logContainer" @mouseover="handleMouseOver" @mouseleave="resetTimer">
<div class="log" v-for="(log, i) in Network.Logs.value" :key="i">> {{ log }}</div>
</div>
</template>
Expand Down
14 changes: 2 additions & 12 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ onKeyStroke('`', () => {
</a>
</el-col>
<el-col :span="4">
<el-tooltip
effect="light"
content="Network settings"
:hide-after="0"
placement="right-start"
>
<el-tooltip effect="light" content="Network settings" :hide-after="0" placement="right-start">
<el-button class="btn" size="small" @click="SignalShowSettings = !SignalShowSettings">
<el-icon color="#aaa" size="20">
<Setting />
Expand All @@ -56,12 +51,7 @@ onKeyStroke('`', () => {
</el-tooltip>
</el-col>
<el-col :span="4">
<el-tooltip
effect="light"
content="Network statistics"
:hide-after="0"
placement="right-start"
>
<el-tooltip effect="light" content="Network statistics" :hide-after="0" placement="right-start">
<el-button class="btn" size="small" @click="SignalShowStatistics = !SignalShowStatistics">
<el-icon color="#aaa" size="20">
<DataAnalysis />
Expand Down
9 changes: 3 additions & 6 deletions src/components/NodeStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import { NODE_TYPE, NODE_TYPE_DISPLAY_NAME } from '@/core/typedefs'
</script>

<template>
<el-card class="card" v-if="SelectedNode > 0 && Network.Nodes.value[SelectedNode]!=undefined">
<el-card class="card" v-if="SelectedNode > 0 && Network.Nodes.value[SelectedNode] != undefined">
<el-row :gutter="30">
<el-col :span="11" align="center">
<img :src="SelectedNode == 1 ? rpi4 : sensortag" />
</el-col>
<el-col :span="13">
<span style="font-weight: 600; font-size: 0.9rem">
{{ NODE_TYPE_DISPLAY_NAME[NODE_TYPE[Network.Nodes.value[SelectedNode].type]] }}-{{
SelectedNode
}}
{{ NODE_TYPE_DISPLAY_NAME[NODE_TYPE[Network.Nodes.value[SelectedNode].type]] }}-{{ SelectedNode }}
</span>
<br />
- TX: {{ Network.Nodes.value[SelectedNode].tx_cnt }} , RX:
{{ Network.Nodes.value[SelectedNode].rx_cnt }}<br />
- TX: {{ Network.Nodes.value[SelectedNode].tx_cnt }} , RX: {{ Network.Nodes.value[SelectedNode].rx_cnt }}<br />
</el-col>
</el-row>
</el-card>
Expand Down
15 changes: 2 additions & 13 deletions src/components/TopoEditToolbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,15 @@ const finishEdit = () => {
<div class="flex-container">
<span class="label-margin">Load preset:</span>
<el-select class="dropdown" v-model="Network.SelectedTopo.value" style="margin-right: 55px">
<el-option
v-for="(_, name) in Network.PresetTopos"
:key="name"
:label="name"
:value="name"
/>
<el-option v-for="(_, name) in Network.PresetTopos" :key="name" :label="name" :value="name" />
</el-select>
</div>

<div class="flex-container mt-4">
<span class="label-margin">Add node:</span>
<el-select class="dropdown" v-model="nodeType">
<el-option-group v-for="group in nodeTypes" :key="group.label" :label="group.label">
<el-option
v-for="item in group.types"
:key="item.value"
:label="item.label"
:value="item.value"
/>
<el-option v-for="item in group.types" :key="item.value" :label="item.label" :value="item.value" />
</el-option-group>
</el-select>

Expand All @@ -80,7 +70,6 @@ const finishEdit = () => {
<el-button class="circular-button" @click="finishEdit" type="danger" :icon="Check" circle />
</div>
</el-card>

</template>

<style scoped>
Expand Down
4 changes: 1 addition & 3 deletions src/components/icons/IconReset.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path
d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"
/>
<path d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z" />
</svg>
</template>
115 changes: 49 additions & 66 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export class NetworkHub {
Logs = ref<string[]>([])
ASN = ref<number>(0) // absolute slot number
Rand: SeededRandom
kdTree: KDTree // to find nearest neighbors

// to find nearest neighbors, only network devices are inserted in KDTrees
kdTreeAny: KDTree // any network devices
kdTreeTSCH: KDTree // TSCH only
kdTreeTSN: KDTree // TSN only
kdTreeFiveGgNB: KDTree // 5G gNB only

PresetTopos: { [name: string]: any } = presetTopos
SelectedTopo = ref('5G-TSN-TSCH') // realistic topo example
Expand All @@ -44,7 +49,10 @@ export class NetworkHub {
this.Config = ref<Config>(config)
this.Nodes = ref<Node[]>([<Node>{ id: 0 }]) // placeholder to let node_id start from 1
this.Rand = new SeededRandom(this.Config.value.seed)
this.kdTree = new KDTree()
this.kdTreeAny = new KDTree()
this.kdTreeTSCH = new KDTree()
this.kdTreeTSN = new KDTree()
this.kdTreeFiveGgNB = new KDTree()

watch(this.SelectedTopo, () => {
this.LoadTopology()
Expand Down Expand Up @@ -86,16 +94,10 @@ export class NetworkHub {
// forward physical layer pkt from each node
handlePkt = (pkt: Packet) => {
// check protocol type
if (
this.Nodes.value[pkt.mac_src].type == NODE_TYPE.TSCH ||
this.Nodes.value[pkt.mac_dst].type == NODE_TYPE.TSCH
) {
if (this.Nodes.value[pkt.mac_src].type == NODE_TYPE.TSCH || this.Nodes.value[pkt.mac_dst].type == NODE_TYPE.TSCH) {
pkt.protocol = PROTOCOL_TYPE.TSCH
}
if (
this.Nodes.value[pkt.mac_src].type == NODE_TYPE.TSN ||
this.Nodes.value[pkt.mac_dst].type == NODE_TYPE.TSN
) {
if (this.Nodes.value[pkt.mac_src].type == NODE_TYPE.TSN || this.Nodes.value[pkt.mac_dst].type == NODE_TYPE.TSN) {
pkt.protocol = PROTOCOL_TYPE.TSN
}
if (
Expand Down Expand Up @@ -167,14 +169,10 @@ export class NetworkHub {
// type: [0, 1, 2, 3, 11, 12, 13, 14, 15, 16, 17][
// Math.floor((this.Rand.next() * Object.keys(NODE_TYPE).length) / 2)
// ],
type: [0, 1, 2, 3, 11, 12, 16][
Math.floor(this.Rand.next() * 7)
],
type: [0, 1, 2, 3, 11, 12, 16][Math.floor(this.Rand.next() * 7)],
pos: [
Math.floor(this.Rand.next() * this.Config.value.grid_size) -
this.Config.value.grid_size / 2,
Math.floor(this.Rand.next() * this.Config.value.grid_size) -
this.Config.value.grid_size / 2
Math.floor(this.Rand.next() * this.Config.value.grid_size) - this.Config.value.grid_size / 2,
Math.floor(this.Rand.next() * this.Config.value.grid_size) - this.Config.value.grid_size / 2
],
neighbors: [],
tx_cnt: 0,
Expand All @@ -198,76 +196,63 @@ export class NetworkHub {
}

EstablishConnection() {
this.kdTree = new KDTree()
this.kdTreeAny = new KDTree()
this.kdTreeTSCH = new KDTree()
this.kdTreeTSN = new KDTree()
this.kdTreeFiveGgNB = new KDTree()
this.Links.value = []
for (const n of this.Nodes.value) {
if (n.id == 0 || n.type > 10) continue
this.kdTree.Insert(new KDNode(n.id, n.pos))
this.kdTreeAny.Insert(new KDNode(n.id, n.pos))
switch (n.type) {
case NODE_TYPE.TSCH:
this.kdTreeTSCH.Insert(new KDNode(n.id, n.pos))
break
case NODE_TYPE.TSN:
this.kdTreeTSN.Insert(new KDNode(n.id, n.pos))
break
case NODE_TYPE.FIVE_G_GNB:
this.kdTreeFiveGgNB.Insert(new KDNode(n.id, n.pos))
break
default:
break
}
}

for (const n of this.Nodes.value) {
if (n.id == 0) continue

const neighbors: any = []
let neighbors: any = []

// actively find connections, final routing table will be based on the
// overall connected graph (Links), not just the neighbors of each node
switch (n.type) {
// 5G UE connects to one 5G tower and multiple wired end systems
// 5G UE connects to one 5G tower
case NODE_TYPE.FIVE_G_UE: {
const ueBsNeighbors = this.kdTree.FindKNearest(n.pos, 1, this.Config.value.tx_range)
const validUeBs = ueBsNeighbors.find(nn => this.Nodes.value[nn]?.type === NODE_TYPE.FIVE_G_GNB)
if (validUeBs !== undefined) neighbors.push(validUeBs)

const ueEndNeighbors = this.kdTree.FindKNearest(n.pos, 1000, 20)
const validUeEnd = ueEndNeighbors.find(nn => this.Nodes.value[nn]?.type >= NODE_TYPE.END_SYSTEM_SERVER)
if (validUeEnd !== undefined) neighbors.push(validUeEnd)

neighbors = this.kdTreeFiveGgNB.FindKNearest(n.pos, 1, this.Config.value.tx_range)
break
}
// 5G GNB connects to a TSN, an end system, and multiple 5G UEs
// 5G GNB connects to TSN bridges
case NODE_TYPE.FIVE_G_GNB: {
const bsNeighbors = this.kdTree.FindKNearest(n.pos, 1, this.Config.value.tx_range)
const validGnbTsn = bsNeighbors.find(nn => this.Nodes.value[nn].type === NODE_TYPE.TSN)
const validBsEnd = bsNeighbors.find(nn => this.Nodes.value[nn].type >= NODE_TYPE.END_SYSTEM_SERVER)
if (validGnbTsn !== undefined) neighbors.push(validGnbTsn)
if (validBsEnd !== undefined) neighbors.push(validBsEnd)

const gnbUeNeighbors = this.kdTree.FindKNearest(n.pos, 1000, this.Config.value.tx_range)
const validUes = gnbUeNeighbors.filter(nn => this.Nodes.value[nn].type === NODE_TYPE.FIVE_G_UE)
neighbors.push(...validUes)

neighbors = this.kdTreeTSN.FindKNearest(n.pos, 2, this.Config.value.grid_size)
break
}
// TSCH node connects to multiple other TSCH nodes and wired end systems
// TSCH node connects to multiple other TSCH nodes and one TSN bridge
case NODE_TYPE.TSCH: {
const tschNeighbors = this.kdTree.FindKNearest(n.pos, 1000, this.Config.value.tx_range)
const validTsch = tschNeighbors.filter(nn => this.Nodes.value[nn].type === NODE_TYPE.TSCH)
const validTschEnd = tschNeighbors.find(nn => this.Nodes.value[nn].type >= NODE_TYPE.END_SYSTEM_SERVER)
neighbors.push(...validTsch)
if (validTschEnd !== undefined) neighbors.push(validTschEnd)
neighbors = this.kdTreeTSCH.FindKNearest(n.pos, 1000, this.Config.value.tx_range)
neighbors.push(...this.kdTreeTSN.FindKNearest(n.pos, 1, 12))
break
}
// TSN bridge connects multiple TSN bridges, 5G tower and end systems
// TSN bridge connects multiple TSN bridges
case NODE_TYPE.TSN: {
const tsnNeighbors = this.kdTree.FindKNearest(n.pos, 1000, this.Config.value.tx_range)
const validTsn = tsnNeighbors.filter(nn => this.Nodes.value[nn]?.type === NODE_TYPE.TSN)
const validFiveGnb = tsnNeighbors.find(nn => this.Nodes.value[nn]?.type === NODE_TYPE.FIVE_G_GNB)
const validTsnEnd = tsnNeighbors.find(nn => this.Nodes.value[nn]?.type >= NODE_TYPE.END_SYSTEM_SERVER)
neighbors.push(...validTsn)
if (validFiveGnb !== undefined) neighbors.push(validFiveGnb)
if (validTsnEnd !== undefined) neighbors.push(validTsnEnd)

neighbors = this.kdTreeTSN.FindKNearest(n.pos, 1000, this.Config.value.tx_range)
break
}
// end system connects to one network node
default: {
const networkNeighbors = this.kdTree.FindKNearest(n.pos, 3, this.Config.value.grid_size)
const validNetwork = networkNeighbors.find(nn =>
this.Nodes.value[nn]?.type === NODE_TYPE.TSN ||
this.Nodes.value[nn]?.type === NODE_TYPE.TSCH ||
this.Nodes.value[nn]?.type === NODE_TYPE.FIVE_G_UE)
if (validNetwork !== undefined) neighbors.push(validNetwork)
neighbors = this.kdTreeAny.FindKNearest(n.pos, 1, this.Config.value.grid_size)
break
}
}
}

n.neighbors = neighbors
Expand Down Expand Up @@ -331,8 +316,7 @@ export class NetworkHub {
id: this.Nodes.value.length,
type: type,
pos: [
Math.floor(this.Rand.next() * this.Config.value.grid_size) -
this.Config.value.grid_size / 2,
Math.floor(this.Rand.next() * this.Config.value.grid_size) - this.Config.value.grid_size / 2,
Math.floor(this.Rand.next() * this.Config.value.grid_size) - this.Config.value.grid_size / 2
],
neighbors: [],
Expand All @@ -347,11 +331,10 @@ export class NetworkHub {

AddLink(v1: number, v2: number) {
if (v1 > v2) {
[v1, v2] = [v2, v1]
;[v1, v2] = [v2, v1]
}
// Cantor pairing
const uid = 0.5 * (v1 + v2) * (v1 + v2 + 1) + v2

let type: number = LINK_TYPE.WIRELESS
if (
this.Nodes.value[v1].type == NODE_TYPE.TSN ||
Expand Down
9 changes: 1 addition & 8 deletions src/core/node_end_system.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Node } from './node'
import {
PKT_TYPE,
type Message,
type Packet,
MSG_TYPE,
type ASNMsgPayload,
type InitMsgPayload
} from './typedefs'
import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs'

class EndSystem extends Node {
constructor() {
Expand Down
9 changes: 1 addition & 8 deletions src/core/node_five_g_gnb.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Node } from './node'
import {
PKT_TYPE,
type Message,
type Packet,
MSG_TYPE,
type ASNMsgPayload,
type InitMsgPayload
} from './typedefs'
import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type ASNMsgPayload, type InitMsgPayload } from './typedefs'

class FiveGBS extends Node {
constructor() {
Expand Down
Loading

0 comments on commit bf4cedd

Please sign in to comment.