mirror of
https://github.com/wisplite/BLE-mesh-sim.git
synced 2026-10-30 13:32:21 -05:00
fixed button style regression that happened ages ago, and added optimized quick packet mode
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
<div id="controlButtons">
|
<div id="controlButtons">
|
||||||
<button id="addNode" class="controlButton">Add Node</button>
|
<button id="addNode" class="controlButton">Add Node</button>
|
||||||
<button id="sendPacket" class="controlButton">Send Packet</button>
|
<button id="sendPacket" class="controlButton">Send Packet</button>
|
||||||
|
<button id="quickPacket" class="controlButton">Quick Packet</button>
|
||||||
<button id="resetTTLColors" class="controlButton">Reset TTL Colors</button>
|
<button id="resetTTLColors" class="controlButton">Reset TTL Colors</button>
|
||||||
<button id="createRandomGraph" class="controlButton">Create Random Network</button>
|
<button id="createRandomGraph" class="controlButton">Create Random Network</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ onEdgeEngine.setArrivalCallback(({ from, to, dot }) => {
|
|||||||
// update color of receiving node for visualization
|
// update color of receiving node for visualization
|
||||||
nodeTable[to].packetCache.push(dot.id.split('-')[0]);
|
nodeTable[to].packetCache.push(dot.id.split('-')[0]);
|
||||||
var packetId = dot.id.split('-')[0];
|
var packetId = dot.id.split('-')[0];
|
||||||
|
var originNode = dot.id.split('-')[3];
|
||||||
ttl--;
|
ttl--;
|
||||||
if (document.getElementById('showTTL').checked) {
|
if (document.getElementById('showTTL').checked) {
|
||||||
nodes.update({id: to, color: {background: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}});
|
nodes.update({id: to, color: {background: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}});
|
||||||
@@ -121,12 +122,12 @@ onEdgeEngine.setArrivalCallback(({ from, to, dot }) => {
|
|||||||
if (ttl > 0) {
|
if (ttl > 0) {
|
||||||
const neighborsSnapshot = nodeTable[to].outgoing.slice();
|
const neighborsSnapshot = nodeTable[to].outgoing.slice();
|
||||||
for (let neighbor of neighborsSnapshot) {
|
for (let neighbor of neighborsSnapshot) {
|
||||||
if (neighbor === from) {
|
if (neighbor === from || neighbor === originNode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var packetShift = generateRealisticLabel();
|
var packetShift = generateRealisticLabel();
|
||||||
var movingNode = {
|
var movingNode = {
|
||||||
id: `${packetId}-${packetShift}-${ttl}`,
|
id: `${packetId}-${packetShift}-${ttl}-${originNode}`,
|
||||||
label: packetId + `-${ttl}`,
|
label: packetId + `-${ttl}`,
|
||||||
shape: dot.shape,
|
shape: dot.shape,
|
||||||
size: dot.size,
|
size: dot.size,
|
||||||
@@ -144,6 +145,45 @@ onEdgeEngine.setArrivalCallback(({ from, to, dot }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function quickPacket(startNode, packetInfo, fromNode) {
|
||||||
|
const packetId = packetInfo.split('-')[0];
|
||||||
|
const ttlStart = parseInt(packetInfo.split('-')[2]);
|
||||||
|
const originNode = packetInfo.split('-')[3];
|
||||||
|
|
||||||
|
const queue = [{ nodeId: startNode, ttl: ttlStart, from: fromNode }];
|
||||||
|
|
||||||
|
while (queue.length > 0) {
|
||||||
|
const { nodeId, ttl, from } = queue.shift();
|
||||||
|
|
||||||
|
if (ttl < 0) {
|
||||||
|
markNeighborsAsFailed(nodeId, from, packetId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (nodeTable[nodeId]?.packetCache?.includes(packetId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeTable[nodeId].packetCache.push(packetId);
|
||||||
|
|
||||||
|
if (document.getElementById('showTTL').checked) {
|
||||||
|
nodes.update({id: nodeId, color: {background: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}});
|
||||||
|
edges.update({id: `${from}->${nodeId}`, color: {color: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl+1), highlight: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}});
|
||||||
|
} else {
|
||||||
|
nodes.update({id: nodeId, color: {background: '#97c2fc'}});
|
||||||
|
edges.update({id: `${from}->${nodeId}`, color: {color: '#2b7ce9', highlight: '#2b7ce9'}});
|
||||||
|
}
|
||||||
|
|
||||||
|
const neighborsSnapshot = (nodeTable[nodeId]?.outgoing?.slice()) || [];
|
||||||
|
|
||||||
|
for (let neighbor of neighborsSnapshot) {
|
||||||
|
if (neighbor === originNode || neighbor === from) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
queue.push({ nodeId: neighbor, ttl: ttl - 1, from: nodeId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
||||||
if (visited.has(nodeId)) {
|
if (visited.has(nodeId)) {
|
||||||
return;
|
return;
|
||||||
@@ -435,7 +475,9 @@ function onNodeAdd() {
|
|||||||
document.getElementById('warningModal').style.display = 'block';
|
document.getElementById('warningModal').style.display = 'block';
|
||||||
document.getElementById('warningModalMessage').innerHTML = 'Large network detected; simulation speed will be reduced.';
|
document.getElementById('warningModalMessage').innerHTML = 'Large network detected; simulation speed will be reduced.';
|
||||||
document.getElementById('warningModalCustomContent').innerHTML = `<details><summary>What does this mean?</summary>
|
document.getElementById('warningModalCustomContent').innerHTML = `<details><summary>What does this mean?</summary>
|
||||||
<p>The simulation, by default, computes every node's connections 100 'times' per second. Due to the size of this network, this could cause the browser to freeze. To prevent this, the update interval (found in engine settings) is now locked to a multiple of the number of nodes. Additionally, when computing which nodes weren't reached after a packet is sent, the simulation will now walk through the network in steps rather than computing everything at once.</p>`;
|
<p>The simulation, by default, computes every node's connections 100 'times' per second. Due to the size of this network, this could cause the browser to freeze. To prevent this, the update interval (found in engine settings) is now locked to a multiple of the number of nodes. Additionally, when computing which nodes weren't reached after a packet is sent, the simulation will now walk through the network in steps rather than computing everything at once.</p>
|
||||||
|
<br>
|
||||||
|
<p>You may also want to consider using the quick packet feature, which will compute the packet propagation instantly rather than animating it. The animated nodes can cause lots of performance issues, especially on non-Chromium browsers.</p>`;
|
||||||
document.getElementById('updateInterval').disabled = true;
|
document.getElementById('updateInterval').disabled = true;
|
||||||
document.getElementById('updateInterval').value = nodeLength*2;
|
document.getElementById('updateInterval').value = nodeLength*2;
|
||||||
UPDATE_INTERVAL = nodeLength*2;
|
UPDATE_INTERVAL = nodeLength*2;
|
||||||
@@ -490,7 +532,7 @@ document.getElementById('sendPacket').addEventListener('click', function() {
|
|||||||
nodes.update({id: selectedNode, color: {background: '#97c2fc'}});
|
nodes.update({id: selectedNode, color: {background: '#97c2fc'}});
|
||||||
for (let connection of nodeTable[selectedNode].outgoing) {
|
for (let connection of nodeTable[selectedNode].outgoing) {
|
||||||
var movingNode = {
|
var movingNode = {
|
||||||
id: `${packetId}-${packetShift}-${ttl}`,
|
id: `${packetId}-${packetShift}-${ttl}-${selectedNode}`,
|
||||||
label: packetId + `-${ttl}`,
|
label: packetId + `-${ttl}`,
|
||||||
shape: 'dot',
|
shape: 'dot',
|
||||||
size: 6,
|
size: 6,
|
||||||
@@ -594,6 +636,16 @@ document.getElementById('darkMode').addEventListener('change', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('quickPacket').addEventListener('click', async function() {
|
||||||
|
if (selectedNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const packetId = generateRealisticLabel();
|
||||||
|
var packetShift = generateRealisticLabel();
|
||||||
|
let ttl = TTL;
|
||||||
|
quickPacket(selectedNode, `${packetId}-${packetShift}-${ttl}-${selectedNode}`, selectedNode);
|
||||||
|
});
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (localStorage.getItem('darkMode') === 'true') {
|
if (localStorage.getItem('darkMode') === 'true') {
|
||||||
document.getElementById('darkMode').checked = true;
|
document.getElementById('darkMode').checked = true;
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ html, body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
width: 100%;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user