Documentation for Topologymanager Module¶
TopologyManager
¶
Source code in nebula/addons/topologymanager.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
__fully_connected()
¶
Generates a fully connected topology where each node is connected to every other node.
This method creates a fully connected network by generating a Watts-Strogatz graph with the number of nodes set to n_nodes
and the number of neighbors set to n_nodes - 1
. The resulting graph is then converted into a numpy matrix and all missing links (i.e., non-ones in the adjacency matrix) are set to 1 to ensure complete connectivity. The diagonal elements are filled with zeros to avoid self-loops.
Returns:
Name | Type | Description |
---|---|---|
None |
The |
Source code in nebula/addons/topologymanager.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
__getstate__()
¶
Serializes the object state for saving.
This method defines which attributes of the class should be serialized when the object is pickled (saved to a file). It returns a dictionary containing the attributes that need to be preserved.
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the relevant attributes of the object for serialization. - scenario_name (str): Name of the scenario. - n_nodes (int): Number of nodes in the network. - topology (list): Topology of the network. - nodes (np.ndarray): Array of nodes in the network. |
Source code in nebula/addons/topologymanager.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
__init__(scenario_name=None, n_nodes=5, b_symmetric=True, undirected_neighbor_num=5, topology=None)
¶
Initializes a network topology for the scenario.
This constructor sets up a network topology with a given number of nodes, neighbors, and other parameters. It includes options to specify whether the topology should be symmetric and the number of undirected neighbors for each node. It also checks for constraints on the number of neighbors and the structure of the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
-
|
scenario_name (str
|
Name of the scenario. |
required |
-
|
n_nodes (int
|
Number of nodes in the network (default 5). |
required |
-
|
b_symmetric (bool
|
Whether the topology is symmetric (default True). |
required |
-
|
undirected_neighbor_num (int
|
Number of undirected neighbors for each node (default 5). |
required |
-
|
topology (list
|
Predefined topology, a list of nodes and connections (default None). |
required |
Raises:
Type | Description |
---|---|
-ValueError
|
If |
Attributes:
Name | Type | Description |
---|---|---|
- |
scenario_name (str
|
Name of the scenario. |
- |
n_nodes (int
|
Number of nodes in the network. |
- |
b_symmetric (bool
|
Whether the topology is symmetric. |
- |
undirected_neighbor_num (int
|
Number of undirected neighbors. |
- |
topology (list
|
Topology of the network. |
- |
nodes (np.ndarray
|
Array of nodes initialized with zeroes. |
- |
b_fully_connected (bool
|
Flag indicating if the topology is fully connected. |
Source code in nebula/addons/topologymanager.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
__randomly_pick_neighbors_asymmetric()
¶
Generates an asymmetric random topology by combining a ring topology with additional random links and random deletions.
This method first creates a ring topology using the Watts-Strogatz model, where each node is connected to two neighbors. Then, it randomly adds links to each node to create a topology with a specified number of undirected neighbors. After that, it randomly deletes some of the links to introduce asymmetry. The result is a topology where nodes have a varying number of directed and undirected links, and the structure is asymmetric.
Returns:
Name | Type | Description |
---|---|---|
None |
The |
Source code in nebula/addons/topologymanager.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
__randomly_pick_neighbors_symmetric()
¶
Generates a symmetric random topology by combining a ring topology with additional random links.
This method first creates a ring topology using the Watts-Strogatz model, where each node is connected to two neighbors. Then, it randomly adds links to each node (up to the specified number of neighbors) to form a symmetric topology. The result is a topology where each node has a fixed number of undirected neighbors, and the connections are symmetric between nodes.
Returns:
Name | Type | Description |
---|---|---|
None |
The |
Source code in nebula/addons/topologymanager.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
__ring_topology(increase_convergence=False)
¶
Generates a ring topology for the nodes.
This method creates a ring topology for the network using the Watts-Strogatz model. Each node is connected to two neighbors, forming a ring. Optionally, additional random connections are added to increase convergence, making the network more connected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
increase_convergence
|
bool
|
If set to True, random connections will be added between nodes to increase the network's connectivity. |
False
|
Returns:
Name | Type | Description |
---|---|---|
None |
The |
Source code in nebula/addons/topologymanager.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
__setstate__(state)
¶
Restores the object state from the serialized data.
This method is called during deserialization (unpickling) to restore the object's state by setting the attributes using the provided state dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
dict
|
A dictionary containing the serialized data, including: - scenario_name (str): Name of the scenario. - n_nodes (int): Number of nodes in the network. - topology (list): Topology of the network. - nodes (np.ndarray): Array of nodes in the network. |
required |
Source code in nebula/addons/topologymanager.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
add_legend(roles)
¶
Adds a legend to the plot for different roles, associating each role with a color.
The method iterates through the provided roles and assigns the corresponding color to each one. The colors are predefined in the legend_map, which associates each role with a specific color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
roles
|
iterable
|
A collection of roles for which the legend should be displayed. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
The function modifies the plot directly by adding the legend. |
Source code in nebula/addons/topologymanager.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
add_nodes(nodes)
¶
Sets the nodes of the topology.
This method updates the nodes
attribute with the given list or array of nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
array - like
|
The new set of nodes to be assigned to the topology. It should be in a format compatible
with the existing |
required |
Returns:
Type | Description |
---|---|
None |
Source code in nebula/addons/topologymanager.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
draw_graph(plot=False, path=None)
¶
Draws the network graph based on the topology and saves it as an image.
This method generates a visualization of the network's topology using NetworkX and Matplotlib. It assigns colors to the nodes based on their role, draws the network's nodes and edges, adds labels to the nodes, and includes a legend for clarity. The resulting plot is saved as an image file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plot
|
bool
|
Whether to display the plot. Default is False. |
False
|
path
|
str
|
The file path where the image will be saved. If None, the image is saved to a default location based on the scenario name. |
None
|
Returns:
Name | Type | Description |
---|---|---|
None |
The method saves the plot as an image at the specified path. |
Source code in nebula/addons/topologymanager.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
generate_random_topology(probability)
¶
Generates a random topology using Erdos-Renyi model with given probability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probability
|
float
|
Probability of edge creation between any two nodes (0-1) |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
Updates self.topology with the generated random topology |
Source code in nebula/addons/topologymanager.py
253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
generate_ring_topology(increase_convergence=False)
¶
Generates a ring topology for the network.
In a ring topology, each node is connected to two other nodes in a circular fashion, forming a closed loop. This method uses a private method to generate the topology, with an optional parameter to control whether the convergence speed of the network should be increased.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
increase_convergence
|
bool
|
Optional flag to increase the convergence speed in the topology. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
None |
The method modifies the internal |
Source code in nebula/addons/topologymanager.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
generate_server_topology()
¶
Generates a server topology where the first node (usually the server) is connected to all other nodes.
This method initializes a topology matrix where the first node (typically the server) is connected to every other node in the network. The first row and the first column of the matrix are set to 1, representing connections to and from the server. The diagonal is set to 0 to indicate that no node is connected to itself.
Returns:
Name | Type | Description |
---|---|---|
None |
The method modifies the internal |
Source code in nebula/addons/topologymanager.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
generate_topology()
¶
Generates the network topology based on the configured settings.
This method generates the network topology for the given scenario. It checks whether the topology should be fully connected, symmetric, or asymmetric and then generates the network accordingly.
- If the topology is fully connected, all nodes will be directly connected to each other.
- If the topology is symmetric, neighbors will be chosen symmetrically between nodes.
- If the topology is asymmetric, neighbors will be picked randomly without symmetry.
Returns:
Name | Type | Description |
---|---|---|
None |
The method modifies the internal topology of the network. |
Source code in nebula/addons/topologymanager.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
get_coordinates(random_geo=True)
staticmethod
¶
Generates random geographical coordinates within predefined bounds for either Spain or Switzerland.
The method returns a random geographical coordinate (latitude, longitude). The bounds for random coordinates are defined for two regions: Spain and Switzerland. The region is chosen randomly, and then the latitude and longitude are selected within the corresponding bounds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
random_geo
|
bool
|
If set to True, the method generates random coordinates within the predefined bounds for Spain or Switzerland. If set to False, this method could be modified to return fixed coordinates. |
True
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the latitude and longitude of the generated point. |
Source code in nebula/addons/topologymanager.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
get_neighbors_string(node_idx)
¶
Retrieves the neighbors of a given node as a string representation.
This method checks the topology
attribute to find the neighbors of the node at the specified index (node_idx
). It then returns a string that lists the coordinates of each neighbor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_idx
|
int
|
The index of the node for which neighbors are to be retrieved. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
A space-separated string of neighbors' coordinates in the format "latitude:longitude". |
Source code in nebula/addons/topologymanager.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
get_node_color(role)
¶
Returns the color associated with a given role.
The method maps roles to specific colors for visualization or representation purposes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role
|
Role
|
The role for which the color is to be determined. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The color associated with the given role. Defaults to "red" if the role is not recognized. |
Source code in nebula/addons/topologymanager.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
update_nodes(config_participants)
¶
Updates the nodes of the topology based on the provided configuration.
This method assigns a new set of nodes to the nodes
attribute, typically based on the configuration of the participants.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_participants
|
array - like
|
A new set of nodes, usually derived from the participants' configuration, to be assigned to the topology. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in nebula/addons/topologymanager.py
309 310 311 312 313 314 315 316 317 318 319 320 321 |
|