1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix port naming for FrameRelay switch

Fix #735
This commit is contained in:
Julien Duponchelle 2016-10-26 11:59:16 +02:00
parent 048d2c12d0
commit cf3ed5a329
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 46 additions and 7 deletions

View File

@ -500,8 +500,14 @@ class Node:
self._ports.append(PortFactory("ATM{}".format(adapter_number), adapter_number, adapter_number, 0, "atm"))
return
elif self._node_type == "frame_relay_switch":
for adapter_number in range(0, len(self.properties["mappings"])):
self._ports.append(PortFactory("FrameRelay{}".format(adapter_number), adapter_number, adapter_number, 0, "frame_relay"))
frame_relay_port = set()
# Mapping is like {"1:101": "10:202"}
for source, dest in self.properties["mappings"].items():
frame_relay_port.add(int(source.split(":")[0]))
frame_relay_port.add(int(dest.split(":")[0]))
frame_relay_port = sorted(frame_relay_port)
for port in frame_relay_port:
self._ports.append(PortFactory("{}".format(port), 0, 0, port, "frame_relay"))
return
elif self._node_type == "dynamips":
self._ports = DynamipsPortFactory(self.properties)

View File

@ -34,6 +34,10 @@ class FrameRelayPort(SerialPort):
return "FrameRelay"
@property
def short_name(self):
return "{}".format(self._port_number)
@property
def data_link_types(self):
"""

View File

@ -48,10 +48,14 @@ class Port:
def link_type(self):
return "ethernet"
@property
def short_name(self):
return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number)
def __json__(self):
return {
"name": self._name,
"short_name": self.short_name_type + "{}/{}".format(self._interface_number, self._port_number),
"short_name": self.short_name,
"data_link_types": self.data_link_types,
"port_number": self._port_number,
"adapter_number": self._adapter_number,

View File

@ -213,15 +213,40 @@ def test_list_ports_frame_relay_switch(project, compute):
node_id=str(uuid.uuid4()),
node_type="frame_relay_switch")
node.properties["mappings"] = {
"1:0:100": "10:0:200"
"1:101": "10:202",
"2:102": "11:203"
}
assert node.__json__()["ports"] == [
{
"name": "FrameRelay0",
"short_name": "s0/0",
"name": "1",
"short_name": "1",
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
"port_number": 0,
"port_number": 1,
"adapter_number": 0,
"link_type": "serial"
},
{
"name": "2",
"short_name": "2",
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
"port_number": 2,
"adapter_number": 0,
"link_type": "serial"
},
{
"name": "10",
"short_name": "10",
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
"port_number": 10,
"adapter_number": 0,
"link_type": "serial"
},
{
"name": "11",
"short_name": "11",
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
"port_number": 11,
"adapter_number": 0,
"link_type": "serial"
}