summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/services/protocols/bgp/base.py2
-rw-r--r--ryu/services/protocols/bgp/bgp_sample_conf.py3
-rw-r--r--ryu/services/protocols/bgp/bgpspeaker.py6
-rw-r--r--ryu/services/protocols/bgp/core.py16
-rw-r--r--ryu/services/protocols/bgp/rtconf/common.py25
5 files changed, 41 insertions, 11 deletions
diff --git a/ryu/services/protocols/bgp/base.py b/ryu/services/protocols/bgp/base.py
index 6295ed9e..d5975dd9 100644
--- a/ryu/services/protocols/bgp/base.py
+++ b/ryu/services/protocols/bgp/base.py
@@ -363,7 +363,7 @@ class Activity(object):
For each connection `server_factory` starts a new protocol.
"""
- info = socket.getaddrinfo(None, loc_addr[1], socket.AF_UNSPEC,
+ info = socket.getaddrinfo(loc_addr[0], loc_addr[1], socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
listen_sockets = {}
for res in info:
diff --git a/ryu/services/protocols/bgp/bgp_sample_conf.py b/ryu/services/protocols/bgp/bgp_sample_conf.py
index efdee698..e3f686c8 100644
--- a/ryu/services/protocols/bgp/bgp_sample_conf.py
+++ b/ryu/services/protocols/bgp/bgp_sample_conf.py
@@ -48,6 +48,9 @@ BGP = {
# Default local preference
'local_pref': 100,
+ # List of TCP listen host addresses.
+ 'bgp_server_hosts': ['0.0.0.0', '::'],
+
# List of BGP neighbors.
# The parameters for each neighbor are the same as the arguments of
# BGPSpeaker.neighbor_add() method.
diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py
index c93eacba..4ffcd829 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
@@ -70,7 +70,9 @@ from ryu.services.protocols.bgp.api.prefix import (
from ryu.services.protocols.bgp.rtconf.common import LOCAL_AS
from ryu.services.protocols.bgp.rtconf.common import ROUTER_ID
from ryu.services.protocols.bgp.rtconf.common import CLUSTER_ID
+from ryu.services.protocols.bgp.rtconf.common import BGP_SERVER_HOSTS
from ryu.services.protocols.bgp.rtconf.common import BGP_SERVER_PORT
+from ryu.services.protocols.bgp.rtconf.common import DEFAULT_BGP_SERVER_HOSTS
from ryu.services.protocols.bgp.rtconf.common import DEFAULT_BGP_SERVER_PORT
from ryu.services.protocols.bgp.rtconf.common import (
DEFAULT_REFRESH_MAX_EOR_TIME, DEFAULT_REFRESH_STALEPATH_TIME)
@@ -218,6 +220,7 @@ class EventPrefix(object):
class BGPSpeaker(object):
def __init__(self, as_number, router_id,
+ bgp_server_hosts=DEFAULT_BGP_SERVER_HOSTS,
bgp_server_port=DEFAULT_BGP_SERVER_PORT,
refresh_stalepath_time=DEFAULT_REFRESH_STALEPATH_TIME,
refresh_max_eor_time=DEFAULT_REFRESH_MAX_EOR_TIME,
@@ -239,6 +242,8 @@ class BGPSpeaker(object):
``router_id`` specifies BGP router identifier. It must be the
string representation of an IPv4 address (e.g. 10.0.0.1).
+ ``bgp_server_host`` specifies a list of TCP listen host addresses.
+
``bgp_server_port`` specifies TCP listen port number. 179 is
used if not specified.
@@ -297,6 +302,7 @@ class BGPSpeaker(object):
settings = {
LOCAL_AS: as_number,
ROUTER_ID: router_id,
+ BGP_SERVER_HOSTS: bgp_server_hosts,
BGP_SERVER_PORT: bgp_server_port,
REFRESH_STALEPATH_TIME: refresh_stalepath_time,
REFRESH_MAX_EOR_TIME: refresh_max_eor_time,
diff --git a/ryu/services/protocols/bgp/core.py b/ryu/services/protocols/bgp/core.py
index 74f23410..cfb296e5 100644
--- a/ryu/services/protocols/bgp/core.py
+++ b/ryu/services/protocols/bgp/core.py
@@ -224,17 +224,17 @@ class CoreService(Factory, Activity):
self._spawn_activity(peer, self.start_protocol)
# Reactively establish bgp-session with peer by listening on
- # server port for connection requests.
- server_addr = (CORE_IP, self._common_config.bgp_server_port)
+ # the given server hosts and port for connection requests.
waiter = kwargs.pop('waiter')
waiter.set()
+ self.listen_sockets = {}
if self._common_config.bgp_server_port != 0:
- server_thread, sockets = self._listen_tcp(server_addr,
- self.start_protocol)
- self.listen_sockets = sockets
- server_thread.wait()
- else:
- self.listen_sockets = {}
+ for host in self._common_config.bgp_server_hosts:
+ server_thread, sockets = self._listen_tcp(
+ (host, self._common_config.bgp_server_port),
+ self.start_protocol)
+ self.listen_sockets.update(sockets)
+ server_thread.wait()
processor_thread.wait()
# ========================================================================
diff --git a/ryu/services/protocols/bgp/rtconf/common.py b/ryu/services/protocols/bgp/rtconf/common.py
index f8427caa..b5bdef0d 100644
--- a/ryu/services/protocols/bgp/rtconf/common.py
+++ b/ryu/services/protocols/bgp/rtconf/common.py
@@ -19,6 +19,8 @@
import logging
import numbers
+import netaddr
+
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
from ryu.services.protocols.bgp.utils.validation import is_valid_asn
@@ -72,6 +74,7 @@ REFRESH_STALEPATH_TIME = 'refresh_stalepath_time'
REFRESH_MAX_EOR_TIME = 'refresh_max_eor_time'
BGP_CONN_RETRY_TIME = 'bgp_conn_retry_time'
+BGP_SERVER_HOSTS = 'bgp_server_hosts'
BGP_SERVER_PORT = 'bgp_server_port'
TCP_CONN_TIMEOUT = 'tcp_conn_timeout'
MAX_PATH_EXT_RTFILTER_ALL = 'maximum_paths_external_rtfilter_all'
@@ -81,6 +84,7 @@ MAX_PATH_EXT_RTFILTER_ALL = 'maximum_paths_external_rtfilter_all'
DEFAULT_LABEL_RANGE = (100, 100000)
DEFAULT_REFRESH_STALEPATH_TIME = 0
DEFAULT_REFRESH_MAX_EOR_TIME = 0
+DEFAULT_BGP_SERVER_HOSTS = ('0.0.0.0', '::')
DEFAULT_BGP_SERVER_PORT = 179
DEFAULT_TCP_CONN_TIMEOUT = 30
DEFAULT_BGP_CONN_RETRY_TIME = 30
@@ -170,6 +174,17 @@ def validate_label_range(label_range):
return label_range
+@validate(name=BGP_SERVER_HOSTS)
+def validate_bgp_server_hosts(hosts):
+ for host in hosts:
+ if (not netaddr.valid_ipv4(host) and
+ not netaddr.valid_ipv6(host)):
+ raise ConfigTypeError(desc=('Invalid bgp sever hosts '
+ 'configuration value %s' % hosts))
+
+ return hosts
+
+
@validate(name=BGP_SERVER_PORT)
def validate_bgp_server_port(server_port):
if not isinstance(server_port, numbers.Integral):
@@ -243,8 +258,8 @@ class CommonConf(BaseConf):
REQUIRED_SETTINGS = frozenset([ROUTER_ID, LOCAL_AS])
OPTIONAL_SETTINGS = frozenset([REFRESH_STALEPATH_TIME,
- REFRESH_MAX_EOR_TIME,
- LABEL_RANGE, BGP_SERVER_PORT,
+ REFRESH_MAX_EOR_TIME, LABEL_RANGE,
+ BGP_SERVER_HOSTS, BGP_SERVER_PORT,
TCP_CONN_TIMEOUT,
BGP_CONN_RETRY_TIME,
MAX_PATH_EXT_RTFILTER_ALL,
@@ -265,6 +280,8 @@ class CommonConf(BaseConf):
REFRESH_STALEPATH_TIME, DEFAULT_REFRESH_STALEPATH_TIME, **kwargs)
self._settings[REFRESH_MAX_EOR_TIME] = compute_optional_conf(
REFRESH_MAX_EOR_TIME, DEFAULT_REFRESH_MAX_EOR_TIME, **kwargs)
+ self._settings[BGP_SERVER_HOSTS] = compute_optional_conf(
+ BGP_SERVER_HOSTS, DEFAULT_BGP_SERVER_HOSTS, **kwargs)
self._settings[BGP_SERVER_PORT] = compute_optional_conf(
BGP_SERVER_PORT, DEFAULT_BGP_SERVER_PORT, **kwargs)
self._settings[TCP_CONN_TIMEOUT] = compute_optional_conf(
@@ -323,6 +340,10 @@ class CommonConf(BaseConf):
return self._settings[LABEL_RANGE]
@property
+ def bgp_server_hosts(self):
+ return self._settings[BGP_SERVER_HOSTS]
+
+ @property
def bgp_server_port(self):
return self._settings[BGP_SERVER_PORT]