mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Dynamips backend (API implementation)
This commit is contained in:
1 parent
0cb98318b5
commit
2516bf80a8
86 files changed
+8004
-418
No files matched your search
@@ -16,10 +16,61 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from gns3server.modules import IModule
|
||||
import gns3server.jsonrpc as jsonrpc
|
||||
from .hypervisor import Hypervisor
|
||||
from .hypervisor_manager import HypervisorManager
|
||||
from .dynamips_error import DynamipsError
|
||||
|
||||
# nodes
|
||||
from .nodes.router import Router
|
||||
from .nodes.c1700 import C1700
|
||||
from .nodes.c2600 import C2600
|
||||
from .nodes.c2691 import C2691
|
||||
from .nodes.c3600 import C3600
|
||||
from .nodes.c3725 import C3725
|
||||
from .nodes.c3745 import C3745
|
||||
from .nodes.c7200 import C7200
|
||||
from .nodes.bridge import Bridge
|
||||
from .nodes.ethernet_switch import EthernetSwitch
|
||||
from .nodes.atm_switch import ATMSwitch
|
||||
from .nodes.atm_bridge import ATMBridge
|
||||
from .nodes.frame_relay_switch import FrameRelaySwitch
|
||||
from .nodes.hub import Hub
|
||||
|
||||
# adapters
|
||||
from .adapters.c7200_io_2fe import C7200_IO_2FE
|
||||
from .adapters.c7200_io_fe import C7200_IO_FE
|
||||
from .adapters.c7200_io_ge_e import C7200_IO_GE_E
|
||||
from .adapters.nm_16esw import NM_16ESW
|
||||
from .adapters.nm_1e import NM_1E
|
||||
from .adapters.nm_1fe_tx import NM_1FE_TX
|
||||
from .adapters.nm_4e import NM_4E
|
||||
from .adapters.nm_4t import NM_4T
|
||||
from .adapters.pa_2fe_tx import PA_2FE_TX
|
||||
from .adapters.pa_4e import PA_4E
|
||||
from .adapters.pa_4t import PA_4T
|
||||
from .adapters.pa_8e import PA_8E
|
||||
from .adapters.pa_8t import PA_8T
|
||||
from .adapters.pa_a1 import PA_A1
|
||||
from .adapters.pa_fe_tx import PA_FE_TX
|
||||
from .adapters.pa_ge import PA_GE
|
||||
from .adapters.pa_pos_oc3 import PA_POS_OC3
|
||||
from .adapters.wic_1t import WIC_1T
|
||||
from .adapters.wic_2t import WIC_2T
|
||||
from .adapters.wic_1enet import WIC_1ENET
|
||||
|
||||
# NIOs
|
||||
from .nios.nio_udp import NIO_UDP
|
||||
from .nios.nio_udp_auto import NIO_UDP_auto
|
||||
from .nios.nio_unix import NIO_UNIX
|
||||
from .nios.nio_vde import NIO_VDE
|
||||
from .nios.nio_tap import NIO_TAP
|
||||
from .nios.nio_generic_ethernet import NIO_GenericEthernet
|
||||
from .nios.nio_linux_ethernet import NIO_LinuxEthernet
|
||||
from .nios.nio_fifo import NIO_FIFO
|
||||
from .nios.nio_mcast import NIO_Mcast
|
||||
from .nios.nio_null import NIO_Null
|
||||
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -29,21 +80,25 @@ class Dynamips(IModule):
|
||||
|
||||
def __init__(self, name=None, args=(), kwargs={}):
|
||||
IModule.__init__(self, name=name, args=args, kwargs=kwargs)
|
||||
|
||||
# start the hypervisor manager
|
||||
#self._hypervisor_manager = HypervisorManager("/usr/bin/dynamips", "/tmp")
|
||||
|
||||
@IModule.route("dynamips/echo")
|
||||
@IModule.route("dynamips.echo")
|
||||
def echo(self, request):
|
||||
print("Echo!")
|
||||
if request == None:
|
||||
self.send_param_error()
|
||||
return
|
||||
log.debug("received request {}".format(request))
|
||||
self.send_response(request)
|
||||
|
||||
@IModule.route("dynamips/create_vm")
|
||||
@IModule.route("dynamips.create_vm")
|
||||
def create_vm(self, request):
|
||||
print("Create VM!")
|
||||
log.debug("received request {}".format(request))
|
||||
self.send_response(request)
|
||||
|
||||
@IModule.route("dynamips/start_vm")
|
||||
@IModule.route("dynamips.start_vm")
|
||||
def start_vm(self, request):
|
||||
print("Start VM!")
|
||||
log.debug("received request {}".format(request))
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,155 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 Adapter(object):
|
||||
"""
|
||||
Base class for adapters.
|
||||
|
||||
:param interfaces: number of interfaces supported by this adapter.
|
||||
:param wics: number of wics supported by this adapter.
|
||||
"""
|
||||
|
||||
def __init__(self, interfaces=0, wics=0):
|
||||
|
||||
self._interfaces = interfaces
|
||||
|
||||
self._ports = {}
|
||||
for port_id in range(0, interfaces):
|
||||
self._ports[port_id] = None
|
||||
self._wics = wics * [None]
|
||||
|
||||
def removable(self):
|
||||
"""
|
||||
Returns True if the adapter can be removed from a slot
|
||||
and False if not.
|
||||
|
||||
:returns: boolean
|
||||
"""
|
||||
|
||||
return True
|
||||
|
||||
def port_exists(self, port_id):
|
||||
"""
|
||||
Checks if a port exists on this adapter.
|
||||
|
||||
:returns: True is the port exists,
|
||||
False otherwise.
|
||||
"""
|
||||
|
||||
if port_id in self._ports:
|
||||
return True
|
||||
return False
|
||||
|
||||
def wic_slot_available(self, wic_slot_id):
|
||||
"""
|
||||
Checks if a WIC slot is available
|
||||
|
||||
:returns: True is the WIC slot is available,
|
||||
False otherwise.
|
||||
"""
|
||||
|
||||
if self._wics[wic_slot_id] == None:
|
||||
return True
|
||||
return False
|
||||
|
||||
def install_wic(self, wic_slot_id, wic):
|
||||
"""
|
||||
Installs a WIC on this adapter.
|
||||
|
||||
:param wic_slot_id: WIC slot ID (integer)
|
||||
:param wic: WIC object
|
||||
"""
|
||||
|
||||
self._wics[wic_slot_id] = wic
|
||||
|
||||
# Dynamips WICs ports start on a multiple of 16 + port number
|
||||
# WIC1 port 1 = 16, WIC1 port 2 = 17
|
||||
# WIC2 port 1 = 32, WIC2 port 2 = 33
|
||||
# WIC3 port 1 = 48, WIC3 port 2 = 49
|
||||
base = 16 * (wic_slot_id + 1)
|
||||
for wic_port in range(0, wic.interfaces):
|
||||
port_id = base + wic_port
|
||||
self._ports[port_id] = None
|
||||
|
||||
def uninstall_wic(self, wic_slot_id):
|
||||
"""
|
||||
Removes a WIC from this adapter.
|
||||
|
||||
:param wic_slot_id: WIC slot ID (integer)
|
||||
"""
|
||||
|
||||
wic = self._wics[wic_slot_id]
|
||||
|
||||
# Dynamips WICs ports start on a multiple of 16 + port number
|
||||
# WIC1 port 1 = 16, WIC1 port 2 = 17
|
||||
# WIC2 port 1 = 32, WIC2 port 2 = 33
|
||||
# WIC3 port 1 = 48, WIC3 port 2 = 49
|
||||
base = 16 * (wic_slot_id + 1)
|
||||
for wic_port in range(0, wic.interfaces):
|
||||
port_id = base + wic_port
|
||||
del self._ports[port_id]
|
||||
self._wics[wic_slot_id] = None
|
||||
|
||||
def add_nio(self, port_id, nio):
|
||||
"""
|
||||
Adds a NIO to a port on this adapter.
|
||||
|
||||
:param port_id: port ID (integer)
|
||||
:param nio: NIO object
|
||||
"""
|
||||
|
||||
self._ports[port_id] = nio
|
||||
|
||||
def remove_nio(self, port_id):
|
||||
"""
|
||||
Removes a NIO from a port on this adapter.
|
||||
|
||||
:param port_id: port ID (integer)
|
||||
"""
|
||||
|
||||
self._ports[port_id] = None
|
||||
|
||||
@property
|
||||
def ports(self):
|
||||
"""
|
||||
Returns port to NIO mapping
|
||||
|
||||
:returns: dictionary port -> NIO
|
||||
"""
|
||||
|
||||
return self._ports
|
||||
|
||||
@property
|
||||
def interfaces(self):
|
||||
"""
|
||||
Returns the number of interfaces supported by this adapter.
|
||||
|
||||
:returns: number of interfaces
|
||||
"""
|
||||
|
||||
return self._interfaces
|
||||
|
||||
@property
|
||||
def wics(self):
|
||||
"""
|
||||
Returns the wics adapters inserted in this adapter.
|
||||
|
||||
:returns: list WIC objects
|
||||
"""
|
||||
|
||||
return self._wics
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C1700_MB_1FE(Adapter):
|
||||
"""
|
||||
Integrated 1 port FastEthernet adapter for c1700 platform.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1, wics=2)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C1700-MB-1FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C1700_MB_WIC1(Adapter):
|
||||
"""
|
||||
Fake module to provide a placeholder for slot 1 interfaces when WICs
|
||||
are inserted into WIC slot 1.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=0, wics=2)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C1700_MB_WIC1"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "N/A"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "N/A"
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_1E(Adapter):
|
||||
"""
|
||||
Integrated 1 port Ethernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1, wics=3)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C2600-MB-1E"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_1FE(Adapter):
|
||||
"""
|
||||
Integrated 1 port FastEthernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1, wics=3)
|
||||
self._interfaces = 1
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C2600-MB-1FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_2E(Adapter):
|
||||
"""
|
||||
Integrated 2 port Ethernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=2, wics=3)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C2600-MB-2E"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_2FE(Adapter):
|
||||
"""
|
||||
Integrated 2 port FastEthernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=2, wics=3)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C2600-MB-2FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C7200_IO_2FE(Adapter):
|
||||
"""
|
||||
C7200-IO-2FE FastEthernet Input/Ouput controller.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=2)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C7200_IO_2FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C7200_IO_FE(Adapter):
|
||||
"""
|
||||
C7200-IO-FE FastEthernet Input/Ouput controller.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C7200_IO_FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class C7200_IO_GE_E(Adapter):
|
||||
"""
|
||||
C7200-IO-GE-E GigabitEthernet Input/Ouput controller.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "C7200-IO-GE-E"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "GigabitEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class GT96100_FE(Adapter):
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=2, wics=3)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "GT96100-FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class Leopard_2FE(Adapter):
|
||||
"""
|
||||
Integrated 2 port FastEthernet adapter for c3660 router.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=2)
|
||||
self._interfaces = 2
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "Leopard-2FE"
|
||||
|
||||
def removable(self):
|
||||
|
||||
return False
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class NM_16ESW(Adapter):
|
||||
"""
|
||||
NM-16ESW FastEthernet network module.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=16)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "NM-16ESW"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class NM_1E(Adapter):
|
||||
"""
|
||||
NM-1E Ethernet network module.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "NM-1E"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class NM_1FE_TX(Adapter):
|
||||
"""
|
||||
NM-1FE-TX FastEthernet network module.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "NM-1FE-TX"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class NM_4E(Adapter):
|
||||
"""
|
||||
NM-4E Ethernet network module.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=4)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "NM-4E"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class NM_4T(Adapter):
|
||||
"""
|
||||
NM-4T Serial network module.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=4)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "NM-4T"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Serial"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_2FE_TX(Adapter):
|
||||
"""
|
||||
PA-2FE-TX FastEthernet port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=2)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-2FE-TX"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_4E(Adapter):
|
||||
"""
|
||||
PA-4E Ethernet port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=4)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-4E"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_4T(Adapter):
|
||||
"""
|
||||
PA-4T+ Serial port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=4)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-4T+"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Serial"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_8E(Adapter):
|
||||
"""
|
||||
PA-8E Ethernet port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=8)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-8E"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_8T(Adapter):
|
||||
"""
|
||||
PA-8T Serial port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=8)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-8T"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Serial"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_A1(Adapter):
|
||||
"""
|
||||
PA-A1 ATM port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-A1"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "ATM"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Serial"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_FE_TX(Adapter):
|
||||
"""
|
||||
PA-FE-TX FastEthernet port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-FE-TX"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "FastEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_GE(Adapter):
|
||||
"""
|
||||
PA-GE GigabitEthernet port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-GE"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "GigabitEthernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 .adapter import Adapter
|
||||
|
||||
|
||||
class PA_POS_OC3(Adapter):
|
||||
"""
|
||||
PA-POS-OC3 port adapter.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
Adapter.__init__(self, interfaces=1)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "PA-POS-OC3"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "POS"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "SONET"
|
||||
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 WIC_1ENET(object):
|
||||
"""
|
||||
WIC-1ENET Ethernet
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self._interfaces = 2
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "WIC-1ENET"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Ethernet"
|
||||
|
||||
@property
|
||||
def interfaces(self):
|
||||
"""
|
||||
Returns the number of interfaces supported by this WIC.
|
||||
|
||||
:returns: number of interfaces
|
||||
"""
|
||||
|
||||
return self._interfaces
|
||||
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 WIC_1T(object):
|
||||
"""
|
||||
WIC-1T Serial
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self._interfaces = 1
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "WIC-1T"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
@property
|
||||
def interfaces(self):
|
||||
"""
|
||||
Returns the number of interfaces supported by this WIC.
|
||||
|
||||
:returns: number of interfaces
|
||||
"""
|
||||
|
||||
return self._interfaces
|
||||
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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 WIC_2T(object):
|
||||
"""
|
||||
WIC-2T Serial
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self._interfaces = 2
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return "WIC-2T"
|
||||
|
||||
def interface_type(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
def medium(self):
|
||||
|
||||
return "Serial"
|
||||
|
||||
@property
|
||||
def interfaces(self):
|
||||
"""
|
||||
Returns the number of interfaces supported by this WIC.
|
||||
|
||||
:returns: number of interfaces
|
||||
"""
|
||||
|
||||
return self._interfaces
|
||||
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Custom exceptions for Dynamips module.
|
||||
"""
|
||||
|
||||
|
||||
class DynamipsError(Exception):
|
||||
|
||||
def __init__(self, message, original_exception=None):
|
||||
|
||||
Exception.__init__(self, message)
|
||||
self._message = message
|
||||
self._original_exception = original_exception
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
return self._message
|
||||
@@ -0,0 +1,419 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips hypervisor management module ("hypervisor")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L46
|
||||
"""
|
||||
|
||||
import socket
|
||||
import re
|
||||
import logging
|
||||
from .dynamips_error import DynamipsError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DynamipsHypervisor(object):
|
||||
"""
|
||||
Creates a new connection to a Dynamips server (also called hypervisor)
|
||||
|
||||
:param host: the hostname or ip address string of the Dynamips server
|
||||
:param port: the tcp port integer (defaults to 7200)
|
||||
:param timeout: timeout integer for how long to wait for a response to commands sent to the
|
||||
hypervisor (defaults to 30 seconds)
|
||||
"""
|
||||
|
||||
# Used to parse Dynamips response codes
|
||||
error_re = re.compile(r"""^2[0-9]{2}-""")
|
||||
success_re = re.compile(r"""^1[0-9]{2}\s{1}""")
|
||||
|
||||
def __init__(self, host, port=7200, timeout=30.0):
|
||||
|
||||
self._host = host
|
||||
self._port = port
|
||||
|
||||
self._devices = []
|
||||
self._ghosts = {}
|
||||
self._jitsharing_groups = {}
|
||||
self._working_dir = ""
|
||||
self._baseconsole = 2000
|
||||
self._baseaux = 2100
|
||||
self._baseudp = 10000
|
||||
self._version = "N/A"
|
||||
self._timeout = 30
|
||||
self._socket = None
|
||||
self._uuid = None
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
Connects to the hypervisor.
|
||||
"""
|
||||
|
||||
try:
|
||||
self._socket = socket.create_connection((self._host,
|
||||
self._port),
|
||||
self._timeout)
|
||||
except socket.error as e:
|
||||
raise DynamipsError("Could not connect to server: {}".format(e))
|
||||
|
||||
try:
|
||||
self._version = self.send("hypervisor version")[0][4:]
|
||||
except IndexError:
|
||||
self._version = "Unknown"
|
||||
|
||||
self._uuid = self.send("hypervisor uuid")
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""
|
||||
Returns Dynamips version.
|
||||
|
||||
:returns: version string
|
||||
"""
|
||||
|
||||
return self._version
|
||||
|
||||
def module_list(self):
|
||||
"""
|
||||
Returns the modules supported by this hypervisor.
|
||||
|
||||
:returns: module list
|
||||
"""
|
||||
|
||||
return self.send("hypervisor module_list")
|
||||
|
||||
def cmd_list(self, module):
|
||||
"""
|
||||
Returns commands recognized by the specified module.
|
||||
|
||||
:param module: the module name
|
||||
:returns: command list
|
||||
"""
|
||||
|
||||
return self.send("hypervisor cmd_list {}".format(module))
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Closes the connection to this hypervisor (but leave it running).
|
||||
"""
|
||||
|
||||
self.send("hypervisor close")
|
||||
self._socket.close()
|
||||
self._socket = None
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops this hypervisor (will no longer run).
|
||||
"""
|
||||
|
||||
self.send("hypervisor stop")
|
||||
self._socket.close()
|
||||
self._socket = None
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Resets this hypervisor (used to get an empty configuration).
|
||||
"""
|
||||
|
||||
self.send('hypervisor reset')
|
||||
|
||||
@property
|
||||
def working_dir(self):
|
||||
"""
|
||||
Returns current working directory
|
||||
|
||||
:returns: path to the working directory
|
||||
"""
|
||||
|
||||
return self._working_dir
|
||||
|
||||
@working_dir.setter
|
||||
def working_dir(self, working_dir):
|
||||
"""
|
||||
Set the working directory for this hypervisor.
|
||||
|
||||
:param working_dir: path to the working directory
|
||||
"""
|
||||
|
||||
# encase working_dir in quotes to protect spaces in the path
|
||||
self.send("hypervisor working_dir {}".format('"' + working_dir + '"'))
|
||||
self._working_dir = working_dir
|
||||
|
||||
def save_config(self, filename):
|
||||
"""
|
||||
Saves the configuration of all Dynamips objects into the specified file.
|
||||
|
||||
:param filename: path string
|
||||
"""
|
||||
|
||||
# encase working_dir in quotes to protect spaces in the path
|
||||
self.send("hypervisor save_config {}".format('"' + filename + '"'))
|
||||
|
||||
@property
|
||||
def uuid(self):
|
||||
"""
|
||||
Returns this hypervisor UUID.
|
||||
|
||||
:Returns: uuid string
|
||||
"""
|
||||
|
||||
return self._uuid
|
||||
|
||||
@property
|
||||
def socket(self):
|
||||
"""
|
||||
Returns the current socket used to communicate with this hypervisor.
|
||||
|
||||
:returns: socket object
|
||||
"""
|
||||
|
||||
assert self._socket
|
||||
return self._socket
|
||||
|
||||
@property
|
||||
def devices(self):
|
||||
"""
|
||||
Returns the list of devices managed by this hypervisor instance.
|
||||
|
||||
:returns: a list of device objects
|
||||
"""
|
||||
|
||||
return self._devices
|
||||
|
||||
@devices.setter
|
||||
def devices(self, devices):
|
||||
"""
|
||||
Set the list of devices managed by this hypervisor instance.
|
||||
This method is for internal use.
|
||||
|
||||
:param devices: a list of device objects
|
||||
"""
|
||||
|
||||
self._devices = devices
|
||||
|
||||
@property
|
||||
def baseconsole(self):
|
||||
"""
|
||||
Returns base console TCP port for this hypervisor.
|
||||
|
||||
:returns: base console value (integer)
|
||||
"""
|
||||
|
||||
return self._baseconsole
|
||||
|
||||
@baseconsole.setter
|
||||
def baseconsole(self, baseconsole):
|
||||
"""
|
||||
Set the base console TCP port for this hypervisor.
|
||||
|
||||
:param baseconsole: base console value (integer)
|
||||
"""
|
||||
|
||||
self._baseconsole = baseconsole
|
||||
|
||||
@property
|
||||
def baseaux(self):
|
||||
"""
|
||||
Returns base auxiliary port for this hypervisor.
|
||||
|
||||
:returns: base auxiliary port value (integer)
|
||||
"""
|
||||
|
||||
return self._baseaux
|
||||
|
||||
@baseaux.setter
|
||||
def baseaux(self, baseaux):
|
||||
"""
|
||||
Set the base auxiliary TCP port for this hypervisor.
|
||||
|
||||
:param baseaux: base auxiliary port value (integer)
|
||||
"""
|
||||
|
||||
self._baseaux = baseaux
|
||||
|
||||
@property
|
||||
def baseudp(self):
|
||||
"""
|
||||
Returns the next available UDP port for UDP NIOs.
|
||||
|
||||
:returns: base UDP port value (integer)
|
||||
"""
|
||||
|
||||
return self._baseudp
|
||||
|
||||
@baseudp.setter
|
||||
def baseudp(self, baseudp):
|
||||
"""
|
||||
Set the next open UDP port for NIOs for this hypervisor.
|
||||
|
||||
:param baseudp: base UDP port value (integer)
|
||||
"""
|
||||
|
||||
self._baseudp = baseudp
|
||||
|
||||
@property
|
||||
def ghosts(self):
|
||||
"""
|
||||
Returns a list of the ghosts hosted by this hypervisor.
|
||||
|
||||
:returns: Ghosts dict (image_name -> device)
|
||||
"""
|
||||
|
||||
return self._ghosts
|
||||
|
||||
def add_ghost(self, image_name, router):
|
||||
"""
|
||||
Adds a ghost name to the list of ghosts created on this hypervisor.
|
||||
|
||||
:param image_name: name of the ghost image
|
||||
:param router: router object
|
||||
"""
|
||||
|
||||
self._ghosts[image_name] = router
|
||||
|
||||
@property
|
||||
def jitsharing_groups(self):
|
||||
"""
|
||||
Returns a list of the JIT sharing groups hosted by this hypervisor.
|
||||
|
||||
:returns: JIT sharing groups dict (image_name -> group number)
|
||||
"""
|
||||
|
||||
return self._ghosts
|
||||
|
||||
def add_jitsharing_group(self, image_name, group_number):
|
||||
"""
|
||||
Adds a JIT blocks sharing group name to the list of groups created on this hypervisor.
|
||||
|
||||
:param image_name: name of the ghost image
|
||||
:param group_number: group (integer)
|
||||
"""
|
||||
|
||||
self._jitsharing_groups[image_name] = group_number
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
"""
|
||||
Returns this hypervisor host.
|
||||
|
||||
:returns: host (string)
|
||||
"""
|
||||
|
||||
return self._host
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
"""
|
||||
Returns this hypervisor port.
|
||||
|
||||
:returns: port (integer)
|
||||
"""
|
||||
|
||||
return self._port
|
||||
|
||||
def send_raw(self, string):
|
||||
"""
|
||||
Sends a raw command to this hypervisor. Use sparingly.
|
||||
|
||||
:param string: command string.
|
||||
|
||||
:returns: command result (string)
|
||||
"""
|
||||
|
||||
result = self.send(string)
|
||||
return result
|
||||
|
||||
def send(self, command):
|
||||
"""
|
||||
Sends commands to this hypervisor.
|
||||
|
||||
:param command: a Dynamips hypervisor command
|
||||
|
||||
:returns: results as a list
|
||||
"""
|
||||
|
||||
# Dynamips responses are of the form:
|
||||
# 1xx yyyyyy\r\n
|
||||
# 1xx yyyyyy\r\n
|
||||
# ...
|
||||
# 100-yyyy\r\n
|
||||
# or
|
||||
# 2xx-yyyy\r\n
|
||||
#
|
||||
# Where 1xx is a code from 100-199 for a success or 200-299 for an error
|
||||
# The result might be multiple lines and might be less than the buffer size
|
||||
# but still have more data. The only thing we know for sure is the last line
|
||||
# will begin with '100-' or a '2xx-' and end with '\r\n'
|
||||
|
||||
if not self._socket:
|
||||
raise DynamipsError("Not connected")
|
||||
|
||||
try:
|
||||
command = command.strip() + '\n'
|
||||
log.debug("sending {}".format(command))
|
||||
self.socket.sendall(command.encode('utf-8'))
|
||||
except socket.error as e:
|
||||
raise DynamipsError("Lost communication with {host}:{port} :{error}"
|
||||
.format(host=self._host, port=self._port, error=e))
|
||||
|
||||
# Now retrieve the result
|
||||
data = []
|
||||
buf = ''
|
||||
while True:
|
||||
try:
|
||||
chunk = self.socket.recv(1024) # match to Dynamips' buffer size
|
||||
buf += chunk.decode("utf-8")
|
||||
except socket.error as e:
|
||||
raise DynamipsError("Communication timed out with {host}:{port} :{error}"
|
||||
.format(host=self._host, port=self._port, error=e))
|
||||
|
||||
# If the buffer doesn't end in '\n' then we can't be done
|
||||
try:
|
||||
if buf[-1] != '\n':
|
||||
continue
|
||||
except IndexError:
|
||||
raise DynamipsError("Could not communicate with {host}:{port}"
|
||||
.format(host=self._host, port=self._port))
|
||||
|
||||
data += buf.split('\r\n')
|
||||
if data[-1] == '':
|
||||
data.pop()
|
||||
buf = ''
|
||||
|
||||
if len(data) == 0:
|
||||
raise DynamipsError("no data returned from {host}:{port}"
|
||||
.format(host=self._host, port=self._port))
|
||||
|
||||
# Does it contain an error code?
|
||||
if self.error_re.search(data[-1]):
|
||||
raise DynamipsError(data[-1][4:])
|
||||
|
||||
# Or does the last line begin with '100-'? Then we are done!
|
||||
if data[-1][:4] == '100-':
|
||||
data[-1] = data[-1][4:]
|
||||
if data[-1] == 'OK':
|
||||
data.pop()
|
||||
break
|
||||
|
||||
# Remove success responses codes
|
||||
for index in range(len(data)):
|
||||
if self.success_re.search(data[index]):
|
||||
data[index] = data[index][4:]
|
||||
|
||||
log.debug("returned result {}".format(data))
|
||||
return data
|
||||
@@ -0,0 +1,270 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Represents a Dynamips hypervisor and starts/stops the associated Dynamips process.
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
from .dynamips_hypervisor import DynamipsHypervisor
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Hypervisor(DynamipsHypervisor):
|
||||
"""
|
||||
Hypervisor.
|
||||
|
||||
:param path: path to Dynamips executable
|
||||
:param workingdir: working directory
|
||||
:param port: port for this hypervisor
|
||||
:param host: host/address for this hypervisor
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, path, workingdir, host, port):
|
||||
|
||||
DynamipsHypervisor.__init__(self, host, port)
|
||||
|
||||
# create an unique ID
|
||||
self._id = Hypervisor._instance_count
|
||||
Hypervisor._instance_count += 1
|
||||
|
||||
self._path = path
|
||||
self._workingdir = workingdir
|
||||
self._command = []
|
||||
self._process = None
|
||||
self._stdout = None
|
||||
|
||||
# settings used the load-balance hypervisors
|
||||
# (for the hypervisor manager)
|
||||
self._memory_load = 0
|
||||
self._ios_image_ref = ""
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Returns the unique ID for this hypervisor.
|
||||
|
||||
:returns: id (integer)
|
||||
"""
|
||||
|
||||
return(self._id)
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
"""
|
||||
Returns the path to the Dynamips executable.
|
||||
|
||||
:returns: path to Dynamips
|
||||
"""
|
||||
|
||||
return(self._path)
|
||||
|
||||
@path.setter
|
||||
def path(self, path):
|
||||
"""
|
||||
Set the path to the Dynamips executable.
|
||||
|
||||
:param path: path to Dynamips
|
||||
"""
|
||||
|
||||
self._path = path
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
"""
|
||||
Returns the port used to start the Dynamips hypervisor.
|
||||
|
||||
:returns: port number (integer)
|
||||
"""
|
||||
|
||||
return(self._port)
|
||||
|
||||
@port.setter
|
||||
def port(self, port):
|
||||
"""
|
||||
Set the port used to start the Dynamips hypervisor.
|
||||
|
||||
:param port: port number (integer)
|
||||
"""
|
||||
|
||||
self._port = port
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
"""
|
||||
Returns the host (binding) used to start the Dynamips hypervisor.
|
||||
|
||||
:returns: host/address (string)
|
||||
"""
|
||||
|
||||
return(self._host)
|
||||
|
||||
@host.setter
|
||||
def host(self, host):
|
||||
"""
|
||||
Set the host (binding) used to start the Dynamips hypervisor.
|
||||
|
||||
:param host: host/address (string)
|
||||
"""
|
||||
|
||||
self._host = host
|
||||
|
||||
@property
|
||||
def workingdir(self):
|
||||
"""
|
||||
Returns the working directory used to start the Dynamips hypervisor.
|
||||
|
||||
:returns: path to a working directory
|
||||
"""
|
||||
|
||||
return(self._workingdir)
|
||||
|
||||
@workingdir.setter
|
||||
def workingdir(self, workingdir):
|
||||
"""
|
||||
Set the working directory used to start the Dynamips hypervisor.
|
||||
|
||||
:param workingdir: path to a working directory
|
||||
"""
|
||||
|
||||
self._workingdir = workingdir
|
||||
|
||||
@property
|
||||
def image_ref(self):
|
||||
"""
|
||||
Returns the reference IOS image name
|
||||
(used by the hypervisor manager for load-balancing purposes).
|
||||
|
||||
:returns: image reference name
|
||||
"""
|
||||
|
||||
return self._ios_image_ref
|
||||
|
||||
@image_ref.setter
|
||||
def image_ref(self, ios_image_name):
|
||||
"""
|
||||
Set the reference IOS image name
|
||||
(used by the hypervisor manager for load-balancing purposes).
|
||||
|
||||
:param ios_image_name: image reference name
|
||||
"""
|
||||
|
||||
self._ios_image_ref = ios_image_name
|
||||
|
||||
def increase_memory_load(self, memory):
|
||||
"""
|
||||
Increases the memory load of this hypervisor.
|
||||
(used by the hypervisor manager for load-balancing purposes).
|
||||
|
||||
:param memory: amount of RAM (integer)
|
||||
"""
|
||||
|
||||
self._memory_load += memory
|
||||
|
||||
def decrease_memory_load(self, memory):
|
||||
"""
|
||||
Decreases the memory load of this hypervisor.
|
||||
(used by the hypervisor manager for load-balancing purposes).
|
||||
|
||||
:param memory: amount of RAM (integer)
|
||||
"""
|
||||
|
||||
self._memory_load -= memory
|
||||
|
||||
@property
|
||||
def memory_load(self):
|
||||
"""
|
||||
Returns the memory load of this hypervisor.
|
||||
(used by the hypervisor manager for load-balancing purposes).
|
||||
|
||||
:returns: amount of RAM (integer)
|
||||
"""
|
||||
|
||||
return self._memory_load
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts the Dynamips hypervisor process.
|
||||
"""
|
||||
|
||||
self._command = self._build_command()
|
||||
try:
|
||||
logger.info("Starting Dynamips: {}".format(self._command))
|
||||
# TODO: create unique filename for stdout
|
||||
self.stdout_file = os.path.join(self._workingdir, "dynamips.log")
|
||||
fd = open(self.stdout_file, "w")
|
||||
# TODO: check for exceptions and if process has already been started
|
||||
self._process = subprocess.Popen(self._command,
|
||||
stdout=fd,
|
||||
stderr=subprocess.STDOUT,
|
||||
cwd=self._workingdir)
|
||||
logger.info("Dynamips started PID={}".format(self._process.pid))
|
||||
except OSError as e:
|
||||
logger.error("Could not start Dynamips: {}".format(e))
|
||||
finally:
|
||||
fd.close()
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the Dynamips hypervisor process.
|
||||
"""
|
||||
|
||||
if self.is_running():
|
||||
logger.info("Stopping Dynamips PID={}".format(self._process.pid))
|
||||
self._process.kill()
|
||||
|
||||
def read_stdout(self):
|
||||
"""
|
||||
Reads the standard output of the Dynamips process.
|
||||
Only use when the process has been stopped or has crashed.
|
||||
"""
|
||||
|
||||
# TODO: check for exceptions
|
||||
with open(self.stdout_file) as file:
|
||||
output = file.read()
|
||||
return output
|
||||
|
||||
def is_running(self):
|
||||
"""
|
||||
Checks if the process is running
|
||||
|
||||
:returns: True or False
|
||||
"""
|
||||
|
||||
if self._process and self._process.poll() == None:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _build_command(self):
|
||||
"""
|
||||
Command to start the Dynamips hypervisor process.
|
||||
(to be passed to subprocess.Popen())
|
||||
"""
|
||||
|
||||
command = [self._path]
|
||||
command.extend(["-N1"]) # use instance IDs for filenames
|
||||
if self._host != '0.0.0.0':
|
||||
command.extend(['-H', self._host + ':' + str(self._port)])
|
||||
else:
|
||||
command.extend(['-H', self._port])
|
||||
return command
|
||||
@@ -0,0 +1,235 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Manages Dynamips hypervisors (load-balancing etc.)
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .hypervisor import Hypervisor
|
||||
import socket
|
||||
import time
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HypervisorManager(object):
|
||||
"""
|
||||
Manages Dynamips hypervisors.
|
||||
|
||||
:param path: path to the Dynamips executable
|
||||
:param workingdir: path to a working directory
|
||||
:param host: host/address for hypervisors to listen to
|
||||
:param base_port: base TCP port for hypervisors
|
||||
:param base_console: base TCP port for consoles
|
||||
:param base_aux: base TCP port for auxiliary consoles
|
||||
:param base_udp: base UDP port for UDP tunnels
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
path,
|
||||
workingdir,
|
||||
host='127.0.0.1',
|
||||
base_port=7200,
|
||||
base_console=2000,
|
||||
base_aux=3000,
|
||||
base_udp=10000):
|
||||
|
||||
self._hypervisors = []
|
||||
self._path = path
|
||||
self._workingdir = workingdir
|
||||
self._base_port = base_port
|
||||
self._current_port = self._base_port
|
||||
self._base_console = base_console
|
||||
self._base_aux = base_aux
|
||||
self._base_udp = base_udp
|
||||
self._host = host
|
||||
self._clean_workingdir = False
|
||||
self._ghost_ios = True
|
||||
self._mmap = True
|
||||
self._jit_sharing = False
|
||||
self._sparsemem = True
|
||||
self._memory_usage_limit_per_hypervisor = 1024
|
||||
self._group_ios_per_hypervisor = True
|
||||
|
||||
def __del__(self):
|
||||
"""
|
||||
Shutdowns all started hypervisors
|
||||
"""
|
||||
|
||||
self.stop_all_hypervisors()
|
||||
|
||||
@property
|
||||
def hypervisors(self):
|
||||
"""
|
||||
Returns all hypervisor instances.
|
||||
|
||||
:returns: list of hypervisor objects
|
||||
"""
|
||||
|
||||
return self._hypervisors
|
||||
|
||||
@property
|
||||
def memory_usage_limit_per_hypervisor(self):
|
||||
"""
|
||||
Returns the memory usage limit per hypervisor
|
||||
|
||||
:returns: limit value (integer)
|
||||
"""
|
||||
|
||||
return self._memory_usage_limit_per_hypervisor
|
||||
|
||||
@memory_usage_limit_per_hypervisor.setter
|
||||
def memory_usage_limit_per_hypervisor(self, memory_limit):
|
||||
"""
|
||||
Set the memory usage limit per hypervisor
|
||||
|
||||
:param memory_limit: memory limit value (integer)
|
||||
"""
|
||||
|
||||
self._memory_usage_limit_per_hypervisor = memory_limit
|
||||
|
||||
@property
|
||||
def group_ios_per_hypervisor(self):
|
||||
"""
|
||||
Returns if router are grouped per hypervisor
|
||||
based on their IOS image.
|
||||
|
||||
:returns: True or False
|
||||
"""
|
||||
|
||||
return self._group_ios_per_hypervisor
|
||||
|
||||
@group_ios_per_hypervisor.setter
|
||||
def group_ios_per_hypervisor(self, value):
|
||||
"""
|
||||
Set if router are grouped per hypervisor
|
||||
based on their IOS image.
|
||||
|
||||
:param value: True or False
|
||||
"""
|
||||
|
||||
self._group_ios_per_hypervisor = value
|
||||
|
||||
def wait_for_hypervisor(self, host, port, timeout=10):
|
||||
"""
|
||||
Waits for an hypervisor to be started (accepting a socket connection)
|
||||
|
||||
:param host: host/address to connect to the hypervisor
|
||||
:param port: port to connect to the hypervisor
|
||||
:param timeout: timeout value (default is 10 seconds)
|
||||
"""
|
||||
|
||||
# try to connect 5 times
|
||||
for _ in range(0, 5):
|
||||
try:
|
||||
s = socket.create_connection((host, port), timeout)
|
||||
except socket.error as e:
|
||||
time.sleep(0.5)
|
||||
last_exception = e
|
||||
continue
|
||||
connection_success = True
|
||||
break
|
||||
|
||||
if connection_success:
|
||||
s.close()
|
||||
#time.sleep(0.1)
|
||||
else:
|
||||
log.critical("Couldn't connect to hypervisor on {}:{} :{}".format(host, port,
|
||||
last_exception))
|
||||
|
||||
def start_new_hypervisor(self):
|
||||
"""
|
||||
Creates a new Dynamips process and start it.
|
||||
|
||||
:returns: the new hypervisor object
|
||||
"""
|
||||
|
||||
hypervisor = Hypervisor(self._path,
|
||||
self._workingdir,
|
||||
self._host,
|
||||
self._current_port)
|
||||
|
||||
log.info("creating new hypervisor {}:{}".format(hypervisor.host, hypervisor.port))
|
||||
hypervisor.start()
|
||||
|
||||
self.wait_for_hypervisor(self._host, self._current_port)
|
||||
log.info("hypervisor {}:{} has successfully started".format(hypervisor.host, hypervisor.port))
|
||||
|
||||
hypervisor.connect()
|
||||
self._hypervisors.append(hypervisor)
|
||||
self._current_port += 1
|
||||
return hypervisor
|
||||
|
||||
def allocate_hypervisor_for_router(self, router_ios_image, router_ram):
|
||||
"""
|
||||
Allocates a Dynamips hypervisor for a specific router
|
||||
(new or existing depending on the RAM amount and IOS image)
|
||||
|
||||
:param router_ios_image: IOS image name
|
||||
:param router_ram: amount of RAM (integer)
|
||||
|
||||
:returns: the allocated hypervisor object
|
||||
"""
|
||||
|
||||
for hypervisor in self._hypervisors:
|
||||
if self._group_ios_per_hypervisor and hypervisor.image_ref != router_ios_image:
|
||||
continue
|
||||
if (hypervisor.memory_load + router_ram) <= self._memory_usage_limit_per_hypervisor:
|
||||
current_memory_load = hypervisor.memory_load
|
||||
hypervisor.increase_memory_load(router_ram)
|
||||
log.info("allocating existing hypervisor {}:{}, RAM={}+{}".format(hypervisor.host,
|
||||
hypervisor.port,
|
||||
current_memory_load,
|
||||
router_ram))
|
||||
return hypervisor
|
||||
|
||||
hypervisor = self.start_new_hypervisor()
|
||||
hypervisor.image_ref = router_ios_image
|
||||
hypervisor.increase_memory_load(router_ram)
|
||||
return hypervisor
|
||||
|
||||
def unallocate_hypervisor_for_router(self, router):
|
||||
"""
|
||||
Unallocates a Dynamips hypervisor for a specific router.
|
||||
|
||||
:param router: router object
|
||||
"""
|
||||
|
||||
hypervisor = router.hypervisor
|
||||
hypervisor.decrease_memory_load(router.ram)
|
||||
|
||||
if hypervisor.memory_load < 0:
|
||||
log.warn("hypervisor {}:{} has a memory load below 0 ({})".format(hypervisor.host,
|
||||
hypervisor.port,
|
||||
hypervisor.memory_load))
|
||||
hypervisor.memory_load = 0
|
||||
|
||||
# memory load at 0MB and no devices managed anymore...
|
||||
# let's stop this hypervisor
|
||||
if hypervisor.memory_load == 0 and not hypervisor.devices:
|
||||
hypervisor.stop()
|
||||
self._hypervisors.remove(hypervisor)
|
||||
|
||||
def stop_all_hypervisors(self):
|
||||
"""
|
||||
Stops all hypervisors.
|
||||
"""
|
||||
|
||||
for hypervisor in self._hypervisors:
|
||||
hypervisor.stop()
|
||||
Whitespace-only changes.
@@ -0,0 +1,236 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Base interface for Dynamips Network Input/Output (NIO) module ("nio").
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L451
|
||||
"""
|
||||
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class NIO(object):
|
||||
"""
|
||||
Base NIO class
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._bandwidth = None # no bandwidth constraint by default
|
||||
self._input_filter = None # no input filter applied by default
|
||||
self._output_filter = None # no output filter applied by default
|
||||
self._input_filter_options = None # no input filter options by default
|
||||
self._output_filter_options = None # no output filter options by default
|
||||
self._dynamips_direction = {"in": 0, "out": 1, "both": 2}
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all NIOs.
|
||||
|
||||
:returns: NIO list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("nio list")
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this NIO.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio delete {}".format(self._name))
|
||||
|
||||
def rename(self, new_name):
|
||||
"""
|
||||
Renames this NIO
|
||||
|
||||
:param new_name: new NIO name
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
def debug(self, debug):
|
||||
"""
|
||||
Enables/Disables debugging for this NIO.
|
||||
|
||||
:param debug: debug value (0 = disable, enable = 1)
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio set_debug {name} {debug}".format(name=self._name,
|
||||
debug=debug))
|
||||
|
||||
def bind_filter(self, direction, filter_name):
|
||||
"""
|
||||
Adds a packet filter to this NIO.
|
||||
Filter "freq_drop" drops packets.
|
||||
Filter "capture" captures packets.
|
||||
|
||||
:param direction: "in", "out" or "both"
|
||||
:param filter_name: name of the filter to apply
|
||||
"""
|
||||
|
||||
if direction not in self._dynamips_direction:
|
||||
raise DynamipsError("Unknown direction {} to bind filter {}:".format(direction, filter_name))
|
||||
dynamips_direction = self._dynamips_direction[direction]
|
||||
|
||||
self._hypervisor.send("nio bind_filter {name} {direction} {filter}".format(name=self._name,
|
||||
direction=dynamips_direction,
|
||||
filter=filter_name))
|
||||
|
||||
if direction == "in":
|
||||
self._input_filter = filter_name
|
||||
elif direction == "out":
|
||||
self._output_filter = filter_name
|
||||
elif direction == "both":
|
||||
self._input_filter = filter_name
|
||||
self._output_filter = filter_name
|
||||
|
||||
def unbind_filter(self, direction):
|
||||
"""
|
||||
Removes packet filter for this NIO.
|
||||
|
||||
:param direction: "in", "out" or "both"
|
||||
"""
|
||||
|
||||
if direction not in self._dynamips_direction:
|
||||
raise DynamipsError("Unknown direction {} to unbind filter:".format(direction))
|
||||
dynamips_direction = self._dynamips_direction[direction]
|
||||
|
||||
self._hypervisor.send("nio unbind_filter {name} {direction}".format(name=self._name,
|
||||
direction=dynamips_direction))
|
||||
|
||||
if direction == "in":
|
||||
self._input_filter = None
|
||||
elif direction == "out":
|
||||
self._output_filter = None
|
||||
elif direction == "both":
|
||||
self._input_filter = None
|
||||
self._output_filter = None
|
||||
|
||||
def setup_filter(self, direction, options):
|
||||
"""
|
||||
Setups a packet filter binded with this NIO.
|
||||
|
||||
Filter "freq_drop" has 1 argument "<frequency>". It will drop
|
||||
everything with a -1 frequency, drop every Nth packet with a
|
||||
positive frequency, or drop nothing.
|
||||
|
||||
Filter "capture" has 2 arguments "<link_type_name> <output_file>".
|
||||
It will capture packets to the target output file. The link type
|
||||
name is a case-insensitive DLT_ name from the PCAP library
|
||||
constants with the DLT_ part removed.See http://www.tcpdump.org/linktypes.html
|
||||
for a list of all available DLT values.
|
||||
|
||||
:param direction: "in", "out" or "both"
|
||||
:param options: options for the packet filter (string)
|
||||
"""
|
||||
|
||||
if direction not in self._dynamips_direction:
|
||||
raise DynamipsError("Unknown direction {} to setup filter:".format(direction))
|
||||
dynamips_direction = self._dynamips_direction[direction]
|
||||
|
||||
self._hypervisor.send("nio setup_filter {name} {direction} {options}".format(name=self._name,
|
||||
direction=dynamips_direction,
|
||||
options=options))
|
||||
|
||||
if direction == "in":
|
||||
self._input_filter_options = options
|
||||
elif direction == "out":
|
||||
self._output_filter_options = options
|
||||
elif direction == "both":
|
||||
self._input_filter_options = options
|
||||
self._output_filter_options = options
|
||||
|
||||
@property
|
||||
def input_filter(self):
|
||||
"""
|
||||
Returns the input packet filter for this NIO.
|
||||
|
||||
:returns: tuple (filter name, filter options)
|
||||
"""
|
||||
|
||||
return (self._input_filter, self._input_filter_options)
|
||||
|
||||
@property
|
||||
def output_filter(self):
|
||||
"""
|
||||
Returns the output packet filter for this NIO.
|
||||
|
||||
:returns: tuple (filter name, filter options)
|
||||
"""
|
||||
|
||||
return (self._output_filter, self._output_filter_options)
|
||||
|
||||
def get_stats(self):
|
||||
"""
|
||||
Gets statistics for this NIO.
|
||||
|
||||
:returns: NIO statistics (string with packets in, packets out, bytes in, bytes out)
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("nio get_stats {}".format(self._name))[0]
|
||||
|
||||
def reset_stats(self):
|
||||
"""
|
||||
Resets statistics for this NIO.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio reset_stats {}".format(self._name))
|
||||
|
||||
def set_bandwidth(self, bandwidth):
|
||||
"""
|
||||
Set bandwidth constraint.
|
||||
|
||||
:param bandwidth: bandwidth integer value (in Kb/s)
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio set_bandwidth {name} {bandwidth}".format(name=self._name,
|
||||
bandwidth=bandwidth))
|
||||
self._bandwidth = bandwidth
|
||||
|
||||
@property
|
||||
def bandwidth(self):
|
||||
"""
|
||||
Returns the bandwidth constraint for this NIO.
|
||||
|
||||
:returns: bandwidth integer value (in Kb/s)
|
||||
"""
|
||||
|
||||
return self._bandwidth
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
NIO string representation.
|
||||
|
||||
:returns: NIO name
|
||||
"""
|
||||
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the NIO name.
|
||||
|
||||
:returns: NIO name
|
||||
"""
|
||||
|
||||
return self._name
|
||||
@@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for FIFO NIOs.
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_FIFO(NIO):
|
||||
"""
|
||||
Dynamips FIFO NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_FIFO._instance_count
|
||||
NIO_FIFO._instance_count += 1
|
||||
self._name = 'nio_fifo' + str(self._id)
|
||||
|
||||
self._hypervisor.send("nio create_fifo {}".format(self._name))
|
||||
|
||||
def crossconnect(self, nio):
|
||||
"""
|
||||
Establishes a cross-connect between this FIFO NIO and another one.
|
||||
|
||||
:param nio: FIFO NIO object.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio crossconnect_fifo {name} {nio}".format(name=self._name,
|
||||
nio=nio))
|
||||
@@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for generic Ethernet NIOs (PCAP library).
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_GenericEthernet(NIO):
|
||||
"""
|
||||
Dynamips generic Ethernet NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param ethernet_device: Ethernet device name (e.g. eth0)
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, ethernet_device):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_GenericEthernet._instance_count
|
||||
NIO_GenericEthernet._instance_count += 1
|
||||
self._name = 'nio_gen_eth' + str(self._id)
|
||||
self._ethernet_device = ethernet_device
|
||||
|
||||
self._hypervisor.send("nio create_gen_eth {name} {eth_device}".format(name=self._name,
|
||||
eth_device=ethernet_device))
|
||||
|
||||
@property
|
||||
def ethernet_device(self):
|
||||
"""
|
||||
Returns the Ethernet device used by this NIO.
|
||||
|
||||
:returns: the Ethernet device name
|
||||
"""
|
||||
|
||||
return self._ethernet_device
|
||||
@@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Linux Ethernet NIOs (Linux only).
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_LinuxEthernet(NIO):
|
||||
"""
|
||||
Dynamips Linux Ethernet NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param ethernet_device: Ethernet device name (e.g. eth0)
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, ethernet_device):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_LinuxEthernet._instance_count
|
||||
NIO_LinuxEthernet._instance_count += 1
|
||||
self._name = 'nio_linux_eth' + str(self._id)
|
||||
self._ethernet_device = ethernet_device
|
||||
|
||||
self._hypervisor.send("nio create_linux_eth {name} {eth_device}".format(name=self._name,
|
||||
eth_device=ethernet_device))
|
||||
|
||||
@property
|
||||
def ethernet_device(self):
|
||||
"""
|
||||
Returns the Ethernet device used by this NIO.
|
||||
|
||||
:returns: the Ethernet device name
|
||||
"""
|
||||
|
||||
return self._ethernet_device
|
||||
@@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for multicast NIOs.
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_Mcast(NIO):
|
||||
"""
|
||||
Dynamips Linux Ethernet NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param group: multicast group to bind
|
||||
:param port: port for binding
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, group, port):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_Mcast._instance_count
|
||||
NIO_Mcast._instance_count += 1
|
||||
self._name = 'nio_mcast' + str(self._id)
|
||||
self._group = group
|
||||
self._port = port
|
||||
self._ttl = 1 # default TTL
|
||||
|
||||
self._hypervisor.send("nio create_mcast {name} {mgroup} {mport}".format(name=self._name,
|
||||
mgroup=group,
|
||||
mport=port))
|
||||
|
||||
@property
|
||||
def group(self):
|
||||
"""
|
||||
Returns the multicast group
|
||||
|
||||
:returns: multicast group address
|
||||
"""
|
||||
|
||||
return self._group
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
"""
|
||||
Returns the port
|
||||
|
||||
:returns: port number
|
||||
"""
|
||||
|
||||
return self._port
|
||||
|
||||
@property
|
||||
def ttl(self):
|
||||
"""
|
||||
Returns the TTL associated with the multicast address.
|
||||
|
||||
:returns: TTL value
|
||||
"""
|
||||
|
||||
return self._ttl
|
||||
|
||||
@ttl.setter
|
||||
def ttl(self, ttl):
|
||||
"""
|
||||
Set the TTL for the multicast address
|
||||
|
||||
:param ttl: TTL value
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio set_mcast_ttl {name} {ttl}".format(name=self._name,
|
||||
ttl=ttl))
|
||||
self._ttl = ttl
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for dummy NIOs (mostly for tests).
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_Null(NIO):
|
||||
"""
|
||||
Dynamips NULL NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_Null._instance_count
|
||||
NIO_Null._instance_count += 1
|
||||
self._name = 'nio_null' + str(self._id)
|
||||
|
||||
self._hypervisor.send("nio create_null {}".format(self._name))
|
||||
@@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for TAP NIOs (UNIX based OSes only).
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_TAP(NIO):
|
||||
"""
|
||||
Dynamips TAP NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param tap_device: TAP device name (e.g. tap0)
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, tap_device):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_TAP._instance_count
|
||||
NIO_TAP._instance_count += 1
|
||||
self._name = 'nio_tap' + str(self._id)
|
||||
self._tap_device = tap_device
|
||||
|
||||
self._hypervisor.send("nio create_tap {name} {tap}".format(name=self._name,
|
||||
tap=tap_device))
|
||||
|
||||
@property
|
||||
def tap_device(self):
|
||||
"""
|
||||
Returns the TAP device used by this NIO.
|
||||
|
||||
:returns: the TAP device name
|
||||
"""
|
||||
|
||||
return self._tap_device
|
||||
@@ -0,0 +1,82 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for UDP NIOs.
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_UDP(NIO):
|
||||
"""
|
||||
Dynamips UDP NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param lport: local port number
|
||||
:param rhost: remote address/host
|
||||
:param rport: remote port number
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, lport, rhost, rport):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_UDP._instance_count
|
||||
NIO_UDP._instance_count += 1
|
||||
self._name = 'nio_udp' + str(self._id)
|
||||
self._lport = lport
|
||||
self._rhost = rhost
|
||||
self._rport = rport
|
||||
|
||||
self._hypervisor.send("nio create_udp {name} {lport} {rhost} {rport}".format(name=self._name,
|
||||
lport=lport,
|
||||
rhost=rhost,
|
||||
rport=rport))
|
||||
|
||||
@property
|
||||
def lport(self):
|
||||
"""
|
||||
Returns the local port
|
||||
|
||||
:returns: local port number
|
||||
"""
|
||||
|
||||
return self._lport
|
||||
|
||||
@property
|
||||
def rhost(self):
|
||||
"""
|
||||
Returns the remote host
|
||||
|
||||
:returns: remote address/host
|
||||
"""
|
||||
|
||||
return self._rhost
|
||||
|
||||
@property
|
||||
def rport(self):
|
||||
"""
|
||||
Returns the remote port
|
||||
|
||||
:returns: remote port number
|
||||
"""
|
||||
|
||||
return self._rport
|
||||
@@ -0,0 +1,106 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for automatic UDP NIOs.
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_UDP_auto(NIO):
|
||||
"""
|
||||
Dynamips auto UDP NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param laddr: local address
|
||||
:param lport_start: start local port range
|
||||
:param lport_end: end local port range
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, laddr, lport_start, lport_end):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_UDP_auto._instance_count
|
||||
NIO_UDP_auto._instance_count += 1
|
||||
self._name = 'nio_udp_auto' + str(self._id)
|
||||
|
||||
self._laddr = laddr
|
||||
self._lport = int(self._hypervisor.send("nio create_udp_auto {name} {laddr} {lport_start} {lport_end}".format(name=self._name,
|
||||
laddr=laddr,
|
||||
lport_start=lport_start,
|
||||
lport_end=lport_end))[0])
|
||||
self._raddr = None
|
||||
self._rport = None
|
||||
|
||||
@property
|
||||
def laddr(self):
|
||||
"""
|
||||
Returns the local address
|
||||
|
||||
:returns: local address
|
||||
"""
|
||||
|
||||
return self._laddr
|
||||
|
||||
@property
|
||||
def lport(self):
|
||||
"""
|
||||
Returns the local port
|
||||
|
||||
:returns: local port number
|
||||
"""
|
||||
|
||||
return self._lport
|
||||
|
||||
@property
|
||||
def raddr(self):
|
||||
"""
|
||||
Returns the remote address
|
||||
|
||||
:returns: remote address
|
||||
"""
|
||||
|
||||
return self._raddr
|
||||
|
||||
@property
|
||||
def rport(self):
|
||||
"""
|
||||
Returns the remote port
|
||||
|
||||
:returns: remote port number
|
||||
"""
|
||||
|
||||
return self._rport
|
||||
|
||||
def connect(self, raddr, rport):
|
||||
"""
|
||||
Connects this NIO to a remote socket
|
||||
|
||||
:param raddr: remote address
|
||||
:param rport: remote port number
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio connect_udp_auto {name} {raddr} {rport}".format(name=self._name,
|
||||
raddr=raddr,
|
||||
rport=rport))
|
||||
self._raddr = raddr
|
||||
self._rport = rport
|
||||
@@ -0,0 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for UNIX NIOs (Unix based OSes only).
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_UNIX(NIO):
|
||||
"""
|
||||
Dynamips UNIX NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param local_file: local UNIX socket filename
|
||||
:param remote_file: remote UNIX socket filename
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, local_file, remote_file):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_UNIX._instance_count
|
||||
NIO_UNIX._instance_count += 1
|
||||
self._name = 'nio_unix' + str(self._id)
|
||||
self._local_file = local_file
|
||||
self._remote_file = remote_file
|
||||
|
||||
self._hypervisor.send("nio create_unix {name} {local} {remote}".format(name=self._name,
|
||||
local=local_file,
|
||||
remote=remote_file))
|
||||
|
||||
@property
|
||||
def local_file(self):
|
||||
"""
|
||||
Returns the local UNIX socket.
|
||||
|
||||
:returns: local UNIX socket filename
|
||||
"""
|
||||
|
||||
return self._local_file
|
||||
|
||||
@property
|
||||
def remote_file(self):
|
||||
"""
|
||||
Returns the remote UNIX socket.
|
||||
|
||||
:returns: remote UNIX socket filename
|
||||
"""
|
||||
|
||||
return self._remote_file
|
||||
@@ -0,0 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for VDE (Virtual Distributed Ethernet) NIOs (Unix based OSes only).
|
||||
"""
|
||||
|
||||
from .nio import NIO
|
||||
|
||||
|
||||
class NIO_VDE(NIO):
|
||||
"""
|
||||
Dynamips VDE NIO.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param control_file: VDE control filename
|
||||
:param local_file: VDE local filename
|
||||
"""
|
||||
|
||||
_instance_count = 0
|
||||
|
||||
def __init__(self, hypervisor, control_file, local_file):
|
||||
|
||||
NIO.__init__(self, hypervisor)
|
||||
|
||||
# create an unique ID
|
||||
self._id = NIO_VDE._instance_count
|
||||
NIO_VDE._instance_count += 1
|
||||
self._name = 'nio_vde' + str(self._id)
|
||||
self._control_file = control_file
|
||||
self._local_file = local_file
|
||||
|
||||
self._hypervisor.send("nio create_vde {name} {control} {local}".format(name=self._name,
|
||||
control=control_file,
|
||||
local=local_file))
|
||||
|
||||
@property
|
||||
def control_file(self):
|
||||
"""
|
||||
Returns the VDE control file.
|
||||
|
||||
:returns: VDE control filename
|
||||
"""
|
||||
|
||||
return self._control_file
|
||||
|
||||
@property
|
||||
def local_file(self):
|
||||
"""
|
||||
Returns the VDE local file.
|
||||
|
||||
:returns: VDE local filename
|
||||
"""
|
||||
|
||||
return self._local_file
|
||||
Whitespace-only changes.
@@ -0,0 +1,170 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual ATM bridge module ("atm_bridge").
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L622
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class ATMBridge(object):
|
||||
"""
|
||||
Dynamips bridge switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("atm_bridge create {}".format(self._name))
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this ATM bridge.
|
||||
|
||||
:returns: ATM bridge name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor object
|
||||
"""
|
||||
|
||||
return self._hypervisor
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all ATM bridge instances.
|
||||
|
||||
:returns: list of all ATM bridges
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("atm_bridge list")
|
||||
|
||||
@property
|
||||
def nios(self):
|
||||
"""
|
||||
Returns all the NIOs member of this ATM bridge.
|
||||
|
||||
:returns: nio list
|
||||
"""
|
||||
|
||||
return self._nios
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"""
|
||||
Returns port mapping
|
||||
|
||||
:returns: mapping list
|
||||
"""
|
||||
|
||||
return self._mapping
|
||||
|
||||
def rename(self, new_name):
|
||||
"""
|
||||
Renames this ATM bridge.
|
||||
|
||||
:param new_name: New name for this bridge
|
||||
"""
|
||||
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("atm_bridge rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this ATM bridge.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("atm_bridge delete {}".format(self._name))
|
||||
self._hypervisor.devices.remove(self)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on ATM bridge.
|
||||
|
||||
:param nio: NIO object to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
self._nios[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this ATM switch.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
del self._nios[port]
|
||||
|
||||
def configure(self, eth_port, atm_port, atm_vpi, atm_vci):
|
||||
"""
|
||||
Configures this ATM bridge.
|
||||
|
||||
:param eth_port: Ethernet port
|
||||
:param atm_port: ATM port
|
||||
:param atm_vpi: ATM VPI
|
||||
:param atm_vci: ATM VCI
|
||||
"""
|
||||
|
||||
if eth_port not in self._nios:
|
||||
raise DynamipsError("Ethernet port {} is not allocated".format(eth_port))
|
||||
|
||||
if atm_port not in self._nios:
|
||||
raise DynamipsError("ATM port {} is not allocated".format(atm_port))
|
||||
|
||||
eth_nio = self._nios[eth_port]
|
||||
atm_nio = self._nios[atm_port]
|
||||
|
||||
self._hypervisor.send("atm_bridge configure {name} {eth_nio} {atm_nio} {vpi} {vci}".format(name=self._name,
|
||||
eth_nio=eth_nio,
|
||||
atm_nio=atm_nio,
|
||||
vpi=atm_vpi,
|
||||
vci=atm_vci))
|
||||
self._mapping[eth_port] = (atm_port, atm_vpi, atm_vci)
|
||||
|
||||
def unconfigure(self):
|
||||
"""
|
||||
Unconfigures this ATM bridge.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("atm_bridge unconfigure {}".format(self._name))
|
||||
del self._mapping
|
||||
@@ -0,0 +1,248 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual ATM switch module ("atmsw").
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L593
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class ATMSwitch(object):
|
||||
"""
|
||||
Dynamips ATM switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("atmsw create {}".format(self._name))
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this ATM switch.
|
||||
|
||||
:returns: ATM switch name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor object
|
||||
"""
|
||||
|
||||
return self._hypervisor
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all ATM switches instances.
|
||||
|
||||
:returns: list of all ATM switches
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("atmsw list")
|
||||
|
||||
@property
|
||||
def nios(self):
|
||||
"""
|
||||
Returns all the NIOs member of this ATM switch.
|
||||
|
||||
:returns: nio list
|
||||
"""
|
||||
|
||||
return self._nios
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"""
|
||||
Returns port mapping
|
||||
|
||||
:returns: mapping list
|
||||
"""
|
||||
|
||||
return self._mapping
|
||||
|
||||
def rename(self, new_name):
|
||||
"""
|
||||
Renames this ATM switch.
|
||||
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("atmsw rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this ATM switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("atmsw delete {}".format(self._name))
|
||||
self._hypervisor.devices.remove(self)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on ATM switch.
|
||||
|
||||
:param nio: NIO object to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
self._nios[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this ATM switch.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
del self._nios[port]
|
||||
|
||||
def map_vp(self, port1, vpi1, port2, vpi2):
|
||||
"""
|
||||
Creates a new Virtual Path connection.
|
||||
|
||||
:param port1: input port
|
||||
:param vpi1: input vpi
|
||||
:param port2: output port
|
||||
:param vpi2: output vpi
|
||||
"""
|
||||
|
||||
if port1 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port1))
|
||||
|
||||
if port2 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port2))
|
||||
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
self._hypervisor.send("atmsw create_vpc {name} {input_nio} {input_vpi} {output_nio} {output_vpi}".format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2))
|
||||
self._mapping[(port1, vpi1)] = (port2, vpi2)
|
||||
|
||||
def unmap_vp(self, port1, vpi1, port2, vpi2):
|
||||
"""
|
||||
Deletes a new Virtual Path connection.
|
||||
|
||||
:param port1: input port
|
||||
:param vpi1: input vpi
|
||||
:param port2: output port
|
||||
:param vpi2: output vpi
|
||||
"""
|
||||
|
||||
if port1 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port1))
|
||||
|
||||
if port2 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port2))
|
||||
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
self._hypervisor.send("atmsw delete_vpc {name} {input_nio} {input_vpi} {output_nio} {output_vpi}".format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2))
|
||||
del self._mapping[(port1, vpi1)]
|
||||
|
||||
def map_pvc(self, port1, vpi1, vci1, port2, vpi2, vci2):
|
||||
"""
|
||||
Creates a new Virtual Channel connection (unidirectional).
|
||||
|
||||
:param port1: input port
|
||||
:param vpi1: input vpi
|
||||
:param vci1: input vci
|
||||
:param port2: output port
|
||||
:param vpi2: output vpi
|
||||
:param vci2: output vci
|
||||
"""
|
||||
|
||||
if port1 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port1))
|
||||
|
||||
if port2 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port2))
|
||||
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
self._hypervisor.send("atmsw create_vcc {name} {input_nio} {input_vpi} {input_vci} {output_nio} {output_vpi} {output_vci}".format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
input_vci=vci1,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2,
|
||||
output_vci=vci2))
|
||||
self._mapping[(port1, vpi1, vci1)] = (port2, vpi2, vci2)
|
||||
|
||||
def unmap_pvc(self, port1, vpi1, vci1, port2, vpi2, vci2):
|
||||
"""
|
||||
Deletes a new Virtual Channel connection (unidirectional).
|
||||
|
||||
:param port1: input port
|
||||
:param vpi1: input vpi
|
||||
:param vci1: input vci
|
||||
:param port2: output port
|
||||
:param vpi2: output vpi
|
||||
:param vci2: output vci
|
||||
"""
|
||||
|
||||
if port1 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port1))
|
||||
|
||||
if port2 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port2))
|
||||
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
self._hypervisor.send("atmsw delete_vcc {name} {input_nio} {input_vpi} {input_vci} {output_nio} {output_vpi} {output_vci}".format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
input_vci=vci1,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2,
|
||||
output_vci=vci2))
|
||||
del self._mapping[(port1, vpi1, vci1)]
|
||||
@@ -0,0 +1,121 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips NIO bridge module ("nio_bridge").
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L538
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
class Bridge(object):
|
||||
"""
|
||||
Dynamips bridge.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this bridge
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("nio_bridge create {}".format(self._name))
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = []
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this bridge.
|
||||
|
||||
:returns: bridge name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor object
|
||||
"""
|
||||
|
||||
return self._hypervisor
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all bridge instances.
|
||||
|
||||
:returns: list of all bridges
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("nio_bridge list")
|
||||
|
||||
@property
|
||||
def nios(self):
|
||||
"""
|
||||
Returns all the NIOs member of this bridge.
|
||||
|
||||
:returns: nio list
|
||||
"""
|
||||
|
||||
return self._nios
|
||||
|
||||
def rename(self, new_name):
|
||||
"""
|
||||
Renames this bridge.
|
||||
|
||||
:param new_name: New name for this bridge
|
||||
"""
|
||||
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("nio_bridge rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this bridge.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio_bridge delete {}".format(self._name))
|
||||
self._hypervisor.devices.remove(self)
|
||||
|
||||
def add_nio(self, nio):
|
||||
"""
|
||||
Adds a NIO as new port on this bridge.
|
||||
|
||||
:param nio: NIO object to add
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio_bridge add_nio {name} {nio}".format(name=self._name,
|
||||
nio=nio))
|
||||
self._nios.append(nio)
|
||||
|
||||
def remove_nio(self, nio):
|
||||
"""
|
||||
Removes the specified NIO as member of this bridge.
|
||||
|
||||
:param nio: NIO object to remove
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio_bridge remove_nio {name} {nio}".format(name=self._name,
|
||||
nio=nio))
|
||||
self._nios.remove(nio)
|
||||
@@ -0,0 +1,125 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 1700 instances module ("c1700")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L428
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .router import Router
|
||||
from ..adapters.c1700_mb_1fe import C1700_MB_1FE
|
||||
from ..adapters.c1700_mb_wic1 import C1700_MB_WIC1
|
||||
|
||||
|
||||
class C1700(Router):
|
||||
"""
|
||||
Dynamips c1700 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
:param chassis: chassis for this router:
|
||||
1720, 1721, 1750, 1751 or 1760 (default = 1720).
|
||||
1710 is not supported.
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, chassis="1720"):
|
||||
Router.__init__(self, hypervisor, name, platform="c1700")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 64
|
||||
self._nvram = 32
|
||||
self._disk0 = 0
|
||||
self._disk1 = 0
|
||||
self._chassis = chassis
|
||||
self._iomem = 15 # percentage
|
||||
self._clock_divisor = 8
|
||||
|
||||
if chassis != "1720":
|
||||
self.chassis = chassis
|
||||
|
||||
self._setup_chassis()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c1700 instances
|
||||
|
||||
:returns: c1700 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c1700 list")
|
||||
|
||||
def _setup_chassis(self):
|
||||
"""
|
||||
Set up the router with the corresponding chassis
|
||||
(create slots and insert default adapters).
|
||||
"""
|
||||
|
||||
# With 1751 and 1760, WICs in WIC slot 1 show up as in slot 1, not 0
|
||||
# e.g. s1/0 not s0/2
|
||||
if self._chassis in ['1751', '1760']:
|
||||
self._create_slots(2)
|
||||
self._slots[1] = C1700_MB_WIC1()
|
||||
else:
|
||||
self._create_slots(1)
|
||||
self._slots[0] = C1700_MB_1FE()
|
||||
|
||||
@property
|
||||
def chassis(self):
|
||||
"""
|
||||
Returns the chassis.
|
||||
|
||||
:returns: chassis string
|
||||
"""
|
||||
|
||||
return self._chassis
|
||||
|
||||
@chassis.setter
|
||||
def chassis(self, chassis):
|
||||
"""
|
||||
Set the chassis.
|
||||
|
||||
:param: chassis string:
|
||||
1720, 1721, 1750, 1751 or 1760
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c1700 set_chassis {name} {chassis}".format(name=self._name,
|
||||
chassis=chassis))
|
||||
self._chassis = chassis
|
||||
self._setup_chassis()
|
||||
|
||||
@property
|
||||
def iomem(self):
|
||||
"""
|
||||
Returns I/O memory size for this router.
|
||||
|
||||
:returns: I/O memory size (integer)
|
||||
"""
|
||||
|
||||
return self._iomem
|
||||
|
||||
@iomem.setter
|
||||
def iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c1700 set_iomem {name} {size}".format(name=self._name,
|
||||
size=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,135 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 2600 instances module ("c2600")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L404
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .router import Router
|
||||
from ..adapters.c2600_mb_1e import C2600_MB_1E
|
||||
from ..adapters.c2600_mb_2e import C2600_MB_2E
|
||||
from ..adapters.c2600_mb_1fe import C2600_MB_1FE
|
||||
from ..adapters.c2600_mb_2fe import C2600_MB_2FE
|
||||
|
||||
|
||||
class C2600(Router):
|
||||
"""
|
||||
Dynamips c2600 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
:param chassis: chassis for this router:
|
||||
2610, 2611, 2620, 2621, 2610XM, 2611XM
|
||||
2620XM, 2621XM, 2650XM or 2651XM (default = 2610).
|
||||
"""
|
||||
|
||||
# adapters to insert by default corresponding the
|
||||
# chosen chassis.
|
||||
integrated_adapters = {'2610': C2600_MB_1E,
|
||||
'2611': C2600_MB_2E,
|
||||
'2620': C2600_MB_1FE,
|
||||
'2621': C2600_MB_2FE,
|
||||
'2610XM': C2600_MB_1FE,
|
||||
'2611XM': C2600_MB_2FE,
|
||||
'2620XM': C2600_MB_1FE,
|
||||
'2621XM': C2600_MB_2FE,
|
||||
'2650XM': C2600_MB_1FE,
|
||||
'2651XM': C2600_MB_2FE}
|
||||
|
||||
def __init__(self, hypervisor, name, chassis="2610"):
|
||||
Router.__init__(self, hypervisor, name, platform="c2600")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 64
|
||||
self._nvram = 128
|
||||
self._disk0 = 0
|
||||
self._disk1 = 0
|
||||
self._chassis = chassis
|
||||
self._iomem = 15 # percentage
|
||||
self._clock_divisor = 8
|
||||
|
||||
if chassis != "2610":
|
||||
self.chassis = chassis
|
||||
|
||||
self._setup_chassis()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c2600 instances
|
||||
|
||||
:returns: c2600 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c2600 list")
|
||||
|
||||
def _setup_chassis(self):
|
||||
"""
|
||||
Set up the router with the corresponding chassis
|
||||
(create slots and insert default adapters).
|
||||
"""
|
||||
|
||||
self._create_slots(2)
|
||||
self._slots[0] = self.integrated_adapters[self._chassis]()
|
||||
|
||||
@property
|
||||
def chassis(self):
|
||||
"""
|
||||
Returns the chassis.
|
||||
|
||||
:returns: chassis string
|
||||
"""
|
||||
|
||||
return self._chassis
|
||||
|
||||
@chassis.setter
|
||||
def chassis(self, chassis):
|
||||
"""
|
||||
Set the chassis.
|
||||
|
||||
:param: chassis string:
|
||||
2610, 2611, 2620, 2621, 2610XM, 2611XM
|
||||
2620XM, 2621XM, 2650XM or 2651XM
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c2600 set_chassis {name} {chassis}".format(name=self._name,
|
||||
chassis=chassis))
|
||||
self._chassis = chassis
|
||||
self._setup_chassis()
|
||||
|
||||
@property
|
||||
def iomem(self):
|
||||
"""
|
||||
Returns I/O memory size for this router.
|
||||
|
||||
:returns: I/O memory size (integer)
|
||||
"""
|
||||
|
||||
return self._iomem
|
||||
|
||||
@iomem.setter
|
||||
def iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c2600 set_iomem {name} {size}".format(name=self._name,
|
||||
size=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 2691 instances module ("c2691")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L387
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .router import Router
|
||||
from ..adapters.gt96100_fe import GT96100_FE
|
||||
|
||||
|
||||
class C2691(Router):
|
||||
"""
|
||||
Dynamips c2691 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
Router.__init__(self, hypervisor, name, platform="c2691")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 128
|
||||
self._nvram = 112
|
||||
self._disk0 = 16
|
||||
self._disk1 = 0
|
||||
self._iomem = 5 # percentage
|
||||
self._clock_divisor = 8
|
||||
|
||||
self._create_slots(2)
|
||||
self._slots[0] = GT96100_FE()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c2691 instances
|
||||
|
||||
:returns: c2691 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c2691 list")
|
||||
|
||||
@property
|
||||
def iomem(self):
|
||||
"""
|
||||
Returns I/O memory size for this router.
|
||||
|
||||
:returns: I/O memory size (integer)
|
||||
"""
|
||||
|
||||
return self._iomem
|
||||
|
||||
@iomem.setter
|
||||
def iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c2691 set_iomem {name} {size}".format(name=self._name,
|
||||
size=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,121 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 3600 instances module ("c3600")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L366
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .router import Router
|
||||
from ..adapters.leopard_2fe import Leopard_2FE
|
||||
|
||||
|
||||
class C3600(Router):
|
||||
"""
|
||||
Dynamips c3600 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
:param chassis: chassis for this router:
|
||||
3620, 3640 or 3660 (default = 3640).
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, chassis="3640"):
|
||||
Router.__init__(self, hypervisor, name, platform="c3600")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 128
|
||||
self._nvram = 128
|
||||
self._disk0 = 0
|
||||
self._disk1 = 0
|
||||
self._iomem = 5 # percentage
|
||||
self._chassis = chassis
|
||||
self._clock_divisor = 4
|
||||
|
||||
if chassis != "3640":
|
||||
self.chassis = chassis
|
||||
|
||||
self._setup_chassis()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c3600 instances
|
||||
|
||||
:returns: c3600 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c3600 list")
|
||||
|
||||
def _setup_chassis(self):
|
||||
"""
|
||||
Set up the router with the corresponding chassis
|
||||
(create slots and insert default adapters).
|
||||
"""
|
||||
|
||||
if self._chassis == "3620":
|
||||
self._create_slots(2)
|
||||
elif self._chassis == "3640":
|
||||
self._create_slots(4)
|
||||
elif self._chassis == "3660":
|
||||
self._create_slots(7)
|
||||
self._slots[0] = Leopard_2FE()
|
||||
|
||||
@property
|
||||
def chassis(self):
|
||||
"""
|
||||
Returns the chassis.
|
||||
|
||||
:returns: chassis string
|
||||
"""
|
||||
|
||||
return self._chassis
|
||||
|
||||
@chassis.setter
|
||||
def chassis(self, chassis):
|
||||
"""
|
||||
Set the chassis.
|
||||
|
||||
:param: chassis string: 3620, 3640 or 3660
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c3600 set_chassis {name} {chassis}".format(name=self._name,
|
||||
chassis=chassis))
|
||||
self._chassis = chassis
|
||||
self._setup_chassis()
|
||||
|
||||
@property
|
||||
def iomem(self):
|
||||
"""
|
||||
Returns I/O memory size for this router.
|
||||
|
||||
:returns: I/O memory size (integer)
|
||||
"""
|
||||
|
||||
return self._iomem
|
||||
|
||||
@iomem.setter
|
||||
def iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c3600 set_iomem {name} {size}".format(name=self._name,
|
||||
size=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 3725 instances module ("c3725")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L346
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .router import Router
|
||||
from ..adapters.gt96100_fe import GT96100_FE
|
||||
|
||||
|
||||
class C3725(Router):
|
||||
"""
|
||||
Dynamips c3725 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
Router.__init__(self, hypervisor, name, platform="c3725")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 128
|
||||
self._nvram = 112
|
||||
self._disk0 = 16
|
||||
self._disk1 = 0
|
||||
self._iomem = 5 # percentage
|
||||
self._clock_divisor = 8
|
||||
|
||||
self._create_slots(3)
|
||||
self._slots[0] = GT96100_FE()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c3725 instances.
|
||||
|
||||
:returns: c3725 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c3725 list")
|
||||
|
||||
@property
|
||||
def iomem(self):
|
||||
"""
|
||||
Returns I/O memory size for this router.
|
||||
|
||||
:returns: I/O memory size (integer)
|
||||
"""
|
||||
|
||||
return self._iomem
|
||||
|
||||
@iomem.setter
|
||||
def iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c3725 set_iomem {name} {size}".format(name=self._name,
|
||||
size=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 3745 instances module ("c3745")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L326
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .router import Router
|
||||
from ..adapters.gt96100_fe import GT96100_FE
|
||||
|
||||
|
||||
class C3745(Router):
|
||||
"""
|
||||
Dynamips c3745 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
Router.__init__(self, hypervisor, name, platform="c3745")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 128
|
||||
self._nvram = 304
|
||||
self._disk0 = 16
|
||||
self._disk1 = 0
|
||||
self._iomem = 5 # percentage
|
||||
self._clock_divisor = 8
|
||||
|
||||
self._create_slots(5)
|
||||
self._slots[0] = GT96100_FE()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c3745 instances.
|
||||
|
||||
:returns: c3745 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c3745 list")
|
||||
|
||||
@property
|
||||
def iomem(self):
|
||||
"""
|
||||
Returns I/O memory size for this router.
|
||||
|
||||
:returns: I/O memory size (integer)
|
||||
"""
|
||||
|
||||
return self._iomem
|
||||
|
||||
@iomem.setter
|
||||
def iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c3745 set_iomem {name} {size}".format(name=self._name,
|
||||
size=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,187 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Cisco 7200 instances module ("c7200")
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L294
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from ..dynamips_error import DynamipsError
|
||||
from .router import Router
|
||||
from ..adapters.c7200_io_2fe import C7200_IO_2FE
|
||||
from ..adapters.c7200_io_ge_e import C7200_IO_GE_E
|
||||
|
||||
|
||||
class C7200(Router):
|
||||
"""
|
||||
Dynamips c7200 router (model is 7206).
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this router
|
||||
:param npe: default NPE
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, npe="npe-400"):
|
||||
Router.__init__(self, hypervisor, name, platform="c7200")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 256
|
||||
self._nvram = 128
|
||||
self._disk0 = 64
|
||||
self._disk1 = 0
|
||||
self._npe = npe
|
||||
self._midplane = "vxr"
|
||||
self._clock_divisor = 4
|
||||
|
||||
if npe != "npe-400":
|
||||
self.npe = npe
|
||||
|
||||
# 4 sensors with a default temperature of 22C:
|
||||
# sensor 1 = I/0 controller inlet
|
||||
# sensor 2 = I/0 controller outlet
|
||||
# sensor 3 = NPE inlet
|
||||
# sensor 4 = NPE outlet
|
||||
self._sensors = [22, 22, 22, 22]
|
||||
|
||||
# 2 power supplies powered on
|
||||
self._power_supplies = [1, 1]
|
||||
|
||||
self._create_slots(7)
|
||||
|
||||
# first slot is a mandatory Input/Output controller (based on NPE type)
|
||||
if npe == "npe-g2":
|
||||
self._slots[0] = C7200_IO_GE_E()
|
||||
else:
|
||||
self._slots[0] = C7200_IO_2FE()
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c7200 instances.
|
||||
|
||||
:returns: c7200 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c7200 list")
|
||||
|
||||
@property
|
||||
def npe(self):
|
||||
"""
|
||||
Returns the NPE model.
|
||||
|
||||
:returns: NPE model string (e.g. "npe-200")
|
||||
"""
|
||||
|
||||
return self._npe
|
||||
|
||||
@npe.setter
|
||||
def npe(self, npe):
|
||||
"""
|
||||
Set the NPE model.
|
||||
|
||||
:params npe: NPE model string (e.g. "npe-200")
|
||||
NPE models are npe-100, npe-150, npe-175, npe-200,
|
||||
npe-225, npe-300, npe-400 and npe-g2 (PowerPC c7200 only)
|
||||
"""
|
||||
|
||||
if self.is_running():
|
||||
raise DynamipsError("Cannot change NPE on running router")
|
||||
|
||||
self._hypervisor.send("c7200 set_npe {name} {npe}".format(name=self._name,
|
||||
npe=npe))
|
||||
self._npe = npe
|
||||
|
||||
@property
|
||||
def midplane(self):
|
||||
"""
|
||||
Returns the midplane model.
|
||||
|
||||
:returns: midplane model string (e.g. "vxr" or "std")
|
||||
"""
|
||||
|
||||
return self._midplane
|
||||
|
||||
@midplane.setter
|
||||
def midplane(self, midplane):
|
||||
"""
|
||||
Set the midplane model.
|
||||
|
||||
:returns: midplane model string (e.g. "vxr" or "std")
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c7200 set_midplane {name} {midplane}".format(name=self._name,
|
||||
midplane=midplane))
|
||||
self._midplane = midplane
|
||||
|
||||
@property
|
||||
def sensors(self):
|
||||
"""
|
||||
Returns the 4 sensors with temperature in degree Celcius.
|
||||
|
||||
:returns: list of 4 sensor temperatures
|
||||
"""
|
||||
|
||||
return self._sensors
|
||||
|
||||
@sensors.setter
|
||||
def sensors(self, sensors):
|
||||
"""
|
||||
Set the 4 sensors with temperature in degree Celcius.
|
||||
|
||||
:param sensors: list of 4 sensor temperatures corresponding to
|
||||
sensor 1 = I/0 controller inlet
|
||||
sensor 2 = I/0 controller outlet
|
||||
sensor 3 = NPE inlet
|
||||
sensor 4 = NPE outlet
|
||||
Example: [22, 22, 22, 22]
|
||||
"""
|
||||
|
||||
sensor_id = 0
|
||||
for sensor in sensors:
|
||||
self._hypervisor.send("c7200 set_temp_sensor {name} {sensor_id} {temp}".format(name=self._name,
|
||||
sensor_id=sensor_id,
|
||||
temp=sensor))
|
||||
sensor_id += 1
|
||||
self._sensors = sensors
|
||||
|
||||
@property
|
||||
def power_supplies(self):
|
||||
"""
|
||||
Returns the 2 power supplies with 0 = off, 1 = on.
|
||||
|
||||
:returns: list of 2 power supplies.
|
||||
"""
|
||||
|
||||
return self._power_supplies
|
||||
|
||||
@power_supplies.setter
|
||||
def power_supplies(self, power_supplies):
|
||||
"""
|
||||
Set the 2 power supplies with 0 = off, 1 = on.
|
||||
|
||||
:param power_supplies: list of 2 power supplies.
|
||||
Example: [1, 0] = first power supply is on, second is off.
|
||||
"""
|
||||
|
||||
power_supply_id = 0
|
||||
for power_supply in power_supplies:
|
||||
self._hypervisor.send("c7200 set_power_supply {name} {power_supply_id} {powered_on}".format(name=self._name,
|
||||
power_supply_id=power_supply_id,
|
||||
powered_on=power_supply))
|
||||
power_supply_id += 1
|
||||
self._power_supplies = power_supplies
|
||||
@@ -0,0 +1,212 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Ethernet switch module ("ethsw").
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L558
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class EthernetSwitch(object):
|
||||
"""
|
||||
Dynamips Ethernet switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("ethsw create {}".format(self._name))
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this Ethernet switch.
|
||||
|
||||
:returns: Ethernet switch name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor object
|
||||
"""
|
||||
|
||||
return self._hypervisor
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all Ethernet switches instances.
|
||||
|
||||
:returns: list of all Ethernet switches
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("ethsw list")
|
||||
|
||||
@property
|
||||
def nios(self):
|
||||
"""
|
||||
Returns all the NIOs member of this Ethernet switch.
|
||||
|
||||
:returns: nio list
|
||||
"""
|
||||
|
||||
return self._nios
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"""
|
||||
Returns port mapping
|
||||
|
||||
:returns: mapping list
|
||||
"""
|
||||
|
||||
return self._mapping
|
||||
|
||||
def rename(self, new_name):
|
||||
"""
|
||||
Renames this Ethernet switch.
|
||||
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("ethsw rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this Ethernet switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("ethsw delete {}".format(self._name))
|
||||
self._hypervisor.devices.remove(self)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on Ethernet switch.
|
||||
|
||||
:param nio: NIO object to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
self._hypervisor.send("ethsw add_nio {name} {nio}".format(name=self._name,
|
||||
nio=nio))
|
||||
self._nios[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this Ethernet switch.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
self._hypervisor.send("ethsw remove_nio {name} {nio}".format(name=self._name,
|
||||
nio=nio))
|
||||
del self._nios[port]
|
||||
|
||||
if port in self._mapping:
|
||||
del self._mapping[port]
|
||||
|
||||
def set_access_port(self, port, vlan_id):
|
||||
"""
|
||||
Set the specified port as an ACCESS port.
|
||||
|
||||
:param port: allocated port
|
||||
:param vlan_id: VLAN number membership
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
self._hypervisor.send("ethsw set_access_port {name} {nio} {vlan_id}".format(name=self._name,
|
||||
nio=nio,
|
||||
vlan_id=vlan_id))
|
||||
self._mapping[port] = ("access", vlan_id)
|
||||
|
||||
def set_dot1q_port(self, port, native_vlan):
|
||||
"""
|
||||
Set the specified port as a 802.1Q trunk port.
|
||||
|
||||
:param port: allocated port
|
||||
:param native_vlan: native VLAN for this trunk port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
self._hypervisor.send("ethsw set_dot1q_port {name} {nio} {native_vlan}".format(name=self._name,
|
||||
nio=nio,
|
||||
native_vlan=native_vlan))
|
||||
self._mapping[port] = ("dot1q", native_vlan)
|
||||
|
||||
def set_qinq_port(self, port, outer_vlan):
|
||||
"""
|
||||
Set the specified port as a trunk (QinQ) port.
|
||||
|
||||
:param port: allocated port
|
||||
:param outer_vlan: outer VLAN (transport VLAN) for this QinQ port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
self._hypervisor.send("ethsw set_qinq_port {name} {nio} {outer_vlan}".format(name=self._name,
|
||||
nio=nio,
|
||||
outer_vlan=outer_vlan))
|
||||
self._mapping[port] = ("qinq", outer_vlan)
|
||||
|
||||
def get_mac_addr_table(self):
|
||||
"""
|
||||
Returns the MAC address table for this Ethernet switch.
|
||||
|
||||
:returns: list of entries (Ethernet address, VLAN, NIO)
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("ethsw show_mac_addr_table {}".format(self._name))
|
||||
|
||||
def clear_mac_addr_table(self):
|
||||
"""
|
||||
Clears the MAC address table for this Ethernet switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("ethsw clear_mac_addr_table {}".format(self._name))
|
||||
@@ -0,0 +1,188 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Interface for Dynamips virtual Frame-Relay switch module.
|
||||
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L642
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class FrameRelaySwitch(object):
|
||||
"""
|
||||
Dynamips Frame Relay switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("frsw create {}".format(self._name))
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this Frame Relay switch.
|
||||
|
||||
:returns: Frame Relay switch name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor object
|
||||
"""
|
||||
|
||||
return self._hypervisor
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all Frame Relay switches instances.
|
||||
|
||||
:returns: list of all Frame Relay switches
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("frsw list")
|
||||
|
||||
@property
|
||||
def nios(self):
|
||||
"""
|
||||
Returns all the NIOs member of this Frame Relay switch.
|
||||
|
||||
:returns: nio list
|
||||
"""
|
||||
|
||||
return self._nios
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"""
|
||||
Returns port mapping
|
||||
|
||||
:returns: mapping list
|
||||
"""
|
||||
|
||||
return self._mapping
|
||||
|
||||
def rename(self, new_name):
|
||||
"""
|
||||
Renames this Frame Relay switch.
|
||||
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
|
||||
self._hypervisor.send("frsw rename {name} {new_name}".format(name=self._name,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this Frame Relay switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("frsw delete {}".format(self._name))
|
||||
self._hypervisor.devices.remove(self)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on Frame Relay switch.
|
||||
|
||||
:param nio: NIO object to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
self._nios[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this Frame Relay switch.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
del self._nios[port]
|
||||
|
||||
def map_vc(self, port1, dlci1, port2, dlci2):
|
||||
"""
|
||||
Creates a new Virtual Circuit connection (unidirectional).
|
||||
|
||||
:param port1: input port
|
||||
:param dlci1: input DLCI
|
||||
:param port2: output port
|
||||
:param dlci2: output DLCI
|
||||
"""
|
||||
|
||||
if port1 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port1))
|
||||
|
||||
if port2 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port2))
|
||||
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
self._hypervisor.send("frsw create_vc {name} {input_nio} {input_dlci} {output_nio} {output_dlci}".format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_dlci=dlci1,
|
||||
output_nio=nio2,
|
||||
output_dlci=dlci2))
|
||||
self._mapping[(port1, dlci1)] = (port2, dlci2)
|
||||
|
||||
def unmap_vc(self, port1, dlci1, port2, dlci2):
|
||||
"""
|
||||
Deletes a Virtual Circuit connection (unidirectional).
|
||||
|
||||
:param port1: input port
|
||||
:param dlci1: input DLCI
|
||||
:param port2: output port
|
||||
:param dlci2: output DLCI
|
||||
"""
|
||||
|
||||
if port1 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port1))
|
||||
|
||||
if port2 not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port2))
|
||||
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
self._hypervisor.send("frsw delete_vc {name} {input_nio} {input_dlci} {output_nio} {output_dlci}".format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_dlci=dlci1,
|
||||
output_nio=nio2,
|
||||
output_dlci=dlci2))
|
||||
del self._mapping[(port1, dlci1)]
|
||||
@@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013 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/>.
|
||||
|
||||
"""
|
||||
Hub object that uses the Bridge interface to create a hub with ports.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from .bridge import Bridge
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class Hub(Bridge):
|
||||
"""
|
||||
Dynamips hub (based on Bridge)
|
||||
|
||||
:param hypervisor: Dynamips hypervisor object
|
||||
:param name: name for this hub
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
Bridge.__init__(self, hypervisor, name)
|
||||
self._mapping = {}
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"""
|
||||
Returns port mapping
|
||||
|
||||
:returns: mapping list
|
||||
"""
|
||||
|
||||
return self._mapping
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on this hub.
|
||||
|
||||
:param nio: NIO object to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._mapping:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
Bridge.add_nio(self, nio)
|
||||
self._mapping[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this hub.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._mapping:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._mapping[port]
|
||||
Bridge.remove_nio(self, nio)
|
||||
del self._mapping[port]
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user