Skip to content

Commit

Permalink
added type checking for nodes in EstablishConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Medrek authored and Jack Medrek committed Jan 8, 2024
1 parent 4da0a48 commit 39a4960
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,61 @@ export class NetworkHub {
let neighbors: any = []

switch (n.type) {
// 5G UE connects to one 5G tower and wired end systems
// 5G UE connects to one 5G tower and multiple wired end systems
case NODE_TYPE.FIVE_G_UE:
neighbors = this.kdTree.FindKNearest(n.pos, 1, 20)
break
const ueBsNeighbors = this.kdTree.FindKNearest(n.pos, 1, 20)
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)

// 5G tower / base station connects one TSN bridge and end systems + multiple 5G UEs
case NODE_TYPE.FIVE_G_BS:
neighbors = this.kdTree.FindKNearest(n.pos, 1000, 20) // k = 1000, arbitrarily large
break

// 5G GNB connects to a TSN, an end system, and multiple 5G UEs
case NODE_TYPE.FIVE_G_GNB:
const bsNeighbors = this.kdTree.FindKNearest(n.pos, 1, 20)
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, 20)
const validUes = gnbUeNeighbors.filter(nn => this.Nodes.value[nn].type === NODE_TYPE.FIVE_G_UE)
neighbors.push(...validUes)

break

// TSCH node connects to multiple other TSCH nodes and wired end systems
case NODE_TYPE.TSCH:
neighbors = this.kdTree.FindKNearest(n.pos, 4, 20)
const tschNeighbors = this.kdTree.FindKNearest(n.pos, 1000, 20)
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)
break

// TSN bridge connects multiple TSN bridges, 5G tower and end systems
case NODE_TYPE.TSN:
neighbors = this.kdTree.FindKNearest(n.pos, 4, 20)
const tsnNeighbors = this.kdTree.FindKNearest(n.pos, 1000, 20)
const validTsn = tsnNeighbors.filter(nn => this.Nodes.value[nn].type === NODE_TYPE.TSN)
const validTsnGnb = 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 (validTsnGnb !== undefined) neighbors.push(validTsnGnb)
if (validTsnEnd !== undefined) neighbors.push(validTsnEnd)

break

// end system connects to one network node
default:
neighbors = this.kdTree.FindKNearest(n.pos, 1, 20)
const networkNeighbors = this.kdTree.FindKNearest(n.pos, 1, 20)
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)
break
}

Expand Down Expand Up @@ -310,7 +342,7 @@ 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
Expand Down

0 comments on commit 39a4960

Please sign in to comment.