mirror of
https://github.com/wisplite/BLE-mesh-sim.git
synced 2026-10-30 13:32:21 -05:00
some patches to moveonedge to trigger a callback rather than using forward tables
This commit is contained in:
+11
-3
@@ -13,6 +13,7 @@ class CompleteNodeOnEdgeEngine {
|
|||||||
this.edges = edges;
|
this.edges = edges;
|
||||||
this.dotNodes = dotNodes;
|
this.dotNodes = dotNodes;
|
||||||
this.forwTable = forwTable;
|
this.forwTable = forwTable;
|
||||||
|
this.onArrival = null;
|
||||||
|
|
||||||
|
|
||||||
this.linksByEdges = {};
|
this.linksByEdges = {};
|
||||||
@@ -30,6 +31,10 @@ class CompleteNodeOnEdgeEngine {
|
|||||||
this.targetInterval = this.time_delay;
|
this.targetInterval = this.time_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setArrivalCallback(callback) {
|
||||||
|
this.onArrival = callback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the movement of the nodes on edges.
|
* Initializes the movement of the nodes on edges.
|
||||||
*/
|
*/
|
||||||
@@ -143,9 +148,9 @@ class CompleteNodeOnEdgeEngine {
|
|||||||
this.maxTime = Math.max(this.maxTime, this.currentTime);
|
this.maxTime = Math.max(this.maxTime, this.currentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("currenttime").innerHTML = this.currentTime/1000;
|
/*document.getElementById("currenttime").innerHTML = this.currentTime/1000;
|
||||||
document.getElementById("ratio_inc").innerHTML = this.ratio_inc/100;
|
document.getElementById("ratio_inc").innerHTML = this.ratio_inc/100;
|
||||||
document.getElementById("maxtime").innerHTML = this.maxTime/1000;
|
document.getElementById("maxtime").innerHTML = this.maxTime/1000;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,7 +191,10 @@ class CompleteNodeOnEdgeEngine {
|
|||||||
dotNode.ratio += current_ratio;
|
dotNode.ratio += current_ratio;
|
||||||
if (dotNode.ratio > 100) {
|
if (dotNode.ratio > 100) {
|
||||||
this.traces_table[dotNode.id].push(dotNode.target);
|
this.traces_table[dotNode.id].push(dotNode.target);
|
||||||
if (!this.updateDotNode(dotNode, dotNode.target, this.forwTable[dotNode.target][dotNode.source], dotNode.ratio - 100)) {
|
if (typeof this.onArrival === 'function') {
|
||||||
|
try {
|
||||||
|
this.onArrival({ from: dotNode.source, to: dotNode.target, dot: dotNode });
|
||||||
|
} catch (e) {}
|
||||||
this.dotNodes.remove(dotNode, time);
|
this.dotNodes.remove(dotNode, time);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,20 @@ var options = {
|
|||||||
var network = new vis.Network(container, data, options);
|
var network = new vis.Network(container, data, options);
|
||||||
let selectedNode = null;
|
let selectedNode = null;
|
||||||
|
|
||||||
|
var dotNodes = new vis.DataSet([
|
||||||
|
]);
|
||||||
|
|
||||||
|
var forwardTable = {};
|
||||||
|
|
||||||
|
var onEdgeEngine = new CompleteNodeOnEdgeEngine(network, nodes, dotNodes, edges, forwardTable);
|
||||||
|
onEdgeEngine.createEdgesTable();
|
||||||
|
onEdgeEngine.initMovement();
|
||||||
|
onEdgeEngine.setArrivalCallback(({ from, to, dot }) => {
|
||||||
|
// Example: log arrival; dot removal is handled by engine
|
||||||
|
// For flood behavior, you can spawn new dots here if needed
|
||||||
|
console.log(`Dot ${dot.id} arrived from ${from} to ${to}`);
|
||||||
|
});
|
||||||
|
|
||||||
function nodeSelectUpdateHandler(properties) {
|
function nodeSelectUpdateHandler(properties) {
|
||||||
// get containers
|
// get containers
|
||||||
const incomingTable = document.getElementById('incomingConnections');
|
const incomingTable = document.getElementById('incomingConnections');
|
||||||
@@ -177,6 +191,9 @@ function main() {
|
|||||||
const currentNodesKeys = Object.keys(currentNodes);
|
const currentNodesKeys = Object.keys(currentNodes);
|
||||||
for (let node1 of currentNodesKeys) {
|
for (let node1 of currentNodesKeys) {
|
||||||
let neighbors = [];
|
let neighbors = [];
|
||||||
|
if (!nodeTable[node1]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (let node2 of currentNodesKeys) {
|
for (let node2 of currentNodesKeys) {
|
||||||
if (node1 !== node2) {
|
if (node1 !== node2) {
|
||||||
const node1data = currentNodes[node1];
|
const node1data = currentNodes[node1];
|
||||||
@@ -199,6 +216,9 @@ function main() {
|
|||||||
}
|
}
|
||||||
const scores = [];
|
const scores = [];
|
||||||
for (let neighbor of neighbors) {
|
for (let neighbor of neighbors) {
|
||||||
|
if (!nodeTable[neighbor.node]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let connectionScore = 0;
|
let connectionScore = 0;
|
||||||
let dropScore = 0;
|
let dropScore = 0;
|
||||||
connectionScore += (100 + neighbor.distance);
|
connectionScore += (100 + neighbor.distance);
|
||||||
@@ -276,3 +296,24 @@ document.getElementById('addNode').addEventListener('click', function() {
|
|||||||
nodes.add({id: nodeId, label: nodeId});
|
nodes.add({id: nodeId, label: nodeId});
|
||||||
nodeTable[nodeId] = {'incoming': [], 'outgoing': []};
|
nodeTable[nodeId] = {'incoming': [], 'outgoing': []};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('sendPacket').addEventListener('click', function() {
|
||||||
|
onEdgeEngine.createEdgesTable();
|
||||||
|
onEdgeEngine.initMovement();
|
||||||
|
const packetId = generateRealisticLabel();
|
||||||
|
const packetShift = 0;
|
||||||
|
for (let connection of nodeTable[selectedNode].outgoing) {
|
||||||
|
var movingNode = {
|
||||||
|
id: packetId + packetShift,
|
||||||
|
label: packetId,
|
||||||
|
shape: 'dot',
|
||||||
|
size: 6,
|
||||||
|
color: {
|
||||||
|
background: 'white',
|
||||||
|
border: 'black'
|
||||||
|
},
|
||||||
|
};
|
||||||
|
onEdgeEngine.createDotNode(movingNode, selectedNode, connection);
|
||||||
|
packetShift++;
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user