summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-27 16:13:25 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-07-15 16:23:47 +0900
commite848eaa57e2532cd2cb298fd58910abc00cedf9d (patch)
treeff15885219132706f49112c84bbdfc309b0f4b50
parentd96e6a60ab15abffe1ddd63a6dd0e36de0b41bf3 (diff)
BGPSpeaker: Enable to specify remote port for neighbor
Currently, the remote port of neighbor is the hard-coded value 179. This patch enables to specify the remote port of neighbor in "BGPSpeaker.neighbor_add()" API. Suggested-by: Suresh Kumar <knetsolutions2@gmail.com> Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r--ryu/services/protocols/bgp/bgpspeaker.py34
-rw-r--r--ryu/services/protocols/bgp/peer.py2
-rw-r--r--ryu/services/protocols/bgp/rtconf/neighbors.py18
3 files changed, 38 insertions, 16 deletions
diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py
index 46cbcaf1..2f53f636 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
@@ -112,21 +112,23 @@ from ryu.services.protocols.bgp.rtconf.neighbors import (
DEFAULT_CAP_MBGP_VPNV4FS,
DEFAULT_CAP_MBGP_VPNV6FS,
DEFAULT_CAP_MBGP_L2VPNFS,
+ DEFAULT_CAP_ENHANCED_REFRESH,
+ DEFAULT_CAP_FOUR_OCTET_AS_NUMBER,
+ DEFAULT_CONNECT_MODE,
+ REMOTE_PORT,
+ DEFAULT_BGP_PORT,
+ PEER_NEXT_HOP,
+ PASSWORD,
+ DEFAULT_IS_ROUTE_SERVER_CLIENT,
+ IS_ROUTE_SERVER_CLIENT,
+ DEFAULT_IS_ROUTE_REFLECTOR_CLIENT,
+ IS_ROUTE_REFLECTOR_CLIENT,
+ DEFAULT_IS_NEXT_HOP_SELF,
+ IS_NEXT_HOP_SELF,
+ CONNECT_MODE,
+ LOCAL_ADDRESS,
+ LOCAL_PORT,
)
-from ryu.services.protocols.bgp.rtconf.neighbors import (
- DEFAULT_CAP_ENHANCED_REFRESH, DEFAULT_CAP_FOUR_OCTET_AS_NUMBER)
-from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CONNECT_MODE
-from ryu.services.protocols.bgp.rtconf.neighbors import PEER_NEXT_HOP
-from ryu.services.protocols.bgp.rtconf.neighbors import PASSWORD
-from ryu.services.protocols.bgp.rtconf.neighbors import (
- DEFAULT_IS_ROUTE_SERVER_CLIENT, IS_ROUTE_SERVER_CLIENT)
-from ryu.services.protocols.bgp.rtconf.neighbors import (
- DEFAULT_IS_ROUTE_REFLECTOR_CLIENT, IS_ROUTE_REFLECTOR_CLIENT)
-from ryu.services.protocols.bgp.rtconf.neighbors import (
- DEFAULT_IS_NEXT_HOP_SELF, IS_NEXT_HOP_SELF)
-from ryu.services.protocols.bgp.rtconf.neighbors import CONNECT_MODE
-from ryu.services.protocols.bgp.rtconf.neighbors import LOCAL_ADDRESS
-from ryu.services.protocols.bgp.rtconf.neighbors import LOCAL_PORT
from ryu.services.protocols.bgp.rtconf.vrfs import SUPPORTED_VRF_RF
from ryu.services.protocols.bgp.info_base.base import Filter
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
@@ -406,6 +408,7 @@ class BGPSpeaker(object):
call('core.stop')
def neighbor_add(self, address, remote_as,
+ remote_port=DEFAULT_BGP_PORT,
enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
enable_ipv6=DEFAULT_CAP_MBGP_IPV6,
enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
@@ -437,6 +440,8 @@ class BGPSpeaker(object):
``remote_as`` specifies the AS number of the peer. It must be
an integer between 1 and 65535.
+ ``remote_port`` specifies the TCP port number of the peer.
+
``enable_ipv4`` enables IPv4 address family for this
neighbor.
@@ -513,6 +518,7 @@ class BGPSpeaker(object):
bgp_neighbor = {
neighbors.IP_ADDRESS: address,
neighbors.REMOTE_AS: remote_as,
+ REMOTE_PORT: remote_port,
PEER_NEXT_HOP: next_hop,
PASSWORD: password,
IS_ROUTE_SERVER_CLIENT: is_route_server_client,
diff --git a/ryu/services/protocols/bgp/peer.py b/ryu/services/protocols/bgp/peer.py
index 2c6e3898..f41715eb 100644
--- a/ryu/services/protocols/bgp/peer.py
+++ b/ryu/services/protocols/bgp/peer.py
@@ -1283,7 +1283,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
else:
bind_addr = None
peer_address = (self._neigh_conf.ip_address,
- const.STD_BGP_SERVER_PORT_NUM)
+ self._neigh_conf.port)
if bind_addr:
LOG.debug('%s trying to connect from'
diff --git a/ryu/services/protocols/bgp/rtconf/neighbors.py b/ryu/services/protocols/bgp/rtconf/neighbors.py
index 6c481a49..b0853f10 100644
--- a/ryu/services/protocols/bgp/rtconf/neighbors.py
+++ b/ryu/services/protocols/bgp/rtconf/neighbors.py
@@ -45,6 +45,7 @@ from ryu.lib.packet.bgp import BGP_CAP_MULTIPROTOCOL
from ryu.lib.packet.bgp import BGP_CAP_ROUTE_REFRESH
from ryu.services.protocols.bgp.base import OrderedDict
+from ryu.services.protocols.bgp.constants import STD_BGP_SERVER_PORT_NUM
from ryu.services.protocols.bgp.rtconf.base import ADVERTISE_PEER_AS
from ryu.services.protocols.bgp.rtconf.base import BaseConf
from ryu.services.protocols.bgp.rtconf.base import BaseConfListener
@@ -88,6 +89,7 @@ LOG = logging.getLogger('bgpspeaker.rtconf.neighbor')
# Various neighbor settings.
REMOTE_AS = 'remote_as'
IP_ADDRESS = 'ip_address'
+REMOTE_PORT = 'remote_port'
ENABLED = 'enabled'
CHANGES = 'changes'
LOCAL_ADDRESS = 'local_address'
@@ -108,6 +110,7 @@ CONNECT_MODE_PASSIVE = 'passive'
CONNECT_MODE_BOTH = 'both'
# Default value constants.
+DEFAULT_BGP_PORT = STD_BGP_SERVER_PORT_NUM
DEFAULT_CAP_GR_NULL = True
DEFAULT_CAP_REFRESH = True
DEFAULT_CAP_ENHANCED_REFRESH = False
@@ -213,6 +216,13 @@ def validate_remote_as(asn):
return asn
+@validate(name=REMOTE_PORT)
+def validate_remote_port(port):
+ if not isinstance(port, numbers.Integral):
+ raise ConfigTypeError(desc='Invalid remote port: %s' % port)
+ return port
+
+
def valid_prefix_filter(filter_):
policy = filter_.get('policy', None)
if policy == 'permit':
@@ -339,7 +349,7 @@ class NeighborConf(ConfWithId, ConfWithStats):
CAP_MBGP_IPV4FS, CAP_MBGP_VPNV4FS,
CAP_MBGP_IPV6FS, CAP_MBGP_VPNV6FS,
CAP_MBGP_L2VPNFS,
- RTC_AS, HOLD_TIME,
+ RTC_AS, HOLD_TIME, REMOTE_PORT,
ENABLED, MULTI_EXIT_DISC, MAX_PREFIXES,
ADVERTISE_PEER_AS, SITE_OF_ORIGINS,
LOCAL_ADDRESS, LOCAL_PORT, LOCAL_AS,
@@ -406,6 +416,8 @@ class NeighborConf(ConfWithId, ConfWithStats):
DEFAULT_IS_NEXT_HOP_SELF, **kwargs)
self._settings[CONNECT_MODE] = compute_optional_conf(
CONNECT_MODE, DEFAULT_CONNECT_MODE, **kwargs)
+ self._settings[REMOTE_PORT] = compute_optional_conf(
+ REMOTE_PORT, DEFAULT_BGP_PORT, **kwargs)
# We do not have valid default MED value.
# If no MED attribute is provided then we do not have to use MED.
@@ -484,6 +496,10 @@ class NeighborConf(ConfWithId, ConfWithStats):
return self._settings[IP_ADDRESS]
@property
+ def port(self):
+ return self._settings[REMOTE_PORT]
+
+ @property
def host_bind_ip(self):
return self._settings[LOCAL_ADDRESS]