Skip to content

Commit

Permalink
adding packet validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Jan 7, 2024
1 parent 4ce947d commit f28f892
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
25 changes: 15 additions & 10 deletions src/components/TopoEditToolbox.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Network, SignalEditTopology, SignalAddNode,SignalUpdateLinks } from '@/hooks/useStates'
import { Network, SignalEditTopology, SignalAddNode, SignalUpdateLinks } from '@/hooks/useStates'
import { Check, Plus, Switch } from '@element-plus/icons-vue'
import { NODE_TYPE } from '@/core/typedefs'
const nodeType = ref(0)
// must follow NODE_TYPE enum defined in '@/core/typedefs'
const nodeTypes = [
{
label: 'Network devices',
types: [
{ label: 'TSCH node', value: 0 },
{ label: 'TSN bridge', value: 1 },
{ label: '5G tower', value: 2 },
{ label: '5G UE', value: 3 }
{ label: 'TSCH node', value: NODE_TYPE.TSCH },
{ label: 'TSN bridge', value: NODE_TYPE.TSN },
{ label: '5G gNB', value: NODE_TYPE.FIVE_G_GNB },
{ label: '5G UE', value: NODE_TYPE.FIVE_G_UE }
]
},
{
label: 'End systems',
types: [
{ label: 'Edge server', value: 11 },
{ label: 'Sensor', value: 12 },
{ label: 'Robotic arm', value: 13 }
{ label: 'Edge server', value: NODE_TYPE.END_SYSTEM_SENSOR },
{ label: 'Sensor', value: NODE_TYPE.END_SYSTEM_SENSOR },
{ label: 'Robotic arm', value: NODE_TYPE.END_SYSTEM_ROBOTIC_ARM }
]
}
]
Expand All @@ -44,7 +44,12 @@ 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>

Expand Down
52 changes: 39 additions & 13 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class NetworkHub {
kdTree: KDTree // to find nearest neighbors

PresetTopos: { [name: string]: any } = presetTopos
SelectedTopo = ref('5G single-cell')
SelectedTopo = ref('Random')

asnTimer: any
SignalReset = ref(0)
Expand Down Expand Up @@ -85,8 +85,6 @@ export class NetworkHub {

// forward physical layer pkt from each node
handlePkt = (pkt: Packet) => {
this.Nodes.value[pkt.mac_dst].w!.postMessage(pkt)

// check protocol type
if (
this.Nodes.value[pkt.mac_src].type == NODE_TYPE.TSCH ||
Expand All @@ -108,17 +106,39 @@ export class NetworkHub {
) {
pkt.protocol = PROTOCOL_TYPE.FIVE_G
}
// must use this format for the detailedView function of el-table-v2
pkt.id = this.Packets.value.length
pkt.children = [
{
id: `${this.Packets.value.length}-detail-content`,
detail: JSON.stringify(pkt.payload).replace(/"/g, '')
}
]

this.Packets.value.push(pkt)
this.PacketsCurrent.value.push(pkt)
let isValid: boolean = false
// To-do: validate packet and check interference
switch (pkt.protocol) {
case PROTOCOL_TYPE.TSN:
isValid = true
break
case PROTOCOL_TYPE.TSCH:
isValid = true
break
case PROTOCOL_TYPE.FIVE_G:
break
default:
isValid = true
}

if (isValid) {
this.Nodes.value[pkt.mac_src].tx_cnt++
this.Nodes.value[pkt.mac_dst].rx_cnt++
this.Nodes.value[pkt.mac_dst].w!.postMessage(pkt)

// must use this format for the detailedView function of el-table-v2
pkt.id = this.Packets.value.length
pkt.children = [
{
id: `${this.Packets.value.length}-detail-content`,
detail: JSON.stringify(pkt.payload).replace(/"/g, '')
}
]

this.Packets.value.push(pkt)
this.PacketsCurrent.value.push(pkt)
}
}
clearNodes() {
for (const n of this.Nodes.value) {
Expand All @@ -131,6 +151,12 @@ export class NetworkHub {
this.Links.value = []
}
LoadTopology() {
this.Running.value = false
clearInterval(this.asnTimer)
this.Links.value = []
this.Packets.value = []
this.PacketsCurrent.value = []
this.ASN.value = 0
this.clearNodes()

if (this.SelectedTopo.value == 'Random') {
Expand Down

0 comments on commit f28f892

Please sign in to comment.