Functional Ethernet hub with new API. Uses Dynamips backend by default for now.

This commit is contained in:
grossmj committed 2016-05-17 21:22:18 -06:00
1 parent f052299eb1
commit 7ebbdcd47c
9 files changed
+138 -402

No files matched your search

+60 -128
View File
@@ -42,136 +42,68 @@ class EthernetHub(BaseNode):
def __init__(self, name, node_id, project, manager):
super().__init__(name, node_id, project, manager)
self._mappings = {}
def __json__(self):
return {"name": self.name,
"project_id": self.project.id,
"node_id": self.id}
"node_id": self.id,
"project_id": self.project.id}
# @asyncio.coroutine
# def create(self):
#
# yield from Bridge.create(self)
# log.info('Ethernet hub "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
#
# @property
# def mappings(self):
# """
# Returns port mappings
#
# :returns: mappings list
# """
#
# return self._mappings
#
# @asyncio.coroutine
# def delete(self):
# """
# Deletes this hub.
# """
#
# for nio in self._nios:
# if nio and isinstance(nio, NIOUDP):
# self.manager.port_manager.release_udp_port(nio.lport, self._project)
#
# try:
# yield from Bridge.delete(self)
# log.info('Ethernet hub "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
# except DynamipsError:
# log.debug("Could not properly delete Ethernet hub {}".format(self._name))
# if self._hypervisor and not self._hypervisor.devices:
# yield from self.hypervisor.stop()
#
# @asyncio.coroutine
# def add_nio(self, nio, port_number):
# """
# Adds a NIO as new port on this hub.
#
# :param nio: NIO instance to add
# :param port_number: port to allocate for the NIO
# """
#
# if port_number in self._mappings:
# raise DynamipsError("Port {} isn't free".format(port_number))
#
# yield from Bridge.add_nio(self, nio)
#
# log.info('Ethernet hub "{name}" [{id}]: NIO {nio} bound to port {port}'.format(name=self._name,
# id=self._id,
# nio=nio,
# port=port_number))
# self._mappings[port_number] = nio
#
# @asyncio.coroutine
# def remove_nio(self, port_number):
# """
# Removes the specified NIO as member of this hub.
#
# :param port_number: allocated port number
#
# :returns: the NIO that was bound to the allocated port
# """
#
# if port_number not in self._mappings:
# raise DynamipsError("Port {} is not allocated".format(port_number))
#
# nio = self._mappings[port_number]
# if isinstance(nio, NIOUDP):
# self.manager.port_manager.release_udp_port(nio.lport, self._project)
# yield from Bridge.remove_nio(self, nio)
#
# log.info('Ethernet switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
# id=self._id,
# nio=nio,
# port=port_number))
#
# del self._mappings[port_number]
# return nio
#
# @asyncio.coroutine
# def start_capture(self, port_number, output_file, data_link_type="DLT_EN10MB"):
# """
# Starts a packet capture.
#
# :param port_number: allocated port number
# :param output_file: PCAP destination file for the capture
# :param data_link_type: PCAP data link type (DLT_*), default is DLT_EN10MB
# """
#
# if port_number not in self._mappings:
# raise DynamipsError("Port {} is not allocated".format(port_number))
#
# nio = self._mappings[port_number]
#
# 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_number))
#
# yield from nio.bind_filter("both", "capture")
# yield from nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
#
# log.info('Ethernet hub "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
# id=self._id,
# port=port_number))
#
# @asyncio.coroutine
# def stop_capture(self, port_number):
# """
# Stops a packet capture.
#
# :param port_number: allocated port number
# """
#
# if port_number not in self._mappings:
# raise DynamipsError("Port {} is not allocated".format(port_number))
#
# nio = self._mappings[port_number]
# yield from nio.unbind_filter("both")
# log.info('Ethernet hub "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
# id=self._id,
# port=port_number))
@asyncio.coroutine
def create(self):
super().create()
log.info('Ethernet hub "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
@asyncio.coroutine
def delete(self):
"""
Deletes this hub.
"""
raise NotImplementedError()
@asyncio.coroutine
def add_nio(self, nio, port_number):
"""
Adds a NIO as new port on this hub.
:param nio: NIO instance to add
:param port_number: port to allocate for the NIO
"""
raise NotImplementedError()
@asyncio.coroutine
def remove_nio(self, port_number):
"""
Removes the specified NIO as member of this hub.
:param port_number: allocated port number
:returns: the NIO that was bound to the allocated port
"""
raise NotImplementedError()
@asyncio.coroutine
def start_capture(self, port_number, output_file, data_link_type="DLT_EN10MB"):
"""
Starts a packet capture.
:param port_number: allocated port number
:param output_file: PCAP destination file for the capture
:param data_link_type: PCAP data link type (DLT_*), default is DLT_EN10MB
"""
raise NotImplementedError()
@asyncio.coroutine
def stop_capture(self, port_number):
"""
Stops a packet capture.
:param port_number: allocated port number
"""
raise NotImplementedError()
+2 -2
View File
@@ -43,7 +43,7 @@ from .dynamips_error import DynamipsError
from .hypervisor import Hypervisor
from .nodes.router import Router
from .dynamips_vm_factory import DynamipsVMFactory
from .dynamips_device import DynamipsDevice
from .dynamips_device_factory import DynamipsDeviceFactory
# NIOs
from .nios.nio_udp import NIOUDP
@@ -103,7 +103,7 @@ WIC_MATRIX = {"WIC-1ENET": WIC_1ENET,
class Dynamips(BaseManager):
_NODE_CLASS = DynamipsVMFactory
_DEVICE_CLASS = DynamipsDevice
_DEVICE_CLASS = DynamipsDeviceFactory
_ghost_ios_lock = None
def __init__(self):
@@ -31,7 +31,7 @@ DEVICES = {'atm_switch': ATMSwitch,
'ethernet_hub': EthernetHub}
class DynamipsDevice:
class DynamipsDeviceFactory:
"""
Factory to create an Device object based on the type
@@ -49,7 +49,7 @@ class EthernetHub(Bridge):
def __json__(self):
return {"name": self.name,
"device_id": self.id,
"node_id": self.id,
"project_id": self.project.id}
@asyncio.coroutine