-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add stats subscribe/report and clean codes
- Loading branch information
Showing
16 changed files
with
172 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.