Skip to content

Commit

Permalink
add stats subscribe/report and clean codes
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Feb 4, 2024
1 parent 55a039c commit 322013e
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 271 deletions.
32 changes: 21 additions & 11 deletions src/components/NodeStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,45 @@
import sensortag from '@/assets/sensortag.png'
import tsn_switch from '@/assets/tsn_switch.png'
import five_g_gnb from '@/assets/five_g_gnb.png'
import { Network, SelectedNode } from '@/hooks/useStates'
import { Network } from '@/hooks/useStates'
import { NODE_TYPE, NODE_TYPE_DISPLAY_NAME } from '@/core/typedefs'
import { Picture } from '@element-plus/icons-vue'
const images: { [type: number]: string } = {
const avatars: { [type: number]: string } = {
[NODE_TYPE.TSCH]: sensortag,
[NODE_TYPE.TSN]: tsn_switch,
[NODE_TYPE.FIVE_G_GNB]: five_g_gnb
}
</script>

<template>
<el-card class="card" v-if="SelectedNode > 0 && Network.Nodes.value[SelectedNode] != undefined">
<el-card class="card" v-if="Network.StatsPublisherNode.value > 0 && Network.NodeStats.value != undefined">
<el-row :gutter="30">
<el-col :span="11" align="center">
<el-image class="image" :src="images[Network.Nodes.value[SelectedNode].type]">
<el-col :span="12" align="center">
<el-image class="avatar" :src="avatars[Network.Nodes.value[Network.StatsPublisherNode.value].type]">
<template #error>
<div class="image">
<div class="avatar">
<el-icon><Picture /></el-icon>
</div>
</template>
</el-image>
</el-col>
<el-col :span="10">
<el-col :span="12">
<span class="stats">
{{ NODE_TYPE_DISPLAY_NAME[Network.Nodes.value[SelectedNode].type] }}-{{ SelectedNode }}
{{ NODE_TYPE_DISPLAY_NAME[Network.Nodes.value[Network.StatsPublisherNode.value].type] }}-{{
Network.StatsPublisherNode.value
}}
</span>
<br />
- TX: {{ Network.Nodes.value[SelectedNode].tx_cnt }} , RX: {{ Network.Nodes.value[SelectedNode].rx_cnt }}<br />
- TX: {{ Network.NodeStats.value.tx_cnt }} , RX: {{ Network.NodeStats.value.rx_cnt }}<br />
- Queue length: {{ Network.NodeStats.value.queue_len }} <br />
- Queue head:
{{
Network.NodeStats.value.queue_head != undefined
? 'Pkt 0x' + Network.NodeStats.value.queue_head.toString(16).toUpperCase().padStart(4, '0')
: undefined
}}
<br />
</el-col>
</el-row>
</el-card>
Expand All @@ -40,10 +50,10 @@ const images: { [type: number]: string } = {
.card {
/* margin-top: 2px; */
height: 130px;
/* width: 380px; */
font-size: 0.82rem;
}
.image {
.avatar {
height: 110px;
font-size: 36px;
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/TopoEditToolbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ const nodeTypes = [
}
]
const { nodeId1, nodeId2 } = toRefs({
nodeId1: ref(''),
nodeId2: ref('')
})
const nodeId1 = ref('')
const nodeId2 = ref('')
const addNode = () => {
Network.AddNode(nodeType.value)
Expand Down
34 changes: 23 additions & 11 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {
PROTOCOL_TYPE,
type RoutingGraph,
type RoutingMsgPayload,
type FlowMsgPayload
type FlowMsgPayload,
type StatsSubscribePayload
} from './typedefs'
import { SeededRandom } from '@/utils/rand'
import type { NodeStats } from './typedefs/stats'

export class NetworkHub {
Config: Ref<Config>
Expand All @@ -41,6 +43,9 @@ export class NetworkHub {
SelectedTopo = ref('5G-TSN-TSCH') // realistic topo example
// SelectedTopo = ref('Routing test') // realistic topo example

StatsPublisherNode = ref(0)
NodeStats = ref<NodeStats | undefined>(undefined) // stats from the publisher node

asnTimer: any
SignalReset = ref(0)
SlotDone = ref(false)
Expand Down Expand Up @@ -71,6 +76,21 @@ export class NetworkHub {
this.LoadTopology()
})

watch(this.StatsPublisherNode, (newN, oldN) => {
if (oldN > 0 && this.Nodes.value[oldN] != undefined) {
this.Nodes.value[oldN].w!.postMessage(<Message>{
type: MSG_TYPE.STATS_SUBSCRIBE,
payload: <StatsSubscribePayload>{ flag: false }
})
}
if (this.Nodes.value[newN] != undefined) {
this.Nodes.value[newN].w!.postMessage(<Message>{
type: MSG_TYPE.STATS_SUBSCRIBE,
payload: <StatsSubscribePayload>{ flag: true }
})
}
})

watch(this.ASN, () => {
if (this.ASN.value > 0) {
this.doneCnt = 0
Expand Down Expand Up @@ -99,7 +119,8 @@ export class NetworkHub {
this.SlotDone.value = true
}
break
case MSG_TYPE.STAT:
case MSG_TYPE.STATS_REPORT:
this.NodeStats.value = msg.payload
break
}
}
Expand Down Expand Up @@ -139,8 +160,6 @@ export class NetworkHub {
}
pkt.asn = this.ASN.value
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
Expand Down Expand Up @@ -188,8 +207,6 @@ export class NetworkHub {
Math.floor(this.Rand.next() * this.Config.value.grid_size) - this.Config.value.grid_size / 2
],
neighbors: [],
tx_cnt: 0,
rx_cnt: 0,
w: undefined
}
this.Nodes.value.push(n)
Expand All @@ -201,8 +218,6 @@ export class NetworkHub {
id: n.id,
type: n.type,
pos: n.pos,
tx_cnt: 0,
rx_cnt: 0,
neighbors: <number[]>[]
})
}
Expand Down Expand Up @@ -332,7 +347,6 @@ export class NetworkHub {

n.w.postMessage(<Message>{
type: MSG_TYPE.INIT,
id: n.id,
payload: <InitMsgPayload>{ id: n.id, neighbors: toRaw(n.neighbors) }
})

Expand All @@ -346,7 +360,6 @@ export class NetworkHub {
}
n.w.postMessage(<Message>{
type: MSG_TYPE.ROUTING,
id: n.id,
payload: toRaw(routingTable)
})

Expand All @@ -355,7 +368,6 @@ export class NetworkHub {
if (flows.length > 0) {
n.w.postMessage(<Message>{
type: MSG_TYPE.FLOW,
id: n.id,
payload: <FlowMsgPayload>{ flows: flows }
})
}
Expand Down
41 changes: 7 additions & 34 deletions src/core/nodes/end_system.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
import { Node } from './node'
import {
PKT_TYPE,
type Message,
type Packet,
MSG_TYPE,
type ASNMsgPayload,
type InitMsgPayload,
type FlowMsgPayload,
type Flow,
type RoutingMsgPayload
} from '../typedefs'
import { PKT_TYPE, type Message, type Packet, MSG_TYPE, type FlowMsgPayload, type Flow } from '../typedefs'

class EndSystem extends Node {
flows: Flow[] = []
constructor() {
super()
this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler)
this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler)
this.registerMsgHandler(MSG_TYPE.FLOW, this.flowMsgHandler)
this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler)

this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler)
}
initMsgHandler = (msg: Message) => {
const payload: InitMsgPayload = msg.payload
this.id = payload.id
this.neighbors = payload.neighbors
}
asnMsgHandler = (msg: Message) => {
const payload: ASNMsgPayload = msg.payload
this.ASN = payload.asn

// do something
action = () => {
for (const flow of this.flows) {
if (this.ASN % flow.period == 1) {
this.queue.push(<Packet>{
Expand All @@ -50,22 +27,18 @@ class EndSystem extends Node {
if (this.queue.length > 0) {
const pkt = this.queue.pop()
postMessage(pkt)
this.tx_cnt++
}

postMessage(<Message>{
type: MSG_TYPE.DONE
})
}

flowMsgHandler = (msg: Message) => {
const payload: FlowMsgPayload = msg.payload
this.flows = payload.flows
}
routingMsgHandler = (msg: Message) => {
const payload: RoutingMsgPayload = msg.payload
this.routingTable = payload
}

dataPktHandler = (pkt: Packet) => {
// console.log('received', pkt)
console.log('received', pkt.uid)
this.rx_cnt++
}
}

Expand Down
47 changes: 0 additions & 47 deletions src/core/nodes/five_g_gnb.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
import { Node } from './node'
import {
PKT_TYPE,
type Message,
type Packet,
MSG_TYPE,
type ASNMsgPayload,
type InitMsgPayload,
type RoutingMsgPayload
} from '../typedefs'

class FiveGBS extends Node {
constructor() {
super()
this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler)
this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler)
this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler)
this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler)
}
initMsgHandler = (msg: Message) => {
const payload: InitMsgPayload = msg.payload
this.id = payload.id
this.neighbors = payload.neighbors
}
asnMsgHandler = (msg: Message) => {
const payload: ASNMsgPayload = msg.payload
this.ASN = payload.asn

// do something
if (this.queue.length > 0) {
const pkt = this.queue.pop()
postMessage(pkt)
}

postMessage(<Message>{
type: MSG_TYPE.DONE
})
}
routingMsgHandler = (msg: Message) => {
const payload: RoutingMsgPayload = msg.payload
this.routingTable = payload
}
dataPktHandler = (pkt: Packet) => {
if (pkt.e2e_dst != this.id) {
if (this.routingTable[pkt.e2e_dst] != undefined) {
pkt.mac_src = this.id
pkt.mac_dst = this.routingTable[pkt.e2e_dst]
this.queue.push(pkt)
} else {
console.log(`[v${this.id}] cannot find next hop for dst ${pkt.e2e_dst}}`)
}
}
}
}

Expand Down
47 changes: 0 additions & 47 deletions src/core/nodes/five_g_ue.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
import { Node } from './node'
import {
PKT_TYPE,
type Message,
type Packet,
MSG_TYPE,
type ASNMsgPayload,
type InitMsgPayload,
type RoutingMsgPayload
} from '../typedefs'

class FiveGUE extends Node {
constructor() {
super()
this.registerMsgHandler(MSG_TYPE.INIT, this.initMsgHandler)
this.registerMsgHandler(MSG_TYPE.ASN, this.asnMsgHandler)
this.registerMsgHandler(MSG_TYPE.ROUTING, this.routingMsgHandler)
this.registerPktHandler(PKT_TYPE.DATA, this.dataPktHandler)
}
initMsgHandler = (msg: Message) => {
const payload: InitMsgPayload = msg.payload
this.id = payload.id
this.neighbors = payload.neighbors
}
asnMsgHandler = (msg: Message) => {
const payload: ASNMsgPayload = msg.payload
this.ASN = payload.asn

// do something
if (this.queue.length > 0) {
const pkt = this.queue.pop()
postMessage(pkt)
}

postMessage(<Message>{
type: MSG_TYPE.DONE
})
}
routingMsgHandler = (msg: Message) => {
const payload: RoutingMsgPayload = msg.payload
this.routingTable = payload
}
dataPktHandler = (pkt: Packet) => {
if (pkt.e2e_dst != this.id) {
if (this.routingTable[pkt.e2e_dst] != undefined) {
pkt.mac_src = this.id
pkt.mac_dst = this.routingTable[pkt.e2e_dst]
this.queue.push(pkt)
} else {
console.log(`[v${this.id}] cannot find next hop for dst ${pkt.e2e_dst}}`)
}
}
}
}
new FiveGUE().Run()
Loading

0 comments on commit 322013e

Please sign in to comment.