Ranges for UDP, console, auxiliary console and hypervisor ports.

Dynamips UDP NIO auto back-end for UDP tunnel connections (excepting
stubs).
This commit is contained in:
grossmj committed 2014-04-30 20:44:13 -06:00
1 parent 97e19ac7a5
commit 93058f92d4
10 files changed
+420 -242

No files matched your search

+12 -4
View File
@@ -30,12 +30,13 @@ import shutil
from gns3server.modules import IModule
from gns3server.config import Config
import gns3server.jsonrpc as jsonrpc
from .iou_device import IOUDevice
from .iou_error import IOUError
from .nios.nio_udp import NIO_UDP
from .nios.nio_tap import NIO_TAP
from .nios.nio_generic_ethernet import NIO_GenericEthernet
import gns3server.jsonrpc as jsonrpc
from ..attic import find_unused_port
from .schemas import IOU_CREATE_SCHEMA
from .schemas import IOU_DELETE_SCHEMA
@@ -90,6 +91,7 @@ class IOU(IModule):
self._iou_instances = {}
self._console_start_port_range = 4001
self._console_end_port_range = 4512
self._allocated_console_ports = []
self._current_console_port = self._console_start_port_range
self._udp_start_port_range = 30001
self._udp_end_port_range = 40001
@@ -299,9 +301,12 @@ class IOU(IModule):
iou_instance = IOUDevice(iou_path, self._working_dir, host=self._host, name=name)
# find a console port
if self._current_console_port >= self._console_end_port_range:
if self._current_console_port > self._console_end_port_range:
self._current_console_port = self._console_start_port_range
iou_instance.console = IOUDevice.find_unused_port(self._current_console_port, self._console_end_port_range, self._host)
try:
iou_instance.console = find_unused_port(self._current_console_port, self._console_end_port_range, self._host)
except Exception as e:
raise IOUError(e)
self._current_console_port += 1
except IOUError as e:
self.send_custom_error(str(e))
@@ -532,7 +537,10 @@ class IOU(IModule):
# find a UDP port
if self._current_udp_port >= self._udp_end_port_range:
self._current_udp_port = self._udp_start_port_range
port = IOUDevice.find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._host, socket_type="UDP")
try:
port = find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._host, socket_type="UDP")
except Exception as e:
raise IOUError(e)
self._current_udp_port += 1
log.info("{} [id={}] has allocated UDP port {} with host {}".format(iou_instance.name,
-37
View File
@@ -22,8 +22,6 @@ order to run an IOU instance.
import os
import re
import socket
import errno
import signal
import subprocess
import argparse
@@ -813,38 +811,3 @@ class IOUDevice(object):
adapters=len(self._serial_adapters)))
self._slots = self._ethernet_adapters + self._serial_adapters
@staticmethod
def find_unused_port(start_port, end_port, host='127.0.0.1', socket_type="TCP"):
"""
Finds an unused port in the specified range.
:param start_port: first port in the range
:param end_port: last port in the range
:param host: host/address for bind()
:param socket_type: TCP (default) or UDP
"""
if socket_type == "UDP":
socket_type = socket.SOCK_DGRAM
else:
socket_type = socket.SOCK_STREAM
for port in range(start_port, end_port):
try:
if ":" in host:
# IPv6 address support
with socket.socket(socket.AF_INET6, socket_type) as s:
s.bind((host, port)) # the port is available if bind is a success
else:
with socket.socket(socket.AF_INET, socket_type) as s:
s.bind((host, port)) # the port is available if bind is a success
return port
except OSError as e:
if e.errno == errno.EADDRINUSE: # socket already in use
if port + 1 == end_port:
raise IOUError("Could not find a free port between {0} and {1}".format(start_port, end_port))
else:
continue
else:
raise IOUError("Could not find an unused port: {}".format(e))
+2
View File
@@ -25,6 +25,8 @@ class IOUError(Exception):
def __init__(self, message, original_exception=None):
Exception.__init__(self, message)
if isinstance(message, Exception):
message = str(message)
self._message = message
self._original_exception = original_exception