Skip to content

Commit ca2c94e

Browse files
Update generation of random topologies
1 parent 377751a commit ca2c94e

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
2424
RUN apt-get update && apt-get install -y build-essential gcc g++ clang git make cmake
2525

2626
# Install docker
27-
RUN apt-get install -y ca-certificates curl gnupg
27+
RUN apt-get update && apt-get install -y ca-certificates curl gnupg
2828
RUN install -m 0755 -d /etc/apt/keyrings
2929
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
3030
RUN chmod a+r /etc/apt/keyrings/docker.gpg

nebula/addons/topologymanager.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ def generate_topology(self):
225225
if self.b_fully_connected:
226226
self.__fully_connected()
227227
return
228+
229+
if self.topology is not None and len(self.topology) > 0:
230+
# Topology was already provided
231+
return
228232

229233
if self.b_symmetric:
230234
self.__randomly_pick_neighbors_symmetric()
@@ -280,6 +284,20 @@ def generate_custom_topology(self, topology):
280284
None: The method modifies the internal `self.topology` to the provided custom topology.
281285
"""
282286
self.topology = topology
287+
288+
def generate_random_topology(self, probability):
289+
"""
290+
Generates a random topology using Erdos-Renyi model with given probability.
291+
292+
Args:
293+
probability (float): Probability of edge creation between any two nodes (0-1)
294+
295+
Returns:
296+
None: Updates self.topology with the generated random topology
297+
"""
298+
random_graph = nx.erdos_renyi_graph(self.n_nodes, probability)
299+
self.topology = nx.to_numpy_array(random_graph, dtype=np.float32)
300+
np.fill_diagonal(self.topology, 0) # No self-loops
283301

284302
def get_matrix_adjacency_from_neighbors(self, neighbors):
285303
"""

nebula/frontend/templates/deployment.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ <h5 class="step-title">Schema of deployment</h5>
10761076
data["nodes_graph"] = nodesGraph
10771077
data["n_nodes"] = getNumberOfNodes()
10781078
data["matrix"] = getMatrix(Graph.graphData().nodes, Graph.graphData().links)
1079+
data["random_topology_probability"] = parseFloat(document.getElementById("random-probability").value)
10791080
// Step 5
10801081
data["dataset"] = document.getElementById("datasetSelect").value
10811082
data["iid"] = document.getElementById("iidSelect").value === "true"
@@ -1155,6 +1156,9 @@ <h5 class="step-title">Schema of deployment</h5>
11551156
document.getElementById("predefined-topology-btn").click();
11561157
document.getElementById("predefined-topology-select").value = data["topology"];
11571158
document.getElementById("predefined-topology-nodes").value = data["n_nodes"];
1159+
if ("random_topology_probability" in data) {
1160+
document.getElementById("random-probability").value = data["random_topology_probability"];
1161+
}
11581162
}
11591163
gData.nodes = data["nodes_graph"]
11601164
// Add links manually

nebula/scenarios.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
mobile_participants_percent,
6868
additional_participants,
6969
schema_additional_participants,
70+
random_topology_probability,
7071
):
7172
"""
7273
Initialize the scenario.
@@ -117,6 +118,7 @@ def __init__(
117118
mobile_participants_percent (float): Percentage of mobile participants.
118119
additional_participants (list): List of additional participants.
119120
schema_additional_participants (str): Schema for additional participants.
121+
random_topology_probability (float): Probability for random topology.
120122
"""
121123
self.scenario_title = scenario_title
122124
self.scenario_description = scenario_description
@@ -161,6 +163,7 @@ def __init__(
161163
self.mobile_participants_percent = mobile_participants_percent
162164
self.additional_participants = additional_participants
163165
self.schema_additional_participants = schema_additional_participants
166+
self.random_topology_probability = random_topology_probability
164167

165168
def attack_node_assign(
166169
self,
@@ -567,8 +570,19 @@ def load_configurations_and_start_nodes(self, additional_participants=None, sche
567570

568571
def create_topology(self, matrix=None):
569572
import numpy as np
570-
571-
if matrix is not None:
573+
574+
if self.scenario.topology == "Random":
575+
# Create network topology using topology manager (random)
576+
probability = float(self.scenario.random_topology_probability)
577+
logging.info(f"Creating random network topology using erdos_renyi_graph: nodes={self.n_nodes}, probability={probability}")
578+
topologymanager = TopologyManager(
579+
scenario_name=self.scenario_name,
580+
n_nodes=self.n_nodes,
581+
b_symmetric=True,
582+
undirected_neighbor_num=3,
583+
)
584+
topologymanager.generate_random_topology(probability)
585+
elif matrix is not None:
572586
if self.n_nodes > 2:
573587
topologymanager = TopologyManager(
574588
topology=np.array(matrix),
@@ -585,7 +599,7 @@ def create_topology(self, matrix=None):
585599
b_symmetric=True,
586600
undirected_neighbor_num=2,
587601
)
588-
elif self.scenario.topology == "fully":
602+
elif self.scenario.topology == "Fully":
589603
# Create a fully connected network
590604
topologymanager = TopologyManager(
591605
scenario_name=self.scenario_name,
@@ -594,20 +608,11 @@ def create_topology(self, matrix=None):
594608
undirected_neighbor_num=self.n_nodes - 1,
595609
)
596610
topologymanager.generate_topology()
597-
elif self.scenario.topology == "ring":
611+
elif self.scenario.topology == "Ring":
598612
# Create a partially connected network (ring-structured network)
599613
topologymanager = TopologyManager(scenario_name=self.scenario_name, n_nodes=self.n_nodes, b_symmetric=True)
600614
topologymanager.generate_ring_topology(increase_convergence=True)
601-
elif self.scenario.topology == "random":
602-
# Create network topology using topology manager (random)
603-
topologymanager = TopologyManager(
604-
scenario_name=self.scenario_name,
605-
n_nodes=self.n_nodes,
606-
b_symmetric=True,
607-
undirected_neighbor_num=3,
608-
)
609-
topologymanager.generate_topology()
610-
elif self.scenario.topology == "star" and self.scenario.federation == "CFL":
615+
elif self.scenario.topology == "Star" and self.scenario.federation == "CFL":
611616
# Create a centralized network
612617
topologymanager = TopologyManager(scenario_name=self.scenario_name, n_nodes=self.n_nodes, b_symmetric=True)
613618
topologymanager.generate_server_topology()

0 commit comments

Comments
 (0)