topolib 0.3.0__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of topolib might be problematic. Click here for more details.
- topolib/__init__.py +4 -0
- topolib/assets/Abilene_IXP.json +285 -0
- topolib/assets/China_pop.json +1063 -0
- topolib/assets/DT-50_pop.json +1415 -0
- {elements → topolib/elements}/node.py +103 -1
- {topology → topolib/topology}/topology.py +54 -8
- topolib/visualization/__init__.py +1 -0
- topolib/visualization/mapview.py +75 -0
- {topolib-0.3.0.dist-info → topolib-0.4.1.dist-info}/METADATA +25 -14
- topolib-0.4.1.dist-info/RECORD +18 -0
- {topolib-0.3.0.dist-info → topolib-0.4.1.dist-info}/WHEEL +1 -2
- assets/DT14.json +0 -386
- assets/DT17.json +0 -423
- assets/FRANCE-43.json +0 -1104
- assets/JPN-12.json +0 -282
- assets/NSFNet.json +0 -357
- assets/PLN-12.json +0 -308
- assets/UKNet.json +0 -617
- topolib-0.3.0.dist-info/RECORD +0 -20
- topolib-0.3.0.dist-info/top_level.txt +0 -4
- {analysis → topolib/analysis}/__init__.py +0 -0
- {analysis → topolib/analysis}/metrics.py +0 -0
- {elements → topolib/elements}/__init__.py +0 -0
- {elements → topolib/elements}/link.py +0 -0
- {topology → topolib/topology}/__init__.py +0 -0
- {topology → topolib/topology}/path.py +0 -0
- {topolib-0.3.0.dist-info → topolib-0.4.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -21,13 +21,75 @@ class Node:
|
|
|
21
21
|
:type latitude: float
|
|
22
22
|
:param longitude: Longitude coordinate of the node.
|
|
23
23
|
:type longitude: float
|
|
24
|
+
:param weight: Node weight (optional, default 0).
|
|
25
|
+
:type weight: float or int
|
|
26
|
+
:param pop: Node population (optional, default 0).
|
|
27
|
+
:type pop: int
|
|
28
|
+
:param dc: Datacenter (DC) value for the node (optional, default 0).
|
|
29
|
+
:type dc: int
|
|
30
|
+
:param ixp: IXP (Internet Exchange Point) value for the node (optional, default 0).
|
|
31
|
+
:type ixp: int
|
|
24
32
|
"""
|
|
25
33
|
|
|
26
|
-
def __init__(
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
id: int,
|
|
37
|
+
name: str,
|
|
38
|
+
latitude: float,
|
|
39
|
+
longitude: float,
|
|
40
|
+
weight: float = 0,
|
|
41
|
+
pop: int = 0,
|
|
42
|
+
dc: int = 0,
|
|
43
|
+
ixp: int = 0,
|
|
44
|
+
):
|
|
27
45
|
self._id = id
|
|
28
46
|
self._name = name
|
|
29
47
|
self._latitude = latitude
|
|
30
48
|
self._longitude = longitude
|
|
49
|
+
self._weight = weight
|
|
50
|
+
self._pop = pop
|
|
51
|
+
self._dc = dc
|
|
52
|
+
self._ixp = ixp
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def dc(self) -> int:
|
|
56
|
+
"""
|
|
57
|
+
Get the datacenter (DC) count or value for the node.
|
|
58
|
+
|
|
59
|
+
:return: Node DC value.
|
|
60
|
+
:rtype: int
|
|
61
|
+
"""
|
|
62
|
+
return self._dc
|
|
63
|
+
|
|
64
|
+
@dc.setter
|
|
65
|
+
def dc(self, value: int) -> None:
|
|
66
|
+
"""
|
|
67
|
+
Set the datacenter (DC) value for the node.
|
|
68
|
+
|
|
69
|
+
:param value: Node DC value.
|
|
70
|
+
:type value: int
|
|
71
|
+
"""
|
|
72
|
+
self._dc = value
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def ixp(self) -> int:
|
|
76
|
+
"""
|
|
77
|
+
Get the IXP (Internet Exchange Point) count or value for the node.
|
|
78
|
+
|
|
79
|
+
:return: Node IXP value.
|
|
80
|
+
:rtype: int
|
|
81
|
+
"""
|
|
82
|
+
return self._ixp
|
|
83
|
+
|
|
84
|
+
@ixp.setter
|
|
85
|
+
def ixp(self, value: int) -> None:
|
|
86
|
+
"""
|
|
87
|
+
Set the IXP (Internet Exchange Point) value for the node.
|
|
88
|
+
|
|
89
|
+
:param value: Node IXP value.
|
|
90
|
+
:type value: int
|
|
91
|
+
"""
|
|
92
|
+
self._ixp = value
|
|
31
93
|
|
|
32
94
|
@property
|
|
33
95
|
def id(self) -> int:
|
|
@@ -109,6 +171,46 @@ class Node:
|
|
|
109
171
|
"""
|
|
110
172
|
self._longitude = value
|
|
111
173
|
|
|
174
|
+
@property
|
|
175
|
+
def weight(self) -> float:
|
|
176
|
+
"""
|
|
177
|
+
Get the weight of the node.
|
|
178
|
+
|
|
179
|
+
:return: Node weight.
|
|
180
|
+
:rtype: float
|
|
181
|
+
"""
|
|
182
|
+
return self._weight
|
|
183
|
+
|
|
184
|
+
@weight.setter
|
|
185
|
+
def weight(self, value: float) -> None:
|
|
186
|
+
"""
|
|
187
|
+
Set the weight of the node.
|
|
188
|
+
|
|
189
|
+
:param value: Node weight.
|
|
190
|
+
:type value: float
|
|
191
|
+
"""
|
|
192
|
+
self._weight = value
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def pop(self) -> int:
|
|
196
|
+
"""
|
|
197
|
+
Get the population of the node.
|
|
198
|
+
|
|
199
|
+
:return: Node population.
|
|
200
|
+
:rtype: int
|
|
201
|
+
"""
|
|
202
|
+
return self._pop
|
|
203
|
+
|
|
204
|
+
@pop.setter
|
|
205
|
+
def pop(self, value: int) -> None:
|
|
206
|
+
"""
|
|
207
|
+
Set the population of the node.
|
|
208
|
+
|
|
209
|
+
:param value: Node population.
|
|
210
|
+
:type value: int
|
|
211
|
+
"""
|
|
212
|
+
self._pop = value
|
|
213
|
+
|
|
112
214
|
def coordinates(self) -> Tuple[float, float]:
|
|
113
215
|
"""
|
|
114
216
|
Returns the (latitude, longitude) coordinates of the node.
|
|
@@ -8,7 +8,7 @@ This file uses NetworkX (BSD 3-Clause License):
|
|
|
8
8
|
https://github.com/networkx/networkx/blob/main/LICENSE.txt
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
|
-
from typing import List, Dict, Any
|
|
11
|
+
from typing import List, Dict, Any, Optional
|
|
12
12
|
import numpy as np
|
|
13
13
|
import networkx as nx
|
|
14
14
|
from topolib.elements.node import Node
|
|
@@ -42,17 +42,25 @@ class Topology:
|
|
|
42
42
|
[1, 0]])
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
def __init__(
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
nodes: Optional[List[Node]] = None,
|
|
48
|
+
links: Optional[List[Link]] = None,
|
|
49
|
+
name: Optional[str] = None,
|
|
50
|
+
):
|
|
46
51
|
"""
|
|
47
52
|
Initialize a Topology object.
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
:param nodes: Initial list of nodes (optional).
|
|
55
|
+
:type nodes: list[topolib.elements.node.Node] or None
|
|
56
|
+
:param links: Initial list of links (optional).
|
|
57
|
+
:type links: list[topolib.elements.link.Link] or None
|
|
58
|
+
:param name: Name of the topology (optional).
|
|
59
|
+
:type name: str or None
|
|
53
60
|
"""
|
|
54
|
-
self.nodes
|
|
55
|
-
self.links
|
|
61
|
+
self.nodes = nodes if nodes is not None else []
|
|
62
|
+
self.links = links if links is not None else []
|
|
63
|
+
self.name = name
|
|
56
64
|
# Internal NetworkX graph for algorithms and visualization
|
|
57
65
|
self._graph = nx.Graph()
|
|
58
66
|
for node in self.nodes:
|
|
@@ -60,6 +68,44 @@ class Topology:
|
|
|
60
68
|
for link in self.links:
|
|
61
69
|
self._graph.add_edge(link.source.id, link.target.id, link=link)
|
|
62
70
|
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_json(cls, json_path: str) -> "Topology":
|
|
73
|
+
"""
|
|
74
|
+
Create a Topology object from a JSON file.
|
|
75
|
+
|
|
76
|
+
:param json_path: Path to the JSON file containing the topology.
|
|
77
|
+
:type json_path: str
|
|
78
|
+
:return: Topology instance loaded from the file.
|
|
79
|
+
:rtype: Topology
|
|
80
|
+
"""
|
|
81
|
+
import json
|
|
82
|
+
from topolib.elements.node import Node
|
|
83
|
+
from topolib.elements.link import Link
|
|
84
|
+
|
|
85
|
+
with open(json_path, "r", encoding="utf-8") as f:
|
|
86
|
+
data = json.load(f)
|
|
87
|
+
nodes = [
|
|
88
|
+
Node(
|
|
89
|
+
n["id"],
|
|
90
|
+
n["name"],
|
|
91
|
+
n["latitude"],
|
|
92
|
+
n["longitude"],
|
|
93
|
+
n.get("weight", 0),
|
|
94
|
+
n.get("pop", 0),
|
|
95
|
+
n.get("dc", n.get("DC", 0)),
|
|
96
|
+
n.get("ixp", n.get("IXP", 0)),
|
|
97
|
+
)
|
|
98
|
+
for n in data["nodes"]
|
|
99
|
+
]
|
|
100
|
+
# Crear un dict para mapear id a Node
|
|
101
|
+
node_dict = {n.id: n for n in nodes}
|
|
102
|
+
links = [
|
|
103
|
+
Link(l["id"], node_dict[l["src"]], node_dict[l["dst"]], l["length"])
|
|
104
|
+
for l in data["links"]
|
|
105
|
+
]
|
|
106
|
+
name = data.get("name", None)
|
|
107
|
+
return cls(nodes=nodes, links=links, name=name)
|
|
108
|
+
|
|
63
109
|
def add_node(self, node: Node) -> None:
|
|
64
110
|
"""
|
|
65
111
|
Add a node to the topology.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .mapview import MapView
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MapView class for visualizing network topologies.
|
|
3
|
+
|
|
4
|
+
This module provides visualization methods for Topology objects.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
from topolib.topology import Topology
|
|
9
|
+
import matplotlib.pyplot as plt
|
|
10
|
+
import contextily as ctx
|
|
11
|
+
import geopandas as gpd
|
|
12
|
+
from shapely.geometry import Point
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MapView:
|
|
16
|
+
"""
|
|
17
|
+
Provides visualization methods for Topology objects.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, topology: Topology) -> None:
|
|
21
|
+
"""
|
|
22
|
+
Initialize MapView with a Topology object.
|
|
23
|
+
:param topology: Topology object
|
|
24
|
+
"""
|
|
25
|
+
self.topology = topology
|
|
26
|
+
|
|
27
|
+
def show_map(self) -> None:
|
|
28
|
+
"""
|
|
29
|
+
Show all nodes and links of the topology on an OpenStreetMap base using contextily and Matplotlib.
|
|
30
|
+
The figure and plot title will be the topology name if available.
|
|
31
|
+
"""
|
|
32
|
+
lons: list[float] = [node.longitude for node in self.topology.nodes]
|
|
33
|
+
lats: list[float] = [node.latitude for node in self.topology.nodes]
|
|
34
|
+
names: list[str] = [node.name for node in self.topology.nodes]
|
|
35
|
+
gdf: gpd.GeoDataFrame = gpd.GeoDataFrame(
|
|
36
|
+
{"name": names},
|
|
37
|
+
geometry=[Point(x, y) for x, y in zip(lons, lats)],
|
|
38
|
+
crs="EPSG:4326",
|
|
39
|
+
)
|
|
40
|
+
gdf = gdf.to_crs(epsg=3857)
|
|
41
|
+
|
|
42
|
+
# Map node id to projected coordinates
|
|
43
|
+
node_id_to_xy = {
|
|
44
|
+
node.id: (pt.x, pt.y) for node, pt in zip(self.topology.nodes, gdf.geometry)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Try to get topology name (from attribute or fallback)
|
|
48
|
+
topo_name = getattr(self.topology, "name", None)
|
|
49
|
+
if topo_name is None:
|
|
50
|
+
# Try to get from dict if loaded from JSON
|
|
51
|
+
topo_name = getattr(self.topology, "_name", None)
|
|
52
|
+
if topo_name is None:
|
|
53
|
+
topo_name = "Topology"
|
|
54
|
+
|
|
55
|
+
fig, ax = plt.subplots(figsize=(10, 7))
|
|
56
|
+
fig.suptitle(topo_name, fontsize=16)
|
|
57
|
+
# Draw links as simple lines
|
|
58
|
+
for link in getattr(self.topology, "links", []):
|
|
59
|
+
src_id = getattr(link, "source").id
|
|
60
|
+
tgt_id = getattr(link, "target").id
|
|
61
|
+
if src_id in node_id_to_xy and tgt_id in node_id_to_xy:
|
|
62
|
+
x0, y0 = node_id_to_xy[src_id]
|
|
63
|
+
x1, y1 = node_id_to_xy[tgt_id]
|
|
64
|
+
ax.plot(
|
|
65
|
+
[x0, x1], [y0, y1], color="gray", linewidth=1, alpha=0.7, zorder=2
|
|
66
|
+
)
|
|
67
|
+
# Draw nodes
|
|
68
|
+
gdf.plot(ax=ax, color="blue", markersize=40, zorder=5)
|
|
69
|
+
for x, y, name in zip(gdf.geometry.x, gdf.geometry.y, gdf["name"]):
|
|
70
|
+
ax.text(x, y, name, fontsize=8, ha="right", va="bottom", color="black")
|
|
71
|
+
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik)
|
|
72
|
+
ax.set_axis_off()
|
|
73
|
+
ax.set_title(f"Nodes and links ({topo_name})")
|
|
74
|
+
plt.tight_layout()
|
|
75
|
+
plt.show()
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: topolib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: A compact Python library for modeling, analyzing, and visualizing optical network topologies.
|
|
5
|
-
|
|
6
|
-
License-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: network,topology,optical,analysis,visualization
|
|
8
|
+
Author: Danilo Bórquez-Paredes
|
|
9
|
+
Author-email: danilo.borquez.p@uai.cl
|
|
10
|
+
Requires-Python: >=3.10
|
|
13
11
|
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
20
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
-
Requires-
|
|
22
|
+
Requires-Dist: contextily
|
|
23
|
+
Requires-Dist: geopandas
|
|
24
|
+
Requires-Dist: matplotlib
|
|
25
|
+
Requires-Dist: networkx (>=2.6)
|
|
26
|
+
Requires-Dist: numpy (>=1.21)
|
|
27
|
+
Requires-Dist: shapely
|
|
28
|
+
Project-URL: Documentation, https://topolib.readthedocs.io/
|
|
29
|
+
Project-URL: Homepage, https://gitlab.com/DaniloBorquez/topolib
|
|
30
|
+
Project-URL: Repository, https://gitlab.com/DaniloBorquez/topolib
|
|
17
31
|
Description-Content-Type: text/markdown
|
|
18
|
-
License-File: LICENSE
|
|
19
|
-
Requires-Dist: numpy>=1.21
|
|
20
|
-
Requires-Dist: networkx>=2.6
|
|
21
|
-
Dynamic: license-file
|
|
22
32
|
|
|
23
33
|
# Topolib 🚀
|
|
24
34
|
|
|
@@ -125,3 +135,4 @@ See `CONTRIBUTING.md` for development guidelines, commit message rules and pre-c
|
|
|
125
135
|
## License
|
|
126
136
|
|
|
127
137
|
See `LICENSE` in the project root.
|
|
138
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
topolib/__init__.py,sha256=iLmy2rOkHS_4KZWMD8BgT7R3tLMKeaTCDVf3B4FyYxM,91
|
|
2
|
+
topolib/analysis/__init__.py,sha256=qvUC9wV_jQNQIlwJXk7LJ-dkTXhH1Ttn0lKWIdwBbrc,52
|
|
3
|
+
topolib/analysis/metrics.py,sha256=Di4HGHlz9c2UTCYdfnmjtPjo7w3wwYuyDPeXI7bR0zA,2592
|
|
4
|
+
topolib/assets/Abilene_IXP.json,sha256=5cnPMbjsNDjmpySdQDYQ2yd83zOFvCRjlAnbX1wyzgk,6010
|
|
5
|
+
topolib/assets/China_pop.json,sha256=v-bs5qib8-CB81rvBNNM9ssoelrNGuFrPEyRCht9YpY,22262
|
|
6
|
+
topolib/assets/DT-50_pop.json,sha256=hCv1MCvipgdrQ34VT-qXJ68BdATriQ8ZObh0fLPqar4,29719
|
|
7
|
+
topolib/elements/__init__.py,sha256=ZWSd5uwVtppJtMnZ30zrAdzXhUAYIK62RrUaH9rsWu0,180
|
|
8
|
+
topolib/elements/link.py,sha256=BwjdCR8peh7dDpKunZodlIsjKcfvwjKxyQ3tmp1obb8,3778
|
|
9
|
+
topolib/elements/node.py,sha256=uOnljwA3jcVR4utUfI-om4SIt_QBsEQt8QLW9uvjr3Y,4974
|
|
10
|
+
topolib/topology/__init__.py,sha256=2VRhVm4ZvKBiTDB2T8BDmLZBpwGCVFRF3fvtxxC_d28,86
|
|
11
|
+
topolib/topology/path.py,sha256=oUNwmpBcS6LMMAJIxokROm3MVqr7vRR44M3Fh5ADq_w,2057
|
|
12
|
+
topolib/topology/topology.py,sha256=PzPx80TxWMcOwpOCh4fohcWT2YUra-4m04tBjqyMU40,5605
|
|
13
|
+
topolib/visualization/__init__.py,sha256=wv065-KB5uDbTaQIASPVfMMW5sE76Bs-q0oai48vAzk,29
|
|
14
|
+
topolib/visualization/mapview.py,sha256=4iKJMYsH6oFNj9tOcgSKLVRtoYfUuH3XLjShsGwUXcM,2799
|
|
15
|
+
topolib-0.4.1.dist-info/METADATA,sha256=WSUvBwdpmS9NRSwm-r5lT2pzJyKFuQ-xUe9khXm_xAY,4671
|
|
16
|
+
topolib-0.4.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
17
|
+
topolib-0.4.1.dist-info/licenses/LICENSE,sha256=kbnIP0XU6f2ualiTjEawdlU81IGPBbwc-_GF3N-1e9E,1081
|
|
18
|
+
topolib-0.4.1.dist-info/RECORD,,
|