From 19a6157f641faafdb61bfdd5c4f5f1162c4d8851 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 12 May 2017 09:48:05 +0200 Subject: [PATCH 1/2] Fix wic numbering Fix #1011 --- gns3server/controller/ports/port.py | 4 ++++ gns3server/controller/ports/port_factory.py | 6 ++++-- tests/controller/test_node_port_name.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/gns3server/controller/ports/port.py b/gns3server/controller/ports/port.py index b801ddbf..886973e5 100644 --- a/gns3server/controller/ports/port.py +++ b/gns3server/controller/ports/port.py @@ -70,6 +70,10 @@ class Port: return self._name return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number) + @short_name.setter + def short_name(self, val): + self._short_name = val + def __json__(self): return { "name": self._name, diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index bc4d509b..4a1fdb93 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -194,7 +194,9 @@ class DynamipsPortFactory: port_class = cls.WIC_MATRIX[properties[name]]["port"] if port_class: for port_number in range(0, cls.WIC_MATRIX[properties[name]]["nb_ports"]): - name = "{}{}/{}".format(port_class.long_name_type(), 0, wic_port_number) - ports.append(port_class(name, 0, 0, wic_port_number)) + name = "{}{}/{}".format(port_class.long_name_type(), 0, wic_port_number - 16) + port = port_class(name, 0, 0, wic_port_number) + port.short_name = "{}{}/{}".format(port.short_name_type, 0, wic_port_number - 16) + ports.append(port) wic_port_number += 1 return ports diff --git a/tests/controller/test_node_port_name.py b/tests/controller/test_node_port_name.py index 8d0ccc64..9ccf55db 100644 --- a/tests/controller/test_node_port_name.py +++ b/tests/controller/test_node_port_name.py @@ -548,8 +548,8 @@ def test_list_ports_dynamips(project, compute): "link_type": "ethernet" }, { - "name": "Serial0/16", - "short_name": "s0/16", + "name": "Serial0/0", + "short_name": "s0/0", "data_link_types": { "Cisco HDLC": "DLT_C_HDLC", "Cisco PPP": "DLT_PPP_SERIAL", @@ -559,8 +559,8 @@ def test_list_ports_dynamips(project, compute): "link_type": "serial" }, { - "name": "Serial0/17", - "short_name": "s0/17", + "name": "Serial0/1", + "short_name": "s0/1", "data_link_types": { "Cisco HDLC": "DLT_C_HDLC", "Cisco PPP": "DLT_PPP_SERIAL", @@ -570,8 +570,8 @@ def test_list_ports_dynamips(project, compute): "link_type": "serial" }, { - "name": "Serial0/18", - "short_name": "s0/18", + "name": "Serial0/2", + "short_name": "s0/2", "data_link_types": { "Cisco HDLC": "DLT_C_HDLC", "Cisco PPP": "DLT_PPP_SERIAL", @@ -581,8 +581,8 @@ def test_list_ports_dynamips(project, compute): "link_type": "serial" }, { - "name": "Serial0/19", - "short_name": "s0/19", + "name": "Serial0/3", + "short_name": "s0/3", "data_link_types": { "Cisco HDLC": "DLT_C_HDLC", "Cisco PPP": "DLT_PPP_SERIAL", From 5721dd3f30ba89b360d3cc07504cbda4783a8b78 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 12 May 2017 14:12:24 +0200 Subject: [PATCH 2/2] Fix port numbering for Wic slot 1 & 2 --- gns3server/controller/ports/port_factory.py | 12 +++++++++--- tests/controller/test_node_port_name.py | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index 4a1fdb93..39dac69c 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -181,7 +181,9 @@ class DynamipsPortFactory: ports = [] adapter_number = 0 - wic_port_number = 16 + wic_slot = 1 + wic_port_number = wic_slot * 16 + display_wic_port_number = 0 for name in sorted(properties.keys()): if name.startswith("slot") and properties[name]: port_class = cls.ADAPTER_MATRIX[properties[name]]["port"] @@ -194,9 +196,13 @@ class DynamipsPortFactory: port_class = cls.WIC_MATRIX[properties[name]]["port"] if port_class: for port_number in range(0, cls.WIC_MATRIX[properties[name]]["nb_ports"]): - name = "{}{}/{}".format(port_class.long_name_type(), 0, wic_port_number - 16) + name = "{}{}/{}".format(port_class.long_name_type(), 0, display_wic_port_number) port = port_class(name, 0, 0, wic_port_number) - port.short_name = "{}{}/{}".format(port.short_name_type, 0, wic_port_number - 16) + port.short_name = "{}{}/{}".format(port.short_name_type, 0, display_wic_port_number) ports.append(port) + display_wic_port_number += 1 wic_port_number += 1 + wic_slot += 1 + wic_port_number = wic_slot * 16 + return ports diff --git a/tests/controller/test_node_port_name.py b/tests/controller/test_node_port_name.py index 9ccf55db..5da90dc8 100644 --- a/tests/controller/test_node_port_name.py +++ b/tests/controller/test_node_port_name.py @@ -576,7 +576,7 @@ def test_list_ports_dynamips(project, compute): "Cisco HDLC": "DLT_C_HDLC", "Cisco PPP": "DLT_PPP_SERIAL", "Frame Relay": "DLT_FRELAY"}, - "port_number": 18, + "port_number": 32, "adapter_number": 0, "link_type": "serial" }, @@ -587,7 +587,7 @@ def test_list_ports_dynamips(project, compute): "Cisco HDLC": "DLT_C_HDLC", "Cisco PPP": "DLT_PPP_SERIAL", "Frame Relay": "DLT_FRELAY"}, - "port_number": 19, + "port_number": 33, "adapter_number": 0, "link_type": "serial" }