Skip to content

Commit ab7d165

Browse files
Update generation of random topologies
1 parent f61351a commit ab7d165

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

nebula/frontend/templates/deployment.html

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ <h5 class="step-title">Topology generation</h5>
283283
</select>
284284
<input type="number" class="form-control" id="predefined-topology-nodes"
285285
placeholder="Number of nodes" min="1" value="3" oninput="greaterthan0(this)" style="display: inline; width: 40%">
286+
<div id="random-topology-options" style="display: none; margin-top: 10px;">
287+
<label for="random-probability">Edge Probability:</label>
288+
<input type="number" class="form-control" id="random-probability"
289+
placeholder="Probability (0-1)" min="0" max="1" step="0.1" value="0.5" style="display: inline; width: 40%">
290+
</div>
286291
</div>
287292
</div>
288293
<div class="form-group row container-shadow tiny grey">
@@ -2355,6 +2360,7 @@ <h5 class="step-title">Schema of deployment</h5>
23552360

23562361

23572362
if ($("#predefined-topology-select").val() === 'Fully') {
2363+
$("#random-topology-options").hide();
23582364
// Update gData: create a link between each node
23592365
for (var i = 0; i < gData.nodes.length; i++) {
23602366
for (var j = 0; j < gData.nodes.length; j++) {
@@ -2366,6 +2372,7 @@ <h5 class="step-title">Schema of deployment</h5>
23662372
}
23672373
// If networkTopology is changed to Ring, gData is updated to a ring graph
23682374
else if ($("#predefined-topology-select").val() === 'Ring') {
2375+
$("#random-topology-options").hide();
23692376
// Update gData: create a link between each node and its two neighbors
23702377
for (var i = 0; i < gData.nodes.length; i++) {
23712378
gData.links.push({ source: i, target: (i + 1) % gData.nodes.length });
@@ -2374,19 +2381,24 @@ <h5 class="step-title">Schema of deployment</h5>
23742381
}
23752382
// If networkTopology is changed to Star, gData is updated to a star graph
23762383
else if ($("#predefined-topology-select").val() === 'Star') {
2384+
$("#random-topology-options").hide();
23772385
// Update gData: create a link between each node and the central node
23782386
for (var i = 0; i < gData.nodes.length; i++) {
23792387
gData.links.push({ source: i, target: 0 });
23802388
}
23812389
} else if ($("#predefined-topology-select").val() === 'Random') {
2382-
// Update gData: create a link between each node and a random node
2383-
for (var i = 0; i < gData.nodes.length; i++) {
2384-
var randomNode = Math.floor(Math.random() * gData.nodes.length);
2385-
while (randomNode === i) {
2386-
randomNode = Math.floor(Math.random() * gData.nodes.length);
2387-
}
2388-
gData.links.push({ source: i, target: randomNode });
2389-
}
2390+
// Show probability input
2391+
$("#random-topology-options").show();
2392+
const probability = parseFloat($("#random-probability").val());
2393+
2394+
// Clear existing links
2395+
gData.links = [];
2396+
2397+
// Generate random links using Erdős-Rényi model
2398+
gData.links = generateRandomLinks(gData.nodes, probability);
2399+
} else {
2400+
// Hide probability input
2401+
$("#random-topology-options").hide();
23902402
}
23912403

23922404
if (document.getElementById("predefined-topology-nodes").value > 10) {

0 commit comments

Comments
 (0)