mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Yet another PEP 8 :)
This commit is contained in:
1 parent
7cf409c392
commit
bbee5f90a0
106 files changed
+9
-29
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,172 @@
|
||||
# -*- 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 ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class ATMBridge(object):
|
||||
|
||||
"""
|
||||
Dynamips bridge switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
# FIXME: instance tracking
|
||||
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
|
||||
|
||||
@name.setter
|
||||
def name(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
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor instance
|
||||
"""
|
||||
|
||||
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 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 instance 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,406 @@
|
||||
# -*- 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
|
||||
"""
|
||||
|
||||
import os
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ATMSwitch(object):
|
||||
|
||||
"""
|
||||
Dynamips ATM switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
_instances = []
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
# find an instance identifier (0 < id <= 4096)
|
||||
self._id = 0
|
||||
for identifier in range(1, 4097):
|
||||
if identifier not in self._instances:
|
||||
self._id = identifier
|
||||
self._instances.append(self._id)
|
||||
break
|
||||
|
||||
if self._id == 0:
|
||||
raise DynamipsError("Maximum number of instances reached")
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("atmsw create {}".format(self._name))
|
||||
|
||||
log.info("ATM switch {name} [id={id}] has been created".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Resets the instance count and the allocated instances list.
|
||||
"""
|
||||
|
||||
cls._instances.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Returns the unique ID for this ATM switch.
|
||||
|
||||
:returns: id (integer)
|
||||
"""
|
||||
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this ATM switch.
|
||||
|
||||
:returns: ATM switch name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@name.setter
|
||||
def name(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))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor instance
|
||||
"""
|
||||
|
||||
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 delete(self):
|
||||
"""
|
||||
Deletes this ATM switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("atmsw delete {}".format(self._name))
|
||||
|
||||
log.info("ATM switch {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._instances.remove(self._id)
|
||||
|
||||
def has_port(self, port):
|
||||
"""
|
||||
Checks if a port exists on this ATM switch.
|
||||
|
||||
:returns: boolean
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on ATM switch.
|
||||
|
||||
:param nio: NIO instance to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: NIO {nio} bound to port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=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))
|
||||
|
||||
nio = self._nios[port]
|
||||
log.info("ATM switch {name} [id={id}]: NIO {nio} removed from port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port))
|
||||
|
||||
del self._nios[port]
|
||||
return nio
|
||||
|
||||
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))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: VPC from port {port1} VPI {vpi1} to port {port2} VPI {vpi2} created".format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
port2=port2,
|
||||
vpi2=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))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: VPC from port {port1} VPI {vpi1} to port {port2} VPI {vpi2} deleted".format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
port2=port2,
|
||||
vpi2=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))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: VCC from port {port1} VPI {vpi1} VCI {vci1} to port {port2} VPI {vpi2} VCI {vci2} created".format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
vci1=vci1,
|
||||
port2=port2,
|
||||
vpi2=vpi2,
|
||||
vci2=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))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: VCC from port {port1} VPI {vpi1} VCI {vci1} to port {port2} VPI {vpi2} VCI {vci2} deleted".format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
vci1=vci1,
|
||||
port2=port2,
|
||||
vpi2=vpi2,
|
||||
vci2=vci2))
|
||||
del self._mapping[(port1, vpi1, vci1)]
|
||||
|
||||
def start_capture(self, port, output_file, data_link_type="DLT_ATM_RFC1483"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
:param output_file: PCAP destination file for the capture
|
||||
:param data_link_type: PCAP data link type (DLT_*), default is DLT_ATM_RFC1483
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
|
||||
data_link_type = data_link_type.lower()
|
||||
if data_link_type.startswith("dlt_"):
|
||||
data_link_type = data_link_type[4:]
|
||||
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port))
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(output_file))
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not create captures directory {}".format(e))
|
||||
|
||||
nio.bind_filter("both", "capture")
|
||||
nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||
|
||||
log.info("ATM switch {name} [id={id}]: starting packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
|
||||
def stop_capture(self, port):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
nio.unbind_filter("both")
|
||||
log.info("ATM switch {name} [id={id}]: stopping packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
@@ -0,0 +1,122 @@
|
||||
# -*- 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
|
||||
"""
|
||||
|
||||
|
||||
class Bridge(object):
|
||||
|
||||
"""
|
||||
Dynamips bridge.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
: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
|
||||
|
||||
@name.setter
|
||||
def name(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
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor instance
|
||||
"""
|
||||
|
||||
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 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 instance 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 instance to remove
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio_bridge remove_nio {name} {nio}".format(name=self._name,
|
||||
nio=nio))
|
||||
self._nios.remove(nio)
|
||||
@@ -0,0 +1,162 @@
|
||||
# -*- 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 .router import Router
|
||||
from ..adapters.c1700_mb_1fe import C1700_MB_1FE
|
||||
from ..adapters.c1700_mb_wic1 import C1700_MB_WIC1
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C1700(Router):
|
||||
|
||||
"""
|
||||
Dynamips c1700 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
:param chassis: chassis for this router:
|
||||
1720, 1721, 1750, 1751 or 1760 (default = 1720).
|
||||
1710 is not supported.
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, router_id=None, chassis="1720"):
|
||||
Router.__init__(self, hypervisor, name, router_id, platform="c1700")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 128
|
||||
self._nvram = 32
|
||||
self._disk0 = 0
|
||||
self._disk1 = 0
|
||||
self._chassis = chassis
|
||||
self._iomem = 15 # percentage
|
||||
self._clock_divisor = 8
|
||||
self._sparsemem = False
|
||||
|
||||
if chassis != "1720":
|
||||
self.chassis = chassis
|
||||
|
||||
self._setup_chassis()
|
||||
|
||||
def defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"chassis": self._chassis,
|
||||
"iomem": self._iomem,
|
||||
"clock_divisor": self._clock_divisor,
|
||||
"sparsemem": self._sparsemem}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c1700 instances
|
||||
|
||||
:returns: c1700 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c1700 list")
|
||||
|
||||
def _setup_chassis(self):
|
||||
"""
|
||||
Sets 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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: chassis set to {chassis}".format(name=self._name,
|
||||
id=self._id,
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: I/O memory updated from {old_iomem}% to {new_iomem}%".format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,171 @@
|
||||
# -*- 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 .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
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C2600(Router):
|
||||
|
||||
"""
|
||||
Dynamips c2600 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
: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, router_id=None, chassis="2610"):
|
||||
Router.__init__(self, hypervisor, name, router_id, platform="c2600")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 128
|
||||
self._nvram = 128
|
||||
self._disk0 = 0
|
||||
self._disk1 = 0
|
||||
self._chassis = chassis
|
||||
self._iomem = 15 # percentage
|
||||
self._clock_divisor = 8
|
||||
self._sparsemem = False
|
||||
|
||||
if chassis != "2610":
|
||||
self.chassis = chassis
|
||||
|
||||
self._setup_chassis()
|
||||
|
||||
def defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"iomem": self._iomem,
|
||||
"chassis": self._chassis,
|
||||
"clock_divisor": self._clock_divisor,
|
||||
"sparsemem": self._sparsemem}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c2600 instances
|
||||
|
||||
:returns: c2600 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c2600 list")
|
||||
|
||||
def _setup_chassis(self):
|
||||
"""
|
||||
Sets 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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: chassis set to {chassis}".format(name=self._name,
|
||||
id=self._id,
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: I/O memory updated from {old_iomem}% to {new_iomem}%".format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,108 @@
|
||||
# -*- 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 .router import Router
|
||||
from ..adapters.gt96100_fe import GT96100_FE
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C2691(Router):
|
||||
|
||||
"""
|
||||
Dynamips c2691 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, router_id=None):
|
||||
Router.__init__(self, hypervisor, name, router_id, platform="c2691")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 192
|
||||
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 defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"iomem": self._iomem,
|
||||
"clock_divisor": self._clock_divisor}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: I/O memory updated from {old_iomem}% to {new_iomem}%".format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,156 @@
|
||||
# -*- 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 .router import Router
|
||||
from ..adapters.leopard_2fe import Leopard_2FE
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C3600(Router):
|
||||
|
||||
"""
|
||||
Dynamips c3600 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
:param chassis: chassis for this router:
|
||||
3620, 3640 or 3660 (default = 3640).
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, router_id=None, chassis="3640"):
|
||||
Router.__init__(self, hypervisor, name, router_id, platform="c3600")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 192
|
||||
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 defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"iomem": self._iomem,
|
||||
"chassis": self._chassis,
|
||||
"clock_divisor": self._clock_divisor}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Returns all c3600 instances
|
||||
|
||||
:returns: c3600 instance list
|
||||
"""
|
||||
|
||||
return self._hypervisor.send("c3600 list")
|
||||
|
||||
def _setup_chassis(self):
|
||||
"""
|
||||
Sets 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):
|
||||
"""
|
||||
Sets the chassis.
|
||||
|
||||
:param: chassis string: 3620, 3640 or 3660
|
||||
"""
|
||||
|
||||
self._hypervisor.send("c3600 set_chassis {name} {chassis}".format(name=self._name,
|
||||
chassis=chassis))
|
||||
|
||||
log.info("router {name} [id={id}]: chassis set to {chassis}".format(name=self._name,
|
||||
id=self._id,
|
||||
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))
|
||||
|
||||
log.info("router {name} [id={id}]: I/O memory updated from {old_iomem}% to {new_iomem}%".format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,108 @@
|
||||
# -*- 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 .router import Router
|
||||
from ..adapters.gt96100_fe import GT96100_FE
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C3725(Router):
|
||||
|
||||
"""
|
||||
Dynamips c3725 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, router_id=None):
|
||||
Router.__init__(self, hypervisor, name, router_id, 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 defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"iomem": self._iomem,
|
||||
"clock_divisor": self._clock_divisor}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: I/O memory updated from {old_iomem}% to {new_iomem}%".format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,108 @@
|
||||
# -*- 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 .router import Router
|
||||
from ..adapters.gt96100_fe import GT96100_FE
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C3745(Router):
|
||||
|
||||
"""
|
||||
Dynamips c3745 router.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, router_id=None):
|
||||
Router.__init__(self, hypervisor, name, router_id, platform="c3745")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 256
|
||||
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 defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"iomem": self._iomem,
|
||||
"clock_divisor": self._clock_divisor}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: I/O memory updated from {old_iomem}% to {new_iomem}%".format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
self._iomem = iomem
|
||||
@@ -0,0 +1,250 @@
|
||||
# -*- 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 ..dynamips_error import DynamipsError
|
||||
from .router import Router
|
||||
from ..adapters.c7200_io_fe import C7200_IO_FE
|
||||
from ..adapters.c7200_io_ge_e import C7200_IO_GE_E
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C7200(Router):
|
||||
|
||||
"""
|
||||
Dynamips c7200 router (model is 7206).
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this router
|
||||
:param router_id: router instance ID
|
||||
:param npe: default NPE
|
||||
"""
|
||||
|
||||
def __init__(self, hypervisor, name, router_id=None, npe="npe-400"):
|
||||
Router.__init__(self, hypervisor, name, router_id, platform="c7200")
|
||||
|
||||
# Set default values for this platform
|
||||
self._ram = 512
|
||||
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.slot_add_binding(0, C7200_IO_GE_E())
|
||||
else:
|
||||
self.slot_add_binding(0, C7200_IO_FE())
|
||||
|
||||
def defaults(self):
|
||||
"""
|
||||
Returns all the default attribute values for this platform.
|
||||
|
||||
:returns: default values (dictionary)
|
||||
"""
|
||||
|
||||
router_defaults = Router.defaults(self)
|
||||
|
||||
platform_defaults = {"ram": self._ram,
|
||||
"nvram": self._nvram,
|
||||
"disk0": self._disk0,
|
||||
"disk1": self._disk1,
|
||||
"npe": self._npe,
|
||||
"midplane": self._midplane,
|
||||
"clock_divisor": self._clock_divisor,
|
||||
"sensors": self._sensors,
|
||||
"power_supplies": self._power_supplies}
|
||||
|
||||
# update the router defaults with the platform specific defaults
|
||||
router_defaults.update(platform_defaults)
|
||||
return router_defaults
|
||||
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: NPE updated from {old_npe} to {new_npe}".format(name=self._name,
|
||||
id=self._id,
|
||||
old_npe=self._npe,
|
||||
new_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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: midplane updated from {old_midplane} to {new_midplane}".format(name=self._name,
|
||||
id=self._id,
|
||||
old_midplane=self._midplane,
|
||||
new_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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: sensor {sensor_id} temperature updated from {old_temp}C to {new_temp}C".format(name=self._name,
|
||||
id=self._id,
|
||||
sensor_id=sensor_id,
|
||||
old_temp=self._sensors[sensor_id],
|
||||
new_temp=sensors[sensor_id]))
|
||||
|
||||
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):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("router {name} [id={id}]: power supply {power_supply_id} state updated to {powered_on}".format(name=self._name,
|
||||
id=self._id,
|
||||
power_supply_id=power_supply_id,
|
||||
powered_on=power_supply))
|
||||
power_supply_id += 1
|
||||
|
||||
self._power_supplies = power_supplies
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts this router.
|
||||
At least the IOS image must be set before starting it.
|
||||
"""
|
||||
|
||||
# trick: we must send sensors and power supplies info after starting the router
|
||||
# otherwise they are not taken into account (Dynamips bug?)
|
||||
Router.start(self)
|
||||
if self._sensors != [22, 22, 22, 22]:
|
||||
self.sensors = self._sensors
|
||||
if self._power_supplies != [1, 1]:
|
||||
self.power_supplies = self._power_supplies
|
||||
@@ -0,0 +1,342 @@
|
||||
# -*- 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
|
||||
"""
|
||||
|
||||
import os
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EthernetSwitch(object):
|
||||
|
||||
"""
|
||||
Dynamips Ethernet switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
_instances = []
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
# find an instance identifier (0 < id <= 4096)
|
||||
self._id = 0
|
||||
for identifier in range(1, 4097):
|
||||
if identifier not in self._instances:
|
||||
self._id = identifier
|
||||
self._instances.append(self._id)
|
||||
break
|
||||
|
||||
if self._id == 0:
|
||||
raise DynamipsError("Maximum number of instances reached")
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("ethsw create {}".format(self._name))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}] has been created".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Resets the instance count and the allocated instances list.
|
||||
"""
|
||||
|
||||
cls._instances.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Returns the unique ID for this Ethernet switch.
|
||||
|
||||
:returns: id (integer)
|
||||
"""
|
||||
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Returns the current name of this Ethernet switch.
|
||||
|
||||
:returns: Ethernet switch name
|
||||
"""
|
||||
|
||||
return self._name[1:-1] # remove quotes
|
||||
|
||||
@name.setter
|
||||
def name(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))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor instance
|
||||
"""
|
||||
|
||||
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 delete(self):
|
||||
"""
|
||||
Deletes this Ethernet switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("ethsw delete {}".format(self._name))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._instances.remove(self._id)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on Ethernet switch.
|
||||
|
||||
:param nio: NIO instance 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))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: NIO {nio} bound to port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port))
|
||||
self._nios[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this Ethernet switch.
|
||||
|
||||
:param port: allocated port
|
||||
|
||||
:returns: the NIO that was bound to the 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))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: NIO {nio} removed from port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port))
|
||||
|
||||
del self._nios[port]
|
||||
|
||||
if port in self._mapping:
|
||||
del self._mapping[port]
|
||||
|
||||
return nio
|
||||
|
||||
def set_access_port(self, port, vlan_id):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: port {port} set as an access port in VLAN {vlan_id}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port,
|
||||
vlan_id=vlan_id))
|
||||
self._mapping[port] = ("access", vlan_id)
|
||||
|
||||
def set_dot1q_port(self, port, native_vlan):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: port {port} set as a 802.1Q port with native VLAN {vlan_id}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port,
|
||||
vlan_id=native_vlan))
|
||||
|
||||
self._mapping[port] = ("dot1q", native_vlan)
|
||||
|
||||
def set_qinq_port(self, port, outer_vlan):
|
||||
"""
|
||||
Sets 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))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: port {port} set as a QinQ port with outer VLAN {vlan_id}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port,
|
||||
vlan_id=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))
|
||||
|
||||
def start_capture(self, port, output_file, data_link_type="DLT_EN10MB"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
:param output_file: PCAP destination file for the capture
|
||||
:param data_link_type: PCAP data link type (DLT_*), default is DLT_EN10MB
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
|
||||
data_link_type = data_link_type.lower()
|
||||
if data_link_type.startswith("dlt_"):
|
||||
data_link_type = data_link_type[4:]
|
||||
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port))
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(output_file))
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not create captures directory {}".format(e))
|
||||
|
||||
nio.bind_filter("both", "capture")
|
||||
nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: starting packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
|
||||
def stop_capture(self, port):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
nio.unbind_filter("both")
|
||||
log.info("Ethernet switch {name} [id={id}]: stopping packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
@@ -0,0 +1,328 @@
|
||||
# -*- 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
|
||||
"""
|
||||
|
||||
import os
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FrameRelaySwitch(object):
|
||||
|
||||
"""
|
||||
Dynamips Frame Relay switch.
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this switch
|
||||
"""
|
||||
|
||||
_instances = []
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
# find an instance identifier (0 < id <= 4096)
|
||||
self._id = 0
|
||||
for identifier in range(1, 4097):
|
||||
if identifier not in self._instances:
|
||||
self._id = identifier
|
||||
self._instances.append(self._id)
|
||||
break
|
||||
|
||||
if self._id == 0:
|
||||
raise DynamipsError("Maximum number of instances reached")
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("frsw create {}".format(self._name))
|
||||
|
||||
log.info("Frame Relay switch {name} [id={id}] has been created".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
self._hypervisor.devices.append(self)
|
||||
self._nios = {}
|
||||
self._mapping = {}
|
||||
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Resets the instance count and the allocated instances list.
|
||||
"""
|
||||
|
||||
cls._instances.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Returns the unique ID for this Frame Relay switch.
|
||||
|
||||
:returns: id (integer)
|
||||
"""
|
||||
|
||||
return self._id
|
||||
|
||||
@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
|
||||
|
||||
@name.setter
|
||||
def name(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))
|
||||
|
||||
log.info("Frame Relay switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
def hypervisor(self):
|
||||
"""
|
||||
Returns the current hypervisor.
|
||||
|
||||
:returns: hypervisor instance
|
||||
"""
|
||||
|
||||
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 delete(self):
|
||||
"""
|
||||
Deletes this Frame Relay switch.
|
||||
"""
|
||||
|
||||
self._hypervisor.send("frsw delete {}".format(self._name))
|
||||
|
||||
log.info("Frame Relay switch {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._hypervisor.devices.remove(self)
|
||||
self._instances.remove(self._id)
|
||||
|
||||
def has_port(self, port):
|
||||
"""
|
||||
Checks if a port exists on this Frame Relay switch.
|
||||
|
||||
:returns: boolean
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on Frame Relay switch.
|
||||
|
||||
:param nio: NIO instance to add
|
||||
:param port: port to allocate for the NIO
|
||||
"""
|
||||
|
||||
if port in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port))
|
||||
|
||||
log.info("Frame Relay switch {name} [id={id}]: NIO {nio} bound to port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=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
|
||||
|
||||
:returns: the NIO that was bound to the allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
log.info("Frame Relay switch {name} [id={id}]: NIO {nio} removed from port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port))
|
||||
|
||||
del self._nios[port]
|
||||
return nio
|
||||
|
||||
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))
|
||||
|
||||
log.info("Frame Relay switch {name} [id={id}]: VC from port {port1} DLCI {dlci1} to port {port2} DLCI {dlci2} created".format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
dlci1=dlci1,
|
||||
port2=port2,
|
||||
dlci2=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))
|
||||
|
||||
log.info("Frame Relay switch {name} [id={id}]: VC from port {port1} DLCI {dlci1} to port {port2} DLCI {dlci2} deleted".format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
dlci1=dlci1,
|
||||
port2=port2,
|
||||
dlci2=dlci2))
|
||||
del self._mapping[(port1, dlci1)]
|
||||
|
||||
def start_capture(self, port, output_file, data_link_type="DLT_FRELAY"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
:param output_file: PCAP destination file for the capture
|
||||
:param data_link_type: PCAP data link type (DLT_*), default is DLT_FRELAY
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
|
||||
data_link_type = data_link_type.lower()
|
||||
if data_link_type.startswith("dlt_"):
|
||||
data_link_type = data_link_type[4:]
|
||||
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port))
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(output_file))
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not create captures directory {}".format(e))
|
||||
|
||||
nio.bind_filter("both", "capture")
|
||||
nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||
|
||||
log.info("Frame relay switch {name} [id={id}]: starting packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
|
||||
def stop_capture(self, port):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._nios[port]
|
||||
nio.unbind_filter("both")
|
||||
log.info("Frame relay switch {name} [id={id}]: stopping packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
@@ -0,0 +1,189 @@
|
||||
# -*- 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.
|
||||
"""
|
||||
|
||||
import os
|
||||
from .bridge import Bridge
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Hub(Bridge):
|
||||
|
||||
"""
|
||||
Dynamips hub (based on Bridge)
|
||||
|
||||
:param hypervisor: Dynamips hypervisor instance
|
||||
:param name: name for this hub
|
||||
"""
|
||||
|
||||
_instances = []
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
# find an instance identifier (0 < id <= 4096)
|
||||
self._id = 0
|
||||
for identifier in range(1, 4097):
|
||||
if identifier not in self._instances:
|
||||
self._id = identifier
|
||||
self._instances.append(self._id)
|
||||
break
|
||||
|
||||
if self._id == 0:
|
||||
raise DynamipsError("Maximum number of instances reached")
|
||||
|
||||
self._mapping = {}
|
||||
Bridge.__init__(self, hypervisor, name)
|
||||
|
||||
log.info("Ethernet hub {name} [id={id}] has been created".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""
|
||||
Resets the instance count and the allocated instances list.
|
||||
"""
|
||||
|
||||
cls._instances.clear()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Returns the unique ID for this Ethernet switch.
|
||||
|
||||
:returns: id (integer)
|
||||
"""
|
||||
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"""
|
||||
Returns port mapping
|
||||
|
||||
:returns: mapping list
|
||||
"""
|
||||
|
||||
return self._mapping
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Deletes this hub.
|
||||
"""
|
||||
|
||||
Bridge.delete(self)
|
||||
log.info("Ethernet hub {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
self._instances.remove(self._id)
|
||||
|
||||
def add_nio(self, nio, port):
|
||||
"""
|
||||
Adds a NIO as new port on this hub.
|
||||
|
||||
:param nio: NIO instance 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)
|
||||
|
||||
log.info("Ethernet hub {name} [id={id}]: NIO {nio} bound to port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port))
|
||||
self._mapping[port] = nio
|
||||
|
||||
def remove_nio(self, port):
|
||||
"""
|
||||
Removes the specified NIO as member of this hub.
|
||||
|
||||
:param port: allocated port
|
||||
|
||||
:returns: the NIO that was bound to the 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)
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: NIO {nio} removed from port {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port))
|
||||
|
||||
del self._mapping[port]
|
||||
return nio
|
||||
|
||||
def start_capture(self, port, output_file, data_link_type="DLT_EN10MB"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
:param output_file: PCAP destination file for the capture
|
||||
:param data_link_type: PCAP data link type (DLT_*), default is DLT_EN10MB
|
||||
"""
|
||||
|
||||
if port not in self._mapping:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._mapping[port]
|
||||
|
||||
data_link_type = data_link_type.lower()
|
||||
if data_link_type.startswith("dlt_"):
|
||||
data_link_type = data_link_type[4:]
|
||||
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port))
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(output_file))
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not create captures directory {}".format(e))
|
||||
|
||||
nio.bind_filter("both", "capture")
|
||||
nio.setup_filter("both", "{} {}".format(data_link_type, output_file))
|
||||
|
||||
log.info("Ethernet hub {name} [id={id}]: starting packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
|
||||
def stop_capture(self, port):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
:param port: allocated port
|
||||
"""
|
||||
|
||||
if port not in self._mapping:
|
||||
raise DynamipsError("Port {} is not allocated".format(port))
|
||||
|
||||
nio = self._mapping[port]
|
||||
nio.unbind_filter("both")
|
||||
log.info("Ethernet hub {name} [id={id}]: stopping packet capture on {port}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port))
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user