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:
parent
d96e6a60ab
commit
e848eaa57e
@ -112,21 +112,23 @@ from ryu.services.protocols.bgp.rtconf.neighbors import (
|
|||||||
DEFAULT_CAP_MBGP_VPNV4FS,
|
DEFAULT_CAP_MBGP_VPNV4FS,
|
||||||
DEFAULT_CAP_MBGP_VPNV6FS,
|
DEFAULT_CAP_MBGP_VPNV6FS,
|
||||||
DEFAULT_CAP_MBGP_L2VPNFS,
|
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.rtconf.vrfs import SUPPORTED_VRF_RF
|
||||||
from ryu.services.protocols.bgp.info_base.base import Filter
|
from ryu.services.protocols.bgp.info_base.base import Filter
|
||||||
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
|
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
|
||||||
@ -406,6 +408,7 @@ class BGPSpeaker(object):
|
|||||||
call('core.stop')
|
call('core.stop')
|
||||||
|
|
||||||
def neighbor_add(self, address, remote_as,
|
def neighbor_add(self, address, remote_as,
|
||||||
|
remote_port=DEFAULT_BGP_PORT,
|
||||||
enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
|
enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
|
||||||
enable_ipv6=DEFAULT_CAP_MBGP_IPV6,
|
enable_ipv6=DEFAULT_CAP_MBGP_IPV6,
|
||||||
enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
|
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
|
``remote_as`` specifies the AS number of the peer. It must be
|
||||||
an integer between 1 and 65535.
|
an integer between 1 and 65535.
|
||||||
|
|
||||||
|
``remote_port`` specifies the TCP port number of the peer.
|
||||||
|
|
||||||
``enable_ipv4`` enables IPv4 address family for this
|
``enable_ipv4`` enables IPv4 address family for this
|
||||||
neighbor.
|
neighbor.
|
||||||
|
|
||||||
@ -513,6 +518,7 @@ class BGPSpeaker(object):
|
|||||||
bgp_neighbor = {
|
bgp_neighbor = {
|
||||||
neighbors.IP_ADDRESS: address,
|
neighbors.IP_ADDRESS: address,
|
||||||
neighbors.REMOTE_AS: remote_as,
|
neighbors.REMOTE_AS: remote_as,
|
||||||
|
REMOTE_PORT: remote_port,
|
||||||
PEER_NEXT_HOP: next_hop,
|
PEER_NEXT_HOP: next_hop,
|
||||||
PASSWORD: password,
|
PASSWORD: password,
|
||||||
IS_ROUTE_SERVER_CLIENT: is_route_server_client,
|
IS_ROUTE_SERVER_CLIENT: is_route_server_client,
|
||||||
|
@ -1283,7 +1283,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
|||||||
else:
|
else:
|
||||||
bind_addr = None
|
bind_addr = None
|
||||||
peer_address = (self._neigh_conf.ip_address,
|
peer_address = (self._neigh_conf.ip_address,
|
||||||
const.STD_BGP_SERVER_PORT_NUM)
|
self._neigh_conf.port)
|
||||||
|
|
||||||
if bind_addr:
|
if bind_addr:
|
||||||
LOG.debug('%s trying to connect from'
|
LOG.debug('%s trying to connect from'
|
||||||
|
@ -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.lib.packet.bgp import BGP_CAP_ROUTE_REFRESH
|
||||||
|
|
||||||
from ryu.services.protocols.bgp.base import OrderedDict
|
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 ADVERTISE_PEER_AS
|
||||||
from ryu.services.protocols.bgp.rtconf.base import BaseConf
|
from ryu.services.protocols.bgp.rtconf.base import BaseConf
|
||||||
from ryu.services.protocols.bgp.rtconf.base import BaseConfListener
|
from ryu.services.protocols.bgp.rtconf.base import BaseConfListener
|
||||||
@ -88,6 +89,7 @@ LOG = logging.getLogger('bgpspeaker.rtconf.neighbor')
|
|||||||
# Various neighbor settings.
|
# Various neighbor settings.
|
||||||
REMOTE_AS = 'remote_as'
|
REMOTE_AS = 'remote_as'
|
||||||
IP_ADDRESS = 'ip_address'
|
IP_ADDRESS = 'ip_address'
|
||||||
|
REMOTE_PORT = 'remote_port'
|
||||||
ENABLED = 'enabled'
|
ENABLED = 'enabled'
|
||||||
CHANGES = 'changes'
|
CHANGES = 'changes'
|
||||||
LOCAL_ADDRESS = 'local_address'
|
LOCAL_ADDRESS = 'local_address'
|
||||||
@ -108,6 +110,7 @@ CONNECT_MODE_PASSIVE = 'passive'
|
|||||||
CONNECT_MODE_BOTH = 'both'
|
CONNECT_MODE_BOTH = 'both'
|
||||||
|
|
||||||
# Default value constants.
|
# Default value constants.
|
||||||
|
DEFAULT_BGP_PORT = STD_BGP_SERVER_PORT_NUM
|
||||||
DEFAULT_CAP_GR_NULL = True
|
DEFAULT_CAP_GR_NULL = True
|
||||||
DEFAULT_CAP_REFRESH = True
|
DEFAULT_CAP_REFRESH = True
|
||||||
DEFAULT_CAP_ENHANCED_REFRESH = False
|
DEFAULT_CAP_ENHANCED_REFRESH = False
|
||||||
@ -213,6 +216,13 @@ def validate_remote_as(asn):
|
|||||||
return 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_):
|
def valid_prefix_filter(filter_):
|
||||||
policy = filter_.get('policy', None)
|
policy = filter_.get('policy', None)
|
||||||
if policy == 'permit':
|
if policy == 'permit':
|
||||||
@ -339,7 +349,7 @@ class NeighborConf(ConfWithId, ConfWithStats):
|
|||||||
CAP_MBGP_IPV4FS, CAP_MBGP_VPNV4FS,
|
CAP_MBGP_IPV4FS, CAP_MBGP_VPNV4FS,
|
||||||
CAP_MBGP_IPV6FS, CAP_MBGP_VPNV6FS,
|
CAP_MBGP_IPV6FS, CAP_MBGP_VPNV6FS,
|
||||||
CAP_MBGP_L2VPNFS,
|
CAP_MBGP_L2VPNFS,
|
||||||
RTC_AS, HOLD_TIME,
|
RTC_AS, HOLD_TIME, REMOTE_PORT,
|
||||||
ENABLED, MULTI_EXIT_DISC, MAX_PREFIXES,
|
ENABLED, MULTI_EXIT_DISC, MAX_PREFIXES,
|
||||||
ADVERTISE_PEER_AS, SITE_OF_ORIGINS,
|
ADVERTISE_PEER_AS, SITE_OF_ORIGINS,
|
||||||
LOCAL_ADDRESS, LOCAL_PORT, LOCAL_AS,
|
LOCAL_ADDRESS, LOCAL_PORT, LOCAL_AS,
|
||||||
@ -406,6 +416,8 @@ class NeighborConf(ConfWithId, ConfWithStats):
|
|||||||
DEFAULT_IS_NEXT_HOP_SELF, **kwargs)
|
DEFAULT_IS_NEXT_HOP_SELF, **kwargs)
|
||||||
self._settings[CONNECT_MODE] = compute_optional_conf(
|
self._settings[CONNECT_MODE] = compute_optional_conf(
|
||||||
CONNECT_MODE, DEFAULT_CONNECT_MODE, **kwargs)
|
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.
|
# We do not have valid default MED value.
|
||||||
# If no MED attribute is provided then we do not have to use MED.
|
# 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):
|
def ip_address(self):
|
||||||
return self._settings[IP_ADDRESS]
|
return self._settings[IP_ADDRESS]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def port(self):
|
||||||
|
return self._settings[REMOTE_PORT]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def host_bind_ip(self):
|
def host_bind_ip(self):
|
||||||
return self._settings[LOCAL_ADDRESS]
|
return self._settings[LOCAL_ADDRESS]
|
||||||
|
Loading…
Reference in New Issue
Block a user