mirror of https://github.com/GNS3/gns3-server
parent
f06c00fdb8
commit
2f0e2260ab
@ -0,0 +1,38 @@
|
||||
Port name formatting
|
||||
####################
|
||||
|
||||
Some node like qemu allow you to personnalize the name of ports in order to match the name of the interfaces inside the emulator.
|
||||
|
||||
Simple syntax
|
||||
==============
|
||||
The first {} will be replace by the interface number
|
||||
|
||||
For example: "eth{}" will give:
|
||||
* eth0
|
||||
* eth1
|
||||
* eth2
|
||||
|
||||
Or more verbose "eth{port0}" and "eth{0}" will do the same.
|
||||
|
||||
Use segments
|
||||
============
|
||||
|
||||
Segment allow you to split your interface in multiple ports
|
||||
|
||||
For example "Ethernet{segment0}/{port0}" with a segment size of 3:
|
||||
* Ethernet0/0
|
||||
* Ethernet0/1
|
||||
* Ethernet0/2
|
||||
* Ethernet1/0
|
||||
* Ethernet1/1
|
||||
|
||||
You can also change the start number.
|
||||
|
||||
For example "Ethernet{segment1}/{port1}" with a segment size of 3:
|
||||
* Ethernet1/1
|
||||
* Ethernet1/2
|
||||
* Ethernet1/3
|
||||
* Ethernet2/1
|
||||
* Ethernet2/2
|
||||
|
||||
This work from port0 to port9 if you need a bigger range ask us.
|
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
ATM port for ATM link end points.
|
||||
"""
|
||||
|
||||
from .port import Port
|
||||
|
||||
|
||||
class ATMPort(Port):
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "ATM"
|
||||
|
||||
@staticmethod
|
||||
def shortNameType():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "a"
|
||||
|
||||
@staticmethod
|
||||
def linkType():
|
||||
"""
|
||||
Returns the link type to be used to connect this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "Serial"
|
||||
|
||||
@staticmethod
|
||||
def dataLinkTypes():
|
||||
"""
|
||||
Returns the supported PCAP DLTs.
|
||||
|
||||
:return: dictionary
|
||||
"""
|
||||
|
||||
return {"ATM": "DLT_ATM_RFC1483"}
|
@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Ethernet port for Ethernet link end points.
|
||||
"""
|
||||
|
||||
|
||||
from .port import Port
|
||||
|
||||
|
||||
class EthernetPort(Port):
|
||||
|
||||
"""
|
||||
Ethernet port.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
@staticmethod
|
||||
def shortNameType():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "e"
|
@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
FastEthernet port for Ethernet link end points.
|
||||
"""
|
||||
|
||||
from .port import Port
|
||||
|
||||
|
||||
class FastEthernetPort(Port):
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
@staticmethod
|
||||
def shortNameType():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "f"
|
@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Frame relay port for serial link end points.
|
||||
"""
|
||||
|
||||
from .serial_port import SerialPort
|
||||
|
||||
|
||||
class FrameRelayPort(SerialPort):
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "FrameRelay"
|
||||
|
||||
@staticmethod
|
||||
def dataLinkTypes():
|
||||
"""
|
||||
Returns the supported PCAP DLTs.
|
||||
|
||||
:return: dictionary
|
||||
"""
|
||||
|
||||
return {"Frame Relay": "DLT_FRELAY"}
|
@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
GigabitEthernet port for Ethernet link end points.
|
||||
"""
|
||||
|
||||
from .port import Port
|
||||
|
||||
|
||||
class GigabitEthernetPort(Port):
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "GigabitEthernet"
|
||||
|
||||
@staticmethod
|
||||
def shortNameType():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "g"
|
@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
class Port:
|
||||
"""
|
||||
Base class for port objects.
|
||||
"""
|
||||
|
||||
def __init__(self, name, interface_number, adapter_number, port_number):
|
||||
self._interface_number = interface_number
|
||||
self._adapter_number = adapter_number
|
||||
self._port_number = port_number
|
||||
self._name = name
|
||||
|
||||
@staticmethod
|
||||
def dataLinkTypes():
|
||||
"""
|
||||
Returns the supported PCAP DLTs.
|
||||
|
||||
:return: dictionary
|
||||
"""
|
||||
return {"Ethernet": "DLT_EN10MB"}
|
||||
|
||||
@staticmethod
|
||||
def linkType():
|
||||
return "Ethernet"
|
||||
|
||||
def __json__(self):
|
||||
return {
|
||||
"name": self._name,
|
||||
"short_name": self.shortNameType() + "{}/{}".format(self._interface_number, self._port_number),
|
||||
"data_link_types": self.dataLinkTypes(),
|
||||
"port_number": self._port_number,
|
||||
"adapter_number": self._adapter_number,
|
||||
"link_type": self.linkType().lower()
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2016 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .atm_port import ATMPort
|
||||
from .frame_relay_port import FrameRelayPort
|
||||
from .gigabitethernet_port import GigabitEthernetPort
|
||||
from .fastethernet_port import FastEthernetPort
|
||||
from .ethernet_port import EthernetPort
|
||||
from .serial_port import SerialPort
|
||||
from .pos_port import POSPort
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
PORTS = {
|
||||
'atm': ATMPort,
|
||||
'frame_relay': FrameRelayPort,
|
||||
'fastethernet': FastEthernetPort,
|
||||
'gigabitethernet': GigabitEthernetPort,
|
||||
'ethernet': EthernetPort,
|
||||
'serial': SerialPort
|
||||
}
|
||||
|
||||
|
||||
class PortFactory:
|
||||
"""
|
||||
Factory to create an Port object based on the type
|
||||
"""
|
||||
|
||||
def __new__(cls, name, interface_number, adapter_number, port_number, port_type, **kwargs):
|
||||
return PORTS[port_type](name, interface_number, adapter_number, port_number, **kwargs)
|
||||
|
||||
|
||||
class StandardPortFactory:
|
||||
"""
|
||||
Create ports for standard device
|
||||
"""
|
||||
def __new__(cls, properties, port_by_adapter, first_port_name, port_name_format, port_segment_size):
|
||||
ports = []
|
||||
interface_number = segment_number = 0
|
||||
if "serial_adapters" in properties:
|
||||
for adapter_number in range(0, properties["serial_adapters"]):
|
||||
for port_number in range(0, port_by_adapter):
|
||||
ports.append(PortFactory("Serial{}/{}".format(adapter_number, port_number), adapter_number, adapter_number, port_number, "serial"))
|
||||
|
||||
if "ethernet_adapters" in properties:
|
||||
ethernet_adapters = properties["ethernet_adapters"]
|
||||
else:
|
||||
ethernet_adapters = properties.get("adapters", 1)
|
||||
|
||||
for adapter_number in range(0, ethernet_adapters):
|
||||
for port_number in range(0, port_by_adapter):
|
||||
if first_port_name and adapter_number == 0:
|
||||
port_name = first_port_name
|
||||
else:
|
||||
port_name = port_name_format.format(
|
||||
interface_number,
|
||||
segment_number,
|
||||
adapter=adapter_number,
|
||||
**cls._generate_replacement(interface_number, segment_number))
|
||||
interface_number += 1
|
||||
if port_segment_size and interface_number % port_segment_size == 0:
|
||||
segment_number += 1
|
||||
interface_number = 0
|
||||
|
||||
ports.append(PortFactory(port_name, adapter_number, adapter_number, port_number, "ethernet"))
|
||||
return ports
|
||||
|
||||
@staticmethod
|
||||
def _generate_replacement(interface_number, segment_number):
|
||||
"""
|
||||
This will generate replacement string for
|
||||
{port0} => {port9}
|
||||
{segment0} => {segment9}
|
||||
"""
|
||||
replacements = {}
|
||||
for i in range(0, 9):
|
||||
replacements["port" + str(i)] = interface_number + i
|
||||
replacements["segment" + str(i)] = segment_number + i
|
||||
return replacements
|
||||
|
||||
|
||||
class DynamipsPortFactory:
|
||||
"""
|
||||
Create port for dynamips devices
|
||||
"""
|
||||
ADAPTER_MATRIX = {
|
||||
"C1700-MB-1FE": {"nb_ports": 1,
|
||||
"port": FastEthernetPort},
|
||||
"C1700-MB-WIC1": {"nb_ports": 0,
|
||||
"port": None},
|
||||
"C2600-MB-1E": {"nb_ports": 1,
|
||||
"port": EthernetPort},
|
||||
"C2600-MB-1FE": {"nb_ports": 1,
|
||||
"port": FastEthernetPort},
|
||||
"C2600-MB-2E": {"nb_ports": 2,
|
||||
"port": EthernetPort},
|
||||
"C2600-MB-2FE": {"nb_ports": 2,
|
||||
"port": FastEthernetPort},
|
||||
"C7200-IO-2FE": {"nb_ports": 2,
|
||||
"port": FastEthernetPort},
|
||||
"C7200-IO-FE": {"nb_ports": 1,
|
||||
"port": FastEthernetPort},
|
||||
"C7200-IO-GE-E": {"nb_ports": 1,
|
||||
"port": GigabitEthernetPort},
|
||||
"GT96100-FE": {"nb_ports": 2,
|
||||
"port": FastEthernetPort},
|
||||
"Leopard-2FE": {"nb_ports": 2,
|
||||
"port": FastEthernetPort},
|
||||
"NM-16ESW": {"nb_ports": 16,
|
||||
"port": FastEthernetPort},
|
||||
"NM-1E": {"nb_ports": 1,
|
||||
"port": EthernetPort},
|
||||
"NM-1FE-TX": {"nb_ports": 1,
|
||||
"port": FastEthernetPort},
|
||||
"NM-4E": {"nb_ports": 4,
|
||||
"port": EthernetPort},
|
||||
"NM-4T": {"nb_ports": 4,
|
||||
"port": SerialPort},
|
||||
"PA-2FE-TX": {"nb_ports": 2,
|
||||
"port": FastEthernetPort},
|
||||
"PA-4E": {"nb_ports": 4,
|
||||
"port": EthernetPort},
|
||||
"PA-4T+": {"nb_ports": 4,
|
||||
"port": SerialPort},
|
||||
"PA-8E": {"nb_ports": 8,
|
||||
"port": EthernetPort},
|
||||
"PA-8T": {"nb_ports": 8,
|
||||
"port": SerialPort},
|
||||
"PA-A1": {"nb_ports": 1,
|
||||
"port": ATMPort},
|
||||
"PA-FE-TX": {"nb_ports": 1,
|
||||
"port": FastEthernetPort},
|
||||
"PA-GE": {"nb_ports": 1,
|
||||
"port": GigabitEthernetPort},
|
||||
"PA-POS-OC3": {"nb_ports": 1,
|
||||
"port": POSPort},
|
||||
}
|
||||
|
||||
WIC_MATRIX = {"WIC-1ENET": {"nb_ports": 1,
|
||||
"port": EthernetPort},
|
||||
|
||||
"WIC-1T": {"nb_ports": 1,
|
||||
"port": SerialPort},
|
||||
|
||||
"WIC-2T": {"nb_ports": 2,
|
||||
"port": SerialPort}
|
||||
}
|
||||
|
||||
def __new__(cls, properties):
|
||||
ports = []
|
||||
|
||||
interface_numbers = {}
|
||||
|
||||
adapter_number = 0
|
||||
wic_port_number = 16
|
||||
for name in sorted(properties.keys()):
|
||||
if name.startswith("slot") and properties[name]:
|
||||
port_class = cls.ADAPTER_MATRIX[properties[name]]["port"]
|
||||
if port_class:
|
||||
interface_numbers.setdefault(port_class, 0)
|
||||
interface_number = interface_numbers[port_class]
|
||||
for port_number in range(0, cls.ADAPTER_MATRIX[properties[name]]["nb_ports"]):
|
||||
name = "{}{}/{}".format(port_class.longNameType(), interface_number, port_number)
|
||||
ports.append(port_class(name, interface_number, adapter_number, port_number))
|
||||
interface_numbers[port_class] += 1
|
||||
adapter_number += 1
|
||||
elif name.startswith("wic") and properties[name]:
|
||||
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.longNameType(), 0, wic_port_number)
|
||||
ports.append(port_class(name, 0, 0, wic_port_number))
|
||||
wic_port_number += 1
|
||||
return ports
|
@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
POS port for Packet over SONET link end points.
|
||||
"""
|
||||
|
||||
from .port import Port
|
||||
|
||||
|
||||
class POSPort(Port):
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "POS"
|
||||
|
||||
@staticmethod
|
||||
def shortNameType():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "p"
|
||||
|
||||
@staticmethod
|
||||
def linkType():
|
||||
"""
|
||||
Returns the link type to be used to connect this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "Serial"
|
||||
|
||||
@staticmethod
|
||||
def dataLinkTypes():
|
||||
"""
|
||||
Returns the supported PCAP DLTs.
|
||||
|
||||
:return: dictionary
|
||||
"""
|
||||
|
||||
# Packet capture on PoS is not supported
|
||||
return {}
|
@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2014 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Serial port for serial link end points.
|
||||
"""
|
||||
|
||||
from .port import Port
|
||||
|
||||
|
||||
class SerialPort(Port):
|
||||
|
||||
@staticmethod
|
||||
def longNameType():
|
||||
"""
|
||||
Returns the long name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "Serial"
|
||||
|
||||
@staticmethod
|
||||
def shortNameType():
|
||||
"""
|
||||
Returns the short name type for this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "s"
|
||||
|
||||
@staticmethod
|
||||
def linkType():
|
||||
"""
|
||||
Returns the link type to be used to connect this port.
|
||||
|
||||
:returns: string
|
||||
"""
|
||||
|
||||
return "Serial"
|
||||
|
||||
@staticmethod
|
||||
def dataLinkTypes():
|
||||
"""
|
||||
Returns the supported PCAP DLTs.
|
||||
|
||||
:return: dictionary
|
||||
"""
|
||||
|
||||
return {"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"}
|
@ -0,0 +1,446 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2016 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import uuid
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
from gns3server.controller.node import Node
|
||||
from gns3server.controller.project import Project
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def compute():
|
||||
s = AsyncioMagicMock()
|
||||
s.id = "http://test.com:42"
|
||||
return s
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def project(controller):
|
||||
return Project(str(uuid.uuid4()), controller=controller)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def node(compute, project):
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"})
|
||||
return node
|
||||
|
||||
|
||||
def test_list_ports(node):
|
||||
"""
|
||||
List port by default
|
||||
"""
|
||||
assert node.__json__()["ports"] == [
|
||||
{
|
||||
"name": "Ethernet0",
|
||||
"short_name": "e0/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_list_ports_port_name_format(node):
|
||||
"""
|
||||
Support port name format
|
||||
"""
|
||||
node._first_port_name = None
|
||||
node._port_name_format = "eth{}"
|
||||
assert node.__json__()["ports"][0]["name"] == "eth0"
|
||||
node._port_name_format = "eth{port0}"
|
||||
assert node.__json__()["ports"][0]["name"] == "eth0"
|
||||
node._port_name_format = "eth{port1}"
|
||||
assert node.__json__()["ports"][0]["name"] == "eth1"
|
||||
|
||||
node._first_port_name = ""
|
||||
node._port_segment_size = 2
|
||||
node._port_name_format = "eth{segment0}/{port0}"
|
||||
node.properties["adapters"] = 8
|
||||
assert node.__json__()["ports"][6]["name"] == "eth3/0"
|
||||
assert node.__json__()["ports"][7]["name"] == "eth3/1"
|
||||
|
||||
node._first_port_name = "mgnt0"
|
||||
assert node.__json__()["ports"][0]["name"] == "mgnt0"
|
||||
assert node.__json__()["ports"][1]["name"] == "eth0/0"
|
||||
|
||||
|
||||
def test_list_ports_adapters(node):
|
||||
"""
|
||||
List port using adapters properties
|
||||
"""
|
||||
node.properties["adapters"] = 2
|
||||
assert node.__json__()["ports"] == [
|
||||
{
|
||||
"name": "Ethernet0",
|
||||
"short_name": "e0/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet1",
|
||||
"short_name": "e1/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_list_ports_atm_switch(project, compute):
|
||||
"""
|
||||
List port for atm switch
|
||||
"""
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="atm_switch")
|
||||
node.properties["mappings"] = {
|
||||
"1:0:100": "10:0:200"
|
||||
}
|
||||
|
||||
assert node.__json__()["ports"] == [
|
||||
{
|
||||
"name": "ATM0",
|
||||
"short_name": "a0/0",
|
||||
"data_link_types": {"ATM": "DLT_ATM_RFC1483"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_list_ports_frame_relay_switch(project, compute):
|
||||
"""
|
||||
List port for frame relay switch
|
||||
"""
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="frame_relay_switch")
|
||||
node.properties["mappings"] = {
|
||||
"1:0:100": "10:0:200"
|
||||
}
|
||||
|
||||
assert node.__json__()["ports"] == [
|
||||
{
|
||||
"name": "FrameRelay0",
|
||||
"short_name": "s0/0",
|
||||
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_list_ports_iou(compute, project):
|
||||
"""
|
||||
IOU has a special behavior 4 port by adapters
|
||||
"""
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="iou")
|
||||
node.properties["serial_adapters"] = 2
|
||||
node.properties["ethernet_adapters"] = 3
|
||||
assert node.__json__()["ports"] == [
|
||||
{
|
||||
"name": "Serial0/0",
|
||||
"short_name": "s0/0",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/1",
|
||||
"short_name": "s0/1",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 1,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/2",
|
||||
"short_name": "s0/2",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 2,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/3",
|
||||
"short_name": "s0/3",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 3,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial1/0",
|
||||
"short_name": "s1/0",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 0,
|
||||
"adapter_number": 1,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial1/1",
|
||||
"short_name": "s1/1",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 1,
|
||||
"adapter_number": 1,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial1/2",
|
||||
"short_name": "s1/2",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 2,
|
||||
"adapter_number": 1,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial1/3",
|
||||
"short_name": "s1/3",
|
||||
"data_link_types": {
|
||||
"Frame Relay": "DLT_FRELAY",
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL"
|
||||
},
|
||||
"port_number": 3,
|
||||
"adapter_number": 1,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet0/0",
|
||||
"short_name": "e0/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet0/1",
|
||||
"short_name": "e0/1",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 1,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet0/2",
|
||||
"short_name": "e0/2",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 2,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet0/3",
|
||||
"short_name": "e0/3",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 3,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet1/0",
|
||||
"short_name": "e1/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet1/1",
|
||||
"short_name": "e1/1",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 1,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet1/2",
|
||||
"short_name": "e1/2",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 2,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet1/3",
|
||||
"short_name": "e1/3",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 3,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet2/0",
|
||||
"short_name": "e2/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 2,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet2/1",
|
||||
"short_name": "e2/1",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 1,
|
||||
"adapter_number": 2,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet2/2",
|
||||
"short_name": "e2/2",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 2,
|
||||
"adapter_number": 2,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Ethernet2/3",
|
||||
"short_name": "e2/3",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 3,
|
||||
"adapter_number": 2,
|
||||
"link_type": "ethernet"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_list_ports_dynamips(project, compute):
|
||||
"""
|
||||
List port for dynamips
|
||||
"""
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="dynamips")
|
||||
node.properties["slot0"] = "C7200-IO-FE"
|
||||
node.properties["slot1"] = "GT96100-FE"
|
||||
node.properties["wic0"] = "WIC-2T"
|
||||
node.properties["wic1"] = "WIC-2T"
|
||||
|
||||
assert node.__json__()["ports"] == [
|
||||
{
|
||||
"name": "FastEthernet0/0",
|
||||
"short_name": "f0/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 0,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "FastEthernet1/0",
|
||||
"short_name": "f1/0",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 0,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "FastEthernet1/1",
|
||||
"short_name": "f1/1",
|
||||
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
||||
"port_number": 1,
|
||||
"adapter_number": 1,
|
||||
"link_type": "ethernet"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/16",
|
||||
"short_name": "s0/16",
|
||||
"data_link_types": {
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL",
|
||||
"Frame Relay": "DLT_FRELAY"},
|
||||
"port_number": 16,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/17",
|
||||
"short_name": "s0/17",
|
||||
"data_link_types": {
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL",
|
||||
"Frame Relay": "DLT_FRELAY"},
|
||||
"port_number": 17,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/18",
|
||||
"short_name": "s0/18",
|
||||
"data_link_types": {
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL",
|
||||
"Frame Relay": "DLT_FRELAY"},
|
||||
"port_number": 18,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
},
|
||||
{
|
||||
"name": "Serial0/19",
|
||||
"short_name": "s0/19",
|
||||
"data_link_types": {
|
||||
"Cisco HDLC": "DLT_C_HDLC",
|
||||
"Cisco PPP": "DLT_PPP_SERIAL",
|
||||
"Frame Relay": "DLT_FRELAY"},
|
||||
"port_number": 19,
|
||||
"adapter_number": 0,
|
||||
"link_type": "serial"
|
||||
}
|
||||
]
|
Loading…
Reference in new issue