topolib 0.8.0__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.
- topolib/__init__.py +4 -0
- topolib/analysis/__init__.py +4 -0
- topolib/analysis/metrics.py +80 -0
- topolib/analysis/traffic_matrix.py +344 -0
- topolib/assets/AMRES.json +1265 -0
- topolib/assets/Abilene.json +285 -0
- topolib/assets/Bell_canada.json +925 -0
- topolib/assets/Brazil.json +699 -0
- topolib/assets/CESNET.json +657 -0
- topolib/assets/CORONET.json +1957 -0
- topolib/assets/China.json +1135 -0
- topolib/assets/DT-14.json +470 -0
- topolib/assets/DT-17.json +525 -0
- topolib/assets/DT-50.json +1515 -0
- topolib/assets/ES-30.json +967 -0
- topolib/assets/EURO-16.json +455 -0
- topolib/assets/FR-43.json +1277 -0
- topolib/assets/FUNET.json +317 -0
- topolib/assets/GCN-BG.json +855 -0
- topolib/assets/GRNET.json +1717 -0
- topolib/assets/HyperOne.json +255 -0
- topolib/assets/IT-21.json +649 -0
- topolib/assets/India.json +517 -0
- topolib/assets/JPN-12.json +331 -0
- topolib/assets/KOREN.json +287 -0
- topolib/assets/NORDUNet.json +783 -0
- topolib/assets/NSFNet.json +399 -0
- topolib/assets/PANEURO.json +757 -0
- topolib/assets/PAVLOV.json +465 -0
- topolib/assets/PLN-12.json +343 -0
- topolib/assets/SANReN.json +161 -0
- topolib/assets/SERBIA-MONTENEGRO.json +139 -0
- topolib/assets/Telefonica-21.json +637 -0
- topolib/assets/Turk_Telekom.json +551 -0
- topolib/assets/UKNet.json +685 -0
- topolib/assets/Vega_Telecom.json +819 -0
- topolib/elements/__init__.py +5 -0
- topolib/elements/link.py +121 -0
- topolib/elements/node.py +230 -0
- topolib/topology/__init__.py +4 -0
- topolib/topology/path.py +84 -0
- topolib/topology/topology.py +469 -0
- topolib/visualization/__init__.py +1 -0
- topolib/visualization/_qt_screenshot.py +103 -0
- topolib/visualization/_qt_window.py +78 -0
- topolib/visualization/_templates.py +101 -0
- topolib/visualization/mapview.py +316 -0
- topolib-0.8.0.dist-info/METADATA +148 -0
- topolib-0.8.0.dist-info/RECORD +51 -0
- topolib-0.8.0.dist-info/WHEEL +4 -0
- topolib-0.8.0.dist-info/licenses/LICENSE +22 -0
topolib/elements/link.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from topolib.elements.node import Node
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Link:
|
|
10
|
+
"""
|
|
11
|
+
Represents a link between two nodes.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
id : int
|
|
16
|
+
Unique identifier for the link.
|
|
17
|
+
source : :class:`topolib.elements.node.Node`
|
|
18
|
+
Source node-like object (must have id, name, latitude, longitude).
|
|
19
|
+
target : :class:`topolib.elements.node.Node`
|
|
20
|
+
Target node-like object (must have id, name, latitude, longitude).
|
|
21
|
+
length : float
|
|
22
|
+
Length of the link (must be non-negative).
|
|
23
|
+
|
|
24
|
+
Examples
|
|
25
|
+
--------
|
|
26
|
+
>>> link = Link(1, nodeA, nodeB, 10.5)
|
|
27
|
+
>>> link.length
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, id: int, source: "Node", target: "Node", length: float):
|
|
31
|
+
self._id = id
|
|
32
|
+
self.source = source
|
|
33
|
+
self.target = target
|
|
34
|
+
self.length = length
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def id(self) -> int:
|
|
38
|
+
"""
|
|
39
|
+
int: Unique identifier for the link.
|
|
40
|
+
"""
|
|
41
|
+
return self._id
|
|
42
|
+
|
|
43
|
+
@id.setter
|
|
44
|
+
def id(self, value: int) -> None:
|
|
45
|
+
"""
|
|
46
|
+
Set the link's unique identifier.
|
|
47
|
+
"""
|
|
48
|
+
self._id = value
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def source(self) -> "Node":
|
|
52
|
+
"""
|
|
53
|
+
:class:`topolib.elements.node.Node`: Source node of the link.
|
|
54
|
+
"""
|
|
55
|
+
return self._source
|
|
56
|
+
|
|
57
|
+
@source.setter
|
|
58
|
+
def source(self, value: "Node") -> None:
|
|
59
|
+
"""
|
|
60
|
+
Set the source node. Must have id, name, latitude, longitude.
|
|
61
|
+
"""
|
|
62
|
+
required_attrs = ("id", "name", "latitude", "longitude")
|
|
63
|
+
for attr in required_attrs:
|
|
64
|
+
if not hasattr(value, attr):
|
|
65
|
+
raise TypeError(f"source must behave like a Node (missing {attr})")
|
|
66
|
+
self._source = value
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def target(self) -> "Node":
|
|
70
|
+
"""
|
|
71
|
+
:class:`topolib.elements.node.Node`: Target node of the link.
|
|
72
|
+
"""
|
|
73
|
+
return self._target
|
|
74
|
+
|
|
75
|
+
@target.setter
|
|
76
|
+
def target(self, value: "Node") -> None:
|
|
77
|
+
"""
|
|
78
|
+
Set the target node. Must have id, name, latitude, longitude.
|
|
79
|
+
"""
|
|
80
|
+
required_attrs = ("id", "name", "latitude", "longitude")
|
|
81
|
+
for attr in required_attrs:
|
|
82
|
+
if not hasattr(value, attr):
|
|
83
|
+
raise TypeError(f"target must behave like a Node (missing {attr})")
|
|
84
|
+
self._target = value
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def length(self) -> float:
|
|
88
|
+
"""
|
|
89
|
+
float: Length of the link (non-negative).
|
|
90
|
+
"""
|
|
91
|
+
return self._length
|
|
92
|
+
|
|
93
|
+
@length.setter
|
|
94
|
+
def length(self, value: float) -> None:
|
|
95
|
+
"""
|
|
96
|
+
Set the length of the link. Must be a non-negative float.
|
|
97
|
+
"""
|
|
98
|
+
try:
|
|
99
|
+
numeric = float(value)
|
|
100
|
+
except Exception:
|
|
101
|
+
raise TypeError("length must be a numeric value")
|
|
102
|
+
if numeric < 0:
|
|
103
|
+
raise ValueError("length must be non-negative")
|
|
104
|
+
self._length = numeric
|
|
105
|
+
|
|
106
|
+
def endpoints(self):
|
|
107
|
+
"""
|
|
108
|
+
Return the (source, target) nodes as a tuple.
|
|
109
|
+
|
|
110
|
+
Returns
|
|
111
|
+
-------
|
|
112
|
+
tuple
|
|
113
|
+
(source_node, target_node)
|
|
114
|
+
"""
|
|
115
|
+
return self._source, self._target
|
|
116
|
+
|
|
117
|
+
def __repr__(self) -> str:
|
|
118
|
+
"""
|
|
119
|
+
Return a string representation of the Link.
|
|
120
|
+
"""
|
|
121
|
+
return f"Link(id={self._id}, source={self._source.id} ({self.source.name}), target={self._target.id} ({self.target.name}), length={self._length})"
|
topolib/elements/node.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Node class for optical network topologies.
|
|
3
|
+
|
|
4
|
+
This module defines the Node class, representing a network node with geographic coordinates.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Tuple
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Node:
|
|
11
|
+
"""
|
|
12
|
+
Represents a node in an optical network topology.
|
|
13
|
+
|
|
14
|
+
:param id: Unique identifier for the node.
|
|
15
|
+
:type id: int
|
|
16
|
+
:param name: Name of the node.
|
|
17
|
+
:type name: str
|
|
18
|
+
:param latitude: Latitude coordinate of the node.
|
|
19
|
+
:type latitude: float
|
|
20
|
+
:param longitude: Longitude coordinate of the node.
|
|
21
|
+
:type longitude: float
|
|
22
|
+
:param weight: Node weight (optional, default 0).
|
|
23
|
+
:type weight: float or int
|
|
24
|
+
:param pop: Node population (optional, default 0).
|
|
25
|
+
:type pop: int
|
|
26
|
+
:param dc: Datacenter (DC) value for the node (optional, default 0).
|
|
27
|
+
:type dc: int
|
|
28
|
+
:param ixp: IXP (Internet Exchange Point) value for the node (optional, default 0).
|
|
29
|
+
:type ixp: int
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
id: int,
|
|
35
|
+
name: str,
|
|
36
|
+
latitude: float,
|
|
37
|
+
longitude: float,
|
|
38
|
+
weight: float = 0,
|
|
39
|
+
pop: int = 0,
|
|
40
|
+
dc: int = 0,
|
|
41
|
+
ixp: int = 0,
|
|
42
|
+
):
|
|
43
|
+
self._id = id
|
|
44
|
+
self._name = name
|
|
45
|
+
self._latitude = latitude
|
|
46
|
+
self._longitude = longitude
|
|
47
|
+
self._weight = weight
|
|
48
|
+
self._pop = pop
|
|
49
|
+
self._dc = dc
|
|
50
|
+
self._ixp = ixp
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def dc(self) -> int:
|
|
54
|
+
"""
|
|
55
|
+
Get the datacenter (DC) count or value for the node.
|
|
56
|
+
|
|
57
|
+
:return: Node DC value.
|
|
58
|
+
:rtype: int
|
|
59
|
+
"""
|
|
60
|
+
return self._dc
|
|
61
|
+
|
|
62
|
+
@dc.setter
|
|
63
|
+
def dc(self, value: int) -> None:
|
|
64
|
+
"""
|
|
65
|
+
Set the datacenter (DC) value for the node.
|
|
66
|
+
|
|
67
|
+
:param value: Node DC value.
|
|
68
|
+
:type value: int
|
|
69
|
+
"""
|
|
70
|
+
self._dc = value
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def ixp(self) -> int:
|
|
74
|
+
"""
|
|
75
|
+
Get the IXP (Internet Exchange Point) count or value for the node.
|
|
76
|
+
|
|
77
|
+
:return: Node IXP value.
|
|
78
|
+
:rtype: int
|
|
79
|
+
"""
|
|
80
|
+
return self._ixp
|
|
81
|
+
|
|
82
|
+
@ixp.setter
|
|
83
|
+
def ixp(self, value: int) -> None:
|
|
84
|
+
"""
|
|
85
|
+
Set the IXP (Internet Exchange Point) value for the node.
|
|
86
|
+
|
|
87
|
+
:param value: Node IXP value.
|
|
88
|
+
:type value: int
|
|
89
|
+
"""
|
|
90
|
+
self._ixp = value
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def id(self) -> int:
|
|
94
|
+
"""
|
|
95
|
+
Get the unique identifier of the node.
|
|
96
|
+
|
|
97
|
+
:return: Node ID.
|
|
98
|
+
:rtype: int
|
|
99
|
+
"""
|
|
100
|
+
return self._id
|
|
101
|
+
|
|
102
|
+
@id.setter
|
|
103
|
+
def id(self, value: int) -> None:
|
|
104
|
+
"""
|
|
105
|
+
Set the unique identifier of the node.
|
|
106
|
+
|
|
107
|
+
:param value: Node ID.
|
|
108
|
+
:type value: int
|
|
109
|
+
"""
|
|
110
|
+
self._id = value
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def name(self) -> str:
|
|
114
|
+
"""
|
|
115
|
+
Get the name of the node.
|
|
116
|
+
|
|
117
|
+
:return: Node name.
|
|
118
|
+
:rtype: str
|
|
119
|
+
"""
|
|
120
|
+
return self._name
|
|
121
|
+
|
|
122
|
+
@name.setter
|
|
123
|
+
def name(self, value: str) -> None:
|
|
124
|
+
"""
|
|
125
|
+
Set the name of the node.
|
|
126
|
+
|
|
127
|
+
:param value: Node name.
|
|
128
|
+
:type value: str
|
|
129
|
+
"""
|
|
130
|
+
self._name = value
|
|
131
|
+
|
|
132
|
+
@property
|
|
133
|
+
def latitude(self) -> float:
|
|
134
|
+
"""
|
|
135
|
+
Get the latitude coordinate of the node.
|
|
136
|
+
|
|
137
|
+
:return: Latitude value.
|
|
138
|
+
:rtype: float
|
|
139
|
+
"""
|
|
140
|
+
return self._latitude
|
|
141
|
+
|
|
142
|
+
@latitude.setter
|
|
143
|
+
def latitude(self, value: float) -> None:
|
|
144
|
+
"""
|
|
145
|
+
Set the latitude coordinate of the node.
|
|
146
|
+
|
|
147
|
+
:param value: Latitude value.
|
|
148
|
+
:type value: float
|
|
149
|
+
"""
|
|
150
|
+
self._latitude = value
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def longitude(self) -> float:
|
|
154
|
+
"""
|
|
155
|
+
Get the longitude coordinate of the node.
|
|
156
|
+
|
|
157
|
+
:return: Longitude value.
|
|
158
|
+
:rtype: float
|
|
159
|
+
"""
|
|
160
|
+
return self._longitude
|
|
161
|
+
|
|
162
|
+
@longitude.setter
|
|
163
|
+
def longitude(self, value: float) -> None:
|
|
164
|
+
"""
|
|
165
|
+
Set the longitude coordinate of the node.
|
|
166
|
+
|
|
167
|
+
:param value: Longitude value.
|
|
168
|
+
:type value: float
|
|
169
|
+
"""
|
|
170
|
+
self._longitude = value
|
|
171
|
+
|
|
172
|
+
@property
|
|
173
|
+
def weight(self) -> float:
|
|
174
|
+
"""
|
|
175
|
+
Get the weight of the node.
|
|
176
|
+
|
|
177
|
+
:return: Node weight.
|
|
178
|
+
:rtype: float
|
|
179
|
+
"""
|
|
180
|
+
return self._weight
|
|
181
|
+
|
|
182
|
+
@weight.setter
|
|
183
|
+
def weight(self, value: float) -> None:
|
|
184
|
+
"""
|
|
185
|
+
Set the weight of the node.
|
|
186
|
+
|
|
187
|
+
:param value: Node weight.
|
|
188
|
+
:type value: float
|
|
189
|
+
"""
|
|
190
|
+
self._weight = value
|
|
191
|
+
|
|
192
|
+
@property
|
|
193
|
+
def pop(self) -> int:
|
|
194
|
+
"""
|
|
195
|
+
Get the population of the node.
|
|
196
|
+
|
|
197
|
+
:return: Node population.
|
|
198
|
+
:rtype: int
|
|
199
|
+
"""
|
|
200
|
+
return self._pop
|
|
201
|
+
|
|
202
|
+
@pop.setter
|
|
203
|
+
def pop(self, value: int) -> None:
|
|
204
|
+
"""
|
|
205
|
+
Set the population of the node.
|
|
206
|
+
|
|
207
|
+
:param value: Node population.
|
|
208
|
+
:type value: int
|
|
209
|
+
"""
|
|
210
|
+
self._pop = value
|
|
211
|
+
|
|
212
|
+
def coordinates(self) -> Tuple[float, float]:
|
|
213
|
+
"""
|
|
214
|
+
Returns the (latitude, longitude) coordinates of the node.
|
|
215
|
+
|
|
216
|
+
:return: Tuple containing latitude and longitude.
|
|
217
|
+
:rtype: Tuple[float, float]
|
|
218
|
+
"""
|
|
219
|
+
return self._latitude, self._longitude
|
|
220
|
+
|
|
221
|
+
def __repr__(self) -> str:
|
|
222
|
+
"""Return a concise representation of the Node.
|
|
223
|
+
|
|
224
|
+
Includes id, name, latitude, longitude and additional attributes.
|
|
225
|
+
"""
|
|
226
|
+
return (
|
|
227
|
+
f"Node(id={self._id}, name={self._name!r}, latitude={self._latitude}, "
|
|
228
|
+
f"longitude={self._longitude}, weight={self._weight}, pop={self._pop}, "
|
|
229
|
+
f"dc={self._dc}, ixp={self._ixp})"
|
|
230
|
+
)
|
topolib/topology/path.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Path class for representing a sequence of nodes and links in a topology.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import List, Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Path:
|
|
9
|
+
"""
|
|
10
|
+
Represents a path through the network topology as an ordered sequence of nodes and links.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
nodes : list
|
|
15
|
+
Ordered list of node objects in the path.
|
|
16
|
+
links : list
|
|
17
|
+
Ordered list of link objects in the path (len(links) == len(nodes) - 1).
|
|
18
|
+
|
|
19
|
+
Raises
|
|
20
|
+
------
|
|
21
|
+
ValueError
|
|
22
|
+
If the number of nodes and links is inconsistent or empty.
|
|
23
|
+
|
|
24
|
+
Attributes
|
|
25
|
+
----------
|
|
26
|
+
nodes : list
|
|
27
|
+
Ordered list of nodes in the path.
|
|
28
|
+
links : list
|
|
29
|
+
Ordered list of links in the path.
|
|
30
|
+
|
|
31
|
+
Examples
|
|
32
|
+
--------
|
|
33
|
+
>>> nodes = [Node(1), Node(2), Node(3)]
|
|
34
|
+
>>> links = [Link('a'), Link('b')]
|
|
35
|
+
>>> path = Path(nodes, links)
|
|
36
|
+
>>> path.length()
|
|
37
|
+
2
|
|
38
|
+
>>> path.endpoints()
|
|
39
|
+
(Node(1), Node(3))
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, nodes: List[Any], links: List[Any]):
|
|
43
|
+
if not nodes or not links:
|
|
44
|
+
raise ValueError("A path must have at least one node and one link.")
|
|
45
|
+
if len(nodes) != len(links) + 1:
|
|
46
|
+
raise ValueError("Number of nodes must be one more than number of links.")
|
|
47
|
+
self.nodes = nodes
|
|
48
|
+
self.links = links
|
|
49
|
+
|
|
50
|
+
def length(self) -> int:
|
|
51
|
+
"""
|
|
52
|
+
Return the number of links in the path.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
int
|
|
57
|
+
Number of links in the path.
|
|
58
|
+
"""
|
|
59
|
+
return len(self.links)
|
|
60
|
+
|
|
61
|
+
def hop_count(self) -> int:
|
|
62
|
+
"""
|
|
63
|
+
Return the number of hops (links) in the path.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
int
|
|
68
|
+
Number of hops (links) in the path.
|
|
69
|
+
"""
|
|
70
|
+
return self.length()
|
|
71
|
+
|
|
72
|
+
def endpoints(self):
|
|
73
|
+
"""
|
|
74
|
+
Return the source and target nodes of the path as a tuple.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
tuple
|
|
79
|
+
(source_node, target_node)
|
|
80
|
+
"""
|
|
81
|
+
return (self.nodes[0], self.nodes[-1])
|
|
82
|
+
|
|
83
|
+
def __repr__(self):
|
|
84
|
+
return f"Path(nodes={self.nodes}, links={self.links})"
|