|
1 | 1 | // Scenario Management Module |
2 | | -const ScenarioManager = (function() { |
| 2 | +const ScenarioManager = (function () { |
3 | 3 | let scenariosList = []; |
4 | 4 | let actual_scenario = 0; |
5 | | - let physical_ips = []; |
| 5 | + let physical_ips = []; |
6 | 6 |
|
7 | 7 | // Initialize scenarios from session storage |
8 | 8 | function initializeScenarios() { |
@@ -151,28 +151,7 @@ const ScenarioManager = (function() { |
151 | 151 | document.getElementById("rounds").value = scenario.rounds; |
152 | 152 |
|
153 | 153 | // Load topology |
154 | | - if (scenario.nodes && scenario.nodes_graph) { |
155 | | - const topologyData = { |
156 | | - nodes: Object.values(scenario.nodes), |
157 | | - links: [] |
158 | | - }; |
159 | | - |
160 | | - // Reconstruct links from the nodes' neighbors |
161 | | - topologyData.nodes.forEach(node => { |
162 | | - if (node.neighbors) { |
163 | | - node.neighbors.forEach(neighborId => { |
164 | | - topologyData.links.push({ |
165 | | - source: node.id, |
166 | | - target: neighborId |
167 | | - }); |
168 | | - }); |
169 | | - } |
170 | | - }); |
171 | 154 |
|
172 | | - window.TopologyManager.setData(topologyData); |
173 | | - } else { |
174 | | - window.TopologyManager.generatePredefinedTopology(); |
175 | | - } |
176 | 155 |
|
177 | 156 | /* if "physical" assign the IPs again*/ |
178 | 157 | if (scenario.physical_ips) { |
@@ -247,6 +226,30 @@ const ScenarioManager = (function() { |
247 | 226 | document.getElementById("federationArchitecture").dispatchEvent(new Event('change')); |
248 | 227 | document.getElementById("datasetSelect").dispatchEvent(new Event('change')); |
249 | 228 | document.getElementById("iidSelect").dispatchEvent(new Event('change')); |
| 229 | + |
| 230 | + // Load topology last to avoid overwrites by event handlers |
| 231 | + if (scenario.nodes && scenario.nodes_graph) { |
| 232 | + const topologyData = { |
| 233 | + nodes: Object.values(scenario.nodes), |
| 234 | + links: [] |
| 235 | + }; |
| 236 | + |
| 237 | + // Reconstruct links from the nodes' neighbors |
| 238 | + topologyData.nodes.forEach(node => { |
| 239 | + if (node.neighbors) { |
| 240 | + node.neighbors.forEach(neighborId => { |
| 241 | + topologyData.links.push({ |
| 242 | + source: node.id, |
| 243 | + target: neighborId |
| 244 | + }); |
| 245 | + }); |
| 246 | + } |
| 247 | + }); |
| 248 | + |
| 249 | + window.TopologyManager.setData(topologyData); |
| 250 | + } else { |
| 251 | + window.TopologyManager.generatePredefinedTopology(); |
| 252 | + } |
250 | 253 | } |
251 | 254 |
|
252 | 255 | function saveScenario() { |
@@ -353,16 +356,16 @@ const ScenarioManager = (function() { |
353 | 356 | function setPhysicalIPs(ipList = []) { |
354 | 357 | physical_ips = [...ipList]; |
355 | 358 | } |
356 | | - |
| 359 | + |
357 | 360 | function setActualScenario(index) { |
358 | 361 | actual_scenario = index; |
359 | 362 | if (scenariosList[index]) { |
360 | 363 | // Clear the current graph |
361 | 364 | window.TopologyManager.clearGraph(); |
362 | | - |
| 365 | + |
363 | 366 | // Load new scenario data |
364 | 367 | loadScenarioData(scenariosList[index]); |
365 | | - |
| 368 | + |
366 | 369 | // If physical deployment, set physical IPs |
367 | 370 | if (scenariosList[index].deployment === 'physical' && scenariosList[index].physical_ips) { |
368 | 371 | window.TopologyManager.setPhysicalIPs(scenariosList[index].physical_ips); |
|
0 commit comments