-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathInternetExchange.py
96 lines (73 loc) · 2.77 KB
/
InternetExchange.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
from .Printable import Printable
from .enums import NetworkType, NodeRole
from .Node import Node,Router
from .Network import Network
from .AddressAssignmentConstraint import AddressAssignmentConstraint
from .Emulator import Emulator
from .Configurable import Configurable
from ipaddress import IPv4Network
class InternetExchange(Printable, Configurable):
"""!
@brief InternetExchange class.
This class represents an internet exchange.
"""
__id: int
__net: Network
__rs: Node
__name: str
def __init__(self, id: int, prefix: str = "auto", aac: AddressAssignmentConstraint = None, create_rs = True):
"""!
@brief InternetExchange constructor.
@param id ID (ASN) for the IX.
@param prefix (optional) prefix to use as peering LAN.
@param aac (option) AddressAssignmentConstraint to use.
@param create_rs (optional) create route server node for the IX or not.
( route servers are only relevant for BGP, thus the default is True. But RSes can be disabled for SCION)
"""
self.__id = id
assert prefix != "auto" or self.__id <= 255, "can't use auto: id > 255"
network = IPv4Network(prefix) if prefix != "auto" else IPv4Network("10.{}.0.0/24".format(self.__id))
self.__name = 'ix{}'.format(str(self.__id))
self.__net = Network(self.__name, NetworkType.InternetExchange, network, aac, False, scope=str(id))
if create_rs:
self.__rs = Router(self.__name, NodeRole.RouteServer, self.__id)
self.__rs.joinNetwork(self.__name)
else:
self.__rs = None
def configure(self, emulator: Emulator):
reg = emulator.getRegistry()
reg.register('ix', 'net', self.__name, self.__net)
if self.__rs != None:
reg.register('ix', 'rs', self.__name, self.__rs)
self.__rs.configure(emulator)
def getId(self) -> int:
"""!
@brief Get internet exchange ID.
@returns ID.
"""
return self.__id
def getPeeringLan(self) -> Network:
"""!
@brief Get the peering lan network for this IX.
@returns Peering network.
"""
return self.__net
def getRouteServerNode(self) -> Node:
"""!
@brief Get route server node.
@returns RS node.
"""
return self.__rs
def getNetwork(self) -> Network:
"""!
@brief Get the network of Internet Exchange.
@returns Network.
"""
return self.__net
def print(self, indent: int) -> str:
out = ' ' * indent
out += 'InternetExchange {}:\n'.format(self.__id)
indent += 4
out += ' ' * indent
out += 'Peering LAN Prefix: {}\n'.format(self.__net.getPrefix())
return out