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>
This commit is contained in:
IWASE Yusuke 2018-06-27 16:13:25 +09:00 committed by FUJITA Tomonori
parent d96e6a60ab
commit e848eaa57e
3 changed files with 38 additions and 16 deletions

View File

@ -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,

View File

@ -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'

View File

@ -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.
@ -483,6 +495,10 @@ class NeighborConf(ConfWithId, ConfWithStats):
def ip_address(self):
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]