Skip to content

Commit

Permalink
Update generation of random topologies
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquetomasmb committed Jan 27, 2025
1 parent 377751a commit ca2c94e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN apt-get update && apt-get install -y build-essential gcc g++ clang git make cmake

# Install docker
RUN apt-get install -y ca-certificates curl gnupg
RUN apt-get update && apt-get install -y ca-certificates curl gnupg
RUN install -m 0755 -d /etc/apt/keyrings
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
RUN chmod a+r /etc/apt/keyrings/docker.gpg
Expand Down
18 changes: 18 additions & 0 deletions nebula/addons/topologymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def generate_topology(self):
if self.b_fully_connected:
self.__fully_connected()
return

if self.topology is not None and len(self.topology) > 0:
# Topology was already provided
return

if self.b_symmetric:
self.__randomly_pick_neighbors_symmetric()
Expand Down Expand Up @@ -280,6 +284,20 @@ def generate_custom_topology(self, topology):
None: The method modifies the internal `self.topology` to the provided custom topology.
"""
self.topology = topology

def generate_random_topology(self, probability):
"""
Generates a random topology using Erdos-Renyi model with given probability.
Args:
probability (float): Probability of edge creation between any two nodes (0-1)
Returns:
None: Updates self.topology with the generated random topology
"""
random_graph = nx.erdos_renyi_graph(self.n_nodes, probability)
self.topology = nx.to_numpy_array(random_graph, dtype=np.float32)
np.fill_diagonal(self.topology, 0) # No self-loops

def get_matrix_adjacency_from_neighbors(self, neighbors):
"""
Expand Down
4 changes: 4 additions & 0 deletions nebula/frontend/templates/deployment.html
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ <h5 class="step-title">Schema of deployment</h5>
data["nodes_graph"] = nodesGraph
data["n_nodes"] = getNumberOfNodes()
data["matrix"] = getMatrix(Graph.graphData().nodes, Graph.graphData().links)
data["random_topology_probability"] = parseFloat(document.getElementById("random-probability").value)
// Step 5
data["dataset"] = document.getElementById("datasetSelect").value
data["iid"] = document.getElementById("iidSelect").value === "true"
Expand Down Expand Up @@ -1155,6 +1156,9 @@ <h5 class="step-title">Schema of deployment</h5>
document.getElementById("predefined-topology-btn").click();
document.getElementById("predefined-topology-select").value = data["topology"];
document.getElementById("predefined-topology-nodes").value = data["n_nodes"];
if ("random_topology_probability" in data) {
document.getElementById("random-probability").value = data["random_topology_probability"];
}
}
gData.nodes = data["nodes_graph"]
// Add links manually
Expand Down
33 changes: 19 additions & 14 deletions nebula/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
mobile_participants_percent,
additional_participants,
schema_additional_participants,
random_topology_probability,
):
"""
Initialize the scenario.
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(
mobile_participants_percent (float): Percentage of mobile participants.
additional_participants (list): List of additional participants.
schema_additional_participants (str): Schema for additional participants.
random_topology_probability (float): Probability for random topology.
"""
self.scenario_title = scenario_title
self.scenario_description = scenario_description
Expand Down Expand Up @@ -161,6 +163,7 @@ def __init__(
self.mobile_participants_percent = mobile_participants_percent
self.additional_participants = additional_participants
self.schema_additional_participants = schema_additional_participants
self.random_topology_probability = random_topology_probability

def attack_node_assign(
self,
Expand Down Expand Up @@ -567,8 +570,19 @@ def load_configurations_and_start_nodes(self, additional_participants=None, sche

def create_topology(self, matrix=None):
import numpy as np

if matrix is not None:

if self.scenario.topology == "Random":
# Create network topology using topology manager (random)
probability = float(self.scenario.random_topology_probability)
logging.info(f"Creating random network topology using erdos_renyi_graph: nodes={self.n_nodes}, probability={probability}")
topologymanager = TopologyManager(
scenario_name=self.scenario_name,
n_nodes=self.n_nodes,
b_symmetric=True,
undirected_neighbor_num=3,
)
topologymanager.generate_random_topology(probability)
elif matrix is not None:
if self.n_nodes > 2:
topologymanager = TopologyManager(
topology=np.array(matrix),
Expand All @@ -585,7 +599,7 @@ def create_topology(self, matrix=None):
b_symmetric=True,
undirected_neighbor_num=2,
)
elif self.scenario.topology == "fully":
elif self.scenario.topology == "Fully":
# Create a fully connected network
topologymanager = TopologyManager(
scenario_name=self.scenario_name,
Expand All @@ -594,20 +608,11 @@ def create_topology(self, matrix=None):
undirected_neighbor_num=self.n_nodes - 1,
)
topologymanager.generate_topology()
elif self.scenario.topology == "ring":
elif self.scenario.topology == "Ring":
# Create a partially connected network (ring-structured network)
topologymanager = TopologyManager(scenario_name=self.scenario_name, n_nodes=self.n_nodes, b_symmetric=True)
topologymanager.generate_ring_topology(increase_convergence=True)
elif self.scenario.topology == "random":
# Create network topology using topology manager (random)
topologymanager = TopologyManager(
scenario_name=self.scenario_name,
n_nodes=self.n_nodes,
b_symmetric=True,
undirected_neighbor_num=3,
)
topologymanager.generate_topology()
elif self.scenario.topology == "star" and self.scenario.federation == "CFL":
elif self.scenario.topology == "Star" and self.scenario.federation == "CFL":
# Create a centralized network
topologymanager = TopologyManager(scenario_name=self.scenario_name, n_nodes=self.n_nodes, b_symmetric=True)
topologymanager.generate_server_topology()
Expand Down

0 comments on commit ca2c94e

Please sign in to comment.